From 6eee5413ff10a5e60ffd797d78a090c7edc6268e Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 7 Nov 2019 18:43:37 +1100 Subject: [PATCH] esp8266/modules/flashbdev.py: Support extended block protocol. --- ports/esp8266/modules/flashbdev.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/ports/esp8266/modules/flashbdev.py b/ports/esp8266/modules/flashbdev.py index 80ddcfbf91..4273b2639c 100644 --- a/ports/esp8266/modules/flashbdev.py +++ b/ports/esp8266/modules/flashbdev.py @@ -10,15 +10,17 @@ class FlashBdev: def __init__(self, blocks=NUM_BLK): self.blocks = blocks - def readblocks(self, n, buf): - #print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf))) - esp.flash_read((n + self.START_SEC) * self.SEC_SIZE, buf) + 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) - def writeblocks(self, n, buf): - #print("writeblocks(%s, %x(%d))" % (n, id(buf), len(buf))) + def writeblocks(self, n, buf, off=None): + #print("writeblocks(%s, %x(%d), %d)" % (n, id(buf), len(buf), off)) #assert len(buf) <= self.SEC_SIZE, len(buf) - esp.flash_erase(n + self.START_SEC) - esp.flash_write((n + self.START_SEC) * self.SEC_SIZE, buf) + 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) def ioctl(self, op, arg): #print("ioctl(%d, %r)" % (op, arg)) @@ -26,6 +28,9 @@ class FlashBdev: return self.blocks if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE return self.SEC_SIZE + if op == 6: # MP_BLOCKDEV_IOCTL_BLOCK_ERASE + esp.flash_erase(arg + self.START_SEC) + return 0 size = esp.flash_size() if size < 1024*1024: