first_boot script
This commit is contained in:
parent
2c2949f73e
commit
10150b111d
|
@ -1,3 +1,4 @@
|
||||||
|
*/dl
|
||||||
*/dl/*
|
*/dl/*
|
||||||
*/output/*
|
*/output/*
|
||||||
*~
|
*~
|
||||||
|
|
|
@ -16,11 +16,18 @@ image sdcard.img {
|
||||||
partition u-boot {
|
partition u-boot {
|
||||||
in-partition-table = "no"
|
in-partition-table = "no"
|
||||||
image = "u-boot-sunxi-with-spl.bin"
|
image = "u-boot-sunxi-with-spl.bin"
|
||||||
offset = 8192
|
offset = 8K
|
||||||
size = 516096 # 512KB - 8192
|
size = 504K # 512KB - 8KB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# partition u-boot-env {
|
||||||
|
# in-partition-table = "no"
|
||||||
|
# offset = 544K
|
||||||
|
# size = 128K
|
||||||
|
# }
|
||||||
|
|
||||||
partition boot {
|
partition boot {
|
||||||
|
offset = 1M
|
||||||
partition-type = 0xC
|
partition-type = 0xC
|
||||||
bootable = "true"
|
bootable = "true"
|
||||||
image = "boot.vfat"
|
image = "boot.vfat"
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Swap
|
# Add swap partition to fstab
|
||||||
sed -i '/^\/swap/d' "${TARGET_DIR}/etc/fstab"
|
sed -i '/^\/swap/d' "${TARGET_DIR}/etc/fstab"
|
||||||
echo "/swap none swap defaults 0 0" >> "${TARGET_DIR}/etc/fstab"
|
echo "/swap none swap defaults 0 0" >> "${TARGET_DIR}/etc/fstab"
|
||||||
|
|
||||||
|
# Add local path to init scripts
|
||||||
|
sed -i '3iexport PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin' ${TARGET_DIR}/etc/init.d/rcK
|
||||||
|
sed -i '3iexport PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin' ${TARGET_DIR}/etc/init.d/rcS
|
||||||
|
|
||||||
|
# Remove log daemon init scripts since they are loaded from inittab
|
||||||
|
rm -f ${TARGET_DIR}/etc/init.d/S01syslogd ${TARGET_DIR}/etc/init.d/S02klogd
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
# <file system> <mount pt> <type> <options> <dump> <pass>
|
||||||
|
/dev/root / ext2 rw,noauto 0 1
|
||||||
|
proc /proc proc defaults 0 0
|
||||||
|
devpts /dev/pts devpts defaults,gid=5,mode=620,ptmxmode=0666 0 0
|
||||||
|
tmpfs /dev/shm tmpfs mode=0777 0 0
|
||||||
|
tmpfs /tmp tmpfs mode=1777 0 0
|
||||||
|
tmpfs /run tmpfs mode=0755,nosuid,nodev 0 0
|
||||||
|
sysfs /sys sysfs defaults 0 0
|
||||||
|
/swap none swap defaults 0 0
|
||||||
|
configfs /sys/kernel/config configfs rw,relatime 0 0
|
||||||
|
/dev/mmcblk0p3 /mnt vfat rw,relatime,fmask=0022,dmask=0022,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 0
|
|
@ -0,0 +1,17 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
THIS=$(basename $0)
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
if [ ! -f /swap ]; then
|
||||||
|
first_boot
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {start|stop}" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
|
@ -1,24 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
THIS=$(basename $0)
|
|
||||||
|
|
||||||
case "$1" in
|
|
||||||
start)
|
|
||||||
sleep 1
|
|
||||||
echo "$THIS: starting resizing the root partition" | tee /dev/kmsg &&
|
|
||||||
resize_rootfs &&
|
|
||||||
rm /etc/init.d/S02resize_rootfs
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
echo "$THIS: finished resizing the root partition, rebooting to enlarge the root filesystem" | tee /dev/kmsg
|
|
||||||
reboot
|
|
||||||
exit 0
|
|
||||||
else
|
|
||||||
echo "$THIS: cannot resize the root partition, aborting" | tee /dev/kmsg
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Usage: $0 start" >&2
|
|
||||||
exit 2
|
|
||||||
;;
|
|
||||||
esac
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
THIS=$(basename $0)
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
if share init; then
|
||||||
|
echo "Starting share: OK"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "Starting share: ERROR"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
if share stop; then
|
||||||
|
echo "Stopping share: OK"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "Stopping share: ERROR"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {start|stop}" >&2
|
||||||
|
exit 3
|
||||||
|
;;
|
||||||
|
esac
|
|
@ -0,0 +1,21 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
THIS=$(basename $0)
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
if /etc/rc.local; then
|
||||||
|
echo "Starting rc.local: OK"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "Starting rc.local: ERROR"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {start|stop}" >&2
|
||||||
|
exit 2
|
||||||
|
;;
|
||||||
|
esac
|
|
@ -1,54 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
THIS=$(basename $0)
|
|
||||||
|
|
||||||
case "$1" in
|
|
||||||
start)
|
|
||||||
if [ ! -f /swap ]; then
|
|
||||||
ROOT_PART=$(df | grep /dev/root)
|
|
||||||
set $ROOT_PART
|
|
||||||
let LEFT="$4 * 1024"
|
|
||||||
if [ $LEFT -lt 134217728 ]; then
|
|
||||||
echo "$THIS: not enough free space for swap file found, aborting" | tee /dev/kmsg
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "$THIS: no swap file found, creating it" | tee /dev/kmsg &&
|
|
||||||
dd if=/dev/zero of=/swap bs=1M count=128 &&
|
|
||||||
mkswap /swap &&
|
|
||||||
chmod 0600 /swap
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
echo "$THIS: created swap file" | tee /dev/kmsg
|
|
||||||
else
|
|
||||||
echo "$THIS: cannot create swap file, aborting" | tee /dev/kmsg
|
|
||||||
rm /swap
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
echo "$THIS: enabling swap file" | tee /dev/kmsg &&
|
|
||||||
swapon -a
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
echo "$THIS: swap file enabled" | tee /dev/kmsg
|
|
||||||
else
|
|
||||||
echo "$THIS: cannot enable swap file, aborting" | tee /dev/kmsg
|
|
||||||
exit 3
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
stop)
|
|
||||||
echo "$THIS: disabling swap file" | tee /dev/kmsg &&
|
|
||||||
swapoff -a
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
echo "$THIS: swap file disabled" | tee /dev/kmsg
|
|
||||||
else
|
|
||||||
echo "$THIS: cannot disable swap file, aborting" | tee /dev/kmsg
|
|
||||||
exit 4
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
restart|reload)
|
|
||||||
"$0" stop
|
|
||||||
"$0" start
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Usage: $0 {start|stop|restart|reload}" >&2
|
|
||||||
exit 5
|
|
||||||
;;
|
|
||||||
esac
|
|
|
@ -12,13 +12,10 @@ case "${1}" in
|
||||||
if [ -r /etc/sysconfig/modules ]; then
|
if [ -r /etc/sysconfig/modules ]; then
|
||||||
egrep -qv '^($|#)' /etc/sysconfig/modules
|
egrep -qv '^($|#)' /etc/sysconfig/modules
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "$THIS: no module found in /etc/sysconfig/modules" | tee/dev/kmsg
|
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$THIS: loading modules from /etc/sysconfig/modules:" | tee/dev/kmsg
|
|
||||||
|
|
||||||
# Only try to load modules if the user has actually given us
|
# Only try to load modules if the user has actually given us
|
||||||
# some modules to load.
|
# some modules to load.
|
||||||
while read MODULE ARGS; do
|
while read MODULE ARGS; do
|
||||||
|
@ -35,18 +32,16 @@ case "${1}" in
|
||||||
# Print the module name if successful,
|
# Print the module name if successful,
|
||||||
# otherwise take note.
|
# otherwise take note.
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "$THIS: loaded module ${MODULE}" | tee /dev/kmsg
|
echo "Loading module ${MODULE}: OK"
|
||||||
else
|
else
|
||||||
echo "$THIS: failed to load module ${MODULE}" | tee /dev/kmsg
|
echo "Loading module ${MODULE}: ERROR"
|
||||||
fi
|
fi
|
||||||
done < /etc/sysconfig/modules
|
done < /etc/sysconfig/modules
|
||||||
|
;;
|
||||||
# Print a message about successfully loaded
|
stop)
|
||||||
# modules on the correct line.
|
|
||||||
echo "$THIS: finished loading modules" | tee /dev/kmsg
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Usage: ${0} {start}"
|
echo "Usage: ${0} {start|stop}"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
# /etc/inittab
|
||||||
|
#
|
||||||
|
# Copyright (C) 2001 Erik Andersen <andersen@codepoet.org>
|
||||||
|
#
|
||||||
|
# Note: BusyBox init doesn't support runlevels. The runlevels field is
|
||||||
|
# completely ignored by BusyBox init. If you want runlevels, use
|
||||||
|
# sysvinit.
|
||||||
|
#
|
||||||
|
# Format for each entry: <id>:<runlevels>:<action>:<process>
|
||||||
|
#
|
||||||
|
# id == tty to run on, or empty for /dev/console
|
||||||
|
# runlevels == ignored
|
||||||
|
# action == one of sysinit, respawn, askfirst, wait, and once
|
||||||
|
# process == program to run
|
||||||
|
|
||||||
|
# Startup the system
|
||||||
|
::sysinit:/bin/sh -c 'echo "Starting FunKey-OS ..."'
|
||||||
|
::sysinit:/bin/mount -t proc proc /proc
|
||||||
|
::sysinit:/bin/mount -o remount,rw /
|
||||||
|
::sysinit:/bin/mkdir -p /dev/pts /dev/shm
|
||||||
|
::sysinit:/bin/mount -a
|
||||||
|
::sysinit:/sbin/swapon -a
|
||||||
|
null::sysinit:/bin/ln -sf /proc/self/fd /dev/fd
|
||||||
|
null::sysinit:/bin/ln -sf /proc/self/fd/0 /dev/stdin
|
||||||
|
null::sysinit:/bin/ln -sf /proc/self/fd/1 /dev/stdout
|
||||||
|
null::sysinit:/bin/ln -sf /proc/self/fd/2 /dev/stderr
|
||||||
|
::sysinit:/bin/hostname -F /etc/hostname
|
||||||
|
::sysinit:/sbin/syslogd
|
||||||
|
::sysinit:/sbin/klogd
|
||||||
|
# now run any rc scripts
|
||||||
|
::sysinit:/etc/init.d/rcS
|
||||||
|
|
||||||
|
# Put a getty on the serial port
|
||||||
|
#ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100 # GENERIC_SERIAL
|
||||||
|
#ttyS0::respawn:/sbin/getty -L -n -l /loginroot.sh ttyS0 115200 vt100 # GENERIC_SERIAL
|
||||||
|
::respawn:-/bin/sh
|
||||||
|
|
||||||
|
# Stuff to do for the 3-finger salute
|
||||||
|
#::ctrlaltdel:/sbin/reboot
|
||||||
|
|
||||||
|
# Stuff to do before rebooting
|
||||||
|
::shutdown:/etc/init.d/rcK
|
||||||
|
::shutdown:/sbin/swapoff -a
|
||||||
|
::shutdown:/bin/umount -a -r
|
|
@ -5,6 +5,6 @@
|
||||||
|___| |_____|__|__||__|\\__||_____|___ |
|
|___| |_____|__|__||__|\\__||_____|___ |
|
||||||
FUN ON A KEYCHAIN |_____|
|
FUN ON A KEYCHAIN |_____|
|
||||||
-----------------------------------------------------
|
-----------------------------------------------------
|
||||||
Version 0.2
|
Version 0.3
|
||||||
-----------------------------------------------------
|
-----------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
allow-hotplug usb0
|
||||||
|
|
||||||
|
iface usb0 inet static
|
||||||
|
address 192.168.137.2/24
|
||||||
|
gateway 192.168.137.1
|
||||||
|
pre-up ip addr flush usb0 || true
|
||||||
|
up echo "nameserver 8.8.8.8" > /etc/resolv.conf
|
|
@ -0,0 +1,21 @@
|
||||||
|
export PATH="/usr/local/games:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||||
|
|
||||||
|
if [ "$PS1" ]; then
|
||||||
|
if [ "`id -u`" -eq 0 ]; then
|
||||||
|
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\# '
|
||||||
|
else
|
||||||
|
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
export PAGER='/bin/more'
|
||||||
|
export EDITOR='/usr/bin/nano'
|
||||||
|
export SDL_NOMOUSE=1
|
||||||
|
|
||||||
|
# Source configuration files from /etc/profile.d
|
||||||
|
for i in /etc/profile.d/*.sh ; do
|
||||||
|
if [ -r "$i" ]; then
|
||||||
|
. $i
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
unset i
|
|
@ -0,0 +1,24 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
#
|
||||||
|
# rc.local
|
||||||
|
#
|
||||||
|
# This script is executed at the end of each multiuser runlevel.
|
||||||
|
# Make sure that the script will "exit 0" on success or any other
|
||||||
|
# value on error.
|
||||||
|
#
|
||||||
|
# In order to enable or disable this script just change the execution
|
||||||
|
# bits.
|
||||||
|
#
|
||||||
|
# By default this script does nothing.
|
||||||
|
|
||||||
|
# Incremental upgrades, blocking process #
|
||||||
|
#notif_set 0 "upgrade"
|
||||||
|
#upgrade_fk_incremental
|
||||||
|
|
||||||
|
# Low bat check #
|
||||||
|
low_bat_check >/dev/null 2>&1 &
|
||||||
|
|
||||||
|
# System stats #
|
||||||
|
system_stats >/dev/null 2>&1 &
|
||||||
|
|
||||||
|
exit 0
|
|
@ -0,0 +1,74 @@
|
||||||
|
# ~/.bashrc: executed by bash(1) for non-login shells.
|
||||||
|
|
||||||
|
# Note: PS1 and umask are already set in /etc/profile. You should not
|
||||||
|
# need this unless you want different defaults for root.
|
||||||
|
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
|
||||||
|
# umask 022
|
||||||
|
|
||||||
|
# You may uncomment the following lines if you want `ls' to be colorized:
|
||||||
|
export TERM=xterm
|
||||||
|
export LS_OPTIONS='--color=auto'
|
||||||
|
eval "`dircolors`"
|
||||||
|
alias ls='ls $LS_OPTIONS'
|
||||||
|
alias ll='ls $LS_OPTIONS -l'
|
||||||
|
alias l='ls $LS_OPTIONS -lA'
|
||||||
|
#
|
||||||
|
# Some more alias to avoid making mistakes:
|
||||||
|
# alias rm='rm -i'
|
||||||
|
# alias cp='cp -i'
|
||||||
|
# alias mv='mv -i'
|
||||||
|
|
||||||
|
# Resize the console to the terminal dimensions
|
||||||
|
resize() {
|
||||||
|
if [[ -t 0 && $# -eq 0 ]]; then
|
||||||
|
local IFS='[;' escape geometry x y
|
||||||
|
echo -ne '\e7\e[r\e[999;999H\e[6n\e8'
|
||||||
|
read -sd R escape geometry
|
||||||
|
x=${geometry##*;} y=${geometry%%;*}
|
||||||
|
if [[ ${COLUMNS} -eq ${x} && ${LINES} -eq ${y} ]]; then
|
||||||
|
echo "${TERM} ${x}x${y}"
|
||||||
|
else
|
||||||
|
echo "${COLUMNS}x${LINES} -> ${x}x${y}"
|
||||||
|
stty cols ${x} rows ${y}
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print 'Usage: resize'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Mount /dev/mmcblk0p1 in /boot
|
||||||
|
echo "Mount /dev/mmcblk0p1 in /boot"
|
||||||
|
mount /dev/mmcblk0p1 /boot/ >/dev/null 2>&1
|
||||||
|
|
||||||
|
# Start ampli if necessary
|
||||||
|
echo "Start ampli if necessary"
|
||||||
|
if [[ "$(volume_get)" -ne "0" ]]; then
|
||||||
|
start_audio_amp 1 >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Force unmute sound card and reset volume
|
||||||
|
echo "Force unmute sound card and reset volume"
|
||||||
|
volume_set $(volume_get) >/dev/null 2>&1
|
||||||
|
|
||||||
|
# Reset saved brightness
|
||||||
|
echo "Reset saved brightness"
|
||||||
|
brightness_set $(brightness_get) >/dev/null 2>&1
|
||||||
|
|
||||||
|
# Enable USB gadget share and internet forwarding over USB
|
||||||
|
share init&
|
||||||
|
|
||||||
|
# Start launcher
|
||||||
|
echo "Start launcher"
|
||||||
|
start_launcher >/dev/null 2>&1 &
|
||||||
|
|
||||||
|
# Init GPIO manager
|
||||||
|
echo "Init GPIO manager"
|
||||||
|
PREVENT_GPIOMNG_FILE=/mnt/prevent_gpiomanager
|
||||||
|
PREVENT_GPIOMNG_FILE2=/boot/prevent_gpiomanager
|
||||||
|
if [ -f $PREVENT_GPIOMNG_FILE ]; then
|
||||||
|
echo "Found file: $PREVENT_GPIOMNG_FILE, not launching gpio manager"
|
||||||
|
elif [ -f $PREVENT_GPIOMNG_FILE2 ]; then
|
||||||
|
echo "Found file: $PREVENT_GPIOMNG_FILE2, not launching gpio manager"
|
||||||
|
else
|
||||||
|
start_gpio_manager >/dev/null 2>&1 &
|
||||||
|
fi
|
|
@ -0,0 +1,74 @@
|
||||||
|
# ~/.bashrc: executed by bash(1) for non-login shells.
|
||||||
|
|
||||||
|
# Note: PS1 and umask are already set in /etc/profile. You should not
|
||||||
|
# need this unless you want different defaults for root.
|
||||||
|
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
|
||||||
|
# umask 022
|
||||||
|
|
||||||
|
# You may uncomment the following lines if you want `ls' to be colorized:
|
||||||
|
export TERM=xterm
|
||||||
|
export LS_OPTIONS='--color=auto'
|
||||||
|
#eval "`dircolors`"
|
||||||
|
alias ls='ls $LS_OPTIONS'
|
||||||
|
alias ll='ls $LS_OPTIONS -l'
|
||||||
|
alias l='ls $LS_OPTIONS -lA'
|
||||||
|
#
|
||||||
|
# Some more alias to avoid making mistakes:
|
||||||
|
# alias rm='rm -i'
|
||||||
|
# alias cp='cp -i'
|
||||||
|
# alias mv='mv -i'
|
||||||
|
|
||||||
|
# Resize the console to the terminal dimensions
|
||||||
|
resize() {
|
||||||
|
if [[ -t 0 && $# -eq 0 ]]; then
|
||||||
|
local IFS='[;' escape geometry x y
|
||||||
|
echo -ne '\e7\e[r\e[999;999H\e[6n\e8'
|
||||||
|
read -sd R escape geometry
|
||||||
|
x=${geometry##*;} y=${geometry%%;*}
|
||||||
|
if [[ ${COLUMNS} -eq ${x} && ${LINES} -eq ${y} ]]; then
|
||||||
|
echo "${TERM} ${x}x${y}"
|
||||||
|
else
|
||||||
|
echo "${COLUMNS}x${LINES} -> ${x}x${y}"
|
||||||
|
stty cols ${x} rows ${y}
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print 'Usage: resize'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Mount /dev/mmcblk0p1 in /boot
|
||||||
|
#echo "Mount /dev/mmcblk0p1 in /boot"
|
||||||
|
#mount /dev/mmcblk0p1 /boot/ >/dev/null 2>&1
|
||||||
|
|
||||||
|
# Start ampli if necessary
|
||||||
|
#echo "Start ampli if necessary"
|
||||||
|
if [[ "$(volume_get)" -ne "0" ]]; then
|
||||||
|
start_audio_amp 1 >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Force unmute sound card and reset volume
|
||||||
|
#echo "Force unmute sound card and reset volume"
|
||||||
|
volume_set $(volume_get) >/dev/null 2>&1
|
||||||
|
|
||||||
|
# Reset saved brightness
|
||||||
|
#echo "Reset saved brightness"
|
||||||
|
brightness_set $(brightness_get) >/dev/null 2>&1
|
||||||
|
|
||||||
|
# Enable USB gadget share and internet forwarding over USB
|
||||||
|
share init&
|
||||||
|
|
||||||
|
# Start launcher
|
||||||
|
#echo "Start launcher"
|
||||||
|
start_launcher >/dev/null 2>&1 &
|
||||||
|
|
||||||
|
# Init GPIO manager
|
||||||
|
#echo "Init GPIO manager"
|
||||||
|
PREVENT_GPIOMNG_FILE=/mnt/prevent_gpiomanager
|
||||||
|
PREVENT_GPIOMNG_FILE2=/boot/prevent_gpiomanager
|
||||||
|
if [ -f $PREVENT_GPIOMNG_FILE ]; then
|
||||||
|
echo "Found file: $PREVENT_GPIOMNG_FILE, not launching gpio manager"
|
||||||
|
elif [ -f $PREVENT_GPIOMNG_FILE2 ]; then
|
||||||
|
echo "Found file: $PREVENT_GPIOMNG_FILE2, not launching gpio manager"
|
||||||
|
else
|
||||||
|
start_gpio_manager >/dev/null 2>&1 &
|
||||||
|
fi
|
|
@ -0,0 +1,20 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Define log functions if they do not exist yet
|
||||||
|
type -t info >/dev/null 2>&1
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
info () {
|
||||||
|
echo "$SELF:" "$@" | tee /dev/kmsg
|
||||||
|
}
|
||||||
|
|
||||||
|
warn () {
|
||||||
|
echo "$SELF:" "$@" >&2 | tee /dev/kmsg
|
||||||
|
}
|
||||||
|
|
||||||
|
die () {
|
||||||
|
local return_code=$1
|
||||||
|
shift
|
||||||
|
warn "$@"
|
||||||
|
exit $return_code
|
||||||
|
}
|
||||||
|
fi
|
|
@ -0,0 +1,176 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Uncomment the following line to get debug info
|
||||||
|
#set -x
|
||||||
|
|
||||||
|
SELF=$(basename $0)
|
||||||
|
|
||||||
|
source /usr/local/lib/utils
|
||||||
|
|
||||||
|
check_swap () {
|
||||||
|
[ -f /swap ] && die 0 "nothing to do"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
check_root_id () {
|
||||||
|
[ $(id -u) -ne 0 ] && die 1 "this script must be run as root, aborting"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
resize_rootfs_partition () {
|
||||||
|
local root_part=$(cat /proc/cmdline | sed -n 's|^.*root=/dev/\([^ ]*\).*|\1|p')
|
||||||
|
local part_num=${root_part#mmcblk0p}
|
||||||
|
if [ "${part_num}" = "{$root_part}" ]; then
|
||||||
|
die 2 "${root_part} is not an SD card. Don't know how to expand it, aborting"
|
||||||
|
fi
|
||||||
|
if [ "${part_num}" -ne 2 ]; then
|
||||||
|
die 3 "your partition layout is not currently supported by this tool, aborting"
|
||||||
|
fi
|
||||||
|
local last_part_line=$(fdisk /dev/mmcblk0 -l | grep '^/' | tail -n 1)
|
||||||
|
set ${last_part_line}
|
||||||
|
local last_part=${1#/dev/}
|
||||||
|
local part_start=${2}
|
||||||
|
if [ "${last_part}" != "${root_part}" ]; then
|
||||||
|
die 4 "${root_part} is not the last partition. Don't know how to expand, aborting"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Return value will likely be error for fdisk as it fails to reload the
|
||||||
|
# partition table because the root fs is mounted
|
||||||
|
# NOTE: This script only works the genuine fdisk, NOT with the busybox one!!!
|
||||||
|
fdisk /dev/mmcblk0 >/dev/null 2>&1 <<EOF
|
||||||
|
d
|
||||||
|
${part_num}
|
||||||
|
n
|
||||||
|
p
|
||||||
|
${part_num}
|
||||||
|
${part_start}
|
||||||
|
+1G
|
||||||
|
w
|
||||||
|
EOF
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
die 5 "cannot resize the rootfs partition, aborting"
|
||||||
|
fi
|
||||||
|
sync
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
reload_partition_table () {
|
||||||
|
partprobe /dev/mmcblk0 >/dev/null 2>&1 || die 6 "cannot reload the partition table, aborting"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
resize_rootfs_filesystem () {
|
||||||
|
local root_part=$(cat /proc/cmdline | sed -n 's|^.*root=/dev/\([^ ]*\).*|\1|p')
|
||||||
|
resize2fs /dev/${root_part} >/dev/null 2>&1 || die 7 "cannot resize the root filesystem, aborting"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
write_bootloader_env () {
|
||||||
|
fw_saveenv /etc/u-boot.env || die 8 "cannot write bootloader inevrionment, aborting"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
create_swap_file () {
|
||||||
|
local root_part_line=$(df | grep /dev/root)
|
||||||
|
set ${root_part_line}
|
||||||
|
local space_left=${4}
|
||||||
|
if [ ${space_left} -lt 131072 ]; then
|
||||||
|
die 9 "not enough free space for swap file found, aborting"
|
||||||
|
fi
|
||||||
|
dd if=/dev/zero of=/swap bs=1M count=128 >/dev/null 2>&1 &&
|
||||||
|
chmod 0600 /swap >/dev/null 2>&1 &&
|
||||||
|
mkswap /swap >/dev/null 2>&1
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
rm /swap
|
||||||
|
die 10 "cannot create swap file, aborting"
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
enable_swap_file () {
|
||||||
|
swapon -a >/dev/null 2>&1 || die 11 "cannot enable swap file, aborting"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
create_backing_store_partition () {
|
||||||
|
mount | grep -q /dev/mmcblk0p3
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
|
||||||
|
# Find out the root partition number from kernel command line
|
||||||
|
local root_part=$(cat /proc/cmdline | sed -n 's|^.*root=/dev/\([^ ]*\).*|\1|p')
|
||||||
|
local part_num=${root_part#mmcblk0p}
|
||||||
|
if [ "$part_num" = "$root_part" ]; then
|
||||||
|
die 5 "$root_part is not an SD card. Don't know how to create the backing store partition"
|
||||||
|
fi
|
||||||
|
if [ "$part_num" -ne 2 ]; then
|
||||||
|
die 6 "your partition layout is not currently supported"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check that the last partition is the root partition
|
||||||
|
local last_part_line=$(fdisk /dev/mmcblk0 -l 2>/dev/null | grep '^/' | tail -n 1)
|
||||||
|
set $last_part_line
|
||||||
|
local last_part=${1#/dev/}
|
||||||
|
if [ "$last_part" != "$root_part" ]; then
|
||||||
|
die 7 "$root_part is not the last partition. Don't know how to create the backing store partition"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# The return value will likely be error for fdisk as it fails
|
||||||
|
# to reload the partition table because the root fs is mounted
|
||||||
|
# NOTE: This script only works the genuine fdisk, NOT with the
|
||||||
|
# busybox one!!!
|
||||||
|
# Create a third FAT32 partition that filsl the disk
|
||||||
|
fdisk /dev/mmcblk0 >/dev/null 2>&1 <<EOF
|
||||||
|
n
|
||||||
|
p
|
||||||
|
3
|
||||||
|
|
||||||
|
|
||||||
|
t
|
||||||
|
3
|
||||||
|
c
|
||||||
|
w
|
||||||
|
EOF
|
||||||
|
sync
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
format_backing_store_partition () {
|
||||||
|
|
||||||
|
# Format the backing store as FAT32
|
||||||
|
mkfs.vfat /dev/mmcblk0p3 >/dev/null 2>&1 || die 9 "cannot format the backing store partition"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
info "First boot detected!"
|
||||||
|
check_swap
|
||||||
|
check_root_id
|
||||||
|
|
||||||
|
info "Step 1/9 - Resize the rootfs partition"
|
||||||
|
resize_rootfs_partition
|
||||||
|
|
||||||
|
info "Step 2/9 - Reload the partition table"
|
||||||
|
reload_partition_table
|
||||||
|
|
||||||
|
info "Step 3/9 - Resize the root filesystem"
|
||||||
|
resize_rootfs_filesystem
|
||||||
|
|
||||||
|
info "Step 4/9 - Write the bootloader environment"
|
||||||
|
write_bootloader_env
|
||||||
|
|
||||||
|
info "Step 5/9 - Create the swap file"
|
||||||
|
create_swap_file
|
||||||
|
|
||||||
|
info "Step 6/9 - Enable the swap file"
|
||||||
|
enable_swap_file
|
||||||
|
|
||||||
|
info "Step 7/9 - Create the backing store partition"
|
||||||
|
create_backing_store_partition
|
||||||
|
|
||||||
|
info "Step 8/9 - Reload the partition table"
|
||||||
|
reload_partition_table
|
||||||
|
|
||||||
|
info "Step 9/9 - Format the backing store partition"
|
||||||
|
format_backing_store_partition
|
||||||
|
|
||||||
|
info "First boot setup finished!"
|
|
@ -0,0 +1,57 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Uncomment the following line to get debug info
|
||||||
|
#set -xv
|
||||||
|
|
||||||
|
source /usr/local/lib/utils
|
||||||
|
|
||||||
|
fw_saveenv () {
|
||||||
|
|
||||||
|
# Check arguments
|
||||||
|
if [ $# -ne 1 ]; then
|
||||||
|
die 1 "usage: fw_saveenv filename"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Save the input file name
|
||||||
|
local input_file="${1}"
|
||||||
|
|
||||||
|
# Read the fw_env config file
|
||||||
|
local config=$(sed -e 's/#.*$//' -e '/^$/d' /etc/fw_env.config)
|
||||||
|
set ${config}
|
||||||
|
local of=${1}
|
||||||
|
local seek=$((${2} / 1024))
|
||||||
|
local count=$((${3} / 1024))
|
||||||
|
|
||||||
|
# Create 2 temporary files
|
||||||
|
local blob_file=$(mktemp /tmp/fw_saveenv.XXXXXX)
|
||||||
|
local env_file=$(mktemp /tmp/fw_saveenv.XXXXXX)
|
||||||
|
|
||||||
|
# Convert the provided file to a null-terminated string blob
|
||||||
|
cat "${input_file}" | tr '\n' '\0' > ${blob_file}
|
||||||
|
|
||||||
|
# Compute the blob length in bytes
|
||||||
|
set -- $(ls -l ${blob_file})
|
||||||
|
local length=${5}
|
||||||
|
|
||||||
|
# Compute the padding size in bytes
|
||||||
|
let padding=${count}*1024-4-${length}
|
||||||
|
|
||||||
|
# Pad the blob file with zeros up to the total size
|
||||||
|
dd if=/dev/zero bs=1 count=${padding} >>${blob_file} 2>/dev/null
|
||||||
|
|
||||||
|
# Compute the CRC32 for the padded blob and store it at the beginning of the env file
|
||||||
|
set $(cat ${blob_file} | gzip -1 | tail -c 8 | head -c 4 | hexdump -e '4/1 "%02X "')
|
||||||
|
printf "\\x$1\\x$2\\x$3\\x$4" > ${env_file}
|
||||||
|
|
||||||
|
# Append the binary blob file to the env file
|
||||||
|
cat ${blob_file} >> ${env_file}
|
||||||
|
|
||||||
|
# Write the final env file to the raw device
|
||||||
|
dd if=${env_file} of=${of} bs=1k count=${count} seek=${seek} 2>/dev/null
|
||||||
|
|
||||||
|
# Remove the temporay files
|
||||||
|
rm ${blob_file} ${env_file}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fw_saveenv $*
|
|
@ -0,0 +1,147 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Uncomment the following line to get debug info
|
||||||
|
#set -x
|
||||||
|
|
||||||
|
SELF=${SELF:-$(basename $0)}
|
||||||
|
LOCK_FILE=/var/lock/share.lock
|
||||||
|
|
||||||
|
source /usr/local/lib/utils
|
||||||
|
source usb_gadget
|
||||||
|
|
||||||
|
# The USB network interface file
|
||||||
|
USB_IF=/etc/network/interfaces.d/usb0
|
||||||
|
|
||||||
|
# The USB mass storag ebacking store file or partition
|
||||||
|
BACKING_STORE_FILE=/sys/kernel/config/usb_gadget/funkey/functions/mass_storage.funkey/lun.0/file
|
||||||
|
|
||||||
|
# Unmount a local share
|
||||||
|
unmount_share () {
|
||||||
|
|
||||||
|
umount /mnt || die 1 "cannot unmount the backing store partition"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Mount a share locally
|
||||||
|
mount_share () {
|
||||||
|
|
||||||
|
mount | grep -q /dev/mmcblk0p3
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
|
||||||
|
# Check if the FAT32 partition has been unmounted cleanly
|
||||||
|
fsck.fat -n /dev/mmcblk0p3 2>/dev/null | egrep -q "Dirty bit"
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
|
||||||
|
# The FAT32 partition was not cleanly unmounted, try to
|
||||||
|
# clean it
|
||||||
|
warn "the backing store partition was not properly unmounted"
|
||||||
|
#warn "the backing store partition was not properly
|
||||||
|
#unmounted, clean it"
|
||||||
|
# fsck.fat -a -t -w /dev/loop0 >/dev/null 2>&1
|
||||||
|
# if [ $? -gt 1 ]; then
|
||||||
|
# die 3 "cannot clean backing store file"
|
||||||
|
# fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Mount the backing store file locally
|
||||||
|
mount /mnt/ || die 4 "cannot mount backing store partition"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create the directory structure if required
|
||||||
|
(cd /mnt; mkdir -p atari_lynx gb gba megadrive neo_geo_pocket nes ps1 snes wonderswan)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initialize the backing store if needed and mount it locally
|
||||||
|
init_share () {
|
||||||
|
if [ -f ${LOCK_FILE} ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
touch ${LOCK_FILE}
|
||||||
|
|
||||||
|
# Initialize the USB gadget
|
||||||
|
init_usb_gadget
|
||||||
|
|
||||||
|
# Mount the backing store partition locally
|
||||||
|
mount_share
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Stop sharing the backing store partition
|
||||||
|
stop_share () {
|
||||||
|
|
||||||
|
# Stop sharing the backing store partition
|
||||||
|
echo > $BACKING_STORE_FILE || die 11 "the backing store partition is still mounted on host"
|
||||||
|
|
||||||
|
# 3) Mount the backing store partition locally
|
||||||
|
mount_share
|
||||||
|
|
||||||
|
info "stopped sharing the backing store partition"
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Start sharing the backing store partition
|
||||||
|
start_share () {
|
||||||
|
|
||||||
|
# 1) Check if the backing store partition is already shared
|
||||||
|
cat $BACKING_STORE_FILE | egrep -q ^/dev/mmcblk0p3 && die 12 "the backing store partition is already shared"
|
||||||
|
|
||||||
|
# 2) Unmount the backing store partition if it is locally mounted
|
||||||
|
unmount_share
|
||||||
|
|
||||||
|
# Everything is now clear to start sharing the backing store partition
|
||||||
|
info "start sharing the backing store partition"
|
||||||
|
echo /dev/mmcblk0p3 > $BACKING_STORE_FILE || die 13 "cannot share the backing store partition"
|
||||||
|
|
||||||
|
# Check if we are connected to an USB host
|
||||||
|
local trials=0
|
||||||
|
local not_ready=1
|
||||||
|
while [ ${trials} -lt 5 -a ${not_ready} -eq 1 ]; do
|
||||||
|
|
||||||
|
# Get connection state
|
||||||
|
local udc_state=$(cat /sys/class/udc/musb-hdrc.1.auto/state)
|
||||||
|
sleep 1
|
||||||
|
let trial=$trial+1
|
||||||
|
|
||||||
|
# Check if USB is mounted
|
||||||
|
if [ x"$udc_state" == "xconfigured" ]; then
|
||||||
|
|
||||||
|
# Connected succesfully to a host
|
||||||
|
info "backing store file shared"
|
||||||
|
return 0
|
||||||
|
elif [ x"$udc_state" == "xdefault" ]; then
|
||||||
|
|
||||||
|
# Connected succesfully to a host
|
||||||
|
info "USB sharing in progress"
|
||||||
|
else
|
||||||
|
# Connection failed
|
||||||
|
not_ready=0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# No USB host connected
|
||||||
|
warn "no host, stop USB sharing"
|
||||||
|
stop_share
|
||||||
|
die 14 "not connected to a host"
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
|
||||||
|
init)
|
||||||
|
init_share
|
||||||
|
;;
|
||||||
|
|
||||||
|
start)
|
||||||
|
start_share
|
||||||
|
;;
|
||||||
|
|
||||||
|
stop)
|
||||||
|
stop_share
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
die 15 "Usage $0 {init|start|stop}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
exit $?
|
|
@ -0,0 +1,169 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
#set -xv
|
||||||
|
|
||||||
|
SELF=${SELF:-$(basename $0)}
|
||||||
|
|
||||||
|
source /usr/local/lib/utils
|
||||||
|
|
||||||
|
# The composite gadget directory
|
||||||
|
GADGET=/sys/kernel/config/usb_gadget/funkey
|
||||||
|
|
||||||
|
# Check if Ethernet over USB network is requested
|
||||||
|
[ ! -f /mnt/usbnet ]
|
||||||
|
USBNET=$?
|
||||||
|
|
||||||
|
# USB VID for Linux Foundation
|
||||||
|
ID_VENDOR="0x1d6b"
|
||||||
|
|
||||||
|
# USB PID for Multifunction Composite Gadget
|
||||||
|
ID_PRODUCT="0x0104"
|
||||||
|
|
||||||
|
# Get the CPU serial number
|
||||||
|
SERIAL="$(grep Serial /proc/cpuinfo | sed 's/Serial\s*: \(\w*\)/\1/')"
|
||||||
|
|
||||||
|
# Build a MAC address from it
|
||||||
|
MAC="$(echo ${SERIAL} | sed 's/\(\w\w\)/:\1/g' | cut -b 2-)"
|
||||||
|
|
||||||
|
# Derive host and device MAC addresses
|
||||||
|
MAC_HOST="12$(echo ${MAC} | cut -b 3-)"
|
||||||
|
MAC_DEV="02$(echo ${MAC} | cut -b 3-)"
|
||||||
|
|
||||||
|
# Initialize the USB gadget
|
||||||
|
init_usb_gadget() {
|
||||||
|
|
||||||
|
# Don't proceed if existing gadget is present
|
||||||
|
if [ -e ${GADGET} ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get the legacy drivers out of the way
|
||||||
|
modprobe -r g_ether
|
||||||
|
modprobe -r g_mass_storage
|
||||||
|
|
||||||
|
# Load the libcomposite USB driver
|
||||||
|
modprobe libcomposite
|
||||||
|
|
||||||
|
# USB Device Controller Driver
|
||||||
|
local udc_driver=$(ls /sys/class/udc | cut -f1 | head -n 1)
|
||||||
|
|
||||||
|
# Create our gadget directory
|
||||||
|
mkdir ${GADGET}
|
||||||
|
mkdir ${GADGET}/strings/0x409
|
||||||
|
mkdir ${GADGET}/configs/c.1
|
||||||
|
mkdir ${GADGET}/configs/c.1/strings/0x409
|
||||||
|
test $USBNET -eq 1 && mkdir ${GADGET}/functions/rndis.usb0
|
||||||
|
mkdir ${GADGET}/functions/mass_storage.funkey
|
||||||
|
|
||||||
|
# USB2
|
||||||
|
echo "0x0200" > ${GADGET}/bcdUSB
|
||||||
|
|
||||||
|
# Communication Device Class
|
||||||
|
if [ $USBNET -eq 1 ]; then
|
||||||
|
echo "0x02" > ${GADGET}/bDeviceClass
|
||||||
|
echo "0x00" > ${GADGET}/bDeviceSubClass
|
||||||
|
fi
|
||||||
|
|
||||||
|
# USB VID and PID
|
||||||
|
echo ${ID_VENDOR} > ${GADGET}/idVendor
|
||||||
|
echo ${ID_PRODUCT} > ${GADGET}/idProduct
|
||||||
|
|
||||||
|
# Device Release Number
|
||||||
|
echo "0x0100" > ${GADGET}/bcdDevice
|
||||||
|
|
||||||
|
# Device String Descriptiors
|
||||||
|
echo "FunKey" > ${GADGET}/strings/0x409/manufacturer
|
||||||
|
echo "FunKey S" > ${GADGET}/strings/0x409/product
|
||||||
|
echo ${SERIAL} > ${GADGET}/strings/0x409/serialnumber
|
||||||
|
|
||||||
|
# Turn on "OS Descriptors" support for RNDIS
|
||||||
|
if [ $USBNET -eq 1 ]; then
|
||||||
|
echo 1 > ${GADGET}/os_desc/use
|
||||||
|
echo "0xcd" > ${GADGET}/os_desc/b_vendor_code
|
||||||
|
echo "MSFT100" > ${GADGET}/os_desc/qw_sign
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
|
||||||
|
# Maximum power is 500 mA
|
||||||
|
echo 500 > ${GADGET}/configs/c.1/MaxPower
|
||||||
|
|
||||||
|
# Configruation String Descriptors
|
||||||
|
if [ $USBNET -eq 1 ]; then
|
||||||
|
echo "Mass Storage + RNDIS" > ${GADGET}/configs/c.1/strings/0x409/configuration
|
||||||
|
else
|
||||||
|
echo "Mass Storage" > ${GADGET}/configs/c.1/strings/0x409/configuration
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $USBNET -eq 1 ]; then
|
||||||
|
|
||||||
|
# Make c.1 the one associated with OS Descriptors
|
||||||
|
ln -s ${GADGET}/configs/c.1 ${GADGET}/os_desc
|
||||||
|
|
||||||
|
# RNDIS Function
|
||||||
|
|
||||||
|
# Host & Device MAC Addresses
|
||||||
|
echo ${MAC_HOST} > ${GADGET}/functions/rndis.usb0/host_addr
|
||||||
|
echo ${MAC_DEV} > ${GADGET}/functions/rndis.usb0/dev_addr
|
||||||
|
|
||||||
|
# Compatible ID & Sub-Compatible ID
|
||||||
|
echo "RNDIS" > ${GADGET}/functions/rndis.usb0/os_desc/interface.rndis/compatible_id
|
||||||
|
echo "5162001" > ${GADGET}/functions/rndis.usb0/os_desc/interface.rndis/sub_compatible_id
|
||||||
|
|
||||||
|
# Add the "Icons" Extended Property
|
||||||
|
mkdir ${GADGET}/functions/rndis.usb0/os_desc/interface.rndis/Icons
|
||||||
|
echo 2 > ${GADGET}/functions/rndis.usb0/os_desc/interface.rndis/Icons/type
|
||||||
|
echo "%SystemRoot%\\system32\\shell32.dll,-233" > ${GADGET}/functions/rndis.usb0/os_desc/interface.rndis/Icons/data
|
||||||
|
|
||||||
|
# Add the "Label" Extended Property
|
||||||
|
mkdir ${GADGET}/functions/rndis.usb0/os_desc/interface.rndis/Label
|
||||||
|
echo 1 > ${GADGET}/functions/rndis.usb0/os_desc/interface.rndis/Label/type
|
||||||
|
echo "FunKey S Device" > ${GADGET}/functions/rndis.usb0/os_desc/interface.rndis/Label/data
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Mass Storage Function
|
||||||
|
|
||||||
|
# Backing Store file
|
||||||
|
#echo "/dev/mmcblk0p3" > ${GADGET}/functions/mass_storage.funkey/lun.0/file
|
||||||
|
|
||||||
|
# Gadget is not allowed to halt bulk endpoints
|
||||||
|
echo 0 > ${GADGET}/functions/mass_storage.funkey/stall
|
||||||
|
|
||||||
|
# Do not simulate a CDROM
|
||||||
|
echo 0 > ${GADGET}/functions/mass_storage.funkey/lun.0/cdrom
|
||||||
|
|
||||||
|
# No SCSI Force Unit Access (FUA) to work in synchronous mode ?!?
|
||||||
|
echo 0 > ${GADGET}/functions/mass_storage.funkey/lun.0/nofua
|
||||||
|
|
||||||
|
# LUN is removable
|
||||||
|
echo 1 > ${GADGET}/functions/mass_storage.funkey/lun.0/removable
|
||||||
|
|
||||||
|
# Inquiry String
|
||||||
|
echo "FunKey S Shared Disk" > ${GADGET}/functions/mass_storage.funkey/lun.0/inquiry_string
|
||||||
|
|
||||||
|
if [ $USBNET -eq 1 ]; then
|
||||||
|
|
||||||
|
# Add the RNDIS function to the c.1 configuration
|
||||||
|
ln -s ${GADGET}/functions/rndis.usb0 ${GADGET}/configs/c.1
|
||||||
|
|
||||||
|
# Bind the USB Gadget as RNDIS device
|
||||||
|
echo ${udc_driver} > ${GADGET}/UDC
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
# Start network services
|
||||||
|
systemctl start networking ntp dropbear > /dev/null 2>&1
|
||||||
|
|
||||||
|
# Unbind the device
|
||||||
|
echo > ${GADGET}/UDC
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Add the Mass Storage function to the c.1 configuration
|
||||||
|
ln -s ${GADGET}/functions/mass_storage.funkey ${GADGET}/configs/c.1
|
||||||
|
|
||||||
|
# Each interface specifies its own class code
|
||||||
|
echo "0x00" > ${GADGET}/bDeviceClass
|
||||||
|
|
||||||
|
# Bind the USB Gadget as a Mass Storage device
|
||||||
|
echo ${udc_driver} > ${GADGET}/UDC
|
||||||
|
return 0
|
||||||
|
}
|
|
@ -1,59 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Uncomment the following line to get debug info
|
|
||||||
#set -xv
|
|
||||||
|
|
||||||
fw_saveenv () {
|
|
||||||
|
|
||||||
# Check arguments
|
|
||||||
if [ $# -ne 1 ]; then
|
|
||||||
echo "usage: fw_saveenv filename" >&2 | tee /dev/kmsg
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Save the input file name
|
|
||||||
local input_file=${1}
|
|
||||||
|
|
||||||
# Read the fw_env config file
|
|
||||||
local config=$(sed -e 's/#.*$//' -e '/^$/d' /etc/fw_env.config)
|
|
||||||
set ${config}
|
|
||||||
local of=${1}
|
|
||||||
local seek=$((${2} / 1024))
|
|
||||||
local count=$((${3} / 1024))
|
|
||||||
|
|
||||||
# Create 2 temporary files
|
|
||||||
local tmp_file=$(mktemp /tmp/fw_saveenv.XXXXXX)
|
|
||||||
local raw_file=$(mktemp /tmp/fw_saveenv.XXXXXX)
|
|
||||||
local raw2_file=$(mktemp /tmp/fw_saveenv.XXXXXX)
|
|
||||||
|
|
||||||
# Convert provided file to null-terminated string blob
|
|
||||||
cat ${input_file} | tr '\n' '\0' > ${tmp_file}
|
|
||||||
|
|
||||||
# Compute blob length in bytes
|
|
||||||
local length=$(stat --printf="%s" ${tmp_file})
|
|
||||||
|
|
||||||
# Compute the padding size
|
|
||||||
let length=${count}*1024-4-${length}
|
|
||||||
|
|
||||||
# Pad blob with zeros up to the total size
|
|
||||||
dd if=/dev/zero bs=1 count=${length} >>${tmp_file} 2>/dev/null
|
|
||||||
|
|
||||||
# Compute the CRC32 for the padded blob and store it into the final file
|
|
||||||
cat ${tmp_file} | gzip -1 | tail -c 8 | head -c 4 | \
|
|
||||||
hexdump -e '1/4 "%08x" "\n"' | xxd -r -p > ${raw_file}
|
|
||||||
|
|
||||||
# Convert CRC32 to little endian
|
|
||||||
tac -rs '.' ${raw_file} > ${raw2_file}
|
|
||||||
|
|
||||||
# Append the binary blob to the final file
|
|
||||||
cat ${tmp_file} >> ${raw2_file}
|
|
||||||
|
|
||||||
# Write the final file to the raw device
|
|
||||||
dd if=${raw2_file} of=${1} bs=1k count=$((${3} / 1024)) seek=$((${2} / 1024)) 2>/dev/null
|
|
||||||
|
|
||||||
# Remove the temporay files
|
|
||||||
rm ${tmp_file} ${raw_file} ${raw2_file}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
fw_saveenv $*
|
|
|
@ -1,80 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
#set -x
|
|
||||||
|
|
||||||
THIS=$(basename $0)
|
|
||||||
|
|
||||||
echo "$THIS: resizing rootfs" | tee /dev/kmsg
|
|
||||||
|
|
||||||
if [ $(id -u) -ne 0 ]; then
|
|
||||||
echo "$THIS: this script must be run as root. Try 'sudo resize_rootfs'\n" | tee /dev/kmsg
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
ROOT_PART=$(cat /proc/cmdline | sed -n 's|^.*root=/dev/\([^ ]*\).*|\1|p')
|
|
||||||
|
|
||||||
PART_NUM=${ROOT_PART#mmcblk0p}
|
|
||||||
if [ "$PART_NUM" = "$ROOT_PART" ]; then
|
|
||||||
echo "$THIS: $ROOT_PART is not an SD card. Don't know how to expand" | tee /dev/kmsg
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$PART_NUM" -ne 2 ]; then
|
|
||||||
echo "$THIS: your partition layout is not currently supported by this tool" | tee /dev/kmsg
|
|
||||||
exit 3
|
|
||||||
fi
|
|
||||||
|
|
||||||
LAST_PART_LINE=$(fdisk /dev/mmcblk0 -l | grep '^/' | tail -n 1)
|
|
||||||
set $LAST_PART_LINE
|
|
||||||
LAST_PART=${1#/dev/}
|
|
||||||
PART_START=${2}
|
|
||||||
if [ "$LAST_PART" != "$ROOT_PART" ]; then
|
|
||||||
echo "$THIS: $ROOT_PART is not the last partition. Don't know how to expand" | tee /dev/kmsg
|
|
||||||
exit 4
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Return value will likely be error for fdisk as it fails to reload the
|
|
||||||
# partition table because the root fs is mounted
|
|
||||||
# NOTE: This script only works the genuine fdisk, NOT with the busybox one!!!
|
|
||||||
fdisk /dev/mmcblk0 <<EOF
|
|
||||||
p
|
|
||||||
d
|
|
||||||
$PART_NUM
|
|
||||||
n
|
|
||||||
p
|
|
||||||
$PART_NUM
|
|
||||||
$PART_START
|
|
||||||
|
|
||||||
n
|
|
||||||
p
|
|
||||||
w
|
|
||||||
EOF
|
|
||||||
sync
|
|
||||||
|
|
||||||
# Now set up an init.d script
|
|
||||||
cat <<EOF > /etc/init.d/S02resize2fs &&
|
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
THIS=\$(basename \$0)
|
|
||||||
|
|
||||||
case "\$1" in
|
|
||||||
start)
|
|
||||||
sleep 1
|
|
||||||
echo "\$THIS: starting resizing the root filesystem" | tee /dev/kmsg &&
|
|
||||||
resize2fs /dev/$ROOT_PART &&
|
|
||||||
rm /etc/init.d/S02resize2fs
|
|
||||||
if [ \$? -eq 0 ]; then
|
|
||||||
echo "\$THIS: finished resizing the root filesystem" | tee /dev/kmsg
|
|
||||||
else
|
|
||||||
echo "\$THIS: cannot resize the root filesystem, aborting" | tee /dev/kmsg
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Usage: \$0 start" >&2
|
|
||||||
exit 3
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
EOF
|
|
||||||
chmod +x /etc/init.d/S02resize2fs
|
|
||||||
echo "$THIS: the root partition has been resized" | tee /dev/kmsg
|
|
||||||
echo "$THIS: the system must reboot to enlarge the root filesystem" | tee /dev/kmsg
|
|
|
@ -1,126 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
#set -x
|
|
||||||
|
|
||||||
THIS=$(basename $0)
|
|
||||||
|
|
||||||
case "${1}" in
|
|
||||||
start)
|
|
||||||
|
|
||||||
if [ ! -f /mass_storage ]; then
|
|
||||||
echo "$THIS: no shared storage file, create it" | tee /dev/kmsg
|
|
||||||
dd if=/dev/zero of=/mass_storage bs=1M seek=1024 count=0 &&
|
|
||||||
cat <<EOF | sfdisk /mass_storage
|
|
||||||
,,C
|
|
||||||
EOF
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "$THIS: cannot create shared storage file" | tee /dev/kmsg
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
UNIT_LINE=$(fdisk -l /mass_storage | egrep Units)
|
|
||||||
UNIT=$(echo "$UNIT_LINE" | cut -f 8 -d ' ')
|
|
||||||
PART_LINE=$(fdisk -l /mass_storage | egrep /mass_storage1)
|
|
||||||
set $PART_LINE
|
|
||||||
let START="${2} * $UNIT"
|
|
||||||
if [ x"$START" = x -o $START -eq 0 ]; then
|
|
||||||
echo "$THIS: cannot find shared storage file start" | tee /dev/kmsg
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
losetup -o$START /dev/loop0 /mass_storage &&
|
|
||||||
mkfs.vfat /dev/loop0 &&
|
|
||||||
losetup -d /dev/loop0
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "$THIS: cannot format shared storage file" | tee /dev/kmsg
|
|
||||||
exit 3
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
lsmod | egrep -q ^g_mass_storage
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
echo "$THIS; shared storage already started" | tee /dev/kmsg
|
|
||||||
exit 4
|
|
||||||
fi
|
|
||||||
echo "$THIS: start shared storage" | tee /dev/kmsg
|
|
||||||
modprobe g_mass_storage file=/mass_storage
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "$THIS: cannot start shared storage" | tee /dev/kmsg
|
|
||||||
exit 5
|
|
||||||
fi
|
|
||||||
echo "$THIS: shared storage started" | tee /dev/kmsg
|
|
||||||
;;
|
|
||||||
|
|
||||||
stop)
|
|
||||||
echo "$THIS: stop shared storage" | tee /dev/kmsg
|
|
||||||
lsmod | egrep -q ^g_mass_storage
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
modprobe -r g_mass_storage
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "$THIS: cannot stop shared storage" | tee /dev/kmsg
|
|
||||||
exit 6
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "$THIS: shared storage not started" | tee /dev/kmsg
|
|
||||||
exit 7
|
|
||||||
fi
|
|
||||||
echo "$THIS: shared storage stopped" | tee /dev/kmsg
|
|
||||||
;;
|
|
||||||
|
|
||||||
mount)
|
|
||||||
if [ ! -f /mass_storage ]; then
|
|
||||||
echo "$THIS: no shared storage file" | tee /dev/kmsg
|
|
||||||
exit 8
|
|
||||||
fi
|
|
||||||
echo "$THIS: mounting shared storage" | tee /dev/kmsg
|
|
||||||
UNIT_LINE=$(fdisk -l /mass_storage | egrep Units)
|
|
||||||
UNIT=$(echo "$UNIT_LINE" | cut -f 8 -d ' ')
|
|
||||||
PART_LINE=$(fdisk -l /mass_storage | egrep /mass_storage1)
|
|
||||||
set $PART_LINE
|
|
||||||
let START="${2} * $UNIT"
|
|
||||||
if [ x"$START" = x -o $START -eq 0 ]; then
|
|
||||||
echo "$THIS: cannot find shared storage file start" | tee /dev/kmsg
|
|
||||||
exit 9
|
|
||||||
fi
|
|
||||||
losetup -o$START /dev/loop0 /mass_storage
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "$THIS: cannot loop mount shared storage file" | tee /dev/kmsg
|
|
||||||
exit 10
|
|
||||||
fi
|
|
||||||
fsck.fat -n /dev/loop0 2>/dev/null | egrep -q "Dirty bit"
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
echo "$THIS: filesystem was not properly unmounted, clean it" | tee /dev/kmsg
|
|
||||||
fsck.fat -a -t -w /dev/loop0 >/dev/null 2>&1
|
|
||||||
if [ $? -gt 1 ]; then
|
|
||||||
echo "$THIS: cannot clean shared storage file" | tee /dev/kmsg
|
|
||||||
exit 11
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
mount -t vfat /dev/loop0 /mnt/
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "$THIS: cannot mount shared storage file" | tee /dev/kmsg
|
|
||||||
exit 12
|
|
||||||
fi
|
|
||||||
echo "$THIS: shared storage mounted" | tee /dev/kmsg
|
|
||||||
;;
|
|
||||||
|
|
||||||
umount)
|
|
||||||
losetup -a | egrep -q /mass_storage
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "$THIS: no mounted shared storage file" | tee /dev/kmsg
|
|
||||||
exit 13
|
|
||||||
fi
|
|
||||||
echo "unmounting shared storage"
|
|
||||||
umount /mnt &
|
|
||||||
losetup -d /dev/loop0
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "$THIS: cannot unmount shared storage" | tee /dev/kmsg
|
|
||||||
exit 14
|
|
||||||
fi
|
|
||||||
echo "$THIS: shared storage unmounted" | tee //dev/kmsg
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
echo "Usage ${0} {start|stop|mount|umount}"
|
|
||||||
exit 15
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
modprobe g_ether
|
|
||||||
HOST_USB_IP=10.0.1.1
|
|
||||||
TARGET_USB_IP=10.0.1.2
|
|
||||||
ifconfig usb0 $TARGET_USB_IP netmask 255.255.255.0
|
|
||||||
route add default dev usb0
|
|
||||||
route add default gw $HOST_USB_IP
|
|
||||||
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
|
|
||||||
RSA_KEYFILE=/etc/dropbear/dropbear_rsa_host_key
|
|
||||||
dropbearkey -t rsa -f $RSA_KEYFILE
|
|
|
@ -4,7 +4,7 @@ BR2_DL_DIR="$(BR2_EXTERNAL_FUNKEY_PATH)/dl"
|
||||||
BR2_CCACHE=y
|
BR2_CCACHE=y
|
||||||
BR2_GLOBAL_PATCH_DIR="$(BR2_EXTERNAL_FUNKEY_PATH)/board/funkey/patches"
|
BR2_GLOBAL_PATCH_DIR="$(BR2_EXTERNAL_FUNKEY_PATH)/board/funkey/patches"
|
||||||
BR2_TOOLCHAIN_EXTERNAL=y
|
BR2_TOOLCHAIN_EXTERNAL=y
|
||||||
BR2_TARGET_GENERIC_HOSTNAME="funkey"
|
BR2_TARGET_GENERIC_HOSTNAME="FunKey"
|
||||||
BR2_TARGET_GENERIC_ISSUE="Welcome to Buildroot for the FunKey"
|
BR2_TARGET_GENERIC_ISSUE="Welcome to Buildroot for the FunKey"
|
||||||
BR2_ROOTFS_DEVICE_TABLE="$(BR2_EXTERNAL_FUNKEY_PATH)/board/funkey/device_table.txt"
|
BR2_ROOTFS_DEVICE_TABLE="$(BR2_EXTERNAL_FUNKEY_PATH)/board/funkey/device_table.txt"
|
||||||
BR2_TARGET_GENERIC_ROOT_PASSWD="funkey"
|
BR2_TARGET_GENERIC_ROOT_PASSWD="funkey"
|
||||||
|
|
Loading…
Reference in New Issue