diff --git a/packages/sysutils/busybox/package.mk b/packages/sysutils/busybox/package.mk index 8a1e79f42e..7968b13155 100644 --- a/packages/sysutils/busybox/package.mk +++ b/packages/sysutils/busybox/package.mk @@ -138,6 +138,10 @@ makeinstall_target() { sed -e "s/@DISTRONAME@/$DISTRONAME/g" \ -i $INSTALL/usr/lib/libreelec/fs-resize + if listcontains "${FIRMWARE}" "rpi-eeprom"; then + cp $PKG_DIR/scripts/rpi-flash-firmware $INSTALL/usr/lib/libreelec + fi + mkdir -p $INSTALL/etc cp $PKG_DIR/config/profile $INSTALL/etc cp $PKG_DIR/config/inputrc $INSTALL/etc @@ -183,6 +187,7 @@ post_install() { enable_service var.mount enable_service var-log-debug.service enable_service fs-resize.service + listcontains "${FIRMWARE}" "rpi-eeprom" && enable_service rpi-flash-firmware.service # cron support if [ "$CRON_SUPPORT" = "yes" ] ; then diff --git a/packages/sysutils/busybox/scripts/init b/packages/sysutils/busybox/scripts/init index 81e2e6735a..777a8379ba 100755 --- a/packages/sysutils/busybox/scripts/init +++ b/packages/sysutils/busybox/scripts/init @@ -1123,17 +1123,16 @@ if [ "$STORAGE_NETBOOT" = "yes" ]; then echo "" > /sysroot/dev/.storage_netboot fi +BACKUP_FILE=$(ls -1 /sysroot/storage/.restore/??????????????.tar 2>/dev/null | head -n 1) + if [ -f /sysroot/storage/.please_resize_me ]; then INIT_UNIT="--unit=fs-resize.target" -fi - -BACKUP_FILE=$(ls -1 /sysroot/storage/.restore/??????????????.tar 2>/dev/null | head -n 1) -if [ -f "$BACKUP_FILE" ]; then - INIT_UNIT="--unit=backup-restore.target" -fi - -if [ -f /sysroot/storage/.cache/reset_oe -o -f /sysroot/storage/.cache/reset_xbmc ]; then +elif [ -f /sysroot/storage/.cache/reset_oe -o -f /sysroot/storage/.cache/reset_xbmc ]; then INIT_UNIT="--unit=factory-reset.target" +elif [ -f "$BACKUP_FILE" ]; then + INIT_UNIT="--unit=backup-restore.target" +elif [ -f /sysroot/storage/.rpi_flash_firmware ]; then + INIT_UNIT="--unit=rpi-flash-firmware.target" fi # switch to new sysroot and start real init diff --git a/packages/sysutils/busybox/scripts/rpi-flash-firmware b/packages/sysutils/busybox/scripts/rpi-flash-firmware new file mode 100755 index 0000000000..cb98427ba8 --- /dev/null +++ b/packages/sysutils/busybox/scripts/rpi-flash-firmware @@ -0,0 +1,66 @@ +#!/bin/sh + +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2019-present Team LibreELEC (https://libreelec.tv) + +FLAG_FILE="/storage/.rpi_flash_firmware" + +. /usr/lib/libreelec/functions + +hidecursor + +if ! mount -o remount,rw /flash 2>/dev/null; then + # Remove flag file and bail out + rm -f "${FLAG_FILE}" + sync + + echo "ERROR: Unable to mount /flash as a read/write file system." + echo + echo "Aborting Flash update process - please proceed with a manual update." + echo + + StartProgress countdown "Rebooting in 15s... " 15 "NOW" +fi + +if [ -f "${FLAG_FILE}" ]; then + . ${FLAG_FILE} + + # Prepare flashing environment + if [ "${MODE}" = "init" ]; then + # Install new SPI bootloader files to /flash (if required) + if [ "${BOOTLOADER}" = "yes" ]; then + USE_FLASHROM=0 /usr/bin/rpi-eeprom-update -a + fi + + # Bump process to next step + sed -e 's/^MODE=.*/MODE="update"/' -i "${FLAG_FILE}" + sync + else + rm -f "${FLAG_FILE}" + sync + + if [ "${MODE}" = "update" ]; then + # Cleanup SPI bootloader files and show current version + if [ "${BOOTLOADER}" = "yes" ]; then + rm -f /flash/pieeprom.bin /flash/pieeprom.upd + rm -f /flash/recovery.bin /flash/recovery.[0-9][0-9][0-9] /flash/RECOVERY.[0-9][0-9][0-9] + # Display current bootloader status + USE_FLASHROM=0 /usr/bin/rpi-eeprom-update + fi + + # Apply VIA USB3 update +# if [ "${USB3}" = "yes" ]; then +# /usr/bin/vl805 +# fi + + sync + echo "" + StartProgress countdown "Rebooting in 15s... " 15 "NOW" + fi + fi + + sync + mount -o remount,ro /flash +fi + +reboot -f &>/dev/null diff --git a/packages/sysutils/busybox/system.d/rpi-flash-firmware.service b/packages/sysutils/busybox/system.d/rpi-flash-firmware.service new file mode 100644 index 0000000000..c05ea654d4 --- /dev/null +++ b/packages/sysutils/busybox/system.d/rpi-flash-firmware.service @@ -0,0 +1,12 @@ +[Unit] +Description=RPi Flash Firmware +Requires=tmp.mount var.mount sys-kernel-config.mount kernel-overlays.service +After=tmp.mount var.mount sys-kernel-config.mount kernel-overlays.service +DefaultDependencies=no + +[Service] +Type=idle +ExecStart=/usr/lib/libreelec/rpi-flash-firmware +StandardInput=tty-force +StandardOutput=inherit +StandardError=inherit diff --git a/packages/sysutils/busybox/system.d/rpi-flash-firmware.target b/packages/sysutils/busybox/system.d/rpi-flash-firmware.target new file mode 100644 index 0000000000..98480bca45 --- /dev/null +++ b/packages/sysutils/busybox/system.d/rpi-flash-firmware.target @@ -0,0 +1,5 @@ +[Unit] +Description=RPi Flash Firmware target +Requires=rpi-flash-firmware.service +After=rpi-flash-firmware.service +AllowIsolate=yes