@@ -107,7 +107,7 @@ static void msc_update_setup_disk(const char * volume_label, uint32_t serial_num
107
107
msc_table = fat_add_table (msc_ram_disk, msc_boot, mcs_is_fat16);
108
108
// fat_dir_entry_t * label = fat_add_label(msc_ram_disk, volume_label);
109
109
if (msc_run_partition){
110
- fw_entry = fat_add_root_file (msc_ram_disk, 0 , " ACTIVEFW " , " BIN" , fw_size, 2 , mcs_is_fat16);
110
+ fw_entry = fat_add_root_file (msc_ram_disk, 0 , " FIRMWARE " , " BIN" , fw_size, 2 , mcs_is_fat16);
111
111
fw_end_sector = FAT_SIZE_TO_SECTORS (fw_size) + fw_start_sector;
112
112
}
113
113
}
@@ -117,10 +117,6 @@ static fat_dir_entry_t * msc_update_get_root_bin_entry(uint8_t index){
117
117
fat_dir_entry_t * entry = (fat_dir_entry_t *)(msc_ram_disk + ((msc_boot->sectors_per_alloc_table +1 ) * DISK_SECTOR_SIZE) + (index * sizeof (fat_dir_entry_t )));
118
118
fat_lfn_entry_t * lfn = (fat_lfn_entry_t *)entry;
119
119
120
- // fw read entry
121
- if (entry == fw_entry){
122
- return NULL ;
123
- }
124
120
// empty entry
125
121
if (entry->file_magic == 0 ){
126
122
return NULL ;
@@ -146,7 +142,8 @@ static fat_dir_entry_t * msc_update_get_root_bin_entry(uint8_t index){
146
142
147
143
// get an empty bin (the host will add an entry for file about to be written with size of zero)
148
144
static fat_dir_entry_t * msc_update_find_new_bin (){
149
- for (uint8_t i=15 ; i; i--){
145
+ for (uint8_t i=16 ; i;){
146
+ i--;
150
147
fat_dir_entry_t * entry = msc_update_get_root_bin_entry (i);
151
148
if (entry && entry->file_size == 0 ){
152
149
return entry;
@@ -155,6 +152,18 @@ static fat_dir_entry_t * msc_update_find_new_bin(){
155
152
return NULL ;
156
153
}
157
154
155
+ // get a bin starting from particular sector
156
+ static fat_dir_entry_t * msc_update_find_bin (uint16_t sector){
157
+ for (uint8_t i=16 ; i; ){
158
+ i--;
159
+ fat_dir_entry_t * entry = msc_update_get_root_bin_entry (i);
160
+ if (entry && entry->data_start_sector == (sector - msc_boot->sectors_per_alloc_table )){
161
+ return entry;
162
+ }
163
+ }
164
+ return NULL ;
165
+ }
166
+
158
167
// write the new data and erase the flash blocks when necessary
159
168
static esp_err_t msc_update_write (const esp_partition_t *partition, uint32_t offset, void *data, size_t size){
160
169
esp_err_t err = ESP_OK;
@@ -222,13 +231,16 @@ static int32_t msc_write(uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_
222
231
}
223
232
msc_update_entry = update_entry;
224
233
} else if (msc_update_state == MSC_UPDATE_RUNNING){
234
+ if (!msc_update_entry && msc_update_start_sector){
235
+ msc_update_entry = msc_update_find_bin (msc_update_start_sector);
236
+ }
225
237
if (msc_update_entry && msc_update_bytes_written >= msc_update_entry->file_size ){
226
238
msc_update_end ();
227
239
}
228
240
}
229
241
}
230
242
}
231
- } else if (lba >= fw_end_sector && lba >= msc_update_start_sector){
243
+ } else if (lba >= msc_update_start_sector){
232
244
// handle writes to the region where the new firmware will be uploaded
233
245
arduino_firmware_msc_event_data_t p = {0 };
234
246
if (msc_update_state <= MSC_UPDATE_STARTING && buffer[0 ] == 0xE9 ){
@@ -312,7 +324,7 @@ FirmwareMSC::FirmwareMSC():msc(){}
312
324
FirmwareMSC::~FirmwareMSC (){}
313
325
314
326
bool FirmwareMSC::begin (){
315
- msc_update_setup_disk (" ESP32S2-FW " , 0x0 );
327
+ msc_update_setup_disk (" ESP32-FWMSC " , 0x0 );
316
328
msc.vendorID (" ESP32S2" );// max 8 chars
317
329
msc.productID (" Firmware MSC" );// max 16 chars
318
330
msc.productRevision (" 1.0" );// max 4 chars
0 commit comments