mmc2.py 1.3 KB

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