This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Embedding firmware for external MCU in firmware image

I have another MCU on the same board as the Nordic 52832. The firmware update image for the MCU is about 50kb in size, so instead of adding a parallel DFU for the MCU through Bluetooth I figured I could just embed the firmware in the Nordic firmware. What is the best way to store this data in the firmware image so it isn't loaded into RAM but can be read directly from flash as required? I'm guessing if I store it in an array it will be loaded into RAM.

Parents
  • Hi Nick, 

    Could you explain a little bit more on what you are planing to do ?

    How do you send the firmware from the nRF52 chip to the 2nd MCU ? 

    How do you receive this firmware to the NRF52  ?

    You can merge 2 binary image in flash. I don't see the reason of using an array here. 

  • I want to store the firmware binary data inside the Nordic firmware so I can just use the Nordic DFU and don’t need to add a second DFU process. The data will then be sent to the MCU via serial. So I need to read the data from flash and send it over serial on the nRF.

  • Hi Nick, 

    I think it's easiest to use J-Link Commander to do the combination. There are functions called loadbin and savebin that you can load a binary file in a location that you choose and then you can load the combined binary out. 

    I have used the tool in my example for DFU master, you can find here. Check the documentation. 

    When you have the binary, you need to modify the .zip and the initpacket manually because nrfutil doesn't support .bin as input. Or you need to convert .bin to .hex (or use nrfjprog to read hex but you may need to modify the .hex so that it only contain the meaningful part not the 0xFFFFFFF part). 

    DFU bootloader when running in dual mode will not overwrite the application until the image is received. 

  • Ok thanks, is there a tool that can convert bin to hex? And how can I obtain a flash address and length of data from the application?

  • What you want to achieve is kind of advance. It's not something out of the box that we can provide. Knowledge on binary (and hex) image is needed.

    If you want to do something, please do search before asking. 

  • I understand that it is not a normal task, and I did search before asking but found nothing. But guidance on how this can roughly be achieved can lead me in the right direction. I’m not asking for it done for me, just how it could be done. So far I’m not sure how I would be able to get the address and length of the data. I guess I would need to store the data at a fixed place in flash specified in the hex file. The length could be stored in the data. But I am asking because perhaps there is another way. I see ARM have a bin2hex tool so I guess I could merge the data into the firmware hex directly using that? And then just use nrfutil to generate zip normally?

  • Yes you can use bin2hex to convert to hex file.

    When you have the .bin file (can be from hex2bin or from nrfutil) you will have the size of the .bin file equal to the size of the actual image. 

    Note that unlike .hex file, in .bin file there is no concept as address. Bin file is simply binary, the actual image data, no address. 

    The challenge is just to create a hex file that contains the 2 images. I haven't done this but I do think that it should be possible using the 2 .bin files, combine them and convert them back to .hex.

    In your code, to detect where the image started you can make a pattern that mark the start of your firmware for example 100 bytes of 0xAA continuously. (in my DFU master code, I simply going backward and look for first byte which is not 0xFF as the marking of the end of the image, please have a look in find_image_size() ). But it's the best if you can modify the bootloader to write to a place in bootloader setting to mark where the image is and the size of the image. 

Reply
  • Yes you can use bin2hex to convert to hex file.

    When you have the .bin file (can be from hex2bin or from nrfutil) you will have the size of the .bin file equal to the size of the actual image. 

    Note that unlike .hex file, in .bin file there is no concept as address. Bin file is simply binary, the actual image data, no address. 

    The challenge is just to create a hex file that contains the 2 images. I haven't done this but I do think that it should be possible using the 2 .bin files, combine them and convert them back to .hex.

    In your code, to detect where the image started you can make a pattern that mark the start of your firmware for example 100 bytes of 0xAA continuously. (in my DFU master code, I simply going backward and look for first byte which is not 0xFF as the marking of the end of the image, please have a look in find_image_size() ). But it's the best if you can modify the bootloader to write to a place in bootloader setting to mark where the image is and the size of the image. 

Children
No Data
Related