|
| 1 | +.. _nrf_modem_bootloader: |
| 2 | + |
| 3 | +Full firmware updates |
| 4 | +##################### |
| 5 | + |
| 6 | +.. contents:: |
| 7 | + :local: |
| 8 | + :depth: 2 |
| 9 | + |
| 10 | +Initializing the Modem library in bootloader mode gives access to the functionality of the modem bootloader, through the :file:`nrf_modem_bootloader.h` interface. |
| 11 | +The modem bootloader can be used to perform a full update of the modem firmware. |
| 12 | +Full modem firmware update is the only operation that can be performed when the library is initialized in bootloader mode. |
| 13 | +AT commands and networking sockets are not available to the application when the modem is in bootloader mode. |
| 14 | + |
| 15 | +It is possible to switch between the bootloader and normal operation modes by reinitializing the library, by calling :c:func:`nrf_modem_shutdown` before :c:func:`nrf_modem_bootloader_init` or :c:func:`nrf_modem_init`, respectively. |
| 16 | + |
| 17 | +Memory requirements |
| 18 | +******************* |
| 19 | + |
| 20 | +The bootloader mode requires a shared memory area of size equal to the value of ``NRF_MODEM_SHMEM_BOOTLOADER_SIZE``. |
| 21 | + |
| 22 | +.. note:: |
| 23 | + |
| 24 | + When using the |NCS|, the library is initialized by the glue, which configures the size and position of the shared memory regions in RAM. |
| 25 | + |
| 26 | +Modem library initialization |
| 27 | +============================ |
| 28 | + |
| 29 | +To perform a full firmware update of the modem, the library must be initialized in bootloader mode as shown in the following code: |
| 30 | + |
| 31 | +.. code-block:: c |
| 32 | +
|
| 33 | + /* Initialize modem to prepare for full modem firmware update */ |
| 34 | + nrf_modem_bootloader_init(bootloader_init_params); |
| 35 | +
|
| 36 | +If the library has already been initialized in normal mode, it must be shut down through the :c:func:`nrf_modem_shutdown` function and reinitialized as shown in the following code: |
| 37 | + |
| 38 | +.. code-block:: c |
| 39 | +
|
| 40 | + nrf_modem_init(init_params); |
| 41 | + /* Shutdown and re-initialize modem to prepare for full modem firmware update */ |
| 42 | + nrf_modem_shutdown(); |
| 43 | + nrf_modem_bootloader_init(bootloader_init_params); |
| 44 | +
|
| 45 | +Considerations for corrupted modem firmware |
| 46 | +=========================================== |
| 47 | + |
| 48 | +When designing your application, you might have to consider an interrupted modem firmware update process, which can lead to corrupted modem firmware. |
| 49 | +There can be various reasons, for example power loss, which can cause an interruption in a firmware update. |
| 50 | +The modem does not have a back-up ROM and hence, an interruption in the modem firmware update process can prevent the modem from further boot up. |
| 51 | + |
| 52 | +As a workaround to the above scenario, either the application must tolerate the situation or another means of recovery must be provided, for example, reprogramming the modem with PC tools. |
| 53 | + |
| 54 | +The Modem library must then be manually initialized with the following code: |
| 55 | + |
| 56 | +.. code-block:: c |
| 57 | +
|
| 58 | + int main(void) |
| 59 | + { |
| 60 | + int rc = nrf_modem_init(init_params); |
| 61 | +
|
| 62 | + if (rc < 0) { |
| 63 | + // Recover the modem firmware from external flash |
| 64 | + nrf_modem_bootloader_init(bootloader_init_params); |
| 65 | + // Perform the full modem firmware update. |
| 66 | + nrf_modem_shutdown(); |
| 67 | + nrf_modem_init(init_params); |
| 68 | + } |
| 69 | + // Modem firmware updated, continue as normal |
| 70 | + } |
| 71 | +
|
| 72 | +
|
| 73 | +Bootloader API |
| 74 | +************** |
| 75 | + |
| 76 | +A full firmware update of the modem consists of the following steps: |
| 77 | + |
| 78 | +1. Initialization |
| 79 | +#. Programming the bootloader |
| 80 | +#. Programming the modem firmware |
| 81 | +#. Verification |
| 82 | + |
| 83 | +Bootloader forms the first segment of the firmware package and it must be programmed initially. |
| 84 | +If any failures happen, the sequence of steps must be restarted from the initialization phase. |
| 85 | + |
| 86 | +Initialization |
| 87 | +============== |
| 88 | + |
| 89 | +To initialize the full firmware update process for the modem, call the following function: |
| 90 | + |
| 91 | +.. code-block:: c |
| 92 | +
|
| 93 | + int nrf_modem_bootloader_init(struct nrf_modem_bootloader_digest *digest_buffer); |
| 94 | +
|
| 95 | +Programming the bootloader |
| 96 | +========================== |
| 97 | + |
| 98 | +To program a bootloader, call the following function: |
| 99 | + |
| 100 | +.. code-block:: c |
| 101 | +
|
| 102 | + int nrf_modem_bootloader_bl_write(void *src, uint32_t len) |
| 103 | +
|
| 104 | +The bootloader may be written in smaller chunks, which are internally appended together by the library. |
| 105 | +When all pieces are written, call the following function: |
| 106 | + |
| 107 | +.. code-block:: c |
| 108 | +
|
| 109 | + int nrf_modem_bootloader_update(void) |
| 110 | +
|
| 111 | +After a successful call, the modem changes to the DFU mode. |
| 112 | +At this stage, you can write firmware segments or issue any other DFU commands like ``verify``. |
| 113 | + |
| 114 | +Programming the modem firmware |
| 115 | +============================== |
| 116 | + |
| 117 | +Firmware segments are written by using the following function call: |
| 118 | + |
| 119 | +.. code-block:: c |
| 120 | +
|
| 121 | + int nrf_modem_bootloader_fw_write(uint32_t addr, void *src, uint32_t len) |
| 122 | +
|
| 123 | +The Modem library buffers the data with the same destination address, until one of the following conditions occur: |
| 124 | + |
| 125 | +* The buffered data reaches 8kb. |
| 126 | +* The destination address changes. |
| 127 | + |
| 128 | +At this point, the buffer is written to the flash. |
| 129 | +When all the segments are written, you must call the following function: |
| 130 | + |
| 131 | +.. code-block:: c |
| 132 | +
|
| 133 | + int nrf_modem_bootloader_update(void) |
| 134 | +
|
| 135 | +Verification |
| 136 | +============ |
| 137 | + |
| 138 | +To verify the content of the modem flash, use the following function: |
| 139 | + |
| 140 | +.. code-block:: c |
| 141 | +
|
| 142 | + nrf_modem_bootloader_digest(uint32_t addr, uint32_t size, struct nrf_modem_bootloader_digest *digest_buffer); |
| 143 | +
|
| 144 | +This function calculates SHA-256 hash over the given flash area. |
| 145 | +Compare the hash to the precalculated value that comes with the modem firmware package, to ensure that the image is programmed successfully. |
0 commit comments