diff --git a/firmware-util.sh b/firmware-util.sh index 0069ed5..d2f18c6 100644 --- a/firmware-util.sh +++ b/firmware-util.sh @@ -13,6 +13,9 @@ #where the stuff is script_url="https://raw.githubusercontent.com/MrChromebox/scripts/master/" +# usage: sudo DEV_MODE=true bash firmware-util.sh +# it will use local version of scripts +dev_mode=${DEV_MODE:-false} #ensure output of system tools in en-us for parsing export LC_ALL=C @@ -23,7 +26,7 @@ if grep -q "Chrom" /etc/lsb-release ; then mkdir -p /usr/local/bin cd /usr/local/bin else - cd /tmp + [[ "$dev_mode" == false ]] && cd /tmp fi #check for cmd line param, expired CrOS certs @@ -33,20 +36,22 @@ else export CURL="curl" fi -#get support scripts -echo -e "\nDownloading supporting files..." -rm -rf firmware.sh >/dev/null 2>&1 -rm -rf functions.sh >/dev/null 2>&1 -rm -rf sources.sh >/dev/null 2>&1 -$CURL -sLO ${script_url}firmware.sh -rc0=$? -$CURL -sLO ${script_url}functions.sh -rc1=$? -$CURL -sLO ${script_url}sources.sh -rc2=$? -if [[ $rc0 -ne 0 || $rc1 -ne 0 || $rc2 -ne 0 ]]; then - echo -e "Error downloading one or more required files; cannot continue" - exit 1 +if [[ "$dev_mode" == false ]]; then + #get support scripts + echo -e "\nDownloading supporting files..." + rm -rf firmware.sh >/dev/null 2>&1 + rm -rf functions.sh >/dev/null 2>&1 + rm -rf sources.sh >/dev/null 2>&1 + $CURL -sLO ${script_url}firmware.sh + rc0=$? + $CURL -sLO ${script_url}functions.sh + rc1=$? + $CURL -sLO ${script_url}sources.sh + rc2=$? + if [[ $rc0 -ne 0 || $rc1 -ne 0 || $rc2 -ne 0 ]]; then + echo -e "Error downloading one or more required files; cannot continue" + exit 1 + fi fi source ./sources.sh diff --git a/firmware.sh b/firmware.sh index 73f5f54..179f425 100644 --- a/firmware.sh +++ b/firmware.sh @@ -170,7 +170,12 @@ else fwTypeStr="UEFI" fi -echo_green "\nInstall/Update ${fwTypeStr} Full ROM Firmware" + +if [[ "$hasLocalPath" = true ]]; then + echo_green "\nInstall/Update Custom ${fwTypeStr} Full ROM Firmware from local path" +else + echo_green "\nInstall/Update ${fwTypeStr} Full ROM Firmware" +fi echo_yellow "IMPORTANT: flashing the firmware has the potential to brick your device, requiring relatively inexpensive hardware and some technical knowledge to recover.Not all boards can be tested prior to release, and even then slight @@ -187,6 +192,12 @@ read -ep "Do you wish to continue? [y/N] " #spacing echo -e "" +if [[ "$hasLocalPath" = true ]]; then + read -ep "Please provide local path for Full ROM Firmware: " + [[ -f "$REPLY" ]] || { exit_red "->$REPLY<- file does note exist"; return 1; } + coreboot_file=$REPLY +fi + # ensure hardware write protect disabled [[ "$wpEnabled" = true ]] && { exit_red "\nHardware write-protect enabled, cannot flash Full ROM firmware."; return 1; } @@ -253,16 +264,18 @@ OS; ${currOS} will no longer be bootable. See https://mrchromebox.tech/#faq" [[ "$REPLY" = "y" || "$REPLY" = "Y" ]] || return fi -#determine correct file / URL -firmware_source=${fullrom_source} -if [[ "$hasUEFIoption" = true || "$hasLegacyOption" = true ]]; then - if [ "$useUEFI" = true ]; then - eval coreboot_file=$`echo "coreboot_uefi_${device}"` - else - eval coreboot_file=$`echo "coreboot_${device}"` - fi -else - exit_red "Unknown or unsupported device (${device^^}); cannot continue."; return 1 +if [[ "hasLocalPath" == false ]];then + #determine correct file / URL + firmware_source=${fullrom_source} + if [[ "$hasUEFIoption" = true || "$hasLegacyOption" = true ]]; then + if [ "$useUEFI" = true ]; then + eval coreboot_file=$`echo "coreboot_uefi_${device}"` + else + eval coreboot_file=$`echo "coreboot_${device}"` + fi + else + exit_red "Unknown or unsupported device (${device^^}); cannot continue."; return 1 + fi fi #auron special case (upgrade from coolstar legacy rom) @@ -381,13 +394,17 @@ fi #download firmware file cd /tmp -echo_yellow "\nDownloading Full ROM firmware\n(${coreboot_file})" -$CURL -sLO "${firmware_source}${coreboot_file}" -$CURL -sLO "${firmware_source}${coreboot_file}.sha1" -#verify checksum on downloaded file -sha1sum -c ${coreboot_file}.sha1 --quiet > /dev/null 2>&1 -[[ $? -ne 0 ]] && { exit_red "Firmware download checksum fail; download corrupted, cannot flash."; return 1; } +if [[ "$hasLocalPath" = false ]]; then + echo_yellow "\nDownloading Full ROM firmware\n(${coreboot_file})" + + $CURL -sLO "${firmware_source}${coreboot_file}" + $CURL -sLO "${firmware_source}${coreboot_file}.sha1" + + #verify checksum on downloaded file + sha1sum -c ${coreboot_file}.sha1 --quiet > /dev/null 2>&1 + [[ $? -ne 0 ]] && { exit_red "Firmware download checksum fail; download corrupted, cannot flash."; return 1; } +fi #preferUSB? if [[ "$preferUSB" = true && $useUEFI = false ]]; then @@ -1426,10 +1443,15 @@ function uefi_menu() { else echo -e "${GRAY_TEXT}** ${GRAY_TEXT} 1)${GRAY_TEXT} Install/Update UEFI (Full ROM) Firmware${NORMAL}" fi + if [[ "$hasUEFIoption" = true ]]; then + echo -e "${MENU}**${WP_TEXT} [WP]${NUMBER} 2)${MENU} Install/Update Custom UEFI (Full ROM) Firmware from local path ${NORMAL}" + else + echo -e "${GRAY_TEXT}** ${GRAY_TEXT} 2)${GRAY_TEXT} Install/Update Custom UEFI (Full ROM) Firmware from local path${NORMAL}" + fi if [[ "$isChromeOS" = false && "$isFullRom" = true ]]; then - echo -e "${MENU}**${WP_TEXT} [WP]${NUMBER} 2)${MENU} Restore Stock Firmware ${NORMAL}" + echo -e "${MENU}**${WP_TEXT} [WP]${NUMBER} 3)${MENU} Restore Stock Firmware ${NORMAL}" else - echo -e "${GRAY_TEXT}** ${GRAY_TEXT} 2)${GRAY_TEXT} Restore Stock ChromeOS Firmware ${NORMAL}" + echo -e "${GRAY_TEXT}** ${GRAY_TEXT} 3)${GRAY_TEXT} Restore Stock ChromeOS Firmware ${NORMAL}" fi if [[ "${device^^}" = "EVE" ]]; then echo -e "${MENU}**${WP_TEXT} [WP]${NUMBER} D)${MENU} Downgrade Touchpad Firmware ${NORMAL}" @@ -1450,7 +1472,14 @@ function uefi_menu() { uefi_menu ;; - 2) if [[ "$isChromeOS" = false && "$isUnsupported" = false \ + 2) if [[ "$hasUEFIoption" = true ]]; then + hasLocalPath=true + flash_coreboot + fi + uefi_menu + ;; + + 3) if [[ "$isChromeOS" = false && "$isUnsupported" = false \ && "$isFullRom" = true ]]; then restore_stock_firmware menu_fwupdate diff --git a/functions.sh b/functions.sh index bd1532a..b3ecb16 100644 --- a/functions.sh +++ b/functions.sh @@ -54,6 +54,7 @@ hasCR50=false kbl_use_rwl18=false useAltfwStd=false runsWindows=false +hasLocalPath=false hsw_boxes=('mccloud' 'panther' 'tricky' 'zako') hsw_books=('falco' 'leon' 'monroe' 'peppy' 'wolf')