mmc2.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python3
  2. import os
  3. import sys
  4. import time
  5. import subprocess
  6. import signal
  7. MMC2DEV=['/dev/mmcblk1p1', '/dev/mmcblk2p1', '/dev/mmcblk3p1', '/dev/mmcblk4p1']
  8. MMC2DEBUG='/sys/kernel/debug/mmc'
  9. MODPROBE='/sbin/modprobe'
  10. MOUNTPOINT='/media/extSD'
  11. def mountMMC2():
  12. mmc_number=0
  13. dev=None
  14. for d in MMC2DEV:
  15. mmc_number += 1
  16. if os.path.exists(d):
  17. dev = d
  18. break
  19. if dev is not None:
  20. r=None
  21. for i in range(10):
  22. r=subprocess.run(['/bin/mount', dev, MOUNTPOINT,'-o','user,ro,umask=000,iocharset=utf8,codepage=932,shortname=mixed'])
  23. if r.returncode != 0:
  24. time.sleep(1)
  25. else:
  26. break
  27. if r.returncode != 0:
  28. print('mmc' + str(mmc_number) +' mount failed.', file=sys.stderr)
  29. return False
  30. else:
  31. mmc_clock = MMC2DEBUG + str(mmc_number) + '/clock'
  32. if os.path.exists(mmc_clock):
  33. with open(mmc_clock,'w') as f:
  34. f.write('16000000')
  35. return True
  36. else:
  37. os.system(MODPROBE + ' -r mmc_spi')
  38. print('Can not find 2nd mmc', file=sys.stderr)
  39. return False
  40. def umountMMC2():
  41. os.system('/bin/umount '+MOUNTPOINT)
  42. return
  43. def signal_handler(signal, handler):
  44. umountMMC2()
  45. sys.exit(0)
  46. # Script starts here
  47. if __name__ == "__main__":
  48. signal.signal(signal.SIGINT, signal_handler)
  49. signal.signal(signal.SIGTERM, signal_handler)
  50. if mountMMC2():
  51. while True:
  52. time.sleep(86400)
  53. else:
  54. sys.exit('exit mmc2.py')