diff options
author | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2018-02-14 00:22:16 +0300 |
---|---|---|
committer | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2018-02-14 00:22:16 +0300 |
commit | 6dfed02838c04e499e287dcc32c15e655664283d (patch) | |
tree | 26774f200eeb1af3af38a45e4207c198560b04fe /mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0040_usb | |
parent | 1923b2d55a0266c945364764df4e1d97b402c4d9 (diff) |
Many changes, updated to madmonkey's hakchi, zImage support, USB host support
Diffstat (limited to 'mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0040_usb')
-rw-r--r-- | mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0040_usb | 195 |
1 files changed, 114 insertions, 81 deletions
diff --git a/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0040_usb b/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0040_usb index 786d6f36..ddfffdb4 100644 --- a/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0040_usb +++ b/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0040_usb @@ -1,81 +1,114 @@ -disableUsbDevice(){
- #disable usb
- echo 0 > "/sys/devices/sunxi_usb/usb_role"
-}
-
-switchToUsbDevice(){
- echo Switching to USB device mode
- disableUsbDevice
-
- # enable device mode
- echo 2 > "/sys/devices/sunxi_usb/usb_role"
-
- # make sure the usb gadgets are disabled
- echo 0 > "/sys/devices/virtual/android_usb/android0/enable"
-}
-
-switchToUsbHost(){
- echo Switching to USB host mode
- # make sure the usb gadgets are disabled
- echo 0 > "/sys/devices/virtual/android_usb/android0/enable"
-
- disableUsbDevice
-
- # enable host mode
- echo 1 > "/sys/devices/sunxi_usb/usb_role"
-}
-
-checkUsbStorage(){
- local disk="/dev/sda1"
-
- local timeout=5
- while [ $timeout -gt 0 ] && ! [ -b "$disk" ]; do
- echo "waiting for media $timeout"
- let timeout=timeout-1
- sleep 1
- done
-
- [ -b "$disk" ] || return 1
-
- local ro="defaults,nosuid,nodev,noatime,ro"
- local rw="defaults,nosuid,nodev,noatime,rw"
- mount -o $ro "$disk" "$mountpoint/media" || return 1
-
- local saves="$modname/saves"
-
- if [ -d "$mountpoint/media/$saves" ] || [ -d "$mountpoint/media/$modname/transfer" ] || [ "$cfg_usb_rw" == "y" ]; then
- mount -o remount,$rw "$disk"
- fi
- [ -d "$mountpoint/media/$saves" ] && mount_bind "$mountpoint/media/$saves" "$mountpoint/var/lib/clover/profiles/0"
-
- local bootlogo0="boot.png"
- local bootlogo1="$mountpoint/media/$modname/$bootlogo0"
- local bootlogo2="$rootfs/etc/$bootlogo0"
- if [ -f "$bootlogo1" ]; then
- rsync -ac "$bootlogo1" "$bootlogo2"
- showImage "$bootlogo2"
- cfg_boot_logo=''
- else
- [ -f "$bootlogo2" ] && rm "$bootlogo2" && source "$preinit.d/p7010_bootlogo"
- fi
-
- return 0
-}
-
-checkUsbGamepath(){
- local disk="/dev/sda1"
- [ -b "$disk" ] || return 1
-
- local games="$modname/games"
- if containsGames "$mountpoint/media/$games"; then
- if ! mkdir -p "$rootfs$gamepath"; then
- rm -rf "$rootfs$gamepath"
- mkdir -p "$rootfs$gamepath" || return 1
- fi
- mount_bind "$mountpoint/media/$games" "$rootfs$gamepath"
- return 0
- else
- echo "no romz found at: $disk:/$games"
- return 1
- fi
-}
+disableUsbDevice(){ + #disable usb + [ -f "/sys/devices/sunxi_usb/usb_role" ] || return 1 + echo 0 > "/sys/devices/sunxi_usb/usb_role" +} + +switchToUsbDevice(){ + [ -f "/sys/devices/sunxi_usb/usb_role" ] || return 1 + disableUsbDevice + # enable device mode + echo 2 > "/sys/devices/sunxi_usb/usb_role" + # make sure the usb gadgets are disabled + echo 0 > "/sys/devices/virtual/android_usb/android0/enable" +} + +switchToUsbHost(){ + [ -f "/sys/devices/sunxi_usb/usb_role" ] || return 1 + # make sure the usb gadgets are disabled + [ -f "/sys/devices/virtual/android_usb/android0/enable" ] && \ + echo 0 > "/sys/devices/virtual/android_usb/android0/enable" + disableUsbDevice + # enable host mode + echo 1 > "/sys/devices/sunxi_usb/usb_role" +} + +getUsbStorageIds(){ + find "/dev/bus/usb" -type c | while read device + do + hexdump -n 1 -s 32 "$device" -C | grep -e '^00000020 08' && echo "$device" + done +} + +waitForUsbDevice(){ + [ -z "$(getUsbStorageIds)" ] && return 1 + local blockDevice="$1" + local timeout=5 + while [ $timeout -gt 0 ] && ! [ -b "$blockDevice" ]; do + echo "waiting for media $timeout" + let timeout=timeout-1 + sleep 1 + done + [ -b "$blockDevice" ] +} + +checkStorageDevice(){ + local blockDevice="$1" + [ -b "$blockDevice" ] || return 1 + + local ro="defaults,nosuid,nodev,noatime,ro" + local rw="defaults,nosuid,nodev,noatime,rw" + local games="$modname/games" + local saves="$modname/saves" + + if ! [ "$cfg_usb_rw" == "y" ]; then + mount -o $ro "$blockDevice" "$mountpoint/media" || return 1 + fi + + local need_repair="" + [ -d "$mountpoint/media/$games" ] && ! [ -z "$(find $mountpoint/media/$games -name .repair.flag -maxdepth 2)" ] && need_repair=y + + if [ -d "$mountpoint/media/$saves" ] || [ -d "$mountpoint/media/$modname/transfer" ] || [ "$cfg_usb_rw" == "y" ] || [ "$need_repair" == "y" ]; then + umount "$mountpoint/media" 2>/dev/null + mount -o $rw "$blockDevice" "$mountpoint/media" || return 1 + fi + + if ! [ -d "$mountpoint/media/$modname" ]; then + umount "$mountpoint/media" + return 1 + fi + + [ -d "$mountpoint/media/$saves" ] && mount_bind "$mountpoint/media/$saves" "$mountpoint$profilepath" + + local bootlogo0="boot.png" + local bootlogo1="$mountpoint/media/$modname/$bootlogo0" + local bootlogo2="$rootfs/etc/$bootlogo0" + if [ -f "$bootlogo1" ]; then + rsync -ac "$bootlogo1" "$bootlogo2" + showImage "$bootlogo2" + cfg_boot_logo='' + else + [ -f "$bootlogo2" ] && rm -f "$bootlogo2" && source "$preinit.d/p7010_bootlogo" + fi + + local bootsound0="boot.wav" + local bootsound1="$mountpoint/media/$modname/$bootsound0" + local bootsound2="$rootfs/etc/$bootsound0" + if [ -f "$bootsound1" ]; then + [ -f "$bootsound2" ] || playSound "$bootsound1" + rsync -ac "$bootsound1" "$bootsound2" + else + rm -f "$bootsound2" + fi + + return 0 +} + +checkExtStorage(){ + local di + local d + local p + local blockDevice="/dev/sd" + waitForUsbDevice "${blockDevice}a1" + for di in $(seq 97 99); do + d="$(printf "\\$(printf %o $di)\n")" + for p in $(seq 1 9); do + checkStorageDevice "$blockDevice$d$p" && return 0 + done + done + blockDevice="/dev/mmcblk0p" + for p in $(seq 1 9); do + checkStorageDevice "$blockDevice$p" && return 0 + done + return 1 +} |