【ESP32之旅】ESP32 PlatformIO 固件单独烧录

背景

有时候使用PIO编写的代码需要发给客户去验证,相比较于发送源码直接发送bin文件,更加的安全而且高效。不用担心源码的泄漏,也不用帮客户配置PIO环境。

操作方法

1.编译

首先进行代码编译,如编译成功会在 .pio\build\airm2m_core_esp32c3目录下生成对应的编译产物

2.准备对应产物文件

编译生成的产物如下图所示,其实还缺少一个boot_app0.bin的二级boot跳转文件,此文件在esp32 sdk的安装目录下。小编的在如下所示路径中。可以参考此目录在自己电脑上找下:

shell 复制代码
C:\Users\songz\.platformio\packages\framework-arduinoespressif32\tools\partitions\boot_app0.bin

3.烧录

首先使用PIO进行一次烧录,查看下每个bin文件对应的地址分布,相应的地址分布如下图所示:

产物名 烧录地址
bootloader.bin 0x00000000
partitions.bin 0x00008000
boot_app0.bin 0x0000e000
firmware.bin 0x00010000

然后使用ESP32 Download tool进行烧录(Flash下载工具|乐鑫科技 (espressif.com))

后记

可能有的读者会好奇我是如何知道上面地址和产物的对应关系的,这是因为PIO烧录ESP32 归根结底也是依赖于ESP tool进行下载的,只是PIO隐藏了烧录过程中关于烧录产物和地址的相关输出,可以直接使用下面的命令在PIO终端中进行一次烧录即可看到相关的信息。

shell 复制代码
pio run -v -t upload

完整的日志如下:

shell 复制代码
PS E:\work\ESP32_BLE_Exit\ESP32_BLE_EXTI> pio run -v -t upload
Processing airm2m_core_esp32c3 (platform: espressif32; board: airm2m_core_esp32c3; framework: arduino; upload_speed: 1152000; upload_port: COM116; monitor_speed: 
115200; monitor_port: COM116)
------------------------------------------------------------------------------------------------------------------------------------------------------------------CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/airm2m_core_esp32c3.html
PLATFORM: Espressif 32 (6.0.1) > AirM2M CORE ESP32C3
HARDWARE: ESP32C3 160MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-builtin, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 @ 3.20006.221224 (2.0.6)
 - tool-esptoolpy @ 1.40400.0 (4.4.0)
 - tool-mkfatfs @ 2.0.1
 - tool-mklittlefs @ 1.203.210628 (2.3)
 - tool-mkspiffs @ 2.230.0 (2.30)
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 33 compatible libraries
Scanning dependencies...
Dependency Graph
|-- ESP32 BLE Arduino @ 2.0.0 (License: Unknown, Path: C:\Users\songz\.platformio\packages\framework-arduinoespressif32\libraries\BLE)
Building in release mode
<lambda>(["checkprogsize"], [".pio\build\airm2m_core_esp32c3\firmware.elf"])
MethodWrapper(["checkprogsize"], [".pio\build\airm2m_core_esp32c3\firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"       
RAM:   [=         ]  13.9% (used 45580 bytes from 327680 bytes)
Flash: [========= ]  87.2% (used 1143238 bytes from 1310720 bytes)
.pio\build\airm2m_core_esp32c3\firmware.elf  :

section                    size         addr

.rtc.text                    16   1342177280

.rtc.force_fast               0   1342177296

.rtc.data                    16   1342177296

.rtc_noinit                   0   1342177312

.rtc.force_slow               0   1342177312

.iram0.text               63518   1077411840

.dram0.dummy              64000   1070071808

.dram0.data               13980   1070135808

.noinit                       0   1070149788

.dram0.bss                31600   1070149792

.flash.text              879028   1107296288

.flash_rodata_dummy      917504   1006632992

.flash.appdesc              256   1007550496

.flash.rodata            186712   1007550752

.eh_frame                 81120   1007737464

.flash.rodata_noload          0   1007818584

.iram0.text_end             482   1077475358

.iram0.data                   0   1077475840

.iram0.bss                    0   1077475840

.dram0.heap_start             0   1070181392

.debug_info             9790248            0

.debug_abbrev            704014            0

.debug_loc              2036887            0

.debug_aranges            89984            0

.debug_ranges            246160            0

.debug_line             3289982            0

.debug_str              1500422            0

.comment                     93            0

.riscv.attributes            55            0

.debug_frame             206320            0

Total                  20102397
<lambda>(["upload"], [".pio\build\airm2m_core_esp32c3\firmware.bin"])
AVAILABLE: cmsis-dap, esp-bridge, esp-builtin, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
BeforeUpload(["upload"], [".pio\build\airm2m_core_esp32c3\firmware.bin"])
Using manually specified: COM116
"C:\Users\songz\.platformio\penv\Scripts\python.exe" "C:\Users\songz\.platformio\packages\tool-esptoolpy\esptool.py" --chip esp32c3 --port "COM116" --baud 1152000 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x0000 E:\work\ESP32_BLE_Exit\ESP32_BLE_EXTI\.pio\build\airm2m_core_esp32c3\bootloader.bin 0x8000 E:\work\ESP32_BLE_Exit\ESP32_BLE_EXTI\.pio\build\airm2m_core_esp32c3\partitions.bin 0xe000 C:\Users\songz\.platformio\packages\framework-arduinoespressif32\tools\partitions\boot_app0.bin 0x10000 .pio\build\airm2m_core_esp32c3\firmware.bin
esptool.py v4.4
Serial port COM116
Connecting....
Chip is ESP32-C3 (revision v0.3)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 60:55:f9:7b:b8:98
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 1152000
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00002fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x0013bfff...
Compressed 12144 bytes to 8814...
Writing at 0x00000000... (100 %)
Wrote 12144 bytes (8814 compressed) at 0x00000000 in 0.2 seconds (effective 422.4 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 146...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (146 compressed) at 0x00008000 in 0.0 seconds (effective 558.6 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 762.0 kbit/s)...
Hash of data verified.
Compressed 1224752 bytes to 637138...
Writing at 0x00010000... (2 %)
Writing at 0x0001bd8c... (5 %)
Writing at 0x00028c4b... (7 %)
Writing at 0x00035a14... (10 %)
Writing at 0x00042dc6... (12 %)
Writing at 0x00050725... (15 %)
Writing at 0x000581cf... (17 %)
Writing at 0x0005df3e... (20 %)
Writing at 0x0006417a... (23 %)
Writing at 0x0006adc0... (25 %)
Writing at 0x00071f47... (28 %)
Writing at 0x00077fc5... (30 %)
Writing at 0x0007ead3... (33 %)
Writing at 0x00085ea9... (35 %)
Writing at 0x0008c45c... (38 %)
Writing at 0x00092af1... (41 %)
Writing at 0x00098f5c... (43 %)
Writing at 0x0009ef42... (46 %)
Writing at 0x000a64ab... (48 %)
Writing at 0x000acd4d... (51 %)
Writing at 0x000b470b... (53 %)
Writing at 0x000baf62... (56 %)
Writing at 0x000c12bc... (58 %)
Writing at 0x000c8372... (61 %)
Writing at 0x000d0324... (64 %)
Writing at 0x000d881c... (66 %)
Writing at 0x000df2c9... (69 %)
Writing at 0x000e5bb3... (71 %)
Writing at 0x000ec6da... (74 %)
Writing at 0x000f2bdb... (76 %)
Writing at 0x000f8997... (79 %)
Writing at 0x000ff7c3... (82 %)
Writing at 0x001078f4... (84 %)
Writing at 0x0010fb59... (87 %)
Writing at 0x0011a658... (89 %)
Writing at 0x001209b6... (92 %)
Writing at 0x001270c7... (94 %)
Writing at 0x0012e3e9... (97 %)
Writing at 0x001359f6... (100 %)
Wrote 1224752 bytes (637138 compressed) at 0x00010000 in 17.1 seconds (effective 572.2 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
================================================================== [SUCCESS] Took 24.93 seconds ==================================================================
相关推荐
图映 图片处理7 小时前
浏览器本地压缩图片安全吗:基于网络请求与文件传输的验证方法
服务器·网络·安全
Techblog of HaoWANG7 小时前
具身智能机器人专题(4) Docker 实战
linux·运维·ubuntu·docker·容器·机器人·ollama
跨境猫小妹7 小时前
自动化点不到页面按钮,先查元素定位还是渲染时机
运维·自动化·跨境电商·营销策略
天远API8 小时前
零信任架构实战:基于天远单人婚姻查询构建自动化保障房准入审核网关
运维·人工智能·架构·自动化
RestCloud8 小时前
ETLCloud中不同表名之间的数据库数据同步
数据库·etl·数据处理·etlcloud·数据传输·数据集成平台
墨痕诉清风8 小时前
docker无法pull镜像问题解决
运维·docker·容器
DeskUI~~9 小时前
8.4M,我把 Linux 变成了一块“磁盘”
linux·运维·服务器
少陽君9 小时前
如何在 PVE 中下载并导入 Ubuntu 24.04 Server 云镜像
linux·数据库·ubuntu
无足鸟ICT9 小时前
【RHCA+】_proc_pid_environ
linux·运维·服务器
智购科技无人售货机工厂店9 小时前
自动售货机振动与运输可靠性测试实战:跌落、振动与包装~YH
java·大数据·服务器·人工智能·科技