-
Notifications
You must be signed in to change notification settings - Fork 421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fel-sdboot: Fix header corruption workaround #52
Conversation
This is not a good fix because there is a prologue code generated by the compiler before the inline assembly block. The #44 code resolves this problem by using a special naked function named "start", which goes to a special ".start" section and is placed in the very beginning by the linker script. |
Oh. That didn't happen with my toolchain - but i guess it's highly version-dependent. I'll adopt the model from And wouldn't it be sufficient if we declare this |
I can reproduce the prologue problem with armv7a-hardfloat-linux-gnueabi-gcc-4.8.3. But it seems that void __attribute__((naked)) _start(void)
{
/* ... */
} would already solve this? |
If you mean to just label the current "main" function as naked, then have a look at https://gcc.gnu.org/onlinedocs/gcc/ARM-Function-Attributes.html#ARM-Function-Attributes
Mixing C and assembly code is not allowed in naked functions. And regarding having a special section, the order of functions is generally not guaranteed. So we could end up with the "main" function before the "start" function in the resulting binary. |
0ae03e9
to
a7f7097
Compare
We'd soon end up with more declarations / framework than actual code for this little bugger. 😝 In the end I decided to just rewrite the thing in assembly... I now get sunxi-tools # r2 -a arm -s 0x20 -c 'pd 12' -q fel-sdboot.sunxi
,=< 0x00000020 020000ea b 0x30
| 0x00000024 00f020e3 nop
| 0x00000028 00f020e3 nop
| 0x0000002c 00f020e3 nop
`-> 0x00000030 100f11ee mrc p15, 0, r0, c1, c0, 0
0x00000034 020a10e3 tst r0, 0x2000
0x00000038 20e0a003 moveq lr, 0x20
0x0000003c 00e01f15 ldrne lr, [pc, -0] ; [0x44:4]=0xffff0020 ; 'D'
0x00000040 1eff2fe1 bx lr
0x00000044 2000ffff invalid
0x00000048 00000000 andeq r0, r0, r0
0x0000004c 00000000 andeq r0, r0, r0 with both gcc 4.8.x and 4.9.x; and have tested the resulting file (via SD card) successfully on Banana Pi (A20) and Pine64+ (A64). |
e2bbc9d
to
02ff098
Compare
Thanks, this makes sense. Not touching the stack at all is another bonus (reduces the possibility of any nasty surprises with future SoCs). Could you please also update the binary in the "bin" directory?
|
Sure. We might also want to have a peek at |
397f298
to
39c35cd
Compare
Now that we have a better understanding of what's causing the issue that prevented entering FEL sometimes, we can adjust the workaround code to a proper solution, i.e. skip over the problematic location. Since the code amounts to less than a dozen ARM instructions, I've decided to rewrite it as assembly code - fel-sdboot.S replaces the former fel-sdboot.c. The commit also includes a new binary (bin/fel-sdboot.sunxi) with these changes. Signed-off-by: Bernhard Nortmann <[email protected]> Reviewed-by: Siarhei Siamashka <[email protected]>
39c35cd
to
17164d8
Compare
Now that we have a better understanding of what's causing the issue that prevented entering FEL sometimes, we can adjust the workaround code to a proper solution.
This is related to #48.
Changes in v1: Initial version
Changes in v2:
bin/fel-sdboot.sunxi
Changes in v3: