diff --git a/board/miyoo/boot/firstboot b/board/miyoo/boot/firstboot index e348a851b..285ebcf3f 100644 --- a/board/miyoo/boot/firstboot +++ b/board/miyoo/boot/firstboot @@ -118,11 +118,12 @@ done # try to read what handheld we're on when calling func console_var_func(){ - if (test -r "${BOOTDIR}/console.cfg"); then - source "${BOOTDIR}/console.cfg" + if (test -r "${CONSOLE_CFG}"); then + source "${CONSOLE_CFG}" else - export CONSOLE_VARIANT="unknown" + CONSOLE_VARIANT="unknown" fi + export CONSOLE_VARIANT } detect_console_func(){ @@ -163,13 +164,13 @@ safe_poweroff_func(){ } console_unknown_func(){ - echo "CONSOLE_VARIANT=unknown" | tee ${BOOTDIR}/console.cfg >> ${LOG} - echo "##DO_NOT_REMOVE_THIS_LINE##" >> ${BOOTDIR}/console.cfg + echo "CONSOLE_VARIANT=unknown" | tee ${CONSOLE_CFG} >> ${LOG} + echo "##DO_NOT_REMOVE_THIS_LINE##" >> ${CONSOLE_CFG} } ## Default CONSOLE_VARIANT for st7789s screens default_console_func(){ - echo "CONSOLE_VARIANT=pocketgo" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=pocketgo" | tee ${CONSOLE_CFG} >> ${LOG} cp ${BOOTDIR}/suniv-f1c100s-miyoo-4bit.dtb ${BOOTDIR}/suniv-f1c100s-miyoo.dtb # No need to overwrite uboot FORCE version for default so continue procedure CONSOLE_OVERWRITE=false @@ -194,8 +195,8 @@ test_image_func(){ else #TODO - make "invert" flag overwriting less dependent echo "Colors are inverted, changing..." | tee -a ${LOG} - sed -i '/^INVERT=/d' ${HOME}/options.cfg | tee -a ${LOG} - echo "INVERT=${INVERSION}" >> ${HOME}/options.cfg + sed -i '/^INVERT=/d' ${OPTIONS_CFG} | tee -a ${LOG} + echo "INVERT=${INVERSION}" >> ${OPTIONS_CFG} safe_reboot_func fi } @@ -212,7 +213,7 @@ test_video_func(){ # "YES" choice for Test_Video msgbox DIALOG_EXTRA exit code if test $CHOICE -eq 3; then # Correct variant for st7789s (non forced) - echo "CONSOLE_VARIANT=st7789s" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=st7789s" | tee ${CONSOLE_CFG} >> ${LOG} # "Flipped!" choice for Test_Video msgbox DIALOG_CANCEL exit code elif test $CHOICE -eq 1; then # Test_Flip-prompt double checks if user selected correct answer for 1'st video test @@ -220,7 +221,7 @@ test_video_func(){ # "NO" or timeout choice for Test_Video msgbox thus DIALOG_OK exit code elif test $CHOICE -eq 0; then # Correct variant for bittboy2x_v1 (non forced) - echo "CONSOLE_VARIANT=bittboy" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=bittboy" | tee ${CONSOLE_CFG} >> ${LOG} safe_reboot_func # Error (DIALOG_ERROR) or ESCAPE button pressed (DIALOG_ESCAPE) thus exit code -1/255 else @@ -240,7 +241,7 @@ test_video2_func(){ # "YES" choice for Test_Video'2 msgbox DIALOG_CANCEL exit code ## thus we have valid version, just update to FORCE_VERSION and continue if test $CHOICE -eq 1; then - echo "CONSOLE_VARIANT=bittboy2x_v1" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=bittboy2x_v1" | tee ${CONSOLE_CFG} >> ${LOG} # "NO" or timeout choice for Test_Video msgbox thus DIALOG_OK exit code 0 (or ERROR/ESCAPE with -1/255) ## correct variant to unknown and redo whole flashing_prd again else @@ -262,28 +263,28 @@ test_keyboard_func(){ ## thus we have valid version, just update to FORCE_VERSION and continue if test $CHOICE -eq 1; then if test "$CONSOLE_VARIANT" == "bittboy3"; then - echo "CONSOLE_VARIANT=bittboy3.5" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=bittboy3.5" | tee ${CONSOLE_CFG} >> ${LOG} elif test "$CONSOLE_VARIANT" == "bittboy2"; then - echo "CONSOLE_VARIANT=bittboy2x_v2" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=bittboy2x_v2" | tee ${CONSOLE_CFG} >> ${LOG} elif test "$CONSOLE_VARIANT" == "xyc"; then - echo "CONSOLE_VARIANT=xyc_gc9306" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=xyc_gc9306" | tee ${CONSOLE_CFG} >> ${LOG} # Test_Image-prompt if proper "invert" colors parameter was loaded: INVERSION=1 #applied only if colors are inverted test_image_func elif test "$CONSOLE_VARIANT" == "m3"; then - echo "CONSOLE_VARIANT=m3_gc9306" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=m3_gc9306" | tee ${CONSOLE_CFG} >> ${LOG} fi # "NO" or timeout choice for Test_Keyboard msgbox DIALOG_OK exit code ## thus correct Auto-Detection variant and reboot elif test $CHOICE -eq 0; then if test "$CONSOLE_VARIANT" == "bittboy3"; then - echo "CONSOLE_VARIANT=bittboy2" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=bittboy2" | tee ${CONSOLE_CFG} >> ${LOG} elif test "$CONSOLE_VARIANT" == "bittboy2"; then console_unknown_func elif test "$CONSOLE_VARIANT" == "xyc"; then console_unknown_func elif test "$CONSOLE_VARIANT" == "m3"; then - echo "CONSOLE_VARIANT=xyc" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=xyc" | tee ${CONSOLE_CFG} >> ${LOG} fi safe_reboot_func # Error (DIALOG_ERROR) or ESCAPE button pressed (DIALOG_ESCAPE) thus exit code -1/255 @@ -313,7 +314,7 @@ test_flip_func(){ echo "Performing Confirmation Flip Test" >> ${LOG} if (dialog --backtitle "MiyooCFW 2.0" --no-shadow --stdout --ok-label YES --cancel-label NO --title "Test Flip" --pause " \n Flipped? \n\nAre you sure?!" 12 15 10); then # Correct variant for bittboy3.5 (non forced) and display info about flipped image - echo "CONSOLE_VARIANT=bittboy3" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=bittboy3" | tee ${CONSOLE_CFG} >> ${LOG} dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 2 --msgbox "Image flipped! correct&reboot" 0 0 sleep 1.5 #TODO: use special Unicode characters to draw text upside-down e.g.: @@ -350,10 +351,10 @@ if ! $FOUND_CONSOLE && ! $FOUND_CONSOLE_AUTO && $CONSOLE_DETECTED; then done elif (grep -q "$DETECTED_2" "${BOOTDIR}/uEnv.txt"); then dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_2" 0 0 - echo "CONSOLE_VARIANT=m3" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=m3" | tee ${CONSOLE_CFG} >> ${LOG} elif (grep -q "$DETECTED_3" "${BOOTDIR}/uEnv.txt"); then dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_3" 0 0 - echo "CONSOLE_VARIANT=m3_r61520" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=m3_r61520" | tee ${CONSOLE_CFG} >> ${LOG} # Test_Image-prompt if proper "invert" colors parameter was loaded: INVERSION=0 #applied only if colors are inverted test_image_func @@ -362,23 +363,23 @@ if ! $FOUND_CONSOLE && ! $FOUND_CONSOLE_AUTO && $CONSOLE_DETECTED; then ## DETECTED_5 - bittboy3/2 elif (grep -q "$DETECTED_6" "${BOOTDIR}/uEnv.txt"); then dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_6" 0 0 - echo "CONSOLE_VARIANT=m3_rm68090" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=m3_rm68090" | tee ${CONSOLE_CFG} >> ${LOG} elif (grep -q "$DETECTED_7" "${BOOTDIR}/uEnv.txt"); then dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_7" 0 0 - #echo "CONSOLE_VARIANT=r61520" | tee ${BOOTDIR}/console.cfg >> ${LOG} + #echo "CONSOLE_VARIANT=r61520" | tee ${CONSOLE_CFG} >> ${LOG} elif (grep -q "$DETECTED_8" "${BOOTDIR}/uEnv.txt"); then dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_8" 0 0 - #echo "CONSOLE_VARIANT=r61505w" | tee ${BOOTDIR}/console.cfg >> ${LOG} + #echo "CONSOLE_VARIANT=r61505w" | tee ${CONSOLE_CFG} >> ${LOG} elif (grep -q "$DETECTED_9" "${BOOTDIR}/uEnv.txt"); then dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_9" 0 0 - echo "CONSOLE_VARIANT=m3_hx8347d" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=m3_hx8347d" | tee ${CONSOLE_CFG} >> ${LOG} elif (grep -q "$DETECTED_10" "${BOOTDIR}/uEnv.txt"); then dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_10" 0 0 echo "Auto-Detected $DETECTED_10, so we have trouble finding correct drivers..." >> ${LOG} - #echo "CONSOLE_VARIANT=unknown-error" | tee ${BOOTDIR}/console.cfg >> ${LOG} + #echo "CONSOLE_VARIANT=unknown-error" | tee ${CONSOLE_CFG} >> ${LOG} fi # Overwrite CONSOLE_VARIANT from new entry - source "${BOOTDIR}/console.cfg" + source "${CONSOLE_CFG}" fi # II - Test_Block @@ -406,22 +407,22 @@ if ! $FOUND_CONSOLE && $FOUND_CONSOLE_AUTO && $CONSOLE_DETECTED; then ## Perform actions based on the user's choice case $CHOICE in 1) - echo "CONSOLE_VARIANT=q20" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=q20" | tee ${CONSOLE_CFG} >> ${LOG} cp ${BOOTDIR}/suniv-f1c100s-miyoo-4bit.dtb ${BOOTDIR}/suniv-f1c100s-miyoo.dtb ;; 2) - echo "CONSOLE_VARIANT=q90" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=q90" | tee ${CONSOLE_CFG} >> ${LOG} cp ${BOOTDIR}/suniv-f1c100s-miyoo-4bit.dtb ${BOOTDIR}/suniv-f1c100s-miyoo.dtb ;; 3) - echo "CONSOLE_VARIANT=v90" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=v90" | tee ${CONSOLE_CFG} >> ${LOG} cp ${BOOTDIR}/suniv-f1c100s-miyoo-4bit.dtb ${BOOTDIR}/suniv-f1c100s-miyoo.dtb ;; 4) default_console_func ;; 5) - echo "CONSOLE_VARIANT=pocketgo_TE" | tee ${BOOTDIR}/console.cfg >> ${LOG} + echo "CONSOLE_VARIANT=pocketgo_TE" | tee ${CONSOLE_CFG} >> ${LOG} cp ${BOOTDIR}/suniv-f1c100s-miyoo-4bit.dtb ${BOOTDIR}/suniv-f1c100s-miyoo.dtb ;; *) @@ -649,7 +650,7 @@ fi if ${CHANGE_FS_P4}; then echo "Correcting inittab of p4 at ${HOME} procedure" >> ${LOG} sleep 1 - mount -o remount,rw / / + mount -o remount,rw / / 2>&1 | tee -a ${LOG} while (pgrep "mount"); do sleep 1 done @@ -658,7 +659,7 @@ if ${CHANGE_FS_P4}; then elif test "${P4_FS_TYPE}" == "BTRFS" ; then sed -i "s|\(::sysinit:/bin/mount /dev/mmcblk0p4\).*|\1 "${HOME}" -o commit=5,flushoncommit,noatime,nodiratime,exec|" /etc/inittab fi - mount -o remount,ro / / + mount -o remount,ro / / 2>&1 | tee -a ${LOG} cat /etc/inittab >> ${LOG} fi @@ -747,7 +748,7 @@ if $CHANGE_FS_P5; then ## Correct inittab for new p5 filesystem type echo "Correcting inittab of p5 at ${ROMS} procedure" >> ${LOG} sleep 1 - mount -o remount,rw / / + mount -o remount,rw / / 2>&1 | tee -a ${LOG} while (pgrep "mount"); do sleep 1 done @@ -758,14 +759,14 @@ if $CHANGE_FS_P5; then elif test "${P5_FS_TYPE}" == "EXT4"; then sed -i "s|\(::sysinit:/bin/mount /dev/mmcblk0p5\).*|\1 "${ROMS}" -o rw,noatime|" /etc/inittab fi - mount -o remount,ro / / + mount -o remount,ro / / 2>&1 | tee -a ${LOG} cat /etc/inittab >> ${LOG} fi ## Correct inittab & check if btrfs module needed for p4/p5 if ($CHANGE_FS_P4 || $CHANGE_FS_P5); then echo "Correcting inittab for btrfs module loading" >> ${LOG} - mount -o remount,rw / / + mount -o remount,rw / / 2>&1 | tee -a ${LOG} if test "${P4_FS_TYPE}" != "BTRFS" && test "${P5_FS_TYPE}" != "BTRFS" ; then sed -i 's|^::sysinit:/sbin/modprobe btrfs|#&|' /etc/inittab modprobe -r btrfs 2>&1 | tee -a "${LOGS}" @@ -773,7 +774,7 @@ if ($CHANGE_FS_P4 || $CHANGE_FS_P5); then sed -i 's|^#::sysinit:/sbin/modprobe btrfs|::sysinit:/sbin/modprobe btrfs|' /etc/inittab modprobe btrfs 2>&1 | tee -a "${LOGS}" fi - mount -o remount,ro / / + mount -o remount,ro / / 2>&1 | tee -a ${LOG} cat /etc/inittab >> ${LOG} fi @@ -876,9 +877,9 @@ rm $TEMP # disable this script mount -o remount,rw "${BOOTDIR}" 2>&1 | tee -a ${LOG} echo "Disabling the firstboot script." | tee -a ${LOG} -if grep -sq FIRSTBOOT\=\1 "${HOME}/options.cfg"; then - sed -i '/^FIRSTBOOT=/d' ${HOME}/options.cfg 2>&1 | tee -a ${LOG} - echo "FIRSTBOOT=0" >> ${HOME}/options.cfg +if grep -sq FIRSTBOOT\=\1 "${OPTIONS_CFG}"; then + sed -i '/^FIRSTBOOT=/d' ${OPTIONS_CFG} 2>&1 | tee -a ${LOG} + echo "FIRSTBOOT=0" >> ${OPTIONS_CFG} else mv "${BOOTDIR}/firstboot" "${BOOTDIR}/firstboot.done" 2>&1 | tee -a ${LOG} fi diff --git a/board/miyoo/boot/options.cfg b/board/miyoo/boot/options.cfg new file mode 100644 index 000000000..191c7c700 --- /dev/null +++ b/board/miyoo/boot/options.cfg @@ -0,0 +1,14 @@ +#In options only "0" and "1" are accepted values + +MODULES_CUSTOM=0 #load custom drivers from /boot/modules_custom.sh +DEBUG=0 #debug whole OS & output logs to $HOME/log.txt +DEBUG_GMENU2X=0 #debug gmenu2x & output logs to $HOME/log_gmenu2x.txt +DEBUG_UMTPR=0 #debug USB storage protocol $HOME/log_umtpr.txt +FIRSTBOOT=0 #perform again firstboot setup (once after reboot) +FS_CHECK=1 #check FileSystems at startup (except BTRFS) +BOOT_LOGO=1 #display scrolling boot-logo at startup +HOTKEY_CUSTOM=1 #use hotkeys from $HOME/.buttons.conf if present +USB_OTG=1 #activate USB On-The-Go for plugging ext. devices (use $HOME/.usbmode FILE for mode change) +FLIP= #(put 0 or 1 to overwrite) flip display up/down +INVERT= #(put 0 or 1 to overwrite) change colors on display to normal/invert +TV_OUT= #(put 0 or 1 to overwrite) force TV-output OFF/ON (use $HOME/.tvmode FILE for PAL/NTSC change) \ No newline at end of file diff --git a/board/miyoo/genimage-sdcard.cfg b/board/miyoo/genimage-sdcard.cfg index 0aac7e2e7..80a72576a 100644 --- a/board/miyoo/genimage-sdcard.cfg +++ b/board/miyoo/genimage-sdcard.cfg @@ -10,6 +10,7 @@ image bootfs.vfat { "boot/autorun.inf", "boot/boot.ico", "boot/console.cfg", + "boot/options.cfg", "boot/firstboot", "boot/firstboot.custom.sh-OFF", "boot/modules.custom.sh", diff --git a/board/miyoo/main/options.cfg b/board/miyoo/main/options.cfg deleted file mode 100644 index a535d59c6..000000000 --- a/board/miyoo/main/options.cfg +++ /dev/null @@ -1,13 +0,0 @@ -MODULES_CUSTOM=0 -DEBUG=0 -DEBUG_GMENU2X=0 -DEBUG_UMTPR=0 -FIRSTBOOT=0 -FS_CHECK=1 -BOOT_LOGO=1 -FLIP= (put 0 or 1 to overwrite) -INVERT= (put 0 or 1 to overwrite) -HOTKEY_CUSTOM=1 -USB_OTG=1 - -Only "0" and "1" are accepted values \ No newline at end of file diff --git a/board/miyoo/rootfs/etc/main b/board/miyoo/rootfs/etc/main index 4311c3a88..cd19e96f8 100755 --- a/board/miyoo/rootfs/etc/main +++ b/board/miyoo/rootfs/etc/main @@ -6,24 +6,34 @@ export ROMS=/roms export BOOTDIR=/boot # we expect /dev/mmcblk0p1 has been mounted here read only, from inittab export SDL_NOMOUSE=1 START="${HOME}/autoexec.sh" +export OPTIONS_CFG="${BOOTDIR}/options.cfg" +export CONSOLE_CFG="${BOOTDIR}/console.cfg" LOGS=/dev/null LOGS_TEMP=/dev/null UMTPR_LOGS=/dev/null GMENU2X_LOGS=/dev/null +FRONTEND_ACTIVE=false +test -f /tmp/frontend.active \ + && FRONTEND_ACTIVE=true +echo "FRONTEND active status: ${FRONTEND_ACTIVE}" >> ${LOGS} + +! test -r "${OPTIONS_CFG}"\ + && echo "Did not find valid ${OPTIONS_CFG} file, using default configuration." | tee -a "${LOGS}" + # check if it's first boot and turn on messages if yes -if (grep -sq DEBUG\=\1 "${HOME}/options.cfg" || test -r "${BOOTDIR}/firstboot" || test -r "${HOME}/firstboot.completed" || grep -sq FIRSTBOOT\=\1 "${HOME}/options.cfg"); then +if (grep -sq DEBUG\=\1 "${OPTIONS_CFG}" || test -r "${BOOTDIR}/firstboot" || test -r "${HOME}/firstboot.completed" || grep -sq FIRSTBOOT\=\1 "${OPTIONS_CFG}"); then DEBUG_MSG="yes" LOGS="${HOME}/log.txt" GMENU2X_LOGS="${HOME}/log_gmenu2x.txt" # just standard stdout/stderr #UMTPR_LOGS=/dev/null # see description at umtprd cmd fi -if (grep -sq DEBUG_GMENU2X\=\1 "${HOME}/options.cfg"); then +if (grep -sq DEBUG_GMENU2X\=\1 "${OPTIONS_CFG}"); then DEBUG_GMENU2X="yes" GMENU2X_LOGS="${HOME}/log_gmenu2x.txt" fi -if (grep -sq DEBUG_UMTPR\=\1 "${HOME}/options.cfg"); then +if (grep -sq DEBUG_UMTPR\=\1 "${OPTIONS_CFG}"); then DEBUG_UMTPR="yes" UMTPR_LOGS="${HOME}/log_umtpr.txt" fi @@ -38,7 +48,6 @@ export DEBUG_MSG DEBUG_UMTPR DEBUG_GMENU2X if test "x${DEBUG_MSG}" == "xyes"; then echo -e "\e[0m" # normal foreground color - export DEBUG_MSG # set it globally for further programs else echo -e "\e[30m" # black foreground color fi @@ -49,182 +58,210 @@ restore_temp_log_func(){ export LOGS_TEMP } -! test -r "${HOME}/options.cfg"\ - && echo "Did not find valid ${HOME}/options.cfg file, using default configuration." >> ${LOGS} - -# load kernel modules - -# Load the expected one screen driver from here with modprobe -## automatically from rootfs/lib/modules/VERSION -# The uEnv.txt is autogenerated by u-boot from HW which outputs -## environmental variables needed for ID of screen type -video=$(cat /sys/kernel/miyoo_video/miyoo_video) \ - || echo "Couldn't read video module from /sys/kernel/miyoo_video/miyoo_video" | tee -a "${LOGS}" - -test -r "${HOME}/.backlight.conf" \ - && BACKLIGHT=$(cat ${HOME}/.backlight.conf) - -# TVout scripting backend -TVOUT="OFF" -test -r "${HOME}/.tvmode" \ - || echo "0" > ${HOME}/.tvmode #default is OFF thus "0" (NTSC=1, PAL!=1) -tvmode=$(cat ${HOME}/.tvmode) -if test $tvmode -ne 0 || test -z "$tvmode" ; then - TVOUT="ON" - echo "Starting TVout video." >> "${LOGS}" - echo 0 > /sys/class/backlight/backlight/brightness - echo 0 > /sys/class/vtconsole/vtcon1/bind - if test $BACKLIGHT -ne 0; then - cp ${HOME}/.backlight.conf ${HOME}/.backlight.bak 2>&1 | tee -a "${LOGS}" +if ! $FRONTEND_ACTIVE; then + # restore date&time + test -r "${HOME}/.date.conf" \ + && date "+%Y-%m-%d %H:%M" -s "$(cat ${HOME}/.date.conf)" >> "${LOGS}" 2>&1 + + # load kernel modules + + # Load the expected one screen driver from here with modprobe + ## automatically from rootfs/lib/modules/VERSION + # The uEnv.txt is autogenerated by u-boot from HW which outputs + ## environmental variables needed for ID of screen type + video=$(cat /sys/kernel/miyoo_video/miyoo_video) \ + || echo "Couldn't read video module from /sys/kernel/miyoo_video/miyoo_video" | tee -a "${LOGS}" + + test -r "${HOME}/.backlight.conf" \ + && BACKLIGHT=$(cat ${HOME}/.backlight.conf) + + # TVout scripting backend + if ! test -r "${HOME}/.tvmode" || grep -sq TV_OUT\=\0 "${OPTIONS_CFG}"; then + echo "0" > ${HOME}/.tvmode #default is OFF thus "0" this is inline with frontend (NTSC!=1, PAL=1 - in kernel) fi - echo 0 > ${HOME}/.backlight.conf - echo "Loding TV module miyoo-tvout with args tvmode=${tvmode}" >> "${LOGS}" - modprobe miyoo-tvout $tvmode 2>&1 | tee -a "${LOGS}" - echo 1 > /sys/class/vtconsole/vtcon1/bind -else - if test -r "${HOME}/.backlight.bak"; then - mv ${HOME}/.backlight.bak ${HOME}/.backlight.conf + tvmode=$(cat ${HOME}/.tvmode) + if test $tvmode -eq 0 && grep -sq TV_OUT\=\1 "${OPTIONS_CFG}"; then + tvmode=1; + fi + if test $tvmode -ne 0 && ! test -z "$tvmode"; then + TVOUT="ON" + if grep -sq TV_OUT\=\0 "${OPTIONS_CFG}" || grep -sq TV_OUT\=\1 "${OPTIONS_CFG}"; then + unset TVOUT #since we have no real idea what video backend should be running when forcing TVout + fi + echo "Starting TVout video." >> "${LOGS}" + echo 0 > /sys/class/backlight/backlight/brightness 2>>"$LOGS" + echo 0 > /sys/class/vtconsole/vtcon1/bind 2>>"$LOGS" + if test $BACKLIGHT -ne 0; then + cp ${HOME}/.backlight.conf ${HOME}/.backlight.bak 2>&1 | tee -a "${LOGS}" + fi + echo 0 > ${HOME}/.backlight.conf + echo "Loading TV module miyoo-tvout with args tvmode=${tvmode}" >> "${LOGS}" + if (modprobe miyoo-tvout $tvmode >> "${LOGS}" 2>&1); then + echo "Loaded TV-out with tvmode=${tvmode}" | tee -a "${LOGS}" + fi + echo 1 > /sys/class/vtconsole/vtcon1/bind 2>>"$LOGS" + else + TVOUT="OFF" + if test -r "${HOME}/.backlight.bak"; then + mv ${HOME}/.backlight.bak ${HOME}/.backlight.conf + fi + # MODULES_CUSTOM scripting + if ( ! test -r "${BOOTDIR}/modules.custom.sh" || ! grep -sq MODULES_CUSTOM\=\1 "${OPTIONS_CFG}"); then + # Load video module read from uEnv.txt & defined by variant in console.cfg + #FLIP & INVERT options.cfg setting + flip=$(grep -o FLIP=[0-1] "${OPTIONS_CFG}" | tr '[:upper:]' '[:lower:]') + invert=$(grep -o INVERT=[0-1] "${OPTIONS_CFG}" | tr '[:upper:]' '[:lower:]') + echo "Loading video module ${video} with args flip=${flip} invert=${invert}" >> "${LOGS}" + if (modprobe $video $flip $invert >> "${LOGS}" 2>&1); then + echo "Loaded video with flip=${flip} invert=${invert}" | tee -a "${LOGS}" + fi + else + echo "Loading custom modules." | tee -a "${LOGS}" + (cd "${BOOTDIR}" && sh modules.custom.sh ) >> "${LOGS}" 2>&1 + fi fi - # MODULES_CUSTOM scripting - if ( ! test -r "${BOOTDIR}/modules.custom.sh" || ! grep -sq MODULES_CUSTOM\=\1 "${HOME}/options.cfg"); then - # Load video module read from uEnv.txt & defined by variant in console.cfg - #FLIP & INVERT options.cfg setting - flip=$(grep -o FLIP=[0-1] "${HOME}/options.cfg" | tr '[:upper:]' '[:lower:]') - invert=$(grep -o INVERT=[0-1] "${HOME}/options.cfg" | tr '[:upper:]' '[:lower:]') - echo "Loding video module ${video} with args flip=${flip} invert=${invert}" >> "${LOGS}" - modprobe $video $flip $invert 2>&1 | tee -a "${LOGS}" + export TVOUT + + # Load sound modules + if cmdline=$(cat /proc/cmdline 2>/dev/null | tee -a "${LOGS}"); then + snd_val=$(echo "$cmdline" | sed -n 's/.*miyoo\.miyoo_snd=\([0-9]\+\).*/\1/p') + test -z "$snd_val" && snd_val=1 # default to 1 from kernel, otherwise module fails to load + tvjack_val=$(echo "$cmdline" | sed -n 's/.*miyoo\.miyoo_tvjack=\([0-9]\+\).*/\1/p') + test -z "$tvjack_val" && tvjack_val=0 # default to 0 from kernel, otherwise module fails to load + echo "Loading sound module miyoo with args miyoo_snd=${snd_val} miyoo_tvjack=${tvjack_val} " | tee -a "${LOGS}" + modprobe miyoo miyoo_snd="$snd_val" miyoo_tvjack="$tvjack_val" 2>&1 | tee -a "${LOGS}" else - echo "Loding custom modules." >> "${LOGS}" - (cd "${BOOTDIR}" && sh modules.custom.sh ) >> "${LOGS}" 2>&1 + echo "Couldn't read /proc/cmdline, loading miyoo_snd with default args" | tee -a "${LOGS}" + modprobe miyoo 2>&1 | tee -a "${LOGS}" fi -fi -export TVOUT - -# Load sound modules -if cmdline=$(cat /proc/cmdline 2>/dev/null | tee -a "${LOGS}"); then - snd_val=$(echo "$cmdline" | sed -n 's/.*miyoo\.miyoo_snd=\([0-9]\+\).*/\1/p') - test -z "$snd_val" && snd_val=1 # default to 1 from kernel, otherwise module fails to load - tvjack_val=$(echo "$cmdline" | sed -n 's/.*miyoo\.miyoo_tvjack=\([0-9]\+\).*/\1/p') - test -z "$tvjack_val" && tvjack_val=0 # default to 0 from kernel, otherwise module fails to load - echo "Loding sound module miyoo with args miyoo_snd=${snd_val} miyoo_tvjack=${tvjack_val} " >> "${LOGS}" - modprobe miyoo miyoo_snd="$snd_val" miyoo_tvjack="$tvjack_val" 2>&1 | tee -a "${LOGS}" -else - echo "Couldn't read /proc/cmdline, loading miyoo_snd with default args" - modprobe miyoo 2>&1 | tee -a "${LOGS}" -fi -# check if it's first boot and defer to the firstboot script if yes -if grep -sq FIRSTBOOT\=\1 "${HOME}/options.cfg"; then - test -r "${BOOTDIR}/firstboot.done" \ - && sh "${BOOTDIR}/firstboot.done" -fi -if test -r "${BOOTDIR}/firstboot"; then - sh "${BOOTDIR}/firstboot" -elif test -r "${HOME}/firstboot.completed"; then - rm "${HOME}/firstboot.completed" -fi + # check if it's first boot and defer to the firstboot script if yes + if grep -sq FIRSTBOOT\=\1 "${OPTIONS_CFG}"; then + test -r "${BOOTDIR}/firstboot.done" \ + && sh "${BOOTDIR}/firstboot.done" + fi + if test -r "${BOOTDIR}/firstboot"; then + sh "${BOOTDIR}/firstboot" + elif test -r "${HOME}/firstboot.completed"; then + rm "${HOME}/firstboot.completed" + fi -if ! (grep -sq FS_CHECK\=\0 "${HOME}/options.cfg"); then -##Check if BOOT (FAT16) is flagged as "dirty", and if so unmount, repair, remount - if dmesg | grep "mmcblk0p1" > /dev/null; then - echo -e "\e[31mDirty sectors detected.\e[0m" | tee -a "${LOGS}" - echo -e "\e[32mChecking&Repairing FAT16 BOOT partition...\e[0m" | tee -a "${LOGS}" - umount /dev/mmcblk0p1 2>&1 | tee -a "${LOGS}" - fsck.vfat -y /dev/mmcblk0p1 >> "${LOGS}" 2>&1 - mount /dev/mmcblk0p1 "${BOOTDIR}" -t vfat -o ro,exec,utf8 2>&1 | tee -a "${LOGS}" - echo -e "\e[32mCheck complete.\e[0m" | tee -a "${LOGS}" + if ! (grep -sq FS_CHECK\=\0 "${OPTIONS_CFG}"); then + ##Check if BOOT (FAT16) is flagged as "dirty", and if so unmount, repair, remount + if dmesg | grep "mmcblk0p1" > /dev/null; then + echo -e "\e[31mDirty sectors detected.\e[0m" | tee -a "${LOGS}" + echo -e "\e[32mChecking&Repairing FAT16 BOOT partition...\e[0m" | tee -a "${LOGS}" + umount /dev/mmcblk0p1 2>&1 | tee -a "${LOGS}" + fsck.vfat -y /dev/mmcblk0p1 >> "${LOGS}" 2>&1 + mount /dev/mmcblk0p1 "${BOOTDIR}" -t vfat -o ro,exec,utf8 2>&1 | tee -a "${LOGS}" + echo -e "\e[32mCheck complete.\e[0m" | tee -a "${LOGS}" + fi + ##Check if MAIN (EXT4) is flagged as "dirty", and if so unmount, repair, remount + if dmesg | grep "EXT4-fs (mmcblk0p4): warning: mounting fs with errors, running e2fsck is recommended" > /dev/null; then + echo -e "\e[31mUnclean shutdown detected.\e[0m" | tee -a "${LOGS}" + echo -e "\e[32mChecking MAIN(EXT4) partition...\e[0m" | tee -a "${LOGS}" + umount /dev/mmcblk0p4 2>&1 | tee -a "${LOGS_TEMP}" + e2fsck -y /dev/mmcblk0p4 >> "${LOGS_TEMP}"; + mount /dev/mmcblk0p4 "${HOME}" -o rw,sync,exec 2>&1 | tee -a "${LOGS_TEMP}" + test "x${DEBUG_MSG}" == "xyes"\ + && restore_temp_log_func + fi + ##Check if ROMS (EXT4 or FAT32) is flagged as "dirty", and if so unmount, repair, remount + if dmesg | grep "EXT4-fs (mmcblk0p5): warning: mounting fs with errors, running e2fsck is recommended" > /dev/null; then + echo -e "\e[31mUnclean shutdown detected.\e[0m" | tee -a "${LOGS}" + echo -e "\e[32mChecking ROMS(EXT4) partition...\e[0m" | tee -a "${LOGS}" + umount /dev/mmcblk0p5 2>&1 | tee -a "${LOGS}" + e2fsck -y /dev/mmcblk0p5 >> "${LOGS}" 2>&1; + mount /dev/mmcblk0p5 "${ROMS}" -o rw,noatime 2>&1 | tee -a "${LOGS}" + elif dmesg | grep "FAT-fs (mmcblk0p5): Volume was not properly unmounted. Some data may be corrupt. Please run fsck." > /dev/null; then + echo -e "\e[31mDirty sectors detected.\e[0m" | tee -a "${LOGS}" + echo -e "\e[32mChecking&Repairing ROMS(FAT32) partition...\e[0m" | tee -a "${LOGS}" + umount /dev/mmcblk0p5 2>&1 | tee -a "${LOGS}" + fsck.vfat -y /dev/mmcblk0p5 >> "${LOGS}" 2>&1 + mount /dev/mmcblk0p5 "${ROMS}" -t vfat -o rw,utf8 2>&1 | tee -a "${LOGS}" + echo -e "\e[32mCheck complete.\e[0m" | tee -a "${LOGS}" + fi fi -##Check if MAIN (EXT4) is flagged as "dirty", and if so unmount, repair, remount - if dmesg | grep "EXT4-fs (mmcblk0p4): warning: mounting fs with errors, running e2fsck is recommended" > /dev/null; then - echo -e "\e[31mUnclean shutdown detected.\e[0m" | tee -a "${LOGS}" - echo -e "\e[32mChecking MAIN(EXT4) partition...\e[0m" | tee -a "${LOGS}" - umount /dev/mmcblk0p4 2>&1 | tee -a "${LOGS_TEMP}" - e2fsck -y /dev/mmcblk0p4 >> "${LOGS_TEMP}"; - mount /dev/mmcblk0p4 "${HOME}" -o rw,sync,exec 2>&1 | tee -a "${LOGS_TEMP}" + + # we could unmount /boot here but since it's read-only it doesn't hurt to leave it running + ## umount /dev/mmcblk0p1 + + # Writes dmesg after firstboot procedure or if DEBUG_MSG=yes + restor temp logs from fsck + if test "x${DEBUG_MSG}" == "xyes"; then + sleep 1 + echo -en "\n\nNew DMESG log:\n" >> ${HOME}/dmesg.txt + dmesg >> ${HOME}/dmesg.txt restore_temp_log_func fi -##Check if ROMS (EXT4 or FAT32) is flagged as "dirty", and if so unmount, repair, remount - if dmesg | grep "EXT4-fs (mmcblk0p5): warning: mounting fs with errors, running e2fsck is recommended" > /dev/null; then - echo -e "\e[31mUnclean shutdown detected.\e[0m" | tee -a "${LOGS}" - echo -e "\e[32mChecking ROMS(EXT4) partition...\e[0m" | tee -a "${LOGS}" - umount /dev/mmcblk0p5 2>&1 | tee -a "${LOGS}" - e2fsck -y /dev/mmcblk0p5 >> "${LOGS}" 2>&1; - mount /dev/mmcblk0p5 "${ROMS}" -o rw,noatime 2>&1 | tee -a "${LOGS}" - elif dmesg | grep "FAT-fs (mmcblk0p5): Volume was not properly unmounted. Some data may be corrupt. Please run fsck." > /dev/null; then - echo -e "\e[31mDirty sectors detected.\e[0m" | tee -a "${LOGS}" - echo -e "\e[32mChecking&Repairing ROMS(FAT32) partition...\e[0m" | tee -a "${LOGS}" - umount /dev/mmcblk0p5 2>&1 | tee -a "${LOGS}" - fsck.vfat -y /dev/mmcblk0p5 >> "${LOGS}" 2>&1 - mount /dev/mmcblk0p5 "${ROMS}" -t vfat -o rw,utf8 2>&1 | tee -a "${LOGS}" - echo -e "\e[32mCheck complete.\e[0m" | tee -a "${LOGS}" + + # run any custom commands ('daemon' expected to be run from there) + if test -r "${BOOTDIR}/normalboot.custom.sh" ; then + (cd "${BOOTDIR}" && sh normalboot.custom.sh) # don't redirect, want output on screen + else + # at least run 'daemon' + daemon >> "${LOGS}" 2>&1 fi + echo "Boot!" | tee -a "${LOGS}" +fi + +# try to read if TVOUT is active +if test -z "${TVOUT}"; then + if test -f /tmp/tvout.enabled; then + export TVOUT="ON" + elif test -f /tmp/tvout.disabled; then + export TVOUT="OFF" + else + echo "TVOUT module disabled, or with no hot-plugin detection" | tee -a "${LOGS}" + fi +elif test "${TVOUT}" == "ON"; then + touch /tmp/tvout.enabled 2>&1 | tee -a "${LOGS}" + #echo "TVOUT module enabled" | tee -a "${LOGS}" +elif test "${TVOUT}" == "OFF"; then + touch /tmp/tvout.disabled 2>&1 | tee -a "${LOGS}" + #echo "TVOUT module disabled" | tee -a "${LOGS}" fi -clear # try to read what handheld we're on if test -r "${BOOTDIR}/console.cfg"; then source "${BOOTDIR}/console.cfg" else - export CONSOLE_VARIANT="unknown" + CONSOLE_VARIANT="unknown" fi +export CONSOLE_VARIANT +echo "Handheld type is ${CONSOLE_VARIANT}" | tee -a "${LOGS}" # load usb modules & gadget -if ! (grep -sq USB_OTG\=\0 "${HOME}/options.cfg"); then +if ! (grep -sq USB_OTG\=\0 "${OPTIONS_CFG}"); then if test -r "${HOME}/.usbmode"; then source ${HOME}/.usbmode else USB_MODE="mtp" # default setup fi - echo "Loading USB ${USB_MODE} default gadget" >> "${LOGS}" + echo "Loading USB ${USB_MODE} default gadget" | tee -a "${LOGS}" usb-mode ${USB_MODE} 2>&1 | tee -a "${LOGS}" export USB_MODE fi -echo "Boot!" >> "${LOGS}" -echo "Handheld type is ${CONSOLE_VARIANT}" >> "${LOGS}" - -# run any custom commands ('daemon' expected to be run from there) -if test -r "${BOOTDIR}/normalboot.custom.sh" ; then - (cd "${BOOTDIR}" && sh normalboot.custom.sh) # don't redirect, want output on screen -else - # at least run 'daemon' - daemon >> "${LOGS}" 2>&1 -fi - # run boot logo animation -if ! (grep -sq BOOT_LOGO\=\0 "${HOME}/options.cfg"); then - ${BOOTLOGO} >> "${LOGS}" 2>&1 +if ! (grep -sq BOOT_LOGO\=\0 "${OPTIONS_CFG}" || $FRONTEND_ACTIVE); then + ${BOOTLOGO} 2>&1 | tee -a "${LOGS}" fi -# we could unmount /boot here but since it's read-only it doesn't hurt to leave it running -## umount /dev/mmcblk0p1 - -# Writes dmesg after firstboot procedure or if DEBUG_MSG=yes -if test "x${DEBUG_MSG}" == "xyes"; then - sleep 1 - echo -en "\n\nNew DMESG log:\n" >> ${HOME}/dmesg.txt - dmesg >> ${HOME}/dmesg.txt - restore_temp_log_func -fi - -while [ 1 ] -do - if test -f "${START}"; then - source "${START}" +clear +if test -f "${START}"; then + echo "Starting ${START} script." >> "${LOGS}" + source "${START}" >> "${LOGS}" 2>&1 +else + echo "Starting GMenu2x" >> "${LOGS}" + cd "${HOME}"/gmenu2x || { echo -en "Failed to cd into ${HOME}/gmenu2x, no frontend to launch.\n\nPOWEROFF..." >> "${LOGS}" ; sync; poweroff; } + if test "x${DEBUG_GMENU2X}" == "xyes"; then + gdb -ex="set confirm off" -ex=run -ex="bt full" -ex=q ./gmenu2x-debug 2>&1 | tee -a "${GMENU2X_LOGS}" else - echo "Starting GMenu2x" >> "${LOGS}" - cd "${HOME}"/gmenu2x || { echo "Failed to cd into ${HOME}/gmenu2x" >> "${LOGS}" ; exit; } - if test "x${DEBUG_GMENU2X}" == "xyes"; then - gdb -ex="set confirm off" -ex=run -ex="bt full" -ex=q ./gmenu2x-debug >> "${GMENU2X_LOGS}" 2>&1 - else - ./gmenu2x >> "${GMENU2X_LOGS}" 2>&1 - fi - if (test -r "${HOME}/.usbmode" && ! (grep -sq USB_OTG\=\0 "${HOME}/options.cfg")); then - source ${HOME}/.usbmode - export USB_MODE - fi - test "x${DEBUG_MSG}" == "xyes"\ - && restore_temp_log_func + ./gmenu2x >> "${GMENU2X_LOGS}" 2>&1 fi - clear -done +fi + +touch /tmp/frontend.active 2>&1 | tee -a "${LOGS}" +echo -en "\n\nOops what are u doing here?\nEnding /etc/main run..." | tee -a "${LOGS}" +sleep 2 +clear