esp8266: Add Python modules for initial configuration.
Main entry point is _boot.py which checks whether FAT FS in flash mountable,
and if so, mounts it. Otherwise, it checks if flash is empty, and if so,
performs initial module setup: makes FAT FS, configures default AP name,
etc. As a last option, if flash is not empty, and could not be mounted,
it means filesystem corruption, and warning message with instructions is
printed in an infinite loop.
2016-04-11 22:37:04 +01:00
|
|
|
import esp
|
|
|
|
|
|
|
|
class FlashBdev:
|
|
|
|
|
|
|
|
SEC_SIZE = 4096
|
2017-05-12 14:08:54 +01:00
|
|
|
RESERVED_SECS = 1
|
2017-01-04 12:47:09 +00:00
|
|
|
START_SEC = esp.flash_user_start() // SEC_SIZE + RESERVED_SECS
|
|
|
|
NUM_BLK = 0x6b - RESERVED_SECS
|
esp8266: Add Python modules for initial configuration.
Main entry point is _boot.py which checks whether FAT FS in flash mountable,
and if so, mounts it. Otherwise, it checks if flash is empty, and if so,
performs initial module setup: makes FAT FS, configures default AP name,
etc. As a last option, if flash is not empty, and could not be mounted,
it means filesystem corruption, and warning message with instructions is
printed in an infinite loop.
2016-04-11 22:37:04 +01:00
|
|
|
|
|
|
|
def __init__(self, blocks=NUM_BLK):
|
|
|
|
self.blocks = blocks
|
|
|
|
|
|
|
|
def readblocks(self, n, buf):
|
2016-04-19 22:35:46 +01:00
|
|
|
#print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
|
esp8266: Add Python modules for initial configuration.
Main entry point is _boot.py which checks whether FAT FS in flash mountable,
and if so, mounts it. Otherwise, it checks if flash is empty, and if so,
performs initial module setup: makes FAT FS, configures default AP name,
etc. As a last option, if flash is not empty, and could not be mounted,
it means filesystem corruption, and warning message with instructions is
printed in an infinite loop.
2016-04-11 22:37:04 +01:00
|
|
|
esp.flash_read((n + self.START_SEC) * self.SEC_SIZE, buf)
|
|
|
|
|
|
|
|
def writeblocks(self, n, buf):
|
2016-04-19 22:35:46 +01:00
|
|
|
#print("writeblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
|
|
|
|
#assert len(buf) <= self.SEC_SIZE, len(buf)
|
esp8266: Add Python modules for initial configuration.
Main entry point is _boot.py which checks whether FAT FS in flash mountable,
and if so, mounts it. Otherwise, it checks if flash is empty, and if so,
performs initial module setup: makes FAT FS, configures default AP name,
etc. As a last option, if flash is not empty, and could not be mounted,
it means filesystem corruption, and warning message with instructions is
printed in an infinite loop.
2016-04-11 22:37:04 +01:00
|
|
|
esp.flash_erase(n + self.START_SEC)
|
|
|
|
esp.flash_write((n + self.START_SEC) * self.SEC_SIZE, buf)
|
|
|
|
|
|
|
|
def ioctl(self, op, arg):
|
2016-04-19 22:35:46 +01:00
|
|
|
#print("ioctl(%d, %r)" % (op, arg))
|
esp8266: Add Python modules for initial configuration.
Main entry point is _boot.py which checks whether FAT FS in flash mountable,
and if so, mounts it. Otherwise, it checks if flash is empty, and if so,
performs initial module setup: makes FAT FS, configures default AP name,
etc. As a last option, if flash is not empty, and could not be mounted,
it means filesystem corruption, and warning message with instructions is
printed in an infinite loop.
2016-04-11 22:37:04 +01:00
|
|
|
if op == 4: # BP_IOCTL_SEC_COUNT
|
|
|
|
return self.blocks
|
|
|
|
if op == 5: # BP_IOCTL_SEC_SIZE
|
|
|
|
return self.SEC_SIZE
|
|
|
|
|
2016-04-25 23:36:32 +01:00
|
|
|
size = esp.flash_size()
|
|
|
|
if size < 1024*1024:
|
2016-04-18 15:14:00 +01:00
|
|
|
bdev = None
|
|
|
|
else:
|
2016-08-06 13:21:49 +01:00
|
|
|
# 20K at the flash end is reserved for SDK params storage
|
|
|
|
bdev = FlashBdev((size - 20480) // FlashBdev.SEC_SIZE - FlashBdev.START_SEC)
|