Skip to content

CMake: Fix Mbed TLS compilation on Cortex-M0/0+/1/M23 #14529

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
merged 1 commit into from
Apr 15, 2021

Conversation

LDong-Arm
Copy link
Contributor

@LDong-Arm LDong-Arm commented Apr 9, 2021

Summary of changes

Due to a known issue in Mbed TLS's architecture determination (Mbed-TLS/mbedtls#1077), we get the error

error: inline assembly requires more registers than available

when compiling bignum.c for Cortex-M0/0+/1/M23 which do not have the macro __thumb2__ set by the compiler.

The workaround is to define the macro MULADDC_CANNOT_USE_R7 which is already defined by Mbed CLI 1 but missing in our CMake support.

Fixes ARMmbed/mbed-os-example-lorawan#220

Impact of changes

Migration actions required

Documentation

None.


Pull request type

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[x] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers

@ARMmbed/mbed-os-core @Patater


@ciarmcom
Copy link
Member

ciarmcom commented Apr 9, 2021

@LDong-Arm, thank you for your changes.
@Patater @ARMmbed/mbed-os-maintainers please review.

harmut01
harmut01 previously approved these changes Apr 9, 2021
Copy link
Contributor

@harmut01 harmut01 left a comment

Choose a reason for hiding this comment

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

LGTM

@mergify mergify bot dismissed harmut01’s stale review April 9, 2021 14:02

Pull request has been modified.

@LDong-Arm
Copy link
Contributor Author

LDong-Arm commented Apr 9, 2021

LGTM

@harmut01 Thanks for the review, but I just force-pushed and changed the approach 😉

@LDong-Arm LDong-Arm requested a review from harmut01 April 9, 2021 14:04
harmut01
harmut01 previously approved these changes Apr 9, 2021
@mergify mergify bot added needs: CI and removed needs: review labels Apr 9, 2021
0xc0170
0xc0170 previously approved these changes Apr 12, 2021
@0xc0170
Copy link
Contributor

0xc0170 commented Apr 12, 2021

CI started

@mbed-ci
Copy link

mbed-ci commented Apr 12, 2021

Jenkins CI Test : ❌ FAILED

Build Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️
jenkins-ci/mbed-os-ci_cmake-example-test

@mergify mergify bot added needs: work and removed needs: CI labels Apr 12, 2021
@LDong-Arm
Copy link
Contributor Author

LDong-Arm commented Apr 12, 2021

mbed-os-example-crash-reporting in cmake-example-test failed on K64F. Being a Cortex-M4F target it doesn't look related to this PR. I'll try to reproduce it anyway.

@LDong-Arm
Copy link
Contributor Author

LDong-Arm commented Apr 12, 2021

It's a CI issue that the mbed-os-example-crash-reporting test is too time-dependent.

mbedhtrun waited one second after the image is flashed, but the application was already running in the background. And after one second, the first line (= System will be rebooted due to a fatal error =) expected by the log was already missed:

[1618220306.79][GLRM][INF] waiting 1.00 sec after reset
[1618220307.85][GLRM][TXD] mbedmbedmbedmbedmbedmbedmbedmbedmbedmbed
[1618220307.85][CONN][WRN] skipping __sync packet (specified with --sync=0)
[1618220307.85][CONN][WRN] UnicodeDecodeError encountered!
[1618220307.85][CONN][RXD] = Reboot count(=1) reached maximum, system will halt after rebooting =

@0xc0170 @saheerb This happens from time to time and not just for one PR: https://jenkins-mbedos.oss.arm.com/blue/organizations/jenkins/mbed-os-ci_cmake-example-test/activity We might need a permanent solution.

@saheerb
Copy link
Contributor

saheerb commented Apr 12, 2021

Yea, what I think is the application is restarted before greentea could process.

@jamesbeyond I think removing first line will make test more robust. What do you think?

@LDong-Arm
Copy link
Contributor Author

Yea, what I think is the application is restarted before greentea could process.

@jamesbeyond I think removing first line will make test more robust. What do you think?

Well, this still relies on the timing of the example. The permanent solution would be an option in mbedgt to skip the reset and/or wait, useful for testing examples.

For now, I wonder if rerunning the CI could allow us to get this PR in.

@saheerb
Copy link
Contributor

saheerb commented Apr 12, 2021

Yea, what I think is the application is restarted before greentea could process.
@jamesbeyond I think removing first line will make test more robust. What do you think?

Well, this still relies on the timing of the example. The permanent solution would be an option in mbedgt to skip the reset and/or wait, useful for testing examples.

For now, I wonder if rerunning the CI could allow us to get this PR in.

The main issue, what I think here is, depending on the restart attempt the first line will change. If we are not checking the first line, then timing wont matter, would it?

For now, I wonder if rerunning the CI could allow us to get this PR in.
We always try that :)

@LDong-Arm
Copy link
Contributor Author

LDong-Arm commented Apr 12, 2021

The main issue, what I think here is, depending on the restart attempt the first line will change. If we are not checking the first line, then timing wont matter, would it?

@saheerb
This isn't the problem. The log is
(many lines above)

= System will be rebooted due to a fatal error =
= Reboot count(=1) reached maximum, system will halt after rebooting =

(many lines below)

So,

  • The log we are matching is the unchangeable line above the count
  • We're relying on this line being printed after the 1 sec wait, and timing can be unreliable

If timing is correct, we should get = System will be rebooted due to a fatal error = no matter it's a first attempt or not.

@LDong-Arm
Copy link
Contributor Author

This failure is seen in lots of places. Need to fix it probably.

@LDong-Arm
Copy link
Contributor Author

This can be merged. The label wasn't updated automatically.

@@ -101,4 +101,6 @@ target_sources(mbed-mbedtls
target_compile_definitions(mbed-mbedtls
INTERFACE
MBED_CONF_MBEDTLS_PRESENT=1
# workaround for https://github.com/ARMmbed/mbedtls/issues/1077
MULADDC_CANNOT_USE_R7
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this conditional on an M0 or M0+ core being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me check why this workaround isn't needed for GCC. But anyway the workaround is probably to set it for M0/M0+.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. The condition also includes M1 and M23 (e.g. NUMAKER_IOT_M263A), added in my latest push.

As for GCC, it compiles exactly the same assembly but doesn't fail, probably related to some optimisation.

Due to a known issue in Mbed TLS's architecture determination
(Mbed-TLS/mbedtls#1077), we get the error

    error: inline assembly requires more registers than available

when compiling `bignum.c` for Cortex-M0/0+/1/M23 which do not have
the macro `__thumb2__` set by the compiler.

The workaround is to define the macro `MULADDC_CANNOT_USE_R7` which
is already defined by Mbed CLI 1 but missing in our CMake support.

Fixes ARMmbed/mbed-os-example-lorawan#220
@mergify mergify bot dismissed stale reviews from harmut01, 0xc0170, and Patater April 15, 2021 10:05

Pull request has been modified.

@LDong-Arm LDong-Arm changed the title CMake: Fix Mbed TLS compilation on Cortex-M0/0+/1 CMake: Fix Mbed TLS compilation on Cortex-M0/0+/1/M23 Apr 15, 2021
@0xc0170
Copy link
Contributor

0xc0170 commented Apr 15, 2021

CI started

@mergify mergify bot added needs: CI and removed needs: work labels Apr 15, 2021
@mbed-ci
Copy link

mbed-ci commented Apr 15, 2021

Jenkins CI Test : ✔️ SUCCESS

Build Number: 4 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-test ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 15, 2021

@Patater all good now ?

@Patater
Copy link
Contributor

Patater commented Apr 15, 2021

Yep, looks good

@0xc0170 0xc0170 merged commit 7f42511 into ARMmbed:master Apr 15, 2021
@mergify mergify bot removed the ready for merge label Apr 15, 2021
@mbedmain mbedmain removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Apr 26, 2021
@msmttchr
Copy link

@LDong-Arm, sorry for unrelated question, but I was under the impression that mbedtls requires an Armv8-A, Armv9-A and Armv8-M core (see https://www.trustedfirmware.org/), but actually this fix is for Armv6. Is mbedtls able to run in Armv6?

@LDong-Arm
Copy link
Contributor Author

LDong-Arm commented Aug 24, 2021

@LDong-Arm, sorry for unrelated question, but I was under the impression that mbedtls requires an Armv8-A, Armv9-A and Armv8-M core (see https://www.trustedfirmware.org/), but actually this fix is for Armv6. Is mbedtls able to run in Armv6?

@msmttchr Mbed TLS is a generic TLS and Crypto library that runs on all kinds of hardware, even including legacy Arm architectures (prior to Armv6) and other platforms such as x86, MIPS, etc. So it is able to run on Armv6, and Mbed OS has a few v6 targets.

What you mentioned is Trusted Firmware, and the firmware itself mainly targets relatively recent Arm platforms. Trusted Firmware M uses Mbed TLS as a dependency.

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.

CMake build fails with error: inline assembly requires more registers than available
9 participants