@@ -491,17 +491,23 @@ onboard_logging.initialize = function (callback) {
491
491
492
492
show_saving_dialog ( ) ;
493
493
494
+ // START PATCH: minimal retry for null/missing blocks
495
+ const MAX_SIMPLE_RETRIES = 1 ;
496
+ let simpleRetryCount = 0 ;
497
+
494
498
function onChunkRead ( chunkAddress , chunkDataView , bytesCompressed ) {
495
499
if ( chunkDataView && chunkDataView . byteLength > 0 ) {
496
- // Always write non-empty data, even if CRC mismatch
500
+ // Reset retry counter after a good block
501
+ simpleRetryCount = 0 ;
502
+
503
+ // --- ORIGINAL BLOCK WRITE LOGIC ---
497
504
const blob = new Blob ( [ chunkDataView ] ) ;
498
505
FileSystem . writeChunck ( openedFile , blob ) ;
499
506
500
507
nextAddress += chunkDataView . byteLength ;
501
508
502
- // Track total compressed bytes, if provided
503
509
if ( typeof bytesCompressed === "number" ) {
504
- if ( totalBytesCompressed == null ) totalBytesCompressed = 0 ; // initialize if previously unknown
510
+ if ( totalBytesCompressed == null ) totalBytesCompressed = 0 ;
505
511
totalBytesCompressed += bytesCompressed ;
506
512
}
507
513
@@ -513,23 +519,34 @@ onboard_logging.initialize = function (callback) {
513
519
} else {
514
520
mspHelper . dataflashRead ( nextAddress , self . blockSize , onChunkRead ) ;
515
521
}
522
+ // --- END ORIGINAL LOGIC ---
516
523
} else if ( chunkDataView && chunkDataView . byteLength === 0 ) {
517
524
// Zero-length block → EOF
518
525
mark_saving_dialog_done ( startTime , nextAddress , totalBytesCompressed ) ;
519
526
FileSystem . closeFile ( openedFile ) ;
520
527
} else {
521
- // Null block → skip ahead (hard error)
522
- console . warn ( `Skipping null block at address ${ nextAddress } ` ) ;
523
- nextAddress += self . blockSize ;
524
-
525
- if ( nextAddress >= maxBytes ) {
526
- mark_saving_dialog_done ( startTime , nextAddress , totalBytesCompressed ) ;
527
- FileSystem . closeFile ( openedFile ) ;
528
- } else {
528
+ // Null/missing block
529
+ if ( simpleRetryCount < MAX_SIMPLE_RETRIES ) {
530
+ simpleRetryCount ++ ;
531
+ console . warn ( `Null/missing block at ${ nextAddress } , retry ${ simpleRetryCount } ` ) ;
529
532
mspHelper . dataflashRead ( nextAddress , self . blockSize , onChunkRead ) ;
533
+ } else {
534
+ console . error (
535
+ `Skipping null block at ${ nextAddress } after ${ MAX_SIMPLE_RETRIES } retry` ,
536
+ ) ;
537
+ nextAddress += self . blockSize ; // Move to next block
538
+ simpleRetryCount = 0 ; // reset counter for next block
539
+
540
+ if ( nextAddress >= maxBytes ) {
541
+ mark_saving_dialog_done ( startTime , nextAddress , totalBytesCompressed ) ;
542
+ FileSystem . closeFile ( openedFile ) ;
543
+ } else {
544
+ mspHelper . dataflashRead ( nextAddress , self . blockSize , onChunkRead ) ;
545
+ }
530
546
}
531
547
}
532
548
}
549
+ // END PATCH
533
550
534
551
const startTime = new Date ( ) . getTime ( ) ; // Start timestamp
535
552
0 commit comments