Skip to content

Commit 8724081

Browse files
almir-okatogustavonihei
authored andcommitted
doc: espressif: Add warning note for Flash Encryption with Serial Recovery usage
Signed-off-by: Almir Okato <[email protected]>
1 parent d165e9b commit 8724081

File tree

1 file changed

+50
-49
lines changed

1 file changed

+50
-49
lines changed

docs/readme-espressif.md

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,34 @@ The current port is available for use in the following SoCs within the OSes:
1616
## [Installing requirements and dependencies](#installing-requirements-and-dependencies)
1717

1818
1. Install additional packages required for development with MCUboot:
19-
20-
```
19+
```bash
2120
cd ~/mcuboot # or to your directory where MCUboot is cloned
21+
```
22+
```bash
2223
pip3 install --user -r scripts/requirements.txt
2324
```
2425

2526
2. Update the submodules needed by the Espressif port. This may take a while.
26-
27-
```
27+
```bash
2828
git submodule update --init --recursive --checkout boot/espressif/hal/esp-idf
2929
```
3030

3131
3. Next, get the Mbed TLS submodule required by MCUboot.
32-
```
32+
```bash
3333
git submodule update --init --recursive ext/mbedtls
3434
```
3535

3636
4. Now we need to install IDF dependencies and set environment variables. This step may take some time:
37-
```
37+
```bash
3838
cd boot/espressif/hal/esp-idf
39+
```
40+
```bash
3941
./install.sh
42+
```
43+
```bash
4044
. ./export.sh
45+
```
46+
```bash
4147
cd ../..
4248
```
4349

@@ -53,23 +59,22 @@ The MCUboot Espressif port bootloader is built using the toolchain and tools pro
5359
---
5460

5561
1. Compile and generate the BIN:
56-
57-
```
62+
```bash
5863
cmake -DCMAKE_TOOLCHAIN_FILE=tools/toolchain-<TARGET>.cmake -DMCUBOOT_TARGET=<TARGET> -DMCUBOOT_FLASH_PORT=<PORT> -B build -GNinja
64+
```
65+
```bash
5966
ninja -C build/
6067
```
6168

6269
2. Flash MCUboot in your device:
63-
64-
```
70+
```bash
6571
ninja -C build/ flash
6672
```
6773

6874
If `MCUBOOT_FLASH_PORT` arg was not passed to `cmake`, the default `PORT` for flashing will be `/dev/ttyUSB0`.
6975

7076
Alternatively:
71-
72-
```
77+
```bash
7378
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
7479
```
7580
---
@@ -79,7 +84,7 @@ You may adjust the port `<PORT>` (like `/dev/ttyUSB0`) and baud rate `<BAUD>` (l
7984
You can also skip `<PORT>` and `<BAUD>` parameters so that esptool tries to automatically detect it.
8085

8186
*`<FLASH_SIZE>` can be found using the command below:*
82-
```
87+
```bash
8388
esptool.py -p <PORT> -b <BAUD> flash_id
8489
```
8590
The output contains device information and its flash size:
@@ -101,8 +106,7 @@ Detected flash size: 4MB
101106
## [Signing and flashing an application](#signing-and-flashing-an-application)
102107

103108
1. Images can be regularly signed with the `scripts/imgtool.py` script:
104-
105-
```
109+
```bash
106110
imgtool.py sign --align 4 -v 0 -H 32 --pad-header -S <SLOT_SIZE> <BIN_IN> <SIGNED_BIN>
107111
```
108112

@@ -125,8 +129,7 @@ For signing with a crypto key and guarantee the authenticity of the image being
125129
---
126130

127131
2. Flash the signed application:
128-
129-
```
132+
```bash
130133
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>
131134
```
132135

@@ -205,8 +208,7 @@ Notice that the public key will be embedded in the bootloader code, since the ha
205208
### [Signing the image](#signing-the-image)
206209

207210
Now you need to sign the **image binary**, use the `imgtool` with `-k` parameter:
208-
209-
```
211+
```bash
210212
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>
211213
```
212214
If signing a Zephyr image, the `--pad-header` is not needed, as it already have the padding for MCUboot header.
@@ -265,12 +267,12 @@ CONFIG_SECURE_ENABLE_SECURE_ROM_DL_MODE=1
265267
Once the **bootloader image** is built, the resulting binary file is required to be signed with `espsecure.py` tool.
266268

267269
First create a signing key:
268-
```
270+
```bash
269271
espsecure.py generate_signing_key --version 2 <BOOTLOADER_SIGNING_KEY.pem>
270272
```
271273

272274
Then sign the bootloader image:
273-
```
275+
```bash
274276
espsecure.py sign_data --version 2 --keyfile <BOOTLOADER_SIGNING_KEY.pem> -o <BOOTLOADER_BIN_OUT> <BOOTLOADER_BIN_IN>
275277
```
276278

@@ -282,7 +284,7 @@ espsecure.py sign_data --version 2 --keyfile <BOOTLOADER_SIGNING_KEY.pem> -o <BO
282284
---
283285

284286
Flash the bootloader as following, with `--after no_reset` flag, so you can reset the device only when assured:
285-
```
287+
```bash
286288
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>
287289
```
288290

@@ -378,19 +380,18 @@ CONFIG_SECURE_ENABLE_SECURE_ROM_DL_MODE=1
378380
When enabling flash encryption, it is required to signed the image using 32-byte alignment: `--align 32 --max-align 32`.
379381

380382
Command example:
381-
```
383+
```bash
382384
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>
383385
```
384386

385387
### [Device generated key](#device-generated-key)
386388

387389
First ensure that the application image is able to perform encrypted read and write operations to the SPI Flash.
388390
Flash the bootloader and application normally:
389-
390-
```
391+
```bash
391392
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>
392393
```
393-
```
394+
```bash
394395
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>
395396
```
396397

@@ -404,7 +405,7 @@ On the **first boot**, the bootloader will:
404405

405406
First ensure that the application image is able to perform encrypted read and write operations to the SPI Flash. Also ensure that the **UART ROM Download Mode is not disabled** - or that the **Secure Download Mode is enabled**.
406407
Before flashing, generate the encryption key using `espsecure.py` tool:
407-
```
408+
```bash
408409
espsecure.py generate_flash_encryption_key <FLASH_ENCRYPTION_KEY.bin>
409410
```
410411

@@ -418,12 +419,12 @@ Burn the key into the device's eFuse (keep a copy on the host), this action can
418419
---
419420

420421
- ESP32
421-
```
422+
```bash
422423
espefuse.py --port PORT burn_key flash_encryption <FLASH_ENCRYPTION_KEY.bin>
423424
```
424425

425426
- ESP32S2, ESP32C3 and ESP32S3
426-
```
427+
```bash
427428
espefuse.py --port PORT burn_key BLOCK <FLASH_ENCRYPTION_KEY.bin> <KEYPURPOSE>
428429
```
429430

@@ -432,11 +433,10 @@ BLOCK is a free keyblock between BLOCK_KEY0 and BLOCK_KEY5. And KEYPURPOSE is ei
432433
Now, similar as the Device generated key, the bootloader and application can be flashed plaintext. The **first boot** will encrypt the flash content using the host key burned in the eFuse instead of generate a new one.
433434

434435
Flashing the bootloader and application:
435-
436-
```
436+
```bash
437437
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>
438438
```
439-
```
439+
```bash
440440
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>
441441
```
442442

@@ -447,12 +447,12 @@ On the **first boot**, the bootloader will:
447447

448448
Encrypting data on the host:
449449
- ESP32
450-
```
450+
```bash
451451
espsecure.py encrypt_flash_data --keyfile <FLASH_ENCRYPTION_KEY.bin> --address <FLASH_OFFSET> --output <OUTPUT_DATA> <INPUT_DATA>
452452
```
453453

454454
- ESP32-S2, ESP32-C3 and ESP32-S3
455-
```
455+
```bash
456456
espsecure.py encrypt_flash_data --aes_xts --keyfile <FLASH_ENCRYPTION_KEY.bin> --address <FLASH_OFFSET> --output <OUTPUT_DATA> <INPUT_DATA>
457457
```
458458

@@ -549,8 +549,7 @@ CONFIG_ESP_SCRATCH_SIZE=0x40000
549549
### [Image version dependency](#image-version-dependency)
550550

551551
MCUboot allows version dependency check between the images when updating them. As `imgtool.py` allows a version assigment when signing an image, it is also possible to add the version dependency constraint:
552-
553-
```
552+
```bash
554553
imgtool.py sign --align 4 -v <VERSION> -d "(<IMAGE_INDEX>, <VERSION_DEPENDENCY>)" -H 32 --pad-header -S <SLOT_SIZE> <BIN_IN> <SIGNED_BIN>
555554
```
556555

@@ -559,7 +558,7 @@ imgtool.py sign --align 4 -v <VERSION> -d "(<IMAGE_INDEX>, <VERSION_DEPENDENCY>)
559558

560559
---
561560
Example:
562-
```
561+
```bash
563562
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
564563
```
565564

@@ -571,13 +570,6 @@ Supposing that the image 0 is being signed, its version is 1.0.0 and it depends
571570

572571
Serial recovery mode allows management through MCUMGR (more information and how to install it: https://github.com/apache/mynewt-mcumgr-cli) for communicating and uploading a firmware to the device.
573572

574-
---
575-
***Note***
576-
577-
Supported on ESP32, ESP32-C3, ESP32-S2 and ESP32-S3.
578-
579-
---
580-
581573
Configuration example:
582574
```
583575
# Enables the MCUboot Serial Recovery, that allows the use of
@@ -605,8 +597,10 @@ Serial mode then uses the UART port configured for communication (`<CONFIG_ESP_S
605597

606598
### [Serial Recovery through USB JTAG Serial port](#serial-recovery-through-usb-jtag-serial-port)
607599

608-
Some chips, like ESP32-C3, have an integrated USB JTAG Serial Controller that implements a serial port (CDC) that can also be used for handling MCUboot Serial Recovery.
609-
More information about the USB pins and hardware configuration on ESP32-C3: https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/api-guides/usb-serial-jtag-console.html.
600+
Some chips, like ESP32-C3 and ESP32-S3 have an integrated USB JTAG Serial Controller that implements a serial port (CDC) that can also be used for handling MCUboot Serial Recovery.
601+
More information about the USB pins and hardware configuration:
602+
- ESP32-C3: https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/api-guides/usb-serial-jtag-console.html
603+
- ESP32-S3: https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-guides/usb-serial-jtag-console.html.
610604

611605
Configuration example:
612606
```
@@ -625,22 +619,29 @@ CONFIG_ESP_SERIAL_BOOT_GPIO_DETECT_VAL=1
625619
CONFIG_ESP_SERIAL_BOOT_DETECT_DELAY_S=5
626620
```
627621

622+
---
623+
:warning: ***ATTENTION***
624+
625+
*When working with Flash Encryption enabled, `CONFIG_ESP_MCUBOOT_ERASE_PROGRESSIVELY` must be ***disabled***, although it is recommended for common Serial Recovery usage*
626+
627+
---
628+
628629
### [MCUMGR image upload example](#mcumgr-image-upload-example)
629630

630631
After entering the Serial recovery mode on the device, MCUMGR can be used as following:
631632

632633
Configure the connection:
633-
```
634+
```bash
634635
mcumgr conn add esp type="serial" connstring="dev=<PORT>,baud=115200,mtu=256"
635636
```
636637

637638
Upload the image (the process may take some time):
638-
```
639+
```bash
639640
mcumgr -c esp image upload <IMAGE_BIN>
640641
```
641642

642643
Reset the device:
643-
```
644+
```bash
644645
mcumgr -c esp reset
645646
```
646647

0 commit comments

Comments
 (0)