ESP32-C3 flash encryption & secure boot

本文介绍ESP32-C3芯片如何启用安全启动和闪存加密,包括配置步骤、生成签名密钥、调整分区表地址及手动烧录等关键环节。

本篇文档用来记录同时使能 ESP32-C3 flash 加密以及 secure boot 的流程。
测试环境如下:

  • 硬件: ESP32-C3(revision 3)
  • idf 版本:v4.4-dev-3042-g220590d599

未使能前,设备的 efuse 信息

$ esptool.py flash_id                                                                                                                                                                                 
esptool.py v3.2-dev
Found 2 serial ports
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP32-C3
Chip is ESP32-C3 (revision 3)
Features: Wi-Fi
Crystal is 40MHz
MAC: 7c:df:a1:61:bd:20
Uploading stub...
Running stub...
Stub running...
Manufacturer: 20
Device: 4016
Detected flash size: 4MB
Hard resetting via RTS pin...
$ espefuse.py --chip esp32c3 summary
Connecting....
espefuse.py v3.2-dev
EFUSE_NAME (Block) Description  = [Meaningful Value] [Readable/Writeable] (Hex Value)
----------------------------------------------------------------------------------------
Calibration fuses:
TEMP_SENSOR_CAL (BLOCK2)                           Temperature calibration                            = -15.100000000000001 R/W (0b110010111)
ADC1_MODE0_D2 (BLOCK2)                             ADC1 calibration 1                                 = -208 R/W (0xb4)
ADC1_MODE1_D2 (BLOCK2)                             ADC1 calibration 2                                 = 348 R/W (0x57)
ADC1_MODE2_D2 (BLOCK2)                             ADC1 calibration 3                                 = -16 R/W (0x84)
ADC1_MODE3_D2 (BLOCK2)                             ADC1 calibration 4                                 = 184 R/W (0x2e)
ADC2_MODE0_D2 (BLOCK2)                             ADC2 calibration 5                                 = -200 R/W (0xb2)
ADC2_MODE1_D2 (BLOCK2)                             ADC2 calibration 6                                 = -488 R/W (0xfa)
ADC2_MODE2_D2 (BLOCK2)                             ADC2 calibration 7                                 = -396 R/W (0xe3)
ADC2_MODE3_D2 (BLOCK2)                             ADC2 calibration 8                                 = -12 R/W (0x83)
ADC1_MODE0_D1 (BLOCK2)                             ADC1 calibration 9                                 = 4 R/W (0b000001)
ADC1_MODE1_D1 (BLOCK2)                             ADC1 calibration 10                                = -100 R/W (0b111001)
ADC1_MODE2_D1 (BLOCK2)                             ADC1 calibration 11                                = 100 R/W (0b011001)
ADC1_MODE3_D1 (BLOCK2)                             ADC1 calibration 12                                = 8 R/W (0b000010)
ADC2_MODE0_D1 (BLOCK2)                             ADC2 calibration 13                                = 0 R/W (0b000000)
ADC2_MODE1_D1 (BLOCK2)                             ADC2 calibration 14                                = 0 R/W (0b000000)
ADC2_MODE2_D1 (BLOCK2)                             ADC2 calibration 15                                = 0 R/W (0b000000)
ADC2_MODE3_D1 (BLOCK2)                             ADC2 calibration 16                                = 0 R/W (0b000000)

Config fuses:
DIS_ICACHE (BLOCK0)                                Disables ICache                                    = False R/W (0b0)
DIS_DOWNLOAD_ICACHE (BLOCK0)                       Disables Icache when SoC is in Download mode       = False R/W (0b0)
DIS_FORCE_DOWNLOAD (BLOCK0)                        Disables forcing chip into Download mode           = False R/W (0b0)
DIS_CAN (BLOCK0)                                   Disables the TWAI Controller hardware              = False R/W (0b0)
VDD_SPI_AS_GPIO (BLOCK0)                           Set this bit to vdd spi pin function as gpio       = False R/W (0b0)
BTLC_GPIO_ENABLE (BLOCK0)                          Enable btlc gpio                                   = 0 R/W (0b00)
POWERGLITCH_EN (BLOCK0)                            Set this bit to enable power glitch function       = False R/W (0b0)
POWER_GLITCH_DSENSE (BLOCK0)                       Sample delay configuration of power glitch         = 0 R/W (0b00)
DIS_LEGACY_SPI_BOOT (BLOCK0)                       Disables Legacy SPI boot mode                      = False R/W (0b0)
UART_PRINT_CHANNEL (BLOCK0)                        Selects the default UART for printing boot msg     = UART0 R/W (0b0)
UART_PRINT_CONTROL (BLOCK0)                        Sets the default UART boot message output mode     = Enabled R/W (0b00)
FORCE_SEND_RESUME (BLOCK0)                         Force ROM code to send a resume command during SPI = False R/W (0b0)
                                                    bootduring SPI boot                              
BLOCK_USR_DATA (BLOCK3)                            User data                                         
   = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 R/W 

Efuse fuses:
WR_DIS (BLOCK0)                                    Disables programming of individual eFuses          = 0 R/W (0x00000000)
RD_DIS (BLOCK0)                                    Disables software reading from BLOCK4-10           = 0 R/W (0b0000000)

Flash Config fuses:
FLASH_TPUW (BLOCK0)                                Configures flash startup delay after SoC power-up, = 0 R/W (0x0)
                                                    unit is (ms/2). When the value is 15, delay is 7.
                                                   5 ms                                              
FLASH_ECC_MODE (BLOCK0)                            Set this bit to set flsah ecc mode.               
   = flash ecc 16to18 byte mode R/W (0b0)
FLASH_TYPE (BLOCK0)                                Selects SPI flash type                             = 4 data lines R/W (0b0)
FLASH_PAGE_SIZE (BLOCK0)                           Flash page size                                    = 0 R/W (0b00)
FLASH_ECC_EN (BLOCK0)                              Enable ECC for flash boot                          = False R/W (0b0)

Identity fuses:
SECURE_VERSION (BLOCK0)                            Secure version (used by ESP-IDF anti-rollback feat = 0 R/W (0x0000)
                                                   ure)                                              
MAC (BLOCK1)                                       Factory MAC Address                               
   = 7c:df:a1:61:bd:20 (OK) R/W 
WAFER_VERSION (BLOCK1)                             WAFER version                                      = 3 R/W (0b011)
PKG_VERSION (BLOCK1)                               Package version                                    = ESP32-C3 R/W (0b000)
BLOCK1_VERSION (BLOCK1)                            BLOCK1 efuse version                               = 4 R/W (0b100)
OPTIONAL_UNIQUE_ID (BLOCK2)                        Optional unique 128-bit ID                        
   = a6 22 f8 ea 75 8e 71 7c ac d6 4c 9c b5 13 80 11 R/W 
BLOCK2_VERSION (BLOCK2)                            Version of BLOCK2                                  = With calibration R/W (0b001)
CUSTOM_MAC (BLOCK3)                                Custom MAC Address                                
   = 00:00:00:00:00:00 (OK) R/W 

Jtag Config fuses:
JTAG_SEL_ENABLE (BLOCK0)                          
### 不同之处概述 ESP32-C3ESP32 是 Espressif 推出的两款基于不同架构设计的微控制器芯片。尽管两者都属于物联网设备的核心组件,但在硬件特性、性能以及应用场景上存在显著差异。 #### 处理器架构 ESP32 使用的是双核 Xtensa LX6 微处理器架构[^4],而 ESP32-C3 则采用了单核 RISC-V 架构。这种架构的变化使得 C3 更加适合低功耗场景下的应用开发,同时也简化了软件生态系统的复杂度[^1]。 #### 存储加密支持 对于安全性需求较高的项目来说,存储机制的安全性至关重要。根据已知资料,在 ESP32 中闪存加密密钥能够被保存于特定 efuse block 当中;然而具体到 ESP32-S3 的情况,则其 flash encryption key 及 secure boot public key digest 仅限于某些固定区块如 BLOCK_KEY0 至 BLOCK_KEY4 范围内存放[^3]。虽然这里提到的信息针对 S3 版本,但从侧面反映出相比传统型号(比如标准版 ESP32),后续产品线可能进一步增强了安全特性的灵活性配置选项或者有所调整优化策略来满足日益增长的数据保护要求趋势——这暗示即使同样是 esp 系列成员之间也可能因为各自定位侧重方向各异而导致实现细节方面存在一定区别对待现象发生可能性较大一些吧? #### Wi-Fi/BT 功能集对比分析 从无线通信能力角度来看待这两款器件的话我们可以发现如下几点主要差别所在: - **Wi-Fi 协议兼容性**: ESP32 支持 IEEE 802.11 b/g/n 模式操作并且具备 station/AP dual mode 同时运行的能力; 相反地讲,C系列目前仅仅提供了基础 level 的station功能而已(即只允许作为客户端连接至外部网络热点而不可以直接充当路由器角色向其他设备提供接入服务). - **蓝牙规格定义范围扩展程度比较结果表明** :前者除了经典 Bluetooth Classic 连接方式之外还额外增加了 BLE (Bluetooth Low Energy) 技术的支持以便更好地服务于可穿戴电子类产品市场领域的需求特点考虑进去之后再做决定会更加明智合理些哦! 以下是部分代码示例展示如何初始化两个平台各自的WiFi模块: ```c /* 初始化 ESP32 WiFi */ void init_wifi_esp32() { tcpip_adapter_init(); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); esp_wifi_init(&cfg); } /* 初始化 ESP32-C3 WiFi */ void init_wifi_c3() { nvs_flash_init(); esp_netif_init(); esp_event_loop_create_default(); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); esp_wifi_init(&cfg); } ``` ### 性能参数总结表 | 参数 | ESP32 | ESP32-C3 | |-----------------|--------------------------|-------------------------| | CPU Core | Dual-Core Xtensa | Single-Core RISC-V | | Clock Speed | Up to 240 MHz | Fixed at 160 MHz | | RAM Size | ~520 KB | ~384 KB | | Flash Support | Yes | Yes |
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值