Skip to content

More MPU work #9061

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 9 commits into from
Dec 19, 2018
Merged

More MPU work #9061

merged 9 commits into from
Dec 19, 2018

Conversation

kjbracey
Copy link
Contributor

@kjbracey kjbracey commented Dec 11, 2018

Description

  • Don't call HAL MPU free code when platform.use-mpu is turned off.
  • Correct MPU synchronisation sequences.
  • Reduce MPU code size further with a loop
  • Use higher-level calls, fix ARMv8-M error
  • Assert number of regions, rather than error
  • ARMv7-M: correctly protect 80000000 RAM region
  • Fix target.mpu-rom-end setting, for ARMv8-M too
  • nRF52840: Set mpu-rom-end to 0x1fffffff (to test this case)

Pull request type

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

c1728p9 and others added 3 commits December 11, 2018 18:59
Use the MPU through the platform layer rather than through the HAL.
Synchronisation instructions were not quite right - too strict on entry,
and not quite correctly synchronising the instruction stream on exit.

References:

* https://static.docs.arm.com/dai0321/a/DAI0321A_programming_guide_memory_barriers_for_m_profile.pdf
* https://static.docs.arm.com/100699/0100/armv8m_architecture_memory_protection_unit_100699_0100_00_en.pdf
@kjbracey kjbracey changed the title More mpu work More MPU work Dec 11, 2018
@kjbracey
Copy link
Contributor Author

Needs some more local testing - would be good if @c1728p9 could have a look at ARMv8-M in particular. Also intending one more commit to change MBED_ERRORs to MBED_ASSERTs.

c1728p9
c1728p9 previously approved these changes Dec 11, 2018
@cmonr
Copy link
Contributor

cmonr commented Dec 11, 2018

@kjbracey-arm Don't forget the astyle fix :)

@kjbracey kjbracey force-pushed the more_mpu_work branch 2 times, most recently from c212214 to 3477c45 Compare December 12, 2018 09:15
@kjbracey
Copy link
Contributor Author

Adjusted a bit more, making ARMv7-M use higher-level API too.

ARMv7-M init code now down to 170 bytes from 215.

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 12, 2018

Please review astyle travis CI

@kjbracey
Copy link
Contributor Author

Full mbed_mpu_v7m.c + mbed_mpu_mgmt.c is now 246+351 = 597, down from 659 in current master.

Switch to higher-level calls and macros, and fix an error in the ARMv8-M
version - "inner" attributes were not being set correctly due to a
copy/paste error - "outer" was being set twice.

This means RAM would have been marked WTRA rather than WBWA for the
inner cache.

Slightly reduces ARMv7-M init code size by feeding region number
into RBAR instead of using RNR.
As we build for a specific CPU, a runtime check for number of MPU
regions in release builds is not worthwhile. Make it an assert only.
Saves a little space in develop images, a lot in release.
Subregion mask for this region was set fully disabled, instead of fully
enabled.
@kjbracey
Copy link
Contributor Author

kjbracey commented Dec 12, 2018

Two more bugs found - target.mpu-rom-end JSON setting wasn't working, and 80000000 wasn't protected in ARMv7-M.

Fixed up, including making mpu-rom-end work on ARMv8-M - was simpler than figuring out what to do to not hit the "not supported" test once JSON was fixed.

Also will save a few more bytes if you do set mpu-rom-end to 0x1fffffff.

@kjbracey kjbracey force-pushed the more_mpu_work branch 2 times, most recently from d4d5fca to 8ee286e Compare December 12, 2018 13:22
targets.json was not specifying the same macro name as the code was
checking for, so setting was ineffective.

Making this work tripped up not-supported checks in ARMv8-M - rather than deal
with making this work, support it instead.

Both ARMv7-M and ARMv8-M slightly reduce code size and runtime impact if
mpu-rom-end is 0x1fffffff, using one fewer region.

This means default setup for ARMv8-M now requires 5 regions, with
mpu-rom-end set to default 0x0fffffff, but this can be put back to 4 by
changing the setting.
So we have at least one test platform exercising the special case of
mpu-rom-end being 0x1fffffff, set that for nRF52840.
@cmonr
Copy link
Contributor

cmonr commented Dec 12, 2018

CI started

@mbed-ci
Copy link

mbed-ci commented Dec 13, 2018

Test run: SUCCESS

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

@kjbracey
Copy link
Contributor Author

kjbracey commented Dec 13, 2018

This does really need rereview - I did some more significant stuff since @c1728p9 last looked at it.

@cmonr
Copy link
Contributor

cmonr commented Dec 13, 2018

Hmm... I wonder.

I recall a time when GitHub would auto-dismiss reviews when a change was made.

@cmonr cmonr dismissed c1728p9’s stale review December 14, 2018 00:30

Significant changes have occurred. Please re-review.

Move the start of RAM from 0x10000000 to 0x20000000 on the
NUMAKER_PFM_M2351. This allows the target to work correctly.
Copy link
Contributor

@c1728p9 c1728p9 left a comment

Choose a reason for hiding this comment

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

I tested this on a NUMAKER_PFM_M2351 and got crashes on boot due to the MPU. I pushed a commit to update the ram/rom split for this target to correct the crashes. This PR looks good to me. Thanks @kjbracey-arm!

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 19, 2018

CI started

@mbed-ci
Copy link

mbed-ci commented Dec 19, 2018

Test run: SUCCESS

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

@cmonr cmonr merged commit 6f57600 into ARMmbed:master Dec 19, 2018
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.

5 participants