From 493cbf8426dadae22ce9f486ecbc3cba0faad1f7 Mon Sep 17 00:00:00 2001 From: Chris Sosa Date: Mon, 15 Aug 2011 16:29:05 -0700 Subject: [PATCH] Add feature to extract kernel image from other recovery image for use in recovery. This CL adds a new option to mod_image_for_recovery that allows a dev to pass in another recovery image as an option and have mod_image_for_recovery use the kernel provided in that image when building a new recovery image. BUG=chromium-os:19189 TEST=Built using option on image signed with non-dev keys using appropriate recovery image as base. Change-Id: I02a3c3bf458fb3c9fee556364005d7eaff5acccc Reviewed-on: http://gerrit.chromium.org/gerrit/6031 Tested-by: Chris Sosa Reviewed-by: Gaurav Shah --- mod_image_for_recovery.sh | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/mod_image_for_recovery.sh b/mod_image_for_recovery.sh index a118a4bce0..1d7fcbef9c 100755 --- a/mod_image_for_recovery.sh +++ b/mod_image_for_recovery.sh @@ -19,6 +19,8 @@ DEFINE_integer statefulfs_sectors 4096 \ # Skips the build steps and just does the kernel swap. DEFINE_string kernel_image "" \ "Path to a pre-built recovery kernel" +DEFINE_string recovery_image_with_kernel "" \ + "Optional path to a recovery image with a pre-built kernel." DEFINE_string kernel_outfile "" \ "Filename and path to emit the kernel outfile to. \ If empty, emits to IMAGE_DIR." @@ -281,6 +283,21 @@ install_recovery_kernel() { return 0 } +# Extracts a kernel from an existing recovery image. +# $1 path to new kernel image. +# $2 path to recovery image. +extract_kernel_image() { + local kernel_path="$1" + local recovery_image="$2" + + local kern_a_offset=$(partoffset ${recovery_image} 2) + local kern_a_count=$(partsize ${recovery_image} 2) + + info "Extracing kernel image from $2" + dd if="$recovery_image" of="$kernel_path" bs=512 \ + skip=$kern_a_offset count=$kern_a_count +} + update_partition_table() { local src_img=$1 # source image local temp_state=$2 # stateful partition image @@ -413,7 +430,11 @@ FACTORY_ROOT="${BOARD_ROOT}/factory-root" USE="fbconsole initramfs" emerge_custom_kernel "$FACTORY_ROOT" || failboat "Cannot emerge custom kernel" -if [ -z "$FLAGS_kernel_image" ]; then +if [ -n "FLAGS_recovery_image_with_kernel" ]; then + RECOVERY_KERNEL_IMAGE="$(tempfile -p "extracted_kernel")" + extract_kernel_image "$RECOVERY_KERNEL_IMAGE" \ + "$FLAGS_recovery_image_with_kernel" +elif [ -z "$FLAGS_kernel_image" ]; then create_recovery_kernel_image echo "Recovery kernel created at $RECOVERY_KERNEL_IMAGE" else