inisetup.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import uos
  2. from flashbdev import bdev
  3. def check_bootsec():
  4. buf = bytearray(bdev.SEC_SIZE)
  5. bdev.readblocks(0, buf)
  6. empty = True
  7. for b in buf:
  8. if b != 0xff:
  9. empty = False
  10. break
  11. if empty:
  12. return True
  13. fs_corrupted()
  14. def fs_corrupted():
  15. import time
  16. while 1:
  17. print("""\
  18. FAT filesystem appears to be corrupted. If you had important data there, you
  19. may want to make a flash snapshot to try to recover it. Otherwise, perform
  20. factory reprogramming of MicroPython firmware (completely erase flash, followed
  21. by firmware programming).
  22. """)
  23. time.sleep(3)
  24. def setup():
  25. check_bootsec()
  26. print("Performing initial setup")
  27. uos.VfsFat.mkfs(bdev)
  28. vfs = uos.VfsFat(bdev)
  29. uos.mount(vfs, '/flash')
  30. uos.chdir('/flash')
  31. with open("boot.py", "w") as f:
  32. f.write("""\
  33. # This file is executed on every boot (including wake-boot from deepsleep)
  34. #import esp
  35. #esp.osdebug(None)
  36. #import webrepl
  37. #webrepl.start()
  38. """)
  39. return vfs