Skip to content
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

cpu/cortexm_common: function to check address validity #11358

Merged
merged 1 commit into from
May 13, 2019

Conversation

fjmolinas
Copy link
Contributor

@fjmolinas fjmolinas commented Apr 8, 2019

Contribution description

This PR retakes the work done in #10051. The PR was ready to merge except for missing white-list in the new test. As discussed in #10051, this is exactly the same PR but adding some boards to the test white-list. The rest of the PR description is as it was in the original one from @olegart.

Adds extremely useful function to check memory addresses for validity on Cortex-M3/M4/M7 MCUs.

Can be used to determine memory sizes, peripherals availability, etc. in run-time to build firmware that runs effectively on a different MCUs without recompiling.

Testing procedure

Build and run tests/cpu_cortexm_address_check for your board, then type 'check address' in the shell, where address is a memory address in hex notation (with '0x' prefix). Check your MCUs' datasheet for memory map.

E.g. on STM32L152RET6:

check 0x1FF02000
Address 0x1ff02000 is NOT valid. Accessing it will result in BusFault

check 0x1FF01999
Address 0x1ff01999 is valid. Feel free to access it

(0x1FF01999 is an upper address of the System Memory section)

Issues/PRs references

closes #10051

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

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

Just a couple of small things. I think comments from #10051 are addressed by this PR.

Maybe also add a couple of kinetis in the list of whitelisted boards (there are only stm32 and sam for the moment) ?
I also think an automated python test script could be added in a follow-up PR.

tests/cpu_cortexm_address_check/Makefile Outdated Show resolved Hide resolved
cpu/cortexm_common/cortexm_init.c Outdated Show resolved Hide resolved
tests/cpu_cortexm_address_check/main.c Show resolved Hide resolved
@aabadie aabadie added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: new feature The issue requests / The PR implemements a new feature for RIOT labels Apr 8, 2019
Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

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

IMO this should be guarded, possibly by a feature.

@fjmolinas fjmolinas force-pushed the riot-cortexm-address-check branch from bd47405 to ab9d714 Compare April 10, 2019 06:52
@fjmolinas
Copy link
Contributor Author

@kaspar030, instead of providing a whitelist the is a cortexm_cpu_address_check pseodomodule feature requirements, is this what you where suggesting?

@aabadie thoughs? @jcarrano maybe you have some input since you where reviewing the original PR.

@kaspar030
Copy link
Contributor

@kaspar030, instead of providing a whitelist the is a cortexm_cpu_address_check pseodomodule feature requirements, is this what you where suggesting?

Yes, that was one part. The other would be to guard the hard fault support code with it. As it is now, all cortexm0 builds gain weight, even if cpu_address_check is not used.

Maybe "cpu_address_check" is sufficient as feature name. All Cortex-M support the feature after all, but other architectures might add something like it.

@fjmolinas fjmolinas force-pushed the riot-cortexm-address-check branch from ab9d714 to dfb5b9d Compare April 10, 2019 13:50
@fjmolinas
Copy link
Contributor Author

@kaspar030 you are right! I think latest changes should address your comments! If everyone is happy with this changes I can squash!

Makefile.dep Outdated Show resolved Hide resolved
Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

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

Looking good! Minor nits. Feel free to squash directly!

tests/cpu_cortexm_address_check/Makefile Outdated Show resolved Hide resolved
@fjmolinas fjmolinas force-pushed the riot-cortexm-address-check branch 3 times, most recently from faaa90a to 170f69f Compare April 11, 2019 16:00
@fjmolinas
Copy link
Contributor Author

fjmolinas commented Apr 11, 2019

@kaspar030 I was doing a final round of testing and found that the M0 catch wasn't working, well it was but the function was allwats returning 1. Looking in to it i found that:

register uint32_t result __asm("r5") = 1;

was being optimized in a way where result was always though to be 1. My fix was to load the register with 1 before assigning result to "r5". I'm honestly not very knowledge in assembly, so I would love your input on that fix, or a suggestion for a different one.

    __asm__ volatile (
        "ldr  r5, =0x1   \n" /* load r5 with 1 to set result    */
    );

    /* R5 will be set to 0 by HardFault handler */
    /* to indicate HardFault has occured */
    register uint32_t result __asm("r5");

PS: didn't squash this late modification since I'm not sure why it wasn't a problem in the original branch, maybe my compiler version?

@olegart
Copy link
Contributor

olegart commented Apr 11, 2019 via email

@jcarrano
Copy link
Contributor

@fjmolinas I have PR'd what I think is a neat fix to your branch: fjmolinas#1

It is a fixup commit that would replace the second commit in this PR.

@fjmolinas
Copy link
Contributor Author

@olegart @jcarrano thanks for the suggestions I will go with @jcarrano suggestion since the code is easier to read while the firmware size remains the same for both options.

@fjmolinas fjmolinas force-pushed the riot-cortexm-address-check branch 2 times, most recently from 37278e5 to 30025e0 Compare April 15, 2019 12:08
@fjmolinas
Copy link
Contributor Author

@kaspar030 @aabadie any final comments?

@fjmolinas
Copy link
Contributor Author

@kaspar030 @aabadie ping!

Copy link
Contributor

@jcarrano jcarrano 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 this is OK. I'd like a more automated test, but let's not delay it further.

@jcarrano jcarrano added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label May 8, 2019
@jcarrano
Copy link
Contributor

jcarrano commented May 8, 2019

@fjmolinas please squash the fixup and then I merge it.

@fjmolinas fjmolinas force-pushed the riot-cortexm-address-check branch from 30025e0 to a5ce6de Compare May 13, 2019 07:36
@fjmolinas
Copy link
Contributor Author

@jcarrano Sorry for the delay, squashed! Waiting for murdock to be happy!

@fjmolinas
Copy link
Contributor Author

@jcarrano should I remove the needs squash tag? (Murdock failed because of it)

@aabadie @kaspar030 ping!!

@jcarrano jcarrano added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels May 13, 2019
@jcarrano
Copy link
Contributor

@fjmolinas Yes, I prefer to remove it before squashing, so as not to trigger Murdock twice (and waste resources). IMO Murdock should not check for that label and it should be on a separate task.

I removed it and re-triggered the build.

@jcarrano jcarrano dismissed kaspar030’s stale review May 13, 2019 09:50

Stale review

@jcarrano jcarrano merged commit cbc08ed into RIOT-OS:master May 13, 2019
@fjmolinas fjmolinas deleted the riot-cortexm-address-check branch May 28, 2019 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants