From c187b8d32cffe970ecea827d625932ffb7068f72 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Sat, 20 Dec 2025 05:31:16 -0500 Subject: [PATCH] Initial support for updating eeprom. --- .includes/eeprom.sh | 77 ++++++++++++++++++++++++++++++++++++++++++++ configure-stormux.sh | 4 +++ 2 files changed, 81 insertions(+) create mode 100644 .includes/eeprom.sh diff --git a/.includes/eeprom.sh b/.includes/eeprom.sh new file mode 100644 index 0000000..0d0e07f --- /dev/null +++ b/.includes/eeprom.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +# EEPROM Update for Raspberry Pi 4/400/5/500 +# Checks for and applies firmware updates to the Pi's EEPROM + +# sudoFlags is defined in the main configure-stormux.sh script +# shellcheck disable=SC2154 + +updateEeprom() { + # Detect Pi version from device tree + local piModel + piModel=$(cat /sys/firmware/devicetree/base/model 2>/dev/null) + + # Determine which EEPROM package is needed + local eepromPackage="" + if [[ "$piModel" == *"Raspberry Pi 5"* ]] || [[ "$piModel" == *"Raspberry Pi 500"* ]]; then + eepromPackage="rpi5-eeprom" + elif [[ "$piModel" == *"Raspberry Pi 4"* ]] || [[ "$piModel" == *"Raspberry Pi 400"* ]]; then + eepromPackage="rpi4-eeprom" + else + # Default to rpi4-eeprom for unknown models + eepromPackage="rpi4-eeprom" + fi + + # Install EEPROM package if not present + if ! pacman -Q "$eepromPackage" &> /dev/null; then + infobox "Installing ${eepromPackage}..." + if ! install_package "$eepromPackage"; then + msgbox "Failed to install ${eepromPackage}. Please check your internet connection and try again." + return 1 + fi + fi + + # Check for EEPROM updates + infobox "Checking for EEPROM updates..." + local checkOutput + local checkResult + checkOutput=$(sudo "${sudoFlags[@]}" rpi-eeprom-update 2>&1) + checkResult=$? + + case $checkResult in + 0) + # Up to date + msgbox "EEPROM is up to date.\n\n${checkOutput}" + ;; + 1) + # Update available + if [[ "$(yesno "An EEPROM update is available.\n\n${checkOutput}\n\nWould you like to apply this update?")" == "Yes" ]]; then + infobox "Applying EEPROM update..." + if sudo "${sudoFlags[@]}" rpi-eeprom-update -a; then + msgbox "EEPROM update applied successfully. A reboot is required to complete the update." + restart + else + msgbox "Failed to apply EEPROM update. Please try again or check the log file for details." + return 1 + fi + fi + ;; + 2) + # Failed + msgbox "EEPROM update check failed.\n\n${checkOutput}" + return 1 + ;; + 3) + # EEPROM frozen + msgbox "EEPROM is currently frozen and cannot be updated.\n\n${checkOutput}\n\nThis may require a reboot to resolve." + return 1 + ;; + *) + # Unknown error + msgbox "Unexpected error checking EEPROM status (exit code: ${checkResult}).\n\n${checkOutput}" + return 1 + ;; + esac +} + +# Execute the update function when sourced +updateEeprom diff --git a/configure-stormux.sh b/configure-stormux.sh index 4e39313..1c778e9 100755 --- a/configure-stormux.sh +++ b/configure-stormux.sh @@ -124,6 +124,9 @@ while [[ "$choice" != "Exit" ]]; do "Configure StormUX Repository") add_stormux_repo ;; + "Update EEPROM") + source .includes/eeprom.sh + ;; esac options=( "Change username" @@ -147,6 +150,7 @@ while [[ "$choice" != "Exit" ]]; do options+=("Set timezone" "Get help on IRC" "Update configure-stormux" + "Update EEPROM" "Convert to Server" "Configure StormUX Repository" )