Skip to content

Commit

Permalink
[componets] fix when printf 0 addr by %p will return nil
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuzhuzhus authored and mysterywolf committed Dec 10, 2024
1 parent 876f2be commit e7b30ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
10 changes: 8 additions & 2 deletions components/drivers/ofw/fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, '/');
Expand Down Expand Up @@ -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");
}
}
}
Expand Down
18 changes: 12 additions & 6 deletions components/mm/mm_memblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit e7b30ed

Please sign in to comment.