Skip to content

Large .text segments are merged incorrectly? #552

Closed
@t-moe

Description

@t-moe

I'm using a esp32c6 here with 8MB of flash and I have a rust program that is around 2 Mb, based on the esp-idf-* crates.

My partition table:

# ESP-IDF Partition Table
# Name,    Type, SubType, Offset,  Size, Flags
nvs,       data, nvs,     0x9000,  0x6000,
phy_init,  data, phy,     0xf000,  0x1000,
factory,   app,  factory, 0x10000, 4M,
Output of riscv32-esp-elf-objdump -h

target/riscv32imac-esp-espidf/debug/esp32_devkit:     file format elf32-littleriscv

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .rtc.text     00000000  50000000  50000000  0020a560  2**0
                  CONTENTS
  1 .rtc.force_fast 00000000  50000000  50000000  0020a560  2**0
                  CONTENTS
  2 .rtc_noinit   00000000  50000000  50000000  0020a560  2**0
                  CONTENTS
  3 .rtc.force_slow 00000000  50000000  50000000  0020a560  2**0
                  CONTENTS
  4 .rtc_reserved 00000018  50003fe8  50003fe8  0020afe8  2**3
                  ALLOC
  5 .iram0.text   0000c84e  40800000  40800000  00001000  2**8
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  6 .iram0.text_end 00000000  4080c84e  4080c84e  0020a560  2**0
                  CONTENTS
  7 .iram0.data   00000002  4080c84e  4080c84e  0000d84e  2**0
                  ALLOC
  8 .iram0.bss    00000000  4080c850  4080c850  0020a560  2**0
                  CONTENTS
  9 .dram0.dummy  0000c850  40800000  40800000  0000e000  2**0
                  ALLOC
 10 .dram0.data   00001f30  4080c850  4080c850  0000d850  2**3
                  CONTENTS, ALLOC, LOAD, DATA
 11 .noinit       00000000  4080e780  4080e780  00000000  2**0
                  ALLOC
 12 .dram0.bss    00001598  4080e780  4080e780  0000f780  2**4
                  ALLOC
 13 .flash.text   0016f3b6  42000020  42000020  00010020  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
 14 iram1.queue_as_raw 00000016  4216f3d6  4216f3d6  0017f3d6  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
 15 iram1.queue_recv_front 0000011a  4216f3ec  4216f3ec  0017f3ec  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
 16 .flash_rodata_dummy 00170000  42000020  42000020  00180020  2**0
                  ALLOC
 17 .flash.appdesc 00000100  42170020  42170020  00180020  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 18 .flash.rodata 000333d8  42170120  42170120  00180120  2**4
                  CONTENTS, ALLOC, LOAD, DATA
 19 .eh_frame     00057068  421a34f8  421a34f8  001b34f8  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 20 .flash.rodata_noload 00000000  421fa560  421fa560  0020a560  2**0
                  CONTENTS
 21 .dram0.heap_start 00000008  4080fd18  4080fd18  0000f780  2**0
                  ALLOC
 22 .debug_loc    0007f8f6  00000000  00000000  0020a560  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 23 .debug_abbrev 00037efb  00000000  00000000  00289e56  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 24 .debug_info   00588cb8  00000000  00000000  002c1d51  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 25 .debug_aranges 0003fee8  00000000  00000000  0084aa10  2**3
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 26 .debug_ranges 00077b30  00000000  00000000  0088a8f8  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 27 .debug_str    00694ced  00000000  00000000  00902428  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 28 .comment      00000094  00000000  00000000  00f97115  2**0
                  CONTENTS, READONLY
 29 .riscv.attributes 0000004d  00000000  00000000  00f971a9  2**0
                  CONTENTS, READONLY
 30 .debug_line   0034d211  00000000  00000000  00f971f6  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 31 .debug_frame  00012e40  00000000  00000000  012e4408  2**2
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 32 .debug_line_str 00002402  00000000  00000000  012f7248  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 33 .debug_loclists 0000f5c9  00000000  00000000  012f964a  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 34 .debug_rnglists 00001d7e  00000000  00000000  01308c13  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS

When I run espflash flash --monitor --partition-table ./partitions.csv <elf>, I get the following output:

Chip type:         esp32c6 (revision v0.0)
Crystal frequency: 40MHz
Flash size:        8MB
...
App/part. size:    2,205,072/4,194,304 bytes, 52.57%
...
I (41) boot: ESP-IDF v5.1-beta1-378-gea5e0ff298-dirt 2nd stage bootloader
I (42) boot: compile time Jun  7 2023 08:02:08
I (43) boot: chip revision: v0.0
I (46) boot.esp32c6: SPI Speed      : 40MHz
I (51) boot.esp32c6: SPI Mode       : DIO
I (56) boot.esp32c6: SPI Flash Size : 4MB
I (61) boot: Enabling RNG early entropy source...
E (66) flash_parts: partition 2 invalid - offset 0x10000 size 0x400000 exceeds flash chip size 0x400000
E (76) boot: Failed to verify partition table
E (81) boot: load partition table error!

Note how the bootloader does not detect the chip size correctly. This is probably a small bug in espflash somewhere.

If I now invoke espflash flash --monitor --partition-table ./partitions.csv --flash-size 8mb <elf> I get the following output:

...
Flash size:        8MB
...
I (41) boot: ESP-IDF v5.1-beta1-378-gea5e0ff298-dirt 2nd stage bootloader
I (42) boot: compile time Jun  7 2023 08:02:08
I (43) boot: chip revision: v0.0
I (46) boot.esp32c6: SPI Speed      : 40MHz
I (51) boot.esp32c6: SPI Mode       : DIO
I (56) boot.esp32c6: SPI Flash Size : 8MB
I (61) boot: Enabling RNG early entropy source...
I (66) boot: Partition Table:
I (70) boot: ## Label            Usage          Type ST Offset   Length
I (77) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (84) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (92) boot:  2 factory          factory app      00 00 00010000 00400000
I (99) boot: End of partition table
I (103) esp_image: segment 0: paddr=00010020 vaddr=42000020 size=16f3b8h (1504184) map
I (417) esp_image: segment 1: paddr=0017f3e0 vaddr=40800000 size=0e780h ( 59264) load
E (432) esp_image: invalid segment length 0x1866
E (432) boot: Factory app partition is not bootable
E (433) boot: No bootable app partitions in the partition table

Now the bootloader detects the flash size correctly, but cannot load the segments.
Without investigating in detail, to me it looks that we still have some problems with merging the segments.

I'm using espflash from todays master branch (074f8bc)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingstatus:needs-investigationIssue requires further investigation

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions