spl: full-featured heap cleanups
v2 cover spl: full-featured heap cleanups
Some platforms cannot use simple malloc even in very early stages, e.g. when using FAT before DRAM is available. Such platforms currently often use non-Kconfig defines to initialize full malloc and rely on simple heap before that.
This series makes some adjustments to ensure SPL behaves the same with simple or full malloc: when CONFIG_SPL_SYS_MALLOC_F_LEN is != 0, both heap types can be used (by changing CONFIG_SPL_SYS_MALLOC_SIMPLE), without manually supplying an address range for the full heap.
Changes in v2:
- make CONFIG_SPL_CLEAR_BSS_F depend on ARM for now
- add CONFIG_SPL_CLEAR_BSS_F implementation for arm64 also
Simon Goldschmidt (6):
spl: add Kconfig option to clear bss early
spl: arm: implement SPL_CLEAR_BSS_F
dlmalloc: fix malloc range at end of ram
dlmalloc: be compatible to tiny printf
spl: support using full malloc with SYS_MALLOC_F_LEN
arm: socfpga: a10: move SPL stack size to Kconfig
arch/arm/lib/crt0.S | 22 ++++++++++++++++++++++ arch/arm/lib/crt0_64.S | 14 ++++++++++++++ common/dlmalloc.c | 6 +++++- common/spl/Kconfig | 12 ++++++++++++ common/spl/spl.c | 5 +++++ configs/socfpga_arria10_defconfig | 1 + include/configs/socfpga_common.h | 14 -------------- 7 files changed, 59 insertions(+), 15 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 1/6 spl: add Kconfig option to clear bss early
This introduces a new Kconfig option SPL_CLEAR_BSS_F. If enabled, it clears the bss before calling board_init_f() instead of clearing it before calling board_init_r().
This also ensures that variables placed in BSS can be shared between board_init_f() and board_init_r() in SPL.
Make the new option depend on ARM for now until more implementations follow.
---
Changes in v2:
- make CONFIG_SPL_CLEAR_BSS_F depend on ARM for now
common/spl/Kconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+)
common/spl/Kconfig +12 -0
@@ -156,6 +156,18 @@ config SPL_STACK_R_MALLOC_SIMPLE_LEN to give board_init_r() a larger heap then the initial heap in SRAM which is limited to SYS_MALLOC_F_LEN bytes. +config SPL_CLEAR_BSS_F + bool "Clear BSS section before calling board_init_f" + depends on ARM + help + The BSS section is initialized to zero. In SPL, this is normally done + before calling board_init_r(). + For platforms using BSS in board_init_f() already, enable this to + clear the BSS section before calling board_init_f() instead of + clearing it before calling board_init_r(). This also ensures that + variables placed in BSS can be shared between board_init_f() and + board_init_r(). + config SPL_SEPARATE_BSS bool "BSS section is in a different memory region from text" help
Signature · 1 line
2.17.1
PATCH v2 1/6 spl: add Kconfig option to clear bss early
Hi,
Quoted 10 lines · Simon Goldschmidt
This introduces a new
KconfigoptionSPL_CLEAR_BSS_F. If enabled, it clears the bss before callingboard_init_f()instead of clearing it before callingboard_init_r().This also ensures that variables placed in BSS can be shared between
board_init_f()andboard_init_r()in SPL.Make the new option depend on ARM for now until more implementations follow.
Quoted 8 lines
Signed-off-by Simon Goldschmidt <[email protected]>---
Changes in v2:
- makeCONFIG_SPL_CLEAR_BSS_Fdepend on ARM for nowcommon/spl/Kconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+)
The current restriction is that you are not allowed to use BSS before board_init_r().
Can you please add a motivation to change this?
Regards,
SImon
PATCH v2 1/6 spl: add Kconfig option to clear bss early
Hi Simon,
Quoted 18 lines · Simon Glass
Hi,
Quoted 13 lines · Simon Goldschmidt
This introduces a new
KconfigoptionSPL_CLEAR_BSS_F. If enabled, it clears the bss before callingboard_init_f()instead of clearing it before callingboard_init_r().This also ensures that variables placed in BSS can be shared between
board_init_f()andboard_init_r()in SPL.Make the new option depend on ARM for now until more implementations follow.
Signed-off-by Simon Goldschmidt <[email protected]>---
Quoted 8 lines
Quoted 5 lines
Changes in v2:
- makeCONFIG_SPL_CLEAR_BSS_Fdepend on ARM for nowcommon/spl/Kconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+)The current restriction is that you are not allowed to use BSS before
board_init_r().
I understood that, but I did not understand why. This is perfectly valid for U-Boot proper or for SPL if SPL_SEPARATE_BSS is used and bss is in SDRAM. However, the latter seems to be seldom used and for the "default" case where bss is in SRAM, it's available right from the start and clearing it after board_init_f() has been run seems quite unuseful and unexpected.
Quoted 2 lines
Can you please add a motivation to change this?
The motivation is to allow SPL to use full malloc in board_init_f() like required
by socfpga_arria10 (see patch 5/6). Without this, the malloc pointers get overwritten after board_init_f() and further calls to malloc() fail.
Regards,
Simon
PATCH v2 1/6 spl: add Kconfig option to clear bss early
Hi Simon,
Quoted 28 lines · Simon Goldschmidt
Hi Simon,
Quoted 24 lines · Simon Glass
Hi,
Quoted 18 lines · Simon Goldschmidt
This introduces a new
KconfigoptionSPL_CLEAR_BSS_F. If enabled, it clears the bss before callingboard_init_f()instead of clearing it before callingboard_init_r().This also ensures that variables placed in BSS can be shared between
board_init_f()andboard_init_r()in SPL.Make the new option depend on ARM for now until more implementations follow.
Signed-off-by Simon Goldschmidt <[email protected]>---
Changes in v2:
- makeCONFIG_SPL_CLEAR_BSS_Fdepend on ARM for nowcommon/spl/Kconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+)
Quoted 8 lines
Quoted 2 lines
The current restriction is that you are not allowed to use BSS before
board_init_r().I understood that, but I did not understand why. This is perfectly valid for U-Boot proper or for SPL if
SPL_SEPARATE_BSSis used and bss is in SDRAM. However, the latter seems to be seldom used and for the "default" case where bss is in SRAM, it's available right from the start and clearing it afterboard_init_f()has been run seems quite unuseful and unexpected.
Well this is the API. We have to have some order and conventions otherwise things just decend into chaos, with so many options that it all becomes bewildering.
See 'Board Initialisation Flow:' in the README.
Quoted 8 lines
Quoted 3 lines
Can you please add a motivation to change this?
The motivation is to allow SPL to use full malloc in
board_init_f()like required
bysocfpga_arria10(see patch 5/6). Without this, the malloc pointers get overwritten afterboard_init_f()and further calls tomalloc()fail.
Can you call spl_early_init() instead?
Regards,
Simon
PATCH v2 2/6 spl: arm: implement SPL_CLEAR_BSS_F
In reply to Simon GoldschmidtThis implements the new option to clear BSS early in SPL for standard arm and arm64 crt0.
BSS is cleared before calling board_init_f() and thus not cleared before calling board_init_r() as it is not relocated in SPL.
---
Changes in v2:
- add CONFIG_SPL_CLEAR_BSS_F implementation for arm64 also
arch/arm/lib/crt0.S | 22 ++++++++++++++++++++++ arch/arm/lib/crt0_64.S | 14 ++++++++++++++ 2 files changed, 36 insertions(+)
arch/arm/lib/crt0.S +22 -0
@@ -80,6 +80,26 @@ ENTRY(_main) mov r9, r0 bl board_init_f_init_reserve +#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_CLEAR_BSS_F) + ldr r0, =__bss_start + +#ifdef CONFIG_USE_ARCH_MEMSET + ldr r3, =__bss_end + mov r1, #0x00000000 /* prepare zero to clear BSS */ + + subs r2, r3, r0 /* r2 = memset len */ + bl memset +#else + ldr r1, =__bss_end + mov r2, #0x00000000 /* prepare zero to clear BSS */ + +clbss_l:cmp r0, r1 /* while not at end of BSS */ + strlo r2, [r0] /* clear 32-bit BSS word */ + addlo r0, r0, #4 /* move to next */ + blo clbss_l +#endif +#endif + mov r0, #0 bl board_init_f
@@ -124,6 +144,7 @@ here: movne sp, r0 movne r9, r0 # endif +#if !defined(CONFIG_SPL_BUILD) || !defined(CONFIG_SPL_CLEAR_BSS_F) ldr r0, =__bss_start /* this is auto-relocated! */ #ifdef CONFIG_USE_ARCH_MEMSET
@@ -141,6 +162,7 @@ clbss_l:cmp r0, r1 /* while not at end of BSS */ addlo r0, r0, #4 /* move to next */ blo clbss_l #endif +#endif #if ! defined(CONFIG_SPL_BUILD) bl coloured_LED_init
arch/arm/lib/crt0_64.S +14 -0
@@ -86,6 +86,18 @@ ENTRY(_main) mov x18, x0 bl board_init_f_init_reserve +#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_CLEAR_BSS_F) +/* + * Clear BSS section + */ + ldr x0, =__bss_start + ldr x1, =__bss_end +clear_loop: + str xzr, [x0], #8 + cmp x0, x1 + b.lo clear_loop +#endif + mov x0, #0 bl board_init_f
@@ -136,6 +148,7 @@ relocation_return: mov sp, x0 #endif +#if !defined(CONFIG_SPL_BUILD) || !defined(CONFIG_SPL_CLEAR_BSS_F) /* * Clear BSS section */
@@ -145,6 +158,7 @@ clear_loop: str xzr, [x0], #8 cmp x0, x1 b.lo clear_loop +#endif /* call board_init_r(gd_t *id, ulong dest_addr) */ mov x0, x18 /* gd_t */
Signature · 1 line
2.17.1
PATCH v2 3/6 dlmalloc: fix malloc range at end of ram
In reply to Simon GoldschmidtIf the malloc range passed to mem_malloc_init() is at the end of address range and 'start + size' overflows to 0, following allocations fail as mem_malloc_end is zero (which looks like uninitialized).
Fix this by subtracting 1 of 'start + size' overflows to zero.
---
Changes in v2: None
common/dlmalloc.c | 4 ++++ 1 file changed, 4 insertions(+)
common/dlmalloc.c +4 -0
@@ -603,6 +603,10 @@ void mem_malloc_init(ulong start, ulong size) mem_malloc_start = start; mem_malloc_end = start + size; mem_malloc_brk = start; +if (start && size && !mem_malloc_end) { +/* overflow: malloc area is at end of address range */ + mem_malloc_end--; + }debug ("using memory %#lx-%#lx for malloc()\n" , mem_malloc_start, mem_malloc_end);
Signature · 1 line
2.17.1
PATCH v2 4/6 dlmalloc: be compatible to tiny printf
In reply to Simon GoldschmidtConvert debug output from '%#lx' to '0x%lx' to be compatible with tiny printf used in SPL.
---
Changes in v2: None
common/dlmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
common/dlmalloc.c +1 -1
@@ -608,7 +608,7 @@ void mem_malloc_init(ulong start, ulong size) mem_malloc_end--; } -debug ("using memory %#lx-%#lx for malloc()\n" , mem_malloc_start, +debug ("using memory 0x%lx-0x%lx for malloc()\n" , mem_malloc_start, mem_malloc_end);#ifdef CONFIG_SYS_MALLOC_CLEAR_ON_INIT memset ((void *)mem_malloc_start,0x0 , size);
Signature · 1 line
2.17.1
PATCH v2 5/6 spl: support using full malloc with SYS_MALLOC_F_LEN
In reply to Simon GoldschmidtSome platforms (like socfpga A10) need a big hep before SDRAM is available (e.g. because FAT is used). For such platforms, simple_malloc is often not a good option as it does not support freeing memory. These platforms often use the non-Kconfig defines CONFIG_SYS_SPL_MALLOC_START (and its SIZE).
This patch allows enabling CONFIG_SPL_SYS_MALLOC_F_LEN while leaving CONFIG_SPL_SYS_MALLOC_SIMPLE disabled. In this case, the full malloc heap is made available as early as the simple_malloc heap would be normally.
This way, platforms can drop the non-Kconfig options to set up the full heap and rely on the same automatically calculated heap allocation used for simple heap.
---
Changes in v2: None
common/spl/spl.c | 5 +++++ 1 file changed, 5 insertions(+)
common/spl/spl.c +5 -0
@@ -383,8 +383,13 @@ static int spl_common_init(bool setup_malloc)#ifdef CONFIG_MALLOC_F_ADDR gd->malloc_base =CONFIG_MALLOC_F_ADDR ;#endif +#if CONFIG_IS_ENABLED (SYS_MALLOC_SIMPLE ) gd->malloc_limit =CONFIG_VAL (SYS_MALLOC_F_LEN ); gd->malloc_ptr =0 ; +#else +mem_malloc_init (gd->malloc_base,CONFIG_VAL (SYS_MALLOC_F_LEN )); + gd->flags |=GD_FLG_FULL_MALLOC_INIT ; +#endif }#endif ret =bootstage_init (true);
Signature · 1 line
2.17.1
PATCH v2 5/6 spl: support using full malloc with SYS_MALLOC_F_LEN
Hi,
Quoted 2 lines · Simon Goldschmidt
Some platforms (like socfpga A10) need a big hep before SDRAM is available
heap
Quoted 2 lines
(e.g. because FAT is used). For such platforms,
simple_mallocis often not a good option as it does not support freeing memory. These platforms often
Does the lack of free() actually cause any problems on this platform?
Quoted 5 lines
use the non-Kconfig defines
CONFIG_SYS_SPL_MALLOC_START(and its SIZE).This patch allows enabling
CONFIG_SPL_SYS_MALLOC_F_LENwhile leavingCONFIG_SPL_SYS_MALLOC_SIMPLEdisabled. In this case, the full malloc heap is made available as early as thesimple_mallocheap would be normally.
Why not init SDRAM before using FAT?
Quoted 5 lines
This way, platforms can drop the non-Kconfig options to set up the full heap and rely on the same automatically calculated heap allocation used for simple heap.
Quoted 7 lines
Signed-off-by Simon Goldschmidt <[email protected]>---
Changes in v2: None
common/spl/spl.c | 5 +++++ 1 file changed, 5 insertions(+)
Regards,
Simon
PATCH v2 5/6 spl: support using full malloc with SYS_MALLOC_F_LEN
Hi Simon,
Quoted 6 lines · Simon Glass
Hi,
Quoted 1 line · Simon Goldschmidt
Quoted 8 lines
Quoted 1 line
Some platforms (like socfpga A10) need a big hep before SDRAM is available
heap
Quoted 2 lines
(e.g. because FAT is used). For such platforms,
simple_mallocis often not a good option as it does not support freeing memory. These platforms oftenDoes the lack of
free()actually cause any problems on this platform?
Yes. Without free(), the available SRAM is not enough to provide the heap required.
Quoted 8 lines
Quoted 6 lines
use the non-Kconfig defines
CONFIG_SYS_SPL_MALLOC_START(and its SIZE).This patch allows enabling
CONFIG_SPL_SYS_MALLOC_F_LENwhile leavingCONFIG_SPL_SYS_MALLOC_SIMPLEdisabled. In this case, the full malloc heap is made available as early as thesimple_mallocheap would be normally.Why not init SDRAM before using FAT?
Because the SDRAM controller is not available yet. As I understood, his is an FPGA
platform where the initial FPGA image has to be loaded to get SDRAM running.
If that initial FPGA image is to be loaded from FAT, you just need a rather big heap.
Currently, the non-Kconfig CONFIG_SYS_SPL_MALLOC_START is used. I don't think using this one is a good approach as it is yet another way of ad-hoc memory
allocation plus it's quite confusing to have full and simple malloc use a different way
to allocate the heap region.
Regards,
Simon
Quoted 16 lines
Quoted 6 lines
This way, platforms can drop the non-Kconfig options to set up the full heap and rely on the same automatically calculated heap allocation used for simple heap.
Quoted 7 lines
Signed-off-by Simon Goldschmidt <[email protected]>---
Changes in v2: None
common/spl/spl.c | 5 +++++ 1 file changed, 5 insertions(+)Regards,
Simon
PATCH v2 6/6 arm: socfpga: a10: move SPL stack size to Kconfig
In reply to Simon GoldschmidtInstead of fixing the SPL stack to 64 KiB in the board config header via CONFIG_SYS_SPL_MALLOC_SIZE, let's just use CONFIG_SPL_SYS_MALLOC_F_LEN in the defconfig.
This also has the advandage that it removes sub-mach specific ifdefs in socfpga_common.h.
---
Changes in v2: None
configs/socfpga_arria10_defconfig | 1 + include/configs/socfpga_common.h | 14 -------------- 2 files changed, 1 insertion(+), 14 deletions(-)
configs/socfpga_arria10_defconfig +1 -0
@@ -2,6 +2,7 @@ CONFIG_ARM=y CONFIG_ARCH_SOCFPGA=y CONFIG_SYS_TEXT_BASE=0x01000040 CONFIG_SYS_MALLOC_F_LEN=0x2000 +CONFIG_SPL_SYS_MALLOC_F_LEN=0x10000 CONFIG_TARGET_SOCFPGA_ARRIA10_SOCDK=y CONFIG_SPL=y CONFIG_IDENT_STRING="socfpga_arria10"
include/configs/socfpga_common.h +0 -14
@@ -251,16 +251,6 @@ unsigned int cm_get_qspi_controller_clk_hz(void);#define CONFIG_SPL_TEXT_BASE CONFIG_SYS_INIT_RAM_ADDR#define CONFIG_SPL_MAX_SIZE CONFIG_SYS_INIT_RAM_SIZE -#if defined(CONFIG_TARGET_SOCFPGA_ARRIA10 ) -/* SPL memory allocation configuration, this is for FAT implementation */ -#ifndef CONFIG_SYS_SPL_MALLOC_START -#define CONFIG_SYS_SPL_MALLOC_SIZE 0x00010000 -#define CONFIG_SYS_SPL_MALLOC_START (CONFIG_SYS_INIT_RAM_SIZE - \ - CONFIG_SYS_SPL_MALLOC_SIZE + \ - CONFIG_SYS_INIT_RAM_ADDR) -#endif -#endif -/* SPL SDMMC boot support */ #ifdef CONFIG_SPL_MMC_SUPPORT #if defined(CONFIG_SPL_FS_FAT ) || defined(CONFIG_SPL_FS_EXT4 )
@@ -294,11 +284,7 @@ unsigned int cm_get_qspi_controller_clk_hz(void);/* * Stack setup */ -#if defined(CONFIG_TARGET_SOCFPGA_GEN5 )#define CONFIG_SPL_STACK CONFIG_SYS_INIT_SP_ADDR -#elif defined(CONFIG_TARGET_SOCFPGA_ARRIA10 ) -#define CONFIG_SPL_STACK CONFIG_SYS_SPL_MALLOC_START -#endif /* Extra Environment */ #ifndef CONFIG_SPL_BUILD
Signature · 1 line
2.17.1
Chee
PATCH v2 6/6 arm: socfpga: a10: move SPL stack size to Kconfig
Quoted 6 lines · Simon Goldschmidt
Instead of fixing the SPL stack to 64 KiB in the board config header via
CONFIG_SYS_SPL_MALLOC_SIZE, let's just useCONFIG_SPL_SYS_MALLOC_F_LEN
in the defconfig.
Quoted 6 lines
This also has the advandage that it removes sub-mach specific ifdefs in
socfpga_common.h.Signed-off-by Simon Goldschmidt <[email protected]>---
Hi Simon,
I found the culprit in patch[5], you cannot put mem_malloc_init in spl_common_init function because spl_common_init would be called in board_init_f, then board_init_f would call mem_malloc_init, mem_malloc_init would store start and end addresses to few global variables such as mem_malloc_start, mem_malloc_end and mem_malloc_brk. By that time, global variables are unavailable yet.
Thanks.
TF
Quoted 59 lines
Changes in v2: None
configs/socfpga_arria10_defconfig | 1 + include/configs/socfpga_common.h | 14 --------------
2 files changed, 1 insertion(+), 14 deletions(-)configs/socfpga_arria10_defconfig +0
-0@@ -2,6 +2,7 @@ CONFIG_ARM=yCONFIG_ARCH_SOCFPGA=y
CONFIG_SYS_TEXT_BASE=0x01000040
CONFIG_SYS_MALLOC_F_LEN=0x2000
+CONFIG_SPL_SYS_MALLOC_F_LEN=0x10000
CONFIG_TARGET_SOCFPGA_ARRIA10_SOCDK=y
CONFIG_SPL=y
CONFIG_IDENT_STRING="socfpga_arria10"include/configs/socfpga_common.h +0
-0@@ -251,16 +251,6 @@ unsigned intcm_get_qspi_controller_clk_hz (void); #define CONFIG_SPL_TEXT_BASE CONFIG_SYS_INIT_RAM_ADDR #define CONFIG_SPL_MAX_SIZE CONFIG_SYS_INIT_RAM_SIZEinclude/configs/socfpga_common.h +0
-2-#if defined(CONFIG_TARGET_SOCFPGA_ARRIA10 ) -/* SPL memory allocation configuration, this is for FAT implementation */
include/configs/socfpga_common.h +1
-9-#ifndef CONFIG_SYS_SPL_MALLOC_START -#define CONFIG_SYS_SPL_MALLOC_SIZE 0x00010000 -#define CONFIG_SYS_SPL_MALLOC_START (CONFIG_SYS_INIT_RAM_SIZE - \ - CONFIG_SYS_SPL_MALLOC_SIZE + \ - CONFIG_SYS_INIT_RAM_ADDR) -#endif -#endif -/* SPL SDMMC boot support */
#ifdefCONFIG_SPL_MMC_SUPPORT
#ifdefined(CONFIG_SPL_FS_FAT)||defined(CONFIG_SPL_FS_EXT4)include/configs/socfpga_common.h +0
-4@@ -294,11 +284,7 @@ unsigned intcm_get_qspi_controller_clk_hz (void); /* * Stack setup */ -#if defined(CONFIG_TARGET_SOCFPGA_GEN5 ) #define CONFIG_SPL_STACK CONFIG_SYS_INIT_SP_ADDR -#elif defined(CONFIG_TARGET_SOCFPGA_ARRIA10 ) -#define CONFIG_SPL_STACK CONFIG_SYS_SPL_MALLOC_START -#endif
/* Extra Environment */
#ifndefCONFIG_SPL_BUILD
PATCH v2 6/6 arm: socfpga: a10: move SPL stack size to Kconfig
Am 19.03.2019 um 17:19 schrieb Chee, Tien Fong:
Quoted 13 lines · Simon Goldschmidt
Quoted 6 lines
Instead of fixing the SPL stack to 64 KiB in the board config header via
CONFIG_SYS_SPL_MALLOC_SIZE, let's just useCONFIG_SPL_SYS_MALLOC_F_LEN
in the defconfig.Quoted 6 lines
This also has the advandage that it removes sub-mach specific ifdefs in
socfpga_common.h.Signed-off-by Simon Goldschmidt <[email protected]>---
Quoted 8 lines
Hi Simon,
I found the culprit in patch[5], you cannot put
mem_malloc_initinspl_common_initfunction becausespl_common_initwould be called inboard_init_f, thenboard_init_fwould callmem_malloc_init,mem_malloc_initwould store start and end addresses to few global variables such asmem_malloc_start,mem_malloc_endandmem_malloc_brk. By that time, global variables are unavailable yet.
Thanks for testing. Patch 2/6 should make sure global variables are available in board_init_f by clearing bss *before* calling that function, not *after* calling it. Because technicaly, global variables are always available for a10-SPL as they are located in SRAM. They only got cleared after board_init_f...
Which gets me to my error: I forgot to enable the newly added CONFIG_SPL_CLEAR_BSS_F in this patch. Could you probably try again with CONFIG_SPL_CLEAR_BSS_F enabled? That would be great!
Regards,
Simon
Quoted 63 lines
Thanks.
TFQuoted 59 lines
Changes in v2: None
configs/socfpga_arria10_defconfig | 1 + include/configs/socfpga_common.h | 14 -------------- 2 files changed, 1 insertion(+), 14 deletions(-)configs/socfpga_arria10_defconfig +1
-0@@ -2,6 +2,7 @@ CONFIG_ARM=y CONFIG_ARCH_SOCFPGA=y CONFIG_SYS_TEXT_BASE=0x01000040 CONFIG_SYS_MALLOC_F_LEN=0x2000 +CONFIG_SPL_SYS_MALLOC_F_LEN=0x10000 CONFIG_TARGET_SOCFPGA_ARRIA10_SOCDK=y CONFIG_SPL=y CONFIG_IDENT_STRING="socfpga_arria10"include/configs/socfpga_common.h +0
-2@@ -251,16 +251,6 @@ unsigned intcm_get_qspi_controller_clk_hz (void); #define CONFIG_SPL_TEXT_BASE CONFIG_SYS_INIT_RAM_ADDR #define CONFIG_SPL_MAX_SIZE CONFIG_SYS_INIT_RAM_SIZE -#if defined(CONFIG_TARGET_SOCFPGA_ARRIA10 ) -/* SPL memory allocation configuration, this is for FAT implementation */
include/configs/socfpga_common.h +1
-13-#ifndef CONFIG_SYS_SPL_MALLOC_START -#define CONFIG_SYS_SPL_MALLOC_SIZE 0x00010000 -#define CONFIG_SYS_SPL_MALLOC_START (CONFIG_SYS_INIT_RAM_SIZE - \ - CONFIG_SYS_SPL_MALLOC_SIZE + \ - CONFIG_SYS_INIT_RAM_ADDR) -#endif -#endif - /* SPL SDMMC boot support */ #ifdef CONFIG_SPL_MMC_SUPPORT #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)@@ -294,11 +284,7 @@ unsigned intcm_get_qspi_controller_clk_hz (void); /* * Stack setup */ -#if defined(CONFIG_TARGET_SOCFPGA_GEN5 ) #define CONFIG_SPL_STACK CONFIG_SYS_INIT_SP_ADDR -#elif defined(CONFIG_TARGET_SOCFPGA_ARRIA10 ) -#define CONFIG_SPL_STACK CONFIG_SYS_SPL_MALLOC_START -#endif /* Extra Environment */#ifndef
CONFIG_SPL_BUILD
Chee
PATCH v2 6/6 arm: socfpga: a10: move SPL stack size to Kconfig
Quoted 28 lines · Simon Goldschmidt
Am 19.03.2019 um 17:19 schrieb Chee, Tien Fong:
Quoted 20 lines · Simon Goldschmidt
Quoted 8 lines
Instead of fixing the SPL stack to 64 KiB in the board config header
viaCONFIG_SYS_SPL_MALLOC_SIZE, let's just useCONFIG_SPL_SYS_MALLOC_F_LEN
in the defconfig.Quoted 8 lines
This also has the advandage that it removes sub-mach specific ifdefs
insocfpga_common.h.Signed-off-by Simon Goldschmidt <[email protected]Quoted 1 line
---
Hi Simon,
Quoted 7 lines
I found the culprit in patch[5], you cannot put
mem_malloc_initinspl_common_initfunction becausespl_common_initwould be called inboard_init_f, thenboard_init_fwould callmem_malloc_init,mem_malloc_initwould store start and end addresses to few global variables such asmem_malloc_start,mem_malloc_endandmem_malloc_brk.
By that time, global variables are unavailable yet.
Quoted 7 lines
Thanks for testing. Patch 2/6 should make sure global variables are available in
board_init_fby clearing bss *before* calling that function, not *after* calling it. Because technicaly, global variables
are always available for a10-SPL as they are located in SRAM. They only
got cleared afterboard_init_f...
Yes, you are right, memset would clear .BSS after mem_malloc_init.
Quoted 5 lines
Which gets me to my error: I forgot to enable the newly added
CONFIG_SPL_CLEAR_BSS_Fin this patch. Could you probably try again withCONFIG_SPL_CLEAR_BSS_Fenabled? That would be great!
Tested, passing. May be force enabling it or compile error if full malloc is used?
Thanks.
TF.
Quoted 75 lines
Regards,
SimonQuoted 71 lines
Thanks.
TFQuoted 66 lines
Changes in v2: None
configs/socfpga_arria10_defconfig | 1 + include/configs/socfpga_common.h | 14 --------------
2 files changed, 1 insertion(+), 14 deletions(-)configs/socfpga_arria10_defconfig +0
-0@@ -2,6 +2,7 @@ CONFIG_ARM=yCONFIG_ARCH_SOCFPGA=y
CONFIG_SYS_TEXT_BASE=0x01000040
CONFIG_SYS_MALLOC_F_LEN=0x2000
+CONFIG_SPL_SYS_MALLOC_F_LEN=0x10000
CONFIG_TARGET_SOCFPGA_ARRIA10_SOCDK=y
CONFIG_SPL=y
CONFIG_IDENT_STRING="socfpga_arria10"include/configs/socfpga_common.h +0
-0@@ -251,16 +251,6 @@ unsigned intcm_get_qspi_controller_clk_hz (void); #define CONFIG_SPL_TEXT_BASE CONFIG_SYS_INIT_RAM
_ADDR
#defineCONFIG_SPL_MAX_SIZECONFIG_SYS_INIT_RAM_
SIZEinclude/configs/socfpga_common.h +0
-2-#if defined(CONFIG_TARGET_SOCFPGA_ARRIA10 ) -/* SPL memory allocation configuration, this is for FAT implementation */
include/configs/socfpga_common.h +0
-3-#ifndef CONFIG_SYS_SPL_MALLOC_START -#define CONFIG_SYS_SPL_MALLOC_SIZE 0x00010000 -#define CONFIG_SYS_SPL_MALLOC_START (CONFIG_SYS_INIT_RAM_SIZE
- \include/configs/socfpga_common.h +0
-1- CONFIG_SYS_SPL_MALLOC_SIZE
+ \include/configs/socfpga_common.h +0
-1- CONFIG_SYS_INIT_RAM_ADDR)
include/configs/socfpga_common.h +0
-3-#endif -#endif -/* SPL SDMMC boot support */
#ifdefCONFIG_SPL_MMC_SUPPORT
#ifdefined(CONFIG_SPL_FS_FAT)||defined(CONFIG_SPL_FS_EXT4)include/configs/socfpga_common.h +0
-3@@ -294,11 +284,7 @@ unsigned intcm_get_qspi_controller_clk_hz (void); /* * Stack setup */ -#if defined(CONFIG_TARGET_SOCFPGA_GEN5 ) #define CONFIG_SPL_STACK CONFIG_SYS_INIT_SP_ADDR -#elif defined(CONFIG_TARGET_SOCFPGA_ARRIA10 ) -#define CONFIG_SPL_STACK CONFIG_SYS_SPL_MALLOC_START
-#endif
/* Extra Environment */
#ifndefCONFIG_SPL_BUILD
PATCH v2 6/6 arm: socfpga: a10: move SPL stack size to Kconfig
Chee, Tien Fong <[email protected]> schrieb am Mi., 20. März 2019, 05:15:
Quoted 36 lines · Simon Goldschmidt
Quoted 28 lines
Am 19.03.2019 um 17:19 schrieb Chee, Tien Fong:
Quoted 20 lines · Simon Goldschmidt
Quoted 8 lines
Instead of fixing the SPL stack to 64 KiB in the board config header
viaCONFIG_SYS_SPL_MALLOC_SIZE, let's just useCONFIG_SPL_SYS_MALLOC_F_LEN
in the defconfig.Quoted 8 lines
This also has the advandage that it removes sub-mach specific ifdefs
insocfpga_common.h.Signed-off-by Simon Goldschmidt <[email protected]Quoted 1 line
---
Hi Simon,
Quoted 7 lines
I found the culprit in patch[5], you cannot put
mem_malloc_initinspl_common_initfunction becausespl_common_initwould be called inboard_init_f, thenboard_init_fwould callmem_malloc_init,mem_malloc_initwould store start and end addresses to few global variables such asmem_malloc_start,mem_malloc_endandmem_malloc_brk.
By that time, global variables are unavailable yet.Quoted 7 lines
Thanks for testing. Patch 2/6 should make sure global variables are available in
board_init_fby clearing bss *before* calling that function, not *after* calling it. Because technicaly, global variables
are always available for a10-SPL as they are located in SRAM. They only
got cleared afterboard_init_f...
Quoted 9 lines
Yes, you are right, memset would clear .BSS after
mem_malloc_init.Quoted 5 lines
Which gets me to my error: I forgot to enable the newly added
CONFIG_SPL_CLEAR_BSS_Fin this patch. Could you probably try again withCONFIG_SPL_CLEAR_BSS_Fenabled? That would be great!Tested, passing. May be force enabling it or compile error if full malloc is used?
Ok, thanks for testing again! I'll make up some kind of check for v3.
Regards,
Simon
Quoted 77 lines
Thanks.
TF.Quoted 75 lines
Regards,
SimonQuoted 71 lines
Thanks.
TFQuoted 66 lines
Changes in v2: None
configs/socfpga_arria10_defconfig | 1 + include/configs/socfpga_common.h | 14 -------------- 2 files changed, 1 insertion(+), 14 deletions(-)configs/socfpga_arria10_defconfig +1
-0@@ -2,6 +2,7 @@ CONFIG_ARM=y CONFIG_ARCH_SOCFPGA=y CONFIG_SYS_TEXT_BASE=0x01000040 CONFIG_SYS_MALLOC_F_LEN=0x2000 +CONFIG_SPL_SYS_MALLOC_F_LEN=0x10000 CONFIG_TARGET_SOCFPGA_ARRIA10_SOCDK=y CONFIG_SPL=y CONFIG_IDENT_STRING="socfpga_arria10"include/configs/socfpga_common.h +0
-0@@ -251,16 +251,6 @@ unsigned intcm_get_qspi_controller_clk_hz (void);#define CONFIG_SPL_TEXT_BASE CONFIG_SYS_INIT_RAM
_ADDR
#defineCONFIG_SPL_MAX_SIZECONFIG_SYS_INIT_RAM_
SIZEinclude/configs/socfpga_common.h +0
-2-#if defined(CONFIG_TARGET_SOCFPGA_ARRIA10 ) -/* SPL memory allocation configuration, this is for FAT implementation */
include/configs/socfpga_common.h +0
-3-#ifndef CONFIG_SYS_SPL_MALLOC_START -#define CONFIG_SYS_SPL_MALLOC_SIZE 0x00010000 -#define CONFIG_SYS_SPL_MALLOC_START (CONFIG_SYS_INIT_RAM_SIZE
- \
-CONFIG_SYS_SPL_MALLOC_S
IZE
+ \
-CONFIG_SYS_INIT_RAM_ADD
R)include/configs/socfpga_common.h +0
-6-#endif -#endif -/* SPL SDMMC boot support */ #ifdef CONFIG_SPL_MMC_SUPPORT #if defined(CONFIG_SPL_FS_FAT ) || defined(CONFIG_SPL_FS_EXT4 )@@ -294,11 +284,7 @@ unsigned intcm_get_qspi_controller_clk_hz (void);/* * Stack setup */ -#if defined(CONFIG_TARGET_SOCFPGA_GEN5 )#define CONFIG_SPL_STACK CONFIG_SYS_INIT_SP_ADDR -#elif defined(CONFIG_TARGET_SOCFPGA_ARRIA10 ) -#define CONFIG_SPL_STACK CONFIG_SYS_SPL_MALLOC_START
-#endif/* Extra Environment */ #ifndef CONFIG_SPL_BUILD