summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@chromium.org>2017-05-18 11:43:05 -0400
committerMike Frysinger <vapier@chromium.org>2017-05-19 04:13:09 +0000
commit9d11bb1b1d0ca7503b195c1de4463f1d1e1ab4d2 (patch)
treef4d1dcc48b1d0bf18599520d2972570f11e90eaf
parentb660356d515473a81e424410ead2cdf566159406 (diff)
downloadvboot-9d11bb1b1d0ca7503b195c1de4463f1d1e1ab4d2.tar.gz
image_signing: unify output helpers
We have `err_die` and `die` helpers that do the same thing, but some scripts just have to know which one to use based on their runtime. Just unify them as the more common `die` so all scripts can use it. Similarly, we provide info, warn, and error to dev scripts, but not to the runtime ones. Add small stubs in common_minimal.sh so the API is consistent. BRANCH=None BUG=chromium:718184 TEST=scripts still work Change-Id: Id44fb27900c37f4e357d20817f909e4534d1c5b3 Reviewed-on: https://chromium-review.googlesource.com/507990 Tested-by: Mike Frysinger <vapier@chromium.org> Reviewed-by: David Riley <davidriley@chromium.org> Commit-Queue: Mike Frysinger <vapier@chromium.org>
-rw-r--r--scripts/image_signing/common.sh8
-rw-r--r--scripts/image_signing/common_minimal.sh18
-rwxr-xr-xscripts/image_signing/make_dev_firmware.sh22
-rwxr-xr-xscripts/image_signing/make_dev_ssd.sh26
-rwxr-xr-xscripts/image_signing/sign_firmware.sh2
-rwxr-xr-xscripts/image_signing/tofactory.sh12
6 files changed, 47 insertions, 41 deletions
diff --git a/scripts/image_signing/common.sh b/scripts/image_signing/common.sh
index 33328612..e816a88c 100644
--- a/scripts/image_signing/common.sh
+++ b/scripts/image_signing/common.sh
@@ -68,14 +68,6 @@ error() {
echo -e >&2 "${V_BOLD_RED}${CROS_LOG_PREFIX:-}ERROR : $1${V_VIDOFF}"
}
-# Prints an error message and exit with an error code.
-# Taken from src/scripts/common.sh.
-# Args: MESSAGE
-die() {
- error "$1"
- exit 1
-}
-
# Usage: lsbval path-to-lsb-file key
# Returns the value for the given lsb-release file variable.
lsbval() {
diff --git a/scripts/image_signing/common_minimal.sh b/scripts/image_signing/common_minimal.sh
index f50a3c0a..c130b918 100644
--- a/scripts/image_signing/common_minimal.sh
+++ b/scripts/image_signing/common_minimal.sh
@@ -38,10 +38,24 @@ load_shflags() {
# Functions for debug output
# ----------------------------------------------------------------------------
+# These helpers are for runtime systems. For scripts using common.sh,
+# they'll get better definitions that will clobber these ones.
+info() {
+ echo "${PROG}: INFO: $*" >&2
+}
+
+warn() {
+ echo "${PROG}: WARN: $*" >&2
+}
+
+error() {
+ echo "${PROG}: ERROR: $*" >&2
+}
+
# Reports error message and exit(1)
# Args: error message
-err_die() {
- echo "ERROR: $*" 1>&2
+die() {
+ error "$@"
exit 1
}
diff --git a/scripts/image_signing/make_dev_firmware.sh b/scripts/image_signing/make_dev_firmware.sh
index 7d9fa414..caf45e4e 100755
--- a/scripts/image_signing/make_dev_firmware.sh
+++ b/scripts/image_signing/make_dev_firmware.sh
@@ -147,15 +147,15 @@ main() {
debug_msg "Checking software write protection status"
disable_write_protection ||
if is_debug_mode; then
- err_die "Failed to disable WP. Diagnose Message: $(cat "$EXEC_LOG")"
+ die "Failed to disable WP. Diagnose Message: $(cat "${EXEC_LOG}")"
else
- err_die "Write protection is still enabled. " \
- "Please verify that hardware write protection is disabled."
+ die "Write protection is still enabled. " \
+ "Please verify that hardware write protection is disabled."
fi
debug_msg "Pulling image to $IMAGE"
(read_image && [ -s "$IMAGE" ]) ||
- err_die "Failed to read image. Error message: $(cat "$EXEC_LOG")"
+ die "Failed to read image. Error message: $(cat "${EXEC_LOG}")"
debug_msg "Prepare to backup the file"
if [ -n "$is_from_live" -o $FLAGS_force_backup = $FLAGS_TRUE ]; then
@@ -168,7 +168,7 @@ main() {
local expanded_firmware_dir="$(make_temp_dir)"
local use_devfw_keyblock="$FLAGS_FALSE"
(cd "$expanded_firmware_dir"; dump_fmap -x "$IMAGE" >/dev/null 2>&1) ||
- err_die "Failed to extract firmware image."
+ die "Failed to extract firmware image."
if [ -f "$expanded_firmware_dir/VBLOCK_A" ]; then
local has_dev=$FLAGS_TRUE has_norm=$FLAGS_TRUE
# In output of vbutil_keyblock, "!DEV" means "bootable on normal mode" and
@@ -211,7 +211,7 @@ main() {
--verify "$expanded_firmware_dir/VBLOCK_A" \
--signpubkey "$expanded_firmware_dir/rootkey" \
--fv "$expanded_firmware_dir/FW_MAIN_A")" 2>/dev/null ||
- err_die "Failed to verify firmware slot A."
+ die "Failed to verify firmware slot A."
data_key_version="$(
echo "$fw_info" | sed -n '/^ *Data key version:/s/.*:[ \t]*//p')"
firmware_version="$(
@@ -262,7 +262,7 @@ main() {
"$kernel_sub_pubkey" \
"$firmware_version" \
$optional_opts >"$EXEC_LOG" 2>&1 ||
- err_die "Failed to re-sign firmware. (message: $(cat "$EXEC_LOG"))"
+ die "Failed to re-sign firmware. (message: $(cat "${EXEC_LOG}"))"
if is_debug_mode; then
cat "$EXEC_LOG"
fi
@@ -274,7 +274,7 @@ main() {
debug_msg "Decide new HWID"
[ -z "$old_hwid" ] &&
- err_die "Cannot find current HWID. (message: $(cat "$EXEC_LOG"))"
+ die "Cannot find current HWID. (message: $(cat "${EXEC_LOG}"))"
local new_hwid="$old_hwid"
if [ "$FLAGS_mod_hwid" = "$FLAGS_TRUE" ]; then
new_hwid="$(echo_dev_hwid "$old_hwid")"
@@ -285,7 +285,7 @@ main() {
sed -rne 's/^flags: (.*)$/\1/p')"
debug_msg "Decide new GBB flags from: $old_gbb_flags"
[ -z "$old_gbb_flags" ] &&
- err_die "Cannot find GBB flags. (message: $(cat "$EXEC_LOG"))"
+ die "Cannot find GBB flags. (message: $(cat "${EXEC_LOG}"))"
# 0x30: GBB_FLAG_FORCE_DEV_BOOT_USB | GBB_FLAG_DISABLE_FW_ROLLBACK_CHECK
local new_gbb_flags="$((old_gbb_flags | 0x30))"
@@ -295,7 +295,7 @@ main() {
--rootkey="$root_pubkey" \
--recoverykey="$recovery_pubkey" \
"$IMAGE" >"$EXEC_LOG" 2>&1 ||
- err_die "Failed to change GBB Data. (message: $(cat "$EXEC_LOG"))"
+ die "Failed to change GBB Data. (message: $(cat "${EXEC_LOG}"))"
# Old firmware does not support GBB flags, so let's make it an exception.
if [ "$FLAGS_mod_gbb_flags" = "$FLAGS_TRUE" ]; then
@@ -344,7 +344,7 @@ main() {
debug_msg "Write the image"
write_image ||
- err_die "Failed to write image. Error message: $(cat "$EXEC_LOG")"
+ die "Failed to write image. Error message: $(cat "${EXEC_LOG}")"
debug_msg "Complete."
if [ -z "$FLAGS_to" ]; then
diff --git a/scripts/image_signing/make_dev_ssd.sh b/scripts/image_signing/make_dev_ssd.sh
index c57ee652..3f8c6b2e 100755
--- a/scripts/image_signing/make_dev_ssd.sh
+++ b/scripts/image_signing/make_dev_ssd.sh
@@ -95,7 +95,7 @@ mydd() {
# oflag=sync is safer, but since we need bs=512, syncing every block would be
# very slow.
dd "$@" >"$EXEC_LOG" 2>&1 ||
- err_die "Failed in [dd $@], Message: $(cat "$EXEC_LOG")"
+ die "Failed in [dd $*], Message: $(cat "${EXEC_LOG}")"
}
# Prints a more friendly name from kernel index number
@@ -154,9 +154,9 @@ resign_ssd_kernel() {
debug_msg "Probing $name information"
local offset size
offset="$(partoffset "$ssd_device" "$kernel_index")" ||
- err_die "Failed to get partition $kernel_index offset from $ssd_device"
+ die "Failed to get partition ${kernel_index} offset from ${ssd_device}"
size="$(partsize "$ssd_device" "$kernel_index")" ||
- err_die "Failed to get partition $kernel_index size from $ssd_device"
+ die "Failed to get partition ${kernel_index} size from ${ssd_device}"
if [ ! $size -gt $min_kernel_size ]; then
info "${name} seems too small (${size}), ignored."
continue
@@ -192,7 +192,7 @@ resign_ssd_kernel() {
local new_config_file
new_config_file="${FLAGS_set_config}.$kernel_index"
kernel_config="$(cat "$new_config_file")" ||
- err_die "Failed to read new kernel config from $new_config_file"
+ die "Failed to read new kernel config from ${new_config_file}"
debug_msg "New kernel config: $kernel_config)"
info "${name}: Replaced config from ${new_config_file}"
fi
@@ -213,7 +213,7 @@ resign_ssd_kernel() {
# editing in in console.
bash -c "read -e -i '${kernel_config}' &&
echo \"\${REPLY}\" >${new_config_file}" ||
- err_die "Failed to run editor. Please specify editor name by VISUAL."
+ die "Failed to run editor. Please specify editor name by VISUAL."
fi
kernel_config="$(cat "${new_config_file}")"
if [ "$(md5sum "${new_config_file}")" = "${old_md5sum}" ]; then
@@ -245,7 +245,7 @@ resign_ssd_kernel() {
--config "$new_kernel_config_file" \
--signprivate "$KERNEL_DATAKEY" \
--oldblob "$old_blob" >"$EXEC_LOG" 2>&1 ||
- err_die "Failed to resign $name. Message: $(cat "$EXEC_LOG")"
+ die "Failed to resign ${name}. Message: $(cat "${EXEC_LOG}")"
debug_msg "Creating new kernel image (vboot+code+config)"
local new_kern="$(make_temp_file)"
@@ -263,7 +263,7 @@ resign_ssd_kernel() {
vbutil_kernel \
--verify "$new_kern" \
--signpubkey "$KERNEL_PUBKEY" --verbose >"$EXEC_LOG" 2>&1 ||
- err_die "Failed to verify new $name. Message: $(cat "$EXEC_LOG")"
+ die "Failed to verify new ${name}. Message: $(cat "${EXEC_LOG}")"
debug_msg "Backup old kernel blob"
local backup_date_time="$(date +'%Y%m%d_%H%M%S')"
@@ -303,8 +303,8 @@ resign_ssd_kernel() {
# disable the RO ext2 hack
debug_msg "Disabling rootfs ext2 RO bit hack"
enable_rw_mount "$ssd_device" "$root_offset_bytes" >"$EXEC_LOG" 2>&1 ||
- err_die "Failed turning off rootfs RO bit. OS may be corrupted. " \
- "Message: $(cat "$EXEC_LOG")"
+ die "Failed turning off rootfs RO bit. OS may be corrupted. " \
+ "Message: $(cat "${EXEC_LOG}")"
fi
fi
@@ -459,7 +459,7 @@ main() {
debug_msg "check valid kernel partitions for live system"
local valid_partitions="$(find_valid_kernel_partitions $FLAGS_partitions)"
[ -n "$valid_partitions" ] ||
- err_die "No valid kernel partitions on $FLAGS_image ($FLAGS_partitions)."
+ die "No valid kernel partitions on ${FLAGS_image} (${FLAGS_partitions})."
FLAGS_partitions="$valid_partitions"
# Sanity checks
@@ -478,7 +478,7 @@ main() {
elif ! sanity_check_live_firmware ||
! sanity_check_live_partitions ||
! sanity_check_crossystem_flags; then
- err_die "IMAGE $FLAGS_image IS NOT MODIFIED."
+ die "IMAGE ${FLAGS_image} IS NOT MODIFIED."
fi
fi
@@ -490,7 +490,7 @@ main() {
info "Successfully re-signed ${num_signed} of ${num_given} kernel(s)" \
" on device ${FLAGS_image}."
else
- err_die "Failed re-signing kernels."
+ die "Failed re-signing kernels."
fi
}
@@ -498,7 +498,7 @@ main() {
# so adding parameter check is safer.
if [ "$#" -gt 0 ]; then
flags_help
- err_die "Unknown parameters: $@"
+ die "Unknown parameters: $*"
fi
main
diff --git a/scripts/image_signing/sign_firmware.sh b/scripts/image_signing/sign_firmware.sh
index 94614ba6..c6107196 100755
--- a/scripts/image_signing/sign_firmware.sh
+++ b/scripts/image_signing/sign_firmware.sh
@@ -116,7 +116,7 @@ main() {
if [[ -e ${key_dir}/loem.ini ]]; then
if [[ -z ${loem_output_dir} ]]; then
- err_die "need loem_output_dir w/loem keysets"
+ die "need loem_output_dir w/loem keysets"
fi
sign_loems
else
diff --git a/scripts/image_signing/tofactory.sh b/scripts/image_signing/tofactory.sh
index e972dca1..1871c384 100755
--- a/scripts/image_signing/tofactory.sh
+++ b/scripts/image_signing/tofactory.sh
@@ -121,8 +121,8 @@ EOF
main() {
# Make sure the files we were passed exist
- [ -n "$FLAGS_bios" ] || err_die "Please specify a BIOS file (-b bios.bin)"
- [ -n "$FLAGS_ec" ] || err_die "Please specify an EC updater (-e updater.sh)"
+ [ -n "$FLAGS_bios" ] || die "Please specify a BIOS file (-b bios.bin)"
+ [ -n "$FLAGS_ec" ] || die "Please specify an EC updater (-e updater.sh)"
ensure_files_exist "$FLAGS_bios" "$FLAGS_ec" || exit 1
# If --nothing was specified, keep flashrom from writing
@@ -158,7 +158,7 @@ main() {
debug_msg "Copying VPD from old firmware to new firmware"
cp "$FLAGS_bios" "$NEW_BIOS"
dd bs=1 seek=$vpd_offset skip=$vpd_offset count=$vpd_size conv=notrunc \
- if="$OLD_BIOS" of="$NEW_BIOS" || err_die "Unable to copy RO VPD"
+ if="$OLD_BIOS" of="$NEW_BIOS" || die "Unable to copy RO VPD"
# Disable write protect
disable_wp "EC" ${FLASHROM_EC}
@@ -167,14 +167,14 @@ main() {
# Write new firmware
debug_msg "Writing EC"
# TODO: if EC file ends in .bin, use flashrom to write it directly?
- $NOTHING sh "$FLAGS_ec" --factory || err_die "Unable to write EC"
+ $NOTHING sh "$FLAGS_ec" --factory || die "Unable to write EC"
debug_msg "Writing BIOS"
- $NOTHING ${FLASHROM_BIOS} -w "$NEW_BIOS" || err_die "Unable to write BIOS"
+ $NOTHING ${FLASHROM_BIOS} -w "$NEW_BIOS" || die "Unable to write BIOS"
# Wipe SSD
if [ "$FLAGS_wipe_ssd" = $FLAGS_TRUE ]; then
debug_msg "Wiping SSD"
- $NOTHING cgpt create -z "$FLAGS_ssd" || err_die "Unable to wipe SSD"
+ $NOTHING cgpt create -z "$FLAGS_ssd" || die "Unable to wipe SSD"
fi
# Leave the update engine stopped. We've mucked with the firmware