@@ -400,6 +400,14 @@ function getIntelHexFiles(
400
400
const startAddress : number = getStartAddress ( hexMap ) ;
401
401
const endAddress : number = getLastPageAddress ( hexMap ) ;
402
402
403
+ // TODO: endAddress as the getLastPageAddress works now because this
404
+ // library uses the last page as the "persistent" page, so the filesystem does
405
+ // end there. In reality, the persistent page could be the first or the last
406
+ // page, so we should get the end address as the magnetometer page and then
407
+ // check if the persistent marker is present in the first of last page and take that
408
+ // into account in the memory range calculation.
409
+ // Note that the persistent marker is only present at the top of the page
410
+
403
411
// Iterate through the filesystem to collect used chunks and file starts
404
412
const usedChunks : { [ index : number ] : Uint8Array } = { } ;
405
413
const startChunkIndexes : number [ ] = [ ] ;
@@ -480,9 +488,25 @@ function getIntelHexFiles(
480
488
return files ;
481
489
}
482
490
491
+ /**
492
+ * Calculate the MicroPython filesystem size.
493
+ *
494
+ * @param intelHex - The MicroPython Intel Hex string.
495
+ * @returns Size of the filesystem in bytes.
496
+ */
497
+ function getIntelHexFsSize ( intelHex : string ) : number {
498
+ const intelHexClean = cleanseOldHexFormat ( intelHex ) ;
499
+ const intelHexMap : MemoryMap = MemoryMap . fromHex ( intelHexClean ) ;
500
+ const startAddress : number = getStartAddress ( intelHexMap ) ;
501
+ const endAddress = getEndAddress ( intelHexMap ) ;
502
+ // Remember that one page is used as persistent page
503
+ return endAddress - startAddress - FLASH_PAGE_SIZE ;
504
+ }
505
+
483
506
export {
484
507
addIntelHexFile ,
485
508
addIntelHexFiles ,
486
509
calculateFileSize ,
487
510
getIntelHexFiles ,
511
+ getIntelHexFsSize ,
488
512
} ;
0 commit comments