Jump to bootloader.

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: barthess, RoccoMarco

Posts: 58
Joined: Sat Mar 19, 2016 8:07 pm
Been thanked: 12 times

Re: Jump to bootloader.

Postby electronic_eel » Sun Apr 25, 2021 12:37 pm

rew wrote:I used the flag-at-a-constant address method at first too. However, after a while I changed to simply using a variable.

You have to be careful with this, as now the linker is free to place your variable wherever it wants.

If this space is used by the bootloader, the bootloader could leave some data in there after flashing. This could be your magic value, depending on what the space is used for in the bootloader. So when the bootloader then does a soft reset after flashing, you end up in the bootloader again. As the address of the variable changes with your code and linker version, this problem could appear out of the blue, just by recompiling.

So I think using a hardcoded memory address for the flag is a better solution as you can now test if and how it is used by the bootloader.

Posts: 367
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

Re: Jump to bootloader.

Postby rew » Sun May 09, 2021 7:40 pm

I consider the situation reasonably safe.

Suppose the bootloader would randomize the whole memory. In that case, there would be a 2^-32 chance this would happen: 1 in 4 billion. I can take that risk. But the bootloader will only use 1 of 20kbyte of RAM in my CPU. So actually we're looking at 1:80 billion. But the bootloader doesn't leave random values lying around. Most things will be things like pointers and counters. Those tend to be "small" or "valid pointers in the addressing space".

I've chosen a magic value "0xabacadab //ra " that has lots of bit flips going from bit x to bit x+1 and is very likely not a valid pointer in the STM32 address space. That reduces the chance of showing up by accident even further....

The only way it is going to show up is if the bootloader was downloading my program and this constant ends up in the last block/buffer.

I'm going to risk it.

To complete my argument, I started out with the fixed address trick and chose the last 4-byte location in memory.... Now i must admit that I didn't change the loader script, I used the standard scripts that come with chibios. And then at one point I had memory completely full and my magic location was overwritten when I didn't want it to.

I just checked, the variable ends up at between 7k and 8k in RAM. IIRC somewhere the bootloader docs say only 1k is used by the bootloader, so it should leave it alone.

Return to “STM32 Support”

Who is online

Users browsing this forum: alexblack, Google [Bot], Google Adsense [Bot] and 5 guests