#!/usr/bin/env python3 import os import sys import time import subprocess import signal MMC2DEV=['/dev/mmcblk1p1', '/dev/mmcblk2p1', '/dev/mmcblk3p1', '/dev/mmcblk4p1'] MMC2DEBUG='/sys/kernel/debug/mmc' MODPROBE='/sbin/modprobe' def mountMMC2(): mmc_number=0 dev=None for d in MMC2DEV: mmc_number += 1 if os.path.exists(d): dev = d break if dev is not None: r=None for i in range(10): r=subprocess.run(['/bin/mount', dev, '/extSD','-o','user,ro,umask=000,iocharset=utf8,codepage=932,shortname=mixed']) if r.returncode != 0: time.sleep(1) else: break if r.returncode != 0: print('mmc' + str(mmc_number) +' mount failed.', file=sys.stderr) return False else: mmc_clock = MMC2DEBUG + str(mmc_number) + '/clock' if os.path.exists(mmc_clock): with open(mmc_clock,'w') as f: f.write('16000000') return True else: os.system(MODPROBE + ' -r mmc_spi') print('Can not find 2nd mmc', file=sys.stderr) return False def umountMMC2(): os.system('/bin/umount /extSD') return def signal_handler(signal, handler): umountMMC2() sys.exit(0) # Script starts here if __name__ == "__main__": signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) if mountMMC2(): while True: time.sleep(86400) else: sys.exit('exit mmc2.py')