Firmware update using a custom bootloader

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

Firmware update using a custom bootloader

1,965 Views
gauravbanyal
Contributor IV

Hello Kerry Zhou,

 

I am using a MKL03Z32 micro-controller and I have a need to write a custom booloader to enable fimware-over-the-air updates to the application code. In my schematics I have only the MKL03Z32 and to its I2C interface I have 2 slave devices, none of them are microcontrollers. When I read through the description of the Kinetis ROM Bootloader that comes with the devices, I understand that I can use it only with another on-board host processor or PC using the MKL03Z as a slave device and connecting to one of its buses I2C/UART/SPI. So in my case I cannot use it. Please confirm if my understanding is correct.

 

The use-case I have is that I can send the FW image to the MKL03 via the on-board NTAG I2C chip. I just need to write a new application that sits on the flash memory in a defined area (separate from the application code) which has a specific flash area used to store the FW image it receives via the NTAG I2C chip (typically sent by a NFC enabled phone app) and overwrites the application area with the received FW image. I am using Keil MDK5 IDE for my work.

 

I need help on the following things:

1. How to modify the scatter file to define separate areas for application, bootloader and the area the bootloader needs to store the incoming FW image file (I don't have an external memory on the board attached to the microcontroller).  I want the boot-up to always run the bootloader code and based on certain conditions, bootloader code may either continue with its stuff or jump to application code area.

I have attached the linker script that my project is using. Please modify it and send me two versions back. One for the bootloader code (default entry point after a reset) and one for the application code (only executed when control jumps from bootloader to application).

 

2. The instructions to write the new FW image to the application area in the flash.

3. Jump the execution to the application area after a successful flashing.

 

Please help me on priority on this one.

 

Many thanks,

Gaurav.

Original Attachment has been moved to: MKL03Z32xxx4_flash.scf.zip

Original Attachment has been moved to: MKL03Z32xxx4_flash_app.scf.zip

Tags (1)
0 Kudos
5 Replies

892 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Gaurav Banyal,

Thank you for your patient!
Answer your understanding question at first:
Yes, if you want to change the KL03Z app with the on board ROM bootloader, you need to find the PC or other chip as host, normally, we use the PC as host, and assoicate with the PC software to download the APP code to the KL03 chip through the UART, USB, I2C, ect. UART and USB is the usually used bus.

You can realize the application which you mentioned, but what I am afraid is the KL03z32 flash size, it is just 32K, it is really very small for your own designed flash bootloader and the application code.
Now answser your several questions:
1. How to modify the scatter file
  About this question, we have some example for your reference.
  I think you may download the KBOOT2.0 before, you can download it from this link:
  https://www.nxp.com/webapp/Download?colCode=NXP_KINETIS_BOOTLOADER_2_0_0&appType=license&Parent_node...
  After you download it, you can refer to the MDK KL25 APP project.
  Folder: NXP_Kinetis_Bootloader_2_0_0\apps\led_demo\MKL25Z4\mdk\led_demo_freedom_8000
  You can refer to this project sct file, it relocate the code to the 0X8000.
   If you want to have two areas, just define two difference area in the .sct file.
   Please refer the offical code at first.
2. The instructions to write the new FW image to the application area in the flash.
   Actually, you just need to learn the KL03 flash write and erase, you also can refer to the KL25 flash bootloader, KL25 don't have the ROM bootloader, so it just the flash bootloader.
   When it save the app code from the PC, it will write to the according application flash area.
   The KL25 flash bootloader code can be found from KBOOT2.0 folder:
   NXP_Kinetis_Bootloader_2_0_0\targets\MKL25Z4\mdk\freedom_bootloader

3. Jump the execution to the application area after a successful flashing.
   Still refer to KL25 flash bootloader jump code.
static void jump_to_application(uint32_t applicationAddress, uint32_t stackPointer)
  This function is used to jump to the applciation code.

Wish it helps you!


Have a great day,
Kerry

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

0 Kudos

892 Views
gauravbanyal
Contributor IV

Hello Kerry,

I am sorry for sending a reminder but I am really stuck because of the issues I am facing and would appreciate if you could kindly help me out on priority.

Best regards,

Gaurav.

0 Kudos

892 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Gaurav Banyal,

   I already reply you in my above reply!

  Your .sct file is correct for address 0x3000.

  About the question: flash addresses 0x0000 through 0x3000

  You just need to modify the m_text_size in the original scf which locate from 0x0000.

Wish it helps you!

  


Have a great day,
Kerry

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

0 Kudos

892 Views
gauravbanyal
Contributor IV

Hello Kerry,

Thanks for the example you shared. I have tried to modify the scatter file with reference to the example. I changed the addresses so that the application code occupies flash addresses 0x3000 through 0x8000. It compiles, links, programming and verification on the chip is fine but never boots, therefore debugging was also not possible. Could you please suggest what's wrong. I will attach the modified scatter file to the original post with the name "MKL03Z32xxx4_flash_app.scf".

Could you please do me another favor, could you please duplicate this file as "MKL03Z32xxx4_flash_bootloader.scf" so that I can use this on my other project (custom bootloader) which I want sits between flash addresses 0x0000 through 0x3000? 

Thanks for your help.

Best regards,

Gaurav Banyal.

0 Kudos

892 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Gaurav Banyal,

    About the .scf for 0X3000, I have check your file, it is correct.

   It never boots, because you didn't add the according jump code.

   As you know, if the code run from the flash, the code will run from 0X000 at first.

  But you put the application code directly at 0X3000, you still need to jump to that address, use ROM bootloader jump or your need to jump  from the 0X000 your own flash bootloader.

  I also modify a application code which relocate to 0X3000, and test it with the ROM bootloader(we need to the make sure the APP relocate have no problem), it works.

  I have attached my code, folder: App_flash0x3000\SDK_2.2_FRDM-KL03Z\boards\frdmkl03z\driver_examples\gpio\led_output\mdk

  It test on the FRDM-KL03, function is blinking the RED led.

pastedImage_1.png

  You can check it at first. After you use the KinetisFlashTool to relocate the app to 0x3000, the code will working, boot have no problem.

   This success is the first step, after it also works, we can add your own flash bootloader code which contains the jump to app code.

Wish it helps you!

 


Have a great day,
Kerry

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

0 Kudos