global_data: Reduce size of struct global_data
Subsystems (2)
v3 cover global_data: Reduce size of struct global_data
The global data structure has grown quite a lot over the years, being the best place to put an important pointer or something that must be accessed before and after relocation.
This series attempts to reduce the size a little, by moving some things out and shrinking and aligning some fields.
Some fields are needed during init but not afterwards. To deal with this a new 'boardf' structure is created, which sits on the stack and is only present during board_init_f(). It is possible that more fields could move to this struct, but for now only 4 are moved.
An assumption is made that an int is 32-bits wide on all architectures, which seems to be true, but maintainers should be able to confirm.
Mostly the code-size impact is neutral, but the patch
'Use less space for environment fields' does increase U-Boot's size by about 30 bytes on aarch64.
For firefly-rk3399 (64-bit) the size of global reduces from 456 to 368 bytes. For SPL it reduces from 416 to 272 bytes.
There are other things which could be attempted, for example:
- Using hlist instead of list for some lists
- Checking that only necessary fields are present in SPL
Changes in v3:
- Keep new_ptr as a ulong to avoid overflow
- Update the comment for malloc_ptr
Changes in v2:
- Rebase to -next
Simon Glass (35):
global_data: Move pci_clk to m68k and powerpc
x86: Drop use of global_data fb_base
video: Add a function to obtain the framebuffer address
video: mxc: Avoid setting global_data fb_base
video: mxs: Avoid setting global_data fb_base
arm: friendlyarm: Avoid accessing global_data fb_base
arm: ronetix: Avoid accessing global_data fb_base
zynqmp: Avoid setting the framebuffer address
video: Avoid setting global_data fb_base from SPL handoff
video: Avoid setting global_data fb_base in video setup
global_data: Drop fb_base
global_data: Convert have_console into a flag
global_data: Remove pci_ram_top
global_data: Drop global_data hose
global_data: Drop pci_bootdelay
global_data: Use less space for environment fields
board_f: Add a new struct to hold pre-relocation info
board_f: Move fdt_size to board
board_f: Move new_bootstage to boardf
board_f: Move new_bloblist to boardf
global_data: Drop spl_handoff
global_data: Collect common fields at the top
global_data: Reduce the size of bus_clk and mem_clk
global_data: Reduce the size of mon_len
global_data: log: Reorder and shrink fields
global_data: Reduce size of early-malloc vars
global_data: Move baud_rate field lower
global_data: Move env_addr field higher
global_data: Put phys_addr fields near the top
global_data: Move ulong fields together
global_data: Move pointer members together
global_data: Remove jump table in SPL
global_data: Remove environment members if not used
doc: Move generic-board documentation into rst
doc: Add some guidelines about global data
arch/arm/cpu/arm926ejs/mxs/spl_boot.c | 2 +-
arch/arm/lib/bdinfo.c | 2 +-
arch/arm/mach-exynos/spl_boot.c | 2 +-
arch/arm/mach-k3/common.c | 2 +-
arch/arm/mach-k3/r5/sysfw-loader.c | 2 +-
arch/arm/mach-tegra/board2.c | 4 -
arch/arm/mach-tegra/cboot.c | 4 -
arch/m68k/cpu/mcf5445x/cpu.c | 2 +-
arch/m68k/include/asm/global_data.h | 2 +
arch/m68k/lib/bdinfo.c | 2 +-
arch/mips/mach-ath79/ar934x/clk.c | 4 +-
arch/mips/mach-octeon/cpu.c | 2 +-
arch/powerpc/cpu/mpc83xx/pci.c | 4 +-
arch/powerpc/cpu/mpc83xx/speed.c | 2 +-
arch/powerpc/include/asm/global_data.h | 2 +
arch/x86/cpu/i386/cpu.c | 8 -
arch/x86/cpu/intel_common/cpu_from_spl.c | 4 +-
arch/x86/cpu/ivybridge/cpu.c | 5 -
arch/x86/lib/fsp/fsp_graphics.c | 1 -
arch/x86/lib/fsp2/fsp_dram.c | 4 +-
board/freescale/ls2080ardb/eth_ls2080rdb.c | 2 +-
board/friendlyarm/nanopi2/board.c | 9 +-
board/ronetix/pm9263/pm9263.c | 6 +-
board/siemens/common/board_am335x.c | 2 +-
cmd/bdinfo.c | 2 -
cmd/sb.c | 6 +-
common/board_f.c | 56 ++-
common/board_r.c | 2 +-
common/console.c | 17 +-
common/hwconfig.c | 8 +-
common/init/handoff.c | 12 +
common/malloc_simple.c | 4 +-
common/spl/spl.c | 6 +-
doc/develop/global_data.rst | 25 ++
.../historical/generic_board.rst} | 17 +-
doc/develop/historical/index.rst | 12 +
doc/develop/index.rst | 8 +
drivers/clk/mpc83xx_clk.c | 2 +-
drivers/clk/rockchip/clk_rk3399.c | 3 +-
drivers/video/imx/mxc_ipuv3_fb.c | 2 -
drivers/video/mxsfb.c | 1 -
drivers/video/video-uclass.c | 16 +-
drivers/video/zynqmp/zynqmp_dpsub.c | 3 +-
include/asm-generic/global_data.h | 351 ++++++++----------
include/board_f.h | 35 ++
include/env_default.h | 3 -
include/env_internal.h | 1 +
include/handoff.h | 7 +
include/video.h | 11 +
lib/asm-offsets.c | 2 +
test/cmd/bdinfo.c | 3 -
test/log/log_test.c | 6 +-
52 files changed, 371 insertions(+), 329 deletions(-)
rename doc/{README.generic-board => develop/historical/generic_board.rst} (96%)
create mode 100644 doc/develop/historical/index.rst
create mode 100644 include/board_f.hSignature · 1 line
2.34.1
PATCH v3 26/35 global_data: Reduce size of early-malloc vars
The early malloc region is normally quite small and is certainly less than 4GB, so use a 32-bit value for the limit and pointer. Update the comments for clarity while we are here.
---
Changes in v3:
- Keep new_ptr as a ulong to avoid overflow
- Update the comment for malloc_ptr
arch/arm/lib/bdinfo.c | 2 +- common/board_r.c | 2 +- common/malloc_simple.c | 4 ++-- common/spl/spl.c | 4 ++-- include/asm-generic/global_data.h | 8 ++++---- 5 files changed, 10 insertions(+), 10 deletions(-)
arch/arm/lib/bdinfo.c +1 -1
@@ -58,7 +58,7 @@ void arch_print_bdinfo(void)printf ("Board Type = %ld\n" , gd->board_type);#endif #if CONFIG_IS_ENABLED (SYS_MALLOC_F ) -printf ("Early malloc usage: %lx / %x\n" , gd->malloc_ptr, +printf ("Early malloc usage: %x / %x\n" , gd->malloc_ptr,CONFIG_VAL (SYS_MALLOC_F_LEN ));#endif }
common/board_r.c +1 -1
@@ -192,7 +192,7 @@ static int initr_malloc(void)ulong start;#if CONFIG_IS_ENABLED (SYS_MALLOC_F ) -debug ("Pre-reloc malloc() used %#lx bytes (%ld KB)\n" , gd->malloc_ptr, +debug ("Pre-reloc malloc() used %#x bytes (%d KB)\n" , gd->malloc_ptr, gd->malloc_ptr /1024 );#endif /* The malloc area is immediately below the monitor copy in DRAM */
common/malloc_simple.c +2 -2
@@ -23,7 +23,7 @@ static void *alloc_simple(size_t bytes, int align) addr =ALIGN (gd->malloc_base + gd->malloc_ptr, align); new_ptr = addr + bytes - gd->malloc_base; -log_debug ("size=%lx, ptr=%lx, limit=%lx: " , (ulong )bytes, new_ptr, +log_debug ("size=%lx, ptr=%lx, limit=%x: " , (ulong )bytes, new_ptr, gd->malloc_limit);if (new_ptr > gd->malloc_limit) {log_err ("alloc space exhausted\n" );
@@ -87,6 +87,6 @@ void free_simple(void *ptr)void malloc_simple_info (void ) { -log_info ("malloc_simple: %lx bytes used, %lx remain\n" , gd->malloc_ptr, +log_info ("malloc_simple: %x bytes used, %x remain\n" , gd->malloc_ptr,CONFIG_VAL (SYS_MALLOC_F_LEN ) - gd->malloc_ptr); }
common/spl/spl.c +2 -2
@@ -784,7 +784,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2) }if (CONFIG_IS_ENABLED (SYS_MALLOC_F ) && !IS_ENABLED (CONFIG_SPL_SYS_MALLOC_SIZE )) -debug ("SPL malloc() used 0x%lx bytes (%ld KB)\n" , +debug ("SPL malloc() used 0x%x bytes (%d KB)\n" ,gd_malloc_ptr (),gd_malloc_ptr () /1024 );bootstage_mark_name (get_bootstage_id (false),"end phase" );
@@ -903,7 +903,7 @@ ulong spl_relocate_stack_gd(void)#if defined(CONFIG_SPL_SYS_MALLOC_SIMPLE ) &&CONFIG_IS_ENABLED (SYS_MALLOC_F )if (CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN ) { -debug ("SPL malloc() before relocation used 0x%lx bytes (%ld KB)\n" , +debug ("SPL malloc() before relocation used 0x%x bytes (%d KB)\n" , gd->malloc_ptr, gd->malloc_ptr /1024 ); ptr -=CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN ; gd->malloc_base = ptr;
include/asm-generic/global_data.h +4 -4
@@ -299,13 +299,13 @@ struct global_data {*/ unsigned long malloc_base;/** -* @malloc_limit: limit address of early malloc() +* @malloc_limit: maximum size of early malloc() */ -unsigned long malloc_limit; +unsigned int malloc_limit;/** -* @malloc_ptr: current address of early malloc() +* @malloc_ptr: currently used bytes of early malloc() */ -unsigned long malloc_ptr; +unsigned int malloc_ptr;#endif #ifdef CONFIG_CONSOLE_RECORD /**
Signature · 1 line
2.34.1
Quoted 8 lines · Simon Glass
The global data structure has grown quite a lot over the years, being the best place to put an important pointer or something that must be accessed before and after relocation.
This series attempts to reduce the size a little, by moving some things out and shrinking and aligning some fields.
[...]
Applied to u-boot/next, thanks!
Signature · 1 line
Tom