@@ -551,15 +551,61 @@ static inline bool stub_flash_should_map(uint32_t load_addr)
551
551
|| (load_addr >= SOC_DROM_LOW && load_addr < SOC_DROM_HIGH );
552
552
}
553
553
554
- static int stub_flash_get_map (uint32_t maps_addr )
554
+ static int stub_flash_get_app_mappings (uint32_t off , struct esp32_flash_mapping * flash_map )
555
+ {
556
+ esp_image_header_t img_hdr ;
557
+ uint16_t maps_num = 0 ;
558
+
559
+ esp_rom_spiflash_result_t rc = esp_rom_spiflash_read (off , (uint32_t * )& img_hdr , sizeof (img_hdr ));
560
+ if (rc != ESP_ROM_SPIFLASH_RESULT_OK ) {
561
+ STUB_LOGE ("Failed to read app image header (%d)!\n" , rc );
562
+ return ESP32_STUB_ERR_FAIL ;
563
+ }
564
+ if (img_hdr .magic != ESP_IMAGE_HEADER_MAGIC ) {
565
+ STUB_LOGE ("Invalid magic number 0x%x in app image!\n" , img_hdr .magic );
566
+ return ESP32_STUB_ERR_FAIL ;
567
+ }
568
+
569
+ STUB_LOGI ("Found app image: magic 0x%x, %d segments, entry @ 0x%x\n" , img_hdr .magic , img_hdr .segment_count , img_hdr .entry_addr );
570
+ uint32_t flash_addr = off + sizeof (img_hdr );
571
+ for (int k = 0 ; k < img_hdr .segment_count ; k ++ ) {
572
+ esp_image_segment_header_t seg_hdr ;
573
+ rc = esp_rom_spiflash_read (flash_addr , (uint32_t * )& seg_hdr , sizeof (seg_hdr ));
574
+ if (rc != ESP_ROM_SPIFLASH_RESULT_OK ) {
575
+ STUB_LOGE ("Failed to read app segment header (%d)!\n" , rc );
576
+ return ESP32_STUB_ERR_FAIL ;
577
+ }
578
+ STUB_LOGI ("App segment %d: %d bytes @ 0x%x\n" , k , seg_hdr .data_len , seg_hdr .load_addr );
579
+ if (stub_flash_should_map (seg_hdr .load_addr )) {
580
+ STUB_LOGI ("Mapped segment %d: %d bytes @ 0x%x -> 0x%x\n" , maps_num , seg_hdr .data_len , flash_addr + sizeof (seg_hdr ), seg_hdr .load_addr );
581
+ if (maps_num < ESP32_STUB_FLASH_MAPPINGS_MAX_NUM ) {
582
+ flash_map -> maps [maps_num ].phy_addr = flash_addr + sizeof (seg_hdr );
583
+ flash_map -> maps [maps_num ].load_addr = seg_hdr .load_addr ;
584
+ flash_map -> maps [maps_num ].size = seg_hdr .data_len ;
585
+ maps_num ++ ;
586
+ } else {
587
+ break ;
588
+ }
589
+ }
590
+ flash_addr += sizeof (seg_hdr ) + seg_hdr .data_len ;
591
+ }
592
+ flash_map -> maps_num = maps_num ;
593
+ return ESP32_STUB_ERR_OK ;
594
+ }
595
+
596
+ static int stub_flash_get_map (uint32_t app_off , uint32_t maps_addr )
555
597
{
556
598
esp_rom_spiflash_result_t rc ;
557
- struct esp32_flash_mapping * flash_map = (struct esp32_flash_mapping * )maps_addr ;
558
599
esp_partition_info_t parts [ESP32_STUB_PARTITION_TABLE_MAX_ENTRIES ];
600
+ struct esp32_flash_mapping * flash_map = (struct esp32_flash_mapping * )maps_addr ;
559
601
uint32_t flash_size = stub_flash_get_size ();
560
- uint32_t maps_num = 0 ;
561
602
562
- STUB_LOGD ("%s: 0x%x\n" , __func__ , flash_map );
603
+ STUB_LOGD ("%s: 0x%x 0x%x\n" , __func__ , app_off , maps_addr );
604
+ flash_map -> maps_num = 0 ;
605
+ if (app_off != (uint32_t )-1 ) {
606
+ return stub_flash_get_app_mappings (app_off , flash_map );
607
+ }
608
+
563
609
rc = esp_rom_spiflash_read (ESP_PARTITION_TABLE_OFFSET , (uint32_t * )parts , sizeof (parts ));
564
610
if (rc != ESP_ROM_SPIFLASH_RESULT_OK ) {
565
611
STUB_LOGE ("Failed to read partitions table (%d)!\n" , rc );
@@ -582,43 +628,12 @@ static int stub_flash_get_map(uint32_t maps_addr)
582
628
}
583
629
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 );
584
630
if (parts [i ].type == PART_TYPE_APP ) {
585
- STUB_LOGI ("Found app partition: '%s' %d KB @ 0x%x\n" , parts [i ].label , parts [i ].pos .size / 1024 , parts [i ].pos .offset );
586
- esp_image_header_t img_hdr ;
587
- rc = esp_rom_spiflash_read (pos -> offset , (uint32_t * )& img_hdr , sizeof (img_hdr ));
588
- if (rc != ESP_ROM_SPIFLASH_RESULT_OK ) {
589
- STUB_LOGE ("Failed to read app image header (%d)!\n" , rc );
590
- return ESP32_STUB_ERR_FAIL ;
591
- }
592
- if (img_hdr .magic != ESP_IMAGE_HEADER_MAGIC ) {
593
- STUB_LOGE ("Invalid magic number 0x%x in app image!\n" , i , img_hdr .magic );
594
- } else {
595
- STUB_LOGI ("Found app image: magic 0x%x, %d segments, entry @ 0x%x\n" , img_hdr .magic , img_hdr .segment_count , img_hdr .entry_addr );
596
- uint32_t flash_addr = pos -> offset + sizeof (img_hdr );
597
- for (int k = 0 ; k < img_hdr .segment_count ; k ++ ) {
598
- esp_image_segment_header_t seg_hdr ;
599
- rc = esp_rom_spiflash_read (flash_addr , (uint32_t * )& seg_hdr , sizeof (seg_hdr ));
600
- if (rc != ESP_ROM_SPIFLASH_RESULT_OK ) {
601
- STUB_LOGE ("Failed to read app segment header (%d)!\n" , rc );
602
- return ESP32_STUB_ERR_FAIL ;
603
- }
604
- STUB_LOGI ("App segment %d: %d bytes @ 0x%x\n" , k , seg_hdr .data_len , seg_hdr .load_addr );
605
- if (stub_flash_should_map (seg_hdr .load_addr )) {
606
- STUB_LOGI ("Mapped segment %d: %d bytes @ 0x%x -> 0x%x\n" , maps_num , seg_hdr .data_len , flash_addr + sizeof (seg_hdr ), seg_hdr .load_addr );
607
- if (maps_num < flash_map -> maps_num ) {
608
- flash_map -> maps [maps_num ].phy_addr = flash_addr + sizeof (seg_hdr );
609
- flash_map -> maps [maps_num ].load_addr = seg_hdr .load_addr ;
610
- flash_map -> maps [maps_num ].size = seg_hdr .data_len ;
611
- }
612
- maps_num ++ ;
613
- }
614
- flash_addr += sizeof (seg_hdr ) + seg_hdr .data_len ;
615
- }
616
- if (maps_num > 0 ) {
617
- STUB_LOGI ("IROM base 0x%x, maps num %d\n" , pos -> offset , maps_num );
618
- flash_map -> maps_num = maps_num ;
619
- break ;
620
- }
631
+ STUB_LOGI ("Found app partition: '%s' %d KB @ 0x%x\n" , parts [i ].label , pos -> size / 1024 , pos -> offset );
632
+ int ret = stub_flash_get_app_mappings (pos -> offset , flash_map );
633
+ if (ret != ESP32_STUB_ERR_OK ) {
634
+ return ret ;
621
635
}
636
+ break ;
622
637
}
623
638
}
624
639
return ESP32_STUB_ERR_OK ;
@@ -775,7 +790,7 @@ static int stub_flash_handler(int cmd, va_list ap)
775
790
ret = stub_flash_get_size ();
776
791
break ;
777
792
case ESP32_STUB_CMD_FLASH_MAP_GET :
778
- ret = stub_flash_get_map (arg1 );
793
+ ret = stub_flash_get_map (arg1 , arg2 );
779
794
break ;
780
795
case ESP32_STUB_CMD_FLASH_BP_SET :
781
796
ret = stub_flash_set_bp (arg1 , arg2 , arg3 );
@@ -801,6 +816,11 @@ static int stub_flash_handler(int cmd, va_list ap)
801
816
return ret ;
802
817
}
803
818
819
+ void ets_update_cpu_frequency (uint32_t ticks_per_us )
820
+ {
821
+ /* do nothing for stub */
822
+ }
823
+
804
824
#if STUB_LOG_LOCAL_LEVEL > STUB_LOG_NONE
805
825
static void clock_configure (void )
806
826
{
@@ -826,7 +846,6 @@ static void clock_configure(void)
826
846
clk_cfg .fast_freq = rtc_clk_fast_freq_get ();
827
847
rtc_clk_init (clk_cfg );
828
848
}
829
-
830
849
static void uart_console_configure (void )
831
850
{
832
851
uartAttach ();
0 commit comments