66
77#include <flash.h>
88#include <err.h>
9+ #include <log.h>
910#include <target/flash.h>
11+ #include <private/rom_flash_config.h>
1012
1113stub_lib_err_t stub_lib_flash_init (void * * state )
1214{
1315 stub_target_flash_init (state );
16+ uint32_t flash_id = stub_target_flash_get_flash_id ();
17+ uint32_t flash_size = stub_target_flash_id_to_flash_size (flash_id );
18+ if (flash_size == 0 ) {
19+ STUB_LOGE ("Invalid flash size: 0\n" );
20+ return STUB_LIB_FAIL ;
21+ }
22+ STUB_LOG_TRACEF ("Flash size: %d MB\n" , flash_size / (1024 * 1024 ));
23+
24+ stub_target_flash_update_config (flash_id , flash_size );
25+
1426 return STUB_LIB_OK ;
1527}
1628
@@ -21,7 +33,32 @@ void stub_lib_flash_deinit(const void *state)
2133
2234stub_lib_err_t stub_lib_flash_get_info (stub_lib_flash_info_t * info )
2335{
24- (void )info ;
25- // TODO: implement
36+ const esp_rom_spiflash_chip_t * chip = stub_target_flash_get_config ();
37+
38+ info -> id = chip -> flash_id ;
39+ info -> size = chip -> chip_size ;
40+ info -> block_size = chip -> block_size ;
41+ info -> sector_size = chip -> sector_size ;
42+ info -> page_size = chip -> page_size ;
43+ info -> mode = 0 ; // TODO: Implement
44+ info -> encrypted = 0 ; // TODO: Implement
45+
2646 return STUB_LIB_OK ;
2747}
48+
49+ void stub_lib_flash_info_print (const stub_lib_flash_info_t * info )
50+ {
51+ (void )info ;
52+ STUB_LOGI ("Flash info:\n"
53+ "\tid: 0x%x, size: %d KB,\n"
54+ "\tblock: %d KB (0x%x), sector: %d B (0x%x), page: %d B (0x%x),\n"
55+ "\tmode: %d, enc: %d\n" ,
56+ info -> id ,
57+ info -> size / 1024 ,
58+ info -> block_size / 1024 , info -> block_size ,
59+ info -> sector_size , info -> sector_size ,
60+ info -> page_size , info -> page_size ,
61+ info -> mode ,
62+ info -> encrypted
63+ );
64+ }
0 commit comments