Skip to main content
Shivam
Associate II
June 22, 2022
Question

Wouldn't disabling the flash readout protection erase the custom boot loader that might be stored in the main flash memory?

  • June 22, 2022
  • 8 replies
  • 4617 views

I'm planning to write a custom boot loader for some reasons. For this the main flash memory will be partitioned into two sectors; the first one holding the custom boot loader and the 2nd one storing the user application. My biggest concern is the read out protection. Suppose I've a device with a custom boot loader along with read out protection enabled and now I want to update the firmware on the 2nd partition. Now as soon as I disable the read out protection, wouldn't it erase the whole flash memory erasing the custom boot loader along with it as stated in AN3155 (Under 3.12 Readout Unprotect Command section)? Is there any way I can set this mass erase only for the 2nd partition? So that the custom boot loader still resides in the 1st partition after this process?

This topic has been closed for replies.

8 replies

Danish1
Lead III
June 22, 2022

Yes disabling flash READOUT protection would erase everything, including your custom bootloader.

But what is the point of your custom bootloader, if not to load the main firmware?

Your bootloader could have a command to erase and load the user application.

Of course your PC or whatever would have to run a program to supply the new application in a form that your bootloader understands. And you might need a way for your main application to request that your bootloader does the erase-and-load cycle.

I tend to debug without a bootloader, and without readout protection.

But my release build only gets loaded by my custom bootloader.

I manage _write_ protection for the appropriate bits of FLASH, and on some stm32 updating this causes a reset cycle.

I never enable _read_ protection for my release build.

Hope this helps,

Danish

Tesla DeLorean
Guru
June 22, 2022

Mass Erase removes everything so you can't recover custom bootloaders, encryption algos and keys.​

D​o the firmware update without changing readout protection, watch which sectors that get write protected.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Shivam
ShivamAuthor
Associate II
June 22, 2022

I actually needed the read out protection so as to prevent the end user from reading the main flash memory and thus getting hold of the firmware. So from what I've understood; there's no way I can keep the read out protection enabled while also having my custom boot loader on the main flash memory. Is that right?

Pavel A.
June 22, 2022

Your custom bootloader can erase and write internal flash even when read out protection is active. This is how you will update your main application.

But do not do mass erase under write protection, and do not erase the bootloader itself. Then everything will be lost.