Skip to content
Permalink
Browse files

usb-host mode

  • Loading branch information...
madmonkey1907 committed Nov 9, 2017
1 parent ef9503c commit 33720d1cd2129b355e8a50b11b00acdc58aa31eb
@@ -7,3 +7,6 @@
[submodule "3rdparty/macdylibbundler"]
path = 3rdparty/macdylibbundler
url = https://github.com/auriamg/macdylibbundler
[submodule "3rdparty/mkbootfs"]
path = 3rdparty/mkbootfs
url = https://github.com/osm0sis/mkbootfs/
Submodule mkbootfs added at a00d39
Submodule mkbootimg updated 2 files
+112 −27 mkbootimg.c
+51 −19 unpackbootimg.c
@@ -0,0 +1,6 @@
#!/bin/sh

EXE="$(dirname "$0")/$1.exe"
[ -f "$EXE" ] || EXE="$1"
shift
exec "$EXE" ${1+"$@"}
@@ -1,5 +1,4 @@
#!/bin/bash
set -e
#!/bin/sh -e

img="$1"
if [ -z "$img" ]; then
@@ -10,8 +9,8 @@ infile="$(basename "$img")"
inpath="./$(basename "$infile" .img)"

rm -rf "$inpath"
mkdir "$inpath"
mkdir -p "$inpath"
unpackbootimg -i "$img" -o "$inpath"
lzop -d "$inpath/$infile-ramdisk.gz" -o "$inpath/initramfs.cpio"
mkdir "$inpath/initramfs"
(cd "$inpath/initramfs";cpio -imd --no-preserve-owner --quiet -I "../initramfs.cpio")
unpack "$inpath/$infile-ramdisk.gz" > "$inpath/initramfs.cpio"
mkdir -p "$inpath/initramfs"
(cd "$inpath/initramfs";bundled cpio -imd --no-preserve-owner --quiet -I "../initramfs.cpio")
@@ -1,33 +1,2 @@
@echo off

set img=%~f1
if "%img%"=="" goto error

set infile=%~nx1
set inpath=.\%~n1

if exist "%inpath%" rd /s /q "%inpath%"
if errorlevel 1 goto error

md "%inpath%"
if errorlevel 1 goto error

unpackbootimg -i "%img%" -o "%inpath%"
if errorlevel 1 goto error

lzop -d "%inpath%\%infile%-ramdisk.gz" -o "%inpath%\initramfs.cpio"
if errorlevel 1 goto error

md "%inpath%\initramfs"
if errorlevel 1 goto error

cd "%inpath%\initramfs"
if errorlevel 1 goto error

cpio -imd --no-preserve-owner --quiet -I "..\initramfs.cpio"
if errorlevel 1 goto error

exit 0
:error
echo %0 %* -^> failed
exit 1
busybox sh -e "bin/%~n0" %*
@@ -1,5 +1,4 @@
#!/bin/bash
set -e
#!/bin/bash -e

sunxi-fel version

@@ -1,12 +1,12 @@
#!/bin/bash
#!/bin/bash -e

input=$(cd $(dirname "$1");pwd)/$(basename "$1")
input="$(readlink -f "$1")"
[ -f "$input" ] || exit 1

ext=.hmod
name=$(basename "$input" .tgz)
name=$(basename "$input" $ext)
output=$(pwd)/$name
ext=".hmod"
name="$(basename "$input" ".tgz")"
name="$(basename "$input" "$ext")"
output="$(pwd)/$name"

mkdir -p "$output"
(cd "$output" && tar xzf "$input" && echo ok)
@@ -1,5 +1,4 @@
#!/bin/bash
set -e
#!/bin/sh -e

inpath="$1"
if [ -z "$inpath" ]; then
@@ -11,21 +10,30 @@ img="./$infile"

rm -rf "$inpath/initramfs/hakchi"
rsync -a "$inpath/../mod/" "$inpath/initramfs/"
if [ "$2" == "notx" ]; then
if [ "$2" = "notx" ]; then
rm -rf "$inpath/initramfs/hakchi/transfer"
rm -f "$inpath/initramfs/bin/rsync"
fi
upx -qq --best "$inpath/initramfs/sbin/cryptsetup" || true
(cd "$inpath/initramfs";find . -print0 | sort -z | cpio -0o -H newc -R root:root --quiet > "../initramfs.cpio")
lzop --best -f -o "$inpath/$infile-ramdisk.gz" "$inpath/initramfs.cpio"

#(cd "$inpath/initramfs";find . -print0 | sort -z | bundled cpio -0o -H newc -R 0:0 --quiet > "../initramfs.cpio")
mkbootfs "$inpath/initramfs" > "$inpath/initramfs.cpio"

kernelzImage="$inpath/../data/zImage"
compress="xz --check=crc32 --lzma2=dict=1MiB"
if ! [ -f "$kernelzImage" ]; then
kernelzImage="$inpath/$infile-zImage"
compress="lzop --best"
fi
bundled $compress -c "$inpath/initramfs.cpio" > "$inpath/$infile-ramdisk.gz"

mkbootimg \
--kernel "$inpath/$infile-zImage" \
--kernel "$kernelzImage" \
--ramdisk "$inpath/$infile-ramdisk.gz" \
--cmdline "$(cat $inpath/$infile-cmdline)" \
--board "$(cat $inpath/$infile-board)" \
--base "$(cat $inpath/$infile-base)" \
--pagesize "$(cat $inpath/$infile-pagesize)" \
--kernel_offset "$(cat $inpath/$infile-kerneloff)" \
--ramdisk_offset "$(cat $inpath/$infile-ramdiskoff)" \
--tags_offset "$(cat $inpath/$infile-tagsoff)" \
--cmdline "$(cat "$inpath/$infile-cmdline")" \
--board "$(cat "$inpath/$infile-board")" \
--base "$(cat "$inpath/$infile-base")" \
--pagesize "$(cat "$inpath/$infile-pagesize")" \
--kernel_offset "$(cat "$inpath/$infile-kerneloff")" \
--ramdisk_offset "$(cat "$inpath/$infile-ramdiskoff")" \
--tags_offset "$(cat "$inpath/$infile-tagsoff")" \
-o "$img"
@@ -1,36 +1,2 @@
@echo off

set inpath=%~f1
if "%inpath%"=="" goto error

set infile=%~nx1.img
set img=.\%~nx1.img

if exist "%inpath%\initramfs\hakchi\transfer" rd /s /q "%inpath%\initramfs\hakchi\transfer"
xcopy "%inpath%\..\mod" "%inpath%\initramfs" /h /y /c /r /s /q || cd >nul
if "%2"=="notx" if exist "%inpath%\initramfs\hakchi\transfer" rd /s /q "%inpath%\initramfs\hakchi\transfer"
if errorlevel 1 goto error

upx -qq --best "%inpath%\initramfs\sbin\cryptsetup" || cd >nul

mkbootfs "%inpath%\initramfs" > "%inpath%\initramfs.cpio"
if errorlevel 1 goto error

lzop --best -f -o "%inpath%\%infile%-ramdisk.gz" "%inpath%\initramfs.cpio"
if errorlevel 1 goto error

set /p cmdline=<"%inpath%\%infile%-cmdline"
set /p board=<"%inpath%\%infile%-board"
set /p base=<"%inpath%\%infile%-base"
set /p pagesize=<"%inpath%\%infile%-pagesize"
set /p kerneloff=<"%inpath%\%infile%-kerneloff"
set /p ramdiskoff=<"%inpath%\%infile%-ramdiskoff"
set /p tagsoff=<"%inpath%\%infile%-tagsoff"

mkbootimg --kernel "%inpath%\%infile%-zImage" --ramdisk "%inpath%\%infile%-ramdisk.gz" --cmdline "%cmdline%" --board "%board%" --base "%base%" --pagesize "%pagesize%" --kernel_offset "%kerneloff%" --ramdisk_offset "%ramdiskoff%" --tags_offset "%tagsoff%" -o "%img%"
if errorlevel 1 goto error

exit 0
:error
echo %0 %* -^> failed
exit 1
busybox sh -e "bin/%~n0" %*
@@ -1,11 +1,11 @@
#!/bin/bash
#!/bin/bash -e

input=$1
input="$1"
[ -d "$input" ] || exit 1

ext=.hmod
name=$(basename "$input" $ext)
output=$(pwd)/$name$ext.tgz
ext=".hmod"
name="$(basename "$input" "$ext")"
output="$(pwd)/$name$ext.tgz"

rm -f "$output"
(cd "$input" && tar -cz --owner=root --group=root --numeric-owner -f "$output" * && echo ok)
@@ -0,0 +1,6 @@
#!/bin/sh

[ "$1" = "-f" ] || exit 1
[ -d "$2" ] && cd "$2" && pwd && exit 0
cd "$(dirname "$2")" && echo "$(pwd)/$(basename "$2")" && exit 0
echo "$(pwd)/$2";exit 1
@@ -0,0 +1,8 @@
#!/bin/sh

[ "$1" = "-a" ] || exit 1
[ "$(uname -o)" = "MS/Windows" ] || exit 1
win32path(){
echo "$(readlink -f "$1")" | sed 's#/#\\#g'
}
xcopy "$(win32path "$2")" "$(win32path "$3")" /h /y /c /r /s /q
@@ -0,0 +1,9 @@
#!/bin/sh -e

input="$1"
[ -f "$input" ] || exit 1
signature="$(hexdump -e '1/4 "%x"' -s 0 -n 4 "$input")"
[ "$signature" = "4f5a4c89" ] && exec lzop -cd "$input"
[ "$signature" = "587a37fd" ] && exec bundled xz -cd "$input"
echo "unknown signature: $signature"
exit 1
@@ -62,6 +62,10 @@ MainWindow::MainWindow(QWidget *parent) :

srand(0);
printf("Knock, knock\n");

#ifndef DEBUG
ui->actionWrite_nand->setVisible(false);
#endif
}

MainWindow::~MainWindow()
@@ -155,5 +159,8 @@ void MainWindow::on_actionDump_nand_triggered()
void MainWindow::on_actionWrite_nand_triggered()
{
// do not use
// emit doWork(Worker::writeNandFull);
return;
if(QMessageBox::warning(this,"nand","sure?",QMessageBox::Yes|QMessageBox::Abort,QMessageBox::Abort)!=QMessageBox::Yes)
return;
emit doWork(Worker::writeNandFull);
}
@@ -82,6 +82,7 @@ void CWinCon::readOutput()
str=codec->toUnicode(buffer);
else
str=QString::fromLocal8Bit(buffer);
str=str.replace("\r","");
if(str.length())
{
readOutput();
@@ -2,3 +2,4 @@ local cf_backup_dummy='n'
local cf_backup='n'
local cf_backup_nandc='n'
local cf_shutdown='n'
local cf_usb='y'
@@ -1,38 +1,36 @@
init(){
echo
/bin/busybox --install -s /bin/
#!/bin/sh

local modname="hakchi"
local modpath="/$modname"
local mountpoint="/newroot"
local installpath=""
local firmwarepath=""
local rootfs=""
local squashfs=""
local preinit=""
local preinitpath=""
local sftype=""
local sfregion=""
local gamepath=""
local temppath="/tmp"
init(){
echo
export modname="hakchi"
export modpath="/$modname"
export mountpoint="/newroot"
export temppath="/tmp"

mkdir -p "$temppath"
/bin/busybox --install -s /bin/
mkdir -p "$temppath"
for dir in etc lib usr; do
[ -e "/$1" ] || ln -s "$mountpoint/$1" "/$1"
done
export PATH="/sbin:$modpath/rootfs/bin:/bin:$mountpoint/sbin:/usr/sbin:$mountpoint/bin:/usr/bin"

source "$modpath/config"
source "$modpath/script/base"
source "$modpath/config"
source "$modpath/script/base"

if [ -d "$modpath/transfer" ]; then
source "$modpath/script/transfer"
else
mount_base
fi
if [ -d "$modpath/transfer" ]; then
cf_usb='n'
source "$modpath/script/transfer"
else
mount_base
fi

if [ -f "$preinit" ]; then
source "$preinit"
preinit
else
umount_base
fi
if [ -f "$preinit" ]; then
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"
else
umount_base
fi
}

init
echo
@@ -32,4 +32,4 @@ fi
uistop
overmount_games

touch "/var/startmpc.flag"
touch "/var/startmcp.flag"
@@ -20,7 +20,9 @@ while [ $# -gt 0 ] ; do
mkdir -p "$tmppath"
cd "$tmppath"
tiny7zx x "$filename"
filename="$tmppath/$(ls)"
filename="$(ls|head -n1)"
mv "$filename" "rom.${filename##*.}"
filename="$tmppath/rom.${filename##*.}"
fi
options="-rom $filename"
shift
@@ -31,4 +33,6 @@ while [ $# -gt 0 ] ; do
done

args="$options $cfg_snes_extra_args"

exec /bin/clover-canoe-shvc $args || \
exec /usr/bin/clover-canoe-shvc $args
@@ -16,17 +16,22 @@ if [ "$extension" == "7z" ]; then
mkdir -p "$tmppath"
cd "$tmppath"
tiny7zx x "$filename"
filename="$tmppath/$(ls)"
filename="$(ls|head -n1)"
mv "$filename" "rom.${filename##*.}"
filename="$tmppath/rom.${filename##*.}"
fi
if [ "$extension" == "gz" ]; then
rm -rf "$tmppath"
mkdir -p "$tmppath"
gunzip -c > "$tmppath/$filebase"
filename="$tmppath/$filebase"
filebase="$(basename "$filebase" ".gz")"
extension="${filebase##*.}"
filename="$tmppath/rom.$extension"
gunzip -c > "$filename"
fi
shift

args="$filename $@ $cfg_nes_extra_args"
[ "$cfg_disable_armet" == "y" ] && args="$(echo $args | sed 's/--enable-armet//g')"

exec /bin/clover-kachikachi $args || \
exec /usr/bin/clover-kachikachi $args

2 comments on commit 33720d1

@DanTheMan827

This comment has been minimized.

Copy link
Collaborator

DanTheMan827 replied Nov 12, 2017

@madmonkey1907 the change to the wrapper scripts cause games to fail to launch. (at least for me and some others)

Removing the first exec line with the || makes it work

It also appears that gamepath doesn’t get set after script_init (its blank)

@DanTheMan827

This comment has been minimized.

Copy link
Collaborator

DanTheMan827 replied Nov 15, 2017

@madmonkey1907 what about linking /var/games to the actual storage path for the games instead of the one in /usr/share/games?

If you replaced references of /usr/share/games or /usr/share/games/nes/kachikachi with /var/games in /bin/hsqs, this would make it resolve to the actual path since /var/games is a symbolic link, right?

Another thought I had, you could mount /usr/share/games as tmpfs and recursively create symbolic links to the source file instead of overmounting, this would require no modification to /bin/hsqs in order to resolve the proper path if the hsqs was stored in a game folder.

You could also then do things like create a symbolic link to the font file on overmount when running the NES software.

Please sign in to comment.
You can’t perform that action at this time.