From 21af45674efb1d56010f8abdb629a1c3867551d6 Mon Sep 17 00:00:00 2001 From: Timothy Pidashev Date: Tue, 14 Apr 2026 08:55:33 -0700 Subject: [PATCH] script fixes --- coreboot-t440p/steps/backup_bios.sh | 41 ++++++++++++++++++++++++----- coreboot-t440p/steps/build_bios.sh | 5 ++++ coreboot-t440p/steps/configure.sh | 40 ++++++++++++++++++++++------ coreboot-t440p/steps/flash_bios.sh | 9 +++++-- coreboot-t440p/steps/revert_bios.sh | 7 +++++ run.sh | 24 ++++++++++------- 6 files changed, 100 insertions(+), 26 deletions(-) diff --git a/coreboot-t440p/steps/backup_bios.sh b/coreboot-t440p/steps/backup_bios.sh index d3cb671..7f4901b 100755 --- a/coreboot-t440p/steps/backup_bios.sh +++ b/coreboot-t440p/steps/backup_bios.sh @@ -1,5 +1,36 @@ #!/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() { section "Verify BIOS Backups" @@ -10,18 +41,14 @@ step_backup_bios() { if diff 4mb_backup1.bin 4mb_backup2.bin >/dev/null 2>&1; then success "4MB chip reads are identical." else - error "4MB chip reads do NOT match!" - warn "The chip may not be reading reliably. Re-seat the programmer and try again." - return 1 + _reread_chip "4mb" "4MB (top)" || return 1 fi info "Verifying 8MB chip reads match..." if diff 8mb_backup1.bin 8mb_backup2.bin >/dev/null 2>&1; then success "8MB chip reads are identical." else - error "8MB chip reads do NOT match!" - warn "The chip may not be reading reliably. Re-seat the programmer and try again." - return 1 + _reread_chip "8mb" "8MB (bottom)" || return 1 fi # Validate file sizes diff --git a/coreboot-t440p/steps/build_bios.sh b/coreboot-t440p/steps/build_bios.sh index f7cf28e..4fe9e7b 100755 --- a/coreboot-t440p/steps/build_bios.sh +++ b/coreboot-t440p/steps/build_bios.sh @@ -30,5 +30,10 @@ step_build_bios() { fi _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)" } diff --git a/coreboot-t440p/steps/configure.sh b/coreboot-t440p/steps/configure.sh index 9f87942..5d9841b 100755 --- a/coreboot-t440p/steps/configure.sh +++ b/coreboot-t440p/steps/configure.sh @@ -23,6 +23,17 @@ step_configure() { return 1 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 "" info "Choose a payload for your coreboot build:" echo "" @@ -46,10 +57,19 @@ step_configure() { done _has_dgpu="n" + _dgpu_vbios="" if [ "$_payload" != "custom" ]; then echo "" if prompt_yes_no "Does your T440p have the GT730M dGPU?"; then _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 @@ -75,7 +95,7 @@ step_configure() { cat > .config << COREBOOT_CONFIG # Mainboard CONFIG_VENDOR_LENOVO=y -CONFIG_BOARD_LENOVO_HASWELL=y +CONFIG_BOARD_LENOVO_THINKPAD_T440P=y # Firmware blobs CONFIG_HAVE_IFD_BIN=y @@ -98,7 +118,6 @@ CONFIG_PAYLOAD_GRUB2=y CONFIG_GRUB2_INCLUDE_RUNTIME_CONFIG_FILE=y # Secondary payloads -CONFIG_PAYLOAD_FILE_IS_GRUB2=y CONFIG_MEMTEST_SECONDARY_PAYLOAD=y CONFIG_NVRAMCUI_SECONDARY_PAYLOAD=y CONFIG_COREINFO_SECONDARY_PAYLOAD=y @@ -115,21 +134,26 @@ SEABIOS_CONFIG edk2) cat >> .config << 'EDK2_CONFIG' -# Payload -CONFIG_PAYLOAD_EDK2=y +# Payload (tianocore/edk2) +CONFIG_PAYLOAD_TIANOCORE=y EDK2_CONFIG ;; esac - # dGPU option ROM + # dGPU option ROM (GT730M) if [ "$_has_dgpu" = "y" ]; then - cat >> .config << 'DGPU_CONFIG' + cat >> .config << DGPU_CONFIG # dGPU (GT730M) VGA option ROM -CONFIG_VGA_BIOS=y CONFIG_VGA_BIOS_DGPU=y +CONFIG_VGA_BIOS_DGPU_FILE="$_dgpu_vbios" +CONFIG_VGA_BIOS_DGPU_ID="10de,1292" 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 # Fill in remaining defaults diff --git a/coreboot-t440p/steps/flash_bios.sh b/coreboot-t440p/steps/flash_bios.sh index 3625771..320fe4b 100755 --- a/coreboot-t440p/steps/flash_bios.sh +++ b/coreboot-t440p/steps/flash_bios.sh @@ -18,8 +18,13 @@ step_flash_bios() { _bottom_size=$(wc -c < bottom.rom) _top_size=$(wc -c < top.rom) - info "bottom.rom: $_bottom_size bytes" - info "top.rom: $_top_size bytes" + info "bottom.rom: $_bottom_size bytes (expected $SIZE_8MB)" + 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 "" warn "You are about to flash coreboot onto your T440p." diff --git a/coreboot-t440p/steps/revert_bios.sh b/coreboot-t440p/steps/revert_bios.sh index 707659d..1fd835c 100755 --- a/coreboot-t440p/steps/revert_bios.sh +++ b/coreboot-t440p/steps/revert_bios.sh @@ -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=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 info "Attach the programmer to the 4MB (top) chip." prompt_continue diff --git a/run.sh b/run.sh index 7553bd9..506af9d 100755 --- a/run.sh +++ b/run.sh @@ -49,20 +49,18 @@ download_script() { if echo "$script_path" | grep -q "\.\(sh\|bash\|pl\|py\)$"; then chmod +x "$output_path" fi - - echo "$output_path" } # Function to download a directory listing get_directory_listing() { 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) # 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) - echo "$listing" + echo "$listing" >&2 } # Function to download an entire directory structure @@ -86,8 +84,8 @@ download_directory() { # Make all shell scripts executable find "$output_dir" -name "*.sh" -exec chmod +x {} \; - - echo "$output_dir" + + printf '%s\n' "$output_dir" } # Interactive menu if no script type was specified @@ -129,12 +127,20 @@ case "$SCRIPT_TYPE" in # Run the main script if it exists 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 # 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 - "$main_script" "$@" + if [ -t 0 ]; then + "$main_script" "$@" + else + "$main_script" "$@" < /dev/tty + fi else echo "Error: No executable scripts found in $script_dir" exit 1