完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我用ESP32S3 开发板测试蓝牙OTA升级功能遇到了点问题。以下是升级代码
Code: Select all case ESP_GATTS_WRITE_EVT:if (descr_value == 0x0003){ ESP_LOGI(GATTS_TAG_CTL, "======beginota======"); // FIXME 在这里增加版本判断 update_partition = esp_ota_get_next_update_partition(NULL); assert(update_partition != NULL); ESP_LOGI(GATTS_TAG_CTL, "Writing to partition subtype %d at offset 0x%lx", update_partition->subtype, update_partition->address); err = esp_ota_begin(update_partition, OTA_WITH_SEQUENTIAL_WRITES, &update_handle); if (err != ESP_OK) { ESP_LOGE(GATTS_TAG_CTL, "esp_ota_begin failed (%s)", esp_err_to_name(err)); esp_ota_abort(update_handle); } else { uchUpdateFlag = UPD_START; uint16_t ulTemp = 0x0003; esp_ble_gatts_send_indicate(gatts_if, param->write.conn_id, param->write.handle, 2, (uint8_t *)&ulTemp, true); }}else if (descr_value == 0x0004){ uchUpdateFlag = UPD_END; ESP_LOGI(GATTS_TAG_CTL, "======endota======"); err = esp_ota_end(update_handle); if (err != ESP_OK) { if (err == ESP_ERR_OTA_VALIDATE_FAILED) { ESP_LOGE(GATTS_TAG_CTL, "Image validation failed, image is corrupted"); } ESP_LOGE(GATTS_TAG_CTL, "esp_ota_end failed (%s)!", esp_err_to_name(err)); } err = esp_ota_set_boot_partition(update_partition); if (err != ESP_OK) { ESP_LOGE(GATTS_TAG_CTL, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err)); } ESP_LOGI(GATTS_TAG_CTL, "Prepare to restart system!"); esp_restart();}if (uchUpdateFlag == UPD_START) { uint16_t length = param->write.len;//modify uint8_t to uint16_t when mtu larger than 255 // ESP_LOGI(GATTS_TAG, "ota-da ta = %d",length); err = esp_ota_write( update_handle, (const void *)param->write.value, length); if (err != ESP_OK) { uchUpdateFlag = UPD_ERR; esp_ota_abort(update_handle); ESP_LOGI(GATTS_TAG, "esp_ota_write error!"); }} 参数设置:开启回滚 Bootloader config -> Enable app rollback support 下面是日志Code: Select all I (1255) example:take_picture: ota_state = 0I (1826605) GATTS_CTL: ESP_GATTS_CONNECT_EVT, conn_id 0, remote 66:be:7f:b7:db:5d:I (1826605) GATTS_OTA: ESP_GATTS_CONNECT_EVT, conn_id 0, remote 66:be:7f:b7:db:5d:W (1826615) BT_L2CAP: l2cble_start_conn_update, the last connection update command still pending.I (1826985) GATTS_DEMO: update connection params status = 0, min_int = 16, max_int = 32,conn_int = 24,latency = 0, timeout = 400I (1827315) GATTS_DEMO: update connection params status = 0, min_int = 16, max_int = 32,conn_int = 6,latency = 0, timeout = 500I (1827475) GATTS_CTL: PROFILE_CTL_APP_ID , value len 2, value : 1I (1827475) GATTS_CTL: notify enableI (1827555) GATTS_DEMO: update connection params status = 0, min_int = 0, max_int = 0,conn_int = 24,latency = 0, timeout = 400I (1828515) GATTS_CTL: ESP_GATTS_MTU_EVT, MTU 512I (1828515) GATTS_OTA: ESP_GATTS_MTU_EVT, MTU 512I (1830465) GATTS_CTL: PROFILE_CTL_APP_ID , value len 2, value :I (1830465) GATTS_CTL: PROFILE_CTL_APP_ID , value len 2, value : 3*************************** begin ota here ***************************************I (1830465) GATTS_CTL: ======beginota======I (1830475) GATTS_CTL: Writing to partition subtype 17 at offset 0x410000I (1940325) GATTS_CTL: PROFILE_CTL_APP_ID , value len 2, value :I (1940325) GATTS_CTL: PROFILE_CTL_APP_ID , value len 2, value : 4I (1940325) GATTS_CTL: ======endota======*************************** end ota here ***************************************I (1940325) esp_image: segment 0: paddr=00410020 vaddr=3c090020 size=27398h (160664) mapI (1940345) esp_image: segment 1: paddr=004373c0 vaddr=3fc99500 size=052f4h ( 21236)I (1940345) esp_image: segment 2: paddr=0043c6bc vaddr=40374000 size=0395ch ( 14684)I (1940355) esp_image: segment 3: paddr=00440020 vaddr=42000020 size=8bae8h (572136) mapI (1940385) esp_image: segment 4: paddr=004cbb10 vaddr=4037795c size=11b2ch ( 72492)I (1940395) esp_image: segment 0: paddr=00410020 vaddr=3c090020 size=27398h (160664) mapI (1940395) esp_image: segment 1: paddr=004373c0 vaddr=3fc99500 size=052f4h ( 21236)I (1940405) esp_image: segment 2: paddr=0043c6bc vaddr=40374000 size=0395ch ( 14684)I (1940415) esp_image: segment 3: paddr=00440020 vaddr=42000020 size=8bae8h (572136) mapI (1940445) esp_image: segment 4: paddr=004cbb10 vaddr=4037795c size=11b2ch ( 72492)I (1940495) GATTS_CTL: Prepare to restart system!ESP-ROM:esp32s3-20210327Build:Mar 27 2021rst:0x3 (RTC_SW_SYS_RST),boot:0x2a (SPI_FAST_FLASH_BOOT)Saved PC:0x40375af00x40375af0: esp_restart_noos_dig at D:/software/Espressif/frameworks/esp-idf-v5.1.2/components/esp_system/port/esp_system_chip.c:57 (discriminator 1)SPIWP:0xeemode:DIO, clock div:1load:0x3fce3818,len:0x19b0load:0x403c9700,len:0x4load:0x403c9704,len:0xda8load:0x403cc700,len:0x31bcSHA-256 comparison failed:Calculated: 5bb68aa5c0be732672fdfbec268fc152901b31dc78855b9ea233aa551a156007Expected: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffAttempting to boot anyway...entry 0x403c9934I (44) boot: ESP-IDF HEAD-HASH-NOTFOUND 2nd stage bootloaderI (45) boot: compile time Apr 24 2024 09:36:06I (45) boot: Multicore bootloaderI (49) boot: chip revision: v0.2I (53) qio_mode: Enabling default flash chip QIOI (58) boot.esp32s3: Boot SPI Speed : 80MHzI (63) boot.esp32s3: SPI Mode : QIOI (67) boot.esp32s3: SPI Flash Size : 8MBI (72) boot: Enabling RNG early entropy source...I (78) boot: Partition Table:I (81) boot: ## Label Usage Type ST Offset LengthI (88) boot: 0 nvs WiFi data 01 02 00009000 00004000I (96) boot: 1 otadata OTA data 01 00 0000d000 00002000I (103) boot: 2 phy_init RF data 01 01 0000f000 00001000I (111) boot: 3 factory factory app 00 00 00010000 00200000I (118) boot: 4 ota_0 OTA app 00 10 00210000 00200000I (126) boot: 5 ota_1 OTA app 00 11 00410000 00200000I (134) boot: End of partition tableI (138) esp_image: segment 0: paddr=00410020 vaddr=3c090020 size=27398h (160664) mapI (146) esp_image: segment 1: paddr=004373c0 vaddr=3fc99500 size=052f4h ( 21236) loadI (156) esp_image: segment 2: paddr=0043c6bc vaddr=40374000 size=0395ch ( 14684) loadI (164) esp_image: segment 3: paddr=00440020 vaddr=42000020 size=8bae8h (572136) mapI (172) esp_image: segment 4: paddr=004cbb10 vaddr=4037795c size=11b2ch ( 72492) loadI (185) boot: Loaded app from partition at offset 0x410000I (186) boot: Disabling RNG early entropy source...I (203) cpu_start: Multicore appI (203) octal_psram: vendor id : 0x0d (AP)I (204) octal_psram: dev id : 0x02 (generation 3)I (207) octal_psram: density : 0x03 (64 Mbit)I (212) octal_psram: good-die : 0x01 (Pass)I (217) octal_psram: Latency : 0x01 (Fixed)I (223) octal_psram: VCC : 0x01 (3V)I (228) octal_psram: SRF : 0x01 (Fast Refresh)I (234) octal_psram: BurstType : 0x01 (Hybrid Wrap)I (239) octal_psram: BurstLen : 0x01 (32 Byte)I (245) octal_psram: Readlatency : 0x02 (10 cycles@Fixed)I (251) octal_psram: DriveStrength: 0x00 (1/1)I (257) MSPI Timing: PSRAM timing tuning index: 5I (262) esp_psram: Found 8MB PSRAM deviceI (266) esp_psram: Speed: 80MHzI (270) cpu_start: Pro cpu up.I (274) cpu_start: Starting app cpu, entry point is 0x403756d80x403756d8: call_start_cpu1 at D:/software/Espressif/frameworks/esp-idf-v5.1.2/components/esp_system/port/cpu_start.c:157I (0) cpu_start: App cpu up.I (733) esp_psram: SPI SRAM memory test OKI (741) cpu_start: Pro cpu start user codeI (741) cpu_start: cpu freq: 240000000 HzI (742) cpu_start: Application information:I (744) cpu_start: Project name: ESP32S3_1.0.4I (750) cpu_start: App version: 1.0.4I (755) cpu_start: Compile time: Apr 24 2024 10:38:42I (761) cpu_start: ELF file SHA256: 5a0e055516ae9115...Warning: checksum mismatch between flashed and built applications. Checksum of built application is 6cfae36c18f56361e51f9696459028e57db8226f7d2c9847981bcd4ee17ae2ffI (767) cpu_start: ESP-IDF: HEAD-HASH-NOTFOUNDI (773) cpu_start: Min chip rev: v0.0I (777) cpu_start: Max chip rev: v0.99I (782) cpu_start: Chip rev: v0.2I (787) heap_init: Initializing. RAM available for dynamic allocation:I (794) heap_init: At 3FCA28C0 len 00046E50 (283 KiB): DRAMI (800) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAMI (807) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAMI (813) heap_init: At 600FE010 len 00001FC8 (7 KiB): RTCRAMI (820) esp_psram: Adding pool of 8192K of PSRAM memory to heap allocatorI (827) spi_flash: detected chip: gdI (831) spi_flash: flash io: qioI (835) sleep: Configure to isolate all GPIO pins in sleep stateI (842) sleep: Enable automatic switching of GPIO sleep configurationI (849) coexist: coex firmware version: b6d5e8cI (854) coexist: coexist rom version e7ae62fI (859) app_start: Starting scheduler on CPU0I (864) app_start: Starting scheduler on CPU1I (864) main_task: Started on CPU0I (874) esp_psram: Reserving pool of 32K of internal memory for DMA/internal allocationsI (884) main_task: Calling app_main()I (884) gpio: GPIO[0]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0I (904) BLE_INIT: BT controller compile version [59725b5]I (914) BLE_INIT: Bluetooth MAC: 48:27:e2:ec:6e:b2I (914) phy_init: phy_version 620,ec7ec30,Sep 5 2023,13:49:13I (964) GATTS_CTL: REGISTER_APP_EVT, status 0, app_id 0I (964) GATTS_CTL: CREATE_SERVICE_EVT, status 0, service_handle 40I (964) GATTS_CTL: SERVICE_START_EVT, status 0, service_handle 40I (974) GATTS_CTL: ADD_CHAR_EVT, status 0, attr_handle 42, service_handle 40I (974) GATTS_CTL: the gatts demo char length = 3I (984) GATTS_CTL: prf_char[0] =11I (984) GATTS_CTL: prf_char[1] =22I (994) GATTS_CTL: prf_char[2] =33I (994) GATTS_OTA: REGISTER_APP_EVT, status 0, app_id 1I (1004) GATTS_CTL: ADD_DESCR_EVT, status 0, attr_handle 43, service_handle 40I (1014) GATTS_OTA: CREATE_SERVICE_EVT, status 0, service_handle 44I (1024) GATTS_OTA: SERVICE_START_EVT, status 0, service_handle 44I (1024) GATTS_OTA: ADD_CHAR_EVT, status 0, attr_handle 46, service_handle 44I (1034) GATTS_OTA: the gatts demo char length = 3I (1034) GATTS_OTA: prf_char[0] =11I (1044) GATTS_OTA: prf_char[1] =22I (1044) GATTS_OTA: prf_char[2] =33I (1054) GATTS_OTA: ADD_DESCR_EVT, status 0, attr_handle 47, service_handle 44I (1064) s3 ll_cam: DMA Channel=0I (1064) cam_hal: cam init okI (1064) sccb: pin_sda 4 pin_scl 5I (1074) sccb: sccb_i2c_port=1I (1084) camera: Detected camera at address=0x30I (1084) camera: Detected OV2640 cameraI (1084) camera: Camera PID=0x26 VER=0x42 MIDL=0x7f MIDH=0xa2I (1164) cam_hal: buffer_size: 16384, half_buffer_size: 1024, node_buffer_size: 1024, node_cnt: 16, total_cnt: 375I (1164) cam_hal: Allocating 384000 Byte frame buffer in PSRAMI (1174) cam_hal: cam config okI (1174) ov2640: Set PLL: clk_2x: 0, clk_div: 0, pclk_auto: 0, pclk_div: 12*************************** print ota_state here ***************************************I (1254) example:take_picture: ota_state = 0 这个是对状态的定义 typedef enum { ESP_OTA_IMG_NEW = 0x0U, ESP_OTA_IMG_PENDING_VERIFY = 0x1U, ESP_OTA_IMG_VALID = 0x2U, ESP_OTA_IMG_INVALID = 0x3U, ESP_OTA_IMG_ABORTED = 0x4U, ESP_OTA_IMG_UNDEFINED = 0xFFFFFFFFU, } esp_ota_img_states_t; 手册上说升级完成后通过下面这个判断确认是否需要回滚版本。 Code: Select all const esp_partition_t *running = esp_ota_get_running_partition(); esp_ota_img_states_t ota_state; if (esp_ota_get_state_partition(running, &ota_state) == ESP_OK) { ESP_LOGI(TAG, "ota_state = %d", ota_state); if (ota_state == ESP_OTA_IMG_PENDING_VERIFY) { // run diagnostic function ... bool diagnostic_is_ok = false; if (diagnostic_is_ok) { ESP_LOGI(TAG, "Diagnostics completed successfully! Continuing execution ..."); esp_ota_mark_app_valid_cancel_rollback(); } else { ESP_LOGE(TAG, "Diagnostics failed! Start rollback to the previous version ..."); esp_ota_mark_app_invalid_rollback_and_reboot(); } } } 但是实际测试发现,升级完成后用esp_ota_get_state_partition获取到的状态一直是ESP_OTA_IMG_NEW(手册上说重启后bootloader会把标志位变成ESP_OTA_IMG_PENDING_VERIFY),所以一直进不去判断条件。手动重启过了也没用。 这个读取到的状态(和手册说的不一样)是对的吗? 我可以判断条件写成"if (ota_state == ESP_OTA_IMG_PENDING_VERIFY || ota_state == ESP_OTA_IMG_NEW)"吗? 有遇到过同样问题的吗?怎么解决的? |
|
相关推荐
1个回答
|
|
= NULL);
esp_err_t result = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &ota_handle); if (result != ESP_OK) { ESP_LOGE(GATTS_TAG_CTL, "OTA begin failed! error = %d", result); } else { ESP_LOGI(GATTS_TAG_CTL, "OTA begin succeeded"); } break; } case ESP_GATTS_WRITE_EVT: if (descr_value == 0x0003) { ESP_LOGI(GATTS_TAG_CTL, "======beginota======"); // FIXME 在这里增加版本判断 update_partition = esp_ota_get_next_update_partition(NULL); assert(update_partition != NULL); esp_err_t result = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &ota_handle); if (result != ESP_OK) { ESP_LOGE(GATTS_TAG_CTL, "OTA begin failed! error = %d", result); } else { ESP_LOGI(GATTS_TAG_CTL, "OTA begin succeeded"); } break; } case ESP_GATTS_WRITE_EVT: if (descr_value == 0x0004) { ESP_LOGI(GATTS_TAG_CTL, "======endota======"); esp_err_t result = esp_ota_end(ota_handle); if (result != ESP_OK) { ESP_LOGE(GATTS_TAG_CTL, "OTA end failed! error = %d", result); } else { ESP_LOGI(GATTS_TAG_CTL, "OTA end succeeded"); } break; } case ESP_GATTS_WRITE_EVT: if (descr_value == 0x0005) { ESP_LOGI(GATTS_TAG_CTL, "======setboot======"); esp_ota_set_boot_partition(update_partition); ESP_LOGI(GATTS_TAG_CTL, "Set OTA boot partition succeeded"); break; } default: break; } 这段代码主要实现了蓝牙OTA升级的开始、结束和设置启动分区的功能。你提到的问题是关于版本判断的部分。在代码中,有一个注释 // FIXME 在这里增加版本判断,这意味着你需要在这里添加版本判断的逻辑。 版本判断的目的是确保OTA升级只针对比当前设备上运行的版本更高的固件进行。以下是如何实现版本判断的示例: 1. 首先,你需要从OTA数据中获取新固件的版本信息。这通常在发送OTA数据时包含在数据包中。 2. 然后,将新固件的版本信息与设备当前运行的版本信息进行比较。设备当前运行的版本信息可以通过 `esp_ota_get_app_description()` 函数获取。 3. 如果新固件的版本高于当前运行的版本,则继续OTA升级过程;否则,终止OTA升级。 以下是添加版本判断的示例代码: ```c #include "esp_ota_ops.h" // ... case ESP_GATTS_WRITE_EVT: if (descr_value == 0x0003) { ESP_LOGI(GATTS_TAG_CTL, "======beginota======"); // 获取新固件的版本信息(假设已经从OTA数据中获取) const char *new_version = "新固件版本号"; // 获取当前运行的固件版本信息 const esp_app_desc_t *app_desc = esp_ota_get_app_description(); if (app_desc) { const char *current_version = app_desc->version; // 比较版本号 if (strcmp(new_version, current_version) > 0) { // 新固件版本高于当前版本,继续OTA升级 update_partition = esp_ota_get_next_update_partition(NULL); assert(update_partition != NULL); esp_err_t result = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &ota_handle); if (result != ESP_OK) { ESP_LOGE(GATTS_TAG_CTL, "OTA begin failed! error = %d", result); } else { ESP_LOGI(GATTS_TAG_CTL, "OTA begin succeeded"); } } else { ESP_LOGI(GATTS_TAG_CTL, "New firmware version is not higher than the current version"); } } else { ESP_LOGE(GATTS_TAG_CTL, "Failed to get app description"); } break; } ``` 请注意,你需要根据你的具体需求和OTA数据格式来调整上述示例代码。 |
|
|
|
只有小组成员才能发言,加入小组>>
598 浏览 1 评论
552浏览 6评论
461浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
443浏览 5评论
445浏览 4评论
415浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 05:35 , Processed in 0.738835 second(s), Total 82, Slave 65 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号