Chip used: ESP32S3
SDK version (run git describe --tags to find it):esp-idf-v5.1.2
I'm having some issues with an OTA update using BLE.
The code is
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!");
}
}
When the upgrade is completed, the status read by the esp_ota_get_state_partition is always ESP_OTA_IMG_NEW.
I try to restart the board, the status is still ESP_OTA_IMG_NEW, and it will not become ESP_OTA_IMG_PENDING_VERIFY.
here is the log.
Code: Select all
I (1255) example:take_picture: ota_state = 0
I (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 = 400
I (1827315) GATTS_DEMO: update connection params status = 0, min_int = 16, max_int = 32,conn_int = 6,latency = 0, timeout = 500
I (1827475) GATTS_CTL: PROFILE_CTL_APP_ID , value len 2, value : 1
I (1827475) GATTS_CTL: notify enable
I (1827555) GATTS_DEMO: update connection params status = 0, min_int = 0, max_int = 0,conn_int = 24,latency = 0, timeout = 400
I (1828515) GATTS_CTL: ESP_GATTS_MTU_EVT, MTU 512
I (1828515) GATTS_OTA: ESP_GATTS_MTU_EVT, MTU 512
I (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 0x410000
I (1940325) GATTS_CTL: PROFILE_CTL_APP_ID , value len 2, value :
I (1940325) GATTS_CTL: PROFILE_CTL_APP_ID , value len 2, value : 4
I (1940325) GATTS_CTL: ======endota======
*************************** end ota here ***************************************
I (1940325) esp_image: segment 0: paddr=00410020 vaddr=3c090020 size=27398h (160664) map
I (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) map
I (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) map
I (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) map
I (1940445) esp_image: segment 4: paddr=004cbb10 vaddr=4037795c size=11b2ch ( 72492)
I (1940495) GATTS_CTL: Prepare to restart system!
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x3 (RTC_SW_SYS_RST),boot:0x2a (SPI_FAST_FLASH_BOOT)
Saved PC:0x40375af0
0x40375af0: 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:0xee
mode:DIO, clock div:1
load:0x3fce3818,len:0x19b0
load:0x403c9700,len:0x4
load:0x403c9704,len:0xda8
load:0x403cc700,len:0x31bc
SHA-256 comparison failed:
Calculated: 5bb68aa5c0be732672fdfbec268fc152901b31dc78855b9ea233aa551a156007
Expected: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Attempting to boot anyway...
entry 0x403c9934
I (44) boot: ESP-IDF HEAD-HASH-NOTFOUND 2nd stage bootloader
I (45) boot: compile time Apr 24 2024 09:36:06
I (45) boot: Multicore bootloader
I (49) boot: chip revision: v0.2
I (53) qio_mode: Enabling default flash chip QIO
I (58) boot.esp32s3: Boot SPI Speed : 80MHz
I (63) boot.esp32s3: SPI Mode : QIO
I (67) boot.esp32s3: SPI Flash Size : 8MB
I (72) boot: Enabling RNG early entropy source...
I (78) boot: Partition Table:
I (81) boot: ## Label Usage Type ST Offset Length
I (88) boot: 0 nvs WiFi data 01 02 00009000 00004000
I (96) boot: 1 otadata OTA data 01 00 0000d000 00002000
I (103) boot: 2 phy_init RF data 01 01 0000f000 00001000
I (111) boot: 3 factory factory app 00 00 00010000 00200000
I (118) boot: 4 ota_0 OTA app 00 10 00210000 00200000
I (126) boot: 5 ota_1 OTA app 00 11 00410000 00200000
I (134) boot: End of partition table
I (138) esp_image: segment 0: paddr=00410020 vaddr=3c090020 size=27398h (160664) map
I (146) esp_image: segment 1: paddr=004373c0 vaddr=3fc99500 size=052f4h ( 21236) load
I (156) esp_image: segment 2: paddr=0043c6bc vaddr=40374000 size=0395ch ( 14684) load
I (164) esp_image: segment 3: paddr=00440020 vaddr=42000020 size=8bae8h (572136) map
I (172) esp_image: segment 4: paddr=004cbb10 vaddr=4037795c size=11b2ch ( 72492) load
I (185) boot: Loaded app from partition at offset 0x410000
I (186) boot: Disabling RNG early entropy source...
I (203) cpu_start: Multicore app
I (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: 5
I (262) esp_psram: Found 8MB PSRAM device
I (266) esp_psram: Speed: 80MHz
I (270) cpu_start: Pro cpu up.
I (274) cpu_start: Starting app cpu, entry point is 0x403756d8
0x403756d8: call_start_cpu1 at D:/software/Espressif/frameworks/esp-idf-v5.1.2/components/esp_system/port/cpu_start.c:157
I (0) cpu_start: App cpu up.
I (733) esp_psram: SPI SRAM memory test OK
I (741) cpu_start: Pro cpu start user code
I (741) cpu_start: cpu freq: 240000000 Hz
I (742) cpu_start: Application information:
I (744) cpu_start: Project name: ESP32S3_1.0.4
I (750) cpu_start: App version: 1.0.4
I (755) cpu_start: Compile time: Apr 24 2024 10:38:42
I (761) cpu_start: ELF file SHA256: 5a0e055516ae9115...
Warning: checksum mismatch between flashed and built applications. Checksum of built application is 6cfae36c18f56361e51f9696459028e57db8226f7d2c9847981bcd4ee17ae2ff
I (767) cpu_start: ESP-IDF: HEAD-HASH-NOTFOUND
I (773) cpu_start: Min chip rev: v0.0
I (777) cpu_start: Max chip rev: v0.99
I (782) cpu_start: Chip rev: v0.2
I (787) heap_init: Initializing. RAM available for dynamic allocation:
I (794) heap_init: At 3FCA28C0 len 00046E50 (283 KiB): DRAM
I (800) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
I (807) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (813) heap_init: At 600FE010 len 00001FC8 (7 KiB): RTCRAM
I (820) esp_psram: Adding pool of 8192K of PSRAM memory to heap allocator
I (827) spi_flash: detected chip: gd
I (831) spi_flash: flash io: qio
I (835) sleep: Configure to isolate all GPIO pins in sleep state
I (842) sleep: Enable automatic switching of GPIO sleep configuration
I (849) coexist: coex firmware version: b6d5e8c
I (854) coexist: coexist rom version e7ae62f
I (859) app_start: Starting scheduler on CPU0
I (864) app_start: Starting scheduler on CPU1
I (864) main_task: Started on CPU0
I (874) esp_psram: Reserving pool of 32K of internal memory for DMA/internal allocations
I (884) main_task: Calling app_main()
I (884) gpio: GPIO[0]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (904) BLE_INIT: BT controller compile version [59725b5]
I (914) BLE_INIT: Bluetooth MAC: 48:27:e2:ec:6e:b2
I (914) phy_init: phy_version 620,ec7ec30,Sep 5 2023,13:49:13
I (964) GATTS_CTL: REGISTER_APP_EVT, status 0, app_id 0
I (964) GATTS_CTL: CREATE_SERVICE_EVT, status 0, service_handle 40
I (964) GATTS_CTL: SERVICE_START_EVT, status 0, service_handle 40
I (974) GATTS_CTL: ADD_CHAR_EVT, status 0, attr_handle 42, service_handle 40
I (974) GATTS_CTL: the gatts demo char length = 3
I (984) GATTS_CTL: prf_char[0] =11
I (984) GATTS_CTL: prf_char[1] =22
I (994) GATTS_CTL: prf_char[2] =33
I (994) GATTS_OTA: REGISTER_APP_EVT, status 0, app_id 1
I (1004) GATTS_CTL: ADD_DESCR_EVT, status 0, attr_handle 43, service_handle 40
I (1014) GATTS_OTA: CREATE_SERVICE_EVT, status 0, service_handle 44
I (1024) GATTS_OTA: SERVICE_START_EVT, status 0, service_handle 44
I (1024) GATTS_OTA: ADD_CHAR_EVT, status 0, attr_handle 46, service_handle 44
I (1034) GATTS_OTA: the gatts demo char length = 3
I (1034) GATTS_OTA: prf_char[0] =11
I (1044) GATTS_OTA: prf_char[1] =22
I (1044) GATTS_OTA: prf_char[2] =33
I (1054) GATTS_OTA: ADD_DESCR_EVT, status 0, attr_handle 47, service_handle 44
I (1064) s3 ll_cam: DMA Channel=0
I (1064) cam_hal: cam init ok
I (1064) sccb: pin_sda 4 pin_scl 5
I (1074) sccb: sccb_i2c_port=1
I (1084) camera: Detected camera at address=0x30
I (1084) camera: Detected OV2640 camera
I (1084) camera: Camera PID=0x26 VER=0x42 MIDL=0x7f MIDH=0xa2
I (1164) cam_hal: buffer_size: 16384, half_buffer_size: 1024, node_buffer_size: 1024, node_cnt: 16, total_cnt: 375
I (1164) cam_hal: Allocating 384000 Byte frame buffer in PSRAM
I (1174) cam_hal: cam config ok
I (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
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;
My code is based on the the manual to confirm the application version, but the status is always ESP_OTA_IMG_NEW, I can't enter the conditional judgment.
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();
}
}
}
How do I make the state to ESP_OTA_IMG_PENDING_VERIFY, or is it right to be ESP_OTA_IMG_NEW?
Can I write the judgment condition as "if (ota_state == ESP_OTA_IMG_PENDING_VERIFY || ota_state == ESP_OTA_IMG_NEW)"?