mod_image_for_recovery.sh: some cleanup.

Motivated by the need to share the default recovery image name across
scripts (image_to_usb.sh in this case) and have it setup in common.sh.
Includes some general cleanup steps such flags and usage strings,
migrating function definitions to the beginning of the script, etc.

BUG=chromium-os:26010
TEST=Tested mod_image_for_recovery.sh on local host.

Change-Id: Ife3731915302a2e7be8beb750501d0ae9a0c43a4
Reviewed-on: https://gerrit.chromium.org/gerrit/15523
Reviewed-by: Richard Barnette <jrbarnette@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
Commit-Ready: Gilad Arnold <garnold@chromium.org>
This commit is contained in:
Gilad Arnold 2012-02-08 12:24:39 -08:00 committed by Gerrit
parent 083662748f
commit 4ac8731001

View File

@ -12,41 +12,39 @@
SCRIPT_ROOT=$(dirname "$0") SCRIPT_ROOT=$(dirname "$0")
. "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1 . "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1
# Default recovery kernel name.
RECOVERY_KERNEL_NAME=recovery_vmlinuz.image
DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" b DEFINE_string board "$DEFAULT_BOARD" \
"board for which the image was built" \
b
DEFINE_integer statefulfs_sectors 4096 \ DEFINE_integer statefulfs_sectors 4096 \
"Number of sectors to use for the stateful filesystem when minimizing" "number of sectors in stateful filesystem when minimizing"
# Skips the build steps and just does the kernel swap.
DEFINE_string kernel_image "" \ DEFINE_string kernel_image "" \
"Path to a pre-built recovery kernel" "path to a pre-built recovery kernel"
DEFINE_string kernel_outfile "" \ DEFINE_string kernel_outfile "" \
"Filename and path to emit the kernel outfile to. \ "emit recovery kernel to path/file ($RECOVERY_KERNEL_NAME if empty)"
If empty, emits to IMAGE_DIR." DEFINE_string image "" \
DEFINE_string image "" "Path to the image to use" "source image to use ($CHROMEOS_IMAGE_NAME if empty)"
DEFINE_string to "" \ DEFINE_string to "" \
"Path to the image to create. If empty, defaults to \ "emit recovery image to path/file ($CHROMEOS_RECOVERY_IMAGE_NAME if empty)"
IMAGE_DIR/recovery_image.bin."
DEFINE_boolean kernel_image_only $FLAGS_FALSE \ DEFINE_boolean kernel_image_only $FLAGS_FALSE \
"Emit the recovery kernel image only" "only emit recovery kernel"
DEFINE_boolean sync_keys $FLAGS_TRUE \ DEFINE_boolean sync_keys $FLAGS_TRUE \
"Update the kernel to be installed with the vblock from stateful" "update install kernel with the vblock from stateful"
DEFINE_boolean minimize_image $FLAGS_TRUE \ DEFINE_boolean minimize_image $FLAGS_TRUE \
"Decides if the original image is used or a minimal recovery image is \ "create a minimized recovery image from source image"
created."
DEFINE_boolean modify_in_place $FLAGS_FALSE \ DEFINE_boolean modify_in_place $FLAGS_FALSE \
"Modifies the source image in place. This cannot be used with \ "modify source image in place"
--minimize_image."
DEFINE_integer jobs -1 \ DEFINE_integer jobs -1 \
"How many packages to build in parallel at maximum." j "how many packages to build in parallel at maximum" \
j
DEFINE_string build_root "/build" \ DEFINE_string build_root "/build" \
"The root location for board sysroots." "root location for board sysroots"
DEFINE_boolean verbose $FLAGS_FALSE \
"Log all commands to stdout." v
# Keep in sync with build_image.
DEFINE_string keys_dir "/usr/share/vboot/devkeys" \ DEFINE_string keys_dir "/usr/share/vboot/devkeys" \
"Directory containing the signing keys." "directory containing the signing keys"
DEFINE_boolean verbose $FLAGS_FALSE \
"log all commands to stdout" v
# Parse command line # Parse command line
FLAGS "$@" || exit 1 FLAGS "$@" || exit 1
@ -61,26 +59,10 @@ if [ $FLAGS_verbose -eq $FLAGS_TRUE ]; then
set -x set -x
fi fi
# Load board options.
. "${SCRIPT_ROOT}/build_library/board_options.sh" || exit 1 . "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1
EMERGE_BOARD_CMD="emerge-$BOARD" EMERGE_BOARD_CMD="emerge-$BOARD"
# No image was provided. Use the standard latest image
if [ -z "$FLAGS_image" ]; then
IMAGES_DIR="$($SCRIPT_ROOT/get_latest_image.sh --board=$BOARD)"
FLAGS_image="$IMAGES_DIR/$CHROMEOS_IMAGE_NAME"
fi
# Turn path into an absolute path.
FLAGS_image=$(eval readlink -f "$FLAGS_image")
# Abort early if we can't find the image
if [ ! -f "$FLAGS_image" ]; then
echo "No image found at $FLAGS_image"
exit 1
fi
get_install_vblock() { get_install_vblock() {
# If it exists, we need to copy the vblock over to stateful # If it exists, we need to copy the vblock over to stateful
@ -361,14 +343,29 @@ cleanup() {
rm "$INSTALL_VBLOCK" rm "$INSTALL_VBLOCK"
} }
# main process begins here.
# Main process begins here.
set -u set -u
# No image was provided, use standard latest image path.
if [ -z "$FLAGS_image" ]; then
DEFAULT_IMAGE_DIR="$($SCRIPT_ROOT/get_latest_image.sh --board=$BOARD)"
FLAGS_image="$DEFAULT_IMAGE_DIR/$CHROMEOS_IMAGE_NAME"
fi
# Turn path into an absolute path.
FLAGS_image=$(readlink -f "$FLAGS_image")
# Abort early if we can't find the image.
if [ ! -f "$FLAGS_image" ]; then
die "Image not found: $FLAGS_image"
fi
IMAGE_DIR="$(dirname "$FLAGS_image")" IMAGE_DIR="$(dirname "$FLAGS_image")"
IMAGE_NAME="$(basename "$FLAGS_image")" IMAGE_NAME="$(basename "$FLAGS_image")"
RECOVERY_IMAGE="${FLAGS_to:-$IMAGE_DIR/recovery_image.bin}" RECOVERY_IMAGE="${FLAGS_to:-$IMAGE_DIR/$CHROMEOS_RECOVERY_IMAGE_NAME}"
RECOVERY_KERNEL_IMAGE=\ RECOVERY_KERNEL_IMAGE=\
"${FLAGS_kernel_outfile:-${IMAGE_DIR}/recovery_vmlinuz.image}" "${FLAGS_kernel_outfile:-$IMAGE_DIR/$RECOVERY_KERNEL_NAME}"
RECOVERY_KERNEL_VBLOCK="${RECOVERY_KERNEL_IMAGE}.vblock" RECOVERY_KERNEL_VBLOCK="${RECOVERY_KERNEL_IMAGE}.vblock"
STATEFUL_DIR="$IMAGE_DIR/stateful_partition" STATEFUL_DIR="$IMAGE_DIR/stateful_partition"
SCRIPTS_DIR=${SCRIPT_ROOT} SCRIPTS_DIR=${SCRIPT_ROOT}