@@ -611,7 +611,7 @@ static int stub_flash_get_app_mappings(uint32_t off, struct esp32_flash_mapping
611
611
static int stub_flash_get_map (uint32_t app_off , uint32_t maps_addr )
612
612
{
613
613
esp_rom_spiflash_result_t rc ;
614
- esp_partition_info_t parts [ ESP32_STUB_PARTITION_TABLE_MAX_ENTRIES ] ;
614
+ esp_partition_info_t part ;
615
615
struct esp32_flash_mapping * flash_map = (struct esp32_flash_mapping * )maps_addr ;
616
616
uint32_t flash_size = stub_flash_get_size ();
617
617
@@ -621,34 +621,25 @@ static int stub_flash_get_map(uint32_t app_off, uint32_t maps_addr)
621
621
return stub_flash_get_app_mappings (app_off , flash_map );
622
622
}
623
623
624
- rc = esp_rom_spiflash_read (ESP_PARTITION_TABLE_OFFSET , (uint32_t * )parts , sizeof (parts ));
625
- if (rc != ESP_ROM_SPIFLASH_RESULT_OK ) {
626
- STUB_LOGE ("Failed to read partitions table (%d)!\n" , rc );
627
- return ESP32_STUB_ERR_FAIL ;
628
- }
629
- for (int i = 0 ; i < ESP32_STUB_PARTITION_TABLE_MAX_ENTRIES ; i ++ ) {
630
- if (parts [i ].magic == 0xFFFF && parts [i ].type == PART_TYPE_END && parts [i ].subtype == PART_SUBTYPE_END ) {
631
- STUB_LOGI ("Found %d partitions\n" , i );
632
- break ;
633
- }
634
- if (parts [i ].magic != ESP_PARTITION_MAGIC ) {
635
- STUB_LOGE ("Partition %d invalid magic number 0x%x!\n" , i , parts [i ].magic );
624
+ for (uint32_t i = 0 ;; i ++ ) {
625
+ rc = esp_rom_spiflash_read (ESP_PARTITION_TABLE_OFFSET + i * sizeof (esp_partition_info_t ), (uint32_t * )& part , sizeof (part ));
626
+ if (rc != ESP_ROM_SPIFLASH_RESULT_OK ) {
627
+ STUB_LOGE ("Failed to read partitions table entrt (%d)!\n" , rc );
636
628
return ESP32_STUB_ERR_FAIL ;
637
629
}
638
- const esp_partition_pos_t * pos = & parts [i ].pos ;
639
- if (pos -> offset > flash_size || pos -> offset + pos -> size > flash_size ) {
630
+ if (part .magic != ESP_PARTITION_MAGIC ) {
631
+ STUB_LOGI ("No app partition found\n" );
632
+ break ;
633
+ }
634
+ if (part .pos .offset > flash_size || part .pos .offset + part .pos .size > flash_size ) {
640
635
STUB_LOGE ("Partition %d invalid - offset 0x%x size 0x%x exceeds flash chip size 0x%x\n" ,
641
- i , pos -> offset , pos -> size , flash_size );
636
+ i , part . pos . offset , part . pos . size , flash_size );
642
637
return ESP32_STUB_ERR_FAIL ;
643
638
}
644
- STUB_LOGD ("Found partition %d, m 0x%x, t 0x%x, st 0x%x, l '%s'\n" , i , parts [i ].magic , parts [i ].type , parts [i ].subtype , parts [i ].label );
645
- if (parts [i ].type == PART_TYPE_APP ) {
646
- STUB_LOGI ("Found app partition: '%s' %d KB @ 0x%x\n" , parts [i ].label , pos -> size / 1024 , pos -> offset );
647
- int ret = stub_flash_get_app_mappings (pos -> offset , flash_map );
648
- if (ret != ESP32_STUB_ERR_OK ) {
649
- return ret ;
650
- }
651
- break ;
639
+ STUB_LOGD ("Found partition %d, m 0x%x, t 0x%x, st 0x%x, l '%s'\n" , i , part .magic , part .type , part .subtype , part .label );
640
+ if (part .type == PART_TYPE_APP ) {
641
+ STUB_LOGI ("Found app partition: '%s' %d KB @ 0x%x\n" , part .label , part .pos .size / 1024 , part .pos .offset );
642
+ return stub_flash_get_app_mappings (part .pos .offset , flash_map );
652
643
}
653
644
}
654
645
return ESP32_STUB_ERR_OK ;
0 commit comments