Skip to content

Commit eaa4ef6

Browse files
committed
Update flashrom binary, rework param usage
Signed-off-by: Matt DeVillier <[email protected]>
1 parent ce898a3 commit eaa4ef6

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

firmware.sh

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,30 @@ fi
457457

458458
#flash Full ROM firmware
459459

460-
#flash without verify, to avoid IFD mismatch upon verification
460+
# ensure no issues overwriting log file
461+
rm -f /tmp/flashrom.log
462+
461463
echo_yellow "Installing Full ROM firmware (may take up to 90s)"
462-
${flashromcmd} ${flashrom_params} -n -w "${coreboot_file}" -o /tmp/flashrom.log > /dev/null 2>&1
464+
#check if flashrom supports --noverify-all
465+
if ${flashromcmd} -h | grep -q "noverify-all" ; then
466+
noverify="--noverify-all"
467+
else
468+
noverify="--noverify"
469+
fi
470+
#check if flashrom supports logging to file
471+
if ${flashromcmd} -L -o /dev/null >/dev/null 2>&1 ; then
472+
output_params=">/dev/null 2>&1 -o /tmp/flashrom.log"
473+
${flashromcmd} ${flashrom_params} ${noverify} -w ${coreboot_file} >/dev/null 2>&1 -o /tmp/flashrom.log
474+
else
475+
output_params=">/tmp/flashrom.log 2>&1"
476+
${flashromcmd} ${flashrom_params} ${noverify} -w ${coreboot_file} >/tmp/flashrom.log 2>&1
477+
fi
463478
if [ $? -ne 0 ]; then
464-
cat /tmp/flashrom.log
479+
echo_red "Error running cmd: ${flashromcmd} ${flashrom_params} ${noverify} -w ${coreboot_file} ${output_params}"
480+
if [ -f /tmp/flashrom.log ]; then
481+
read -rp "Press enter to view the flashrom log file, then space for next page, q to quit"
482+
more /tmp/flashrom.log
483+
fi
465484
exit_red "An error occurred flashing the Full ROM firmware. DO NOT REBOOT!"; return 1
466485
else
467486
echo_green "Full ROM firmware successfully installed/updated."
@@ -530,7 +549,7 @@ the touchpad firmware, otherwise the touchpad will not work."
530549
if [[ $? -eq 0 ]]; then
531550
# flash TP firmware
532551
echo_green "Flashing touchpad firmware -- do not touch the touchpad while updating!"
533-
${flashromcmd#${flashrom_params}} -p ec:type=tp -i EC_RW -w ${touchpad_eve_fw} -o /tmp/flashrom.log >/dev/null 2>&1
552+
${flashromcmd#${flashrom_programmer}} -p ec:type=tp -i EC_RW -w ${touchpad_eve_fw} -o /tmp/flashrom.log >/dev/null 2>&1
534553
if [ $? -eq 0 ]; then
535554
echo_green "Touchpad firmware successfully downgraded."
536555
echo_yellow "Please reboot your Pixelbook now."
@@ -732,7 +751,7 @@ fi
732751
echo_yellow "Restoring stock firmware"
733752
# we won't verify here, since we need to flash the entire BIOS region
734753
# but don't want to get a mismatch from the IFD or ME
735-
${flashromcmd} ${flashrom_params} -n -w "${firmware_file}" -o /tmp/flashrom.log > /dev/null 2>&1
754+
${flashromcmd} ${flashrom_params} --noverify-all -w "${firmware_file}" -o /tmp/flashrom.log > /dev/null 2>&1
736755
if [ $? -ne 0 ]; then
737756
cat /tmp/flashrom.log
738757
exit_red "An error occurred restoring the stock firmware. DO NOT REBOOT!"; return 1

functions.sh

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ isChromeOS=true
1010
isChromiumOS=false
1111
isCloudready=false
1212
flashromcmd=""
13-
flashrom_params="-p host"
13+
flashrom_params=""
14+
flashrom_programmer="-p internal"
1415
cbfstoolcmd=""
1516
gbbutilitycmd=""
1617
preferUSB=false
@@ -37,6 +38,7 @@ isCmlBox=false
3738
isZen2=false
3839
isJsl=false
3940
isTgl=false
41+
isAdl=false
4042
isUnsupported=false
4143
firmwareType=""
4244
isStock=true
@@ -53,7 +55,6 @@ hasLAN=false
5355
hasCR50=false
5456
kbl_use_rwl18=false
5557
useAltfwStd=false
56-
runsWindows=false
5758

5859
hsw_boxes=('mccloud' 'panther' 'tricky' 'zako')
5960
hsw_books=('falco' 'leon' 'monroe' 'peppy' 'wolf')
@@ -247,7 +248,7 @@ if [ ! -f ${flashromcmd} ]; then
247248
else
248249
#have to use partition 12 (27 for cloudready) on rootdev due to noexec restrictions
249250
rootdev=$(rootdev -d -s)
250-
[[ "${rootdev}" =~ "mmcblk" || "${rootdev}" =~ "nvme" ]] && part_pfx="p" || part_pfx=""
251+
[[ "${rootdev}" =~ "mmcblk" || "${rootdev}" =~ "nvme" ]] && part_pfx="p" || part_pfx=""
251252
[[ "$isCloudready" = "true" && -b ${rootdev}${part_pfx}27 ]] \
252253
&& part_num="${part_pfx}27" || part_num="${part_pfx}12"
253254
boot_mounted=$(mount | grep "${rootdev}""${part_num}")
@@ -271,15 +272,15 @@ if [ ! -f ${flashromcmd} ]; then
271272
#needed to avoid dependencies not found on older ChromeOS
272273
$CURL -sLo "flashrom.tar.gz" "${util_source}flashrom_old.tar.gz"
273274
else
274-
$CURL -sLO "${util_source}flashrom.tar.gz"
275+
$CURL -sLO "${util_source}flashrom_20230202.tar.gz"
275276
fi
276277
if [ $? -ne 0 ]; then
277278
echo_red "Error downloading flashrom; cannot proceed."
278279
#restore working dir
279280
cd ${working_dir}
280281
return 1
281282
fi
282-
tar -zxf flashrom.tar.gz --no-same-owner
283+
tar -zxf flashrom_20230202.tar.gz --no-same-owner
283284
if [ $? -ne 0 ]; then
284285
echo_red "Error extracting flashrom; cannot proceed."
285286
#restore working dir
@@ -288,8 +289,6 @@ if [ ! -f ${flashromcmd} ]; then
288289
fi
289290
#set +x
290291
chmod +x flashrom
291-
#add params
292-
flashromcmd="${flashromcmd} ${flashrom_params}"
293292
#restore working dir
294293
cd ${working_dir}
295294
fi
@@ -414,11 +413,15 @@ if [ $? -ne 0 ]; then
414413
echo_red "Unable to download flashrom utility; cannot continue"
415414
return 1
416415
fi
416+
# append programmer type
417+
flashromcmd="${flashromcmd} ${flashrom_programmer}"
418+
417419
get_cbfstool
418420
if [ $? -ne 0 ]; then
419421
echo_red "Unable to download cbfstool utility; cannot continue"
420422
return 1
421423
fi
424+
422425
get_gbb_utility
423426
if [ $? -ne 0 ]; then
424427
echo_red "Unable to download gbb_utility utility; cannot continue"
@@ -427,13 +430,15 @@ fi
427430

428431
#get device firmware info
429432
echo -e "\nGetting device/system info..."
430-
#try reading only flash descriptor
431-
if ${flashromcmd} --ifd -i fd -r /tmp/bios.bin > /dev/null 2>&1; then
432-
#we can flash only BIOS region later
433-
flashrom_params="--ifd -i bios"
433+
#try reading only BIOS region
434+
[[ "$isChromeOS" = "false" ]] && test_params=":ich_spi_mode=hwseq" || test_params=""
435+
if ${flashromcmd}${test_params} --ifd -i bios -r /tmp/bios.bin > /dev/null 2>&1; then
436+
flashromcmd="${flashromcmd}${test_params}"
437+
flashrom_params="--ifd -i bios"
438+
else
439+
#read entire firmware
440+
${flashromcmd} -r /tmp/bios.bin > /dev/null 2>&1
434441
fi
435-
#read entire firmware
436-
${flashromcmd} -r /tmp/bios.bin > /dev/null 2>&1
437442
if [ $? -ne 0 ]; then
438443
echo_red "\nUnable to read current firmware; cannot continue."
439444
echo_red "Either add 'iomem=relaxed' to your kernel parameters,\nor trying running from a Live USB with a more permissive kernel (eg, Ubuntu)."

0 commit comments

Comments
 (0)