From 7e57ce181b37692be59ddfb626e0b949247bd2c3 Mon Sep 17 00:00:00 2001 From: Jonathon Hall Date: Mon, 8 Jan 2024 16:32:20 -0500 Subject: [PATCH 1/3] initrd/bin/flash-gui.sh: Fix indentation Signed-off-by: Jonathon Hall --- initrd/bin/flash-gui.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/initrd/bin/flash-gui.sh b/initrd/bin/flash-gui.sh index 4f1bb537..d492268a 100755 --- a/initrd/bin/flash-gui.sh +++ b/initrd/bin/flash-gui.sh @@ -113,12 +113,12 @@ while true; do # talos-2 uses a .tgz file for its "plain" update, contains other parts as well, validated against hashes under flash.sh # Skip prompt for hash validation for talos-2. Only method is through tgz or through bmc with individual parts if [ "${CONFIG_BOARD%_*}" != talos-2 ]; then - # a rom file was provided. exit if we shall not proceed - ROM="$PKG_FILE" - ROM_HASH=$(sha256sum "$ROM" | awk '{print $1}') || die "Failed to hash ROM file" - if ! (whiptail $CONFIG_ERROR_BG_COLOR --title 'Flash ROM without integrity check?' \ - --yesno "You have provided a *.$UPDATE_PLAIN_EXT file. The integrity of the file can not be\nchecked automatically for this file type.\n\nROM: $ROM\nSHA256SUM: $ROM_HASH\n\nIf you do not know how to check the file integrity yourself,\nyou should use a *.zip file instead.\n\nIf the file is damaged, you will not be able to boot anymore.\nDo you want to proceed flashing without file integrity check?" 0 80); then - exit 1 + # a rom file was provided. exit if we shall not proceed + ROM="$PKG_FILE" + ROM_HASH=$(sha256sum "$ROM" | awk '{print $1}') || die "Failed to hash ROM file" + if ! (whiptail $CONFIG_ERROR_BG_COLOR --title 'Flash ROM without integrity check?' \ + --yesno "You have provided a *.$UPDATE_PLAIN_EXT file. The integrity of the file can not be\nchecked automatically for this file type.\n\nROM: $ROM\nSHA256SUM: $ROM_HASH\n\nIf you do not know how to check the file integrity yourself,\nyou should use a *.zip file instead.\n\nIf the file is damaged, you will not be able to boot anymore.\nDo you want to proceed flashing without file integrity check?" 0 80); then + exit 1 fi else #We are on talos-2, so we have a tgz file. We will pass it directly to flash.sh which will take care of it From 40e96c7daec69082ef0110cb04db74d32f65fc2a Mon Sep 17 00:00:00 2001 From: Jonathon Hall Date: Mon, 8 Jan 2024 16:50:40 -0500 Subject: [PATCH 2/3] initrd/bin/flash-gui.sh: Show message if plain ROM is unreadable If the user selects a plain ROM, but that file can't be read, show a message and exit rather than dying. Copy the ROM to RAM before doing anything with it in case the media fails later. Signed-off-by: Jonathon Hall --- initrd/bin/flash-gui.sh | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/initrd/bin/flash-gui.sh b/initrd/bin/flash-gui.sh index d492268a..f07620e1 100755 --- a/initrd/bin/flash-gui.sh +++ b/initrd/bin/flash-gui.sh @@ -72,12 +72,16 @@ while true; do PKG_FILE=$FILE fi + # Display the package file without the "/media/" prefix + PKG_FILE_DISPLAY="${PKG_FILE#"/media/"}" + + # Unzip the package + PKG_EXTRACT="/tmp/flash_gui/update_package" + rm -rf "$PKG_EXTRACT" + mkdir -p "$PKG_EXTRACT" + # is an update package provided? if [ -z "${PKG_FILE##*.zip}" ]; then - # Unzip the package - PKG_EXTRACT="/tmp/flash_gui/update_package" - rm -rf "$PKG_EXTRACT" - mkdir -p "$PKG_EXTRACT" # If extraction fails, delete everything and fall through to the # integrity failure prompt. This is the most likely path if the ROM # was actually corrupted in transit. Corrupting the ZIP in a way that @@ -91,19 +95,19 @@ while true; do # check file integrity if ! (cd "$PKG_EXTRACT" && sha256sum -cs sha256sum.txt); then whiptail --title 'ROM Integrity Check Failed! ' \ - --msgbox "Integrity check failed in\n$PKG_FILE.\nDid not flash.\n\nPlease check your file (e.g. re-download).\n" 16 60 + --msgbox "Integrity check failed in\n$PKG_FILE_DISPLAY.\nDid not flash.\n\nPlease check your file (e.g. re-download).\n" 16 60 exit 1 fi # The package must contain exactly one *.rom file, flash that. if ! PACKAGE_ROM="$(single_glob "$PKG_EXTRACT/"*."$UPDATE_PLAIN_EXT")"; then whiptail --title 'BIOS Image Not Found! ' \ - --msgbox "A BIOS image was not found in\n$PKG_FILE.\n\nPlease check your file (e.g. re-download).\n" 16 60 + --msgbox "A BIOS image was not found in\n$PKG_FILE_DISPLAY.\n\nPlease check your file (e.g. re-download).\n" 16 60 exit 1 fi if ! whiptail $BG_COLOR_WARNING --title 'Flash ROM?' \ - --yesno "This will replace your current ROM with:\n\n${PKG_FILE#"/media/"}\n\nDo you want to proceed?" 0 80; then + --yesno "This will replace your current ROM with:\n\n$PKG_FILE_DISPLAY\n\nDo you want to proceed?" 0 80; then exit 1 fi @@ -113,11 +117,18 @@ while true; do # talos-2 uses a .tgz file for its "plain" update, contains other parts as well, validated against hashes under flash.sh # Skip prompt for hash validation for talos-2. Only method is through tgz or through bmc with individual parts if [ "${CONFIG_BOARD%_*}" != talos-2 ]; then - # a rom file was provided. exit if we shall not proceed - ROM="$PKG_FILE" - ROM_HASH=$(sha256sum "$ROM" | awk '{print $1}') || die "Failed to hash ROM file" + # Though a plain ROM isn't a package, copy it to /tmp before doing + # anything, so we can be sure the media won't disappear or fail + # while flashing. + if ! cp "$PKG_FILE" "$PKG_EXTRACT/"; then + whiptail --title 'Failed to read ROM' \ + --msgbox "Failed to read ROM:\n$PKG_FILE_DISPLAY\n\nPlease check your file (e.g. re-download).\n" 16 60 + exit 1 + fi + ROM="$PKG_EXTRACT/$(basename "$PKG_FILE")" + ROM_HASH=$(sha256sum "$ROM" | awk '{print $1}') if ! (whiptail $CONFIG_ERROR_BG_COLOR --title 'Flash ROM without integrity check?' \ - --yesno "You have provided a *.$UPDATE_PLAIN_EXT file. The integrity of the file can not be\nchecked automatically for this file type.\n\nROM: $ROM\nSHA256SUM: $ROM_HASH\n\nIf you do not know how to check the file integrity yourself,\nyou should use a *.zip file instead.\n\nIf the file is damaged, you will not be able to boot anymore.\nDo you want to proceed flashing without file integrity check?" 0 80); then + --yesno "You have provided a *.$UPDATE_PLAIN_EXT file. The integrity of the file can not be\nchecked automatically for this file type.\n\nROM: $PKG_FILE_DISPLAY\nSHA256SUM: $ROM_HASH\n\nIf you do not know how to check the file integrity yourself,\nyou should use a *.zip file instead.\n\nIf the file is damaged, you will not be able to boot anymore.\nDo you want to proceed flashing without file integrity check?" 0 80); then exit 1 fi else @@ -140,7 +151,7 @@ while true; do /bin/flash.sh "$ROM" fi whiptail --title 'ROM Flashed Successfully' \ - --msgbox "${PKG_FILE#"/media/"}\n\nhas been flashed successfully.\n\nPress Enter to reboot\n" 0 80 + --msgbox "$PKG_FILE_DISPLAY\n\nhas been flashed successfully.\n\nPress Enter to reboot\n" 0 80 umount /media /bin/reboot fi From 905d40bd9b4a9cbbd7ad7b009f770ce54ebcfddd Mon Sep 17 00:00:00 2001 From: Jonathon Hall Date: Tue, 9 Jan 2024 13:11:01 -0500 Subject: [PATCH 3/3] initrd/bin/flash-gui.sh: Show error if find fails due to I/O error 'find' may fail if I/O errors occur (medium faulty or removed, filesystem corruption, etc.) Show a message if this occurs rather than just dying and returning to the main menu. Signed-off-by: Jonathon Hall --- initrd/bin/flash-gui.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/initrd/bin/flash-gui.sh b/initrd/bin/flash-gui.sh index f07620e1..56d52719 100755 --- a/initrd/bin/flash-gui.sh +++ b/initrd/bin/flash-gui.sh @@ -60,10 +60,19 @@ while true; do --yesno "You will need to insert a USB drive containing your BIOS image (*.zip or\n*.$UPDATE_PLAIN_EXT).\n\nAfter you select this file, this program will reflash your BIOS.\n\nDo you want to proceed?" 0 80); then mount_usb if grep -q /media /proc/mounts; then + # 'find' parameters to match desired ROM extensions + FIND_ROM_EXTS=(\( -name "*.$UPDATE_PLAIN_EXT" -o -type f -name "*.zip" \)) if [ "${CONFIG_BOARD%_*}" = talos-2 ]; then - find /media ! -path '*/\.*' -type f -name "*.$UPDATE_PLAIN_EXT" | sort >/tmp/filelist.txt - else - find /media ! -path '*/\.*' -type f \( -name "*.$UPDATE_PLAIN_EXT" -o -type f -name "*.zip" \) | sort >/tmp/filelist.txt + # Show only *.tgz on talos-2 (lacks ZIP update package support) + FIND_ROM_EXTS=(-name "*.$UPDATE_PLAIN_EXT") + fi + # Media errors can cause this to fail (flash drive pulled, filesystem + # corruption, etc.) + if ! find /media ! -path '*/\.*' -type f "${FIND_ROM_EXTS[@]}" | sort >/tmp/filelist.txt; then + whiptail --title 'Unable to read USB drive' \ + --msgbox "The USB drive is not readable. Check the drive, reformat, or try a + \ndifferent drive." 16 60 + exit 1 fi file_selector "/tmp/filelist.txt" "Choose the ROM to flash" if [ "$FILE" == "" ]; then