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

Custom DFU bootloader

Hi,

I have a custom board with the nRF52840.

Is it possible to customize the DFU to be able to update the firmware through other interfaces than BLE or USB/UART?

I have a SD-card connected and would like to check for a flash image on the card and then update the firmware if there is an image.

Would that be possible?

Parents
  • Hello, did you ever get it to work? 

    I have a similar problem for my pca10040/S132 (Laird BL652), and am getting really confused by the cryptic barely documented DFU interface.  I noticed that one example uses pstorage, is that the way to bypass all that?  I suddenly have clients breathing down my neck wanting a firmware update to allow SD-card firmware updates before end customer distribution.  ;-)  

    Thank you,

    -Erik

  • Hi,

    I did get it to work, but doing some reverse engineering.

    I made use of the Background DFU - that are running inside my application. So I have access to all my peripherals - including my SPI interface to my external sd-card running with FatFS.

    In my program I check the sd-card for a specific bootloader file, and if that exists I go to a state where I read the file 1 byte at a time.

    I added the UART bootloader to my code and commented out the interrupt routines and added my own function to call. Then I can pass the byte I read from the file to the UART bootloader.

    In order to get it to work I had to make a file-converter that actually reads the .zip package, that are normally used by the bootloader, and convert it to a new file that also contains the DFU package info (because this is normally handled by the interface program on the PC).

    Hope this helps a little - if you like I will be happy to share my code for the bootloader and the file-converter with you.

    -Morten

  • Marten,

    Oh!  Please!  Anything that helps.  I don't understand why I am having so much trouble with this when I had little problem with everything else (except for a library bug which I fixed), so anything that gives me a light bulb over my head is great.

    Thanks,

    -Erik

  • I have attached my main.c file and the nrf_dfu_serial_uart that I uses.

    I have removed most of the code from my main file, but you can see the state where I do the bootloader.

    nrf_dfu_serial_uart.zip

  • Thanks!  I like how you tied it into the serial_dfu code.  Two questions, 

    1. DFU_TRANSPORT_REGISTER doesn't seem to exist.  What rev of nRF are you using?  I have 15.2.

    2. I notice that you go into a complicated bootloader setup in main.  Is all that necessary for the DFU to work?

    Thanks again,

    -Erik

Reply Children
  • Hi Erik,

    1. I use nRF52840 with SDK 15.3 (I believe the background DFU requires 15.3 as a minimum).

    2. There is a lot of log info that is not needed. In the Main function I start with a lot of if...else statements to decide if we start the bootloader - I only uses this to check if my program needs to go to other states (not related to the bootloader). This is not necessary - you can go directly to MAIN_SM_BOOTLOADER state which is were everything regarding the bootloader is handled.

    Regards,

    Morten



  • Hi mosgaard2000, thanks a lot for your code, it helped me to understand the dfu process in uart mode.

    I managed to integrate your code on my application, however, when I start the DFU process, the observer only reaches the NRF_DFU_EVT_TRANSPORT_ACTIVATED switch case and not the NRF_DFU_EVT_DFU_STARTED.

    I copied the MAIN_SM_BOOTLOADER part, and I send the upgraded image stored in the sd card byte by byte, but it doesn't do the upgrade process. 

    Do you know which could be the error?

    You mentioned that you had to make a file converter to insert the DFU package info in the .zip file. Could it be the part I'm missing?

    Thanks in advance

    Javier Balboa

  • Hi Javier,

    I think you are right that you are missing the file conversion.

    I have made a git-hub repository and put a small program to do the DFU conversion if you need that.

    https://github.com/mosgaard2000/Software_XE7

    I also uploaded a main.cpp file so you can see the code I use for converesion.

  • OMG thank you so much!!! I'll give it a try and post the results!!!

    Javier Balboa

  • Hi Morten, 

    I used your tool (thanks again) to make a .hex file. Now my application reads that file and write it byte by byte. 

    Now the NRF_DFU_EVT_DFU_STARTED switch case gets fired but right after, the nrf_dfu_req_handler complaints about the firmware size:

    Creating the object with size 0x00001000 would overflow firmware size. Offset is 0x00000000 and firmware size is 0x00000844

    I'm not sure if I set a wrong value for the firmware size or if there is any other problem. 

    The full log is this:

    <info> app: Application version 0
    <info> app: Writting
    <info> app: NRF_DFU_EVT_DFU_STARTED
    <error> nrf_dfu_req_handler: Creating the object with size 0x00001000 would overflow firmware size. Offset is 0x00000000 and firmware size is 0x00000844.
    <warning> nrf_dfu_serial: DFU request completed with result: 0x8
    <info> app: NRF_DFU_EVT_DFU_FAILED
    <error> nrf_dfu_req_handler: Write request too long
    <warning> nrf_dfu_serial: DFU request completed with result: 0x3
    <info> app: NRF_DFU_EVT_DFU_FAILED
    <error> nrf_dfu_req_handler: Write request too long
    <warning> nrf_dfu_serial: DFU request completed with result: 0x3
    <info> app: NRF_DFU_EVT_DFU_FAILED
    <error> nrf_dfu_serial_uart: Failed to allocate buffer
    <error> nrf_dfu_req_handler: Write request too long
    <warning> nrf_dfu_serial: DFU request completed with result: 0x3
    <info> app: NRF_DFU_EVT_DFU_FAILED
    <error> nrf_dfu_serial_uart: Failed to allocate buffer
    <error> nrf_dfu_req_handler: Write request too long
    <warning> nrf_dfu_serial: DFU request completed with result: 0x3
    <info> app: NRF_DFU_EVT_DFU_FAILED

    Am I missing something?

    Javier Balboa

Related