66
77#include <flash.h>
88#include <err.h>
9+ #include <log.h>
10+ #include <bit_utils.h>
911#include <target/flash.h>
12+ #include <private/rom_flash_config.h>
1013
1114stub_lib_err_t stub_lib_flash_init (void * * state )
1215{
1316 stub_target_flash_init (state );
17+ uint32_t flash_id = stub_target_flash_get_flash_id ();
18+ uint32_t flash_size = stub_target_flash_id_to_flash_size (flash_id );
19+ if (flash_size == 0 ) {
20+ STUB_LOGE ("Invalid flash size: 0\n" );
21+ return STUB_LIB_ERR_UNKNOWN_FLASH_ID ;
22+ }
23+ STUB_LOG_TRACEF ("Flash size: %d MB\n" , MB (flash_size ));
24+
25+ stub_target_flash_update_config (flash_id , flash_size );
26+
1427 return STUB_LIB_OK ;
1528}
1629
@@ -19,9 +32,32 @@ void stub_lib_flash_deinit(const void *state)
1932 stub_target_flash_deinit (state );
2033}
2134
22- stub_lib_err_t stub_lib_flash_get_info (stub_lib_flash_info_t * info )
35+ void stub_lib_flash_get_info (stub_lib_flash_info_t * info )
2336{
24- (void )info ;
25- // TODO: implement
26- return STUB_LIB_OK ;
37+ const esp_rom_spiflash_chip_t * chip = stub_target_flash_get_config ();
38+
39+ info -> id = chip -> flash_id ;
40+ info -> size = chip -> chip_size ;
41+ info -> block_size = chip -> block_size ;
42+ info -> sector_size = chip -> sector_size ;
43+ info -> page_size = chip -> page_size ;
44+ info -> mode = 0 ; // TODO: Implement
45+ info -> encrypted = 0 ; // TODO: Implement
46+ }
47+
48+ void stub_lib_flash_info_print (const stub_lib_flash_info_t * info )
49+ {
50+ (void )info ; // to avoid the 'unused-parameter' warning when LOG is disabled
51+ STUB_LOGI ("Flash info:\n"
52+ "\tid: 0x%x, size: %d KB,\n"
53+ "\tblock: %d KB (0x%x), sector: %d B (0x%x), page: %d B (0x%x),\n"
54+ "\tmode: %d, enc: %d\n" ,
55+ info -> id ,
56+ KB (info -> size ),
57+ KB (info -> block_size ), info -> block_size ,
58+ info -> sector_size , info -> sector_size ,
59+ info -> page_size , info -> page_size ,
60+ info -> mode ,
61+ info -> encrypted
62+ );
2763}
0 commit comments