cancel
Showing results for 
Search instead for 
Did you mean: 

How to store a 1-bit bootloader flag without wasting 1 Flash page

bhagat
Visitor

Hello,

I am working on custom bootloader + application setup on a STM32G070CBT6

Currently, I need to store bootloader flag that indicate whether the MCU should jump to the bootloader code or to the application code.

  • Since the movement i am reserving 1 flash page(2KB) ,just to store single flag bit.
  • This feels like a waste of memory, since I only need 1 bit of storage.

My questions are:

     1. Can I use Option Bytes memory area to store the custom flag? 

  • Are Option bytes  writable at runtime for application/bootloader use, or are they limited to ST system configurations (e.g., RDP, WRP, BOR levels)?

      2. If Option Bytes memory area are not suitable ,is there another small memory area(apart from flash)

          that is recommended for storing such a small boot flag?

I need only one bit for this flag, but dedicating a full 2KB flash feel inefficient.

20 REPLIES 20

I do agree. That was a method among others, the usage of noinit in the linker for example ..

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Sorry, I accepted it as the solution by mistake. I couldn’t find an option to unmark it. Could you please guide me if there’s a way to undo that?


@bhagat wrote:

Sorry, I accepted it as the solution by mistake. I couldn’t find an option to unmark it. Could you please guide me if there’s a way to undo that?


mALLEm_0-1757931260356.png

Meanwhile, using RAM still a solution for you.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

@bhagat wrote:

I couldn’t find an option to unmark it.


It is here. But it has been noted that this is not at all obvious:

Unmark Solution is too hard to find.

@mƎALLEm 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
LCE
Principal II

I guess the OP wants to keep that info / bit even after power-down, so no RAM.

What about putting that info into the application flash when the bootloader writes it?
You're probably moving the vector table anyway, so move it a little further, and put the info you need into flash before the new VT address. Some linker file & __attribute__((section(".BootInfo"))) shenanigans required... :D


@LCE wrote:

I guess the OP wants to keep that info / bit even after power-down, so no RAM.


@bhagat only said it needs to survive reset:

https://community.st.com/t5/stm32-mcus-products/how-to-store-a-1-bit-bootloader-flag-without-wasting-1-flash/m-p/838949/highlight/true#M285703

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

I would consider the hint to store this flag in RAM aviable solution.
Anyway ...

But back to your initial post, you don't mention if you want this flag persistent, or just to survive a MCU reset.
Which makes quite a difference.
The follow-up discussion suggests it's the latter, i.e. you only need to store a flag bit beyond a reset.
But to avoid "spurious boot issues" I would avoid a bit flag, and would use a larger pattern instead.
A single RAM bit might be set by random chance, a regular pattern (as those used to enable the Flash erase/write interface) is much safer. 

Sorry in my case, I need the bootloader flag to survive not only a reset but also a full power cycle. Since RAM contents are lost when power is removed, I cannot rely on RAM for this purpose.

Yes, that’s correct. I need the bootloader flag to be retained even after a full power-down, so RAM won’t work for my case.

Yes, I understand. Reserving a word in RAM and accessing it directly by address can work for  use case if I only need the flag across resets. But since I want the bootloader flag to survive even after a power cycle.