diff mbox series

[v3,19/43] Show the malloc base with the bdinfo command

Message ID 20230504165823.v3.19.Ifeceb389ca067768037fa89ba27000a62fe8c64d@changeid
State Superseded
Delegated to: Bin Meng
Headers show
Series x86: Use qemu-x86_64 to boot EFI installers | expand

Commit Message

Simon Glass May 4, 2023, 10:58 p.m. UTC
It is useful to see the base of the malloc region. This is visible when
debugging but not in normal usage.

Add it to the global data so that it can be shown.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 cmd/bdinfo.c                      |  1 +
 common/board_r.c                  |  7 ++++---
 include/asm-generic/global_data.h | 11 +++++++++++
 3 files changed, 16 insertions(+), 3 deletions(-)

Comments

Nikhil Jain May 5, 2023, 7:50 a.m. UTC | #1
On 05/05/23 04:28, Simon Glass wrote:
> It is useful to see the base of the malloc region. This is visible when
> debugging but not in normal usage.
> 
> Add it to the global data so that it can be shown.
> 
> Signed-off-by: Simon Glass<sjg@chromium.org>
> ---
> 
> (no changes since v1)
> 
>   cmd/bdinfo.c                      |  1 +
>   common/board_r.c                  |  7 ++++---
>   include/asm-generic/global_data.h | 11 +++++++++++
>   3 files changed, 16 insertions(+), 3 deletions(-)

Reviewed-by: Nikhil M Jain <n-jain1@ti.com>
Tested-by: Nikhil M Jain <n-jain1@ti.com>
diff mbox series

Patch

diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c
index 4e0c763a709..f1f8d59673f 100644
--- a/cmd/bdinfo.c
+++ b/cmd/bdinfo.c
@@ -148,6 +148,7 @@  int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	if (IS_ENABLED(CONFIG_CMD_BDINFO_EXTRA)) {
 		bdinfo_print_num_ll("stack ptr", (ulong)&bd);
 		bdinfo_print_num_ll("ram_top ptr", (ulong)gd->ram_top);
+		bdinfo_print_num_l("malloc base", gd_malloc_start());
 	}
 
 	arch_print_bdinfo();
diff --git a/common/board_r.c b/common/board_r.c
index d798c00a80a..4aaa8940311 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -196,7 +196,7 @@  static int initr_barrier(void)
 
 static int initr_malloc(void)
 {
-	ulong malloc_start;
+	ulong start;
 
 #if CONFIG_VAL(SYS_MALLOC_F_LEN)
 	debug("Pre-reloc malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr,
@@ -207,8 +207,9 @@  static int initr_malloc(void)
 	 * This value MUST match the value of gd->start_addr_sp in board_f.c:
 	 * reserve_noncached().
 	 */
-	malloc_start = gd->relocaddr - TOTAL_MALLOC_LEN;
-	mem_malloc_init((ulong)map_sysmem(malloc_start, TOTAL_MALLOC_LEN),
+	start = gd->relocaddr - TOTAL_MALLOC_LEN;
+	gd_set_malloc_start(start);
+	mem_malloc_init((ulong)map_sysmem(start, TOTAL_MALLOC_LEN),
 			TOTAL_MALLOC_LEN);
 	return 0;
 }
diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index a1e1b9d6400..a5cf87f86b3 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -301,6 +301,10 @@  struct global_data {
 	 * @timebase_l: low 32 bits of timer
 	 */
 	unsigned int timebase_l;
+	/**
+	 * @malloc_start: start of malloc() region
+	 */
+	CONFIG_IS_ENABLED(CMD_BDINFO_EXTRA, (ulong malloc_start;))
 #if CONFIG_VAL(SYS_MALLOC_F_LEN)
 	/**
 	 * @malloc_base: base address of early malloc()
@@ -560,6 +564,13 @@  static_assert(sizeof(struct global_data) == GD_SIZE);
 #define gd_event_state()	NULL
 #endif
 
+#if CONFIG_IS_ENABLED(CMD_BDINFO_EXTRA)
+#define gd_malloc_start()		gd->malloc_start
+#define gd_set_malloc_start(_val)	gd->malloc_start = (_val)
+#else
+#define gd_malloc_start()	0
+#define gd_set_malloc_start(val)
+#endif
 /**
  * enum gd_flags - global data flags
  *