bdinfo: Show the malloc base with the bdinfo command
authorSimon Glass <sjg@chromium.org>
Sun, 16 Jul 2023 03:38:53 +0000 (21:38 -0600)
committerBin Meng <bmeng@tinylab.org>
Mon, 17 Jul 2023 09:12:21 +0000 (17:12 +0800)
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>
Reviewed-by: Nikhil M Jain <n-jain1@ti.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Nikhil M Jain <n-jain1@ti.com>
cmd/bdinfo.c
common/board_r.c
include/asm-generic/global_data.h

index 44e6d6a..1fe13ca 100644 (file)
@@ -176,6 +176,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();
index d798c00..4aaa894 100644 (file)
@@ -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;
 }
index a1e1b9d..8fc205d 100644 (file)
@@ -301,6 +301,12 @@ struct global_data {
         * @timebase_l: low 32 bits of timer
         */
        unsigned int timebase_l;
+       /**
+        * @malloc_start: start of malloc() region
+        */
+#if CONFIG_IS_ENABLED(CMD_BDINFO_EXTRA)
+       unsigned long malloc_start;
+#endif
 #if CONFIG_VAL(SYS_MALLOC_F_LEN)
        /**
         * @malloc_base: base address of early malloc()
@@ -560,6 +566,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
  *