#Set the Boot Key and disable read and writeespefuse.py burn_key secure_boot ./hello_world_k1/secure-bootloader-key-256.binespefuse.py burn_efuse ABS_DONE_0
Flash the AES Flash Encryption Key:
#Generate Keyespsecure.py generate_flash_encryption_key my_flash_encryption_key.bin#Key Datahexdump my_flash_encryption_key.bin 0000000 c838 e375 7633 1541 5ff9 4365 f2dd 2ce90000010 1f78 42a0 bf53 8f14 68ce 009f 5586 9b52#Flash Key and disable write and readespefuse.py --port /dev/ttyUSB0 burn_key flash_encryption my_flash_encryption_key.binespefuse.py v2.7-devConnecting......Write key in efuse block 1. The key block will be read and write protected (no further changes or readback). This is an irreversible operation.Type'BURN' (all capitals)to continue.BURNBurned key data. New value: 9b 52 55 86 00 9f 68 ce 8f 14 bf 53 42 a0 1f 78 2c e9 f2 dd 43 65 5f f9 15 41 76 33 e3 75 c8 38Disabling read/write to key efuse block...#Activate the Keyespefuse.py burn_efuse FLASH_CRYPT_CONFIG 0xfespefuse.py burn_efuse FLASH_CRYPT_CNT
voidapp_main(){while(1){printf("Hello from SEC boot K1 & FE !\n");vTaskDelay(1000/ portTICK_PERIOD_MS);}}
Compile with the proper flags:
# Enable the secure boot and the flash encryptionmake menuconfig#Generate the Hash digest to validate the Application from being replacedespsecure.py encrypt_flash_data -k ../../my_flash_encryption_key.bin -o bootloader-reflash-digest-encrypted.bin -a 0x0 bootloader-reflash-digest.bin # Flash the Digest Information python /home/limited/esp/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x0 /home/ limited/esp/hello_world_k1_FE/build/bootloader/bootloader-reflash-digest-encrypted.bin# Flash the Encrypted Application to the memory address of 0x10000# This is the Entry point for the Device and starts the decrypting (Stage 1)espsecure.py encrypt_flash_data -k ../my_flash_encryption_key.bin -o hello-world-encrypted.bin -a 0x10000 hello-world.bin # Encrypt the App Partition that starts at the offset of 0x08000# This is the main app that is the stage 2espsecure.py encrypt_flash_data -k ../my_flash_encryption_key.bin -o partitions_singleapp-encrypted.bin -a 0x08000 partitions_singleapp.bin # Now flash them with the appropriate offsetpython /home/limited/esp/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x10000 /home/limited/esp/hello_world_k1_FE/build/hello-world-encrypted.bin 0x8000 /home/limited/esp/hello_world_k1_FE/build/partitions_singleapp-encrypted.bin