kirkwood: CONFIG_SYS_INIT_SP_ADDR wrong?
Hi Prafulla,
In commit 0b20ed76 (Kirkwood: Changes specific to ARM relocation support), you set CONFIG_SYS_INIT_SP_ADDR to 0xC8012000 which is supposed to lie within the internal Security SRAM.
However, the Kirkwood Functional Specification (chapter 2.13 Default Address Map) and arch/arm/include/asm/arch-kirkwood/cpu.h suggest that the Security SRAM is mapped to 0xC8010000. Given the size of 2 KiB, the upper end would be 0xC8010800.
So I am wondering whether the value 0xC8012000 works at all.
In addition, "CONFIG_SYS_INIT_SP_ADDR should point to RAM with enough space for global data above and enough stack space below", as Reinhard Meyer points out in:
http://article.gmane.org/gmane.comp.boot-loaders.u-boot/87490
Since you use quite a large print buffer (CONFIG_SYS_PBSIZE > 1 KiB), I assume something like 0xC8010700 might work.
@Heiko: include/configs/km_arm.h may have the same problem.
Best regards,
Daniel
Hello Daniel,
Quoted 15 lines · Daniel Hobi
In commit
0b20ed76(Kirkwood: Changes specific to ARM relocation support), you setCONFIG_SYS_INIT_SP_ADDRto0xC8012000which is supposed to lie within the internal Security SRAM.However, the Kirkwood Functional Specification (chapter 2.13 Default Address Map) and
arch/arm/include/asm/arch-kirkwood/cpu.hsuggest that the Security SRAM is mapped to0xC8010000. Given the size of 2 KiB, the upper end would be0xC8010800.So I am wondering whether the value
0xC8012000works at all.In addition, "
CONFIG_SYS_INIT_SP_ADDRshould point to RAM with enough space for global data above and enough stack space below", as Reinhard Meyer points out in:
Quoted 6 lines
http://article.gmane.org/gmane.comp.boot-loaders.u-boot/87490
Since you use quite a large print buffer (
CONFIG_SYS_PBSIZE> 1 KiB), I assume something like0xC8010700might work.@Heiko:
include/configs/km_arm.hmay have the same problem.
I made a patch for this, see:
http://lists.denx.de/pipermail/u-boot/2010-November/081275.html
but you are right, looking in Kirkwood Functional Specification (chapter 2.13 Default Address Map) internal Security SRAM is mapped from 0xc8010000-0xc801ffff with the note, that only 2kb sram are implemented) ... so your question is right, why this is working ... I just can say, it works on the suen3 ... Prafulla, do you have an idea for this (maybe the sram is mirrored?)
bye,
Heiko
Signature · 2 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Hi Heiko,
Quoted 6 lines · Heiko Schocher
Quoted 1 line · Daniel Hobi
@Heiko:
include/configs/km_arm.hmay have the same problem.I made a patch for this, see:
http://lists.denx.de/pipermail/u-boot/2010-November/081275.html
Reading your patch, I noticed that we don't align the early stack pointer to an 8-byte boundary which may lead to the problem described here:
http://article.gmane.org/gmane.comp.boot-loaders.u-boot/69342
Since you seem to be the author of the relevant assembly code, could you please prepare a fix (adding "bic sp, sp, #7")?
Best regards,
Daniel
Hello Daniel,
Quoted 5 lines · Daniel Hobi
Hi Heiko,
Quoted 2 lines · Heiko Schocher
Quoted 1 line · Daniel Hobi
@Heiko:
include/configs/km_arm.hmay have the same problem.
Quoted 8 lines
Quoted 3 lines
I made a patch for this, see:
http://lists.denx.de/pipermail/u-boot/2010-November/081275.html
Reading your patch, I noticed that we don't align the early stack pointer to an 8-byte boundary which may lead to the problem described here:
http://article.gmane.org/gmane.comp.boot-loaders.u-boot/69342
This article is from 2009-10-06 06:44:22 GMT (1 year, 5 weeks, 2 hours and 15 minutes ago)
Quoted 2 lines
Since you seem to be the author of the relevant assembly code, could you please prepare a fix (adding "bic sp, sp, #7")?
We do this, since relocation is introduced, now here:
line 405
bye,
Heiko
Signature · 2 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Hi Heiko,
Quoted 6 lines · Heiko Schocher
Quoted 4 lines · Daniel Hobi
Reading your patch, I noticed that we don't align the early stack pointer to an 8-byte boundary which may lead to the problem described here:
http://article.gmane.org/gmane.comp.boot-loaders.u-boot/69342
Quoted 8 lines
This article is from 2009-10-06 06:44:22 GMT (1 year, 5 weeks, 2 hours and 15 minutes ago)
Quoted 2 lines
Since you seem to be the author of the relevant assembly code, could you please prepare a fix (adding "bic sp, sp, #7")?
We do this, since relocation is introduced, now here:
[link to
arch/arm/lib/board.c]
Yes, I know.
But you also added assembly code to setup the initial stack pointer in arch/arm/cpu/*/start.S (ie commit ab86f72c for arm926ejf) which reads:
/* Set stackpointer in internal RAM to call board_init_f */ call_board_init_f:
ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
CONFIG_SYS_INIT_SP_ADDR may not be aligned properly, especially with your latest patch to km_arm.h:
#define CONFIG_SYS_INIT_SP_ADDR (0xC8012000 - GENERATED_GBL_DATA_SIZE)
Best regards,
Daniel
Hello Daniel,
Quoted 19 lines · Daniel Hobi
Quoted 4 lines · Heiko Schocher
Quoted 3 lines · Daniel Hobi
Reading your patch, I noticed that we don't align the early stack pointer to an 8-byte boundary which may lead to the problem described here:
Quoted 8 lines
This article is from 2009-10-06 06:44:22 GMT (1 year, 5 weeks, 2 hours and 15 minutes ago)
Quoted 2 lines
Since you seem to be the author of the relevant assembly code, could you please prepare a fix (adding "bic sp, sp, #7")?
We do this, since relocation is introduced, now here:
[link to
arch/arm/lib/board.c]Yes, I know.
But you also added assembly code to setup the initial stack pointer in
arch/arm/cpu/*/start.S(ie commitab86f72cfor arm926ejf) which reads:
Quoted 8 lines
/* Set stackpointer in internal RAM to call
board_init_f*/call_board_init_f:ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
CONFIG_SYS_INIT_SP_ADDRmay not be aligned properly, especially with your latest patch tokm_arm.h:#define
CONFIG_SYS_INIT_SP_ADDR(0xC8012000-GENERATED_GBL_DATA_SIZE)
Ah, good catch.
Then we should add this alignment into the generation of GENERATED_GBL_DATA_SIZE.
bye,
Heiko
Signature · 2 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Hi Heiko,
Quoted 11 lines · Heiko Schocher
Quoted 10 lines · Daniel Hobi
But you also added assembly code to setup the initial stack pointer in
arch/arm/cpu/*/start.S(ie commitab86f72cfor arm926ejf) which reads:/* Set stackpointer in internal RAM to call
board_init_f*/call_board_init_f:ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
CONFIG_SYS_INIT_SP_ADDRmay not be aligned properly, especially with your latest patch tokm_arm.h:
Quoted 6 lines
Quoted 1 line
#define
CONFIG_SYS_INIT_SP_ADDR(0xC8012000-GENERATED_GBL_DATA_SIZE)Ah, good catch.
Then we should add this alignment into the generation of
GENERATED_GBL_DATA_SIZE.
Hm? The stack pointer needs alignment, not GENERATED_GBL_DATA_SIZE. What happens if I define:
#define CONFIG_SYS_INIT_SP_ADDR (0xC8012004 - GENERATED_GBL_DATA_SIZE)
Why not add alignment to start.S?
/* Set stackpointer in internal RAM to call board_init_f */ call_board_init_f:
ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
+ bic sp, sp, #7
Best regards,
Daniel
Le 10/11/2010 16:46, Daniel Hobi a ?crit :
Quoted 33 lines
Hi Heiko,
Quoted 11 lines · Heiko Schocher
Quoted 10 lines · Daniel Hobi
But you also added assembly code to setup the initial stack pointer in
arch/arm/cpu/*/start.S(ie commitab86f72cfor arm926ejf) which reads:/* Set stackpointer in internal RAM to call
board_init_f*/call_board_init_f:ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
CONFIG_SYS_INIT_SP_ADDRmay not be aligned properly, especially with your latest patch tokm_arm.h:Quoted 6 lines
Quoted 1 line
#define
CONFIG_SYS_INIT_SP_ADDR(0xC8012000-GENERATED_GBL_DATA_SIZE)Ah, good catch.
Then we should add this alignment into the generation of
GENERATED_GBL_DATA_SIZE.Hm? The stack pointer needs alignment, not
GENERATED_GBL_DATA_SIZE. What happens if I define:#define
CONFIG_SYS_INIT_SP_ADDR(0xC8012004-GENERATED_GBL_DATA_SIZE)Why not add alignment to
start.S?/* Set stackpointer in internal RAM to call
board_init_f*/call_board_init_f:
ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)(quoted diff) +1
-0+ bic sp, sp, #7
Quoted 2 lines
Best regards,
Daniel
Bad solution IMO: if the symbol is used elsewhere, one would have to always remember that it should be aligned down to a multiple of eight. We may not need to make it a generated constant, but we definitely need to make sure it is correctly aligned wherever it is used, e.g. by defining it as
#define CONFIG_SYS_INIT_SP_ADDR (0xC8012004-GENERATED_GBL_DATA_SIZE)&~7
(spacing squashed to avoid funny line breaks)
Amicalement,
Signature · 1 line
Albert.
Hello Daniel,
Quoted 9 lines · Daniel Hobi
Quoted 8 lines · Heiko Schocher
Quoted 7 lines · Daniel Hobi
But you also added assembly code to setup the initial stack pointer in
arch/arm/cpu/*/start.S(ie commitab86f72cfor arm926ejf) which reads:/* Set stackpointer in internal RAM to call
board_init_f*/call_board_init_f:ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
CONFIG_SYS_INIT_SP_ADDRmay not be aligned properly, especially with your latest patch tokm_arm.h:#define
CONFIG_SYS_INIT_SP_ADDR(0xC8012000-GENERATED_GBL_DATA_SIZE)Ah, good catch.
Then we should add this alignment into the generation of
GENERATED_GBL_DATA_SIZE.
looked in the generation of GENERATED_GBL_DATA_SIZE:
./lib/asm-offsets.c
/* Round up to make sure size gives nice stack alignment */
DEFINE(GENERATED_GBL_DATA_SIZE,
(sizeof(struct global_data)+15) & ~15);this is ok.
Quoted 4 lines
Hm? The stack pointer needs alignment, not
GENERATED_GBL_DATA_SIZE. What happens if I define:#define
CONFIG_SYS_INIT_SP_ADDR(0xC8012004-GENERATED_GBL_DATA_SIZE)
Indeed, that would be bad ... don;t do it ;-)
Review
Quoted 6 lines
Why not add alignment to
start.S?/* Set stackpointer in internal RAM to call
board_init_f*/call_board_init_f:(quoted diff) +1
-0ldr sp, =(CONFIG_SYS_INIT_SP_ADDR) + bic sp, sp, #7
Hmm.. because we do in board_init_f:
gd = (gd_t *) (CONFIG_SYS_INIT_SP_ADDR);
Hmm.. maybe we should call board_init_f with the info, where to find the stack, but this would be a change for all architectures, not only arm ...
opinions?
bye,
Heiko
Signature · 2 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Hi Albert and Heiko,
Quoted 11 lines · Heiko Schocher
Review
Quoted 6 lines · Daniel Hobi
Why not add alignment to
start.S?/* Set stackpointer in internal RAM to call
board_init_f*/call_board_init_f:(quoted diff) +1
-0ldr sp, =(CONFIG_SYS_INIT_SP_ADDR) + bic sp, sp, #7Hmm.. because we do in
board_init_f:gd = (
gd_t*) (CONFIG_SYS_INIT_SP_ADDR);
gd (struct global_data) does not require the same alignment as the stack pointer. If CONFIG_SYS_INIT_SP_ADDR is 4-byte aligned, but not 8-byte aligned, 4 bytes between these two are unused. If you care about that, just 8-byte align gd in the assignment above. It makes sense to at least 4-byte align gd anyway.
Quoted 3 lines
Hmm.. maybe we should call
board_init_fwith the info, where to find the stack, but this would be a change for all architectures, not only arm ...
We would tell board_init_f where to find the global_data, not the stack. If other architectures also use the same computation for stack (in start.S) and global_data (in board_init_f), this change should be considered.
Quoted 8 lines · Albert ARIBAUD
Bad solution IMO: if the symbol is used elsewhere, one would have to always remember that it should be aligned down to a multiple of eight. We may not need to make it a generated constant, but we definitely need to make sure it is correctly aligned wherever it is used, e.g. by defining it as
#define
CONFIG_SYS_INIT_SP_ADDR
(0xC8012004-GENERATED_GBL_DATA_SIZE)&~7
I think it's much less error-prone to align CONFIG_SYS_INIT_SP_ADDR wherever it is used. It should be used only at two places anyway: to initialize the early stack pointer and the global_data pointer.
As a reminder: it was extremely difficult the find the misaligned stack pointer (resulting in the patch from 2009-10-06) given the symptoms. And since you cannot expect board maintainers to spend an equal amount of time to solve this problem over and over again, we definitely need to align CONFIG_SYS_INIT_SP_ADDR where it is used, and not where it is defined.
Best regards,
Daniel
Dear Heiko Schocher,
Quoted 10 lines · In message <[email protected]> you wrote:
looked in the generation of
GENERATED_GBL_DATA_SIZE:
./lib/asm-offsets.c/* Round up to make sure size gives nice stack alignment */ DEFINE(GENERATED_GBL_DATA_SIZE, (sizeof(struct global_data)+15) & ~15);this is ok.
I know that I let me talk into adding this. It was a bad idea. Let's get rid of this and fix it properly instead.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de What the gods would destroy they first submit to an IEEE standards committee.
Dear Heiko Schocher,
Quoted 3 lines · In message <[email protected]> you wrote:
Then we should add this alignment into the generation of
GENERATED_GBL_DATA_SIZE.
No. GENERATED_GBL_DATA_SIZE is just a size. As you don't really know the alignment of the base address that GENERATED_GBL_DATA_SIZE is added to or substracted from, you cannot add the alignment requirements here.
This must be done where they are neede d- whichis also much better to make the code readable / understandable.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de He'd been wrong, there _was_ a light at the end of the tunnel, and it was a flamethrower. - Terry Pratchett, _Mort_