樂鑫科技matter協議智能家居物聯網ble和wifi芯片Secure Boot方案示例,Secure Boot 方案的功能已經集成在 ESP-IDF 中,讀者只需要理解它的實現原理,結合需求在menuconfig 中配置合適的選項啟用 Secure Boot 方案即可。相比于軟 Secure Boot 方案,硬Secure Boot方案提供了更完整的固件合法性校驗,因此應該在設備出廠時使用硬樂鑫科技matter協議智能家居物聯網ble和wifi芯片Secure Boot方案來增強設備的安全性。本文將介紹啟用硬 Secure Boot 方案的一些示例,小伙伴可以仿照示例進行測試。此外,當向使用硬樂鑫科技matter協議智能家居物聯網ble和wifi芯片Secure Boot 方案的設備端發送新固件出錯時,也可以參照下面的 Log 進行分析,排查出錯的原因。
按照所述的步驟啟用硬 Secure Boot 方案后,設備端在上電后將出現啟用硬樂鑫科技matter協議智能家居物聯網ble和wifi芯片Secure Boot 方案的 Log:
I(10251) secure boot v2: Secure boot y2 is not enabled yet and efsue digest keys are not set
I(10256) secure_boot_v2: Verifying with RSA-PSS...
I(10254) secure_boot_v2: Signature verified successfully!
I(10272) boot: boot: Loaded app from partition at offset 0x120000
I(10274) secure_boot_v2: Enabling secure boot v2...
使用樂鑫科技matter協議智能家居物聯網ble和wifi芯片Secure Boot 方案后的設備端再次上電的 Log 如下:
ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0x1 (POWERON),boot:0xC(SPI_EAST FLASH BOOT)
SPIWP:0xee
mode:DIO,clock div:1
Valid Secure Boot key blocks: 0
Secure Boot verification succeeded
load:0x3fcd6268,len:0x2ebc
load:0x403ce000,len:0x928
load:0x403d0000,len:0x4ce4
entry 0x403ce000
I(71) boot:ESP-IDF V4.3.2-2741-g7c0fa3fc70 2nd stage bootloader
向使用硬 Secure Boot 方案的設備端燒錄未簽名的 Bootloader 固件,設備端在啟動后將打印提示出錯的 Log,并終止引導。
ESP-ROM:esp32c3-api1-20210207Build:Feb 7 2021
rst:0x1 (POWERON),boot:0xC(SPI FAST FLASH BOOT)SPIWP:Oxee
mode:DIO,clock div:1
Valid secure boot key blocks: 0
No signature block magic byte found at signature sector (found 0xcd not 0xe7). Imagenot V2 signed?
secure boot verification failed
ets main.c 333
向使用樂鑫科技matter協議智能家居物聯網ble和wifi芯片硬 Secure Boot 的設備端燒錄未經簽名的 app 固件,設備端在啟動后將打印提示出錯的Log,并終止引導。
I (310) esp_image: Verifying image signature..
I (312) secure boot v2: Verifying with RSA-PSS...
No signature block magic byte found at signature sector (found 0x41 not 0xe7). Image not V2 signed?
E (326) secure boot_v2: Secure Boot V2 verification failed.
E (332) esp_image: secure boot signature verification failed
I (339) esp_image: Calculating simple hash to check for corruption...
W(418)esp_image:image valid, signature bad
通過 OTA 升級向使用硬樂鑫科技matter協議智能家居物聯網ble和wifi芯片Secure Boot 方案的設備端發送未經簽名的 app 固件,將結束數據傳輸,提示簽名校驗失敗,并停止加載下載的固件。
I (4487) simple ota example: Starting OTA example
I (5657) esp https ota: Starting OTA...
I (5657) esphttps ota: writing to partition subtype 16 at offset 0x120000
I (26557) esp_image: segment 0: paddr=00120020 vaddr=3c0a0020 size=lb488h (111752) map
I (26567) esp_image: segment 1: paddr=0013b4b0 vaddr=3fc8d800 size=02b10h ( 11024)
I (26567) esp_image: segment 2: paddr-0013dfc8 vaddr=40380000 size=02050h ( 8272)
I(26577) esp_image: segment 3: paddr=00140020 vaddr=42000020 size-9d9ech (645612) map
I (26667) esp image: segment 4: paddr=001ddal4 vaddr-40382050 size=0b60ch ( 46604)
I (26667) esp_image: segment 5: paddr=001e9028 vaddr-50000000 size-00010h (16)
I (26667) esp image: Verifying image signature...
I (26677) secure boot v2: Take trusted digest key(s) from eFuse block(s)
E (26687) esp image: Secure boot signature verification failed
I (26687) esp_mage: Calculating simple hash to check for corruption..
W (26757) esp image: image valid,signature bad
E (26767) simple_ota_example: Firmware upgrade failed