Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 1 | # [Building and using MCUboot with Espressif's chips](#building-and-using-mcuboot-with-espressifs-chips) |
Almir Okato | 428e2e7 | 2021-08-11 10:52:10 -0300 | [diff] [blame] | 2 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 3 | The MCUBoot Espressif's port depends on HAL (Hardware Abstraction Layer) sources based on ESP-IDF |
| 4 | or 3rd party frameworks as such as Zephyr-RTOS (`zephyrproject-rtos/hal_espressif/`) or NuttX RTOS |
| 5 | (`espressif/esp-hal-3rdparty`). Building the MCUboot Espressif's port and its features is platform |
| 6 | dependent, therefore, the system environment including toolchains, must be set accordingly. A |
| 7 | standalone build version means that ESP-IDF and its toolchain are used as source. For 3rd parties |
| 8 | framework, HAL path and toolchain must be set. |
Almir Okato | 428e2e7 | 2021-08-11 10:52:10 -0300 | [diff] [blame] | 9 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 10 | Documentation about the MCUboot bootloader design, operation and features can be found in the |
| 11 | [design document](design.md). |
Almir Okato | 428e2e7 | 2021-08-11 10:52:10 -0300 | [diff] [blame] | 12 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 13 | ## [SoC support availability](#soc-support-availability) |
Almir Okato | 428e2e7 | 2021-08-11 10:52:10 -0300 | [diff] [blame] | 14 | |
| 15 | The current port is available for use in the following SoCs within the OSes: |
Almir Okato | 428e2e7 | 2021-08-11 10:52:10 -0300 | [diff] [blame] | 16 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 17 | | | ESP32 | ESP32-S2 | ESP32-C3 | ESP32-S3 | ESP32-C2 | ESP32-C6 | ESP32-H2 | |
| 18 | | :----: | :-----: | :-----: | :-----: | :-----: | :---------: | :-----: | :-----: | |
Almir Okato | c1efa00 | 2023-08-09 14:47:30 -0300 | [diff] [blame] | 19 | | Zephyr | Supported | Supported | Supported | Supported | In progress | In progress | In progress | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 20 | | NuttX | Supported | Supported | Supported | Supported | In progress | In progress | In progress | |
Almir Okato | 879348b | 2023-05-09 22:31:36 -0300 | [diff] [blame] | 21 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 22 | Notice that any customization in the memory layout from the OS application must be done aware of |
| 23 | the bootloader own memory layout to avoid overlapping. More information on the section |
| 24 | [Memory map organization for OS compatibility](#memory-map-organization-for-os-compatibility). |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 25 | |
| 26 | ## [Installing requirements and dependencies](#installing-requirements-and-dependencies) |
Almir Okato | 428e2e7 | 2021-08-11 10:52:10 -0300 | [diff] [blame] | 27 | |
Almir Okato | 879348b | 2023-05-09 22:31:36 -0300 | [diff] [blame] | 28 | The following instructions considers a MCUboot Espressif port standalone build. |
| 29 | |
Almir Okato | 428e2e7 | 2021-08-11 10:52:10 -0300 | [diff] [blame] | 30 | 1. Install additional packages required for development with MCUboot: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 31 | |
| 32 | ```bash |
| 33 | cd ~/mcuboot # or to your directory where MCUboot is cloned |
| 34 | ``` |
| 35 | |
| 36 | ```bash |
| 37 | pip3 install --user -r scripts/requirements.txt |
| 38 | ``` |
Almir Okato | 428e2e7 | 2021-08-11 10:52:10 -0300 | [diff] [blame] | 39 | |
Almir Okato | 879348b | 2023-05-09 22:31:36 -0300 | [diff] [blame] | 40 | 2. Update the Mbed TLS submodule required by MCUboot: |
Almir Okato | 428e2e7 | 2021-08-11 10:52:10 -0300 | [diff] [blame] | 41 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 42 | ```bash |
| 43 | git submodule update --init --recursive ext/mbedtls |
| 44 | ``` |
Almir Okato | 879348b | 2023-05-09 22:31:36 -0300 | [diff] [blame] | 45 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 46 | 3. If ESP-IDF is the chosen option for use as HAL layer and the system already have ESP-IDF |
| 47 | installed, ensure that the environment is set: |
Almir Okato | 879348b | 2023-05-09 22:31:36 -0300 | [diff] [blame] | 48 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 49 | ```bash |
| 50 | <IDF_PATH>/install.sh |
| 51 | ``` |
Almir Okato | 879348b | 2023-05-09 22:31:36 -0300 | [diff] [blame] | 52 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 53 | ```bash |
| 54 | . <IDF_PATH>/export.sh |
| 55 | ``` |
Almir Okato | 879348b | 2023-05-09 22:31:36 -0300 | [diff] [blame] | 56 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 57 | --- |
| 58 | ***Note*** |
Almir Okato | 879348b | 2023-05-09 22:31:36 -0300 | [diff] [blame] | 59 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 60 | *If desirable, instructions for ESP-IDF installation can be found |
| 61 | [here](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html#manual-installation)* |
Almir Okato | 879348b | 2023-05-09 22:31:36 -0300 | [diff] [blame] | 62 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 63 | --- |
| 64 | |
| 65 | --- |
| 66 | ***Note*** |
| 67 | |
| 68 | *The other HALs mentioned above like `hal_espressif` from Zephyr RTOS or `esp-hal-3rdparty` |
| 69 | from NuttX RTOS environments also can be used for the bootloader standalone build, however as |
| 70 | eventually code revision may differ from what is currently expected, it is recommended using |
| 71 | them only within their RTOS build system.* |
| 72 | |
| 73 | --- |
Almir Okato | 879348b | 2023-05-09 22:31:36 -0300 | [diff] [blame] | 74 | |
| 75 | 4. If ESP-IDF is not installed and will not be used, install `esptool`: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 76 | |
| 77 | ```bash |
| 78 | pip3 install esptool |
| 79 | ``` |
Almir Okato | 428e2e7 | 2021-08-11 10:52:10 -0300 | [diff] [blame] | 80 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 81 | ## [Building the bootloader itself](#building-the-bootloader-itself) |
Almir Okato | 428e2e7 | 2021-08-11 10:52:10 -0300 | [diff] [blame] | 82 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 83 | The MCUboot Espressif port bootloader is built using the toolchain and tools provided by Espressif. |
| 84 | Additional configuration related to MCUboot features and slot partitioning may be made using the |
| 85 | `port/<TARGET>/bootloader.conf` file or passing a custom config file using the |
| 86 | `-DMCUBOOT_CONFIG_FILE` argument on the first step below. |
Almir Okato | 428e2e7 | 2021-08-11 10:52:10 -0300 | [diff] [blame] | 87 | |
Francesco Servidio | 2fe449d | 2021-10-21 12:38:36 +0200 | [diff] [blame] | 88 | --- |
| 89 | ***Note*** |
| 90 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 91 | *Replace `<TARGET>` with the target ESP32 family (like `esp32`, `esp32s2` and others).* |
Francesco Servidio | 2fe449d | 2021-10-21 12:38:36 +0200 | [diff] [blame] | 92 | |
| 93 | --- |
Almir Okato | 428e2e7 | 2021-08-11 10:52:10 -0300 | [diff] [blame] | 94 | |
Almir Okato | fa173df | 2022-04-19 01:10:30 -0300 | [diff] [blame] | 95 | 1. Compile and generate the BIN: |
Almir Okato | 428e2e7 | 2021-08-11 10:52:10 -0300 | [diff] [blame] | 96 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 97 | ```bash |
| 98 | cmake -DCMAKE_TOOLCHAIN_FILE=tools/toolchain-<TARGET>.cmake -DMCUBOOT_TARGET=<TARGET> -DESP_HAL_PATH=<ESP_HAL_PATH> -DMCUBOOT_FLASH_PORT=<PORT> -B build -GNinja |
| 99 | ``` |
Almir Okato | 879348b | 2023-05-09 22:31:36 -0300 | [diff] [blame] | 100 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 101 | ```bash |
| 102 | ninja -C build/ |
| 103 | ``` |
Almir Okato | 879348b | 2023-05-09 22:31:36 -0300 | [diff] [blame] | 104 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 105 | --- |
| 106 | ***Note*** |
| 107 | |
| 108 | *If using ESP-IDF as HAL layer source, `ESP_HAL_PATH` can be ommited.* |
| 109 | |
Almir Okato | d3819c9 | 2023-10-04 19:42:40 -0300 | [diff] [blame] | 110 | *If desirable, `<TOOLCHAIN_BIN_DIR>` can be defined with the path for a different compatible |
| 111 | toolchain, however it is recommended to actually create a CMake toolchain file and |
| 112 | pass it through `<CMAKE_TOOLCHAIN_FILE>` variable since it may require a distinct set of |
| 113 | compilation flags.* |
| 114 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 115 | --- |
Almir Okato | 879348b | 2023-05-09 22:31:36 -0300 | [diff] [blame] | 116 | |
Almir Okato | fa173df | 2022-04-19 01:10:30 -0300 | [diff] [blame] | 117 | 2. Flash MCUboot in your device: |
Almir Okato | 428e2e7 | 2021-08-11 10:52:10 -0300 | [diff] [blame] | 118 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 119 | ```bash |
| 120 | ninja -C build/ flash |
| 121 | ``` |
Almir Okato | fa173df | 2022-04-19 01:10:30 -0300 | [diff] [blame] | 122 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 123 | If `MCUBOOT_FLASH_PORT` arg was not passed to `cmake`, the default `PORT` for flashing will be |
| 124 | `/dev/ttyUSB0`. |
Almir Okato | a1d641d | 2022-02-21 19:31:46 -0300 | [diff] [blame] | 125 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 126 | Alternatively: |
Almir Okato | 428e2e7 | 2021-08-11 10:52:10 -0300 | [diff] [blame] | 127 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 128 | ```bash |
| 129 | esptool.py -p <PORT> -b <BAUD> --before default_reset --after no_reset --chip <TARGET> write_flash --flash_mode dio --flash_size <FLASH_SIZE> --flash_freq 40m <BOOTLOADER_FLASH_OFFSET> build/mcuboot_<TARGET>.bin |
| 130 | ``` |
Sylvio Alves | d523094 | 2022-01-20 21:35:53 -0300 | [diff] [blame] | 131 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 132 | --- |
| 133 | ***Note*** |
Sylvio Alves | d523094 | 2022-01-20 21:35:53 -0300 | [diff] [blame] | 134 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 135 | You may adjust the port `<PORT>` (like `/dev/ttyUSB0`) and baud rate `<BAUD>` (like `2000000`) |
| 136 | according to the connection with your board. You can also skip `<PORT>` and `<BAUD>` parameters |
| 137 | so that esptool tries to automatically detect it. |
Almir Okato | b365e23 | 2022-03-08 01:35:54 -0300 | [diff] [blame] | 138 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 139 | *`<FLASH_SIZE>` can be found using the command below:* |
Sylvio Alves | d523094 | 2022-01-20 21:35:53 -0300 | [diff] [blame] | 140 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 141 | ```bash |
| 142 | esptool.py -p <PORT> -b <BAUD> flash_id |
| 143 | ``` |
| 144 | |
| 145 | The output contains device information and its flash size: |
| 146 | |
| 147 | ``` |
| 148 | Detected flash size: 4MB |
| 149 | ``` |
| 150 | |
| 151 | *`<BOOTLOADER_FLASH_OFFSET>` value must follow one of the addresses below:* |
| 152 | |
| 153 | | ESP32 | ESP32-S2 | ESP32-C3 | ESP32-S3 | ESP32-C2 | ESP32-C6 | ESP32-H2 | |
| 154 | | :-----: | :-----: | :-----: | :-----: | :-----: | :-----: | :-----: | |
| 155 | | 0x1000 | 0x1000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | 0x0000 | |
| 156 | |
| 157 | --- |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 158 | |
Almir Okato | fa173df | 2022-04-19 01:10:30 -0300 | [diff] [blame] | 159 | 3. Reset your device |
| 160 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 161 | ## [Signing and flashing an application](#signing-and-flashing-an-application) |
| 162 | |
| 163 | 1. Images can be regularly signed with the `scripts/imgtool.py` script: |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 164 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 165 | ```bash |
| 166 | imgtool.py sign --align 4 -v 0 -H 32 --pad-header -S <SLOT_SIZE> <BIN_IN> <SIGNED_BIN> |
| 167 | ``` |
Sylvio Alves | d523094 | 2022-01-20 21:35:53 -0300 | [diff] [blame] | 168 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 169 | --- |
Almir Okato | a1d641d | 2022-02-21 19:31:46 -0300 | [diff] [blame] | 170 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 171 | ***Note*** |
Sylvio Alves | d523094 | 2022-01-20 21:35:53 -0300 | [diff] [blame] | 172 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 173 | `<SLOT_SIZE>` is the size of the slot to be used. |
| 174 | Default slot0 size is `0x100000`, but it can change as per application flash partitions. |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 175 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 176 | For Zephyr images, `--pad-header` is not needed as it already has the padding for MCUboot |
| 177 | header. |
Sylvio Alves | d523094 | 2022-01-20 21:35:53 -0300 | [diff] [blame] | 178 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 179 | --- |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 180 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 181 | :warning: ***ATTENTION*** |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 182 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 183 | *This is the basic signing needed for adding MCUboot headers and trailers. |
| 184 | For signing with a crypto key and guarantee the authenticity of the image being booted, see the |
| 185 | section [MCUboot image signature verification](#mcuboot-image-signature-verification) below.* |
| 186 | |
| 187 | --- |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 188 | |
| 189 | 2. Flash the signed application: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 190 | |
| 191 | ```bash |
| 192 | esptool.py -p <PORT> -b <BAUD> --before default_reset --after hard_reset --chip <TARGET> write_flash --flash_mode dio --flash_size <FLASH_SIZE> --flash_freq 40m <SLOT_OFFSET> <SIGNED_BIN> |
| 193 | ``` |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 194 | |
Almir Okato | 84da51b | 2022-11-25 01:25:41 -0300 | [diff] [blame] | 195 | # [Downgrade prevention](#downgrade-prevention) |
| 196 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 197 | Downgrade prevention (avoid updating of images to an older version) can be enabled using the |
| 198 | following configuration: |
Almir Okato | 84da51b | 2022-11-25 01:25:41 -0300 | [diff] [blame] | 199 | |
| 200 | ``` |
| 201 | CONFIG_ESP_DOWNGRADE_PREVENTION=y |
| 202 | ``` |
| 203 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 204 | MCUboot will then verify and compare the new image version number with the current one before |
| 205 | perform an update swap. |
Almir Okato | 84da51b | 2022-11-25 01:25:41 -0300 | [diff] [blame] | 206 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 207 | Version number is added to the image when signing it with `imgtool` (`-v` parameter, e.g. |
| 208 | `-v 1.0.0`). |
Almir Okato | 84da51b | 2022-11-25 01:25:41 -0300 | [diff] [blame] | 209 | |
| 210 | ### [Downgrade prevention with security counter](#downgrade-prevention-with-security-counter) |
| 211 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 212 | It is also possible to rely on a security counter, also added to the image when signing with |
| 213 | `imgtool` (`-s` parameter), apart from version number. This allows image downgrade at some extent, |
| 214 | since any update must have greater or equal security counter value. Enable using the following |
| 215 | configuration: |
Almir Okato | 84da51b | 2022-11-25 01:25:41 -0300 | [diff] [blame] | 216 | |
| 217 | ``` |
| 218 | CONFIG_ESP_DOWNGRADE_PREVENTION_SECURITY_COUNTER=y |
| 219 | ``` |
| 220 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 221 | E.g.: if the current image was signed using `-s 1` parameter, an eventual update image must have |
| 222 | been signed using security counter `-s 1` or greater. |
Almir Okato | 84da51b | 2022-11-25 01:25:41 -0300 | [diff] [blame] | 223 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 224 | # [Security Chain on Espressif port](#security-chain-on-espressif-port) |
| 225 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 226 | [MCUboot encrypted images](encrypted_images.md) do not provide full code confidentiality when only |
| 227 | external storage is available (see [Threat model](encrypted_images.md#threat-model)) since by |
| 228 | MCUboot design the image in Primary Slot, from where the image is executed, is stored plaintext. |
| 229 | Espressif chips have off-chip flash memory, so to ensure a security chain along with MCUboot image |
| 230 | signature verification, the hardware-assisted Secure Boot and Flash Encryption were made available |
| 231 | on the MCUboot Espressif port. |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 232 | |
| 233 | ## [MCUboot image signature verification](#mcuboot-image-signature-verification) |
| 234 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 235 | The image that MCUboot is booting can be signed with 4 types of keys: RSA-2048, RSA-3072, EC256 and |
| 236 | ED25519. In order to enable the feature, the **bootloader** must be compiled with the following |
| 237 | configurations: |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 238 | |
| 239 | --- |
| 240 | ***Note*** |
Almir Okato | a1d641d | 2022-02-21 19:31:46 -0300 | [diff] [blame] | 241 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 242 | *It is strongly recommended to generate a new signing key using `imgtool` instead of use the |
| 243 | existent samples.* |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 244 | |
| 245 | --- |
| 246 | |
| 247 | #### For EC256 algorithm use |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 248 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 249 | ``` |
| 250 | CONFIG_ESP_SIGN_EC256=y |
| 251 | |
| 252 | # Use Tinycrypt lib for EC256 or ED25519 signing |
| 253 | CONFIG_ESP_USE_TINYCRYPT=y |
| 254 | |
| 255 | CONFIG_ESP_SIGN_KEY_FILE=<YOUR_SIGNING_KEY.pem> |
| 256 | ``` |
| 257 | |
| 258 | #### For ED25519 algorithm use |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 259 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 260 | ``` |
| 261 | CONFIG_ESP_SIGN_ED25519=y |
| 262 | |
| 263 | # Use Tinycrypt lib for EC256 or ED25519 signing |
| 264 | CONFIG_ESP_USE_TINYCRYPT=y |
| 265 | |
| 266 | CONFIG_ESP_SIGN_KEY_FILE=<YOUR_SIGNING_KEY.pem> |
| 267 | ``` |
| 268 | |
| 269 | #### For RSA (2048 or 3072) algorithm use |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 270 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 271 | ``` |
| 272 | CONFIG_ESP_SIGN_RSA=y |
| 273 | # RSA_LEN is 2048 or 3072 |
| 274 | CONFIG_ESP_SIGN_RSA_LEN=<RSA_LEN> |
| 275 | |
| 276 | # Use Mbed TLS lib for RSA image signing |
| 277 | CONFIG_ESP_USE_MBEDTLS=y |
| 278 | |
| 279 | CONFIG_ESP_SIGN_KEY_FILE=<YOUR_SIGNING_KEY.pem> |
| 280 | ``` |
| 281 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 282 | Notice that the public key will be embedded in the bootloader code, since the hardware key storage |
| 283 | is not supported by Espressif port. |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 284 | |
| 285 | ### [Signing the image](#signing-the-image) |
| 286 | |
| 287 | Now you need to sign the **image binary**, use the `imgtool` with `-k` parameter: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 288 | |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 289 | ```bash |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 290 | imgtool.py sign -k <YOUR_SIGNING_KEY.pem> --pad --pad-sig --align 4 -v 0 -H 32 --pad-header -S 0x00100000 <BIN_IN> <BIN_OUT> |
| 291 | ``` |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 292 | |
| 293 | If signing a Zephyr image, the `--pad-header` is not needed, as it already have the padding for |
| 294 | MCUboot header. |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 295 | |
| 296 | |
| 297 | ## [Secure Boot](#secure-boot) |
| 298 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 299 | The Secure Boot implementation is based on |
| 300 | [IDF's Secure Boot V2](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/security/secure-boot-v2.html), |
Almir Okato | db2024e | 2023-08-24 15:40:26 -0300 | [diff] [blame] | 301 | is hardware-assisted and RSA based - except ESP32-C2 that uses ECDSA signing scheme - and has the |
| 302 | role for ensuring that only authorized code will be executed on the device. This is done through |
| 303 | bootloader signature checking by the ROM bootloader. |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 304 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 305 | ***Note***: ROM bootloader is the First Stage Bootloader, while the Espressif MCUboot port is the |
| 306 | Second Stage Bootloader. |
| 307 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 308 | ### [Building bootloader with Secure Boot](#building-bootloader-with-secure-boot) |
| 309 | |
| 310 | In order to build the bootloader with the feature on, the following configurations must be enabled: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 311 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 312 | ``` |
| 313 | CONFIG_SECURE_BOOT=1 |
| 314 | CONFIG_SECURE_BOOT_V2_ENABLED=1 |
| 315 | CONFIG_SECURE_SIGNED_ON_BOOT=1 |
Almir Okato | db2024e | 2023-08-24 15:40:26 -0300 | [diff] [blame] | 316 | ``` |
| 317 | |
| 318 | For the currently supported chips, with exception of ESP32-C2, enable RSA signing scheme: |
| 319 | |
| 320 | ``` |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 321 | CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME=1 |
| 322 | CONFIG_SECURE_BOOT_SUPPORTS_RSA=1 |
| 323 | ``` |
| 324 | |
Almir Okato | db2024e | 2023-08-24 15:40:26 -0300 | [diff] [blame] | 325 | For ESP32-C2, enable ECDSA signing scheme and, if working with Flash Encryption too, enable the |
| 326 | configuration to burn keys to efuse together: |
| 327 | |
| 328 | ``` |
| 329 | CONFIG_SECURE_SIGNED_APPS_ECDSA_V2_SCHEME=1 |
| 330 | |
| 331 | CONFIG_SECURE_BOOT_FLASH_ENC_KEYS_BURN_TOGETHER=1 |
| 332 | ``` |
| 333 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 334 | --- |
| 335 | :warning: ***ATTENTION*** |
| 336 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 337 | *On development phase is recommended add the following configuration in order to keep the debugging |
| 338 | enabled and also to avoid any unrecoverable/permanent state change:* |
| 339 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 340 | ``` |
| 341 | CONFIG_SECURE_BOOT_ALLOW_JTAG=1 |
| 342 | CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_CACHE=1 |
| 343 | |
| 344 | # Options for enabling eFuse emulation in Flash |
| 345 | CONFIG_EFUSE_VIRTUAL=1 |
| 346 | CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH=1 |
| 347 | ``` |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 348 | --- |
| 349 | |
Almir Okato | b365e23 | 2022-03-08 01:35:54 -0300 | [diff] [blame] | 350 | --- |
| 351 | :warning: ***ATTENTION*** |
| 352 | |
| 353 | *You can disable UART Download Mode by adding the following configuration:* |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 354 | |
Almir Okato | b365e23 | 2022-03-08 01:35:54 -0300 | [diff] [blame] | 355 | ``` |
| 356 | CONFIG_SECURE_DISABLE_ROM_DL_MODE=1 |
| 357 | ``` |
| 358 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 359 | *This may be suitable for __production__ builds. __After disabling UART Download Mode you will not |
| 360 | be able to flash other images through UART.__* |
Almir Okato | b365e23 | 2022-03-08 01:35:54 -0300 | [diff] [blame] | 361 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 362 | *Otherwise, you can switch the UART ROM Download Mode to the Secure Download Mode. It will limit |
| 363 | the use of Download Mode functions to simple flash read, write and erase operations.* |
| 364 | |
Almir Okato | b365e23 | 2022-03-08 01:35:54 -0300 | [diff] [blame] | 365 | ``` |
| 366 | CONFIG_SECURE_ENABLE_SECURE_ROM_DL_MODE=1 |
| 367 | ``` |
| 368 | |
| 369 | *Once the device makes its first full boot, these configurations cannot be reverted* |
| 370 | |
| 371 | --- |
| 372 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 373 | Once the **bootloader image** is built, the resulting binary file is required to be signed with |
| 374 | `espsecure.py` tool. |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 375 | |
| 376 | First create a signing key: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 377 | |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 378 | ```bash |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 379 | espsecure.py generate_signing_key --version 2 <BOOTLOADER_SIGNING_KEY.pem> |
| 380 | ``` |
| 381 | |
| 382 | Then sign the bootloader image: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 383 | |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 384 | ```bash |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 385 | espsecure.py sign_data --version 2 --keyfile <BOOTLOADER_SIGNING_KEY.pem> -o <BOOTLOADER_BIN_OUT> <BOOTLOADER_BIN_IN> |
| 386 | ``` |
| 387 | |
| 388 | --- |
| 389 | :warning: ***ATTENTION*** |
| 390 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 391 | *Once the bootloader is flashed and the device resets, the **first boot will enable Secure Boot** |
| 392 | and the bootloader and key **no longer can be modified**. So **ENSURE** that both bootloader and |
| 393 | key are correct and you did not forget anything before flashing.* |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 394 | |
| 395 | --- |
| 396 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 397 | Flash the bootloader as following, with `--after no_reset` flag, so you can reset the device only |
| 398 | when assured: |
| 399 | |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 400 | ```bash |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 401 | esptool.py -p <PORT> -b 2000000 --after no_reset --chip <ESP_CHIP> write_flash --flash_mode dio --flash_size <FLASH_SIZE> --flash_freq 40m <BOOTLOADER_FLASH_OFFSET> <SIGNED_BOOTLOADER_BIN> |
| 402 | ``` |
| 403 | |
| 404 | ### [Secure Boot Process](#secure-boot-process) |
| 405 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 406 | Secure boot uses a signature block appended to the bootloader image in order to verify the |
| 407 | authenticity. The signature block contains the RSA-3072 signature of that image and the RSA-3072 |
| 408 | public key. |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 409 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 410 | On its **first boot** the Secure Boot is not enabled on the device eFuses yet, neither the key nor |
| 411 | digests. So the first boot will have the following process: |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 412 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 413 | 1. On startup, since it is the first boot, the ROM bootloader will not verify the bootloader image |
| 414 | (the Secure Boot bit in the eFuse is disabled) yet, so it proceeds to execute it (our MCUboot |
| 415 | bootloader port). |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 416 | 2. Bootloader calculates the SHA-256 hash digest of the public key and writes the result to eFuse. |
| 417 | 3. Bootloader validates the application images and prepare the booting process (MCUboot phase). |
| 418 | 4. Bootloader burns eFuse to enable Secure Boot V2. |
| 419 | 5. Bootloader proceeds to load the Primary image. |
| 420 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 421 | After that the Secure Boot feature is permanently enabled and on every next boot the ROM bootloader |
| 422 | will verify the MCUboot bootloader image. The process of an usual boot: |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 423 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 424 | 1. On startup, the ROM bootloader checks the Secure Boot enable bit in the eFuse. If it is enabled, |
| 425 | the boot will proceed as following. |
| 426 | 2. ROM bootloader verifies the bootloader's signature block integrity (magic number and CRC). |
| 427 | Interrupt boot if it fails. |
| 428 | 3. ROM bootloader verifies the bootloader image, interrupt boot if any step fails: |
| 429 | 1. Compare the SHA-256 hash digest of the public key embedded in the bootloader’s signature |
| 430 | block with the digest saved in the eFuses. |
| 431 | 2. Generate the application image digest and match it with the image digest in the signature |
| 432 | block. |
| 433 | 3. Use the public key to verify the signature of the bootloader image, using RSA-PSS with the |
| 434 | image digest calculated from previous step for comparison. |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 435 | 4. ROM bootloader executes the bootloader image. |
| 436 | 5. Bootloader does the usual verification (MCUboot phase). |
| 437 | 6. Proceeds to boot the Primary image. |
| 438 | |
| 439 | ## [Flash Encryption](#flash-encryption) |
| 440 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 441 | The Espressif Flash Encryption is hardware-assisted, transparent to the MCUboot process and is an |
| 442 | additional security measure beyond MCUboot existent features. |
| 443 | The Flash Encryption implementation is also based on |
| 444 | [IDF](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/security/flash-encryption.html) |
| 445 | and is intended for encrypting off-chip flash memory contents, so it is protected against physical |
| 446 | reading. |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 447 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 448 | When enabling the Flash Encryption, the user can encrypt the content either using a **device |
| 449 | generated key** (remains unknown and unreadable) or a **host generated key** (owner is responsible |
| 450 | for keeping the key private and safe). After the flash encryption gets enabled through eFuse |
| 451 | burning on the device, all read and write operations are decrypted/encrypted in runtime. |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 452 | |
| 453 | ### [Building bootloader with Flash Encryption](#building-bootloader-with-flash-encryption) |
| 454 | |
| 455 | In order to build the bootloader with the feature on, the following configurations must be enabled: |
| 456 | |
| 457 | For **release mode**: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 458 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 459 | ``` |
| 460 | CONFIG_SECURE_FLASH_ENC_ENABLED=1 |
| 461 | CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE=1 |
| 462 | ``` |
| 463 | |
| 464 | For **development mode**: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 465 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 466 | ``` |
| 467 | CONFIG_SECURE_FLASH_ENC_ENABLED=1 |
| 468 | CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT=1 |
| 469 | ``` |
Almir Okato | b365e23 | 2022-03-08 01:35:54 -0300 | [diff] [blame] | 470 | |
| 471 | --- |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 472 | :warning: ***ATTENTION*** |
| 473 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 474 | *On development phase is strongly recommended adding the following configuration in order to keep |
| 475 | the debugging enabled and also to avoid any unrecoverable/permanent state change:* |
| 476 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 477 | ``` |
| 478 | CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_ENC=1 |
| 479 | CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_DEC=1 |
| 480 | CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_CACHE=1 |
| 481 | CONFIG_SECURE_BOOT_ALLOW_JTAG=1 |
| 482 | |
| 483 | # Options for enabling eFuse emulation in Flash |
| 484 | CONFIG_EFUSE_VIRTUAL=1 |
| 485 | CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH=1 |
| 486 | ``` |
Almir Okato | b365e23 | 2022-03-08 01:35:54 -0300 | [diff] [blame] | 487 | --- |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 488 | |
| 489 | --- |
| 490 | :warning: ***ATTENTION*** |
| 491 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 492 | *Unless the recommended flags for __DEVELOPMENT MODE__ were enabled, the actions made by Flash |
| 493 | Encryption process are __PERMANENT__.* \ |
| 494 | *Once the bootloader is flashed and the device resets, the __first boot will enable Flash |
| 495 | Encryption, encrypt the flash content including bootloader and image slots, burn the eFuses that no |
| 496 | longer can be modified__ and if device generated the key __it will not be recoverable__.* \ |
| 497 | *When on __RELEASE MODE__, __ENSURE__ that the application with an update agent is flashed before |
| 498 | reset the device.* |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 499 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 500 | *In the same way as Secure Boot feature, you can disable UART Download Mode by adding the following |
| 501 | configuration:* |
| 502 | |
Almir Okato | b365e23 | 2022-03-08 01:35:54 -0300 | [diff] [blame] | 503 | ``` |
| 504 | CONFIG_SECURE_DISABLE_ROM_DL_MODE=1 |
| 505 | ``` |
| 506 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 507 | *This may be suitable for __production__ builds. __After disabling UART Download Mode you will not |
| 508 | be able to flash other images through UART.__* |
Almir Okato | b365e23 | 2022-03-08 01:35:54 -0300 | [diff] [blame] | 509 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 510 | *Otherwise, you can switch the UART Download Mode to the Secure Download Mode. It will limit the |
| 511 | use of Download Mode functions to simple flash read, write and erase operations.* |
| 512 | |
Almir Okato | b365e23 | 2022-03-08 01:35:54 -0300 | [diff] [blame] | 513 | ``` |
| 514 | CONFIG_SECURE_ENABLE_SECURE_ROM_DL_MODE=1 |
| 515 | ``` |
| 516 | |
| 517 | *These configurations cannot be reverted after the device's first boot* |
| 518 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 519 | --- |
| 520 | |
Sylvio Alves | d523094 | 2022-01-20 21:35:53 -0300 | [diff] [blame] | 521 | ### [Signing the image when working with Flash Encryption](#signing-the-image-when-working-with-flash-encryption) |
| 522 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 523 | When enabling flash encryption, it is required to signed the image using 32-byte alignment: |
| 524 | `--align 32 --max-align 32`. |
Sylvio Alves | d523094 | 2022-01-20 21:35:53 -0300 | [diff] [blame] | 525 | |
| 526 | Command example: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 527 | |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 528 | ```bash |
Sylvio Alves | d523094 | 2022-01-20 21:35:53 -0300 | [diff] [blame] | 529 | imgtool.py sign -k <YOUR_SIGNING_KEY.pem> --pad --pad-sig --align 32 --max-align 32 -v 0 -H 32 --pad-header -S <SLOT_SIZE> <BIN_IN> <BIN_OUT> |
| 530 | ``` |
| 531 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 532 | ### [Device generated key](#device-generated-key) |
| 533 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 534 | First ensure that the application image is able to perform encrypted read and write operations to |
| 535 | the SPI Flash. Flash the bootloader and application normally: |
| 536 | |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 537 | ```bash |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 538 | esptool.py -p <PORT> -b 2000000 --after no_reset --chip <ESP_CHIP> write_flash --flash_mode dio --flash_size <FLASH_SIZE> --flash_freq 40m <BOOTLOADER_FLASH_OFFSET> <BOOTLOADER_BIN> |
| 539 | ``` |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 540 | |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 541 | ```bash |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 542 | esptool.py -p <PORT> -b 2000000 --after no_reset --chip <ESP_CHIP> write_flash --flash_mode dio --flash_size <FLASH_SIZE> --flash_freq 40m <PRIMARY_SLOT_FLASH_OFFSET> <APPLICATION_BIN> |
| 543 | ``` |
| 544 | |
| 545 | On the **first boot**, the bootloader will: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 546 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 547 | 1. Generate Flash Encryption key and write to eFuse. |
| 548 | 2. Encrypt flash in-place including bootloader, image primary/secondary slot and scratch. |
| 549 | 3. Burn eFuse to enable Flash Encryption. |
| 550 | 4. Reset system to ensure Flash Encryption cache resets properly. |
| 551 | |
| 552 | ### [Host generated key](#host-generated-key) |
| 553 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 554 | First ensure that the application image is able to perform encrypted read and write operations to |
| 555 | the SPI Flash. Also ensure that the **UART ROM Download Mode is not disabled** - or that the |
| 556 | **Secure Download Mode is enabled**. Before flashing, generate the encryption key using |
| 557 | `espsecure.py` tool: |
| 558 | |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 559 | ```bash |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 560 | espsecure.py generate_flash_encryption_key <FLASH_ENCRYPTION_KEY.bin> |
| 561 | ``` |
| 562 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 563 | Burn the key into the device's eFuse (keep a copy on the host), this action can be done **only |
| 564 | once**: |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 565 | |
| 566 | --- |
| 567 | :warning: ***ATTENTION*** |
| 568 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 569 | *eFuse emulation in Flash configuration options do not have any effect, so if the key burning |
| 570 | command below is used, it will actually burn the physical eFuse.* |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 571 | |
| 572 | --- |
| 573 | |
| 574 | - ESP32 |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 575 | |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 576 | ```bash |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 577 | espefuse.py --port PORT burn_key flash_encryption <FLASH_ENCRYPTION_KEY.bin> |
| 578 | ``` |
| 579 | |
Sylvio Alves | d8eff81 | 2022-01-31 23:16:06 -0300 | [diff] [blame] | 580 | - ESP32S2, ESP32C3 and ESP32S3 |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 581 | |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 582 | ```bash |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 583 | espefuse.py --port PORT burn_key BLOCK <FLASH_ENCRYPTION_KEY.bin> <KEYPURPOSE> |
| 584 | ``` |
| 585 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 586 | `BLOCK` is a free keyblock between `BLOCK_KEY0` and `BLOCK_KEY5`. And `KEYPURPOSE` is either |
| 587 | `XTS_AES_128_KEY`, `XTS_AES_256_KEY_1`, `XTS_AES_256_KEY_2` (AES XTS 256 is available only in |
| 588 | ESP32S2). |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 589 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 590 | Now, similar as the Device generated key, the bootloader and application can be flashed plaintext. |
| 591 | The **first boot** will encrypt the flash content using the host key burned in the eFuse instead |
| 592 | of generate a new one. |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 593 | |
| 594 | Flashing the bootloader and application: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 595 | |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 596 | ```bash |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 597 | esptool.py -p <PORT> -b 2000000 --after no_reset --chip <ESP_CHIP> write_flash --flash_mode dio --flash_size <FLASH_SIZE> --flash_freq 40m <BOOTLOADER_FLASH_OFFSET> <BOOTLOADER_BIN> |
| 598 | ``` |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 599 | |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 600 | ```bash |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 601 | esptool.py -p <PORT> -b 2000000 --after no_reset --chip <ESP_CHIP> write_flash --flash_mode dio --flash_size <FLASH_SIZE> --flash_freq 40m <PRIMARY_SLOT_FLASH_OFFSET> <APPLICATION_BIN> |
| 602 | ``` |
| 603 | |
| 604 | On the **first boot**, the bootloader will: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 605 | |
| 606 | 1. Encrypt flash in-place including bootloader, image primary/secondary slot and scratch using the |
| 607 | written key. |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 608 | 2. Burn eFuse to enable Flash Encryption. |
| 609 | 3. Reset system to ensure Flash Encryption cache resets properly. |
| 610 | |
Almir Okato | b365e23 | 2022-03-08 01:35:54 -0300 | [diff] [blame] | 611 | Encrypting data on the host: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 612 | |
Almir Okato | b365e23 | 2022-03-08 01:35:54 -0300 | [diff] [blame] | 613 | - ESP32 |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 614 | |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 615 | ```bash |
Almir Okato | b365e23 | 2022-03-08 01:35:54 -0300 | [diff] [blame] | 616 | espsecure.py encrypt_flash_data --keyfile <FLASH_ENCRYPTION_KEY.bin> --address <FLASH_OFFSET> --output <OUTPUT_DATA> <INPUT_DATA> |
| 617 | ``` |
| 618 | |
| 619 | - ESP32-S2, ESP32-C3 and ESP32-S3 |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 620 | |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 621 | ```bash |
Almir Okato | b365e23 | 2022-03-08 01:35:54 -0300 | [diff] [blame] | 622 | espsecure.py encrypt_flash_data --aes_xts --keyfile <FLASH_ENCRYPTION_KEY.bin> --address <FLASH_OFFSET> --output <OUTPUT_DATA> <INPUT_DATA> |
| 623 | ``` |
| 624 | |
| 625 | --- |
| 626 | ***Note*** |
Almir Okato | e8cbc0d | 2022-06-13 10:45:39 -0300 | [diff] [blame] | 627 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 628 | OTA updates are required to be sent plaintext. The reason is that, as said before, after the Flash |
| 629 | Encryption is enabled all read/write operations are decrypted/encrypted in runtime, so as e.g. if |
| 630 | pre-encrypted data is sent for an OTA update, it would be wrongly double-encrypted when the update |
| 631 | agent writes to the flash. |
Almir Okato | b365e23 | 2022-03-08 01:35:54 -0300 | [diff] [blame] | 632 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 633 | For updating with an image encrypted on the host, flash it through serial using `esptool.py` as |
| 634 | above. **UART ROM Download Mode must not be disabled**. |
Almir Okato | b365e23 | 2022-03-08 01:35:54 -0300 | [diff] [blame] | 635 | |
| 636 | --- |
| 637 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 638 | ## [Security Chain scheme](#security-chain-scheme) |
| 639 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 640 | Using the 3 features, Secure Boot, Image signature verification and Flash Encryption, a Security |
| 641 | Chain can be established so only trusted code is executed, and also the code and content residing |
| 642 | in the off-chip flash are protected against undesirable reading. |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 643 | |
| 644 | The overall final process when all features are enabled: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 645 | |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 646 | 1. ROM bootloader validates the MCUboot bootloader using RSA signature verification. |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 647 | 2. MCUboot bootloader validates the image using the chosen algorithm EC256/RSA/ED25519. It also |
| 648 | validates an upcoming image when updating. |
Almir Okato | 39eb63d | 2022-01-05 18:31:54 -0300 | [diff] [blame] | 649 | 3. Flash Encryption guarantees that code and data are not exposed. |
| 650 | |
| 651 | ### [Size Limitation](#size-limitation) |
| 652 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 653 | When all 3 features are enable at same time, the bootloader size may exceed the fixed limit for |
| 654 | the ROM bootloader checking on the Espressif chips **depending on which algorithm** was chosen for |
| 655 | MCUboot image signing. The issue <https://github.com/mcu-tools/mcuboot/issues/1262> was created to |
| 656 | track this limitation. |
Almir Okato | a1d641d | 2022-02-21 19:31:46 -0300 | [diff] [blame] | 657 | |
| 658 | ## [Multi image](#multi-image) |
| 659 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 660 | The multi image feature (currently limited to 2 images) allows the images to be updated separately |
| 661 | (each one has its own primary and secondary slot) by MCUboot. |
Almir Okato | a1d641d | 2022-02-21 19:31:46 -0300 | [diff] [blame] | 662 | |
| 663 | The Espressif port bootloader handles the boot in two different approaches: |
| 664 | |
| 665 | ### [Host OS boots second image](#host-os-boots-second-image) |
| 666 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 667 | Host OS from the *first image* is responsible for booting the *second image*, therefore the |
| 668 | bootloader is aware of the second image regions and can update it, however it does not load |
| 669 | neither boots it. |
Almir Okato | a1d641d | 2022-02-21 19:31:46 -0300 | [diff] [blame] | 670 | |
| 671 | Configuration example (`bootloader.conf`): |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 672 | |
Almir Okato | a1d641d | 2022-02-21 19:31:46 -0300 | [diff] [blame] | 673 | ``` |
| 674 | CONFIG_ESP_BOOTLOADER_SIZE=0xF000 |
| 675 | CONFIG_ESP_MCUBOOT_WDT_ENABLE=y |
| 676 | |
| 677 | # Enables multi image, if it is not defined, its assumed |
| 678 | # only one updatable image |
| 679 | CONFIG_ESP_IMAGE_NUMBER=2 |
| 680 | |
| 681 | # Example of values to be used when multi image is enabled |
| 682 | # Notice that the OS layer and update agent must be aware |
| 683 | # of these regions |
| 684 | CONFIG_ESP_APPLICATION_SIZE=0x50000 |
| 685 | CONFIG_ESP_IMAGE0_PRIMARY_START_ADDRESS=0x10000 |
| 686 | CONFIG_ESP_IMAGE0_SECONDARY_START_ADDRESS=0x60000 |
| 687 | CONFIG_ESP_IMAGE1_PRIMARY_START_ADDRESS=0xB0000 |
| 688 | CONFIG_ESP_IMAGE1_SECONDARY_START_ADDRESS=0x100000 |
| 689 | CONFIG_ESP_SCRATCH_OFFSET=0x150000 |
| 690 | CONFIG_ESP_SCRATCH_SIZE=0x40000 |
| 691 | ``` |
| 692 | |
| 693 | ### [Multi boot](#multi-boot) |
| 694 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 695 | In the multi boot approach the bootloader is responsible for booting two different images in two |
| 696 | different CPUs, firstly the *second image* on the APP CPU and then the *first image* on the PRO |
| 697 | CPU (current CPU), it is also responsible for update both images as well. Thus multi boot will be |
| 698 | only supported by Espressif multi core chips - currently only ESP32 is implemented. |
Almir Okato | a1d641d | 2022-02-21 19:31:46 -0300 | [diff] [blame] | 699 | |
| 700 | --- |
| 701 | ***Note*** |
| 702 | |
| 703 | *The host OSes in each CPU must handle how the resources are divided/controlled between then.* |
| 704 | |
| 705 | --- |
| 706 | |
| 707 | Configuration example: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 708 | |
Almir Okato | a1d641d | 2022-02-21 19:31:46 -0300 | [diff] [blame] | 709 | ``` |
| 710 | CONFIG_ESP_BOOTLOADER_SIZE=0xF000 |
| 711 | CONFIG_ESP_MCUBOOT_WDT_ENABLE=y |
| 712 | |
| 713 | # Enables multi image, if it is not defined, its assumed |
| 714 | # only one updatable image |
| 715 | CONFIG_ESP_IMAGE_NUMBER=2 |
| 716 | |
| 717 | # Enables multi image boot on independent processors |
| 718 | # (main host OS is not responsible for booting the second image) |
| 719 | # Use only with CONFIG_ESP_IMAGE_NUMBER=2 |
| 720 | CONFIG_ESP_MULTI_PROCESSOR_BOOT=y |
| 721 | |
| 722 | # Example of values to be used when multi image is enabled |
| 723 | # Notice that the OS layer and update agent must be aware |
| 724 | # of these regions |
| 725 | CONFIG_ESP_APPLICATION_SIZE=0x50000 |
| 726 | CONFIG_ESP_IMAGE0_PRIMARY_START_ADDRESS=0x10000 |
| 727 | CONFIG_ESP_IMAGE0_SECONDARY_START_ADDRESS=0x60000 |
| 728 | CONFIG_ESP_IMAGE1_PRIMARY_START_ADDRESS=0xB0000 |
| 729 | CONFIG_ESP_IMAGE1_SECONDARY_START_ADDRESS=0x100000 |
| 730 | CONFIG_ESP_SCRATCH_OFFSET=0x150000 |
| 731 | CONFIG_ESP_SCRATCH_SIZE=0x40000 |
| 732 | ``` |
| 733 | |
| 734 | ### [Image version dependency](#image-version-dependency) |
| 735 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 736 | MCUboot allows version dependency check between the images when updating them. As `imgtool.py` |
| 737 | allows a version assigment when signing an image, it is also possible to add the version |
| 738 | dependency constraint: |
| 739 | |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 740 | ```bash |
Almir Okato | a1d641d | 2022-02-21 19:31:46 -0300 | [diff] [blame] | 741 | imgtool.py sign --align 4 -v <VERSION> -d "(<IMAGE_INDEX>, <VERSION_DEPENDENCY>)" -H 32 --pad-header -S <SLOT_SIZE> <BIN_IN> <SIGNED_BIN> |
| 742 | ``` |
| 743 | |
| 744 | - `<VERSION>` defines the version of the image being signed. |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 745 | - `"(<IMAGE_INDEX>, <VERSION_DEPENDENCY>)"` defines the minimum version and from which image is |
| 746 | needed to satisfy the dependency. |
Almir Okato | a1d641d | 2022-02-21 19:31:46 -0300 | [diff] [blame] | 747 | |
| 748 | --- |
| 749 | Example: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 750 | |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 751 | ```bash |
Almir Okato | a1d641d | 2022-02-21 19:31:46 -0300 | [diff] [blame] | 752 | imgtool.py sign --align 4 -v 1.0.0 -d "(1, 0.0.1+0)" -H 32 --pad-header -S 0x100000 image0.bin image0-signed.bin |
| 753 | ``` |
| 754 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 755 | Supposing that the image 0 is being signed, its version is 1.0.0 and it depends on image 1 with |
| 756 | version at least 0.0.1+0. |
Almir Okato | a1d641d | 2022-02-21 19:31:46 -0300 | [diff] [blame] | 757 | |
| 758 | --- |
Almir Okato | e8cbc0d | 2022-06-13 10:45:39 -0300 | [diff] [blame] | 759 | |
| 760 | ## [Serial recovery mode](#serial-recovery-mode) |
| 761 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 762 | Serial recovery mode allows management through MCUMGR (more information and how to install it: |
| 763 | <https://github.com/apache/mynewt-mcumgr-cli>) for communicating and uploading a firmware to the |
| 764 | device. |
Almir Okato | e8cbc0d | 2022-06-13 10:45:39 -0300 | [diff] [blame] | 765 | |
Almir Okato | e8cbc0d | 2022-06-13 10:45:39 -0300 | [diff] [blame] | 766 | Configuration example: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 767 | |
Almir Okato | e8cbc0d | 2022-06-13 10:45:39 -0300 | [diff] [blame] | 768 | ``` |
| 769 | # Enables the MCUboot Serial Recovery, that allows the use of |
| 770 | # MCUMGR to upload a firmware through the serial port |
| 771 | CONFIG_ESP_MCUBOOT_SERIAL=y |
| 772 | # GPIO used to boot on Serial Recovery |
| 773 | CONFIG_ESP_SERIAL_BOOT_GPIO_DETECT=32 |
| 774 | # GPIO input type (0 for Pull-down, 1 for Pull-up) |
| 775 | CONFIG_ESP_SERIAL_BOOT_GPIO_INPUT_TYPE=0 |
| 776 | # GPIO signal value |
| 777 | CONFIG_ESP_SERIAL_BOOT_GPIO_DETECT_VAL=1 |
| 778 | # Delay time for identify the GPIO signal |
| 779 | CONFIG_ESP_SERIAL_BOOT_DETECT_DELAY_S=5 |
| 780 | # UART port used for serial communication |
| 781 | CONFIG_ESP_SERIAL_BOOT_UART_NUM=1 |
| 782 | # GPIO for Serial RX signal |
| 783 | CONFIG_ESP_SERIAL_BOOT_GPIO_RX=25 |
| 784 | # GPIO for Serial TX signal |
| 785 | CONFIG_ESP_SERIAL_BOOT_GPIO_TX=26 |
| 786 | ``` |
| 787 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 788 | When enabled, the bootloader checks the if the GPIO `<CONFIG_ESP_SERIAL_BOOT_GPIO_DETECT>` |
| 789 | configured has the signal value `<CONFIG_ESP_SERIAL_BOOT_GPIO_DETECT_VAL>` for approximately |
| 790 | `<CONFIG_ESP_SERIAL_BOOT_DETECT_DELAY_S>` seconds for entering the Serial recovery mode. Example: |
| 791 | a button configured on GPIO 32 pressed for 5 seconds. |
Almir Okato | e8cbc0d | 2022-06-13 10:45:39 -0300 | [diff] [blame] | 792 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 793 | Serial mode then uses the UART port configured for communication |
| 794 | (`<CONFIG_ESP_SERIAL_BOOT_UART_NUM>`, pins `<CONFIG_ESP_SERIAL_BOOT_GPIO_RX>`, |
| 795 | `<CONFIG_ESP_SERIAL_BOOT_GPIO_RX>`). |
Almir Okato | e8cbc0d | 2022-06-13 10:45:39 -0300 | [diff] [blame] | 796 | |
Almir Okato | 09cca38 | 2022-09-23 15:25:28 -0300 | [diff] [blame] | 797 | ### [Serial Recovery through USB JTAG Serial port](#serial-recovery-through-usb-jtag-serial-port) |
| 798 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 799 | Some chips, like ESP32-C3 and ESP32-S3 have an integrated USB JTAG Serial Controller that |
| 800 | implements a serial port (CDC) that can also be used for handling MCUboot Serial Recovery. |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 801 | More information about the USB pins and hardware configuration: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 802 | |
| 803 | - ESP32-C3: <https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/api-guides/usb-serial-jtag-console.html> |
| 804 | - ESP32-S3: <https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-guides/usb-serial-jtag-console.html> |
| 805 | - ESP32-C6: <https://docs.espressif.com/projects/esp-idf/en/latest/esp32c6/api-guides/usb-serial-jtag-console.html> |
| 806 | - ESP32-H2: <https://docs.espressif.com/projects/esp-idf/en/latest/esp32h2/api-guides/usb-serial-jtag-console.html> |
Almir Okato | 09cca38 | 2022-09-23 15:25:28 -0300 | [diff] [blame] | 807 | |
| 808 | Configuration example: |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 809 | |
Almir Okato | 09cca38 | 2022-09-23 15:25:28 -0300 | [diff] [blame] | 810 | ``` |
| 811 | # Use Serial through USB JTAG Serial port for Serial Recovery |
| 812 | CONFIG_ESP_MCUBOOT_SERIAL_USB_SERIAL_JTAG=y |
| 813 | # Use sector erasing (recommended) instead of entire image size |
| 814 | # erasing when uploading through Serial Recovery |
| 815 | CONFIG_ESP_MCUBOOT_ERASE_PROGRESSIVELY=y |
| 816 | # GPIO used to boot on Serial Recovery |
| 817 | CONFIG_ESP_SERIAL_BOOT_GPIO_DETECT=5 |
| 818 | # GPIO input type (0 for Pull-down, 1 for Pull-up) |
| 819 | CONFIG_ESP_SERIAL_BOOT_GPIO_INPUT_TYPE=0 |
| 820 | # GPIO signal value |
| 821 | CONFIG_ESP_SERIAL_BOOT_GPIO_DETECT_VAL=1 |
| 822 | # Delay time for identify the GPIO signal |
| 823 | CONFIG_ESP_SERIAL_BOOT_DETECT_DELAY_S=5 |
| 824 | ``` |
| 825 | |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 826 | --- |
| 827 | :warning: ***ATTENTION*** |
| 828 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 829 | *When working with Flash Encryption enabled, `CONFIG_ESP_MCUBOOT_ERASE_PROGRESSIVELY` must be |
| 830 | __disabled__, although it is recommended for common Serial Recovery usage* |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 831 | |
| 832 | --- |
| 833 | |
Almir Okato | e8cbc0d | 2022-06-13 10:45:39 -0300 | [diff] [blame] | 834 | ### [MCUMGR image upload example](#mcumgr-image-upload-example) |
| 835 | |
| 836 | After entering the Serial recovery mode on the device, MCUMGR can be used as following: |
| 837 | |
| 838 | Configure the connection: |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 839 | ```bash |
Almir Okato | e8cbc0d | 2022-06-13 10:45:39 -0300 | [diff] [blame] | 840 | mcumgr conn add esp type="serial" connstring="dev=<PORT>,baud=115200,mtu=256" |
| 841 | ``` |
| 842 | |
| 843 | Upload the image (the process may take some time): |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 844 | ```bash |
Almir Okato | e8cbc0d | 2022-06-13 10:45:39 -0300 | [diff] [blame] | 845 | mcumgr -c esp image upload <IMAGE_BIN> |
| 846 | ``` |
| 847 | |
| 848 | Reset the device: |
Almir Okato | 8724081 | 2022-12-21 00:05:07 -0300 | [diff] [blame] | 849 | ```bash |
Almir Okato | e8cbc0d | 2022-06-13 10:45:39 -0300 | [diff] [blame] | 850 | mcumgr -c esp reset |
| 851 | ``` |
| 852 | |
| 853 | --- |
| 854 | :warning: ***ATTENTION*** |
| 855 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 856 | *Serial recovery mode uploads the image to the PRIMARY_SLOT, therefore if the upload process gets |
| 857 | interrupted the image may be corrupted and unable to boot* |
Almir Okato | e8cbc0d | 2022-06-13 10:45:39 -0300 | [diff] [blame] | 858 | |
| 859 | --- |
Almir Okato | 4a05118 | 2023-08-09 14:50:04 -0300 | [diff] [blame] | 860 | |
| 861 | ## [Memory map organization for OS compatibility](#memory-map-organization-for-os-compatibility) |
| 862 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 863 | When adding support for this MCUboot port to an OS or even customizing an already supported |
| 864 | application memory layout, it is mandatory for the OS linker script to avoid overlaping on |
| 865 | `iram_loader_seg` and `dram_seg` bootloader RAM regions. Although part of the RAM becomes initially |
| 866 | unavailable, it is reclaimable by the OS after boot as heap. |
Almir Okato | 4a05118 | 2023-08-09 14:50:04 -0300 | [diff] [blame] | 867 | |
| 868 | Therefore, the application must be designed aware of the bootloader memory usage. |
| 869 | |
| 870 | --- |
| 871 | ***Note*** |
| 872 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 873 | *Mostly of the Espressif chips have a separation on the address space for the same physical memory |
| 874 | ammount: IRAM (accessed by the instruction bus) and DRAM (accessed by the data bus), which means |
| 875 | that they need to be accessed by different addresses ranges depending on type, but refer to the |
| 876 | same region. More information on the |
| 877 | [Espressif TRMs](https://www.espressif.com/en/support/documents/technical-documents?keys=&field_download_document_type_tid%5B%5D=963).* |
Almir Okato | 4a05118 | 2023-08-09 14:50:04 -0300 | [diff] [blame] | 878 | |
| 879 | --- |
| 880 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 881 | The following diagrams illustrate a memory organization from the bootloader point of view (notice |
| 882 | that the addresses and sizes may vary depending on the chip), they reflect the linker script |
| 883 | `boot/espressif/port/<TARGET>/ld/bootloader.ld`: |
Almir Okato | 4a05118 | 2023-08-09 14:50:04 -0300 | [diff] [blame] | 884 | |
| 885 | ### ESP32 |
| 886 | |
| 887 | #### ESP32 standard |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 888 | |
Almir Okato | 4a05118 | 2023-08-09 14:50:04 -0300 | [diff] [blame] | 889 | ``` |
| 890 | SRAM0 |
| 891 | IRAM ADDR / DRAM ADDR |
| 892 | * +--------+--------------+------+ 0x40070000 / --------- - SRAM0 START |
| 893 | * | ^ | |
| 894 | * | | PRO CPU Cache | *NOT CLAIMABLE BY OS RAM |
| 895 | * | v | |
| 896 | * +--------+--------------+------+ 0x40078000 / ---------- |
| 897 | * | ^ | |
| 898 | * | | | *NOT CLAIMABLE BY OS RAM |
| 899 | * | | iram_loader_seg | *Region usable as iram_loader_seg during boot |
| 900 | * | | (APP CPU Cache) | as APP CPU is not initialized yet |
| 901 | * | | | |
| 902 | * | v | |
| 903 | * +--------+--------------+------+ 0x40080000 / ---------- |
| 904 | * | ^ | |
| 905 | * | | FREE | *CLAIMABLE BY OS RAM |
| 906 | * | v | |
| 907 | * +------------------------------+ 0x40090000 / ---------- |
| 908 | * | ^ | |
| 909 | * | | iram_seg | *CLAIMABLE BY OS RAM |
| 910 | * | | | |
| 911 | * | v | |
| 912 | * +--------+--------------+------+ 0x40099000 / ---------- |
| 913 | * | | FREE | *CLAIMABLE BY OS RAM |
| 914 | * +------------------------------+ 0x4009FFFF / ---------- - SRAM0 END |
| 915 | |
| 916 | SRAM1 |
| 917 | IRAM ADDR / DRAM ADDR |
| 918 | * +------------------------------+ 0x400A0000 / 0x3FFFFFFF - SRAM1 START |
| 919 | * | ^ | |
| 920 | * | | | *** SHOULD NOT BE OVERLAPPED *** |
| 921 | * | | dram_seg | *** OS CAN RECLAIM IT AFTER BOOT LATER AS HEAP *** |
| 922 | * | v | |
| 923 | * +--------+--------------+------+ 0x400AB900 / 0x3FFF4700 |
| 924 | * | ^ | |
| 925 | * | | | |
| 926 | * | | | |
| 927 | * | | FREE | *CLAIMABLE BY OS RAM |
| 928 | * | | | |
| 929 | * | | | |
| 930 | * | v | |
| 931 | * +--------+--------------+------+ 0x400BFFFF / 0x3FFE0000 - SRAM1 END |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 932 | Note: On ESP32 the SRAM1 addresses are accessed in reverse order comparing Instruction |
| 933 | bus (IRAM) and Data bus (DRAM), but refer to the same location. See the TRM for more |
| 934 | information. |
Almir Okato | 4a05118 | 2023-08-09 14:50:04 -0300 | [diff] [blame] | 935 | |
| 936 | SRAM2 |
| 937 | IRAM ADDR / DRAM ADDR |
| 938 | * +--------+--------------+------+ ---------- / 0x3FFAE000 - SRAM2 START |
| 939 | * | | FREE | *CLAIMABLE BY OS RAM |
| 940 | * +--------+--------------+------+ ---------- / 0x3FFDFFFF - SRAM2 END |
| 941 | ``` |
| 942 | |
| 943 | #### ESP32 Multi Processor Boot |
| 944 | |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 945 | This is the linker script mapping when the `CONFIG_ESP_MULTI_PROCESSOR_BOOT` is enabled |
| 946 | ([Multi boot](#multi-boot)) since APP CPU Cache region cannot be used for `iram_loader_seg` region |
| 947 | as there would be conflict when the bootloader starts the APP CPU before jump to the main |
| 948 | application. |
Almir Okato | 4a05118 | 2023-08-09 14:50:04 -0300 | [diff] [blame] | 949 | |
| 950 | ``` |
| 951 | SRAM0 |
| 952 | IRAM ADDR / DRAM ADDR |
| 953 | * +--------+--------------+------+ 0x40070000 / --------- - SRAM0 START |
| 954 | * | ^ | |
| 955 | * | | | |
| 956 | * | | Cache | *Used by PRO CPU and APP CPU as Cache |
| 957 | * | | | |
| 958 | * | v | |
| 959 | * +--------+--------------+------+ 0x40080000 / ---------- |
| 960 | * | ^ | |
| 961 | * | | FREE | *CLAIMABLE BY OS RAM |
| 962 | * | v | |
| 963 | * +------------------------------+ 0x40090000 / ---------- |
| 964 | * | ^ | |
| 965 | * | | iram_seg | *CLAIMABLE BY OS RAM |
| 966 | * | | | |
| 967 | * | v | |
| 968 | * +--------+--------------+------+ 0x40099000 / ---------- |
| 969 | * | | FREE | *CLAIMABLE BY OS RAM |
| 970 | * +------------------------------+ 0x4009FFFF / ---------- - SRAM0 END |
| 971 | |
| 972 | SRAM1 |
| 973 | IRAM ADDR / DRAM ADDR |
| 974 | * +------------------------------+ 0x400A0000 / 0x3FFFFFFF - SRAM1 START |
| 975 | * | ^ | |
| 976 | * | | | *** SHOULD NOT BE OVERLAPPED *** |
| 977 | * | | dram_seg | *** OS CAN RECLAIM IT AFTER BOOT LATER AS HEAP *** |
| 978 | * | v | |
| 979 | * +--------+--------------+------+ 0x400AB900 / 0x3FFF4700 |
| 980 | * | ^ | |
| 981 | * | | | *** SHOULD NOT BE OVERLAPPED *** |
| 982 | * | | iram_loader_seg | *** OS CAN RECLAIM IT AFTER BOOT LATER AS HEAP *** |
| 983 | * | | | |
| 984 | * | v | |
| 985 | * +------------------------------+ 0x400B1E00 / 0x3FFEE200 |
| 986 | * | ^ | |
| 987 | * | | | |
| 988 | * | | FREE | *CLAIMABLE BY OS RAM |
| 989 | * | | | |
| 990 | * | v | |
| 991 | * +--------+--------------+------+ 0x400BFFFF / 0x3FFE0000 - SRAM1 END |
Fabio Utzig | b58962f | 2023-09-02 15:58:55 -0300 | [diff] [blame] | 992 | Note: On ESP32 the SRAM1 addresses are accessed in reverse order comparing Instruction |
| 993 | bus (IRAM) and Data bus (DRAM), but refer to the same location. See the TRM for more |
| 994 | information. |
Almir Okato | 4a05118 | 2023-08-09 14:50:04 -0300 | [diff] [blame] | 995 | |
| 996 | SRAM2 |
| 997 | IRAM ADDR / DRAM ADDR |
| 998 | * +--------+--------------+------+ ---------- / 0x3FFAE000 - SRAM2 START |
| 999 | * | | FREE | *CLAIMABLE BY OS RAM |
| 1000 | * +--------+--------------+------+ ---------- / 0x3FFDFFFF - SRAM2 END |
| 1001 | ``` |
| 1002 | |
| 1003 | ### ESP32-S2 |
| 1004 | |
| 1005 | ``` |
| 1006 | SRAM0 |
| 1007 | IRAM ADDR / DRAM ADDR |
| 1008 | * +--------+--------------+------+ 0x40020000 / 0x3FFB0000 - SRAM0 START |
| 1009 | * | | FREE | *CLAIMABLE BY OS RAM |
| 1010 | * +--------+--------------+------+ 0x40027FFF / 0x3FFB7FFF - SRAM0 END |
| 1011 | |
| 1012 | SRAM1 |
| 1013 | IRAM ADDR / DRAM ADDR |
| 1014 | * +--------+--------------+------+ 0x40028000 / 0x3FFB8000 - SRAM1 START |
| 1015 | * | ^ | |
| 1016 | * | | | |
| 1017 | * | | FREE | *CLAIMABLE BY OS RAM |
| 1018 | * | | | |
| 1019 | * | v | |
| 1020 | * +--------+--------------+------+ 0x40047000 / 0x3FFD7000 |
| 1021 | * | ^ | |
| 1022 | * | | | |
| 1023 | * | | | |
| 1024 | * | | iram_seg | *CLAIMABLE BY OS RAM |
| 1025 | * | | | |
| 1026 | * | | | |
| 1027 | * | v | |
| 1028 | * +------------------------------+ 0x40050000 / 0x3FFE0000 |
| 1029 | * | ^ | |
| 1030 | * | | | |
| 1031 | * | | | |
| 1032 | * | | iram_loader_seg | *** SHOULD NOT BE OVERLAPPED *** |
| 1033 | * | | | *** OS CAN RECLAIM IT AFTER BOOT LATER AS HEAP *** |
| 1034 | * | | | |
| 1035 | * | v | |
| 1036 | * +------------------------------+ 0x40056000 / 0x3FFE6000 |
| 1037 | * | ^ | |
| 1038 | * | | | |
| 1039 | * | | dram_seg | *** SHOULD NOT BE OVERLAPPED *** |
| 1040 | * | | | *** OS CAN RECLAIM IT AFTER BOOT LATER AS HEAP *** |
| 1041 | * | v | |
| 1042 | * +--------+--------------+------+ 0x4006FFFF / 0x3FFFFFFF - SRAM1 END |
| 1043 | ``` |
| 1044 | |
| 1045 | ### ESP32-S3 |
| 1046 | |
| 1047 | ``` |
| 1048 | SRAM0 |
| 1049 | IRAM ADDR / DRAM ADDR |
| 1050 | * +--------+--------------+------+ 0x40370000 / ---------- - SRAM0 START |
| 1051 | * | | FREE | *CLAIMABLE BY OS RAM |
| 1052 | * +--------+--------------+------+ 0x40377FFF / ---------- - SRAM0 END |
| 1053 | |
| 1054 | SRAM1 |
| 1055 | IRAM ADDR / DRAM ADDR |
| 1056 | * +--------+--------------+------+ 0x40378000 / 0x3FC88000 - SRAM1 START |
| 1057 | * | ^ | |
| 1058 | * | | | |
| 1059 | * | | FREE | *CLAIMABLE BY OS RAM |
| 1060 | * | | | |
| 1061 | * | v | |
| 1062 | * +--------+--------------+------+ 0x403B0000 / 0x3FCC0000 |
| 1063 | * | ^ | |
| 1064 | * | | | |
| 1065 | * | | | |
| 1066 | * | | iram_seg | *CLAIMABLE BY OS RAM |
| 1067 | * | | | |
| 1068 | * | | | |
| 1069 | * | v | |
| 1070 | * +------------------------------+ 0x403BA000 / 0x3FCCA000 |
| 1071 | * | ^ | |
| 1072 | * | | | |
| 1073 | * | | | |
| 1074 | * | | iram_loader_seg | *** SHOULD NOT BE OVERLAPPED *** |
| 1075 | * | | | *** OS CAN RECLAIM IT AFTER BOOT LATER AS HEAP *** |
| 1076 | * | | | |
| 1077 | * | v | |
| 1078 | * +------------------------------+ 0x403C0000 / 0x3FCD0000 |
| 1079 | * | ^ | |
| 1080 | * | | | |
| 1081 | * | | dram_seg | *** SHOULD NOT BE OVERLAPPED *** |
| 1082 | * | | | *** OS CAN RECLAIM IT AFTER BOOT LATER AS HEAP *** |
| 1083 | * | v | |
| 1084 | * +--------+--------------+------+ 0x403DFFFF / 0x3FCEFFFF - SRAM1 END |
| 1085 | |
| 1086 | SRAM2 |
| 1087 | IRAM ADDR / DRAM ADDR |
| 1088 | * +--------+--------------+------+ ---------- / 0x3FCF0000 - SRAM2 START |
| 1089 | * | | FREE | *CLAIMABLE BY OS RAM |
| 1090 | * +--------+--------------+------+ ---------- / 0x3FCFFFFF - SRAM2 END |
| 1091 | ``` |
| 1092 | |
| 1093 | ### ESP32-C2 |
| 1094 | |
| 1095 | ``` |
| 1096 | SRAM0 |
| 1097 | IRAM ADDR / DRAM ADDR |
| 1098 | * +--------+--------------+------+ 0x4037C000 / ---------- - SRAM0 START |
| 1099 | * | | FREE | *CLAIMABLE BY OS RAM |
| 1100 | * +--------+--------------+------+ 0x4037FFFF / ---------- - SRAM0 END |
| 1101 | |
| 1102 | SRAM1 |
| 1103 | IRAM ADDR / DRAM ADDR |
| 1104 | * +--------+--------------+------+ 0x40380000 / 0x3FCA0000 - SRAM1 START |
| 1105 | * | ^ | |
| 1106 | * | | | |
| 1107 | * | | | |
| 1108 | * | | FREE | *CLAIMABLE BY OS RAM |
| 1109 | * | | | |
| 1110 | * | | | |
| 1111 | * | v | |
| 1112 | * +--------+--------------+------+ 0x403A1370 / 0x3FCC1370 |
| 1113 | * | ^ | |
| 1114 | * | | | |
| 1115 | * | | | |
| 1116 | * | | iram_seg | *CLAIMABLE BY OS RAM |
| 1117 | * | | | |
| 1118 | * | | | |
| 1119 | * | v | |
| 1120 | * +------------------------------+ 0x403A9B70 / 0x3FCC9B70 |
| 1121 | * | ^ | |
| 1122 | * | | | |
| 1123 | * | | | |
| 1124 | * | | iram_loader_seg | *** SHOULD NOT BE OVERLAPPED *** |
| 1125 | * | | | *** OS CAN RECLAIM IT AFTER BOOT LATER AS HEAP *** |
| 1126 | * | | | |
| 1127 | * | v | |
| 1128 | * +------------------------------+ 0x403B0B70 / 0x3FCD0B70 |
| 1129 | * | ^ | |
| 1130 | * | | | |
| 1131 | * | | dram_seg | *** SHOULD NOT BE OVERLAPPED *** |
| 1132 | * | | | *** OS CAN RECLAIM IT AFTER BOOT LATER AS HEAP *** |
| 1133 | * | v | |
| 1134 | * +--------+--------------+------+ 0x403BFFFF / 0x3FCDFFFF - SRAM1 END |
| 1135 | ``` |
| 1136 | |
| 1137 | ### ESP32-C3 |
| 1138 | |
| 1139 | ``` |
| 1140 | SRAM0 |
| 1141 | IRAM ADDR / DRAM ADDR |
| 1142 | * +--------+--------------+------+ 0x4037C000 / ---------- - SRAM0 START |
| 1143 | * | | FREE | *CLAIMABLE BY OS RAM |
| 1144 | * +--------+--------------+------+ 0x4037FFFF / ---------- - SRAM0 END |
| 1145 | |
| 1146 | SRAM1 |
| 1147 | IRAM ADDR / DRAM ADDR |
| 1148 | * +--------+--------------+------+ 0x40380000 / 0x3FC80000 - SRAM1 START |
| 1149 | * | ^ | |
| 1150 | * | | | |
| 1151 | * | | | |
| 1152 | * | | FREE | *CLAIMABLE BY OS RAM |
| 1153 | * | | | |
| 1154 | * | | | |
| 1155 | * | v | |
| 1156 | * +--------+--------------+------+ 0x403C7000 / 0x3FCC7000 |
| 1157 | * | ^ | |
| 1158 | * | | | |
| 1159 | * | | | |
| 1160 | * | | iram_seg | *CLAIMABLE BY OS RAM |
| 1161 | * | | | |
| 1162 | * | | | |
| 1163 | * | v | |
| 1164 | * +------------------------------+ 0x403D0000 / 0x3FCD0000 |
| 1165 | * | ^ | |
| 1166 | * | | | |
| 1167 | * | | | |
| 1168 | * | | iram_loader_seg | *** SHOULD NOT BE OVERLAPPED *** |
| 1169 | * | | | *** OS CAN RECLAIM IT AFTER BOOT LATER AS HEAP *** |
| 1170 | * | | | |
| 1171 | * | v | |
Almir Okato | db2024e | 2023-08-24 15:40:26 -0300 | [diff] [blame] | 1172 | * +------------------------------+ 0x403D5400 / 0x3FCD5400 |
Almir Okato | 4a05118 | 2023-08-09 14:50:04 -0300 | [diff] [blame] | 1173 | * | ^ | |
| 1174 | * | | | |
| 1175 | * | | dram_seg | *** SHOULD NOT BE OVERLAPPED *** |
| 1176 | * | | | *** OS CAN RECLAIM IT AFTER BOOT LATER AS HEAP *** |
| 1177 | * | v | |
| 1178 | * +--------+--------------+------+ 0x403DFFFF / 0x3FCDFFFF - SRAM1 END |
| 1179 | ``` |
| 1180 | |
| 1181 | ### ESP32-C6 |
| 1182 | |
| 1183 | ``` |
| 1184 | IRAM ADDR / DRAM ADDR |
| 1185 | * +--------+--------------+------+ 0x40800000 / 0x40800000 - HP SRAM START |
| 1186 | * | ^ | |
| 1187 | * | | | |
| 1188 | * | | | |
| 1189 | * | | FREE | *CLAIMABLE BY OS RAM |
| 1190 | * | | | |
| 1191 | * | | | |
| 1192 | * | v | |
| 1193 | * +--------+--------------+------+ 0x40860610 / 0x40860610 |
| 1194 | * | ^ | |
| 1195 | * | | | |
| 1196 | * | | | |
| 1197 | * | | iram_seg | *CLAIMABLE BY OS RAM |
| 1198 | * | | | |
| 1199 | * | | | |
| 1200 | * | v | |
| 1201 | * +------------------------------+ 0x40869610 / 0x40869610 |
| 1202 | * | ^ | |
| 1203 | * | | | |
| 1204 | * | | | |
| 1205 | * | | iram_loader_seg | *** SHOULD NOT BE OVERLAPPED *** |
| 1206 | * | | | *** OS CAN RECLAIM IT AFTER BOOT LATER AS HEAP *** |
| 1207 | * | | | |
| 1208 | * | v | |
| 1209 | * +------------------------------+ 0x40870610 / 0x40870610 |
| 1210 | * | ^ | |
| 1211 | * | | | |
| 1212 | * | | dram_seg | *** SHOULD NOT BE OVERLAPPED *** |
| 1213 | * | | | *** OS CAN RECLAIM IT AFTER BOOT LATER AS HEAP *** |
| 1214 | * | v | |
| 1215 | * +--------+--------------+------+ 0x4087FFFF / 0x4087FFFF - HP SRAM END |
| 1216 | ``` |
| 1217 | |
| 1218 | ### ESP32-H2 |
| 1219 | |
| 1220 | ``` |
| 1221 | IRAM ADDR / DRAM ADDR |
| 1222 | * +--------+--------------+------+ 0x40800000 / 0x40800000 - HP SRAM START |
| 1223 | * | ^ | |
| 1224 | * | | | |
| 1225 | * | | | |
| 1226 | * | | FREE | *CLAIMABLE BY OS RAM |
| 1227 | * | | | |
| 1228 | * | | | |
| 1229 | * | v | |
| 1230 | * +--------+--------------+------+ 0x408317D0 / 0x408317D0 |
| 1231 | * | ^ | |
| 1232 | * | | | |
| 1233 | * | | | |
| 1234 | * | | iram_seg | *CLAIMABLE BY OS RAM |
| 1235 | * | | | |
| 1236 | * | | | |
| 1237 | * | v | |
| 1238 | * +------------------------------+ 0x40839FD0 / 0x40839FD0 |
| 1239 | * | ^ | |
| 1240 | * | | | |
| 1241 | * | | | |
| 1242 | * | | iram_loader_seg | *** SHOULD NOT BE OVERLAPPED *** |
| 1243 | * | | | *** OS CAN RECLAIM IT AFTER BOOT LATER AS HEAP *** |
| 1244 | * | | | |
| 1245 | * | v | |
| 1246 | * +------------------------------+ 0x40840FD0 / 0x40840FD0 |
| 1247 | * | ^ | |
| 1248 | * | | | |
| 1249 | * | | dram_seg | *** SHOULD NOT BE OVERLAPPED *** |
| 1250 | * | | | *** OS CAN RECLAIM IT AFTER BOOT LATER AS HEAP *** |
| 1251 | * | v | |
| 1252 | * +--------+--------------+------+ 0x4084FFFF / 0x4084FFFF - HP SRAM END |
| 1253 | ``` |