blob: 1d120b920d7bded9c84971326d917772ed2d7ec0 [file] [log] [blame]
Paul Sokolovsky40f5ecd2016-04-12 00:37:04 +03001import esp
2
3class FlashBdev:
4
5 SEC_SIZE = 4096
6 START_SEC = 0xa0000 // SEC_SIZE
7 NUM_BLK = 64
8
9 def __init__(self, blocks=NUM_BLK):
10 self.blocks = blocks
11
12 def readblocks(self, n, buf):
13 print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
14 esp.flash_read((n + self.START_SEC) * self.SEC_SIZE, buf)
15
16 def writeblocks(self, n, buf):
17 print("writeblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
18 assert len(buf) <= self.SEC_SIZE, len(buf)
19 esp.flash_erase(n + self.START_SEC)
20 esp.flash_write((n + self.START_SEC) * self.SEC_SIZE, buf)
21
22 def ioctl(self, op, arg):
23 print("ioctl(%d, %r)" % (op, arg))
24 if op == 4: # BP_IOCTL_SEC_COUNT
25 return self.blocks
26 if op == 5: # BP_IOCTL_SEC_SIZE
27 return self.SEC_SIZE
28
29bdev = FlashBdev()