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

preparing a hex file to program in flash

Hello, I am using nrf52832 board, with SDK 11.0.0 and s132_nrf52_2.0.0. and trying to program a 512 Bytes text file using nrfjprog (J-Link: JLinkExe) in flash. The nrfjprog tool only allows a 4 Byte value write at a time to a an offset so I am trying to use the J-link loadfile command. I think I need to convert my 512 B text file to an Intel hex format and then use the mergehex to merge the file with softdevice and application hex files. However, I can't find clear instructions on how to convert my text file to hex as well as addresses to change before merging the 3 hex files. Would I need to manually create "records" for the Intel hex file? I am using Linux for development. Please advise on instructions to create the hex file, and tools to flash. Thanks.

  • Hi Sal, I don't think it would a simple way to convert a text file to binary/hex. You need to compile it or if it's simply data (or keys), you need to state the address it going to be.

    What I would suggest is to try to read the address you want to put the data in on the flash using nrfjprog. And then use any editor that can edit hex (notepad++ for example) and edit the hex file you get to the data you need, you then need to calculate CRC according to Intel Hex format. There is a CRC calculator here: www.fischl.de/.../

    Then you can use nrfjprog to flash it back to the chip.

  • Hi Hung, Thank you for your help. The text file contains openssl key pair, base64 format. I used a hex converter to encode in hex (tomeko.net/.../base64.php). Then used the jlink loadbin command to load the file to an offset on the flash. After reading the file, looks to be okay, although endian converted and needs to be reverted back for authentication.

    I am using the openssl to authenticate my peripheral device when connecting to the central. I think it is not really designed for embedded applications. Looking at your comment, on a similar post here: devzone.nordicsemi.com/.../

    I am also not using device manager, and wondering if it would be possible to not use bonding and only write a key on flash (I am using pstorage) along with FW+BL+SD that on connection is read (with pstorage_load()?) and could be used to authenticate connection to a central device?

    Many thanks.

  • Hi Sal, Thanks for the link, good to know the tool.

    If you have control on both side of the link (central + peripheral) you can hardcode the long term key (LTK) and re-use it when they connect. Just like what happens here on the central and here on the peripheral.

    However, this way of using hardcoded key is not very safe. Anyone who has physical access to your device can try to read the key (even if you block them from accessing the debug port, it's possible to physically manipulate the chip and read the flash directly) or if you do DFU, they can read the DFU package that includes the key.

  • Thanks for your suggestion Hung. Unfortunately I do not have control over the central device.

Related