Loading Image in app and passing to bootloader

I am using SDK16 and attempting to load images for loading.I have questions and would welcome pointers

1. I need to use the application to load a new image into memory ready for loading. What is preferred method to pass information to the bootloader so that it will load the image on next reboot? I have adapted open bootloader to remove all the transports.

2. When I am developing an application and use an IDE to load a new image, how can the bootloader be informed there is a valid app so that it runs the app?

Parents
  • Hello,

    I have adapted open bootloader to remove all the transports.

    What bootloader, exactly did you start with?

    IT's been a while since I looked into this, but there are ways to make the bootloader use images already stored in flash. You need to store it in flash as if it was uploaded by the bootloader itself, but I am not sure about what you mean by "Open bootloader" Did you disable the security? Or just the transport layers?

    Best regards,

    Edvin

  • I started from an example in SDK16 called open_bootloader and disabled all the transports as these are not used in the bootleader, rather the applications places a binary copy of the image in flash using a file sent in ascii format, either hex or srec, and coverts on the fly. This provides information on load address, store address, and size, and could also manage merged hex.

    My questions are:

    1. How does my application pass information to the bootloader that there is an image in flash to be loaded. Is there a preferred method. If not then I can use a common area of flash.

    2. If I have a bootloader, how do I provide information to the bootloader that there is a valid application to run if I load the application using the flash tools provided by an IDE.The problem is that I can't use the app to signal the bootloader as the app is never run.

  • My application already does 90% of the work and so I have decided to add code to erase the old image and flash the new image. This is easily done by running the required code from RAM so that it is not erased. This works.

    The hex file contains a value to be written at 10001018 (UICR_PARAM_PAGE_ADDR) and the start address for the application. My question is where to write the start address so that soft device jumps to the correct location to run the application as I do not have a bootloader.

    This approach works if I flash the same image as the start address does not change, but will fail if i change the code in the image.

  • Malcolm said:
    This is easily done by running the required code from RAM so that it is not erased. This works.

    You should consider what would happen if you loose power during this operation. At least if this is an end product, it is not unlikely that someone are to power off the device, not knowing the consequences. 

    Malcolm said:
    The hex file contains a value to be written at 10001018 (UICR_PARAM_PAGE_ADDR) and the start address for the application

    You can't update the UICR on the nRF52840 during runtime. That is, you can write to it if it is 0xFFFFFFFF, but if it is not 0xFFFFFFFF, you can't write to it without erasing it, and you can't erase it from the application on the nRF52840. So if you need to update this register on every DFU, then you can't do that. 

    But why do you need to update the value at UICR_PARAM_PAGE_ADDR? Wouldn't it be the same every time?

    Best regards,

    Edvin

  • I accept your point about the bootloader and so I am returning to determine if I can fix issues so the bootlloader will cooperate with my app:

    1. How do I initialise access to memory used by the bootloader within my app to pass information on the image to flash (i.e write to bank 1 with parameters)?

    2. How do I ensure my app creates a separate area in flash for FDS storage so it does not use the same area as bootloader?

    3. When the bootloader starts an app (nrf_bootloader_app_start) how do I initialise NRF_LOG to use RTT. Before the bootlloader was used this used to work, but now I only see bootloader messages?

  • 1: Not sure exactly what you mean? Do you mean how to tell the bootloader to start the DFU process, moving the new application to the correct place? If so, you can look at the ble_app_buttonless_dfu example, which does this. It writes a value to the GPREGRET register in ble_dfu.c:

        err_code = sd_power_gpregret_set(0, BOOTLOADER_DFU_START);
        VERIFY_SUCCESS(err_code);

    This register is retained during resets, and the bootloader checks this register on startup to decide whether to enter DFU mode or not.

    Malcolm said:
    2. How do I ensure my app creates a separate area in flash for FDS storage so it does not use the same area as bootloader?

    In your bootloader's sdk_config.h, you will find a definition:

    NRF_DFU_APP_DATA_AREA_SIZE

    Which is the number of bytes closest to the bootloader (the top, right beneath the bootloader) that the bootloader will never touch. This is the location where FDS is also being placed. By default, this has the value 12288, which is 3 flash pages, but you can adjust this to fit your application.

    Malcolm said:
    3. When the bootloader starts an app (nrf_bootloader_app_start) how do I initialise NRF_LOG to use RTT. Before the bootlloader was used this used to work, but now I only see bootloader messages?

    The way that RTT logging works is that the messages are written to an area in ram. When you have two instances (bootloader and application) using RTT, then these will end up in different places. Unfortunately, the way that the RTT terminals work is that it looks for a special word in RAM where it will find the logs. It usually looks until it finds it, and starts printing the logs from there. So if you have two places in RAM where this appears, then you need to either search for another address where this is set. You can specify what addresses to search in, so if you find the first place in one RTT log instance, you can search for only the ram addresses after that.

    Or a simpler option is probably to disable the RTT logging from the bootloader when you want to monitor the logs from the application.

    Best regards,

    Edvin

  • 1. I have used GPREGRET in the application to signal to the bootloader to commence loading a new image.

    2. I am struggling to understand how to configure FDS so that my application and the bootloader can share a common area of memory.  I can get them to use separate areas. However I need to exchange information on the location and size of the image to load. The bootloader uses FDS to define an area to store information on the banks, and my application uses FDS to define an area to store information on the image to load. Somehow one needs to access the information of the other.

    3. The simple option works fine.

Reply
  • 1. I have used GPREGRET in the application to signal to the bootloader to commence loading a new image.

    2. I am struggling to understand how to configure FDS so that my application and the bootloader can share a common area of memory.  I can get them to use separate areas. However I need to exchange information on the location and size of the image to load. The bootloader uses FDS to define an area to store information on the banks, and my application uses FDS to define an area to store information on the image to load. Somehow one needs to access the information of the other.

    3. The simple option works fine.

Children
  • Oh, I think I misunderstood you in your previous reply, regarding the shared memory.

    Usually the way this works, is that this is part of the init packet (and then later the bootloader settings, which holds information about the application image. 

    I am actually not sure what the best way to do this without an init packet, which I guess that you don't have. I guess I would look into just using the first flash page in the bank to store the size of the application (or elsewhere), and this information will be present when the bootloader is told to start changing the application. Use the first page to store your application information (size, CRC, and so on), and then you store the actual application image from the second page and onwards.

    Best regards,

    Edvin

  • It may sounds a bit too much to use an entire flash page for this, but I imagine it is easier to have this at a known address, and also that it is better to copy N pages from page 2 (the application image) into where it is supposed to be, rather than having this awkward offset. An alternative is to store it somewhere else that is known, but that will be the page right beneath the FDS pages (since you can only erase an entire flash page at the time, it is probably easier to use an entire flash page for this). Another option is to store it in FDS, but that would require you to add FDS to your bootloader as well, which will increase the size of your bootloader. (Or you can look into the structure of FDS, and implement a parser looking for the record containing the start address and size of the new image. Sort of like a strip down version of FDS).

    Best regards,

    Edvin

  • Thank you for the suggestions. There could be several approaches such as a link (SWI?) between app and bootloader and include an action block in the call to pass parameters, much as the init.

    However there is lots of space between the bootloader (E0000) and MBR parameters (FE000) to use 1 page as common memory available to both and to use simple erase and write functions..

  • Malcolm said:
    There could be several approaches such as a link (SWI?)

    That is possible, and I know this is being used by the application to tell the bootloader what advertising name to use, but unfortunately I am not very familiar with the very details on how that works. I also don't see why that would be better than just storing it in flash, since this is what the bootloader would have to do after being triggered by SWI either way, so that the bootloader can check it after the next reboot.

    As I mentioned, the reason you need a separate flash page, and that you can't use the last few bytes of e.g. the bootloader's pages, is that whenever you need to update the values that you write, you need to erase it first, and the smallest partition that you can erase is one flash page (4096 bytes). So if that was the tail of the bootloader, you would need to erase part of your bootloader, which is unfortunate. 

    Typically the bootloader is pushed as far up (high address) as possible, while reserving a page for bootloader settings and MBR params. So if you have taken away so much of the bootloader that it's flash size has reduced by more than one flash page, I would rather suggest moving the bootloader up one page. Note that it is not possible to move the start address of the bootloader through DFU, so if you want to add features to the bootloader, causing it to increase in size, then you may want to consider leaving an empty flash page above the bootloader. 

    Either way, I would suggest having this flash page directly beneath your FDS pages, and remember to increase the NRF_DFU_APP_DATA_AREA_SIZE by one page, so that the bootloader doesn't overwrite it during DFU. 

    Best regards,

    Edvin

  • Thank you for your valuable suggestions. By removing all the transports, and thus security code, and dealing with commands, the bootloader is reduced to 30k (none optimized) and can be moved up to F0000, just below MBR parameters, with 1 page beneath MBR for my parameter passing. I think I have a solution,

Related