8000 esp8266: Change from FAT to littlefs v2 as default filesystem. · codemee/micropython@e0905e8 · GitHub
[go: up one dir, main page]

Skip to content

Commit e0905e8

Browse files
committed
esp8266: Change from FAT to littlefs v2 as default filesystem.
This commit changes the esp8266 boards to use littlefs v2 as the filesystem, rather than FAT. Since the esp8266 doesn't expose the filesystem to the PC over USB there's no strong reason to keep it as FAT. Littlefs is smaller in code size, is more efficient in use of flash to store data, is resilient over power failure, and using it saves about 4k of heap RAM, which can now be used for other things. This is a backwards incompatible change because all existing esp8266 boards will need to update their filesystem after installing new firmware (eg backup old files, install firmware, restore files to new filesystem). As part of this commit the memory layout of the default board (GENERIC) has changed. It now allocates all 1M of memory-mapped flash to the firmware, so the filesystem area starts at the 2M point. This is done to allow more frozen bytecode to be stored in the 1M of memory-mapped flash. This requires an esp8266 module with 2M or more of flash to work, so a new board called GENERIC_1M is added which has the old memory-mapping (but still changed to use littlefs for the filesystem). In summary there are now 3 esp8266 board definitions: - GENERIC_512K: for 512k modules, doesn't have a filesystem. - GENERIC_1M: for 1M modules, 572k for firmware+frozen code, 396k for filesystem (littlefs). - GENERIC: for 2M (or greater) modules, 968k for firmware+frozen code, 1M+ for filesystem (littlefs), FAT driver also included in firmware for use on, eg, external SD cards.
1 parent df156b1 commit e0905e8

File tree

12 files changed

+91
-34
lines changed

12 files changed

+91
-34
lines changed

docs/reference/filesystem.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ Board FAT littlefs v1 littlefs v2
178178
==================== ===== =========== ===========
179179
pyboard 1.0, 1.1, D Yes No Yes
180180
Other STM32 Yes No No
181-
ESP8266 Yes No No
181+
ESP8266 (1M) No No Yes
182+
ESP8266 (2M+) Yes No Yes
182183
ESP32 Yes No Yes
183184
==================== ===== =========== ===========
184185

ports/esp8266/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ QSTR_GLOBAL_DEPENDENCIES = $(BOARD_DIR)/mpconfigboard.h
2222
MICROPY_PY_USSL = 1
2323
MICROPY_SSL_AXTLS = 1
2424
AXTLS_DEFS_EXTRA = -Dabort=abort_ -DRT_MAX_PLAIN_LENGTH=1024 -DRT_EXTRA=4096
25-
MICROPY_PY_BTREE ?= 1
2625
BTREE_DEFS_EXTRA = -DDEFPSIZE=1024 -DMINCACHE=3
2726

2827
FROZEN_MANIFEST ?= boards/manifest.py
@@ -60,7 +59,7 @@ CFLAGS_XTENSA = -fsingle-precision-constant -Wdouble-promotion \
6059
CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -std=gnu99 -nostdlib -DUART_OS=$(UART_OS) \
6160
$(CFLAGS_XTENSA) $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA) -I$(BOARD_DIR)
6261

63-
LD_FILES ?= boards/esp8266.ld
62+
LD_FILES ?= boards/esp8266_2m.ld
6463
LDFLAGS = -nostdlib -T $(LD_FILES) -Map=$(@:.elf=.map) --cref
6564
LIBS = -L$(ESP_SDK)/lib -lmain -ljson -llwip_open -lpp -lnet80211 -lwpa -lphy -lnet80211 $(LDFLAGS_MOD)
6665

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
LD_FILES = boards/esp8266_2m.ld
2+
3+
MICROPY_PY_BTREE = 1
14
MICROPY_VFS_FAT = 1
5+
MICROPY_VFS_LFS2 = 1
26

37
FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#define MICROPY_HW_BOARD_NAME "ESP module (1M)"
2+
#define MICROPY_HW_MCU_NAME "ESP8266"
3+
4+
#define MICROPY_PERSISTENT_CODE_LOAD (1)
5+
#define MICROPY_EMIT_XTENSA (1)
6+
#define MICROPY_EMIT_INLINE_XTENSA (1)
7+
8+
#define MICROPY_DEBUG_PRINTERS (1)
9+
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL)
10+
11+
#define MICROPY_READER_VFS (MICROPY_VFS)
12+
#define MICROPY_VFS (1)
13+
14+
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (1)
15+
#define MICROPY_PY_ALL_SPECIAL_METHODS (1)
16+
#define MICROPY_PY_IO_FILEIO (1)
17+
#define MICROPY_PY_SYS_STDIO_BUFFER (1)
18+
#define MICROPY_PY_URE_SUB (1)
19+
#define MICROPY_PY_UCRYPTOLIB (1)
20+
#define MICROPY_PY_FRAMEBUF (1)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
LD_FILES = boards/esp8266_1m.ld
2+
3+
MICROPY_PY_BTREE = 1
4+
MICROPY_VFS_LFS2 = 1
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
MICROPY_PY_BTREE = 0
2-
MICROPY_VFS_FAT = 0
31
LD_FILES = boards/esp8266_512k.ld

ports/esp8266/boards/esp8266.ld

Lines changed: 0 additions & 12 deletions
This file was deleted.

ports/esp8266/boards/esp8266_1m.ld

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* GNU linker script for ESP8266 with 1M flash
2+
3+
Flash layout:
4+
0x40200000 36k header + iram/dram init
5+
0x40209000 572k firmware (irom0)
6+
0x40298000 396k filesystem
7+
0x402fb000 20k SDK parameters
8+
*/
9+
10+
MEMORY
11+
{
12+
dport0_0_seg : org = 0x3ff00000, len = 16
13+
dram0_0_seg : org = 0x3ffe8000, len = 80K
14+
iram1_0_seg : org = 0x40100000, len = 32K
15+
irom0_0_seg : org = 0x40209000, len = 572K
16+
}
17+
18+
/* define common sections and symbols */
19+
INCLUDE boards/esp8266_common.ld

ports/esp8266/boards/esp8266_2m.ld

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* GNU linker script for ESP8266 with 2M or more flash
2+
3+
Flash layout:
4+
0x40200000 36k header + iram/dram init
5+
0x40209000 988k firmware (irom0)
6+
0x40300000 1M+ filesystem (not memory mapped)
7+
*/
8+
9+
MEMORY
10+
{
11+
dport0_0_seg : org = 0x3ff00000, len = 16
12+
dram0_0_seg : org = 0x3ffe8000, len = 80K
13+
iram1_0_seg : org = 0x40100000, len = 32K
14+
irom0_0_seg : org = 0x40209000, len = 1M - 36K
15+
}
16+
17+
/* define common sections and symbols */
18+
INCLUDE boards/esp8266_common.ld

ports/esp8266/boards/esp8266_512k.ld

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
/* GNU linker script for ESP8266 */
1+
/* GNU linker script for ESP8266 with 512K flash
2+
3+
Flash layout:
4+
0x40200000 36k header + iram/dram init
5+
0x40209000 456k firmware (irom0)
6+
0x4027b000 20k SDK parameters
7+
*/
28

39
MEMORY
410
{
5-
dport0_0_seg : org = 0x3ff00000, len = 0x10
6-
dram0_0_seg : org = 0x3ffe8000, len = 0x14000
7-
iram1_0_seg : org = 0x40100000, len = 0x8000
8-
irom0_0_seg : org = 0x40209000, len = 0x72000
11+
dport0_0_seg : org = 0x3ff00000, len = 16
12+
dram0_0_seg : org = 0x3ffe8000, len = 80K
13+
iram1_0_seg : org = 0x40100000, len = 32K
14+
irom0_0_seg : org = 0x40209000, len = 512K - 36K - 20K
915
}
1016

1117
/* define common sections and symbols */

ports/esp8266/modules/flashbdev.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,23 @@
22

33

44
class FlashBdev:
5-
65
SEC_SIZE = 4096
7-
RESERVED_SECS = 1
8-
START_SEC = esp.flash_user_start() // SEC_SIZE + RESERVED_SECS
9-
NUM_BLK = 0x6B - RESERVED_SECS
106

11-
def __init__(self, blocks=NUM_BLK):
7+
def __init__(self, start_sec, blocks):
8+
self.start_sec = start_sec
129
self.blocks = blocks
1310

1411
def readblocks(self, n, buf, off=0):
1512
# print("readblocks(%s, %x(%d), %d)" % (n, id(buf), len(buf), off))
16-
esp.flash_read((n + self.START_SEC) * self.SEC_SIZE + off, buf)
13+
esp.flash_read((n + self.start_sec) * self.SEC_SIZE + off, buf)
1714

1815
def writeblocks(self, n, buf, off=None):
1916
# print("writeblocks(%s, %x(%d), %d)" % (n, id(buf), len(buf), off))
2017
# assert len(buf) <= self.SEC_SIZE, len(buf)
2118
if off is None:
22-
esp.flash_erase(n + self.START_SEC)
19+
esp.flash_erase(n + self.start_sec)
2320
off = 0
24-
esp.flash_write((n + self.START_SEC) * self.SEC_SIZE + off, buf)
21+
esp.flash_write((n + self.start_sec) * self.SEC_SIZE + off, buf)
2522

2623
def ioctl(self, op, arg):
2724
# print("ioctl(%d, %r)" % (op, arg))
@@ -30,13 +27,16 @@ def ioctl(self, op, arg):
3027
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
3128
return self.SEC_SIZE
3229
if op == 6: # MP_BLOCKDEV_IOCTL_BLOCK_ERASE
33-
esp.flash_erase(arg + self.START_SEC)
30+
esp.flash_erase(arg + self.start_sec)
3431
return 0
3532

3633

3734
size = esp.flash_size()
3835
if size < 1024 * 1024:
3936
bdev = None
4037
else:
38+
start_sec = esp.flash_user_start() // FlashBdev.SEC_SIZE
39+
if start_sec < 256:
40+
start_sec += 1 # Reserve space for native code
4141
# 20K at the flash end is reserved for SDK params storage
42-
bdev = FlashBdev((size - 20480) // FlashBdev.SEC_SIZE - FlashBdev.START_SEC)
42+
bdev = FlashBdev(start_sec, (size - 20480) // FlashBdev.SEC_SIZE - start_sec)

ports/esp8266/modules/inisetup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def setup():
4545
check_bootsec()
4646
print("Performing initial setup")
4747
wifi()
48-
uos.VfsFat.mkfs(bdev)
49-
vfs = uos.VfsFat(bdev)
48+
uos.VfsLfs2.mkfs(bdev)
49+
vfs = uos.VfsLfs2(bdev)
5050
uos.mount(vfs, "/")
5151
with open("boot.py", "w") as f:
5252
f.write(

0 commit comments

Comments
 (0)
0