Paul Sokolovsky | 40f5ecd | 2016-04-12 00:37:04 +0300 | [diff] [blame^] | 1 | import esp |
| 2 | |
| 3 | class 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 | |
| 29 | bdev = FlashBdev() |