Skip to content

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

Merged

Conversation

hugueskamba
Copy link
Collaborator

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

[x] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@bridadan @theotherjimmy

Fixes internal issue IOTCORE-1149

@ciarmcom
Copy link
Member

ciarmcom commented Jun 7, 2019

@hugueskamba, thank you for your changes.
@bridadan @MarceloSalazar @maclobdell @theotherjimmy @ARMmbed/mbed-os-maintainers please review.

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent. Thanks

Copy link
Contributor

@kjbracey kjbracey Jun 18, 2019

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...

Copy link
Collaborator Author

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...

@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?

Copy link
Contributor

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.

Copy link
Collaborator Author

@hugueskamba hugueskamba Jun 26, 2019

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.

Copy link
Contributor

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).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@bridadan bridadan left a 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)
Copy link
Contributor

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?

Copy link
Collaborator Author

@hugueskamba hugueskamba Jun 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@mmahadevan108 mmahadevan108 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@adbridge
Copy link
Contributor

@hugueskamba please take a look at Kevin's comments

@hugueskamba hugueskamba force-pushed the fix-lpc55s69-bootloader-segmentation branch from 923c1f2 to 4e735a1 Compare June 24, 2019 13:57
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.
@hugueskamba hugueskamba force-pushed the fix-lpc55s69-bootloader-segmentation branch from 923c1f2 to b0804c4 Compare June 26, 2019 12:55
@hugueskamba
Copy link
Collaborator Author

The last force used the built-in AlignExpr to align the text region at the 8-byte boundary and squashed all commits of this branch.

Copy link
Contributor

@kjbracey kjbracey left a 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.

@0xc0170
Copy link
Contributor

0xc0170 commented Jun 26, 2019

Ci started

@hugueskamba
Copy link
Collaborator Author

hugueskamba commented Jun 26, 2019

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.

@kjbracey-arm Could you please raise a ticket so we don't forget this?

@mbed-ci
Copy link

mbed-ci commented Jun 26, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 1
Build artifacts

@hugueskamba hugueskamba deleted the fix-lpc55s69-bootloader-segmentation branch July 30, 2019 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants