cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f4 custom bootloader

eran
Associate II
Posted on May 31, 2014 at 15:40

Hi All,

I want to implement my own bootloader instead of using ST's.

I read UART BL but it doesn't explain how to implement custom.

I implemented BL in the past for freescale 8-bit mcu.

Where can I find documentation for this issue?

Thanks.

#stm32f4-custom-bootloader
6 REPLIES 6
chen
Associate II
Posted on May 31, 2014 at 16:33

Hi

''I want to implement my own bootloader instead of using ST's.

I read UART BL but it doesn't explain how to implement custom.

I implemented BL in the past for freescale 8-bit mcu.

Where can I find documentation for this issue?''

I do not know if there is a simple how to write a bootloader manual out for STM32 out there.

What do you want it to do?

Download a program binary over serial

Program it into flash (fixed location)

Jump to the new progam

The tricky thing to do the jump. Read this thread for how to do the jump:

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a%2f%2fmy.st.com%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex_mx_stm32%2fCustom%20BootLoader%20jump%20to%20FreeRTOS%20application&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CD...

Posted on May 31, 2014 at 18:08

Yeah, I'm not sure what the real question is here. Boot Loaders are pretty generic things, perhaps some specific custom code for USART, FLASH and local storage, but I've got a bunch of code I've used over decades on 68K, ARM7/9, MIPS, CORTEX, etc, heck XMODEM is it's original form dates from 1977, and people ROM that onto MIPS and ARM SoC designs today.

So what specific magic do you want your boot loader to do?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
eran
Associate II
Posted on May 31, 2014 at 19:34

Thanks for the response guys.

By saying ''custom Bootloader'' I mean that my BL will be done using modem

which is connected to my uart.

I want to implement my own Host/Client protocol.

In freescale when implementing bootloader, you could protect the bootloader from being written, you had to relocate vector table.

So my questions are:

Do I need to relocate my vector table (if so where to)?

Can I protect my BL code in flash?

How can I make my BL code and app code flashed on different flash sectors?

I am not going to use jump, when app needs to go to bootloader, it set specific bytes in flash and make reset. When MCU boots, it reads these bytes and decides if to go to app or continue to app upgrade section.

Posted on May 31, 2014 at 20:16

A modem based OTA update is quite a complicated process, I'd probably opt to stage the new firmware code on an SDCard or serial flash, using HTTP to pull data from a server. Others use FTP, and a not internet solution could dial up a server doing X/Y-Modem. You can write to the flash while executing from other regions, but this will stall the processor, perhaps in ways that are less than ideal for real-time interrupt servicing. Code could be copied and executed from RAM to avoid this, in much the way flash parts are classically programmed.

Yes the vector table will need to be relocated for the base address used by the Boot Loader, and that used by the app. ST has several IAP examples which do just this, and partition the flash based on the usage requirements of the loader. Normally the vector table code is handled in SystemInit() within in system_stm32f4xx.c with an OFFSET into the FLASH, and a write to SCB->VTOR to point the Cortex at the desired table location. No need to copy or change things. The load address of the boot loader and app is generally controlled by the linker, and the supplied linker script or scatter file.

There are ways to write protect the flash sectors in the F4, and also a global method to lock down read and jtag access to the part, which provide some level of protection. It's not an inherently secure device.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
eran
Associate II
Posted on May 31, 2014 at 21:07

Hi clive1 thank you for your response.

I've already implemented OTA for freescale over GPRS (modem), which is not that complicated.

I would like to do the same thing I did in freescale:

1. having to projects. one for BL and one for app. each one is written on different location on the flash.

The BL will not use any interrupts, only the app.

This means mapping app and BL on different sectors of the flash, which will allow me to execute code from flash and not RAM.
chen
Associate II
Posted on June 02, 2014 at 10:39

Hi

''The BL will not use any interrupts, only the app.''

It does not matter if the BL does not use IRQs, it still needs a vector table, due to the way ARM implements the boot up process.

''1. having to projects. one for BL and one for app. each one is written on different location on the flash.''

So each project (BL and App) will have a vector table defined for it.

The only thing you have to do is to locate one of them away from the default boot location of 0x000000 and set the SCB->VTOR to match the new vector table location.

''I am not going to use jump, when app needs to go to bootloader, it set specific bytes in flash and make reset. When MCU boots, it reads these bytes and decides if to go to app or continue to app upgrade section.''

Unfortunately it does not work like this. When the ARM core boots, it will automatically go to the default boot location of 0x000000. So your bootloader will have to do the 'check the specific bytes in flash' and do a jump. Hence my original post and link to the other thread.

(FYI, the ST parts do allow you to select different boot options but not what you want. It allows you to boot from Flash, embedded BL or SRAM)