@@ -4603,7 +4603,9 @@ bool load_guts(picoboot::connection con, iostream_memory_access &file_access) {
4603
4603
// new scope for progress bar
4604
4604
{
4605
4605
progress_bar bar (" Loading into " + memory_names[type] + " : " );
4606
- uint32_t batch_size = FLASH_SECTOR_ERASE_SIZE;
4606
+ // Use batches of size/100 rounded up to FLASH_SECTOR_ERASE_SIZE
4607
+ uint32_t batch_size = std::max (FLASH_SECTOR_ERASE_SIZE,
4608
+ (mem_range.len ()/100 + FLASH_SECTOR_ERASE_SIZE - 1 ) & ~(FLASH_SECTOR_ERASE_SIZE - 1 ));
4607
4609
bool ok = true ;
4608
4610
vector<uint8_t > file_buf;
4609
4611
vector<uint8_t > device_buf;
@@ -4612,24 +4614,24 @@ bool load_guts(picoboot::connection con, iostream_memory_access &file_access) {
4612
4614
if (type == flash) {
4613
4615
// we have to erase an entire page, so then fill with zeros
4614
4616
range aligned_range (base & ~(FLASH_SECTOR_ERASE_SIZE - 1 ),
4615
- (base & ~( FLASH_SECTOR_ERASE_SIZE - 1 )) + FLASH_SECTOR_ERASE_SIZE);
4617
+ (base + this_batch + FLASH_SECTOR_ERASE_SIZE - 1 ) & ~( FLASH_SECTOR_ERASE_SIZE - 1 ) );
4616
4618
range read_range (base, base + this_batch);
4617
4619
read_range.intersect (aligned_range);
4618
4620
file_access.read_into_vector (read_range.from , read_range.to - read_range.from , file_buf, true ); // zero fill to cope with holes
4619
- // zero padding up to FLASH_SECTOR_ERASE_SIZE
4621
+ // zero padding up to batch_size
4620
4622
file_buf.insert (file_buf.begin (), read_range.from - aligned_range.from , 0 );
4621
4623
file_buf.insert (file_buf.end (), aligned_range.to - read_range.to , 0 );
4622
- assert (file_buf.size () == FLASH_SECTOR_ERASE_SIZE );
4624
+ assert (file_buf.size () == aligned_range. len () );
4623
4625
4624
4626
bool skip = false ;
4625
4627
if (settings.load .update ) {
4626
4628
vector<uint8_t > read_device_buf;
4627
- raw_access.read_into_vector (aligned_range.from , batch_size , read_device_buf);
4629
+ raw_access.read_into_vector (aligned_range.from , file_buf. size () , read_device_buf);
4628
4630
skip = file_buf == read_device_buf;
4629
4631
}
4630
4632
if (!skip) {
4631
4633
con.exit_xip ();
4632
- con.flash_erase (aligned_range.from , FLASH_SECTOR_ERASE_SIZE );
4634
+ con.flash_erase (aligned_range.from , file_buf. size () );
4633
4635
raw_access.write_vector (aligned_range.from , file_buf);
4634
4636
}
4635
4637
base = read_range.to ; // about to add batch_size
0 commit comments