ESP32C3 invalid segment length

ushank
Posts: 1
Joined: Wed May 25, 2022 12:41 am

ESP32C3 invalid segment length

Postby ushank » Wed May 25, 2022 1:05 am

I All,

I am developing an application on ESP32C3 platform and I am using VSCODE as the IDE. When the application reaches a certain code size, the bootloader can not verify the segment header. Debug message is shown below. My code is nowhere near the flash size.
The reason for the failures is that the last segment has an invalid length. The last two bits of the length filed must be zero as per bootloader code (attached below). If I reduce the size of my code (by commenting on a part of the code) the last segment is not created and working fine. Why does IDF create a flash image that is rejected by the bootloader?
is this a know bug?

I (53) boot: ESP-IDF v4.4.1 2nd stage bootloader
I (53) boot: compile time 18:15:13
I (53) boot: chip revision: 3
I (55) boot.esp32c3: SPI Speed : 80MHz
I (60) boot.esp32c3: SPI Mode : DIO
I (65) boot.esp32c3: SPI Flash Size : 4MB
I (69) boot: Enabling RNG early entropy source...
I (75) boot: Partition Table:
I (78) boot: ## Label Usage Type ST Offset Length
I (86) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (93) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (101) boot: 2 factory factory app 00 00 00010000 00100000
I (108) boot: End of partition table
I (112) esp_image: segment 0: paddr=00010020 vaddr=3c020020 size=09c68h ( 40040) map
I (127) esp_image: segment 1: paddr=00019c90 vaddr=3fc8aa00 size=0159ch ( 5532) load
I (130) esp_image: segment 2: paddr=0001b234 vaddr=40380000 size=04de4h ( 19940) load
I (141) esp_image: segment 3: paddr=00020020 vaddr=42000020 size=1ad8ch (109964) map
I (163) esp_image: segment 4: paddr=0003adb4 vaddr=40384de4 size=05a50h ( 23120) load
I (168) esp_image: segment 5: paddr=0004080c vaddr=50000010 size=00010h ( 16) load

E (169) esp_image: invalid segment length 0x1a57e
E (175) boot: Factory app partition is not bootable
E (180) boot: No bootable app partitions in the partition table

  1. static esp_err_t verify_segment_header(int index, const esp_image_segment_header_t *segment, uint32_t segment_data_offs, bool silent)
  2. {
  3.     if ((segment->data_len & 3) != 0
  4.             || segment->data_len >= SIXTEEN_MB) {
  5.         if (!silent) {
  6.             ESP_LOGE(TAG, "invalid segment length 0x%x", segment->data_len);
  7.         }
  8.         return ESP_ERR_IMAGE_INVALID;
  9.     }
  10.  
  11.     uint32_t load_addr = segment->load_addr;
  12.     bool map_segment = should_map(load_addr);
  13.  
  14.     /* Check that flash cache mapped segment aligns correctly from flash to its mapped address,
  15.        relative to the 64KB page mapping size.
  16.     */
  17.     ESP_LOGV(TAG, "segment %d map_segment %d segment_data_offs 0x%x load_addr 0x%x",
  18.              index, map_segment, segment_data_offs, load_addr);
  19.     if (map_segment
  20.             && ((segment_data_offs % SPI_FLASH_MMU_PAGE_SIZE) != (load_addr % SPI_FLASH_MMU_PAGE_SIZE))) {
  21.         if (!silent) {
  22.             ESP_LOGE(TAG, "Segment %d load address 0x%08x, doesn't match data 0x%08x",
  23.                      index, load_addr, segment_data_offs);
  24.         }
  25.         return ESP_ERR_IMAGE_INVALID;
  26.     }
  27.  
  28.     return ESP_OK;
  29. }

Who is online

Users browsing this forum: awegel and 111 guests