convey information from firmware to bootloader across software reset

Discussion created by riechardt.joerg on Oct 25, 2017

It took some time for me to figure this out. Hope it helps you.

This works on a STM32F103, where the stack is at the end of ram.

The end of stack is lowered by 8 bytes to give space to add section noinit, into which boot_flag is put. boot_flag survives reset.

It can be easily adapted to other STM32xxxx.


In firmware:

volatile uint32_t boot_flag__attribute__((__section__(".noinit")));

boot_flag = 0x12345678; /* let bootloader know reset is from here */



In bootloader:

volatile uint32_t boot_flag __attribute__((__section__(".noinit")));

if (boot_flag == 0x12345678) {  /* software reset from firmware */

boot_flag = 0; /* clear the firmware reset flag */

/* do whats needed for software reset from firmware */



Linker file for both:


/* leave last 8 bytes in ram for noinit section */

_estack = ORIGIN(ram) + LENGTH(ram) – 8;




.noinit _estack (NOLOAD): /* for boot_flag */



} > ram