summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Benn <evanbenn@chromium.org>2023-01-12 14:18:28 +1100
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-02-09 09:31:04 +0000
commit3495110ff91df002e8b6c13b9af9a80c93d9dbb3 (patch)
tree3bcdd9da2a38050e212c6389397ceaec6fb333ec
parentf494c76bf12dd4caa4c1646404ad58e2aabceaa5 (diff)
downloadvboot-3495110ff91df002e8b6c13b9af9a80c93d9dbb3.tar.gz
set/get_gbb_flags.sh: Use futility instead of flashrom
futility gbb can now read and write from flash or file. BUG=b:260531154 BRANCH=None TEST=SERVOD_NAME=damu get_gbb_flags.sh -e --servo TEST=get_gbb_flags.sh -e TEST=get_gbb_flags.sh -e --file /tmp/bios TEST=set_gbb_flags.sh 0x0 TEST=set_gbb_flags.sh 0x0 --servo TEST=set_gbb_flags.sh 0x0 /tmp/bios Change-Id: I5cc1a893171195c09f7363b3e99f676806049d0d Signed-off-by: Evan Benn <evanbenn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/4161091 Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Yu-Ping Wu <yupingso@chromium.org>
-rwxr-xr-xscripts/image_signing/gbb_flags_common.sh62
-rwxr-xr-xscripts/image_signing/get_gbb_flags.sh32
-rwxr-xr-xscripts/image_signing/set_gbb_flags.sh42
3 files changed, 33 insertions, 103 deletions
diff --git a/scripts/image_signing/gbb_flags_common.sh b/scripts/image_signing/gbb_flags_common.sh
index 5c8c9e2f..ee9e886f 100755
--- a/scripts/image_signing/gbb_flags_common.sh
+++ b/scripts/image_signing/gbb_flags_common.sh
@@ -49,65 +49,3 @@ FLAGS_HELP="Manages Chrome OS Firmware GBB Flags value.
Usage: $0 [option_flags] GBB_FLAGS_VALUE
${GBBFLAGS_DESCRIPTION}"
-
-flashrom_read() {
- local file="$1"
- local programmer="$2"
- flashrom -p "${programmer}" -i GBB -i FMAP -r "${file}"
-}
-
-flashrom_write() {
- local file="$1"
- local programmer="$2"
- flashrom -p "${programmer}" -i GBB --noverify-all -w "${file}"
-}
-
-CPU_FW_SPI="${FLAGS_FALSE}"
-
-enable_cpu_fw_spi() {
- dut-control cpu_fw_spi:on >/dev/null
- CPU_FW_SPI="${FLAGS_TRUE}"
-}
-
-maybe_disable_cpu_fw_spi() {
- if [ "${CPU_FW_SPI}" = "${FLAGS_TRUE}" ]; then
- dut-control cpu_fw_spi:off >/dev/null
- fi
- cleanup_temps_and_mounts
-}
-
-# This overrides the trap set in common_minimal.
-trap "maybe_disable_cpu_fw_spi" EXIT
-
-update_programmer_for_servo() {
- local servo_type
- local serial
- servo_type=$(dut-control -o servo_type 2>/dev/null) || \
- die "Failed to get servo information. Is servod running?"
- case "${servo_type}" in
- *with_servo_micro*)
- serial=$(dut-control -o servo_micro_serialname 2>/dev/null)
- ;;
- *with_c2d2*)
- serial=$(dut-control -o c2d2_serialname 2>/dev/null)
- ;;
- *with_ccd*)
- serial=$(dut-control -o ccd_serialname 2>/dev/null)
- ;;
- *)
- serial=$(dut-control -o serialname 2>/dev/null)
- ;;
- esac
- case "${servo_type}" in
- *servo_micro*|*c2d2*)
- programmer="raiden_debug_spi:serial=${serial}"
- enable_cpu_fw_spi
- ;;
- *ccd_ti50*|*ccd_cr50*|*ccd_gsc*)
- programmer="raiden_debug_spi:target=AP,serial=${serial}"
- ;;
- *)
- die "Unsupported servo type ${servo_type}"
- ;;
- esac
-}
diff --git a/scripts/image_signing/get_gbb_flags.sh b/scripts/image_signing/get_gbb_flags.sh
index b3d2c44d..2d00713c 100755
--- a/scripts/image_signing/get_gbb_flags.sh
+++ b/scripts/image_signing/get_gbb_flags.sh
@@ -4,8 +4,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
-# This script can change GBB flags in system live firmware or a given image
-# file.
+# This script can read GBB flags from system flash or a file.
+# This script calls `futility gbb --get`, consider using that directly.
SCRIPT_BASE="$(dirname "$0")"
. "${SCRIPT_BASE}/gbb_flags_common.sh"
@@ -26,30 +26,28 @@ main() {
echo 'NOTICE: This script has been replaced with futility functionality and will be removed.' 1>&2
echo 'NOTICE: Please try `futility gbb --get --flags`' 1>&2
- local image_file="${FLAGS_file}"
- local programmer="${FLAGS_programmer}"
-
- if [ -z "${FLAGS_file}" ]; then
- image_file="$(make_temp_file)"
- if [ "${FLAGS_servo}" = "${FLAGS_TRUE}" ]; then
- update_programmer_for_servo
- fi
- flashrom_read "${image_file}" "${programmer}"
+ local args=()
+ if [ -n "${FLAGS_file}" ]; then
+ args+=("${FLAGS_file}")
+ elif [ "${FLAGS_servo}" = "${FLAGS_TRUE}" ]; then
+ args+=("--servo")
+ else
+ args+=("--flash" "--programmer=${FLAGS_programmer}")
fi
- # Process file.
-
# Keep 'local' declaration split from assignment so return code is checked.
local gbb_flags
- gbb_flags="$(futility gbb -g --flags "${image_file}")"
- local raw_gbb_flags="$(echo "${gbb_flags}" | egrep -o "0x[0-9a-fA-F]+")"
- printf "Chrome OS GBB set ${gbb_flags}\n"
+ gbb_flags="$(futility gbb --get --flags "${args[@]}" | grep "flags: ")"
+
+ local raw_gbb_flags
+ raw_gbb_flags="$(echo "${gbb_flags}" | grep -E -o "0x[0-9a-fA-F]+")"
+ printf "Chrome OS GBB set %s\n" "${gbb_flags}"
if [ "${FLAGS_explicit}" = "${FLAGS_TRUE}" ]; then
printf "Chrome OS GBB set flags listed:\n"
echo "${GBBFLAGS_LIST}" | while read -r flag code; do
if [ $((code & raw_gbb_flags)) -ne 0 ]; then
- printf "${flag}\n"
+ printf "%s\n" "${flag}"
fi
done
fi
diff --git a/scripts/image_signing/set_gbb_flags.sh b/scripts/image_signing/set_gbb_flags.sh
index b9632314..e44158d1 100755
--- a/scripts/image_signing/set_gbb_flags.sh
+++ b/scripts/image_signing/set_gbb_flags.sh
@@ -1,11 +1,11 @@
-#!/bin/sh
+#!/bin/bash
#
# Copyright 2012 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
-# This script can change GBB flags in system live firmware or a given image
-# file.
+# This script can change GBB flags in system flash or a file.
+# This script calls `futility gbb --set`, consider using that directly.
SCRIPT_BASE="$(dirname "$0")"
. "${SCRIPT_BASE}/gbb_flags_common.sh"
@@ -51,36 +51,30 @@ main() {
echo 'NOTICE: Please try `futility gbb --set --flags=`' 1>&2
local value="$(($1))"
- local image_file="${FLAGS_file}"
- local programmer="${FLAGS_programmer}"
- if [ -z "${FLAGS_file}" ]; then
- image_file="$(make_temp_file)"
- if [ "${FLAGS_servo}" = "${FLAGS_TRUE}" ]; then
- update_programmer_for_servo
- fi
-
- flashrom_read "${image_file}" "${programmer}"
- fi
-
- # Process file
- # Keep 'local' declaration split from assignment so return code is checked.
- local old_value
- old_value="$(futility gbb -g --flags "${image_file}")"
- printf "Setting GBB flags from %s to %#x.." "${old_value}" "${value}"
- futility gbb -s --flags="${value}" "${image_file}"
-
- if [ -z "${FLAGS_file}" ]; then
+ local args=()
+ if [ -n "${FLAGS_file}" ]; then
+ args+=("${FLAGS_file}")
+ elif [ "${FLAGS_servo}" = "${FLAGS_TRUE}" ]; then
+ args+=("--servo")
+ else
+ args+=("--flash" "--programmer=${FLAGS_programmer}")
if [ "${FLAGS_check_wp}" = "${FLAGS_TRUE}" ]; then
- if ! check_write_protection "${programmer}"; then
+ if ! check_write_protection "${FLAGS_programmer}"; then
echo ""
echo "WARNING: System GBB Flags are NOT changed!!!"
echo "ERROR: You must disable write protection before setting flags."
exit 1
fi
fi
- flashrom_write "${image_file}" "${programmer}"
fi
+
+ # Process file
+ # Keep 'local' declaration split from assignment so return code is checked.
+ local old_value
+ old_value="$(futility gbb --get --flags "${args[@]}" | grep "flags: ")"
+ printf "Setting GBB flags from %s to %#x\n" "${old_value}" "${value}"
+ futility gbb --set --flags="${value}" "${args[@]}"
}
# Parse command line