由 Arduino IDE 执行的 ESP32 闪存命令似乎闪存了两个引导加载程序文件:boot_app0.bin
在偏移量 0xe000
和 bootloader_dio_80m.bin
在偏移 0x1000
处。我想知道这两个引导加载程序文件实际上做了什么,为什么会有两个。下面我给出一些更多的信息。
1。语境
我所在的团队正在为微 Controller 开发全新的免费 IDE:Embeetle IDE。我们计划在不久的将来支持 ESP32 微 Controller 系列。因此,我现在正在研究 ESP32 构建系统 - ESP-IDF
工具和用于 ESP32 项目的 Arduino IDE 方法。
2。 ESP32项目的Arduino IDE flash程序
构建.elf
文件后,Arduino IDE 启动命令将其转换为二进制文件:
python esptool.py --chip esp32 elf2image
--flash_mode dio
--flash_freq 80m
--flash_size 4MB
-o /tmp/arduino_build_852524/WiFiScan.ino.bin
/tmp/arduino_build_852524/WiFiScan.ino.elf
最后,这个 WiFiScan.ino.bin
文件连同两个引导加载程序文件和分区表被闪存到电路板:
python esptool.py --chip esp32
--port /dev/ttyUSB0
--baud 921600
--before default_reset
--after hard_reset write_flash
-z
--flash_mode dio
--flash_freq 80m
--flash_size detect
0xe000 ~/.arduino15/packages/esp32/hardware/esp32/1.0.6/tools/partitions/boot_app0.bin
0x1000 ~/.arduino15/packages/esp32/hardware/esp32/1.0.6/tools/sdk/bin/bootloader_dio_80m.bin
0x10000 /tmp/arduino_build_852524/WiFiScan.ino.bin
0x8000 /tmp/arduino_build_852524/WiFiScan.ino.partitions.bin
Arduino IDE 使用的默认分区表如下所示(csv 格式):
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x140000,
app1, app, ota_1, 0x150000,0x140000,
spiffs, data, spiffs, 0x290000,0x170000,
此 csv 文件的二进制等价物被闪存到地址 0x8000
。还有两个引导加载程序文件分别被闪存到地址 0xe000
和 0x1000
(见下一段)。
3。 Bootstrap 文件
正在刷新的两个引导加载程序文件是:
# flashed at 0xe000
~/.arduino15/packages/esp32/hardware/esp32/1.0.6/tools/partitions/boot_app0.bin
和:
# flashed at 0x1000
~/.arduino15/packages/esp32/hardware/esp32/1.0.6/tools/sdk/bin/bootloader_dio_80m.bin
Question 1: What do these two bootloader files do?
观察它们的位置也很有趣。第一个 boot_app0.bin
位于名为 'partitions'
的文件夹中。它位于多个分区 .csv
文件旁边。为什么?但也许当问题 1 得到回答时,这一点就会变得清楚。
另一个,bootloader_dio_80m.bin
位于名为 'sdk/bin/'
的文件夹中,与其他名称以 开头的文件放在一起>'bootloader_'
前缀:
Question 2: As for the bootloader file flashed at address
0x1000
, I think the'_40m'
and'_80m'
suffixes stand for the flash speed in MHz. But I've no idea what the'_dio'
,'_dout'
and'_qout'
suffixes stand for.
请赐教^_^
回答
感谢@Juraj,我现在对 ESP32 芯片的启动过程有了更深入的了解。我相信它看起来像这样:
第一阶段引导加载程序:
硬件连接的ROM-bootloader首先运行。第一阶段引导加载程序位于闪存之外,无法编程。它加载第二阶段引导加载程序(请参阅下一步)。SECOND STAGE BOOTLOADER:
第一阶段 ROM-bootloader 在地址0x1000< 加载第二阶段 ESP-IDF Software bootloader/
在 Flash 中。这里的代码是bootloader_dio_80m.bin
可执行文件,可以在ESP-IDF框架的components/bootloader
目录下找到。 第二阶段引导加载程序读取默认情况下在偏移量0x8000
处找到的分区表。如果在分区表中找到 OTA 应用程序分区,引导加载程序会查询ota_data
分区以确定应引导哪个分区。BOOT SWITCH
ota_data
部分可以认为只是一个开关,位于0xe000
在 Flash 中。它确定app0
或app1
是否应该启动。开关本身是boot_app0.bin
二进制文件。正如 Juraj 所说,2kB 大小还用于在 OTA 闪存期间做笔记。APPLICATION
app0
或app1
处的应用程序执行。
也感谢您向我指出这些资源:
最佳答案
0x1000 处的二进制文件是引导加载程序。 Arduino ESP32 具有与 Arduino IDE(从 boards.txt 构建)中工具菜单中的板选项对应的引导加载程序二进制文件。
引导加载程序功能已记录 here .
The ESP-IDF Software Bootloader performs the following functions:
- Minimal initial configuration of internal modules;
- Initialize Flash Encryption and/or Secure features, if configured;
- Select the application partition to boot, based on the partition table and ota_data (if any);
- Load this image to RAM (IRAM & DRAM) and transfer management to it.
boot_app0.bin是OTA数据分区的初始内容。已记录 here .
The OTA data partition is two flash sectors (0x2000 bytes) in size, to prevent problems if there is a power failure while it is being written. Sectors are independently erased and written with matching data, and if they disagree a counter field is used to determine which sector was written more recently.
DIO、QIO、DOUT、QOUT 是闪存的 SPI 模式。不同的esp32模块有不同的闪存芯片和它们的连接。 (D是双倍的,Q是四倍的)
关于arduino - boot_app0.bin 和 bootloader_dio_80m.bin 文件有什么用? (ESP32-Arduino 集成开发环境),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67149410/