-
Notifications
You must be signed in to change notification settings - Fork 63
Use picolibc instead of newlib-nano #134
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
base: main
Are you sure you want to change the base?
Conversation
9cd8235
to
50a91d4
Compare
85833fd
to
01be64f
Compare
These are (finally) passing Zephyr tests using both SDK 0.17 and SDK 0.18-alpha4 (although each requires some additional changes which are wending their way upstream). I think they're ready for review and help getting them upstream. |
/* Reset current position for subsequent sections */ | ||
. = LOADADDR(.ER_CODE_SRAM) + SIZEOF(.ER_CODE_SRAM); |
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.
How did the linker get confused exactly? Is this really needed?
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.
. got set to LOADADDR instead of ADDR when building with binutils 2.43. I'm afraid that after spending several hours chasing this down, I didn't dig into the linker code to figure out precisely why that happened.
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've re-added this patch as it is necessary even with SDK 0.17.4.
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.
Had a chat with upstream about these (picolibc) changes. Let's keep them only in this fork until they're not needed anymore (TF-M is moving away from C library usage), in the next release or the one following it.
But it would be good to have someone who understands this a bit to review the changes. Don't know who that could be. cc @frkv @d3zd3z @ceolin @dleach02 @Vge0rge
Sounds good. I'll keep running tests as this series moves forward. This is not buildable using SDK 0.17.2 because of a last-minute oops in that release, but it should be buildable with the upcoming SDK 0.17.3. |
I recommend @wearyzen and @adeaarm give it a quick look from TF-M's perspective. The Clang/LLVM toolchain for TF-M was added with no dependency on libc and/or picolib in the core TF-M code, but you still see references to nano.specs in the GNUARM toolchain Zephyr, making this choice for GNUARM toolchain (this change), will take any penalty related to support, any security advisories etc... But the choice to go to picolibc is an active choice in the Zephyr community, and in extension it will impact any vendor who makes use of standard c library function in PSA crypto and PSA crypto driver build as well as in bootloaders... With regards to these commits, I think we should consider them to be marked as commits emitted from zephyr integration, unless they are possible to add upstream in the TF-M project... If they are out-of-tree patches required for Zephyr integration, they would need to be maintained across updated versions of TF-M in our fork |
Yeah this is something we've agreed on and I think just needs to be implemented (documenting the practice basically). In the meantime I don't think we can require that of anyone yet. |
True, TF-M plans to remove Additionally, you might want to consider these recent fixes in the scripts: |
Sounds like any libc-specific changes will be transient then, which will be nice. |
This adds linker script bits and compiler options so that trusted-firmware-m will build with picolibc. This has not been merged to the Zephyr trusted-firmware-m repository yet, that PR is zephyrproject-rtos/trusted-firmware-m#134 Signed-off-by: Keith Packard <[email protected]>
This adds linker script bits and compiler options so that trusted-firmware-m will build with picolibc. This has not been merged to the Zephyr trusted-firmware-m repository yet: zephyrproject-rtos/trusted-firmware-m#134 Signed-off-by: Keith Packard <[email protected]>
This adds linker script bits and compiler options so that trusted-firmware-m will build with picolibc. This has not been merged to the Zephyr trusted-firmware-m repository yet: zephyrproject-rtos/trusted-firmware-m#134 Signed-off-by: Keith Packard <[email protected]>
While trying to build the non-secure MPS4 board with this PR and Zephyr SDK 0.18.0-alpha4 we see below error:
Referring to the changes in this PR, I tried below patch and it seems to fix the issue:
I am not a linker script expert but if above change looks good then please let me know if you would like to include it in this PR. |
This adds linker script bits and compiler options so that trusted-firmware-m will build with picolibc. This has not been merged to the Zephyr trusted-firmware-m repository yet: zephyrproject-rtos/trusted-firmware-m#134 Signed-off-by: Keith Packard <[email protected]>
01be64f
to
a73e0d7
Compare
Use the pending module PR: zephyrproject-rtos/trusted-firmware-m#134 Signed-off-by: Keith Packard <[email protected]>
This adds linker script bits and compiler options so that trusted-firmware-m will build with picolibc. This has not been merged to the Zephyr trusted-firmware-m repository yet: zephyrproject-rtos/trusted-firmware-m#134 Signed-off-by: Keith Packard <[email protected]>
a73e0d7
to
a847492
Compare
This adds linker script bits and compiler options so that trusted-firmware-m will build with picolibc. This has not been merged to the Zephyr trusted-firmware-m repository yet: zephyrproject-rtos/trusted-firmware-m#134 Signed-off-by: Keith Packard <[email protected]>
1. Add picolibc bits to linker scripts. Picolibc uses thread local storage for unshared data, and the picolibc startup code relies on carefully constructed linker script that allocates one TLS block in RAM for applications that don't have explicit TLS support. The picolibc startup code also uses different symbols than the tf-m startup code. 2. Support picolibc stdio. There was already picolibc support code present in the library for the ARM LLVM toolchain. The conditionals which selected it have been changed to use __PICOLIBC__ instead of __clang_major__. 3. Add _exit stub. Code using assert or abort end up calling _exit through the picolibc signal handling code. 4. Switch to picolibc.specs. This is needed for toolchains which don't use picolibc by default, and can also be used without trouble in toolchains where picolibc is the default. Signed-off-by: Keith Packard <[email protected]>
a847492
to
8d8f341
Compare
When processing the .ER_CODE_SRAM section, the location counter is set to the VMA of that section, so after processing the next section will use that VMA instead of the next available address in the FLASH region. Reset the location counter to the next available FLASH address after processing this section will ensure that any subsequent FLASH data is placed in the correct location. This test fails without this patch: $ west build -p -b lpcxpresso55s69/lpc55s69/cpu0/ns \ samples/synchronization -T sample.kernel.synchronization .../ld: address 0x14003e84 of bin/tfm_s.axf section `.ER_TFM_CODE' is not within region `FLASH' .../ld: address 0x14005c20 of bin/tfm_s.axf section `.TFM_UNPRIV_CODE' is not within region `FLASH' .../ld: bin/tfm_s.axf section `.TFM_PSA_ROT_LINKER_DATA' will not fit in region `FLASH' .../ld: address 0x14003e84 of bin/tfm_s.axf section `.ER_TFM_CODE' is not within region `FLASH' .../ld: address 0x14005c20 of bin/tfm_s.axf section `.TFM_UNPRIV_CODE' is not within region `FLASH' .../ld: ERROR: CMSE stub (.gnu.sgstubs section) too far (0x10008540) from destination (0x14003ee4) Note that the linker is generating addresses within the CODE_RAM memory region rather than the FLASH region. Signed-off-by: Keith Packard <[email protected]>
This adds linker script bits and compiler options so that trusted-firmware-m will build with picolibc. This has not been merged to the Zephyr trusted-firmware-m repository yet: zephyrproject-rtos/trusted-firmware-m#134 Signed-off-by: Keith Packard <[email protected]>
This adds linker script bits and compiler options so that trusted-firmware-m will build with picolibc. This has not been merged to the Zephyr trusted-firmware-m repository yet: zephyrproject-rtos/trusted-firmware-m#134 Signed-off-by: Keith Packard <[email protected]>
This adds linker script bits and compiler options so that trusted-firmware-m will build with picolibc. This has not been merged to the Zephyr trusted-firmware-m repository yet: zephyrproject-rtos/trusted-firmware-m#134 Signed-off-by: Keith Packard <[email protected]>
@wearyzen could you review this? |
--entry=Reset_Handler | ||
-specs=nano.specs | ||
-specs=nosys.specs | ||
-specs=picolibc.specs |
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 will work for Zephyr SDK, but Zephyr SDK is not the only supported toolchain in Zephyr.
This will not work for users using GNU Arm embedded toolchain with newlib enabled.
Shouldn't we be supporting both options ?
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.
We could support both options with some configuration mechanism to select between them, but that seems like a lot of added complexity. For users with the GNU Arm embedded toolchain, we could direct them to download the picolibc add-in and use that for this library?
I don't have expertise on toolchain or linker so hard for me to say if there is an issue with this but I remember from my previous comment this change is needed to use with Zephyr SDK 0.18.0-alpha4. |
This adds linker script bits and compiler options so that trusted-firmware-m will build with picolibc. This has not been merged to the Zephyr trusted-firmware-m repository yet: zephyrproject-rtos/trusted-firmware-m#134 Signed-off-by: Keith Packard <[email protected]>
This adds linker script bits and compiler options so that trusted-firmware-m will build with picolibc. This has not been merged to the Zephyr trusted-firmware-m repository yet: zephyrproject-rtos/trusted-firmware-m#134 Signed-off-by: Keith Packard <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.