script fixes

This commit is contained in:
2026-04-14 08:55:33 -07:00
parent aaa53d6a09
commit 21af45674e
6 changed files with 100 additions and 26 deletions
+34 -7
View File
@@ -1,5 +1,36 @@
#!/bin/sh #!/bin/sh
# Step: Verify BIOS backup integrity # Step: Verify BIOS backup integrity (with per-chip retry)
# Re-read a single chip until two reads match or user gives up
_reread_chip() {
_label="$1" # "4mb" or "8mb"
_desc="$2" # human-readable description
while true; do
warn "$_desc reads do NOT match. The chip may not be reading reliably."
echo ""
echo " 1) Re-seat programmer on $_desc chip and retry"
echo " 2) Abort"
echo ""
printf "${CYAN}Choice [1-2]:${NC} "
read -r _choice
case "$_choice" in
1)
info "Re-reading $_desc chip (read 1 of 2)..."
run_cmd "sudo flashrom --programmer ch341a_spi -r ${_label}_backup1.bin" || return 1
info "Re-reading $_desc chip (read 2 of 2)..."
run_cmd "sudo flashrom --programmer ch341a_spi -r ${_label}_backup2.bin" || return 1
if diff "${_label}_backup1.bin" "${_label}_backup2.bin" >/dev/null 2>&1; then
success "$_desc reads now match."
return 0
fi
;;
*)
return 1
;;
esac
done
}
step_backup_bios() { step_backup_bios() {
section "Verify BIOS Backups" section "Verify BIOS Backups"
@@ -10,18 +41,14 @@ step_backup_bios() {
if diff 4mb_backup1.bin 4mb_backup2.bin >/dev/null 2>&1; then if diff 4mb_backup1.bin 4mb_backup2.bin >/dev/null 2>&1; then
success "4MB chip reads are identical." success "4MB chip reads are identical."
else else
error "4MB chip reads do NOT match!" _reread_chip "4mb" "4MB (top)" || return 1
warn "The chip may not be reading reliably. Re-seat the programmer and try again."
return 1
fi fi
info "Verifying 8MB chip reads match..." info "Verifying 8MB chip reads match..."
if diff 8mb_backup1.bin 8mb_backup2.bin >/dev/null 2>&1; then if diff 8mb_backup1.bin 8mb_backup2.bin >/dev/null 2>&1; then
success "8MB chip reads are identical." success "8MB chip reads are identical."
else else
error "8MB chip reads do NOT match!" _reread_chip "8mb" "8MB (bottom)" || return 1
warn "The chip may not be reading reliably. Re-seat the programmer and try again."
return 1
fi fi
# Validate file sizes # Validate file sizes
+5
View File
@@ -30,5 +30,10 @@ step_build_bios() {
fi fi
_size=$(wc -c < "$COREBOOT_DIR/build/coreboot.rom") _size=$(wc -c < "$COREBOOT_DIR/build/coreboot.rom")
if [ "$_size" -ne "$SIZE_12MB" ]; then
error "coreboot.rom size is $_size bytes, expected $SIZE_12MB (12MB)."
error "Flashing a wrong-sized ROM will brick the board. Check your config."
return 1
fi
success "Build complete: $COREBOOT_DIR/build/coreboot.rom ($_size bytes)" success "Build complete: $COREBOOT_DIR/build/coreboot.rom ($_size bytes)"
} }
+32 -8
View File
@@ -23,6 +23,17 @@ step_configure() {
return 1 return 1
fi fi
# Warn before overwriting existing .config
if [ -f "$COREBOOT_DIR/.config" ]; then
echo ""
warn "An existing .config was found in $COREBOOT_DIR."
if ! prompt_yes_no "Overwrite it?"; then
info "Keeping existing .config. Opening nconfig for review..."
make nconfig
return $?
fi
fi
echo "" echo ""
info "Choose a payload for your coreboot build:" info "Choose a payload for your coreboot build:"
echo "" echo ""
@@ -46,10 +57,19 @@ step_configure() {
done done
_has_dgpu="n" _has_dgpu="n"
_dgpu_vbios=""
if [ "$_payload" != "custom" ]; then if [ "$_payload" != "custom" ]; then
echo "" echo ""
if prompt_yes_no "Does your T440p have the GT730M dGPU?"; then if prompt_yes_no "Does your T440p have the GT730M dGPU?"; then
_has_dgpu="y" _has_dgpu="y"
echo ""
info "dGPU support needs a VGA option ROM (VBIOS) for the GT730M."
info "Extract it from your original ROM, dump from live Windows, or obtain separately."
_dgpu_vbios=$(prompt_value "Path to GT730M VBIOS file (leave empty to skip auto-set)" "")
if [ -n "$_dgpu_vbios" ] && [ ! -f "$_dgpu_vbios" ]; then
warn "File not found: $_dgpu_vbios. Will set flags only; fill path in nconfig."
_dgpu_vbios=""
fi
fi fi
fi fi
@@ -75,7 +95,7 @@ step_configure() {
cat > .config << COREBOOT_CONFIG cat > .config << COREBOOT_CONFIG
# Mainboard # Mainboard
CONFIG_VENDOR_LENOVO=y CONFIG_VENDOR_LENOVO=y
CONFIG_BOARD_LENOVO_HASWELL=y CONFIG_BOARD_LENOVO_THINKPAD_T440P=y
# Firmware blobs # Firmware blobs
CONFIG_HAVE_IFD_BIN=y CONFIG_HAVE_IFD_BIN=y
@@ -98,7 +118,6 @@ CONFIG_PAYLOAD_GRUB2=y
CONFIG_GRUB2_INCLUDE_RUNTIME_CONFIG_FILE=y CONFIG_GRUB2_INCLUDE_RUNTIME_CONFIG_FILE=y
# Secondary payloads # Secondary payloads
CONFIG_PAYLOAD_FILE_IS_GRUB2=y
CONFIG_MEMTEST_SECONDARY_PAYLOAD=y CONFIG_MEMTEST_SECONDARY_PAYLOAD=y
CONFIG_NVRAMCUI_SECONDARY_PAYLOAD=y CONFIG_NVRAMCUI_SECONDARY_PAYLOAD=y
CONFIG_COREINFO_SECONDARY_PAYLOAD=y CONFIG_COREINFO_SECONDARY_PAYLOAD=y
@@ -115,21 +134,26 @@ SEABIOS_CONFIG
edk2) edk2)
cat >> .config << 'EDK2_CONFIG' cat >> .config << 'EDK2_CONFIG'
# Payload # Payload (tianocore/edk2)
CONFIG_PAYLOAD_EDK2=y CONFIG_PAYLOAD_TIANOCORE=y
EDK2_CONFIG EDK2_CONFIG
;; ;;
esac esac
# dGPU option ROM # dGPU option ROM (GT730M)
if [ "$_has_dgpu" = "y" ]; then if [ "$_has_dgpu" = "y" ]; then
cat >> .config << 'DGPU_CONFIG' cat >> .config << DGPU_CONFIG
# dGPU (GT730M) VGA option ROM # dGPU (GT730M) VGA option ROM
CONFIG_VGA_BIOS=y
CONFIG_VGA_BIOS_DGPU=y CONFIG_VGA_BIOS_DGPU=y
CONFIG_VGA_BIOS_DGPU_FILE="$_dgpu_vbios"
CONFIG_VGA_BIOS_DGPU_ID="10de,1292"
DGPU_CONFIG DGPU_CONFIG
info "dGPU option ROM support enabled." if [ -z "$_dgpu_vbios" ]; then
warn "dGPU VBIOS path empty — set CONFIG_VGA_BIOS_DGPU_FILE in nconfig before building."
else
info "dGPU option ROM configured: $_dgpu_vbios"
fi
fi fi
# Fill in remaining defaults # Fill in remaining defaults
+7 -2
View File
@@ -18,8 +18,13 @@ step_flash_bios() {
_bottom_size=$(wc -c < bottom.rom) _bottom_size=$(wc -c < bottom.rom)
_top_size=$(wc -c < top.rom) _top_size=$(wc -c < top.rom)
info "bottom.rom: $_bottom_size bytes" info "bottom.rom: $_bottom_size bytes (expected $SIZE_8MB)"
info "top.rom: $_top_size bytes" info "top.rom: $_top_size bytes (expected $SIZE_4MB)"
if [ "$_bottom_size" -ne "$SIZE_8MB" ] || [ "$_top_size" -ne "$SIZE_4MB" ]; then
error "Split ROM sizes wrong. Refusing to flash."
return 1
fi
echo "" echo ""
warn "You are about to flash coreboot onto your T440p." warn "You are about to flash coreboot onto your T440p."
+7
View File
@@ -38,6 +38,13 @@ _revert_external() {
run_cmd "dd if=t440p-original.rom of=bottom.rom bs=1M count=8" || return 1 run_cmd "dd if=t440p-original.rom of=bottom.rom bs=1M count=8" || return 1
run_cmd "dd if=t440p-original.rom of=top.rom bs=1M skip=8" || return 1 run_cmd "dd if=t440p-original.rom of=top.rom bs=1M skip=8" || return 1
_b=$(wc -c < bottom.rom)
_t=$(wc -c < top.rom)
if [ "$_b" -ne "$SIZE_8MB" ] || [ "$_t" -ne "$SIZE_4MB" ]; then
error "Split sizes wrong (bottom=$_b, top=$_t). Aborting."
return 1
fi
# Flash 4MB (top) chip # Flash 4MB (top) chip
info "Attach the programmer to the 4MB (top) chip." info "Attach the programmer to the 4MB (top) chip."
prompt_continue prompt_continue
+15 -9
View File
@@ -49,20 +49,18 @@ download_script() {
if echo "$script_path" | grep -q "\.\(sh\|bash\|pl\|py\)$"; then if echo "$script_path" | grep -q "\.\(sh\|bash\|pl\|py\)$"; then
chmod +x "$output_path" chmod +x "$output_path"
fi fi
echo "$output_path"
} }
# Function to download a directory listing # Function to download a directory listing
get_directory_listing() { get_directory_listing() {
dir_path="$1" dir_path="$1"
echo "Getting file listing for $dir_path..." echo "Getting file listing for $dir_path..." >&2
# Use curl to fetch directory listing (this assumes your web server has directory listing enabled) # Use curl to fetch directory listing (this assumes your web server has directory listing enabled)
# This is a simple approach that may need customization based on your web server # This is a simple approach that may need customization based on your web server
listing=$(curl -s "$BASE_URL/$dir_path/" | grep -o 'href="[^"]*"' | cut -d'"' -f2) listing=$(curl -s "$BASE_URL/$dir_path/" | grep -o 'href="[^"]*"' | cut -d'"' -f2)
echo "$listing" echo "$listing" >&2
} }
# Function to download an entire directory structure # Function to download an entire directory structure
@@ -86,8 +84,8 @@ download_directory() {
# Make all shell scripts executable # Make all shell scripts executable
find "$output_dir" -name "*.sh" -exec chmod +x {} \; find "$output_dir" -name "*.sh" -exec chmod +x {} \;
echo "$output_dir" printf '%s\n' "$output_dir"
} }
# Interactive menu if no script type was specified # Interactive menu if no script type was specified
@@ -129,12 +127,20 @@ case "$SCRIPT_TYPE" in
# Run the main script if it exists # Run the main script if it exists
if [ -f "$script_dir/main.sh" ]; then if [ -f "$script_dir/main.sh" ]; then
"$script_dir/main.sh" "$@" if [ -t 0 ]; then
"$script_dir/main.sh" "$@"
else
"$script_dir/main.sh" "$@" < /dev/tty
fi
else else
# Try to find any shell script # Try to find any shell script
main_script=$(find "$script_dir" -name "*.sh" -perm +111 | head -1) main_script=$(find "$script_dir" -name "*.sh" -perm -111 | head -1)
if [ -n "$main_script" ]; then if [ -n "$main_script" ]; then
"$main_script" "$@" if [ -t 0 ]; then
"$main_script" "$@"
else
"$main_script" "$@" < /dev/tty
fi
else else
echo "Error: No executable scripts found in $script_dir" echo "Error: No executable scripts found in $script_dir"
exit 1 exit 1