Skip to content

Commit e7b30ed

Browse files
zhuzhuzhusmysterywolf
authored andcommitted
[componets] fix when printf 0 addr by %p will return nil
1 parent 876f2be commit e7b30ed

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

components/drivers/ofw/fdt.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ static rt_phandle _phandle_max;
3737
static rt_size_t _root_size_cells;
3838
static rt_size_t _root_addr_cells;
3939

40+
#ifdef ARCH_CPU_64BIT
41+
#define MIN_BIT 16
42+
#else
43+
#define MIN_BIT 8
44+
#endif
45+
4046
const char *rt_fdt_node_name(const char *full_name)
4147
{
4248
const char *node_name = strrchr(full_name, '/');
@@ -358,11 +364,11 @@ static rt_err_t fdt_scan_memory(void)
358364

359365
if (!err)
360366
{
361-
LOG_I("Memory node(%d) ranges: %p - %p%s", no, base, base + size, "");
367+
LOG_I("Memory node(%d) ranges: 0x%.*lx - 0x%.*lx%s", no, MIN_BIT, base, MIN_BIT, base + size, "");
362368
}
363369
else
364370
{
365-
LOG_W("Memory node(%d) ranges: %p - %p%s", no, base, base + size, " unable to record");
371+
LOG_W("Memory node(%d) ranges: 0x%.*lx - 0x%.*lx%s", no, MIN_BIT, base, MIN_BIT, base + size, " unable to record");
366372
}
367373
}
368374
}

components/mm/mm_memblock.c

+12-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
#define MAX(a, b) ((a) > (b) ? (a) : (b))
2323
#define MIN(a, b) ((a) < (b) ? (a) : (b))
2424

25+
#ifdef ARCH_CPU_64BIT
26+
#define MIN_BIT 16
27+
#else
28+
#define MIN_BIT 8
29+
#endif
30+
2531
#ifndef RT_INIT_MEMORY_REGIONS
2632
#define RT_INIT_MEMORY_REGIONS 128
2733
#endif
@@ -155,16 +161,16 @@ static rt_err_t _memblock_add_range(struct rt_memblock *memblock,
155161

156162
rt_err_t rt_memblock_add_memory(const char *name, rt_size_t start, rt_size_t end, mmblk_flag_t flags)
157163
{
158-
LOG_D("add physical address range [%p-%p) with flag 0x%x" \
159-
" to overall memory regions\n", base, base + size, flag);
164+
LOG_D("add physical address range [0x%.*lx-0x%.*lx) with flag 0x%x" \
165+
" to overall memory regions\n", MIN_BIT, base, MIN_BIT, base + size, flag);
160166

161167
return _memblock_add_range(&mmblk_memory, name, start, end, flags);
162168
}
163169

164170
rt_err_t rt_memblock_reserve_memory(const char *name, rt_size_t start, rt_size_t end, mmblk_flag_t flags)
165171
{
166-
LOG_D("add physical address range [%p-%p) to reserved memory regions\n",\
167-
base, base + size);
172+
LOG_D("add physical address range %s [0x%.*lx-0x%.*lx) to reserved memory regions\n",
173+
name, MIN_BIT, start, MIN_BIT, end);
168174

169175
return _memblock_add_range(&mmblk_reserved, name, start, end, flags);
170176
}
@@ -347,14 +353,14 @@ void rt_memblock_setup_memory_environment(void)
347353

348354
rt_slist_for_each_entry(iter, &(mmblk_memory.reg_list), node)
349355
{
350-
LOG_I(" %-*.s [%p, %p]", RT_NAME_MAX, iter->memreg.name, iter->memreg.start, iter->memreg.end);
356+
LOG_I(" %-*.s [0x%.*lx, 0x%.*lx]", RT_NAME_MAX, iter->memreg.name, MIN_BIT, iter->memreg.start, MIN_BIT, iter->memreg.end);
351357
}
352358

353359
LOG_I("Reserved memory:");
354360

355361
rt_slist_for_each_entry(iter, &(mmblk_reserved.reg_list), node)
356362
{
357-
LOG_I(" %-*.s [%p, %p]", RT_NAME_MAX, iter->memreg.name, iter->memreg.start, iter->memreg.end);
363+
LOG_I(" %-*.s [0x%.*lx, 0x%.*lx]", RT_NAME_MAX, iter->memreg.name, MIN_BIT, iter->memreg.start, MIN_BIT, iter->memreg.end);
358364

359365
if (iter->flags != MEMBLOCK_NONE)
360366
{

0 commit comments

Comments
 (0)