-
Notifications
You must be signed in to change notification settings - Fork 3k
bootloader: Fix LPC55S69 bootloader segmentation #10791
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
bootloader: Fix LPC55S69 bootloader segmentation #10791
Conversation
@hugueskamba, thank you for your changes. |
@@ -57,15 +57,19 @@ __ram_vector_table__ = 1; | |||
#define MBED_BOOT_STACK_SIZE 0x400 | |||
#endif | |||
|
|||
#if !defined(MBED_NVIC_SIZE) | |||
#define MBED_NVIC_SIZE 0x130 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be defined as NVIC_NUM_VECTORS * 4 to avoid magic numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an 8-byte alignment requirement, if I recall correctly, so just using NVIC_NUM_VECTORS * 4
may not quite be magic enough in general. Not sure if GCC has a handy alignment built-in to help you here. I know the ARM linker would let you use AlignExpr(NVIC_NUM_VECTORS * 4,8)
.
Sure, it happens to be aligned on this platform, but if someone were to copy the general-looking implementation to another...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an 8-byte alignment requirement, if I recall correctly, so just using
NVIC_NUM_VECTORS * 4
may not quite be magic enough in general. Not sure if GCC has a handy alignment built-in to help you here. I know the ARM linker would let you useAlignExpr(NVIC_NUM_VECTORS * 4,8)
.Sure, it happens to be aligned on this platform, but if someone were to copy the general-looking implementation to another...
@kjbracey-arm
The mention of the image start address alignment I saw in the user manual is a requirement for a 32-bit word alignment (see linked user manual on page 153).
Should it not be AlignExpr(NVIC_NUM_VECTORS * 4, 4)
instead for the ARM toolchain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Individual chips might permit things to be 4-byte aligned, but architecturally regions are supposed to be 8-byte aligned these days. The ARMC6 toolchain is only letting you get away with 4-byte alignment because --legacyalign
is being passed.
There are certain instructions that only work or work faster with 8-byte alignment that the compiler may wish to use.
See other PRs #8013 and #10373, correcting platforms to 8-byte alignment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @kjbracey-arm.
I will modify the ARM toolchain linker file. However, for GCC I believe it is handled with . = ALIGN(8);
which is already present in the section definitions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that probably works. Crosscheck how other implementations do it, including in those PRs, there are a couple of common patterns (including hard-coding alignment to 8 by hand in quite a few).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable to me! Not an expert on this platform, but your changes seem sane 😄
@@ -57,15 +57,19 @@ __ram_vector_table__ = 1; | |||
#define MBED_BOOT_STACK_SIZE 0x400 | |||
#endif | |||
|
|||
#if !defined(MBED_NVIC_SIZE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the define MBED_NVIC_SIZE used only for the GCC linker script?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
@hugueskamba please take a look at Kevin's comments |
923c1f2
to
4e735a1
Compare
As the build tool in mbed-os 5.13 cannot appropriately deal with a segmented bootloader when combining it with an application, this commit adjusts the size reserved for interrupts (via the linker file) to avoid a bootloader segmentation due to an unpopulated ROM area. The microcontroller has a total of 60 vector interrupts + 16 exception handlers. The allocated ROM flash for interrupts should be (60 + 16) x word size in bytes = 76 x 4 = 304 = 0x130. This commit changes the interrupt reserved space from 0x140 to 0x130.
923c1f2
to
b0804c4
Compare
The last force used the built-in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would have done it by locking in the alignment to the "interrupts_size" define itself, but this is fine.
Not relevant to this change, but I see that the RAM interrupt table size is fixed at 0x200 - there's no reason why that shouldn't be the size as the ROM region. The base address needs to be 0x200 aligned (if the table is 0x1xx-sized), but you could start the static data immediately after it. You could adjust that if it gets revisited at any point.
Ci started |
@kjbracey-arm Could you please raise a ticket so we don't forget this? |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
Description
As the build tool in mbed-os 5.13 cannot appropriately deal with a segmented
bootloader when combining it with an application, this commit adjusts the
size reserved for interrupts (via the linker file) to avoid a bootloader
segmentation due to an unpopulated ROM area.
The microcontroller has a total of 60 vector interrupts + 16 exception
handlers. The allocated ROM flash for interrupts should be (60 + 16) x word
size in bytes = 76 x 4 = 304 = 0x130.
This commit changes the interrupt reserved space from 0x140 to 0x130.
Pull request type
Reviewers
@bridadan @theotherjimmy
Fixes internal issue IOTCORE-1149