Nordic Flash protect - #11258
Conversation
dhalbert
left a comment
There was a problem hiding this comment.
I don't understand why you need this mechanism. When are writes being done outside the flash areas that we are allowed to write in? We can write in the filesystem area (if it's an internal filesystem), the NVM area, and the BLE_CONFIG area.
You can reserve areas in flash by augmenting ports/nordic/boards/common.template.ld.
Also, if you use the ACL mechanism, would that not also block the custom bootloader from writing to that area of flash?
|
I do not know of a specific case where out of bounds writes were occurring. I added it as a precaution due to the SP-1 bootloader settings page falling directly after the filesystem region, and it did not seem to me to have existing bounds check. I will look into
My understanding is that the protection lasts until reset. So this would prevent the bootloader from writing to it's settings after CircuitPython has started running. But from a cold boot, the bootloader goes first and can make any writes that it wants before launching CircuitPython. I don't believe that the bootloader is trying to make any writes after launching CircuitPython, though everything I have learned about it is gleaned from it's behavior only. There is no code published for it. |
|
After looking in to
|
|
I understand this is a "belt and suspenders" protection against stray writes. But I think the LLM's thinking on this has misplaced priorities. The cases you listed would all be due to code errors. All the other things like LBA should already be range-checked. But I still think you should reserve the area by adding a region in Maybe the smashing of the bootloader region you saw was due to the size of this bootloader settings region not being taken into account by the size calculations of the other regions. The CircuitPython firmware area would also be in danger of these supposed stray writes, but I have never seen it being smashed while running, except maybe when we had errors in the initial flash map setup. And this would be true on non-nordic boards as well. By the way, the If you really want to set ACL regions, I think you could do that more at compile time. The ACL routine would use a small table of bottom and top boundaries for each region to protect and would just set the ACL to read-only on those regions. I think you could dispense with a lot of other run-time code here, like |
|
Okay, thank you. Will close this and use a reservation in |
Adds mechanisms for preventing writing to out of bounds flash pages that we don't own.
flash_page_is_ours()enforcer function for NVM to block writes for out of bounds regions.These came up while working on the SP-1 because it's flash layout has a settings page for the custom bootloader that sits at the end after NVM and CIRCUITPY. SWD is not easy to access on the device and there isn't a published copy of the bootloader firmware to recover from if things go sideways due to an unintended write to the settings.
I tested this build successfully with
CIRCUITPY_NRF_FLASH_PROTECT=1on a CircuitPlayground bluefruit