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

Bootloader to applocation switching issue

Hi ,

I am working on NRF DFU firmware update. for that i am using secure bootloader code .

I tried with the of way of flasing bootloader code on my custom board and sent my application code through app(NRF CONNECT) .when want to change the bootloader its moving to bootmode and can able to update . its working fine..

then i tried to merge my applicartion and bootloader code ... ( in components file i took the softdevice hex file + application code hex file ) merged together usinng commad

mergehex.exe -m softdevice.hex application.hex -o new_app.hex

using the above command - my aplication working fine.... the with the new_app.hex file merged with my bootloader hex file using the command

mergehex.exe -m new_app.hex bootloader.hex -o final.hex

using the above command - got by final hex file .

using nrfjporg command flashed my final.hex file to my custom board ..

now my question is ....

in my custom board i flashed my merged file (which is my application + bootloader )

but at first time , it enters in bootloader mode only .. in my bootloader code i set 2 mins stand by time in bootloader mode .
after that it moves from bootloader mode to application mode.but it does not enter to application mode.

Once i sent my application code via app then its switching to application mode .. as i metioned above when i want to change to boot its switching to bootloader mode if i dont update my firmware ,its automatically moving to my appllication which is running before ...if i updates its updating ...

why my merged file only in bootloader mode at first ...

from my assumption it should switch to application after 2mins (which from the merged file )

Whats the issue of it does not enter into apllication mode at first time.??????

Parents
  • Hello,

    The behavior that you see is expected because the bootloader can see that there is an application in flash, but since the application is flashed directly and not via DFU (nRF Connect), the bootloader never verified that the application is signed with the correct private key. This is a safety mechanism.

    Usually, when you generate a DFU image, you need to enter the private key as one of the parameters:

    nrfutil pkg generate --application app.hex --application-version 1 --hw-version 52 --sd-req 0xAF --key-file private.key

    This will create an image including the application, and a signature verifying that the person who generated this packet has access to the private key. When the bootloader receives this image, it will store the CRC of the application and the signature in something called bootloader settings. This means if someone changes the application in this image, the CRC will no longer match, and the singature is no longer valid. 

    Luckily, there is a way to work around this. If you have access to the private key, you can generate the bootloader settings manually using your private key and merge it together with your application+bootloader, and flash it manually. Now, when this happens, the bootloader will see that the bootloader settings accepts the flashed application, and start the application as if you transferred the application via DFU.

    To generate bootloader settings (bl_settings) you can use the following command:

    nrfutil settings generate --family NRF52840 --application app.hex --application-version 1 --bootloader-version 1 --bl-settings-version 1 --key-file private.key bl_settings.hex

    (use "nrfutil settings generate --help" for more information)

    now merge your hex file:

    mergehex.exe -m final.hex bl_settings.hex -o final_with_bl_settings.hex

    and program it using

    nrfjprog --program final_with_bl_settings.hex --verify && nrfjprog --reset

    And it should start the application.

    Best regards,

    Edvin

Reply
  • Hello,

    The behavior that you see is expected because the bootloader can see that there is an application in flash, but since the application is flashed directly and not via DFU (nRF Connect), the bootloader never verified that the application is signed with the correct private key. This is a safety mechanism.

    Usually, when you generate a DFU image, you need to enter the private key as one of the parameters:

    nrfutil pkg generate --application app.hex --application-version 1 --hw-version 52 --sd-req 0xAF --key-file private.key

    This will create an image including the application, and a signature verifying that the person who generated this packet has access to the private key. When the bootloader receives this image, it will store the CRC of the application and the signature in something called bootloader settings. This means if someone changes the application in this image, the CRC will no longer match, and the singature is no longer valid. 

    Luckily, there is a way to work around this. If you have access to the private key, you can generate the bootloader settings manually using your private key and merge it together with your application+bootloader, and flash it manually. Now, when this happens, the bootloader will see that the bootloader settings accepts the flashed application, and start the application as if you transferred the application via DFU.

    To generate bootloader settings (bl_settings) you can use the following command:

    nrfutil settings generate --family NRF52840 --application app.hex --application-version 1 --bootloader-version 1 --bl-settings-version 1 --key-file private.key bl_settings.hex

    (use "nrfutil settings generate --help" for more information)

    now merge your hex file:

    mergehex.exe -m final.hex bl_settings.hex -o final_with_bl_settings.hex

    and program it using

    nrfjprog --program final_with_bl_settings.hex --verify && nrfjprog --reset

    And it should start the application.

    Best regards,

    Edvin

Children
Related