Skip to content

Commit

Permalink
Make SPIFFS be an integer number of blocks (esp8266#5989)
Browse files Browse the repository at this point in the history
* Make SPIFFS be an integer number of blocks

boards.txt.py simply calculated the end and start using flash sizes, but
in cases where an 8K page was used (>512KB SPIFFS), this could leave a
4K half-block left at the end of SPIFFS.

mkspiffs and the SPIFFS code uses integer division to calculate the
maximum block number, so it worked fine in practice and the code simply
ignored the extra, fractional block.

Now actually take block size into account when calculating the end of
SPIFFS, ensuring no fractional blocks are passed in.  Does not result in
data loss on pre-existing SPIFFS filesystems.

* Fix the 1m512 case and clean up code

Ensure that no SPIFFS_block in the LD files is modified from the
original to endure correct backwards compatibility

* Factor out common if, clean code

* Make boards.py vars "fs_xx" instead of "spiffs_xx"
  • Loading branch information
earlephilhower authored and d-a-v committed Jul 9, 2019
1 parent adf2b14 commit 828857d
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 130 deletions.
160 changes: 80 additions & 80 deletions boards.txt

Large diffs are not rendered by default.

63 changes: 31 additions & 32 deletions tools/boards.txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ def all_debug ():
################################################################
# flash size

def flash_map (flashsize_kb, spiffs_kb = 0):
def flash_map (flashsize_kb, fs_kb = 0):

# mapping:
# flash | reserved | empty | spiffs | eeprom | rf-cal | sdk-wifi-settings
Expand All @@ -1172,29 +1172,32 @@ def flash_map (flashsize_kb, spiffs_kb = 0):
eeprom_size_kb = 4
rfcal_size_kb = 4
sdkwifi_size_kb = 12
spiffs_end = (flashsize_kb - sdkwifi_size_kb - rfcal_size_kb - eeprom_size_kb) * 1024
fs_end = (flashsize_kb - sdkwifi_size_kb - rfcal_size_kb - eeprom_size_kb) * 1024
rfcal_addr = (flashsize_kb - sdkwifi_size_kb - rfcal_size_kb) * 1024
if flashsize_kb <= 1024:
max_upload_size = (flashsize_kb - (spiffs_kb + eeprom_size_kb + rfcal_size_kb + sdkwifi_size_kb)) * 1024 - reserved
spiffs_start = spiffs_end - spiffs_kb * 1024
spiffs_blocksize = 4096
max_upload_size = (flashsize_kb - (fs_kb + eeprom_size_kb + rfcal_size_kb + sdkwifi_size_kb)) * 1024 - reserved
fs_start = fs_end - fs_kb * 1024
else:
max_upload_size = 1024 * 1024 - reserved
spiffs_start = (flashsize_kb - spiffs_kb) * 1024
if spiffs_kb < 512:
spiffs_blocksize = 4096
else:
spiffs_blocksize = 8192
fs_start = (flashsize_kb - fs_kb) * 1024

if fs_kb < 512:
fs_blocksize = 4096
else:
fs_blocksize = 8192

max_ota_size = min(max_upload_size, spiffs_start / 2) # =(max_upload_size+empty_size)/2
# Adjust SPIFFS_end to be a multiple of the block size
fs_end = fs_blocksize * (int)((fs_end - fs_start)/fs_blocksize) + fs_start;

max_ota_size = min(max_upload_size, fs_start / 2) # =(max_upload_size+empty_size)/2
strsize = str(int(flashsize_kb / 1024)) + 'M' if (flashsize_kb >= 1024) else str(flashsize_kb) + 'K'
strspiffs = str(int(spiffs_kb / 1024)) + 'M' if (spiffs_kb >= 1024) else str(spiffs_kb) + 'K'
strspiffs_strip = str(int(spiffs_kb / 1024)) + 'M' if (spiffs_kb >= 1024) else str(spiffs_kb) if (spiffs_kb > 0) else ''
strfs = str(int(fs_kb / 1024)) + 'M' if (fs_kb >= 1024) else str(fs_kb) + 'K'
strfs_strip = str(int(fs_kb / 1024)) + 'M' if (fs_kb >= 1024) else str(fs_kb) if (fs_kb > 0) else ''

ld = 'eagle.flash.' + strsize.lower() + strspiffs_strip.lower() + '.ld'
menu = '.menu.eesz.' + strsize + strspiffs_strip
ld = 'eagle.flash.' + strsize.lower() + strfs_strip.lower() + '.ld'
menu = '.menu.eesz.' + strsize + strfs_strip
menub = menu + '.build.'
desc = 'no' if (spiffs_kb == 0) else strspiffs + 'B'
desc = 'no' if (fs_kb == 0) else strfs + 'B'
d = collections.OrderedDict([
( menu, strsize + 'B (FS:' + desc + ' OTA:~%iKB)' % (max_ota_size / 1024)),
( menub + 'flash_size', strsize ),
Expand All @@ -1204,11 +1207,11 @@ def flash_map (flashsize_kb, spiffs_kb = 0):
( menu + '.upload.maximum_size', "%i" % max_upload_size ),
( menub + 'rfcal_addr', "0x%X" % rfcal_addr)
])
if spiffs_kb > 0:
if fs_kb > 0:
d.update(collections.OrderedDict([
( menub + 'spiffs_start', "0x%05X" % spiffs_start ),
( menub + 'spiffs_end', "0x%05X" % spiffs_end ),
( menub + 'spiffs_blocksize', "%i" % spiffs_blocksize ),
( menub + 'spiffs_start', "0x%05X" % fs_start ),
( menub + 'spiffs_end', "0x%05X" % fs_end ),
( menub + 'spiffs_blocksize', "%i" % fs_blocksize ),
]))

if ldshow:
Expand All @@ -1224,23 +1227,19 @@ def flash_map (flashsize_kb, spiffs_kb = 0):
realstdout = sys.stdout
sys.stdout = open(lddir + ld, 'w')

if spiffs_kb == 0:
spiffs_start = spiffs_end
if fs_kb == 0:
fs_start = fs_end
page = 0
block = 0
elif spiffs_kb < 0x80000 / 1024:
page = 0x100
block = 0x1000
fs_blocksize = 0
else:
page = 0x100
block = 0x2000

print("/* Flash Split for %s chips */" % strsize)
print("/* sketch @0x%X (~%dKB) (%dB) */" % (spi, (max_upload_size / 1024), max_upload_size))
empty_size = spiffs_start - max_upload_size
empty_size = fs_start - max_upload_size
if empty_size > 0:
print("/* empty @0x%X (~%dKB) (%dB) */" % (spi + max_upload_size, empty_size / 1024, empty_size))
print("/* spiffs @0x%X (~%dKB) (%dB) */" % (spi + spiffs_start, ((spiffs_end - spiffs_start) / 1024), spiffs_end - spiffs_start))
print("/* spiffs @0x%X (~%dKB) (%dB) */" % (spi + fs_start, ((fs_end - fs_start) / 1024), fs_end - fs_start))
print("/* eeprom @0x%X (%dKB) */" % (spi + rfcal_addr - eeprom_size_kb * 1024, eeprom_size_kb))
print("/* rfcal @0x%X (%dKB) */" % (spi + rfcal_addr, rfcal_size_kb))
print("/* wifi @0x%X (%dKB) */" % (spi + rfcal_addr + rfcal_size_kb * 1024, sdkwifi_size_kb))
Expand All @@ -1253,10 +1252,10 @@ def flash_map (flashsize_kb, spiffs_kb = 0):
print(" irom0_0_seg : org = 0x40201010, len = 0x%x" % max_upload_size)
print("}")
print("")
print("PROVIDE ( _FS_start = 0x%08X );" % (0x40200000 + spiffs_start))
print("PROVIDE ( _FS_end = 0x%08X );" % (0x40200000 + spiffs_end))
print("PROVIDE ( _FS_start = 0x%08X );" % (0x40200000 + fs_start))
print("PROVIDE ( _FS_end = 0x%08X );" % (0x40200000 + fs_end))
print("PROVIDE ( _FS_page = 0x%X );" % page)
print("PROVIDE ( _FS_block = 0x%X );" % block)
print("PROVIDE ( _FS_block = 0x%X );" % fs_blocksize)
print("")
print('INCLUDE "local.eagle.app.v6.common.ld"')

Expand Down
4 changes: 2 additions & 2 deletions tools/sdk/ld/eagle.flash.16m14m.ld
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Flash Split for 16M chips */
/* sketch @0x40200000 (~1019KB) (1044464B) */
/* empty @0x402FEFF0 (~1028KB) (1052688B) */
/* spiffs @0x40400000 (~14316KB) (14659584B) */
/* spiffs @0x40400000 (~14312KB) (14655488B) */
/* eeprom @0x411FB000 (4KB) */
/* rfcal @0x411FC000 (4KB) */
/* wifi @0x411FD000 (12KB) */
Expand All @@ -15,7 +15,7 @@ MEMORY
}

PROVIDE ( _FS_start = 0x40400000 );
PROVIDE ( _FS_end = 0x411FB000 );
PROVIDE ( _FS_end = 0x411FA000 );
PROVIDE ( _FS_page = 0x100 );
PROVIDE ( _FS_block = 0x2000 );

Expand Down
4 changes: 2 additions & 2 deletions tools/sdk/ld/eagle.flash.16m15m.ld
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Flash Split for 16M chips */
/* sketch @0x40200000 (~1019KB) (1044464B) */
/* empty @0x402FEFF0 (~4KB) (4112B) */
/* spiffs @0x40300000 (~15340KB) (15708160B) */
/* spiffs @0x40300000 (~15336KB) (15704064B) */
/* eeprom @0x411FB000 (4KB) */
/* rfcal @0x411FC000 (4KB) */
/* wifi @0x411FD000 (12KB) */
Expand All @@ -15,7 +15,7 @@ MEMORY
}

PROVIDE ( _FS_start = 0x40300000 );
PROVIDE ( _FS_end = 0x411FB000 );
PROVIDE ( _FS_end = 0x411FA000 );
PROVIDE ( _FS_page = 0x100 );
PROVIDE ( _FS_block = 0x2000 );

Expand Down
4 changes: 2 additions & 2 deletions tools/sdk/ld/eagle.flash.2m1m.ld
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Flash Split for 2M chips */
/* sketch @0x40200000 (~1019KB) (1044464B) */
/* empty @0x402FEFF0 (~4KB) (4112B) */
/* spiffs @0x40300000 (~1004KB) (1028096B) */
/* spiffs @0x40300000 (~1000KB) (1024000B) */
/* eeprom @0x403FB000 (4KB) */
/* rfcal @0x403FC000 (4KB) */
/* wifi @0x403FD000 (12KB) */
Expand All @@ -15,7 +15,7 @@ MEMORY
}

PROVIDE ( _FS_start = 0x40300000 );
PROVIDE ( _FS_end = 0x403FB000 );
PROVIDE ( _FS_end = 0x403FA000 );
PROVIDE ( _FS_page = 0x100 );
PROVIDE ( _FS_block = 0x2000 );

Expand Down
4 changes: 2 additions & 2 deletions tools/sdk/ld/eagle.flash.2m512.ld
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Flash Split for 2M chips */
/* sketch @0x40200000 (~1019KB) (1044464B) */
/* empty @0x402FEFF0 (~516KB) (528400B) */
/* spiffs @0x40380000 (~492KB) (503808B) */
/* spiffs @0x40380000 (~488KB) (499712B) */
/* eeprom @0x403FB000 (4KB) */
/* rfcal @0x403FC000 (4KB) */
/* wifi @0x403FD000 (12KB) */
Expand All @@ -15,7 +15,7 @@ MEMORY
}

PROVIDE ( _FS_start = 0x40380000 );
PROVIDE ( _FS_end = 0x403FB000 );
PROVIDE ( _FS_end = 0x403FA000 );
PROVIDE ( _FS_page = 0x100 );
PROVIDE ( _FS_block = 0x2000 );

Expand Down
4 changes: 2 additions & 2 deletions tools/sdk/ld/eagle.flash.4m1m.ld
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Flash Split for 4M chips */
/* sketch @0x40200000 (~1019KB) (1044464B) */
/* empty @0x402FEFF0 (~2052KB) (2101264B) */
/* spiffs @0x40500000 (~1004KB) (1028096B) */
/* spiffs @0x40500000 (~1000KB) (1024000B) */
/* eeprom @0x405FB000 (4KB) */
/* rfcal @0x405FC000 (4KB) */
/* wifi @0x405FD000 (12KB) */
Expand All @@ -15,7 +15,7 @@ MEMORY
}

PROVIDE ( _FS_start = 0x40500000 );
PROVIDE ( _FS_end = 0x405FB000 );
PROVIDE ( _FS_end = 0x405FA000 );
PROVIDE ( _FS_page = 0x100 );
PROVIDE ( _FS_block = 0x2000 );

Expand Down
4 changes: 2 additions & 2 deletions tools/sdk/ld/eagle.flash.4m2m.ld
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Flash Split for 4M chips */
/* sketch @0x40200000 (~1019KB) (1044464B) */
/* empty @0x402FEFF0 (~1028KB) (1052688B) */
/* spiffs @0x40400000 (~2028KB) (2076672B) */
/* spiffs @0x40400000 (~2024KB) (2072576B) */
/* eeprom @0x405FB000 (4KB) */
/* rfcal @0x405FC000 (4KB) */
/* wifi @0x405FD000 (12KB) */
Expand All @@ -15,7 +15,7 @@ MEMORY
}

PROVIDE ( _FS_start = 0x40400000 );
PROVIDE ( _FS_end = 0x405FB000 );
PROVIDE ( _FS_end = 0x405FA000 );
PROVIDE ( _FS_page = 0x100 );
PROVIDE ( _FS_block = 0x2000 );

Expand Down
4 changes: 2 additions & 2 deletions tools/sdk/ld/eagle.flash.4m3m.ld
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Flash Split for 4M chips */
/* sketch @0x40200000 (~1019KB) (1044464B) */
/* empty @0x402FEFF0 (~4KB) (4112B) */
/* spiffs @0x40300000 (~3052KB) (3125248B) */
/* spiffs @0x40300000 (~3048KB) (3121152B) */
/* eeprom @0x405FB000 (4KB) */
/* rfcal @0x405FC000 (4KB) */
/* wifi @0x405FD000 (12KB) */
Expand All @@ -15,7 +15,7 @@ MEMORY
}

PROVIDE ( _FS_start = 0x40300000 );
PROVIDE ( _FS_end = 0x405FB000 );
PROVIDE ( _FS_end = 0x405FA000 );
PROVIDE ( _FS_page = 0x100 );
PROVIDE ( _FS_block = 0x2000 );

Expand Down
4 changes: 2 additions & 2 deletions tools/sdk/ld/eagle.flash.8m6m.ld
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Flash Split for 8M chips */
/* sketch @0x40200000 (~1019KB) (1044464B) */
/* empty @0x402FEFF0 (~1028KB) (1052688B) */
/* spiffs @0x40400000 (~6124KB) (6270976B) */
/* spiffs @0x40400000 (~6120KB) (6266880B) */
/* eeprom @0x409FB000 (4KB) */
/* rfcal @0x409FC000 (4KB) */
/* wifi @0x409FD000 (12KB) */
Expand All @@ -15,7 +15,7 @@ MEMORY
}

PROVIDE ( _FS_start = 0x40400000 );
PROVIDE ( _FS_end = 0x409FB000 );
PROVIDE ( _FS_end = 0x409FA000 );
PROVIDE ( _FS_page = 0x100 );
PROVIDE ( _FS_block = 0x2000 );

Expand Down
4 changes: 2 additions & 2 deletions tools/sdk/ld/eagle.flash.8m7m.ld
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Flash Split for 8M chips */
/* sketch @0x40200000 (~1019KB) (1044464B) */
/* empty @0x402FEFF0 (~4KB) (4112B) */
/* spiffs @0x40300000 (~7148KB) (7319552B) */
/* spiffs @0x40300000 (~7144KB) (7315456B) */
/* eeprom @0x409FB000 (4KB) */
/* rfcal @0x409FC000 (4KB) */
/* wifi @0x409FD000 (12KB) */
Expand All @@ -15,7 +15,7 @@ MEMORY
}

PROVIDE ( _FS_start = 0x40300000 );
PROVIDE ( _FS_end = 0x409FB000 );
PROVIDE ( _FS_end = 0x409FA000 );
PROVIDE ( _FS_page = 0x100 );
PROVIDE ( _FS_block = 0x2000 );

Expand Down

0 comments on commit 828857d

Please sign in to comment.