SlideShare a Scribd company logo
ST built-in Boot Loader
By Omer Korech
Applicable to: STM32L1XX
Due to the technical limitations that will be detailed below,
my company has decided not to use ST built in boot loader
therefore this presentation is released for the public
in hope not to repeat our mistakes 
Added value in brief
Undocumented important Takeaways:
– When running from bank 2 (nBFB2 = 0),
an attempt to update firmware from system memory
will FAIL, because it will result in jumping back to bank 2
– Unlike STM32L0XXX and STM32L4XXX,
nBFB2 does not result in bank swap
– A concrete bootloader flowchart is presented in slide #7
© Hakim Weatherspoon, Computer Science, Cornell University
Basic Computer System
• A processor
is a device that executes instructions
Processor has some internal state in storage elements (registers)
• A memory
holds instructions and data
von Neumann architecture is assumed for simplicity
• A bus connects the two
regs
bus
processor memory
01010000
10010100
…
addr, data,
r/w
ARM Cortex-M Start UP Sequence
• Electronically
– Fetch Stack Pointer from address 0x00
– Fetch Program Counter from address 0x04
• Software
– Execute assembly function Reset_Handler
Initialize vector table and call the followings:
– Execute c function SystemInit
Initializes clocks and VTOR
– Execute assembly function __iar_data_init3Initialize
Initializes variables
– Call function main
User program
But address 0x00 does not exist in Flash !
It is mapped to other address (0x08000000 in normal execution)
System Memory
• Written in ROM within the Flash
• Has two functions:
– Firmware update
(When nBFB2 = 1)
– Execute code from bank 2
(When nBFB2 = 0)
nBFB2 bit
• nBFB2 = 1 at startup
– Normal Execution
• nBFB2 = 0 at startup
– Address 0x00 is mapped electronically to System memory
– System memory Jumps to bank 2
• Undocumented important Takeaways:
– When running from bank 2 (nBFB2 = 0),
an attempt to update firmware from system memory
will FAIL, because it will result in jumping back to bank 2
– Unlike STM32L0XXX and STM32L4XXX,
nBFB2 does not result in bank swap
Wrtieto EEPROM:
Go_to_BL_Flag=1
Yes
Wake up
from Reset
Go_to_BL_Flag=0
Remap 0x00 to BLflash
Set stackpointer to BLStack
Jump to BL
Yes
Software
Reset
nBFB2 ==1 ?
Field Upgrade
Request ?
Normal code
Run from bank 2
No
Communication
with BL
Established ?
Establish
communication
with BL
Error message
(in application)
Reset (Opt. Byte)
No Writecodeto Bank2
And / Or Datato Bank1
Read To ValidateOK?
Set nBFB2 =0
(Initiatesreset)
Yes
No
Yes
Go_to_BL_Flag==1 ?
No
Remap 0x00
to Flash 2
Remap 0x00 to Flash1No
Set nBFB2 =1
Coderun from bank 1
Field Upgrade
Request ?
No
Yes
Yes
BL.C
#include "BL.h"
void GoToBootLoader(void)
{
//Initializing the arguments for HAL functions
FLASH_AdvOBProgramInitTypeDef OBbank1;
OBbank1.BootConfig = OB_BOOT_BANK1;
OBbank1.OptionType = OPTIONBYTE_BOOTCONFIG;
// Write to EEPROM that BootLoader should be executed
HAL_FLASHEx_DATAEEPROM_Unlock();
HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_WORD,
EEPROM_Address_Mode_Of_Execution,
ShouldExecuteBootLoader);
//Change to (or stay at) bank1 and reset the device
HAL_FLASH_OB_Unlock();
HAL_FLASHEx_AdvOBProgram(&OBbank1);
HAL_FLASH_Unlock();
HAL_FLASH_OB_Launch();
}
void SystemInit (void)
// Define our function pointer
void (__code*SysMemBootJump)(void);
// Set system memory address.
volatile uint32_t addr = BootLoaderMemoryLocation;
if(…) // MCU was Set to be boot from bank 1
if ( // Jump to boot loader request is registered
// Reset our trigger
HAL_FLASHEx_DATAEEPROM_Erase(FLASH_TYPEPROGRAM_WORD, EEPROM_Address_Mode_Of_Execution);
//Set jump memory location for system memory
SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4 )));
//Remap system memory to address 0x0000 0000 in address space
__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
SCB->VTOR = 0; // BootLoaderMemoryLocation; Since 0 is mapped to system memory
__set_MSP(*(uint32_t *)addr);
// Point the PC to the System Memory reset vector
SysMemBootJump();
}
else{ // Running Code from bank 1
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH.*/
}
}
else // run from bank2
{
SCB->VTOR = FLASH_BANK2_BASE | VECT_TAB_OFFSET;
}
Requirement from external application
Input
The input to the external (smarthphone) is a binary file of
size X bytes,
where in our case 0x38000 < X < 0x40000 changes from
one update to the other.
Goal
The binary file is to be copied into flash, where the first
byte is copied to address UpdateCodeStartAddress and
the last address is to be copied to
UpdateCodeStartAddress + X, where
UpdateCodeStartAddress = 0x08008000.
After the file is copied (and verified that it is copied
correctly), the micro-controller should be booted from
bank 2.
Bootloader limitations
ST bootloader has limited address range allowed to be written (all of
bank 1 and ½ of bank 2).
Usually two valid applications should be available, in order to
accommodate a failure during update of one of the versions.
If the application requires more than ½ the space of a bank, only one
out of the two application may be updated 
Why?
Hint: The firmware update by ST built in bootloader may only take
place when nBFB2 = 1.
Due to the above limitation, it has been decided to use custom boot
loader, and therefore this presentation is brought back to the public
domain (as all of my knowledge was learned from the public domain)
Memory banks in STM32L1XX
Two Banks
All of Bank 1 and Half of Bank 2 are accessible
by ST ROM Bootloader
Factory Code @ Bank1
(start address 0x08000000)
Updated Code @ Bank2
(start address 0x08040000)
Updated Graphics data @ bank 1
(start address 0x08008000)
Factory Graphics data @ bank2
(start address 0x08048000)

More Related Content

What's hot

Basic computer organization
Basic computer organizationBasic computer organization
Basic computer organization
Nitesh Singh
 
COMPUTER ORGNAIZATION NOTES
COMPUTER ORGNAIZATION NOTESCOMPUTER ORGNAIZATION NOTES
COMPUTER ORGNAIZATION NOTES
Dr.MAYA NAYAK
 
Chapter 6 input output
Chapter 6 input outputChapter 6 input output
Chapter 6 input outputrisal07
 
introduction to computers
 introduction to computers introduction to computers
introduction to computersDeepak John
 
Instruction codes and computer registers
Instruction codes and computer registersInstruction codes and computer registers
Instruction codes and computer registers
mahesh kumar prajapat
 
Chapter 2
Chapter 2Chapter 2
The Digital Logic Level
The Digital Logic LevelThe Digital Logic Level
The Digital Logic LevelLiEdo
 
Chapter 7
Chapter 7Chapter 7
Computer architecture input output organization
Computer architecture input output organizationComputer architecture input output organization
Computer architecture input output organization
Mazin Alwaaly
 
Assembly Language
Assembly LanguageAssembly Language
Assembly Language
Vijay Kumar
 
COMPUTER ORGANIZATION NOTES Unit 5
COMPUTER ORGANIZATION NOTES Unit 5COMPUTER ORGANIZATION NOTES Unit 5
COMPUTER ORGANIZATION NOTES Unit 5
Dr.MAYA NAYAK
 
Unit 4-input-output organization
Unit 4-input-output organizationUnit 4-input-output organization
Unit 4-input-output organization
vishal choudhary
 
Chapter 4
Chapter 4Chapter 4
VJITSk 6713 user manual
VJITSk 6713 user manualVJITSk 6713 user manual
VJITSk 6713 user manual
kot seelam
 
Module4
Module4Module4
Module4
cs19club
 
COMPUTER ORGANIZATION NOTES Unit 3 4
COMPUTER ORGANIZATION NOTES  Unit 3 4COMPUTER ORGANIZATION NOTES  Unit 3 4
COMPUTER ORGANIZATION NOTES Unit 3 4
Dr.MAYA NAYAK
 
Computer organisation
Computer organisationComputer organisation
Computer organisationMohd Arif
 
Input output organisation
Input output organisationInput output organisation
Input output organisation
Sanjeev Patel
 
Input output in computer Orgranization and architecture
Input output in computer Orgranization and architectureInput output in computer Orgranization and architecture
Input output in computer Orgranization and architecture
vikram patel
 

What's hot (20)

Basic computer organization
Basic computer organizationBasic computer organization
Basic computer organization
 
COMPUTER ORGNAIZATION NOTES
COMPUTER ORGNAIZATION NOTESCOMPUTER ORGNAIZATION NOTES
COMPUTER ORGNAIZATION NOTES
 
Chapter 6 input output
Chapter 6 input outputChapter 6 input output
Chapter 6 input output
 
introduction to computers
 introduction to computers introduction to computers
introduction to computers
 
Instruction codes and computer registers
Instruction codes and computer registersInstruction codes and computer registers
Instruction codes and computer registers
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Unit3 input
Unit3 inputUnit3 input
Unit3 input
 
The Digital Logic Level
The Digital Logic LevelThe Digital Logic Level
The Digital Logic Level
 
Chapter 7
Chapter 7Chapter 7
Chapter 7
 
Computer architecture input output organization
Computer architecture input output organizationComputer architecture input output organization
Computer architecture input output organization
 
Assembly Language
Assembly LanguageAssembly Language
Assembly Language
 
COMPUTER ORGANIZATION NOTES Unit 5
COMPUTER ORGANIZATION NOTES Unit 5COMPUTER ORGANIZATION NOTES Unit 5
COMPUTER ORGANIZATION NOTES Unit 5
 
Unit 4-input-output organization
Unit 4-input-output organizationUnit 4-input-output organization
Unit 4-input-output organization
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
VJITSk 6713 user manual
VJITSk 6713 user manualVJITSk 6713 user manual
VJITSk 6713 user manual
 
Module4
Module4Module4
Module4
 
COMPUTER ORGANIZATION NOTES Unit 3 4
COMPUTER ORGANIZATION NOTES  Unit 3 4COMPUTER ORGANIZATION NOTES  Unit 3 4
COMPUTER ORGANIZATION NOTES Unit 3 4
 
Computer organisation
Computer organisationComputer organisation
Computer organisation
 
Input output organisation
Input output organisationInput output organisation
Input output organisation
 
Input output in computer Orgranization and architecture
Input output in computer Orgranization and architectureInput output in computer Orgranization and architecture
Input output in computer Orgranization and architecture
 

Similar to Boot loader for STM32L1XX

ST Built in Boot loader
ST Built in Boot loaderST Built in Boot loader
ST Built in Boot loader
Omer Korech
 
4bit PC report
4bit PC report4bit PC report
4bit PC report
tanvin
 
4bit pc report[cse 08-section-b2_group-02]
4bit pc report[cse 08-section-b2_group-02]4bit pc report[cse 08-section-b2_group-02]
4bit pc report[cse 08-section-b2_group-02]
shibbirtanvin
 
Assembler4
Assembler4Assembler4
Assembler4
Omar Sanchez
 
The hardware of the Mcs 51 microcontroller
 The hardware of the Mcs 51 microcontroller The hardware of the Mcs 51 microcontroller
The hardware of the Mcs 51 microcontroller
Garba Geidam
 
Pic full note
Pic full notePic full note
H63ECH_1B_023799_OsamaAzim
H63ECH_1B_023799_OsamaAzimH63ECH_1B_023799_OsamaAzim
H63ECH_1B_023799_OsamaAzimOsama Azim
 
Ht usb5130-v2
Ht usb5130-v2Ht usb5130-v2
Ht usb5130-v2
handson28
 
unit-2.pptx
unit-2.pptxunit-2.pptx
unit-2.pptx
KanchanThory
 
Assembly programming
Assembly programmingAssembly programming
Assembly programming
Omar Sanchez
 
AAME ARM Techcon2013 005v02 System Startup
AAME ARM Techcon2013 005v02 System StartupAAME ARM Techcon2013 005v02 System Startup
AAME ARM Techcon2013 005v02 System Startup
Anh Dung NGUYEN
 
Protocolo de programacion del pic16 f8x
Protocolo de programacion del pic16 f8xProtocolo de programacion del pic16 f8x
Protocolo de programacion del pic16 f8x
rich_glez
 
Hacking the 2016 Hackaday SuperConference Badge
Hacking the 2016 Hackaday SuperConference BadgeHacking the 2016 Hackaday SuperConference Badge
Hacking the 2016 Hackaday SuperConference Badge
szczys
 
Sms based patient report from remote place1
Sms based patient report from remote place1Sms based patient report from remote place1
Sms based patient report from remote place1Atul Uttam
 
Best-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbaiBest-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbai
Unmesh Baile
 
Pc based wire less data aquisition system using rf(1)
Pc based wire less data aquisition system using rf(1)Pc based wire less data aquisition system using rf(1)
Pc based wire less data aquisition system using rf(1)
Vishalya Dulam
 
Microcontroller
MicrocontrollerMicrocontroller
MicrocontrollerSpitiq
 
EC/Bios Interaction Laptop Repair Course
EC/Bios Interaction Laptop Repair CourseEC/Bios Interaction Laptop Repair Course
EC/Bios Interaction Laptop Repair Course
Vikas Deoarshi
 

Similar to Boot loader for STM32L1XX (20)

ST Built in Boot loader
ST Built in Boot loaderST Built in Boot loader
ST Built in Boot loader
 
4bit PC report
4bit PC report4bit PC report
4bit PC report
 
4bit pc report[cse 08-section-b2_group-02]
4bit pc report[cse 08-section-b2_group-02]4bit pc report[cse 08-section-b2_group-02]
4bit pc report[cse 08-section-b2_group-02]
 
Assembler4
Assembler4Assembler4
Assembler4
 
The hardware of the Mcs 51 microcontroller
 The hardware of the Mcs 51 microcontroller The hardware of the Mcs 51 microcontroller
The hardware of the Mcs 51 microcontroller
 
Pic full note
Pic full notePic full note
Pic full note
 
control unit
control unitcontrol unit
control unit
 
H63ECH_1B_023799_OsamaAzim
H63ECH_1B_023799_OsamaAzimH63ECH_1B_023799_OsamaAzim
H63ECH_1B_023799_OsamaAzim
 
Ht usb5130-v2
Ht usb5130-v2Ht usb5130-v2
Ht usb5130-v2
 
unit-2.pptx
unit-2.pptxunit-2.pptx
unit-2.pptx
 
Assembly programming
Assembly programmingAssembly programming
Assembly programming
 
AAME ARM Techcon2013 005v02 System Startup
AAME ARM Techcon2013 005v02 System StartupAAME ARM Techcon2013 005v02 System Startup
AAME ARM Techcon2013 005v02 System Startup
 
Protocolo de programacion del pic16 f8x
Protocolo de programacion del pic16 f8xProtocolo de programacion del pic16 f8x
Protocolo de programacion del pic16 f8x
 
Hacking the 2016 Hackaday SuperConference Badge
Hacking the 2016 Hackaday SuperConference BadgeHacking the 2016 Hackaday SuperConference Badge
Hacking the 2016 Hackaday SuperConference Badge
 
Sms based patient report from remote place1
Sms based patient report from remote place1Sms based patient report from remote place1
Sms based patient report from remote place1
 
Best-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbaiBest-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbai
 
2.computer org.
2.computer org.2.computer org.
2.computer org.
 
Pc based wire less data aquisition system using rf(1)
Pc based wire less data aquisition system using rf(1)Pc based wire less data aquisition system using rf(1)
Pc based wire less data aquisition system using rf(1)
 
Microcontroller
MicrocontrollerMicrocontroller
Microcontroller
 
EC/Bios Interaction Laptop Repair Course
EC/Bios Interaction Laptop Repair CourseEC/Bios Interaction Laptop Repair Course
EC/Bios Interaction Laptop Repair Course
 

Recently uploaded

一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
zwunae
 
An Approach to Detecting Writing Styles Based on Clustering Techniques
An Approach to Detecting Writing Styles Based on Clustering TechniquesAn Approach to Detecting Writing Styles Based on Clustering Techniques
An Approach to Detecting Writing Styles Based on Clustering Techniques
ambekarshweta25
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
Kamal Acharya
 
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
dxobcob
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 

Recently uploaded (20)

一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
 
An Approach to Detecting Writing Styles Based on Clustering Techniques
An Approach to Detecting Writing Styles Based on Clustering TechniquesAn Approach to Detecting Writing Styles Based on Clustering Techniques
An Approach to Detecting Writing Styles Based on Clustering Techniques
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
 
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 

Boot loader for STM32L1XX

  • 1. ST built-in Boot Loader By Omer Korech Applicable to: STM32L1XX Due to the technical limitations that will be detailed below, my company has decided not to use ST built in boot loader therefore this presentation is released for the public in hope not to repeat our mistakes 
  • 2. Added value in brief Undocumented important Takeaways: – When running from bank 2 (nBFB2 = 0), an attempt to update firmware from system memory will FAIL, because it will result in jumping back to bank 2 – Unlike STM32L0XXX and STM32L4XXX, nBFB2 does not result in bank swap – A concrete bootloader flowchart is presented in slide #7
  • 3. © Hakim Weatherspoon, Computer Science, Cornell University Basic Computer System • A processor is a device that executes instructions Processor has some internal state in storage elements (registers) • A memory holds instructions and data von Neumann architecture is assumed for simplicity • A bus connects the two regs bus processor memory 01010000 10010100 … addr, data, r/w
  • 4. ARM Cortex-M Start UP Sequence • Electronically – Fetch Stack Pointer from address 0x00 – Fetch Program Counter from address 0x04 • Software – Execute assembly function Reset_Handler Initialize vector table and call the followings: – Execute c function SystemInit Initializes clocks and VTOR – Execute assembly function __iar_data_init3Initialize Initializes variables – Call function main User program But address 0x00 does not exist in Flash ! It is mapped to other address (0x08000000 in normal execution)
  • 5. System Memory • Written in ROM within the Flash • Has two functions: – Firmware update (When nBFB2 = 1) – Execute code from bank 2 (When nBFB2 = 0)
  • 6. nBFB2 bit • nBFB2 = 1 at startup – Normal Execution • nBFB2 = 0 at startup – Address 0x00 is mapped electronically to System memory – System memory Jumps to bank 2 • Undocumented important Takeaways: – When running from bank 2 (nBFB2 = 0), an attempt to update firmware from system memory will FAIL, because it will result in jumping back to bank 2 – Unlike STM32L0XXX and STM32L4XXX, nBFB2 does not result in bank swap
  • 7. Wrtieto EEPROM: Go_to_BL_Flag=1 Yes Wake up from Reset Go_to_BL_Flag=0 Remap 0x00 to BLflash Set stackpointer to BLStack Jump to BL Yes Software Reset nBFB2 ==1 ? Field Upgrade Request ? Normal code Run from bank 2 No Communication with BL Established ? Establish communication with BL Error message (in application) Reset (Opt. Byte) No Writecodeto Bank2 And / Or Datato Bank1 Read To ValidateOK? Set nBFB2 =0 (Initiatesreset) Yes No Yes Go_to_BL_Flag==1 ? No Remap 0x00 to Flash 2 Remap 0x00 to Flash1No Set nBFB2 =1 Coderun from bank 1 Field Upgrade Request ? No Yes Yes
  • 8. BL.C #include "BL.h" void GoToBootLoader(void) { //Initializing the arguments for HAL functions FLASH_AdvOBProgramInitTypeDef OBbank1; OBbank1.BootConfig = OB_BOOT_BANK1; OBbank1.OptionType = OPTIONBYTE_BOOTCONFIG; // Write to EEPROM that BootLoader should be executed HAL_FLASHEx_DATAEEPROM_Unlock(); HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_WORD, EEPROM_Address_Mode_Of_Execution, ShouldExecuteBootLoader); //Change to (or stay at) bank1 and reset the device HAL_FLASH_OB_Unlock(); HAL_FLASHEx_AdvOBProgram(&OBbank1); HAL_FLASH_Unlock(); HAL_FLASH_OB_Launch(); }
  • 9. void SystemInit (void) // Define our function pointer void (__code*SysMemBootJump)(void); // Set system memory address. volatile uint32_t addr = BootLoaderMemoryLocation; if(…) // MCU was Set to be boot from bank 1 if ( // Jump to boot loader request is registered // Reset our trigger HAL_FLASHEx_DATAEEPROM_Erase(FLASH_TYPEPROGRAM_WORD, EEPROM_Address_Mode_Of_Execution); //Set jump memory location for system memory SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4 ))); //Remap system memory to address 0x0000 0000 in address space __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH(); SCB->VTOR = 0; // BootLoaderMemoryLocation; Since 0 is mapped to system memory __set_MSP(*(uint32_t *)addr); // Point the PC to the System Memory reset vector SysMemBootJump(); } else{ // Running Code from bank 1 SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH.*/ } } else // run from bank2 { SCB->VTOR = FLASH_BANK2_BASE | VECT_TAB_OFFSET; }
  • 10. Requirement from external application Input The input to the external (smarthphone) is a binary file of size X bytes, where in our case 0x38000 < X < 0x40000 changes from one update to the other. Goal The binary file is to be copied into flash, where the first byte is copied to address UpdateCodeStartAddress and the last address is to be copied to UpdateCodeStartAddress + X, where UpdateCodeStartAddress = 0x08008000. After the file is copied (and verified that it is copied correctly), the micro-controller should be booted from bank 2.
  • 11. Bootloader limitations ST bootloader has limited address range allowed to be written (all of bank 1 and ½ of bank 2). Usually two valid applications should be available, in order to accommodate a failure during update of one of the versions. If the application requires more than ½ the space of a bank, only one out of the two application may be updated  Why? Hint: The firmware update by ST built in bootloader may only take place when nBFB2 = 1. Due to the above limitation, it has been decided to use custom boot loader, and therefore this presentation is brought back to the public domain (as all of my knowledge was learned from the public domain)
  • 12. Memory banks in STM32L1XX Two Banks All of Bank 1 and Half of Bank 2 are accessible by ST ROM Bootloader Factory Code @ Bank1 (start address 0x08000000) Updated Code @ Bank2 (start address 0x08040000) Updated Graphics data @ bank 1 (start address 0x08008000) Factory Graphics data @ bank2 (start address 0x08048000)