[U-Boot] [PATCH v2 0/9] make SPL and normal u-boot stage use independent SYS_MALLOC_F_LEN

Some platforms like RK3036 has very small sram to run spl code, so it has no enough sapce for so much malloc pool before relocation in spl stage as the normal u-boot stake. As the long discussion in [1] [2], I make this series out, try to make spl and normal u-boot stage use independent SYS_MALLOC_F_LEN.
[1]https://lists.denx.de/pipermail/u-boot/2017-July/297370.html [2]https://lists.denx.de/pipermail/u-boot/2017-July/297504.html
Changes in v2: - introduce a new control CONFIG_SPL_SYS_MALLOC_F_LEN, adviced by Simon - set spl pre relocation malloc pool by CONFIG_SPL_SYS_MALLOC_F_LEN
Andy Yan (9): make SPL and normal u-boot stage use independent SYS_MALLOC_F_LEN mips: spl and normal u-boot stage set SYS_MALLOC_F indepently powerpc: spl and normal u-boot stage set SYS_MALLOC_F indepently microblaze: spl and normal u-boot stage set SYS_MALLOC_F indepently rockchip: set malloc pool size to 0 before relocation in spl state on rk3036 based board rockchip: disable SPL_ARCH_MEMCPY/MEMSET for rk3036 rockchip: enable SPL_LIBGENERIC for rk3036 based boards rockchip: use debug() instead of printf when back to bootrom rockchip: add u-boot specific dts for rk3036 sdk
Kconfig | 10 ++++++++++ arch/arm/dts/rk3036-sdk-u-boot.dtsi | 11 +++++++++++ arch/arm/mach-rockchip/bootrom.c | 2 +- arch/arm/mach-rockchip/rk3036-board-spl.c | 6 ------ arch/microblaze/cpu/start.S | 11 ++++++++--- arch/mips/cpu/start.S | 8 ++++++-- arch/powerpc/cpu/mpc83xx/start.S | 13 +++++++++---- arch/powerpc/cpu/mpc85xx/start.S | 16 ++++++++++------ arch/sandbox/cpu/start.c | 2 +- cmd/bdinfo.c | 2 +- common/Makefile | 2 +- common/board_f.c | 4 ++-- common/board_r.c | 2 +- common/dlmalloc.c | 12 ++++++------ common/init/board_init.c | 4 ++-- common/spl/spl.c | 6 +++--- configs/evb-rk3036_defconfig | 5 +++++ configs/kylin-rk3036_defconfig | 6 +++++- drivers/core/Kconfig | 8 ++++---- drivers/serial/serial-uclass.c | 4 ++-- include/asm-generic/global_data.h | 2 +- include/common.h | 11 +++++++++++ lib/asm-offsets.c | 2 +- lib/efi/efi_app.c | 2 +- 24 files changed, 102 insertions(+), 49 deletions(-) create mode 100644 arch/arm/dts/rk3036-sdk-u-boot.dtsi

Some platforms has very small sram to run spl code, so it has no enough sapce for so much malloc pool before relocation in spl stage as the normal u-boot stake. Make spl and normal u-boot stage use independent SYS_MALLOC_F_LEN, Then people can sets the pre-relocation malloc pool according to the memory space indepently.
Signed-off-by: Andy Yan andy.yan@rock-chips.com
---
Changes in v2: - introduce a new control CONFIG_SPL_SYS_MALLOC_F_LEN, adviced by Simon
Kconfig | 10 ++++++++++ arch/sandbox/cpu/start.c | 2 +- cmd/bdinfo.c | 2 +- common/Makefile | 2 +- common/board_f.c | 4 ++-- common/board_r.c | 2 +- common/dlmalloc.c | 12 ++++++------ common/init/board_init.c | 4 ++-- common/spl/spl.c | 6 +++--- drivers/core/Kconfig | 8 ++++---- drivers/serial/serial-uclass.c | 4 ++-- include/asm-generic/global_data.h | 2 +- include/common.h | 11 +++++++++++ lib/asm-offsets.c | 2 +- lib/efi/efi_app.c | 2 +- 15 files changed, 47 insertions(+), 26 deletions(-)
diff --git a/Kconfig b/Kconfig index bb80ada..c1451bc 100644 --- a/Kconfig +++ b/Kconfig @@ -95,6 +95,16 @@ config SYS_MALLOC_F_LEN particular needs this to operate, so that it can allocate the initial serial device and any others that are needed.
+config SPL_SYS_MALLOC_F_LEN + hex "Size of malloc() pool in spl before relocation" + depends on SYS_MALLOC_F + default SYS_MALLOC_F_LEN + help + Before relocation, memory is very limited on many platforms. Still, + we can provide a small malloc() pool if needed. Driver model in + particular needs this to operate, so that it can allocate the + initial serial device and any others that are needed. + menuconfig EXPERT bool "Configure standard U-Boot features (expert users)" default y diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index f605d4d..17e531a 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -310,7 +310,7 @@ int main(int argc, char *argv[])
memset(&data, '\0', sizeof(data)); gd = &data; -#ifdef CONFIG_SYS_MALLOC_F_LEN +#ifdef CONFIG_SYS_MALLOC_F gd->malloc_base = CONFIG_MALLOC_F_ADDR; #endif setup_ram_buf(state); diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c index 8971697..64836e9 100644 --- a/cmd/bdinfo.c +++ b/cmd/bdinfo.c @@ -346,7 +346,7 @@ static int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, #endif #ifdef CONFIG_SYS_MALLOC_F printf("Early malloc usage: %lx / %x\n", gd->malloc_ptr, - CONFIG_SYS_MALLOC_F_LEN); + get_sys_malloc_f_len()); #endif if (gd->fdt_blob) printf("fdt_blob = %p\n", gd->fdt_blob); diff --git a/common/Makefile b/common/Makefile index 17a92ea..29c880d 100644 --- a/common/Makefile +++ b/common/Makefile @@ -139,7 +139,7 @@ obj-y += console.o endif obj-$(CONFIG_CROS_EC) += cros_ec.o obj-y += dlmalloc.o -ifdef CONFIG_SYS_MALLOC_F_LEN +ifdef CONFIG_SYS_MALLOC_F obj-y += malloc_simple.o endif obj-y += image.o diff --git a/common/board_f.c b/common/board_f.c index ffa84e3..82dae70 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -727,7 +727,7 @@ static int initf_bootstage(void)
static int initf_console_record(void) { -#if defined(CONFIG_CONSOLE_RECORD) && defined(CONFIG_SYS_MALLOC_F_LEN) +#if defined(CONFIG_CONSOLE_RECORD) && defined(CONFIG_SYS_MALLOC_F) return console_record_init(); #else return 0; @@ -736,7 +736,7 @@ static int initf_console_record(void)
static int initf_dm(void) { -#if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN) +#if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F) int ret;
bootstage_start(BOOTSTATE_ID_ACCUM_DM_F, "dm_f"); diff --git a/common/board_r.c b/common/board_r.c index ecca1ed..e7d4010 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -256,7 +256,7 @@ static int initr_malloc(void) { ulong malloc_start;
-#ifdef CONFIG_SYS_MALLOC_F_LEN +#ifdef CONFIG_SYS_MALLOC_F debug("Pre-reloc malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr, gd->malloc_ptr / 1024); #endif diff --git a/common/dlmalloc.c b/common/dlmalloc.c index fc1e8b3..d19c3e1 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -1254,7 +1254,7 @@ Void_t* mALLOc(bytes) size_t bytes;
INTERNAL_SIZE_T nb;
-#ifdef CONFIG_SYS_MALLOC_F_LEN +#ifdef CONFIG_SYS_MALLOC_F if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) return malloc_simple(bytes); #endif @@ -1522,7 +1522,7 @@ void fREe(mem) Void_t* mem; mchunkptr fwd; /* misc temp for linking */ int islr; /* track whether merging with last_remainder */
-#ifdef CONFIG_SYS_MALLOC_F_LEN +#ifdef CONFIG_SYS_MALLOC_F /* free() is a no-op - all the memory will be freed on relocation */ if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) return; @@ -1679,7 +1679,7 @@ Void_t* rEALLOc(oldmem, bytes) Void_t* oldmem; size_t bytes; /* realloc of null is supposed to be same as malloc */ if (oldmem == NULL) return mALLOc(bytes);
-#ifdef CONFIG_SYS_MALLOC_F_LEN +#ifdef CONFIG_SYS_MALLOC_F if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) { /* This is harder to support and should not be needed */ panic("pre-reloc realloc() is not supported"); @@ -2074,7 +2074,7 @@ Void_t* cALLOc(n, elem_size) size_t n; size_t elem_size; return NULL; else { -#ifdef CONFIG_SYS_MALLOC_F_LEN +#ifdef CONFIG_SYS_MALLOC_F if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) { MALLOC_ZERO(mem, sz); return mem; @@ -2375,9 +2375,9 @@ int mALLOPt(param_number, value) int param_number; int value;
int initf_malloc(void) { -#ifdef CONFIG_SYS_MALLOC_F_LEN +#ifdef CONFIG_SYS_MALLOC_F assert(gd->malloc_base); /* Set up by crt0.S */ - gd->malloc_limit = CONFIG_SYS_MALLOC_F_LEN; + gd->malloc_limit = get_sys_malloc_f_len(); gd->malloc_ptr = 0; #endif
diff --git a/common/init/board_init.c b/common/init/board_init.c index bf4255b..7698558 100644 --- a/common/init/board_init.c +++ b/common/init/board_init.c @@ -47,7 +47,7 @@ ulong board_init_f_alloc_reserve(ulong top) { /* Reserve early malloc arena */ #if defined(CONFIG_SYS_MALLOC_F) - top -= CONFIG_SYS_MALLOC_F_LEN; + top -= get_sys_malloc_f_len(); #endif /* LAST : reserve GD (rounded up to a multiple of 16 bytes) */ top = rounddown(top-sizeof(struct global_data), 16); @@ -125,7 +125,7 @@ void board_init_f_init_reserve(ulong base) /* go down one 'early malloc arena' */ gd->malloc_base = base; /* next alloc will be higher by one 'early malloc arena' size */ - base += CONFIG_SYS_MALLOC_F_LEN; + base += get_sys_malloc_f_len(); #endif }
diff --git a/common/spl/spl.c b/common/spl/spl.c index 7f3fd92..006ed02 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -220,12 +220,12 @@ static int spl_common_init(bool setup_malloc)
debug("spl_early_init()\n");
-#if defined(CONFIG_SYS_MALLOC_F_LEN) +#if defined(CONFIG_SYS_MALLOC_F) if (setup_malloc) { #ifdef CONFIG_MALLOC_F_ADDR gd->malloc_base = CONFIG_MALLOC_F_ADDR; #endif - gd->malloc_limit = CONFIG_SYS_MALLOC_F_LEN; + gd->malloc_limit = get_sys_malloc_f_len(); gd->malloc_ptr = 0; } #endif @@ -419,7 +419,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2) default: debug("Unsupported OS image.. Jumping nevertheless..\n"); } -#if defined(CONFIG_SYS_MALLOC_F_LEN) && !defined(CONFIG_SYS_SPL_MALLOC_SIZE) +#if defined(CONFIG_SYS_MALLOC_F) && !defined(CONFIG_SYS_SPL_MALLOC_SIZE) debug("SPL malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr, gd->malloc_ptr / 1024); #endif diff --git a/drivers/core/Kconfig b/drivers/core/Kconfig index fb5c4e8..f8b19a4 100644 --- a/drivers/core/Kconfig +++ b/drivers/core/Kconfig @@ -16,10 +16,10 @@ config SPL_DM suitable malloc() implementation. If you are not using the full malloc() enabled by CONFIG_SYS_SPL_MALLOC_START, consider using CONFIG_SYS_MALLOC_SIMPLE. In that case you - must provide CONFIG_SYS_MALLOC_F_LEN to set the size. + must provide CONFIG_SPL_SYS_MALLOC_F_LEN to set the size. In most cases driver model will only allocate a few uclasses and devices in SPL, so 1KB should be enable. See - CONFIG_SYS_MALLOC_F_LEN for more details on how to enable it. + CONFIG_SPL_SYS_MALLOC_F_LEN for more details on how to enable it.
config TPL_DM bool "Enable Driver Model for TPL" @@ -29,10 +29,10 @@ config TPL_DM suitable malloc() implementation. If you are not using the full malloc() enabled by CONFIG_SYS_SPL_MALLOC_START, consider using CONFIG_SYS_MALLOC_SIMPLE. In that case you - must provide CONFIG_SYS_MALLOC_F_LEN to set the size. + must provide CONFIG_SPL_SYS_MALLOC_F_LEN to set the size. In most cases driver model will only allocate a few uclasses and devices in SPL, so 1KB should be enough. See - CONFIG_SYS_MALLOC_F_LEN for more details on how to enable it. + CONFIG_SPL_SYS_MALLOC_F_LEN for more details on how to enable it. Disable this for very small implementations.
config DM_WARN diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c index f360534..8d63b05 100644 --- a/drivers/serial/serial-uclass.c +++ b/drivers/serial/serial-uclass.c @@ -23,8 +23,8 @@ DECLARE_GLOBAL_DATA_PTR; */ static const unsigned long baudrate_table[] = CONFIG_SYS_BAUDRATE_TABLE;
-#ifndef CONFIG_SYS_MALLOC_F_LEN -#error "Serial is required before relocation - define CONFIG_SYS_MALLOC_F_LEN to make this work" +#ifndef CONFIG_SYS_MALLOC_F +#error "Serial is required before relocation - define CONFIG_$(SPL_)SYS_MALLOC_F_LEN to make this work" #endif
static int serial_check_stdout(const void *blob, struct udevice **devp) diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index fb90be9..cf3e12a 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -88,7 +88,7 @@ typedef struct global_data { #endif unsigned int timebase_h; unsigned int timebase_l; -#ifdef CONFIG_SYS_MALLOC_F_LEN +#ifdef CONFIG_SYS_MALLOC_F unsigned long malloc_base; /* base address of early malloc() */ unsigned long malloc_limit; /* limit address */ unsigned long malloc_ptr; /* current address */ diff --git a/include/common.h b/include/common.h index 751665f..afba422 100644 --- a/include/common.h +++ b/include/common.h @@ -717,6 +717,17 @@ int cpu_disable(int nr); int cpu_release(int nr, int argc, char * const argv[]); #endif
+#if defined(CONFIG_SYS_MALLOC_F) +static inline int get_sys_malloc_f_len(void) +{ +#if defined(CONFIG_SPL_BUILD) + return CONFIG_SPL_SYS_MALLOC_F_LEN; +#else + return CONFIG_SYS_MALLOC_F_LEN; +#endif +} +#endif + #else /* __ASSEMBLY__ */
/* Drop a C type modifier (like in 3UL) for constants used in assembly. */ diff --git a/lib/asm-offsets.c b/lib/asm-offsets.c index 221ebbf..a65df59 100644 --- a/lib/asm-offsets.c +++ b/lib/asm-offsets.c @@ -28,7 +28,7 @@ int main(void) DEFINE(GD_SIZE, sizeof(struct global_data));
DEFINE(GD_BD, offsetof(struct global_data, bd)); -#ifdef CONFIG_SYS_MALLOC_F_LEN +#ifdef CONFIG_SYS_MALLOC_F DEFINE(GD_MALLOC_BASE, offsetof(struct global_data, malloc_base)); #endif
diff --git a/lib/efi/efi_app.c b/lib/efi/efi_app.c index 452ab5d..89bbc1b 100644 --- a/lib/efi/efi_app.c +++ b/lib/efi/efi_app.c @@ -48,7 +48,7 @@ static efi_status_t setup_memory(struct efi_priv *priv) return ret; memset(gd, '\0', sizeof(*gd));
- gd->malloc_base = (ulong)efi_malloc(priv, CONFIG_SYS_MALLOC_F_LEN, + gd->malloc_base = (ulong)efi_malloc(priv, get_sys_malloc_f_len(), &ret); if (!gd->malloc_base) return ret;

On Thu, Jul 13, 2017 at 11:12:29AM +0800, Andy Yan wrote:
Some platforms has very small sram to run spl code, so it has no enough sapce for so much malloc pool before relocation in spl stage as the normal u-boot stake. Make spl and normal u-boot stage use independent SYS_MALLOC_F_LEN, Then people can sets the pre-relocation malloc pool according to the memory space indepently.
Signed-off-by: Andy Yan andy.yan@rock-chips.com
Reviewed-by: Tom Rini trini@konsulko.com

Hi Andy,
On 12 July 2017 at 20:12, Andy Yan andy.yan@rock-chips.com wrote:
Some platforms has very small sram to run spl code, so it has no enough sapce for so much malloc pool before relocation in spl stage as the normal u-boot stake. Make spl and normal u-boot stage use independent SYS_MALLOC_F_LEN, Then people can sets the pre-relocation malloc pool according to the memory space indepently.
Signed-off-by: Andy Yan andy.yan@rock-chips.com
Changes in v2:
- introduce a new control CONFIG_SPL_SYS_MALLOC_F_LEN, adviced by Simon
Kconfig | 10 ++++++++++ arch/sandbox/cpu/start.c | 2 +- cmd/bdinfo.c | 2 +- common/Makefile | 2 +- common/board_f.c | 4 ++-- common/board_r.c | 2 +- common/dlmalloc.c | 12 ++++++------ common/init/board_init.c | 4 ++-- common/spl/spl.c | 6 +++--- drivers/core/Kconfig | 8 ++++---- drivers/serial/serial-uclass.c | 4 ++-- include/asm-generic/global_data.h | 2 +- include/common.h | 11 +++++++++++ lib/asm-offsets.c | 2 +- lib/efi/efi_app.c | 2 +- 15 files changed, 47 insertions(+), 26 deletions(-)
diff --git a/Kconfig b/Kconfig index bb80ada..c1451bc 100644 --- a/Kconfig +++ b/Kconfig @@ -95,6 +95,16 @@ config SYS_MALLOC_F_LEN particular needs this to operate, so that it can allocate the initial serial device and any others that are needed.
+config SPL_SYS_MALLOC_F_LEN
hex "Size of malloc() pool in spl before relocation"
depends on SYS_MALLOC_F
default SYS_MALLOC_F_LEN
help
Before relocation, memory is very limited on many platforms. Still,
we can provide a small malloc() pool if needed. Driver model in
particular needs this to operate, so that it can allocate the
initial serial device and any others that are needed.
menuconfig EXPERT bool "Configure standard U-Boot features (expert users)" default y diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index f605d4d..17e531a 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -310,7 +310,7 @@ int main(int argc, char *argv[])
memset(&data, '\0', sizeof(data)); gd = &data;
-#ifdef CONFIG_SYS_MALLOC_F_LEN +#ifdef CONFIG_SYS_MALLOC_F
This is a good change. Can you please split out the change to move to SYS_MALLOC_F into its own patch? It seems to be separate from the change to support an SPL version.
gd->malloc_base = CONFIG_MALLOC_F_ADDR;
#endif setup_ram_buf(state); diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c index 8971697..64836e9 100644 --- a/cmd/bdinfo.c +++ b/cmd/bdinfo.c @@ -346,7 +346,7 @@ static int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, #endif #ifdef CONFIG_SYS_MALLOC_F printf("Early malloc usage: %lx / %x\n", gd->malloc_ptr,
CONFIG_SYS_MALLOC_F_LEN);
get_sys_malloc_f_len());
Can you use CONFIG_VAL(SYS_MALLOC_F_LEN) here instead of the function?
[...]
Regards, Simon

Some platforms has very small sram to run spl code, so it may have no enough sapce for so much malloc pool before relocation in spl stage as the normal u-boot stage.
Signed-off-by: Andy Yan andy.yan@rock-chips.com ---
Changes in v2: None
arch/mips/cpu/start.S | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/arch/mips/cpu/start.S b/arch/mips/cpu/start.S index d01ee9f..0cc140b 100644 --- a/arch/mips/cpu/start.S +++ b/arch/mips/cpu/start.S @@ -60,8 +60,12 @@ sp, sp, GD_SIZE # reserve space for gd and sp, sp, t0 # force 16 byte alignment move k0, sp # save gd pointer -#ifdef CONFIG_SYS_MALLOC_F_LEN +#ifdef CONFIG_SYS_MALLOC_F +# ifdef CONFIG_SPL_BUILD + li t2, CONFIG_SPL_SYS_MALLOC_F_LEN +# else li t2, CONFIG_SYS_MALLOC_F_LEN +# endif PTR_SUBU \ sp, sp, t2 # reserve space for early malloc and sp, sp, t0 # force 16 byte alignment @@ -75,7 +79,7 @@ blt t0, t1, 1b PTR_ADDIU t0, PTRSIZE
-#ifdef CONFIG_SYS_MALLOC_F_LEN +#ifdef CONFIG_SYS_MALLOC_F PTR_S sp, GD_MALLOC_BASE(k0) # gd->malloc_base offset #endif .endm

2017-07-13 5:23 GMT+02:00 Andy Yan andy.yan@rock-chips.com:
Some platforms has very small sram to run spl code, so it may have no enough sapce for so much malloc pool before relocation in spl stage as the normal u-boot stage.
Signed-off-by: Andy Yan andy.yan@rock-chips.com
Changes in v2: None
arch/mips/cpu/start.S | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
Acked-by: Daniel Schwierzeck daniel.schwierzeck@gmail.com
diff --git a/arch/mips/cpu/start.S b/arch/mips/cpu/start.S index d01ee9f..0cc140b 100644 --- a/arch/mips/cpu/start.S +++ b/arch/mips/cpu/start.S @@ -60,8 +60,12 @@ sp, sp, GD_SIZE # reserve space for gd and sp, sp, t0 # force 16 byte alignment move k0, sp # save gd pointer -#ifdef CONFIG_SYS_MALLOC_F_LEN +#ifdef CONFIG_SYS_MALLOC_F +# ifdef CONFIG_SPL_BUILD
li t2, CONFIG_SPL_SYS_MALLOC_F_LEN
+# else li t2, CONFIG_SYS_MALLOC_F_LEN +# endif PTR_SUBU \ sp, sp, t2 # reserve space for early malloc and sp, sp, t0 # force 16 byte alignment @@ -75,7 +79,7 @@ blt t0, t1, 1b PTR_ADDIU t0, PTRSIZE
-#ifdef CONFIG_SYS_MALLOC_F_LEN +#ifdef CONFIG_SYS_MALLOC_F PTR_S sp, GD_MALLOC_BASE(k0) # gd->malloc_base offset #endif .endm -- 2.7.4

Some platforms has very small sram to run spl code, so it may have no enough sapce for so much malloc pool before relocation in spl stage as the normal u-boot stage.
Signed-off-by: Andy Yan andy.yan@rock-chips.com ---
Changes in v2: None
arch/powerpc/cpu/mpc83xx/start.S | 13 +++++++++---- arch/powerpc/cpu/mpc85xx/start.S | 16 ++++++++++------ 2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/cpu/mpc83xx/start.S b/arch/powerpc/cpu/mpc83xx/start.S index 2fed4a1..f067b9e 100644 --- a/arch/powerpc/cpu/mpc83xx/start.S +++ b/arch/powerpc/cpu/mpc83xx/start.S @@ -48,6 +48,11 @@ #define CONFIG_SYS_FLASHBOOT #endif
+#if defined(CONFIG_SPL_BUILD) +#define MALLOC_F_LEN CONFIG_SPL_SYS_MALLOC_F_LEN +#else +#define MALLOC_F_LEN CONFIG_SYS_MALLOC_F_LEN +#endif /* * Set up GOT: Global Offset Table * @@ -274,14 +279,14 @@ in_flash: cmplw r3, r4 bne 1b
-#ifdef CONFIG_SYS_MALLOC_F_LEN +#ifdef CONFIG_SYS_MALLOC_F
-#if CONFIG_SYS_MALLOC_F_LEN + GENERATED_GBL_DATA_SIZE > CONFIG_SYS_INIT_RAM_SIZE -#error "CONFIG_SYS_MALLOC_F_LEN too large to fit into initial RAM." +#if MALLOC_F_LEN + GENERATED_GBL_DATA_SIZE > CONFIG_SYS_INIT_RAM_SIZE +#error "MALLOC_F_LEN too large to fit into initial RAM." #endif
/* r3 = new stack pointer / pre-reloc malloc area */ - subi r3, r3, CONFIG_SYS_MALLOC_F_LEN + subi r3, r3, MALLOC_F_LEN
/* Set pointer to pre-reloc malloc area in GD */ stw r3, GD_MALLOC_BASE(r4) diff --git a/arch/powerpc/cpu/mpc85xx/start.S b/arch/powerpc/cpu/mpc85xx/start.S index 63fdffd..6fa7592 100644 --- a/arch/powerpc/cpu/mpc85xx/start.S +++ b/arch/powerpc/cpu/mpc85xx/start.S @@ -38,6 +38,11 @@ #define NOR_BOOT #endif
+#if defined(CONFIG_SPL_BUILD) +#define MALLOC_F_LEN CONFIG_SPL_SYS_MALLOC_F_LEN +#else +#define MALLOC_F_LEN CONFIG_SYS_MALLOC_F_LEN +#endif /* * Set up GOT: Global Offset Table * @@ -1183,14 +1188,13 @@ _start_cont: lis r3,(CONFIG_SYS_INIT_RAM_ADDR)@h ori r3,r3,((CONFIG_SYS_INIT_SP_OFFSET-16)&~0xf)@l /* Align to 16 */
-#ifdef CONFIG_SYS_MALLOC_F_LEN - -#if CONFIG_SYS_MALLOC_F_LEN + GENERATED_GBL_DATA_SIZE > CONFIG_SYS_INIT_RAM_SIZE -#error "CONFIG_SYS_MALLOC_F_LEN too large to fit into initial RAM." +#ifdef CONFIG_SYS_MALLOC_F +#if MALLOC_F_LEN + GENERATED_GBL_DATA_SIZE > CONFIG_SYS_INIT_RAM_SIZE +#error "MALLOC_F_LEN too large to fit into initial RAM." #endif
/* Leave 16+ byte for back chain termination and NULL return address */ - subi r3,r3,((CONFIG_SYS_MALLOC_F_LEN+16+15)&~0xf) + subi r3,r3,((MALLOC_F_LEN+16+15)&~0xf) #endif
/* End of RAM */ @@ -1204,7 +1208,7 @@ _start_cont: cmplw r4,r3 bne 1b
-#ifdef CONFIG_SYS_MALLOC_F_LEN +#ifdef CONFIG_SYS_MALLOC_F lis r4,(CONFIG_SYS_INIT_RAM_ADDR)@h ori r4,r4,(CONFIG_SYS_GBL_DATA_OFFSET)@l

Hi Andy,
On 12 July 2017 at 20:25, Andy Yan andy.yan@rock-chips.com wrote:
Some platforms has very small sram to run spl code, so it may have no enough sapce for so much malloc pool before relocation in spl stage as the normal u-boot stage.
Signed-off-by: Andy Yan andy.yan@rock-chips.com
Changes in v2: None
arch/powerpc/cpu/mpc83xx/start.S | 13 +++++++++---- arch/powerpc/cpu/mpc85xx/start.S | 16 ++++++++++------ 2 files changed, 19 insertions(+), 10 deletions(-)
I think you can use CONFIG_VAL() in this patch too.
Regards, Simon

Some platforms has very small sram to run spl code, so it may have no enough sapce for so much malloc pool before relocation in spl stage as the normal u-boot stage.
Signed-off-by: Andy Yan andy.yan@rock-chips.com ---
Changes in v2: None
arch/microblaze/cpu/start.S | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/arch/microblaze/cpu/start.S b/arch/microblaze/cpu/start.S index 79dc0cf..bfc0f54 100644 --- a/arch/microblaze/cpu/start.S +++ b/arch/microblaze/cpu/start.S @@ -11,6 +11,11 @@ #include <asm-offsets.h> #include <config.h>
+#if defined(CONFIG_SPL_BUILD) +#define MALLOC_F_LEN CONFIG_SPL_SYS_MALLOC_F_LEN +#else +#define MALLOC_F_LEN CONFIG_SYS_MALLOC_F_LEN +#endif .text .global _start _start: @@ -32,7 +37,7 @@ _start: addi r1, r1, -4 /* Decrement SP to top of memory */ #else #if defined(CONFIG_SYS_MALLOC_F_LEN) - addi r1, r0, CONFIG_SYS_INIT_SP_OFFSET - CONFIG_SYS_MALLOC_F_LEN + addi r1, r0, CONFIG_SYS_INIT_SP_OFFSET - MALLOC_F_LEN #else addi r1, r0, CONFIG_SYS_INIT_SP_OFFSET #endif @@ -162,14 +167,14 @@ clear_bss: #ifndef CONFIG_SPL_BUILD or r5, r0, r0 /* flags - empty */ addi r31, r0, _gd -#if defined(CONFIG_SYS_MALLOC_F_LEN) +#if defined(CONFIG_SYS_MALLOC_F) addi r6, r0, CONFIG_SYS_INIT_SP_OFFSET swi r6, r31, GD_MALLOC_BASE #endif brai board_init_f #else addi r31, r0, _gd -#if defined(CONFIG_SYS_MALLOC_F_LEN) +#if defined(CONFIG_SYS_MALLOC_F) addi r6, r0, CONFIG_SPL_STACK_ADDR swi r6, r31, GD_MALLOC_BASE #endif

RK3036 only has 4kb sram, the spl code will use 3.4 ~ 3.5 kb, the last 0.5kb are used for SP and GD, so there is no space for malloc. Also, the spl will directly return to bootrom after dram initialized, they never need the space for malloc.
Signed-off-by: Andy Yan andy.yan@rock-chips.com
---
Changes in v2: - set spl pre relocation malloc pool by CONFIG_SPL_SYS_MALLOC_F_LEN
configs/evb-rk3036_defconfig | 1 + configs/kylin-rk3036_defconfig | 1 + 2 files changed, 2 insertions(+)
diff --git a/configs/evb-rk3036_defconfig b/configs/evb-rk3036_defconfig index 321ef71..78e2095 100644 --- a/configs/evb-rk3036_defconfig +++ b/configs/evb-rk3036_defconfig @@ -4,6 +4,7 @@ CONFIG_ROCKCHIP_RK3036=y CONFIG_TARGET_EVB_RK3036=y CONFIG_SPL_STACK_R_ADDR=0x80000 CONFIG_DEFAULT_DEVICE_TREE="rk3036-sdk" +CONFIG_SPL_SYS_MALLOC_F_LEN=0x0 CONFIG_DEBUG_UART=y # CONFIG_DISPLAY_CPUINFO is not set CONFIG_SPL_STACK_R=y diff --git a/configs/kylin-rk3036_defconfig b/configs/kylin-rk3036_defconfig index 715e4b2..fd20eff 100644 --- a/configs/kylin-rk3036_defconfig +++ b/configs/kylin-rk3036_defconfig @@ -4,6 +4,7 @@ CONFIG_ROCKCHIP_RK3036=y CONFIG_TARGET_KYLIN_RK3036=y CONFIG_SPL_STACK_R_ADDR=0x80000 CONFIG_DEFAULT_DEVICE_TREE="rk3036-sdk" +CONFIG_SPL_SYS_MALLOC_F_LEN=0x0 # CONFIG_DISPLAY_CPUINFO is not set CONFIG_SPL_STACK_R=y # CONFIG_CMD_IMLS is not set

On 12 July 2017 at 20:28, Andy Yan andy.yan@rock-chips.com wrote:
RK3036 only has 4kb sram, the spl code will use 3.4 ~ 3.5 kb, the last 0.5kb are used for SP and GD, so there is no space for malloc. Also, the spl will directly return to bootrom after dram initialized, they never need the space for malloc.
Signed-off-by: Andy Yan andy.yan@rock-chips.com
Changes in v2:
- set spl pre relocation malloc pool by CONFIG_SPL_SYS_MALLOC_F_LEN
configs/evb-rk3036_defconfig | 1 + configs/kylin-rk3036_defconfig | 1 + 2 files changed, 2 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

RK3036 has no enough sapce use ARCH_MEMCPY/MEMSET in spl stage
Signed-off-by: Andy Yan andy.yan@rock-chips.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
configs/evb-rk3036_defconfig | 2 ++ configs/kylin-rk3036_defconfig | 2 ++ 2 files changed, 4 insertions(+)
diff --git a/configs/evb-rk3036_defconfig b/configs/evb-rk3036_defconfig index 78e2095..8e7a65b 100644 --- a/configs/evb-rk3036_defconfig +++ b/configs/evb-rk3036_defconfig @@ -1,4 +1,6 @@ CONFIG_ARM=y +# CONFIG_SPL_USE_ARCH_MEMCPY is not set +# CONFIG_SPL_USE_ARCH_MEMSET is not set CONFIG_ARCH_ROCKCHIP=y CONFIG_ROCKCHIP_RK3036=y CONFIG_TARGET_EVB_RK3036=y diff --git a/configs/kylin-rk3036_defconfig b/configs/kylin-rk3036_defconfig index fd20eff..266ac94 100644 --- a/configs/kylin-rk3036_defconfig +++ b/configs/kylin-rk3036_defconfig @@ -1,4 +1,6 @@ CONFIG_ARM=y +# CONFIG_SPL_USE_ARCH_MEMCPY is not set +# CONFIG_SPL_USE_ARCH_MEMSET is not set CONFIG_ARCH_ROCKCHIP=y CONFIG_ROCKCHIP_RK3036=y CONFIG_TARGET_KYLIN_RK3036=y

function board_init_f_init_reserve will call memset, which is implemented in lib, and enabled by CONFIG_SPL_LIBGENERIC_SUPPORT in spl stage. To reduce the code size, also enable SPL_TINY_MEMSET.
Signed-off-by: Andy Yan andy.yan@rock-chips.com ---
Changes in v2: None
arch/arm/mach-rockchip/rk3036-board-spl.c | 6 ------ configs/evb-rk3036_defconfig | 2 ++ configs/kylin-rk3036_defconfig | 3 ++- 3 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/arch/arm/mach-rockchip/rk3036-board-spl.c b/arch/arm/mach-rockchip/rk3036-board-spl.c index 7b8d0ee..9458201 100644 --- a/arch/arm/mach-rockchip/rk3036-board-spl.c +++ b/arch/arm/mach-rockchip/rk3036-board-spl.c @@ -53,9 +53,3 @@ void board_init_r(gd_t *id, ulong dest_addr) while (1) ; } - -void hang(void) -{ - while (1) - ; -} diff --git a/configs/evb-rk3036_defconfig b/configs/evb-rk3036_defconfig index 8e7a65b..c0eef27 100644 --- a/configs/evb-rk3036_defconfig +++ b/configs/evb-rk3036_defconfig @@ -2,6 +2,7 @@ CONFIG_ARM=y # CONFIG_SPL_USE_ARCH_MEMCPY is not set # CONFIG_SPL_USE_ARCH_MEMSET is not set CONFIG_ARCH_ROCKCHIP=y +CONFIG_SPL_LIBGENERIC_SUPPORT=y CONFIG_ROCKCHIP_RK3036=y CONFIG_TARGET_EVB_RK3036=y CONFIG_SPL_STACK_R_ADDR=0x80000 @@ -38,5 +39,6 @@ CONFIG_DEBUG_UART_BASE=0x20068000 CONFIG_DEBUG_UART_CLOCK=24000000 CONFIG_DEBUG_UART_SHIFT=2 CONFIG_SYSRESET=y +CONFIG_SPL_TINY_MEMSET=y CONFIG_CMD_DHRYSTONE=y CONFIG_ERRNO_STR=y diff --git a/configs/kylin-rk3036_defconfig b/configs/kylin-rk3036_defconfig index 266ac94..bba01fd 100644 --- a/configs/kylin-rk3036_defconfig +++ b/configs/kylin-rk3036_defconfig @@ -2,6 +2,7 @@ CONFIG_ARM=y # CONFIG_SPL_USE_ARCH_MEMCPY is not set # CONFIG_SPL_USE_ARCH_MEMSET is not set CONFIG_ARCH_ROCKCHIP=y +CONFIG_SPL_LIBGENERIC_SUPPORT=y CONFIG_ROCKCHIP_RK3036=y CONFIG_TARGET_KYLIN_RK3036=y CONFIG_SPL_STACK_R_ADDR=0x80000 @@ -22,7 +23,6 @@ CONFIG_CMD_TIME=y # CONFIG_SPL_DOS_PARTITION is not set # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set -CONFIG_SPL_PARTITION_UUIDS=y CONFIG_REGMAP=y CONFIG_SYSCON=y CONFIG_CLK=y @@ -38,5 +38,6 @@ CONFIG_SYSRESET=y CONFIG_USB=y CONFIG_USB_DWC2=y CONFIG_USB_STORAGE=y +CONFIG_SPL_TINY_MEMSET=y CONFIG_CMD_DHRYSTONE=y CONFIG_ERRNO_STR=y

On 12 July 2017 at 20:29, Andy Yan andy.yan@rock-chips.com wrote:
function board_init_f_init_reserve will call memset, which is implemented in lib, and enabled by CONFIG_SPL_LIBGENERIC_SUPPORT in spl stage. To reduce the code size, also enable SPL_TINY_MEMSET.
Signed-off-by: Andy Yan andy.yan@rock-chips.com
Changes in v2: None
arch/arm/mach-rockchip/rk3036-board-spl.c | 6 ------ configs/evb-rk3036_defconfig | 2 ++ configs/kylin-rk3036_defconfig | 3 ++- 3 files changed, 4 insertions(+), 7 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

printf will increase the code size more than 1kb, but platform like rk3036 has no enough space for it.
Signed-off-by: Andy Yan andy.yan@rock-chips.com ---
Changes in v2: None
arch/arm/mach-rockchip/bootrom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/mach-rockchip/bootrom.c b/arch/arm/mach-rockchip/bootrom.c index da36f92..ba34c35 100644 --- a/arch/arm/mach-rockchip/bootrom.c +++ b/arch/arm/mach-rockchip/bootrom.c @@ -10,7 +10,7 @@ void back_to_bootrom(void) { #if defined(CONFIG_SPL_LIBGENERIC_SUPPORT) && !defined(CONFIG_TPL_BUILD) - printf("Returning to boot ROM..."); + debug("Returning to boot ROM..."); #endif _back_to_bootrom_s(); }

Hi Andy,
On 12 July 2017 at 20:30, Andy Yan andy.yan@rock-chips.com wrote:
printf will increase the code size more than 1kb, but platform like rk3036 has no enough space for it.
Signed-off-by: Andy Yan andy.yan@rock-chips.com
Changes in v2: None
arch/arm/mach-rockchip/bootrom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/mach-rockchip/bootrom.c b/arch/arm/mach-rockchip/bootrom.c index da36f92..ba34c35 100644 --- a/arch/arm/mach-rockchip/bootrom.c +++ b/arch/arm/mach-rockchip/bootrom.c @@ -10,7 +10,7 @@ void back_to_bootrom(void) { #if defined(CONFIG_SPL_LIBGENERIC_SUPPORT) && !defined(CONFIG_TPL_BUILD)
printf("Returning to boot ROM...");
debug("Returning to boot ROM...");
#endif _back_to_bootrom_s(); } -- 2.7.4
This is nice for seeing what went wrong when the return does not work. Could we use puts() instead perhaps?
Regards, Simon

Add this dts to enable debug uart releated devices before relocation.
Signed-off-by: Andy Yan andy.yan@rock-chips.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
arch/arm/dts/rk3036-sdk-u-boot.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 arch/arm/dts/rk3036-sdk-u-boot.dtsi
diff --git a/arch/arm/dts/rk3036-sdk-u-boot.dtsi b/arch/arm/dts/rk3036-sdk-u-boot.dtsi new file mode 100644 index 0000000..6f15f4a --- /dev/null +++ b/arch/arm/dts/rk3036-sdk-u-boot.dtsi @@ -0,0 +1,11 @@ +&uart2 { + u-boot,dm-pre-reloc; +}; + +&grf { + u-boot,dm-pre-reloc; +}; + +&pinctrl { + u-boot,dm-pre-reloc; +};
participants (4)
-
Andy Yan
-
Daniel Schwierzeck
-
Simon Glass
-
Tom Rini