From 52f377fb3b61184bccf300a01e925fffcb53fa93 Mon Sep 17 00:00:00 2001 From: Michel-FK Date: Sun, 10 May 2020 17:31:38 +0200 Subject: [PATCH] init scripts & usb gadget cleanup, login banner --- .../rootfs-overlay/etc/default/dropbear | 3 ++ .../funkey/rootfs-overlay/etc/init.d/S02share | 2 +- .../rootfs-overlay/etc/init.d/S20urandom | 51 +++++++++++++++++++ .../rootfs-overlay/etc/init.d/S41dhcpcd | 48 +++++++++++++++++ .../rootfs-overlay/etc/init.d/S50alsa-utils | 8 +-- .../board/funkey/rootfs-overlay/etc/inittab | 2 +- FunKey/board/funkey/rootfs-overlay/etc/issue | 2 +- .../funkey/rootfs-overlay/etc/u-boot.env | 2 +- .../rootfs-overlay/lib/lsb/init-functions | 10 ++-- .../rootfs-overlay/usr/local/sbin/first_boot | 33 ++++++++---- .../rootfs-overlay/usr/local/sbin/usb_gadget | 38 +++++++------- 11 files changed, 156 insertions(+), 43 deletions(-) create mode 100644 FunKey/board/funkey/rootfs-overlay/etc/default/dropbear create mode 100755 FunKey/board/funkey/rootfs-overlay/etc/init.d/S20urandom create mode 100755 FunKey/board/funkey/rootfs-overlay/etc/init.d/S41dhcpcd diff --git a/FunKey/board/funkey/rootfs-overlay/etc/default/dropbear b/FunKey/board/funkey/rootfs-overlay/etc/default/dropbear new file mode 100644 index 0000000..62d55ee --- /dev/null +++ b/FunKey/board/funkey/rootfs-overlay/etc/default/dropbear @@ -0,0 +1,3 @@ +#!/bin/sh + +DROPBEAR_ARGS="-b /etc/issue" diff --git a/FunKey/board/funkey/rootfs-overlay/etc/init.d/S02share b/FunKey/board/funkey/rootfs-overlay/etc/init.d/S02share index ec37c3d..6a73137 100755 --- a/FunKey/board/funkey/rootfs-overlay/etc/init.d/S02share +++ b/FunKey/board/funkey/rootfs-overlay/etc/init.d/S02share @@ -13,7 +13,7 @@ case "$1" in fi ;; stop) - if share stop; then + if share stop >/dev/null 2>&1; then echo "Stopping share: OK" exit 0 else diff --git a/FunKey/board/funkey/rootfs-overlay/etc/init.d/S20urandom b/FunKey/board/funkey/rootfs-overlay/etc/init.d/S20urandom new file mode 100755 index 0000000..126c9d4 --- /dev/null +++ b/FunKey/board/funkey/rootfs-overlay/etc/init.d/S20urandom @@ -0,0 +1,51 @@ +#! /bin/sh +# +# urandom This script saves the random seed between reboots. +# It is called from the boot, halt and reboot scripts. +# +# Version: @(#)urandom 1.33 22-Jun-1998 miquels@cistron.nl +# + +[ -c /dev/urandom ] || exit 0 +#. /etc/default/rcS + +case "$1" in + start|"") + # check for read only file system + if ! touch /etc/random-seed 2>/dev/null + then +# echo "read-only file system detected...done" + exit + fi + if [ "$VERBOSE" != no ] + then + echo -n "Starting random number generator: " + fi + # Load and then save 512 bytes, + # which is the size of the entropy pool + cat /etc/random-seed >/dev/urandom + rm -f /etc/random-seed + umask 077 + dd if=/dev/urandom of=/etc/random-seed count=1 \ + >/dev/null 2>&1 || echo "ERROR" + umask 022 + [ "$VERBOSE" != no ] && echo "OK" + ;; + stop) + if ! touch /etc/random-seed 2>/dev/null + then + exit + fi + # Carry a random seed from shut-down to start-up; + # see documentation in linux/drivers/char/random.c + [ "$VERBOSE" != no ] && echo -n "Stopping random number generator: " + umask 077 + dd if=/dev/urandom of=/etc/random-seed count=1 \ + >/dev/null 2>&1 || echo "ERROR" + [ "$VERBOSE" != no ] && echo "OK" + ;; + *) + echo "Usage: urandom {start|stop}" >&2 + exit 1 + ;; +esac diff --git a/FunKey/board/funkey/rootfs-overlay/etc/init.d/S41dhcpcd b/FunKey/board/funkey/rootfs-overlay/etc/init.d/S41dhcpcd new file mode 100755 index 0000000..24f985f --- /dev/null +++ b/FunKey/board/funkey/rootfs-overlay/etc/init.d/S41dhcpcd @@ -0,0 +1,48 @@ +#!/bin/sh +# +# Start/stop dhcpcd +# + +DAEMON=/sbin/dhcpcd +CONFIG=/etc/dhcpcd.conf +PIDFILE=/var/run/dhcpcd.pid + +[ -f $CONFIG ] || exit 0 + +case "$1" in + start) + echo -n "Starting dhcpcd: " + start-stop-daemon -S -x "$DAEMON" -p "$PIDFILE" -- -f "$CONFIG" > /dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "OK" + else + echo "ERROR" + fi + ;; + stop) + echo -n "Stopping dhcpcd: " + start-stop-daemon -K -x "$DAEMON" -p "$PIDFILE" -o > /dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "OK" + else + echo "ERROR" + fi + ;; + reload|force-reload) + echo -n "Reloading dhcpcd configuration: " + "$DAEMON" -s reload >/dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "OK" + else + echo "ERROR" + fi + ;; + restart) + "$0" stop + sleep 1 # Prevent race condition: ensure dhcpcd stops before start. + "$0" start + ;; + *) + echo "Usage: $0 {start|stop|restart|reload|force-reload}" + exit 1 +esac diff --git a/FunKey/board/funkey/rootfs-overlay/etc/init.d/S50alsa-utils b/FunKey/board/funkey/rootfs-overlay/etc/init.d/S50alsa-utils index e6a6e92..6621fe8 100755 --- a/FunKey/board/funkey/rootfs-overlay/etc/init.d/S50alsa-utils +++ b/FunKey/board/funkey/rootfs-overlay/etc/init.d/S50alsa-utils @@ -161,8 +161,8 @@ case "$1" in EXITSTATUS=0 TARGET_CARD="$2" case "$TARGET_CARD" in - ""|all) TARGET_CARD=all ; log_action_begin_msg "Setting up ALSA" ;; - *) log_action_begin_msg "Setting up ALSA card ${TARGET_CARD}" ;; + ""|all) TARGET_CARD=all ; log_action_begin_msg "Starting ALSA" ;; + *) log_action_begin_msg "Starting ALSA card ${TARGET_CARD}" ;; esac card_OK "$TARGET_CARD" || log_action_end_msg_and_exit "$( [ ! "$2" ] ; echo $? ; )" "none loaded" preinit_levels "$TARGET_CARD" || EXITSTATUS=1 @@ -176,8 +176,8 @@ case "$1" in EXITSTATUS=0 TARGET_CARD="$2" case "$TARGET_CARD" in - ""|all) TARGET_CARD=all ; log_action_begin_msg "Shutting down ALSA" ;; - *) log_action_begin_msg "Shutting down ALSA card ${TARGET_CARD}" ;; + ""|all) TARGET_CARD=all ; log_action_begin_msg "Stopping ALSA" ;; + *) log_action_begin_msg "Stopping ALSA card ${TARGET_CARD}" ;; esac card_OK "$TARGET_CARD" || log_action_end_msg_and_exit "$( [ ! "$2" ] ; echo $? ; )" "none loaded" store_levels "$TARGET_CARD" || EXITSTATUS=1 diff --git a/FunKey/board/funkey/rootfs-overlay/etc/inittab b/FunKey/board/funkey/rootfs-overlay/etc/inittab index ef6cc78..119c823 100644 --- a/FunKey/board/funkey/rootfs-overlay/etc/inittab +++ b/FunKey/board/funkey/rootfs-overlay/etc/inittab @@ -14,7 +14,7 @@ # process == program to run # Startup the system -::sysinit:/bin/sh -c 'echo "Starting FunKey-OS ..."' +::sysinit:/bin/cat /etc/issue ::sysinit:/bin/mount -t proc proc /proc ::sysinit:/bin/mount -o remount,rw / ::sysinit:/bin/mkdir -p /dev/pts /dev/shm diff --git a/FunKey/board/funkey/rootfs-overlay/etc/issue b/FunKey/board/funkey/rootfs-overlay/etc/issue index 5ef3412..c853c05 100644 --- a/FunKey/board/funkey/rootfs-overlay/etc/issue +++ b/FunKey/board/funkey/rootfs-overlay/etc/issue @@ -2,7 +2,7 @@ _______ __ __ | ___|.--.--.-----.| |/ |.-----.--.--. | ___|| | | || < | -__| | | -|___| |_____|__|__||__|\\__||_____|___ | +|___| |_____|__|__||__|\__||_____|___ | FUN ON A KEYCHAIN |_____| ----------------------------------------------------- Version 0.3 diff --git a/FunKey/board/funkey/rootfs-overlay/etc/u-boot.env b/FunKey/board/funkey/rootfs-overlay/etc/u-boot.env index 445430e..27bbfd4 100644 --- a/FunKey/board/funkey/rootfs-overlay/etc/u-boot.env +++ b/FunKey/board/funkey/rootfs-overlay/etc/u-boot.env @@ -1,5 +1,5 @@ arch=arm -args_mmc=setenv bootargs console=ttyS0,115200 panic=5 rootwait fbcon=map:10 fbcon=font:VGA8x8 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=120,data=writeback,barrier=0,journal_async_commit rw resume=/dev/mmcblk0p2 resume_offset=88064 hibernate=nocompress quiet +args_mmc=setenv bootargs console=ttyS0,115200 panic=5 rootwait fbcon=map:10 fbcon=font:VGA8x8 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=120,data=writeback,barrier=0,journal_async_commit rw quiet baudrate=115200 board=sunxi board_name=sunxi diff --git a/FunKey/board/funkey/rootfs-overlay/lib/lsb/init-functions b/FunKey/board/funkey/rootfs-overlay/lib/lsb/init-functions index 1a0b2f0..a326eb2 100755 --- a/FunKey/board/funkey/rootfs-overlay/lib/lsb/init-functions +++ b/FunKey/board/funkey/rootfs-overlay/lib/lsb/init-functions @@ -10,7 +10,7 @@ log_action_msg () { } log_action_begin_msg () { - echo "${THIS}${@}..." | tee /dev/kmsg + echo -n "${THIS}${@}: " | tee /dev/kmsg } log_action_cont_msg () { @@ -20,15 +20,15 @@ log_action_cont_msg () { log_action_end_msg () { local end if [ -z "${2:-}" ]; then - end="." + end="" else - end=" ($2)." + end=" ($2)" fi if [ $1 -eq 0 ]; then - echo "${THIS}done${end}" | tee /dev/kmsg + echo "${THIS}OK${end}" | tee /dev/kmsg else - echo "${THIS}failed${end}" | tee /dev/kmsg + echo "${THIS}ERROR${end}" | tee /dev/kmsg fi } diff --git a/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/first_boot b/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/first_boot index 3ec6736..2ebd0c7 100755 --- a/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/first_boot +++ b/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/first_boot @@ -7,6 +7,15 @@ SELF=$(basename $0) source /usr/local/lib/utils +notif () { + info "$@" + printf "$@" > /sys/class/graphics/fb0/notification +} + +clear_notif () { + printf "clear" > /sys/class/graphics/fb0/notification +} + check_swap () { [ -f /swap ] && die 0 "nothing to do" return 0 @@ -142,35 +151,37 @@ format_backing_store_partition () { return 0 } -info "First boot detected!" +notif "First boot detected!" check_swap check_root_id -info "Step 1/9 - Resize the rootfs partition" +notif "1/9 Resize root partition" resize_rootfs_partition -info "Step 2/9 - Reload the partition table" +notif "2/9 Reload partition table" reload_partition_table -info "Step 3/9 - Resize the root filesystem" +notif "3/9 Resize root filsystem" resize_rootfs_filesystem -info "Step 4/9 - Write the bootloader environment" +notif "4/9 Write boot environment" write_bootloader_env -info "Step 5/9 - Create the swap file" +notif "5/9 Create swap" create_swap_file -info "Step 6/9 - Enable the swap file" +notif "6/9 Enable swap" enable_swap_file -info "Step 7/9 - Create the backing store partition" +notif "6/9 Create share partition" create_backing_store_partition -info "Step 8/9 - Reload the partition table" +notif "8/9 Reload partition table" reload_partition_table -info "Step 9/9 - Format the backing store partition" +notif "9/9 Format share partition" format_backing_store_partition -info "First boot setup finished!" +notif "First boot setup finished!" +sleep 1 +clear_notif diff --git a/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/usb_gadget b/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/usb_gadget index 0316a55..7cfffaf 100755 --- a/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/usb_gadget +++ b/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/usb_gadget @@ -7,7 +7,7 @@ SELF=${SELF:-$(basename $0)} source /usr/local/lib/utils # The composite gadget directory -GADGET=/sys/kernel/config/usb_gadget/funkey +GADGET=/sys/kernel/config/usb_gadget/FunKey # Check if Ethernet over USB network is requested [ ! -f /mnt/usbnet ] @@ -50,10 +50,10 @@ init_usb_gadget() { # Create our gadget directory mkdir ${GADGET} mkdir ${GADGET}/strings/0x409 - mkdir ${GADGET}/configs/c.1 - mkdir ${GADGET}/configs/c.1/strings/0x409 + mkdir ${GADGET}/configs/FunKey.1 + mkdir ${GADGET}/configs/FunKey.1/strings/0x409 test $USBNET -eq 1 && mkdir ${GADGET}/functions/rndis.usb0 - mkdir ${GADGET}/functions/mass_storage.funkey + mkdir ${GADGET}/functions/mass_storage.mmcblk0p3 # USB2 echo "0x0200" > ${GADGET}/bcdUSB @@ -86,19 +86,19 @@ init_usb_gadget() { # Configuration # Maximum power is 500 mA - echo 500 > ${GADGET}/configs/c.1/MaxPower + echo 500 > ${GADGET}/configs/FunKey.1/MaxPower # Configruation String Descriptors if [ $USBNET -eq 1 ]; then - echo "Mass Storage + RNDIS" > ${GADGET}/configs/c.1/strings/0x409/configuration + echo "Mass Storage + RNDIS" > ${GADGET}/configs/FunKey.1/strings/0x409/configuration else - echo "Mass Storage" > ${GADGET}/configs/c.1/strings/0x409/configuration + echo "Mass Storage" > ${GADGET}/configs/FunKey.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 + # Make the FunKey.1 configuration the one associated with OS Descriptors + ln -s ${GADGET}/configs/FunKey.1 ${GADGET}/os_desc # RNDIS Function @@ -124,27 +124,27 @@ init_usb_gadget() { # Mass Storage Function # Backing Store file - #echo "/dev/mmcblk0p3" > ${GADGET}/functions/mass_storage.funkey/lun.0/file + #echo "/dev/mmcblk0p3" > ${GADGET}/functions/mass_storage.mmcblk0p3/lun.0/file # Gadget is not allowed to halt bulk endpoints - echo 0 > ${GADGET}/functions/mass_storage.funkey/stall + echo 0 > ${GADGET}/functions/mass_storage.mmcblk0p3/stall # Do not simulate a CDROM - echo 0 > ${GADGET}/functions/mass_storage.funkey/lun.0/cdrom + echo 0 > ${GADGET}/functions/mass_storage.mmcblk0p3/lun.0/cdrom # No SCSI Force Unit Access (FUA) to work in synchronous mode ?!? - echo 0 > ${GADGET}/functions/mass_storage.funkey/lun.0/nofua + echo 0 > ${GADGET}/functions/mass_storage.mmcblk0p3/lun.0/nofua # LUN is removable - echo 1 > ${GADGET}/functions/mass_storage.funkey/lun.0/removable + echo 1 > ${GADGET}/functions/mass_storage.mmcblk0p3/lun.0/removable # Inquiry String - echo "FunKey S Shared Disk" > ${GADGET}/functions/mass_storage.funkey/lun.0/inquiry_string + echo "FunKey S Shared Disk" > ${GADGET}/functions/mass_storage.mmcblk0p3/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 + # Add the RNDIS function to the FunKey.1 configuration + ln -s ${GADGET}/functions/rndis.usb0 ${GADGET}/configs/FunKey.1 # Bind the USB Gadget as RNDIS device echo ${udc_driver} > ${GADGET}/UDC @@ -157,8 +157,8 @@ init_usb_gadget() { 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 + # Add the Mass Storage function to the FunKey.1 configuration + ln -s ${GADGET}/functions/mass_storage.mmcblk0p3 ${GADGET}/configs/FunKey.1 # Each interface specifies its own class code echo "0x00" > ${GADGET}/bDeviceClass