SlideShare a Scribd company logo
1 of 12
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 organizationNitesh Singh
 
COMPUTER ORGNAIZATION NOTES
COMPUTER ORGNAIZATION NOTESCOMPUTER ORGNAIZATION NOTES
COMPUTER ORGNAIZATION NOTESDr.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 registersmahesh kumar prajapat
 
The Digital Logic Level
The Digital Logic LevelThe Digital Logic Level
The Digital Logic LevelLiEdo
 
Computer architecture input output organization
Computer architecture input output organizationComputer architecture input output organization
Computer architecture input output organizationMazin Alwaaly
 
Assembly Language
Assembly LanguageAssembly Language
Assembly LanguageVijay Kumar
 
COMPUTER ORGANIZATION NOTES Unit 5
COMPUTER ORGANIZATION NOTES Unit 5COMPUTER ORGANIZATION NOTES Unit 5
COMPUTER ORGANIZATION NOTES Unit 5Dr.MAYA NAYAK
 
Unit 4-input-output organization
Unit 4-input-output organizationUnit 4-input-output organization
Unit 4-input-output organizationvishal choudhary
 
VJITSk 6713 user manual
VJITSk 6713 user manualVJITSk 6713 user manual
VJITSk 6713 user manualkot seelam
 
COMPUTER ORGANIZATION NOTES Unit 3 4
COMPUTER ORGANIZATION NOTES  Unit 3 4COMPUTER ORGANIZATION NOTES  Unit 3 4
COMPUTER ORGANIZATION NOTES Unit 3 4Dr.MAYA NAYAK
 
Computer organisation
Computer organisationComputer organisation
Computer organisationMohd Arif
 
Input output organisation
Input output organisationInput output organisation
Input output organisationSanjeev 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 architecturevikram 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 loaderOmer Korech
 
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
 
4bit PC report
4bit PC report4bit PC report
4bit PC reporttanvin
 
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 microcontrollerGarba Geidam
 
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-v2handson28
 
Assembly programming
Assembly programmingAssembly programming
Assembly programmingOmar Sanchez
 
AAME ARM Techcon2013 005v02 System Startup
AAME ARM Techcon2013 005v02 System StartupAAME ARM Techcon2013 005v02 System Startup
AAME ARM Techcon2013 005v02 System StartupAnh Dung NGUYEN
 
Protocolo de programacion del pic16 f8x
Protocolo de programacion del pic16 f8xProtocolo de programacion del pic16 f8x
Protocolo de programacion del pic16 f8xrich_glez
 
Hacking the 2016 Hackaday SuperConference Badge
Hacking the 2016 Hackaday SuperConference BadgeHacking the 2016 Hackaday SuperConference Badge
Hacking the 2016 Hackaday SuperConference Badgeszczys
 
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-mumbaiUnmesh 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 CourseVikas 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[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]
 
4bit PC report
4bit PC report4bit PC report
4bit PC report
 
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

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 

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)