env_mmc: avoid stack allocation for env
PATCH 1/1 env_mmc: avoid stack allocation for env
Allocating space for temporary env on the stack makes env_relocate_spec() unsuitable for SPL environments which have very little stack.
--- common/env_mmc.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
common/env_mmc.c +11 -3
@@ -213,13 +213,19 @@ void env_relocate_spec(void)u32 offset1, offset2;int read1_fail =0 , read2_fail =0 ;int crc1_ok =0 , crc2_ok =0 ; -env_t *ep; +env_t *ep, *tmp_env1, *tmp_env2;int ret;int dev =CONFIG_SYS_MMC_ENV_DEV ;const char *errmsg =NULL ; -ALLOC_CACHE_ALIGN_BUFFER (env_t, tmp_env1,1 ); -ALLOC_CACHE_ALIGN_BUFFER (env_t, tmp_env2,1 ); + tmp_env1 =memalign (CONFIG_SYS_CACHELINE_SIZE ,CONFIG_ENV_SIZE ); + tmp_env2 =memalign (CONFIG_SYS_CACHELINE_SIZE ,CONFIG_ENV_SIZE ); +if (tmp_env1 ==NULL || tmp_env2 ==NULL ) { +puts ("Can't allocate buffers for environment\n" ); + ret =1 ; + errmsg ="!malloc() failed" ; + goto err; + }#ifdef CONFIG_SPL_BUILD dev =0 ;
@@ -287,6 +293,8 @@ void env_relocate_spec(void) ret =0 ; fini: +free (tmp_env1); +free (tmp_env2);fini_mmc_for_env (mmc); err:if (ret)
Signature · 1 line
1.9.1
PATCH 1/1 env_mmc: avoid stack allocation for env
Quoted 2 lines · Tim Harvey
Allocating space for temporary env on the stack makes
env_relocate_spec()unsuitable for SPL environments which have very little stack.
Well yeah, but what if you don't have malloc area ? I'd expect that the be the case in SPL quite often.
Best regards,
Marek Vasut
PATCH 1/1 env_mmc: avoid stack allocation for env
Quoted 6 lines · Marek Vasut
Quoted 2 lines · Tim Harvey
Allocating space for temporary env on the stack makes
env_relocate_spec()unsuitable for SPL environments which have very little stack.Well yeah, but what if you don't have malloc area ? I'd expect that the be the case in SPL quite often.
OK, hold up. We went through this a while back which is why things are how they are today. First, we have things setup today such that you can throw stack (at the point we do env in SPL) into DDR. This means we can keep doing things the way they are. You can take a look at include/configs/am335x_evm.h and where CONFIG_EMMC_BOOT is set, that's how we do what it looks like you're trying to do on imx6 but on TI am335x.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150508/f62c641b/attachment.sig>
PATCH 1/1 env_mmc: avoid stack allocation for env
Quoted 16 lines · Tom Rini
Quoted 6 lines · Marek Vasut
Quoted 2 lines · Tim Harvey
Allocating space for temporary env on the stack makes
env_relocate_spec()unsuitable for SPL environments which have very little stack.Well yeah, but what if you don't have malloc area ? I'd expect that the be the case in SPL quite often.
OK, hold up. We went through this a while back which is why things are how they are today. First, we have things setup today such that you can throw stack (at the point we do env in SPL) into DDR. This means we can keep doing things the way they are. You can take a look at
include/configs/am335x_evm.hand whereCONFIG_EMMC_BOOTis set, that's how we do what it looks like you're trying to do on imx6 but on TI am335x.
Quoted 2 lines
--
Tom
Tom,
Yes, I'm doing this on Gateworks Ventana (board/gateworks/gw_ventana) based on IMX6 which has a limmited stack size during SPL. I don't see anything magic in include/configs/am335x_evm.h that catches my attention. Do you know where the code is that lets you point the stack to DDR? It sounds like that's what I need.
This sounds like there could be some boards using nand that rely on malloc (that's where I got the inspiration from for this) and others using mmc that rely on a decent size stack. I wonder if there is a #define that we can base off of to provide the best of both? Its not that great having two env drivers that have opposite requirements but I certainly don't want to change one to make them consistent it it will break boards.
Tim
PATCH 1/1 env_mmc: avoid stack allocation for env
Quoted 17 lines · Tim Harvey
Quoted 8 lines · Tom Rini
Quoted 6 lines · Marek Vasut
Quoted 2 lines · Tim Harvey
Allocating space for temporary env on the stack makes
env_relocate_spec()unsuitable for SPL environments which have very little stack.Well yeah, but what if you don't have malloc area ? I'd expect that the be the case in SPL quite often.
Quoted 7 lines
OK, hold up. We went through this a while back which is why things are how they are today. First, we have things setup today such that you can throw stack (at the point we do env in SPL) into DDR. This means we can keep doing things the way they are. You can take a look at
include/configs/am335x_evm.hand whereCONFIG_EMMC_BOOTis set, that's how we do what it looks like you're trying to do on imx6 but on TI am335x.
Quoted 5 lines
Yes, I'm doing this on Gateworks Ventana (board/gateworks/gw_ventana) based on IMX6 which has a limmited stack size during SPL. I don't see anything magic in
include/configs/am335x_evm.hthat catches my attention. Do you know where the code is that lets you point the stack to DDR? It sounds like that's what I need.
Ah oops. Kconfig, we use Kconfig now :) configs/am335x_evm_defconfig:CONFIG_SPL_STACK_R=y configs/am335x_evm_defconfig:CONFIG_SPL_STACK_R_ADDR=0x82000000
That's moving stack to DDR and then grabbing 0x82000000 for stack (base
+ 0x02000000 which is not too high, not too low, not likely to stomp on the kernel).
Quoted 7 lines
This sounds like there could be some boards using nand that rely on malloc (that's where I got the inspiration from for this) and others using mmc that rely on a decent size stack. I wonder if there is a #define that we can base off of to provide the best of both? Its not that great having two env drivers that have opposite requirements but I certainly don't want to change one to make them consistent it it will break boards.
My first guess is that NAND should also be converted to DDR not stack (I too found the NAND example, switched MMC to it, and then Wolfgang/others pointed out that really stack is where this kind of allocation should be, iirc, but then didn't get a chance to dig back at NAND).
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150512/3a450df9/attachment.sig>
PATCH 1/1 env_mmc: avoid stack allocation for env
Quoted 24 lines · Tom Rini
Quoted 17 lines · Tim Harvey
Quoted 8 lines · Tom Rini
Quoted 6 lines · Marek Vasut
Quoted 2 lines · Tim Harvey
Allocating space for temporary env on the stack makes
env_relocate_spec()unsuitable for SPL environments which have very little stack.Well yeah, but what if you don't have malloc area ? I'd expect that the be the case in SPL quite often.
Quoted 7 lines
OK, hold up. We went through this a while back which is why things are how they are today. First, we have things setup today such that you can throw stack (at the point we do env in SPL) into DDR. This means we can keep doing things the way they are. You can take a look at
include/configs/am335x_evm.hand whereCONFIG_EMMC_BOOTis set, that's how we do what it looks like you're trying to do on imx6 but on TI am335x.Quoted 5 lines
Yes, I'm doing this on Gateworks Ventana (board/gateworks/gw_ventana) based on IMX6 which has a limmited stack size during SPL. I don't see anything magic in
include/configs/am335x_evm.hthat catches my attention. Do you know where the code is that lets you point the stack to DDR? It sounds like that's what I need.
Quoted 7 lines
Ah oops.
Kconfig, we useKconfignow :) configs/am335x_evm_defconfig:CONFIG_SPL_STACK_R=y configs/am335x_evm_defconfig:CONFIG_SPL_STACK_R_ADDR=0x82000000That's moving stack to DDR and then grabbing
0x82000000for stack (base
+0x02000000which is not too high, not too low, not likely to stomp on the kernel).
thats strange... common/spl/spl.c uses CONFIG_SPL_STACK_R as the address not CONFIG_SPL_STACK_R_ADDR - how can that even compile?
http://git.denx.de/?p=u-boot.git;a=blob;f=common/spl/spl.c;#l324
Quoted 9 lines
Quoted 8 lines
This sounds like there could be some boards using nand that rely on malloc (that's where I got the inspiration from for this) and others using mmc that rely on a decent size stack. I wonder if there is a #define that we can base off of to provide the best of both? Its not that great having two env drivers that have opposite requirements but I certainly don't want to change one to make them consistent it it will break boards.
Quoted 4 lines
My first guess is that NAND should also be converted to DDR not stack (I too found the NAND example, switched MMC to it, and then Wolfgang/others pointed out that really stack is where this kind of allocation should be, iirc, but then didn't get a chance to dig back at NAND).
You said that backwards right? You mean nand env should be converted to stack not dram.
How do we do that without risking the chance of breaking boards that don't have CONFIG_SPL_STACK_R? Wouldn't you need to implement both around a #define to not cause breakage?
Tim
PATCH 1/1 env_mmc: avoid stack allocation for env
Quoted 29 lines · Tim Harvey
Quoted 28 lines · Tom Rini
Quoted 17 lines · Tim Harvey
Quoted 8 lines · Tom Rini
Quoted 6 lines · Marek Vasut
Quoted 2 lines · Tim Harvey
Allocating space for temporary env on the stack makes
env_relocate_spec()unsuitable for SPL environments which have very little stack.Well yeah, but what if you don't have malloc area ? I'd expect that the be the case in SPL quite often.
Quoted 7 lines
OK, hold up. We went through this a while back which is why things are how they are today. First, we have things setup today such that you can throw stack (at the point we do env in SPL) into DDR. This means we can keep doing things the way they are. You can take a look at
include/configs/am335x_evm.hand whereCONFIG_EMMC_BOOTis set, that's how we do what it looks like you're trying to do on imx6 but on TI am335x.Quoted 5 lines
Yes, I'm doing this on Gateworks Ventana (board/gateworks/gw_ventana) based on IMX6 which has a limmited stack size during SPL. I don't see anything magic in
include/configs/am335x_evm.hthat catches my attention. Do you know where the code is that lets you point the stack to DDR? It sounds like that's what I need.Ah oops.
Kconfig, we useKconfignow :) configs/am335x_evm_defconfig:CONFIG_SPL_STACK_R=y configs/am335x_evm_defconfig:CONFIG_SPL_STACK_R_ADDR=0x82000000
Quoted 8 lines
Quoted 3 lines
That's moving stack to DDR and then grabbing
0x82000000for stack (base
+0x02000000which is not too high, not too low, not likely to stomp on the kernel).thats strange...
common/spl/spl.cusesCONFIG_SPL_STACK_Ras the address notCONFIG_SPL_STACK_R_ADDR- how can that even compile?http://git.denx.de/?p=u-boot.git;a=blob;f=common/spl/spl.c;#l324
Tom,
I don't really understand the CONFIG_SPL_STACK_R usage at all. The only thing that uses CONFIG_SPL_STACK_R is spl_relocate_stack_gd which is called from arch/arm/lib/crt0.S 'after' board_init_f() is called, which will never return for SPL because we loaded and jumped to u-boot.img.
How is this working for the am335x stuff?
Tim
PATCH 1/1 env_mmc: avoid stack allocation for env
Hi,
Quoted 41 lines · Tim Harvey
Quoted 29 lines · Tim Harvey
Quoted 28 lines · Tom Rini
Quoted 17 lines · Tim Harvey
Quoted 8 lines · Tom Rini
Quoted 6 lines · Marek Vasut
Quoted 2 lines · Tim Harvey
Allocating space for temporary env on the stack makes
env_relocate_spec()unsuitable for SPL environments which have very little stack.Well yeah, but what if you don't have malloc area ? I'd expect that the be the case in SPL quite often.
Quoted 7 lines
OK, hold up. We went through this a while back which is why things are how they are today. First, we have things setup today such that you can throw stack (at the point we do env in SPL) into DDR. This means we can keep doing things the way they are. You can take a look at
include/configs/am335x_evm.hand whereCONFIG_EMMC_BOOTis set, that's how we do what it looks like you're trying to do on imx6 but on TI am335x.Quoted 5 lines
Yes, I'm doing this on Gateworks Ventana (board/gateworks/gw_ventana) based on IMX6 which has a limmited stack size during SPL. I don't see anything magic in
include/configs/am335x_evm.hthat catches my attention. Do you know where the code is that lets you point the stack to DDR? It sounds like that's what I need.Ah oops.
Kconfig, we useKconfignow :) configs/am335x_evm_defconfig:CONFIG_SPL_STACK_R=y configs/am335x_evm_defconfig:CONFIG_SPL_STACK_R_ADDR=0x82000000Quoted 8 lines
Quoted 3 lines
That's moving stack to DDR and then grabbing
0x82000000for stack (base
+0x02000000which is not too high, not too low, not likely to stomp on the kernel).thats strange...
common/spl/spl.cusesCONFIG_SPL_STACK_Ras the address notCONFIG_SPL_STACK_R_ADDR- how can that even compile?http://git.denx.de/?p=u-boot.git;a=blob;f=common/spl/spl.c;#l324
Tom,
Quoted 7 lines
I don't really understand the
CONFIG_SPL_STACK_Rusage at all. The only thing that usesCONFIG_SPL_STACK_Risspl_relocate_stack_gdwhich is called fromarch/arm/lib/crt0.S'after'board_init_f()is called, which will never return for SPL because we loaded and jumped to u-boot.img.How is this working for the am335x stuff?
Tom just forwarded me this thread. There is definitely something missing upstream compared to my local branch. I'll take a look and see what I missed.
Regards,
Simon
PATCH 1/1 env_mmc: avoid stack allocation for env
Hi,
Quoted 50 lines · Simon Glass
Hi,
Quoted 47 lines · Tim Harvey
Quoted 29 lines · Tim Harvey
Quoted 28 lines · Tom Rini
Quoted 17 lines · Tim Harvey
Quoted 8 lines · Tom Rini
Quoted 6 lines · Marek Vasut
Quoted 2 lines · Tim Harvey
Allocating space for temporary env on the stack makes
env_relocate_spec()unsuitable for SPL environments which have very little stack.Well yeah, but what if you don't have malloc area ? I'd expect that the be the case in SPL quite often.
Quoted 7 lines
OK, hold up. We went through this a while back which is why things are how they are today. First, we have things setup today such that you can throw stack (at the point we do env in SPL) into DDR. This means we can keep doing things the way they are. You can take a look at
include/configs/am335x_evm.hand whereCONFIG_EMMC_BOOTis set, that's how we do what it looks like you're trying to do on imx6 but on TI am335x.Quoted 5 lines
Yes, I'm doing this on Gateworks Ventana (board/gateworks/gw_ventana) based on IMX6 which has a limmited stack size during SPL. I don't see anything magic in
include/configs/am335x_evm.hthat catches my attention. Do you know where the code is that lets you point the stack to DDR? It sounds like that's what I need.Ah oops.
Kconfig, we useKconfignow :) configs/am335x_evm_defconfig:CONFIG_SPL_STACK_R=y configs/am335x_evm_defconfig:CONFIG_SPL_STACK_R_ADDR=0x82000000Quoted 8 lines
Quoted 3 lines
That's moving stack to DDR and then grabbing
0x82000000for stack (base
+0x02000000which is not too high, not too low, not likely to stomp on the kernel).thats strange...
common/spl/spl.cusesCONFIG_SPL_STACK_Ras the address notCONFIG_SPL_STACK_R_ADDR- how can that even compile?http://git.denx.de/?p=u-boot.git;a=blob;f=common/spl/spl.c;#l324
Tom,
I don't really understand the
CONFIG_SPL_STACK_Rusage at all. The only thing that usesCONFIG_SPL_STACK_Risspl_relocate_stack_gdwhich is called fromarch/arm/lib/crt0.S'after'board_init_f()is called, which will never return for SPL because we loaded and jumped to u-boot.img.
Quoted 5 lines
Quoted 1 line
How is this working for the am335x stuff?
Tom just forwarded me this thread. There is definitely something missing upstream compared to my local branch. I'll take a look and see what I missed.
It should say CONFIG_SPL_STACK_R_ADDR instead of CONFIG_SPL_STACK_R
As to the question about why CONFIG_SPL_STACK_R does not produce a compile error, it is defined to 1 in autoconf.h, which is a valid number. With the current value it sets the stack to 0xffffff28 which seems invalid to me (it is in reserved memory).
It's a little bit of a mystery as to why this works on my beaglebone black.
Anyway I have sent a patch to correct it.
There are instructions in the README for using CONFIG_SPL_STACK_R, and for the new board init flow. Basically you need to return normally from your SPL board_init_f(). The code in crt0.S will then change the SPL stack to CONFIG_SPL_STACK_R_ADDR which should be in SDRAM and everything should be good.
So perhaps what you are missing is that board_init_f() is now expected to return. It must not load U-Boot at this stage. That is supposed to happen in board_init_r().
Regards,
Simon
PATCH 1/1 env_mmc: avoid stack allocation for env
Quoted 7 lines · Simon Glass
Hi,
Quoted 4 lines · Simon Glass
Hi,
Quoted 1 line · Tim Harvey
On Wed, May 13, 2015 at 12:58 PM, Tim Harvey <[email protected]> wrote:
<snip
Quoted 15 lines
Quoted 9 lines
Quoted 9 lines
Tom,
I don't really understand the
CONFIG_SPL_STACK_Rusage at all. The only thing that usesCONFIG_SPL_STACK_Risspl_relocate_stack_gdwhich is called fromarch/arm/lib/crt0.S'after'board_init_f()is called, which will never return for SPL because we loaded and jumped to u-boot.img.Quoted 5 lines
Quoted 1 line
How is this working for the am335x stuff?
Tom just forwarded me this thread. There is definitely something missing upstream compared to my local branch. I'll take a look and see what I missed.
Quoted 6 lines
It should say
CONFIG_SPL_STACK_R_ADDRinstead ofCONFIG_SPL_STACK_RAs to the question about why
CONFIG_SPL_STACK_Rdoes not produce a compile error, it is defined to 1 inautoconf.h, which is a valid number. With the current value it sets the stack to0xffffff28which seems invalid to me (it is in reserved memory).
ok - makes sense.... I thought I was going crazy.
Quoted 2 lines
It's a little bit of a mystery as to why this works on my beaglebone black.
probably just lucky address wrapping
Quoted 9 lines
Anyway I have sent a patch to correct it.
There are instructions in the README for using
CONFIG_SPL_STACK_R, and for the new board init flow. Basically you need to return normally from your SPLboard_init_f(). The code incrt0.Swill then change the SPL stack toCONFIG_SPL_STACK_R_ADDRwhich should be in SDRAM and everything should be good.
Quoted 3 lines
So perhaps what you are missing is that
board_init_f()is now expected to return. It must not load U-Boot at this stage. That is supposed to happen inboard_init_r().
I completely missed your recent commit regarding the stack relocation (db910353a126d84fe8dff7a694ea792f50fcfb6a) - I must admit I don't have time to keep up-to-date on the maillist.
As its a new thing that spl board_init_f should 'not' call board_init_r, there are a lot of spl files that still call it directly (as well as the weak implementation of board_init_f in arch/arm/lib/spl.c). Of course, as I found out you really don't need to remove that call unless you want to use stack relocation. The documentation in arch/arm/lib/crt0.S is now out of date and doesn't mention the fact that for SPL you should not call board_init_f - perhaps this documentation should be removed and the README referred to (or visa versa).
Thanks for clearing this up.
Tim
PATCH 1/1 env_mmc: avoid stack allocation for env
Hi Tim,
Quoted 65 lines · Tim Harvey
Quoted 7 lines · Simon Glass
Hi,
Quoted 4 lines · Simon Glass
Hi,
Quoted 1 line · Tim Harvey
On Wed, May 13, 2015 at 12:58 PM, Tim Harvey <[email protected]> wrote:
<snip
Quoted 15 lines
Quoted 9 lines
Quoted 9 lines
Tom,
I don't really understand the
CONFIG_SPL_STACK_Rusage at all. The only thing that usesCONFIG_SPL_STACK_Risspl_relocate_stack_gdwhich is called fromarch/arm/lib/crt0.S'after'board_init_f()is called, which will never return for SPL because we loaded and jumped to u-boot.img.Quoted 5 lines
Quoted 1 line
How is this working for the am335x stuff?
Tom just forwarded me this thread. There is definitely something missing upstream compared to my local branch. I'll take a look and see what I missed.
Quoted 6 lines
It should say
CONFIG_SPL_STACK_R_ADDRinstead ofCONFIG_SPL_STACK_RAs to the question about why
CONFIG_SPL_STACK_Rdoes not produce a compile error, it is defined to 1 inautoconf.h, which is a valid number. With the current value it sets the stack to0xffffff28which seems invalid to me (it is in reserved memory).ok - makes sense.... I thought I was going crazy.
Quoted 2 lines
It's a little bit of a mystery as to why this works on my beaglebone black.
probably just lucky address wrapping
Quoted 9 lines
Anyway I have sent a patch to correct it.
There are instructions in the README for using
CONFIG_SPL_STACK_R, and for the new board init flow. Basically you need to return normally from your SPLboard_init_f(). The code incrt0.Swill then change the SPL stack toCONFIG_SPL_STACK_R_ADDRwhich should be in SDRAM and everything should be good.Quoted 3 lines
So perhaps what you are missing is that
board_init_f()is now expected to return. It must not load U-Boot at this stage. That is supposed to happen inboard_init_r().I completely missed your recent commit regarding the stack relocation (
db910353a126d84fe8dff7a694ea792f50fcfb6a) - I must admit I don't have time to keep up-to-date on the maillist.As its a new thing that spl
board_init_fshould 'not' callboard_init_r, there are a lot of spl files that still call it directly (as well as the weak implementation ofboard_init_finarch/arm/lib/spl.c). Of course, as I found out you really don't need to remove that call unless you want to use stack relocation. The documentation inarch/arm/lib/crt0.Sis now out of date and doesn't mention the fact that for SPL you should not callboard_init_f- perhaps this documentation should be removed and the README referred to (or visa versa).
Quoted 3 lines
Thanks for clearing this up.
Tim
Just to update this thread, I sent a patch for this:
http://patchwork.ozlabs.org/patch/502840/
Regards,
Simon
PATCH 1/1 env_mmc: avoid stack allocation for env
In reply to Marek VasutQuoted 9 lines · Marek Vasut
Quoted 2 lines · Tim Harvey
Allocating space for temporary env on the stack makes
env_relocate_spec()unsuitable for SPL environments which have very little stack.Well yeah, but what if you don't have malloc area ? I'd expect that the be the case in SPL quite often.
Best regards,
Marek Vasut
Marek,
I suppose it depends on when in SPL you need env. I assume memory controller is about the first thing done after things like iomux. If this is a problem then at least nand env (env_nand.c) is broken too as that's where I got my inspiration for this after I realized I was hanging due to not having enough stack space.
It looks like Tom may have a solution that I'll look at.
Tim