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 17:37:04 -04:00
|
|
|
import esp
|
|
|
|
|
|
|
|
class FlashBdev:
|
|
|
|
|
|
|
|
SEC_SIZE = 4096
|
2017-05-12 09:08:54 -04:00
|
|
|
RESERVED_SECS = 1
|
2017-01-04 07:47:09 -05: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 17:37:04 -04:00
|
|
|
|
|
|
|
def __init__(self, blocks=NUM_BLK):
|
|
|
|
self.blocks = blocks
|
|
|
|
|
2019-11-07 02:43:37 -05:00
|
|
|
def readblocks(self, n, buf, off=0):
|
|
|
|
#print("readblocks(%s, %x(%d), %d)" % (n, id(buf), len(buf), off))
|
|
|
|
esp.flash_read((n + self.START_SEC) * self.SEC_SIZE + off, 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 17:37:04 -04:00
|
|
|
|
2019-11-07 02:43:37 -05:00
|
|
|
def writeblocks(self, n, buf, off=None):
|
|
|
|
#print("writeblocks(%s, %x(%d), %d)" % (n, id(buf), len(buf), off))
|
2016-04-19 17:35:46 -04:00
|
|
|
#assert len(buf) <= self.SEC_SIZE, len(buf)
|
2019-11-07 02:43:37 -05:00
|
|
|
if off is None:
|
|
|
|
esp.flash_erase(n + self.START_SEC)
|
|
|
|
off = 0
|
|
|
|
esp.flash_write((n + self.START_SEC) * self.SEC_SIZE + off, 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 17:37:04 -04:00
|
|
|
|
|
|
|
def ioctl(self, op, arg):
|
2016-04-19 17:35:46 -04:00
|
|
|
#print("ioctl(%d, %r)" % (op, arg))
|
2019-10-28 21:25:30 -04:00
|
|
|
if op == 4: # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
|
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 17:37:04 -04:00
|
|
|
return self.blocks
|
2019-10-28 21:25:30 -04:00
|
|
|
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
|
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 17:37:04 -04:00
|
|
|
return self.SEC_SIZE
|
2019-11-07 02:43:37 -05:00
|
|
|
if op == 6: # MP_BLOCKDEV_IOCTL_BLOCK_ERASE
|
|
|
|
esp.flash_erase(arg + self.START_SEC)
|
|
|
|
return 0
|
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 17:37:04 -04:00
|
|
|
|
2016-04-25 18:36:32 -04:00
|
|
|
size = esp.flash_size()
|
|
|
|
if size < 1024*1024:
|
2016-04-18 10:14:00 -04:00
|
|
|
bdev = None
|
|
|
|
else:
|
2016-08-06 08:21:49 -04:00
|
|
|
# 20K at the flash end is reserved for SDK params storage
|
|
|
|
bdev = FlashBdev((size - 20480) // FlashBdev.SEC_SIZE - FlashBdev.START_SEC)
|