Boot-loader code vs Start-up code?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Boot-loader code vs Start-up code?

9,334 Views
aswinkumarr
Contributor III

Hi,

 

I am getting confused often between the difference of Bootloader code and start-up code. What is the difference between these two codes. which code will get execute first while power-on-reset.

 

Thank you.

Labels (1)
Tags (2)
3 Replies

3,634 Views
RadekS
NXP Employee
NXP Employee

Hi Aswinkumar,

Start-up code is short code which will clear your RAM after reset and initialize variables (copy from flash to RAM). It could also initialize memory map (enable/disable EEPROM/Flash, set register, RAM, EEPROM alignment – only for old S12 MCUs, disable/enable watchdog,…). Tasks for start-up code depend on your definitions, but initialize RAM is most important step. I case of S12(X) cores and CW Classic IDE, default start-up code is in Start12.c file. In case of S12Z core and CW Eclipse IDE, default start-up code is in Start12z.c file.

These file are typically executed as first prior main application. Reset vector typically points to _Startup() function.

Bootloader is application which allow to you erase main application and load new version of this application back to flash.

In typical case, we switch between Bootloader and main application trough MCU reset. Therefore very small part of bootloader could be executed even before _Startup() function and just decide whether Bootloader or main application will be executed. After that, appropriate _Startup() function and application or bootloader code will be executed.

Bootloader typically communicate with computer via some standard interfaces like SCI, SPI, CAN,…

Example of bootloaders:

AN4258 Serial Bootloader for S12(X) Microcontrollers Based on 180 nm Technology

http://www.freescale.com/files/microcontrollers/doc/app_note/AN4258.pdf

http://www.freescale.com/files/microcontrollers/doc/app_note/AN4258SW.zip

for MCUs like S12G, S12XE,….

Or

AN4723 S12Z MagniV Bootloader

http://www.freescale.com/files/microcontrollers/doc/app_note/AN4723.pdf

http://www.freescale.com/files/microcontrollers/doc/app_note/AN4723_SW.zip

for MCUs like S12ZVM, S12VC,…


I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

3,634 Views
aswinkumarr
Contributor III

Hi,

Thank you for your reply.

From your explanation, i understood after reset vector startup() will execute first. I have gone through the start12z.c file, in that after all process main() function is getting invoked. Whether that main() function is application main() or bootloader main() function.

Thank you.

0 Kudos

3,634 Views
RadekS
NXP Employee
NXP Employee

Hi Aswinkumar,

Yes, you could implement code for decision between application main() or bootloader main() function into start12z.c file. But in fact, both AN4258 and AN4723 used slightly different approach.

AN4258 has very small assembler code which is executed as first and make decision which _Startup() function will be executed (startup code from application or startup code from bootloader). This decision could be based on pin level, value in EEPROM…

This approach has advantage in minimal intrusion of bootloader code. MCU execute just few instruction prior start application. Disadvantage is that this small code is slightly more difficult to use – it is not user friendly like C-code, we do not have initialized variables yet,…

AN4723 bootloader starts bootloader at every start include MCU initialization. Condition for start of main application is part of this bootloader. To ensure that the main application receives the MCU in a known and expected state, the bootloader must return all the modified registers to its initial value.

Biggest advantage is that this approach is simpler solution. Disadvantages of this solution is in double initialization (first bootloader and after that application) for most of MCU resets and this way also delay in start application.

Second disadvantage is dangerous in use of some write-once registers. Some of registers could be written just once after MCU reset, like initialization COP watchdog. This settings cannot be revert back to default without MCU reset. So, in some cases, it is necessary to develop application code in cooperation with bootloader code and knowledge of options which cannot be modified in application.


I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos