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

NRFUtil package generate drops portion of hexfile at address 0

Hello Nordic,

I'm evaluating the --external-app option of nrfutil and I noticed something odd. 

First, I create an example hex file with 8kb of random data and then run it through bin2hex.py, and then generate a package with nrfutil.

$ bin2hex.py rand8kb.bin rand8kb.hex
$ nrfutil pkg generate --hw-version 52 --application-version 0 --external-app --key-file ./source_code/private-key.pem --application rand8kb.hex rand8kb.ota.zip --sd-req 0xCD
Zip created at rand8kb.ota.zip

But then I noticed that NRF connect was telling me it was only 4kb. And nrfutil agrees:

$ nrfutil pkg display rand8kb.ota.zip

DFU Package: <rand8kb.ota.zip>:
|
|- Image count: 1
|
|- Image #0:
   |- Type: application
   |- Image file: rand8kb.bin
   |- Init packet file: rand8kb.dat
      |
      |- op_code: INIT
      |- signature_type: ECDSA_P256_SHA256
      |- signature (little-endian): b'2ff622cd82c6b90e2ef98c64f037234f09ff075137a0b5c4f563b05fe5635ef2d256fc5636f640229a23695b29e8bbdc8da8e04c3c39ebdeaaafd2b047e3592b'
      |
      |- fw_version: 0x00000000 (0)
      |- hw_version 0x00000034 (52)
      |- sd_req: 0xCD
      |- type: EXTERNAL_APPLICATION
      |- sd_size: 0
      |- bl_size: 0
      |- app_size: 4096
      |
      |- hash_type: SHA256
      |- hash (little-endian): b'49d07e45417d54efb3c33c150d227793a214bb27d1d8ed7323b79e22752fc8ba'
      |
      |- boot_validation_type: ['VALIDATE_GENERATED_CRC']
      |- boot_validation_signature (little-endian): [b'']
      |
      |- is_debug: False

After double checking by binary and hex files, I had the thought to try a different offset in my hex file. Perhaps a lucky guess, but this seems to preserve the beginning of my hex file.

$ bin2hex.py --offset=4096 rand8kb.bin rand8kb-offset4kb.hex
$ nrfutil pkg generate --hw-version 52 --application-version 0 --external-app --key-file ./source_code/private-key.pem --application rand8kb-offset4kb.hex rand8kb-offset4kb.ota.zip --sd-req 0xCD
$ nrfutil pkg display rand8kb-offset4kb.ota.zip

DFU Package: <rand8kb-offset4kb.ota.zip>:
|
|- Image count: 1
|
|- Image #0:
   |- Type: application
   |- Image file: rand8kb-offset4kb.bin
   |- Init packet file: rand8kb-offset4kb.dat
      |
      |- op_code: INIT
      |- signature_type: ECDSA_P256_SHA256
      |- signature (little-endian): b'19aef0aa50fef35c7c5de824da50d9004357d1e72b26cdef95bcf36ed92208c9d02e18f807f74257f35bd6b3e7bb0d147858c116cdaf7383f5cde941c491a694'
      |
      |- fw_version: 0x00000000 (0)
      |- hw_version 0x00000034 (52)
      |- sd_req: 0xFFFE
      |- type: EXTERNAL_APPLICATION
      |- sd_size: 0
      |- bl_size: 0
      |- app_size: 8192
      |
      |- hash_type: SHA256
      |- hash (little-endian): b'006f43a90c0c7b7524455a76df35552b86850bd56c804cd061359e03367186df'
      |
      |- boot_validation_type: ['VALIDATE_GENERATED_CRC']
      |- boot_validation_signature (little-endian): [b'']
      |
      |- is_debug: False

It's now the full 8kB. Same 8kB size is preserved with a hex file offset of 8kB or even 256kB. 

So I guess the question is: does nrfutil drop a portion (4kB?) from the hex file at address 0? I'm guessing this is to avoid including the MBR in an OTA package. If so, would it be possible to skip this behavior when using --external-app? 

Thanks,

Paul

Related