From e7b30ed2ccf53c2da5128b33ab83ae0e3823fbff Mon Sep 17 00:00:00 2001 From: zhujiale <945386260@qq.com> Date: Tue, 3 Dec 2024 16:19:29 +0800 Subject: [PATCH] [componets] fix when printf 0 addr by %p will return nil --- components/drivers/ofw/fdt.c | 10 ++++++++-- components/mm/mm_memblock.c | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/components/drivers/ofw/fdt.c b/components/drivers/ofw/fdt.c index d1ee385f0f..cca4cdd20d 100644 --- a/components/drivers/ofw/fdt.c +++ b/components/drivers/ofw/fdt.c @@ -37,6 +37,12 @@ static rt_phandle _phandle_max; static rt_size_t _root_size_cells; static rt_size_t _root_addr_cells; +#ifdef ARCH_CPU_64BIT +#define MIN_BIT 16 +#else +#define MIN_BIT 8 +#endif + const char *rt_fdt_node_name(const char *full_name) { const char *node_name = strrchr(full_name, '/'); @@ -358,11 +364,11 @@ static rt_err_t fdt_scan_memory(void) if (!err) { - LOG_I("Memory node(%d) ranges: %p - %p%s", no, base, base + size, ""); + LOG_I("Memory node(%d) ranges: 0x%.*lx - 0x%.*lx%s", no, MIN_BIT, base, MIN_BIT, base + size, ""); } else { - LOG_W("Memory node(%d) ranges: %p - %p%s", no, base, base + size, " unable to record"); + LOG_W("Memory node(%d) ranges: 0x%.*lx - 0x%.*lx%s", no, MIN_BIT, base, MIN_BIT, base + size, " unable to record"); } } } diff --git a/components/mm/mm_memblock.c b/components/mm/mm_memblock.c index 77ef4ddbe0..d3d4e44f64 100644 --- a/components/mm/mm_memblock.c +++ b/components/mm/mm_memblock.c @@ -22,6 +22,12 @@ #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) +#ifdef ARCH_CPU_64BIT +#define MIN_BIT 16 +#else +#define MIN_BIT 8 +#endif + #ifndef RT_INIT_MEMORY_REGIONS #define RT_INIT_MEMORY_REGIONS 128 #endif @@ -155,16 +161,16 @@ static rt_err_t _memblock_add_range(struct rt_memblock *memblock, rt_err_t rt_memblock_add_memory(const char *name, rt_size_t start, rt_size_t end, mmblk_flag_t flags) { - LOG_D("add physical address range [%p-%p) with flag 0x%x" \ - " to overall memory regions\n", base, base + size, flag); + LOG_D("add physical address range [0x%.*lx-0x%.*lx) with flag 0x%x" \ + " to overall memory regions\n", MIN_BIT, base, MIN_BIT, base + size, flag); return _memblock_add_range(&mmblk_memory, name, start, end, flags); } rt_err_t rt_memblock_reserve_memory(const char *name, rt_size_t start, rt_size_t end, mmblk_flag_t flags) { - LOG_D("add physical address range [%p-%p) to reserved memory regions\n",\ - base, base + size); + LOG_D("add physical address range %s [0x%.*lx-0x%.*lx) to reserved memory regions\n", + name, MIN_BIT, start, MIN_BIT, end); return _memblock_add_range(&mmblk_reserved, name, start, end, flags); } @@ -347,14 +353,14 @@ void rt_memblock_setup_memory_environment(void) rt_slist_for_each_entry(iter, &(mmblk_memory.reg_list), node) { - LOG_I(" %-*.s [%p, %p]", RT_NAME_MAX, iter->memreg.name, iter->memreg.start, iter->memreg.end); + LOG_I(" %-*.s [0x%.*lx, 0x%.*lx]", RT_NAME_MAX, iter->memreg.name, MIN_BIT, iter->memreg.start, MIN_BIT, iter->memreg.end); } LOG_I("Reserved memory:"); rt_slist_for_each_entry(iter, &(mmblk_reserved.reg_list), node) { - LOG_I(" %-*.s [%p, %p]", RT_NAME_MAX, iter->memreg.name, iter->memreg.start, iter->memreg.end); + LOG_I(" %-*.s [0x%.*lx, 0x%.*lx]", RT_NAME_MAX, iter->memreg.name, MIN_BIT, iter->memreg.start, MIN_BIT, iter->memreg.end); if (iter->flags != MEMBLOCK_NONE) {