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

MPU/flash: replace MPU_ALLOW_FLASH_WRITE by more fine-grained settings #13913

Open
andrewboie opened this issue Feb 27, 2019 · 8 comments
Open
Assignees
Labels
area: ARM ARM (32-bit) Architecture area: Drivers area: Flash area: Memory Protection Enhancement Changes/Updates/Additions to existing features priority: low Low impact/importance bug

Comments

@andrewboie
Copy link
Contributor

Logging from a message from JK on slack:

Hi, Im using SAME70 (Cortex-M7) platform and I have a problem with the FLASH driver when MPU is enabled. The basic problem is that MPU is protecting FLASH before writing - this is what we actually want. How ever the FLASH controller does not count with this behavior and need to perform the write operation into the FLASH address area, which cause write into internal latch registers. So when the MPU is enabled and protecting the FLASH area, this operation cause MPU to rise exception - as expected. However this write can be anywhere where the FLASH memory is expected (but it dont have to be installed) There is no simply workaround, i see three options:

  1. Disable before write and then enable MPU - with multi threading this is might not be a good idea. I have a limited knowledge here.
  2. Shrink down the MPU area to make a free space which is not covered by MPU. But the size of MPU area is defined as 2^x - so shrinking down is pretty complex.
  3. Create workaround which will not cover all FLASH variant (I can write beyond the installed flash area, but for example with SAME70 this is working only for 515KB and 1MB flash and it will not work for 2MB flash as I can't write beyond the 2BM flash area)
    We can create all patch variants, But Im not sure which one is preferred by Zephyr community. Can some help me to make a good decision.
@andrewboie andrewboie added bug The issue is a bug, or the PR is fixing a bug area: Drivers area: Flash area: Memory Protection area: ARM ARM (32-bit) Architecture and removed area: Flash labels Feb 27, 2019
@aurel32
Copy link
Collaborator

aurel32 commented Feb 27, 2019

When the MPU is enabled, if you want to be able to write to flash, you need to enabled the MPU_ALLOW_FLASH_WRITE option. Is it enabled in your case?

@ioannisg
Copy link
Member

I think this is only enabled, by default in Bluetooth -supported builds. So I doubt that it is.

@rljordan-zz rljordan-zz added priority: low Low impact/importance bug question and removed bug The issue is a bug, or the PR is fixing a bug labels Mar 1, 2019
@ioannisg
Copy link
Member

ioannisg commented Mar 8, 2019

Could this issue be closed?

@aescolar aescolar reopened this Mar 27, 2019
@kubiaj
Copy link
Contributor

kubiaj commented Mar 27, 2019

Hi,
as I didnt file the question I didnt get the notification about your purpose.

The catch here is that user normally dont want to have the ability to write to the flash (when NAND flash is used) - that is why we have MPU. We want to catch the program exception when something goes wrong - when it really try write into FLASH area because some pointer is wrong.

In our SW we need sometime update backup firmware or update system environment variables. NAND memories have controller to write/read/erase memory and for SAM device you are filling the shadow register via write to FLASH area but you are not really writing into the flash. When this shadow register is filled then you can issue a command to write the shadow register into the specific FLASH address. The problem here is that I must fill the shadow register via writing to the flash area.

From my point of view setting MPU_ALLOW_FLASH_WRITE is a workaround and not true solution - it leaves FLASH open for writing but in real it is not possible.

My understanding of MPU_ALLOW_FLASH_WRITE is that can use this with NOR memories when I can do direct FLASH write without use special flash controller.

@aurel32 aurel32 added area: Flash Enhancement Changes/Updates/Additions to existing features and removed question labels May 8, 2019
@aurel32 aurel32 changed the title MPU policy interactions with SAM E70 flash driver MPU/flash: replace MPU_ALLOW_FLASH_WRITE by more fine-grained settings May 8, 2019
@aurel32
Copy link
Collaborator

aurel32 commented May 8, 2019

Thanks for the details. I have retitle the issue as it's a generic issue with MPU and flash support in Zephyr and not specific to the SAM E70 flash driver.

@ioannisg
Copy link
Member

Any solution we pick here, @aurel32 will eat at least one MPU region, AFAICS.

@kubiaj
Copy link
Contributor

kubiaj commented May 31, 2019

Hi,
I dont know. However Im almost convinced that the only one good solution might be to temporarily enable MPU_MPU_FLASH_WRITE or temporarily disable MPU. I have discovered that the Nordic driver behave in the same way.

@aurel32
Copy link
Collaborator

aurel32 commented May 31, 2019

Any solution we pick here, @aurel32 will eat at least one MPU region, AFAICS.

Agreed, we still need to keep one region for the program execution and then we need a new region to program the flash.

I have discovered that the Nordic driver behave in the same way.

The behavior is not at the flash driver level, but at the MPU level. Therefore the behavior is the same for all SoCs.

@zephyrbot zephyrbot added Needs review This PR needs attention from Zephyr's maintainers and removed Needs review This PR needs attention from Zephyr's maintainers labels Feb 8, 2024
@kristofer-jonsson-arm kristofer-jonsson-arm removed their assignment Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ARM ARM (32-bit) Architecture area: Drivers area: Flash area: Memory Protection Enhancement Changes/Updates/Additions to existing features priority: low Low impact/importance bug
Projects
None yet
Development

No branches or pull requests