mirror of
https://github.com/linuxboot/heads.git
synced 2024-12-19 21:17:55 +00:00
Split flash GUI into separate script
To keep the flash logic simpler the GUI logic has been split into a flash-gui.sh program so flash.sh behaves closer to the original flashrom scripts it was based from. I've also removed the previous flashrom scripts and incorporated their options into flash.sh. Finally I set CONFIG_BOARD via the Makefile instead of setting a duplicate option in each board's config.
This commit is contained in:
parent
89b008a042
commit
3c88bc5d86
5
Makefile
5
Makefile
@ -389,6 +389,7 @@ bin_modules-$(CONFIG_FLASHTOOLS) += flashtools
|
||||
bin_modules-$(CONFIG_NEWT) += newt
|
||||
bin_modules-$(CONFIG_CAIRO) += cairo
|
||||
bin_modules-$(CONFIG_FBWHIPTAIL) += fbwhiptail
|
||||
bin_modules-$(CONFIG_NITROKEY) += nitrokey-hotp-verification
|
||||
|
||||
$(foreach m, $(bin_modules-y), \
|
||||
$(call map,initrd_bin_add,$(call bins,$m)) \
|
||||
@ -496,11 +497,13 @@ $(initrd_tmp_dir)/etc/config: FORCE
|
||||
-e 's/\\\"//g' \
|
||||
> $@ \
|
||||
)
|
||||
$(call do,HASH,$(GIT_HASH) $(GIT_STATUS), \
|
||||
$(call do,HASH,$(GIT_HASH) $(GIT_STATUS) $(BOARD), \
|
||||
echo export GIT_HASH=\'$(GIT_HASH)\' \
|
||||
>> $@ ; \
|
||||
echo export GIT_STATUS=$(GIT_STATUS) \
|
||||
>> $@ ; \
|
||||
echo export CONFIG_BOARD=$(BOARD) \
|
||||
>> $@ ; \
|
||||
)
|
||||
|
||||
# Ensure that the initrd depends on all of the modules that produce
|
||||
|
@ -34,4 +34,3 @@ export CONFIG_BOOT_GUI_MENU_NAME="Purism Librem 13v2 Heads Boot Menu"
|
||||
export CONFIG_USB_BOOT_DEV="/dev/sdb1"
|
||||
export CONFIG_WARNING_BG_COLOR="--background-gradient 0 0 0 150 125 0"
|
||||
export CONFIG_ERROR_BG_COLOR="--background-gradient 0 0 0 150 0 0"
|
||||
export CONFIG_BOARD="librem"
|
||||
|
@ -34,4 +34,3 @@ export CONFIG_BOOT_KERNEL_REMOVE=""
|
||||
export CONFIG_BOOT_DEV="/dev/sda1"
|
||||
export CONFIG_BOOT_GUI_MENU_NAME="Purism Librem 15v3 Heads Boot Menu"
|
||||
export CONFIG_USB_BOOT_DEV="/dev/sdb1"
|
||||
export CONFIG_BOARD="librem"
|
||||
|
@ -28,7 +28,6 @@ export CONFIG_BOOT_KERNEL_ADD="intel_iommu=on"
|
||||
export CONFIG_BOOT_KERNEL_REMOVE="quiet"
|
||||
export CONFIG_BOOT_DEV="/dev/sda1"
|
||||
export CONFIG_USB_BOOT_DEV="/dev/sdb1"
|
||||
export CONFIG_BOARD="x230"
|
||||
|
||||
# This board has two SPI flash chips, an 8 MB that holds the IFD,
|
||||
# the ME image and part of the coreboot image, and a 4 MB one that
|
||||
|
126
initrd/bin/flash-gui.sh
Executable file
126
initrd/bin/flash-gui.sh
Executable file
@ -0,0 +1,126 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# based off of flashrom-x230 and usb-scan
|
||||
#
|
||||
set -e -o pipefail
|
||||
. /etc/functions
|
||||
. /etc/config
|
||||
|
||||
# Mount the USB boot device
|
||||
if ! grep -q /media /proc/mounts ; then
|
||||
mount-usb "$CONFIG_USB_BOOT_DEV" || USB_FAILED=1
|
||||
if [ $USB_FAILED -ne 0 ]; then
|
||||
if [ ! -e "$CONFIG_USB_BOOT_DEV" ]; then
|
||||
if [ -x /bin/whiptail ]; then
|
||||
whiptail --title 'USB Drive Missing' \
|
||||
--msgbox "Insert the USB drive containing your ROM and press Enter to continue." 16 60
|
||||
else
|
||||
echo "Insert the USB drive containing your ROM and press Enter to continue."
|
||||
fi
|
||||
USB_FAILED=0
|
||||
mount-usb "$CONFIG_USB_BOOT_DEV" || USB_FAILED=1
|
||||
fi
|
||||
if [ $USB_FAILED -ne 0 ]; then
|
||||
if [ -x /bin/whiptail ]; then
|
||||
whiptail $CONFIG_ERROR_BG_COLOR --title 'ERROR: Mounting /media Failed' \
|
||||
--msgbox "Unable to mount $CONFIG_USB_BOOT_DEV" 16 60
|
||||
else
|
||||
die "ERROR: Unable to mount $CONFIG_USB_BOOT_DEV"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
get_menu_option() {
|
||||
if [ -x /bin/whiptail ]; then
|
||||
MENU_OPTIONS=""
|
||||
n=0
|
||||
while read option
|
||||
do
|
||||
n=`expr $n + 1`
|
||||
option=$(echo $option | tr " " "_")
|
||||
MENU_OPTIONS="$MENU_OPTIONS $n ${option}"
|
||||
done < /tmp/rom_menu.txt
|
||||
|
||||
MENU_OPTIONS="$MENU_OPTIONS a abort"
|
||||
whiptail --clear --title "Select your ROM" \
|
||||
--menu "Choose the ROM to flash [1-$n, a to abort]:" 20 120 8 \
|
||||
-- $MENU_OPTIONS \
|
||||
2>/tmp/whiptail || die "Aborting flash attempt"
|
||||
|
||||
option_index=$(cat /tmp/whiptail)
|
||||
else
|
||||
echo "+++ Select your ROM:"
|
||||
n=0
|
||||
while read option
|
||||
do
|
||||
n=`expr $n + 1`
|
||||
echo "$n. $option"
|
||||
done < /tmp/rom_menu.txt
|
||||
|
||||
read \
|
||||
-p "Choose the ROM to flash [1-$n, a to abort]: " \
|
||||
option_index
|
||||
fi
|
||||
|
||||
if [ "$option_index" = "a" ]; then
|
||||
die "Aborting flash attempt"
|
||||
fi
|
||||
|
||||
option=`head -n $option_index /tmp/rom_menu.txt | tail -1`
|
||||
}
|
||||
|
||||
# create ROM menu options
|
||||
ls -1r /media/*.rom 2>/dev/null > /tmp/rom_menu.txt || true
|
||||
if [ `cat /tmp/rom_menu.txt | wc -l` -gt 0 ]; then
|
||||
option_confirm=""
|
||||
while [ -z "$option" ]
|
||||
do
|
||||
get_menu_option
|
||||
done
|
||||
|
||||
if [ -n "$option" ]; then
|
||||
MOUNTED_ROM=$option
|
||||
ROM=${option:7} # remove /media/ to get device relative path
|
||||
|
||||
if [ -x /bin/whiptail ]; then
|
||||
if (whiptail --title 'Flash ROM?' \
|
||||
--yesno "This will replace your old ROM with $ROM\n\nDo you want to proceed?" 16 90) then
|
||||
/bin/flash.sh $MOUNTED_ROM
|
||||
whiptail --title 'ROM Flashed Successfully' \
|
||||
--msgbox "$ROM flashed successfully. Press Enter to reboot" 16 60
|
||||
/bin/reboot
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
echo "+++ Flash ROM $ROM?"
|
||||
read \
|
||||
-n 1 \
|
||||
-p "This will replace your old ROM with $ROM, Do you want to proceed? [y/N] " \
|
||||
do_flash
|
||||
echo
|
||||
if [ "$do_flash" != "y" \
|
||||
-a "$do_flash" != "Y" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
/bin/flash.sh $MOUNTED_ROM
|
||||
echo "$ROM flashed successfuly. Press Enter to reboot"
|
||||
read
|
||||
/bin/reboot
|
||||
fi
|
||||
|
||||
die "Something failed in ROM flash"
|
||||
fi
|
||||
else
|
||||
if [ -x /bin/whiptail ]; then
|
||||
whiptail --title 'No ROMs found' \
|
||||
--msgbox "No ROMs found on USB disk" 16 60
|
||||
else
|
||||
echo "No ROMs found on USB disk. Press Enter to continue"
|
||||
read
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
@ -1,98 +1,29 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# based off of flashrom-x230 and usb-scan
|
||||
# based off of flashrom-x230
|
||||
#
|
||||
set -e -o pipefail
|
||||
. /etc/functions
|
||||
. /etc/config
|
||||
|
||||
case "$CONFIG_BOARD" in
|
||||
"librem" )
|
||||
librem* )
|
||||
FLASHROM_OPTIONS='-p internal:laptop=force_I_want_a_brick,ich_spi_mode=hwseq'
|
||||
;;
|
||||
"x230" )
|
||||
FLASHROM_OPTIONS='--force --noverify-all --programmer internal --ifd --image bios'
|
||||
;;
|
||||
"kgpe-d16" )
|
||||
FLASHROM_OPTIONS='--force --noverify --programmer internal'
|
||||
;;
|
||||
"kgpe-d16-openbmc" )
|
||||
FLASHROM_OPTIONS='--programmer="ast1100:spibus=2,cpu=reset" -c "S25FL128P......0"'
|
||||
;;
|
||||
* )
|
||||
if [ -x /bin/whiptail ]; then
|
||||
whiptail $CONFIG_ERROR_BG_COLOR --title 'ERROR: No Board Configured' \
|
||||
--msgbox "ERROR: No board has been configured!\n\nEach board requires specific flashrom options and it's unsafe to flash without them.\n\nAborting." 16 60
|
||||
else
|
||||
die "ERROR: No board has been configured!\n\nEach board requires specific flashrom options and it's unsafe to flash without them.\n\nAborting."
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$1" = "-c" ]; then
|
||||
CLEAN=1
|
||||
else
|
||||
CLEAN=0
|
||||
fi
|
||||
|
||||
# Mount the USB boot device
|
||||
if ! grep -q /media /proc/mounts ; then
|
||||
mount-usb "$CONFIG_USB_BOOT_DEV" || USB_FAILED=1
|
||||
if [ $USB_FAILED -ne 0 ]; then
|
||||
if [ ! -e "$CONFIG_USB_BOOT_DEV" ]; then
|
||||
if [ -x /bin/whiptail ]; then
|
||||
whiptail --title 'USB Drive Missing' \
|
||||
--msgbox "Insert the USB drive containing your ROM and press Enter to continue." 16 60
|
||||
else
|
||||
echo "Insert the USB drive containing your ROM and press Enter to continue."
|
||||
fi
|
||||
USB_FAILED=0
|
||||
mount-usb "$CONFIG_USB_BOOT_DEV" || USB_FAILED=1
|
||||
fi
|
||||
if [ $USB_FAILED -ne 0 ]; then
|
||||
if [ -x /bin/whiptail ]; then
|
||||
whiptail $CONFIG_ERROR_BG_COLOR --title 'ERROR: Mounting /media Failed' \
|
||||
--msgbox "Unable to mount $CONFIG_USB_BOOT_DEV" 16 60
|
||||
else
|
||||
die "ERROR: Unable to mount $CONFIG_USB_BOOT_DEV"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
get_menu_option() {
|
||||
if [ -x /bin/whiptail ]; then
|
||||
MENU_OPTIONS=""
|
||||
n=0
|
||||
while read option
|
||||
do
|
||||
n=`expr $n + 1`
|
||||
option=$(echo $option | tr " " "_")
|
||||
MENU_OPTIONS="$MENU_OPTIONS $n ${option}"
|
||||
done < /tmp/rom_menu.txt
|
||||
|
||||
MENU_OPTIONS="$MENU_OPTIONS a abort"
|
||||
whiptail --clear --title "Select your ROM" \
|
||||
--menu "Choose the ROM to flash [1-$n, a to abort]:" 20 120 8 \
|
||||
-- $MENU_OPTIONS \
|
||||
2>/tmp/whiptail || die "Aborting flash attempt"
|
||||
|
||||
option_index=$(cat /tmp/whiptail)
|
||||
else
|
||||
echo "+++ Select your ROM:"
|
||||
n=0
|
||||
while read option
|
||||
do
|
||||
n=`expr $n + 1`
|
||||
echo "$n. $option"
|
||||
done < /tmp/rom_menu.txt
|
||||
|
||||
read \
|
||||
-p "Choose the ROM to flash [1-$n, a to abort]: " \
|
||||
option_index
|
||||
fi
|
||||
|
||||
if [ "$option_index" = "a" ]; then
|
||||
die "Aborting flash attempt"
|
||||
fi
|
||||
|
||||
option=`head -n $option_index /tmp/rom_menu.txt | tail -1`
|
||||
}
|
||||
|
||||
flash_rom() {
|
||||
ROM=$1
|
||||
cp "$ROM" /tmp/${CONFIG_BOARD}.rom
|
||||
@ -106,57 +37,17 @@ flash_rom() {
|
||||
|| die "$ROM: Flash failed"
|
||||
}
|
||||
|
||||
# create ROM menu options
|
||||
ls -1r /media/*.rom 2>/dev/null > /tmp/rom_menu.txt || true
|
||||
if [ `cat /tmp/rom_menu.txt | wc -l` -gt 0 ]; then
|
||||
option_confirm=""
|
||||
while [ -z "$option" ]
|
||||
do
|
||||
get_menu_option
|
||||
done
|
||||
|
||||
if [ -n "$option" ]; then
|
||||
MOUNTED_ROM=$option
|
||||
ROM=${option:7} # remove /media/ to get device relative path
|
||||
|
||||
if [ -x /bin/whiptail ]; then
|
||||
if (whiptail --title 'Flash ROM?' \
|
||||
--yesno "This will replace your old ROM with $ROM\n\nDo you want to proceed?" 16 90) then
|
||||
flash_rom $MOUNTED_ROM
|
||||
whiptail --title 'ROM Flashed Successfully' \
|
||||
--msgbox "$ROM flashed successfully. Press Enter to reboot" 16 60
|
||||
/bin/reboot
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
echo "+++ Flash ROM $ROM?"
|
||||
read \
|
||||
-n 1 \
|
||||
-p "This will replace your old ROM with $ROM, Do you want to proceed? [y/N] " \
|
||||
do_flash
|
||||
echo
|
||||
if [ "$do_flash" != "y" \
|
||||
-a "$do_flash" != "Y" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
flash_rom $MOUNTED_ROM
|
||||
echo "$ROM flashed successfuly. Press Enter to reboot"
|
||||
read
|
||||
/bin/reboot
|
||||
fi
|
||||
|
||||
die "Something failed in ROM flash"
|
||||
fi
|
||||
if [ "$1" = "-c" ]; then
|
||||
CLEAN=1
|
||||
ROM="$2"
|
||||
else
|
||||
if [ -x /bin/whiptail ]; then
|
||||
whiptail --title 'No ROMs found' \
|
||||
--msgbox "No ROMs found on USB disk" 16 60
|
||||
else
|
||||
echo "No ROMs found on USB disk. Press Enter to continue"
|
||||
read
|
||||
fi
|
||||
CLEAN=0
|
||||
ROM="$1"
|
||||
fi
|
||||
|
||||
if [ ! -e "$ROM" ]; then
|
||||
die "Usage: $0 [-c] <path_to_image.rom>"
|
||||
fi
|
||||
|
||||
flash_rom $ROM
|
||||
exit 0
|
||||
|
@ -1,16 +0,0 @@
|
||||
#!/bin/sh
|
||||
. /etc/functions
|
||||
|
||||
ROM="$1"
|
||||
if [ -z "$1" ]; then
|
||||
die "Usage: $0 /media/kgpe-d16-openbmc.rom"
|
||||
fi
|
||||
|
||||
cp "$ROM" /tmp/kgpe-d16-openbmc.rom
|
||||
sha256sum /tmp/kgpe-d16-openbmc.rom
|
||||
|
||||
flashrom --programmer="ast1100:spibus=2,cpu=reset" -c "S25FL128P......0" -w /tmp/kgpe-d16-openbmc.rom \
|
||||
|| die "$ROM: Flash failed"
|
||||
|
||||
warn "Reboot and hopefully it works..."
|
||||
exit 0
|
@ -1,31 +0,0 @@
|
||||
#!/bin/sh
|
||||
. /etc/functions
|
||||
|
||||
if [ "$1" = "-c" ]; then
|
||||
CLEAN=1
|
||||
ROM="$2"
|
||||
else
|
||||
CLEAN=0
|
||||
ROM="$1"
|
||||
fi
|
||||
|
||||
if [ ! -e "$ROM" ]; then
|
||||
die "Usage: $0 [-c] /media/kgpe-d16.rom"
|
||||
fi
|
||||
|
||||
cp "$ROM" /tmp/kgpe-d16.rom
|
||||
sha256sum /tmp/kgpe-d16.rom
|
||||
if [ "$CLEAN" -eq 0 ]; then
|
||||
preserve_rom /tmp/kgpe-d16.rom \
|
||||
|| die "$ROM: Config preservation failed"
|
||||
fi
|
||||
|
||||
flashrom \
|
||||
--force \
|
||||
--noverify \
|
||||
--programmer internal \
|
||||
-w /tmp/kgpe-d16.rom \
|
||||
|| die "$ROM: Flash failed"
|
||||
|
||||
warn "Reboot and hopefully it works..."
|
||||
exit 0
|
@ -1,33 +0,0 @@
|
||||
#!/bin/sh
|
||||
. /etc/functions
|
||||
|
||||
if [ "$1" = "-c" ]; then
|
||||
CLEAN=1
|
||||
ROM="$2"
|
||||
else
|
||||
CLEAN=0
|
||||
ROM="$1"
|
||||
fi
|
||||
|
||||
if [ ! -e "$ROM" ]; then
|
||||
die "Usage: $0 [-c] /media/x230.rom"
|
||||
fi
|
||||
|
||||
cp "$ROM" /tmp/x230.rom
|
||||
sha256sum /tmp/x230.rom
|
||||
if [ "$CLEAN" -eq 0 ]; then
|
||||
preserve_rom /tmp/x230.rom \
|
||||
|| die "$ROM: Config preservation failed"
|
||||
fi
|
||||
|
||||
flashrom \
|
||||
--force \
|
||||
--noverify-all \
|
||||
--programmer internal \
|
||||
--ifd \
|
||||
--image bios \
|
||||
-w /tmp/x230.rom \
|
||||
|| die "$ROM: Flash failed"
|
||||
|
||||
warn "Reboot and hopefully it works..."
|
||||
exit 0
|
@ -247,7 +247,7 @@ while true; do
|
||||
fi
|
||||
|
||||
if [ "$totp_confirm" = "f" ]; then
|
||||
/bin/flash.sh
|
||||
flash-gui.sh
|
||||
continue
|
||||
fi
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user