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 | |
parent | 1923b2d55a0266c945364764df4e1d97b402c4d9 (diff) |
Many changes, updated to madmonkey's hakchi, zImage support, USB host support
Diffstat (limited to 'mods')
20 files changed, 355 insertions, 165 deletions
diff --git a/mods/hmods/core-modules.hmod b/mods/hmods/core-modules.hmod Binary files differdeleted file mode 100644 index ca8247a1..00000000 --- a/mods/hmods/core-modules.hmod +++ /dev/null diff --git a/mods/hmods/modules-3.4.112.madmonkey.hmod b/mods/hmods/modules-3.4.112.madmonkey.hmod Binary files differnew file mode 100644 index 00000000..3419c1a8 --- /dev/null +++ b/mods/hmods/modules-3.4.112.madmonkey.hmod diff --git a/mods/hmods/ntfs-3g.hmod b/mods/hmods/ntfs-3g.hmod Binary files differnew file mode 100644 index 00000000..558d5b58 --- /dev/null +++ b/mods/hmods/ntfs-3g.hmod diff --git a/mods/mod_hakchi/bin/busybox b/mods/mod_hakchi/bin/busybox Binary files differindex 0cf516b5..f2a314ff 100755 --- a/mods/mod_hakchi/bin/busybox +++ b/mods/mod_hakchi/bin/busybox diff --git a/mods/mod_hakchi/etc/filesystems b/mods/mod_hakchi/etc/filesystems new file mode 100644 index 00000000..2b8cb984 --- /dev/null +++ b/mods/mod_hakchi/etc/filesystems @@ -0,0 +1,37 @@ +nodev sysfs +nodev rootfs +nodev bdev +nodev proc +nodev tmpfs +nodev devtmpfs +nodev binfmt_misc +nodev sockfs +nodev usbfs +nodev pipefs +nodev anon_inodefs +nodev rpc_pipefs +nodev configfs +nodev devpts + ext3 + ext2 + ext4 + cramfs + squashfs +nodev ramfs + vfat + msdos + iso9660 +nodev nfs +nodev nfs4 +nodev cifs +nodev autofs + fuseblk +nodev fuse +nodev fusectl +nodev overlayfs + udf +nodev mqueue +nodev functionfs +nodev oprofilefs + ntfs + exfat diff --git a/mods/mod_hakchi/hakchi/config b/mods/mod_hakchi/hakchi/config index 6e90132e..6cefdfe6 100644 --- a/mods/mod_hakchi/hakchi/config +++ b/mods/mod_hakchi/hakchi/config @@ -1,5 +1,4 @@ -local cf_backup_dummy='n' -local cf_backup='n' -local cf_backup_nandc='n' -local cf_shutdown='n' -local cf_usb='y' +export cf_backup_dummy='n' +export cf_backup='n' +export cf_backup_nandc='n' +export cf_shutdown='r' diff --git a/mods/mod_hakchi/hakchi/init b/mods/mod_hakchi/hakchi/init index 50fc66a4..023db13a 100644 --- a/mods/mod_hakchi/hakchi/init +++ b/mods/mod_hakchi/hakchi/init @@ -6,6 +6,7 @@ init(){ export modpath="/$modname" export mountpoint="/newroot" export temppath="/tmp" + echo "$modname init script version: 1.0" /bin/busybox --install -s /bin/ mkdir -p "$temppath" @@ -18,15 +19,15 @@ init(){ source "$modpath/script/base" if [ -d "$modpath/transfer" ]; then - export cf_usb='n' source "$modpath/script/transfer" else mount_base fi if [ -f "$preinit" ]; then + export preinit PATH="$rootfs/sbin:$rootfs/usr/sbin:$rootfs/bin:$rootfs/usr/bin:$PATH" - "$rootfs/bin/busybox" sh -c "source "$preinit.d/b0000_defines" && source "$preinit" && preinit" + "$rootfs/bin/busybox" sh -c "source "$preinit" && preinit" else umount_base fi diff --git a/mods/mod_hakchi/hakchi/rootfs/bin/chmenu b/mods/mod_hakchi/hakchi/rootfs/bin/chmenu index 3ad32b84..921709ca 100755 --- a/mods/mod_hakchi/hakchi/rootfs/bin/chmenu +++ b/mods/mod_hakchi/hakchi/rootfs/bin/chmenu @@ -2,34 +2,27 @@ source /etc/preinit script_init -state_file="$installpath/menu" +state_path="/var/saves/$modname" +state_file="$state_path/menu" [ -z "$1" ] && exit 1 [ -f "$state_file" ] && prev_code="$(cat "$state_file")" || prev_code="000" [ "$1" == "$prev_code" ] && exit 1 echo "Switching to menu $1" -if [ "$1" == "000" ]; then - targetpath="$rootfs$gamepath" -else - targetpath="$rootfs$gamepath/$1" +gameStorage="$(findGameStorage)" +targetpath="$gameStorage/$1" +if ! containsGames "$targetpath"; then + [ "$1" == "000" ] || exit 1 + targetpath="$gameStorage" + containsGames "$targetpath" || exit 1 fi -[ -d "$targetpath" ] || exit 1 +mkdir -p "$state_path" echo "$1" > "$state_file" echo "New directory: $targetpath" - -if [ "$1" != "000" ]; then - if [ -f "$rootfs$gamepath/title.fnt" ] && [ ! -f "$targetpath/title.fnt" ]; then - ln -s "$rootfs$gamepath/title.fnt" "$targetpath/title.fnt" - fi - if [ -f "$rootfs$gamepath/copyright.fnt" ] && [ ! -f "$targetpath/copyright.fnt" ]; then - ln -s "$rootfs$gamepath/copyright.fnt" "$targetpath/copyright.fnt" - fi -fi - uistop -overmount_games +overmount_games "$1" sleep 1 touch "/var/startmcp.flag" diff --git a/mods/mod_hakchi/hakchi/rootfs/bin/hsqs b/mods/mod_hakchi/hakchi/rootfs/bin/hsqs index 800c4567..041654fc 100755 --- a/mods/mod_hakchi/hakchi/rootfs/bin/hsqs +++ b/mods/mod_hakchi/hakchi/rootfs/bin/hsqs @@ -6,7 +6,7 @@ echo "current firmware: $(currentFirmware)" printSoftwareInfo firmware="$1" -if [ "$firmware" != "_nand_" ]; then +if [ "$firmware" != "auto" ] && [ "$firmware" != "_nand_" ]; then firmware="$(echo "$firmware" | sed -re 's/^\/usr\/share\/games\/(nes\/kachikachi\/)?/\/var\/games\//')" firmware="$(readlink -f "$firmware")" checkFirmware "$firmware" || exit 1 @@ -17,6 +17,7 @@ cfg_firmware="$firmware" save_config [ "$(currentFirmware)" == "$firmware" ] && exit 0 +[ "$(currentFirmware)" == "auto" ] && exit 0 #? echo "changing firmware to: $firmware" reboot diff --git a/mods/mod_hakchi/hakchi/rootfs/etc/pleasewait.fb b/mods/mod_hakchi/hakchi/rootfs/etc/pleasewait.fb Binary files differnew file mode 100644 index 00000000..2826ef40 --- /dev/null +++ b/mods/mod_hakchi/hakchi/rootfs/etc/pleasewait.fb diff --git a/mods/mod_hakchi/hakchi/rootfs/etc/pleasewait.png b/mods/mod_hakchi/hakchi/rootfs/etc/pleasewait.png Binary files differnew file mode 100644 index 00000000..229e0fd3 --- /dev/null +++ b/mods/mod_hakchi/hakchi/rootfs/etc/pleasewait.png diff --git a/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0000_defines b/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0000_defines index 684054df..c774d8c6 100644 --- a/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0000_defines +++ b/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0000_defines @@ -3,11 +3,13 @@ modpath="/$modname" #mountpoint="/newroot" installpath="$mountpoint/var/lib/$modname" firmwarepath="$installpath/firmware" +extfirmwarepath="$mountpoint/media/$modname/firmware" rootfs="$installpath/rootfs" -squashfs="$installpath/squashfs" +squashfs="$mountpoint/var/squashfs" preinit="$rootfs/etc/preinit" preinitpath="$preinit.d" sftype="" sfregion="" gamepath="" +profilepath="/var/lib/clover/profiles/0" temppath="/tmp" diff --git a/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0010_functions b/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0010_functions index 7ec99650..cb5c9e15 100644 --- a/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0010_functions +++ b/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0010_functions @@ -75,7 +75,10 @@ remount_root(){ mount_move l media mount_move l var + stopTask decodepng + stopTask aplay umount "$mountpoint" + local loopfile="/var${1##$mountpoint/var}" [ -f "$loopfile" ] || loopfile="/media${1##$mountpoint/media}" if ! mount -o loop,ro,noatime "$loopfile" "$mountpoint"; then @@ -97,7 +100,7 @@ checkFirmware(){ } currentFirmware(){ - local firmware="$(losetup | awk '{print $3'})" + local firmware="$(losetup -a | awk '{print $3'})" if ! [ -z "$firmware" ]; then echo "$firmware" return 0 @@ -109,14 +112,28 @@ currentFirmware(){ return 1 } +overmountModules(){ + if [ ! -d "$mountpoint/lib/modules/$(uname -r)" ]; then + if [ -d "$rootfs/lib/modules/$(uname -r)" ]; then + overmount "/lib/modules" + else + echo "no modules for loaded kernel $(uname -r)" + fi + fi +} + loadFirmware(){ [ -z "$(mount | grep -F loop0)" ] || return 1 local firmware="$mountpoint$cfg_firmware" if ! checkFirmware "$firmware"; then [ "$cfg_firmware" == "auto" ] || return 0 - [ -d "$firmwarepath" ] || return 0 - firmware="$(find "$firmwarepath" -type f -name "*.hsqs" | sort | head -n 1)" + [ -d "$extfirmwarepath" ] && \ + firmware="$(find "$extfirmwarepath" -type f -name "*.hsqs" | sort | head -n1)" + if ! checkFirmware "$firmware"; then + [ -d "$firmwarepath" ] && \ + firmware="$(find "$firmwarepath" -type f -name "*.hsqs" | sort | head -n1)" + fi fi checkFirmware "$firmware" || return 0 @@ -125,13 +142,7 @@ loadFirmware(){ remount_root "$firmware" cryptsetup close root-crypt mountSquash - if [ ! -d "$mountpoint/lib/modules/$(uname -r)" ]; then - if [ -d "$rootfs/lib/modules/$(uname -r)" ]; then - overmount "/lib/modules" - else - echo "no modules for loaded kernel $(uname -r)" - fi - fi + overmountModules } shutdown(){ @@ -181,6 +192,8 @@ restore(){ mount_bind(){ if mountpoint -q "$2"; then umount "$2" || umount -f "$2" + else + umount "$2" 2>/dev/null fi mount -o bind "$1" "$2" } @@ -205,7 +218,7 @@ containsGames(){ } linkGames(){ - local games="$mountpoint/media/$modname/games${1##$rootfs$gamepath}" + local games="$mountpoint/media/$modname/games${1##$installpath/games}" [ -d "$games" ] || games="$installpath/games${1##$rootfs$gamepath}" [ -d "$games" ] || games="$1" games="${games##$mountpoint}" @@ -221,7 +234,7 @@ softwareCheck(){ [ "$(cat "$mountpoint/etc/clover/REGION")" == "JPN" ] && sfregion="jpn" [ "$(cat "$mountpoint/etc/clover/REGION")" == "EUR" ] && sfregion="eur" - local feck="$mountpoint/var/lib/clover/profiles/0/home-menu/save/system-save.json" + local feck="$mountpoint$profilepath/home-menu/save/system-save.json" if [ "$sftype" == "snes" ]; then gamepath="/usr/share/games" [ -f "$feck" ] && mv -f "$feck" "$feck.nes" @@ -231,31 +244,35 @@ softwareCheck(){ [ -d "$feck" ] && rm -rf "$feck.snes" && mv "$feck" "$feck.snes" [ -f "$feck.nes" ] && mv -f "$feck.nes" "$feck" fi - + + mkdir -p "$mountpoint$profilepath/$modname" + rm -f "$mountpoint/var/saves" - ln -s "/var/lib/clover/profiles/0" "$mountpoint/var/saves" + ln -s "$profilepath" "$mountpoint/var/saves" } repair_fonts(){ if [ "$sftype" == "nes" ]; then mkdir -p "$1" || return 1 - [ ! -f "$1/title.fnt" ] && (cp $rootfs$gamepath/title.fnt "$1" || cp $squashfs$gamepath/title.fnt "$1") - [ ! -f "$1/copyright.fnt" ] && (cp $rootfs$gamepath/copyright.fnt "$1" || cp $squashfs$gamepath/copyright.fnt "$1") + [ ! -f "$1/title.fnt" ] && copy "$squashfs$gamepath/title.fnt" "$1/" + [ ! -f "$1/copyright.fnt" ] && copy "$squashfs$gamepath/copyright.fnt" "$1/" fi } repair_games(){ [ -w "$1" ] || return 0 + [ -f "$1/.repair.flag" ] || return 0 + cat "$rootfs/etc/pleasewait.fb" | gunzip -c - > "/dev/fb0" local usesymlink='' - ln -s / "$1/symlinktest" && rm "$1/symlinktest" && usesymlink='y' - + ln -s / "$1/symlinktest" 2>/dev/null && rm -f "$1/symlinktest" && usesymlink='y' + ls -1 "$squashfs$gamepath" | grep CLV- | while read code do - local gamedir="$1/$code" + local gamedir=$(find "$1" -name $code -type d) local squashgamedir="$squashfs$gamepath/$code" - + [ -d "$gamedir" ] || continue - + if [ ! -f "$gamedir/$code.desktop" ]; then cp "$squashgamedir/$code.desktop" "$gamedir/" [ "$sftype" == "nes" ] && \ @@ -263,10 +280,10 @@ repair_games(){ [ "$sftype" == "snes" ] && \ sed -i -e 's#/usr/bin/clover-canoe-shvc#/bin/clover-canoe-shvc-wr#g' "$gamedir/$code.desktop" fi - - [ -d "$gamedir/autoplay/" ] && ([ "$(ls -A "$gamedir/autoplay/")" ] || rm -r "$gamedir/autoplay/") - [ -d "$gamedir/pixelart/" ] && ([ "$(ls -A "$gamedir/pixelart/")" ] || rm -r "$gamedir/pixelart/") - + + [ -d "$gamedir/autoplay/" ] && ([ "$(ls -A "$gamedir/autoplay/")" ] || rm -rf "$gamedir/autoplay/") + [ -d "$gamedir/pixelart/" ] && ([ "$(ls -A "$gamedir/pixelart/")" ] || rm -rf "$gamedir/pixelart/") + find "$squashgamedir" -maxdepth 1 | sed -n '1!p' | while read squashfile do if [ "$usesymlink" == "y" ]; then @@ -276,19 +293,58 @@ repair_games(){ fi done done - sync - return 0 + + ls -1 "$1" | while read f; do repair_fonts "$1/$f"; done + + rm -f "$1/.repair.flag" && sync && reboot +} + +checkGamepath(){ + containsGames "$1" && echo "$1" && return 0 + containsGames "$1/000" && echo "$1" && return 0 + return 1 +} + +checkPath(){ + [ -d "$1" ] && echo "$1" && return 0 + return 1 +} + +findGameSyncStorage(){ + checkPath "$mountpoint/media/hakchi/games" && return 0 + mkdir -p "$installpath/games" + checkPath "$installpath/games" && return 0 + return 1 +} + +findGameStorage(){ + checkGamepath "$mountpoint/media/hakchi/games/$sftype-$sfregion" && return 0 + checkGamepath "$mountpoint/media/hakchi/games/$sftype" && return 0 + checkGamepath "$mountpoint/media/hakchi/games" && return 0 + + checkGamepath "$installpath/games/$sftype-$sfregion" && return 0 + checkGamepath "$installpath/games/$sftype" && return 0 + checkGamepath "$installpath/games" && return 0 + return 1 } overmount_games(){ - local menu_code="000" - [ -f "$installpath/menu" ] && menu_code="$(cat "$installpath/menu")" - containsGames "$rootfs$gamepath/$menu_code" || menu_code="" + local gameStorage="$(findGameStorage)" || return 0 + local state_path="$mountpoint$profilepath/$modname" + local state_file="$state_path/menu" + local menu_code="$1" + [ -z "$1" ] && menu_code="000" + [ -z "$1" ] && [ -f "$state_file" ] && menu_code="$(cat "$state_file")" + containsGames "$gameStorage/$menu_code" || menu_code="" echo "menu code: $menu_code" - if containsGames "$rootfs$gamepath/$menu_code"; then - overmount "$gamepath/$menu_code" "$gamepath" && repair_games "$rootfs$gamepath/$menu_code" && linkGames "$rootfs$gamepath/$menu_code" && return 0 + if containsGames "$gameStorage/$menu_code"; then + mount_bind "$gameStorage/$menu_code" "$mountpoint/$gamepath" && \ + repair_games "$gameStorage" + repair_fonts "$gameStorage/$menu_code" && \ + linkGames "$gameStorage/$menu_code" && \ + return 0 else - echo "no romz found at: $rootfs$gamepath/$menu_code" + echo "no romz found at: $gameStorage/$menu_code" fi linkGames "$gamepath" return 1 @@ -330,15 +386,86 @@ printSoftwareInfo(){ echo "region=$sfregion" } +stopTask(){ + local tokill="false" + if [ "$1" = "-f" ]; then + tokill="true" + shift + fi + local pid="$(pidof "$1")" + [ -z "$pid" ] && return 0 + "$tokill" && kill "$pid" + wait "$pid" +} + +waitTask(){ + local A="stopTask ${1+"$@"}" + trap "$A" EXIT +} + showImage(){ - image="$(eval echo "$1")" + local image="$(eval echo "$1")" [ -f "$image" ] || image="$rootfs$1" [ -f "$image" ] || image="$squashfs$1" [ -f "$image" ] || return 1 decodepng "$image" > "/dev/fb0" & + waitTask decodepng + return 0 +} + +playSound(){ + local wavfile="$(eval echo "$1")" + [ -f "$wavfile" ] || wavfile="$rootfs$1" + [ -f "$wavfile" ] || wavfile="$squashfs$1" + [ -f "$wavfile" ] || return 1 + aplay -q "$wavfile" & + waitTask aplay return 0 } hwmon(){ cat "/sys/devices/virtual/hwmon/hwmon1/temp1_input" } + +usedBlockSpace(){ + local path="$1" + [ -e "$path" ] || path="$rootfs" + local line="$(df -k "$path" | tail -n1)" + local used="$(echo "$line" | awk '{print $3}')" + local available="$(echo "$line" | awk '{print $4}')" + local total="$(($used+$available))" + echo "$used $total" +} + +freeBlockSpace(){ + local path="$1" + [ -e "$path" ] || path="$rootfs" + df -k "$path" | tail -n1 | awk '{print $4}' +} + +usedSpace(){ +# Warning: SLOW + local path="$1" + [ -e "$path" ] || path="$rootfs" + du -ksx "$path" | awk '{print $1}' +} + +usedBy(){ + case "$1" in + games) + usedSpace "$(findGameSyncStorage)" + ;; + saves) + usedSpace "$profilepath" + ;; + mods) + usedSpace "$rootfs" + ;; + firmware) + usedSpace "$firmwarepath" + ;; + *) + echo "Usage: usedBy {games|saves|mods|firmware}" + return 1 + esac +} diff --git a/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0020_backup b/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0020_backup index 8377e1d7..6819ccdd 100644 --- a/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0020_backup +++ b/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/b0020_backup @@ -14,7 +14,7 @@ backup_nandb(){ if [ ! -f "$nandb_filename" ]; then echo "backup $nandb_filename" dd if=/dev/mapper/root-crypt bs=4k \ - count=$((($(hexdump -e '1/4 "%u"' -s $((0x28)) -n 4 /dev/mapper/root-crypt)+0xfff)/0x1000)) \ + count="$((($(hexdump -e '1/4 "%u"' -s $((0x28)) -n 4 /dev/mapper/root-crypt)+0xfff)/0x1000))" \ > "$nandb_filename" && \ md5sum "$nandb_filename" > "$nandb_filename.md5" fi 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 +} diff --git a/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/p0000_config b/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/p0000_config index 7e99591c..00917bff 100644 --- a/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/p0000_config +++ b/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/p0000_config @@ -1,3 +1,6 @@ cfg_boot_stock='n' +cfg_disable_armet='y' cfg_firmware='auto' -cfg_usb_host='n' +cfg_nes_extra_args='' +cfg_snes_extra_args='' +cfg_usb_host='y' diff --git a/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/p7010_bootlogo b/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/p7010_bootlogo index 9675ad27..4a5e3f18 100644 --- a/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/p7010_bootlogo +++ b/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/p7010_bootlogo @@ -1 +1,2 @@ showImage "$cfg_boot_logo" || showImage "$rootfs/etc/boot.png" || showImage "$rootfs/etc/$modname.png" +playSound "$rootfs/etc/boot.wav" diff --git a/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/p7020_usb b/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/p7020_usb index 6f299d7f..43b27c24 100644 --- a/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/p7020_usb +++ b/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/p7020_usb @@ -1,13 +1,12 @@ -if [ "$cfg_usb_host" != "y" ]; then
- switchToUsbDevice
-else
- # the usb driver needs some time to initialize
- sleep 1
-
- if [ -z "$(lsusb | grep -v "1d6b:0001")" ]; then
- switchToUsbDevice
- else
- checkUsbStorage
- fi
-
-fi
+if [ "$cfg_usb_host" != "y" ]; then + switchToUsbDevice +else + switchToUsbHost + # the usb driver needs some time to initialize + sleep 1 + if [ -z "$(lsusb | grep -v "1d6b:0001")" ]; then + switchToUsbDevice + fi +fi + +checkExtStorage diff --git a/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/p7070_firmware b/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/p7070_firmware index e14653c0..ba531140 100644 --- a/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/p7070_firmware +++ b/mods/mod_hakchi/hakchi/rootfs/etc/preinit.d/p7070_firmware @@ -2,12 +2,5 @@ mod_repair_etc softwareCheck -checkUsbGamepath -if [ ! -d "$mountpoint/lib/modules/$(uname -r)" ]; then - if [ -d "$rootfs/lib/modules/$(uname -r)" ]; then - overmount "/lib/modules" - else - echo "no modules for loaded kernel $(uname -r)" - fi -fi +overmountModules diff --git a/mods/mod_hakchi/hakchi/script/transfer b/mods/mod_hakchi/hakchi/script/transfer index 6a27c7bf..82110c8f 100644 --- a/mods/mod_hakchi/hakchi/script/transfer +++ b/mods/mod_hakchi/hakchi/script/transfer @@ -68,5 +68,6 @@ transfer_path "$transferpath" echo save_config -[ "$cf_shutdown" != "y" ] || shutdown +[ "$cf_shutdown" == "y" ] && shutdown +[ "$cf_shutdown" == "r" ] && reboot echo |