接前一篇文章:ESP32-C3模组上跑通OTA升级(10)
本文内容参考:
《ESP3-C3 物联网工程开发实战》 乐鑫科技
特此致谢!
上一回说到解决了证书验证的问题,但紧接着又出现了一个新的问题:版本相同无法升级。本回就来讲解一下这个问题如何解决,并也给出正常OTA的显示。
八、程序调试过程中遇到的问题及解决
2. Current running version is the same as a new. We will not continue the update.问题
详细的问题log如下:
I (22596) esp_https_ota: Starting OTA...
I (22596) esp_https_ota: Writing to partition subtype 17 at offset 0x190000
I (22596) Wi-Fi Module: Reading Image Description
I (22606) Wi-Fi Module: Running firmware version: 1
W (22616) Wi-Fi Module: Current running version is the same as a new. We will not continue the update.
E (22626) Wi-Fi Module: image header verification failed
I (22626) Wi-Fi Module: OTA abort
E (22636) Wi-Fi Module: ESP_HTTPS_OTA upgrade failed
之所以会出现这个问题,是因为笔者之前在之前研究固件版本管理的时候(参见ESP32-C3模组上跑通OTA升级(8)-CSDN博客),在menuconfig中进行了设置,如下图所示:
制作升级文件的时候,也忘记把它去掉了。
笔者尝试了以下解决方法:
(1)在menuconfig中去掉以上选项
如下图所示:
保存退出,编译并运行。结果发现问题依旧,这个方法行不通。
(2)配置menuconfig,OTA时不进行版本检查
经过代码定位,发现以上提示信息出自于main\advanced_https_ota_example.c的validate_image_header函数中,代码片段如下:
#ifndef CONFIG_EXAMPLE_SKIP_VERSION_CHECKif (memcmp(new_app_info->version, running_app_info.version, sizeof(new_app_info->version)) == 0) {ESP_LOGW(TAG, "Current running version is the same as a new. We will not continue the update.");return ESP_FAIL;}
#endif
可以看到,版本检查时通过宏CONFIG_EXAMPLE_SKIP_VERSION_CHECK控制的。这个宏对应到menuconfig中是如下配置项:
将“Skip firmware version check”项设置为“*”即选中:
保存退出,编译并运行。结果发现是可以正常升级的,此方法行得通。
(3)将固件版本修改为不同值
本方法既无须选中“Skip fireware version check”项,也无须不勾选“Get the project version from Kconfig”项,而是将固件版本修改为不同值。如下所示:
或者
保存退出,编译并运行。结果发现是可以正常升级的,此方法也行得通。
接下来,看一下最终成功进行OTA的完整过程。完整的log如下:
……
I (10776) Wi-Fi Module: OTA started
W (10776) esp_https_ota: Continuing with insecure option because CONFIG_ESP_HTTPS_OTA_ALLOW_HTTP is set.
I (11676) Wi-Fi Module: Connected to server
I (11676) esp_https_ota: Starting OTA...
I (11676) esp_https_ota: Writing to partition subtype 17 at offset 0x190000
I (11686) Wi-Fi Module: Reading Image Description
I (11876) Wi-Fi Module: Running firmware version: 0
I (11876) Wi-Fi Module: Verifying chip id of new image: 5
I (19926) esp_image: segment 0: paddr=00190020 vaddr=3c020020 size=0b580h ( 46464) map
I (19936) esp_image: segment 1: paddr=0019b5a8 vaddr=3fc8c800 size=0128ch ( 4748)
I (19936) esp_image: segment 2: paddr=0019c83c vaddr=40380000 size=037dch ( 14300)
I (19946) esp_image: segment 3: paddr=001a0020 vaddr=42000020 size=1ec5ch (126044) map
I (19966) esp_image: segment 4: paddr=001bec84 vaddr=403837dc size=08f20h ( 36640)
I (19976) esp_image: segment 0: paddr=00190020 vaddr=3c020020 size=0b580h ( 46464) map
I (19986) esp_image: segment 1: paddr=0019b5a8 vaddr=3fc8c800 size=0128ch ( 4748)
I (19986) esp_image: segment 2: paddr=0019c83c vaddr=40380000 size=037dch ( 14300)
I (19996) esp_image: segment 3: paddr=001a0020 vaddr=42000020 size=1ec5ch (126044) map
I (20016) esp_image: segment 4: paddr=001bec84 vaddr=403837dc size=08f20h ( 36640)
I (20096) Wi-Fi Module: Boot partition updated. Next Partition: 17
I (20096) Wi-Fi Module: OTA finish
I (20096) Wi-Fi Module: ESP_HTTPS_OTA upgrade successful. Rebooting ...
I (21096) wifi:state: run -> init (0)
I (21096) wifi:pm stop, total sleep time: 940136 us / 17407619 usI (21096) wifi:<ba-del>idx:0, tid:0
I (21096) wifi:new:<1,0>, old:<1,1>, ap:<255,255>, sta:<1,1>, prof:1
E (21106) transport_base: poll_read select error 113, errno = Software caused connection abort, fd = 54
E (21106) mqtt_client: Poll read error: 119, aborting connection
I (21116) wifi:flush txq
I (21116) wifi:stop sw txq
I (21116) wifi:lmac stop hw txq
I (21126) Wi-Fi Module: MQTT_EVENT_DISCONNECTED
I (21126) wifi:Deinit lldesc rx mblock:10
ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0xc (RTC_SW_CPU_RST),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x403806bc
0x403806bc: esp_restart_noos at C:/Espressif/frameworks/esp-idf-v5.2.1/components/esp_system/port/soc/esp32c3/system_internal.c:111SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5820,len:0x1738
load:0x403cc710,len:0xb9c
load:0x403ce710,len:0x2e40
entry 0x403cc71a
I (35) boot: ESP-IDF v5.2.1-dirty 2nd stage bootloader
I (35) boot: compile time Jun 1 2024 13:49:40
I (35) boot: chip revision: v0.4
I (39) boot.esp32c3: SPI Speed : 80MHz
I (43) boot.esp32c3: SPI Mode : DIO
I (48) boot.esp32c3: SPI Flash Size : 4MB
I (53) boot: Enabling RNG early entropy source...
I (58) boot: Partition Table:
I (62) boot: ## Label Usage Type ST Offset Length
I (69) boot: 0 nvs WiFi data 01 02 00009000 00004000
I (77) boot: 1 otadata OTA data 01 00 0000d000 00002000
I (84) boot: 2 phy_init RF data 01 01 0000f000 00001000
I (91) boot: 3 ota_0 OTA app 00 10 00010000 00180000
I (99) boot: 4 ota_1 OTA app 00 11 00190000 00180000
I (106) boot: 5 nvs_2 WiFi data 01 02 00310000 0004b000
I (114) boot: End of partition table
I (118) esp_image: segment 0: paddr=00190020 vaddr=3c020020 size=0b580h ( 46464) map
I (134) esp_image: segment 1: paddr=0019b5a8 vaddr=3fc8c800 size=0128ch ( 4748) load
I (136) esp_image: segment 2: paddr=0019c83c vaddr=40380000 size=037dch ( 14300) load
I (146) esp_image: segment 3: paddr=001a0020 vaddr=42000020 size=1ec5ch (126044) map
I (172) esp_image: segment 4: paddr=001bec84 vaddr=403837dc size=08f20h ( 36640) load
I (183) boot: Loaded app from partition at offset 0x190000
I (183) boot: Disabling RNG early entropy source...
I (194) cpu_start: Unicore app
I (203) cpu_start: Pro cpu start user code
I (203) cpu_start: cpu freq: 160000000 Hz
I (203) cpu_start: Application information:
I (206) cpu_start: Project name: Wi-Fi_InterMediator
I (212) cpu_start: App version: 1
I (216) cpu_start: Compile time: May 31 2024 09:08:42
I (222) cpu_start: ELF file SHA256: 19a43d3f1...
Warning: checksum mismatch between flashed and built applications. Checksum of built application is 5613e903b84aab210bbe7593a85bec2bcddb198640f2b72ae57a5d604852e29e
I (228) cpu_start: ESP-IDF: v5.2.1-dirty
I (233) cpu_start: Min chip rev: v0.3
I (238) cpu_start: Max chip rev: v1.99
I (243) cpu_start: Chip rev: v0.4
I (248) heap_init: Initializing. RAM available for dynamic allocation:
I (255) heap_init: At 3FC8EA40 len 000315C0 (197 KiB): RAM
I (261) heap_init: At 3FCC0000 len 0001C710 (113 KiB): Retention RAM
I (268) heap_init: At 3FCDC710 len 00002950 (10 KiB): Retention RAM
I (275) heap_init: At 50000010 len 00001FD8 (7 KiB): RTCRAM
I (282) spi_flash: detected chip: generic
I (286) spi_flash: flash io: dio
I (290) sleep: Configure to isolate all GPIO pins in sleep state
I (296) sleep: Enable automatic switching of GPIO sleep configuration
I (304) main_task: Started on CPU0
I (304) main_task: Calling app_main()
I (304) Wi-Fi Module: OTA example app_main start
uart_resp_data is: report event 0
这里要特别说明一下。网上也有很多博客给出了OTA的log,但是都没有动态地即描述。在这里笔者更为深入地描述一下过程。
从收到升级命令开始(打印输出“OTA Started”)到“Verify chip id of new image”这一段很快。
但是“Verify chip id of new image”这一个动作停顿时间较长,在笔者这里是20秒左右,之后再往下进行(从上边log中的时间戳上也能看出来)。接下来就是:
准备重启了。重启的同时MQTT任务也会出现中止的提示,链接也会断开。
接下来就差不多该启动的log输出了:
这就是完整且正常的OTA过程。
至此,本系列(ESP32-C3模组上跑通OTA升级)的内容就全部讲完了。