Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1004)

Unified Diff: scripts/image_signing/convert_recovery_to_full_ssd.sh

Issue 6909005: Add script to convert a recovery image to a factory-usable SSD image (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git@master
Patch Set: Fix ws Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scripts/image_signing/convert_recovery_to_full_ssd.sh
diff --git a/scripts/image_signing/convert_recovery_to_full_ssd.sh b/scripts/image_signing/convert_recovery_to_full_ssd.sh
new file mode 100755
index 0000000000000000000000000000000000000000..1c5b6811f6ee22dcc042ffff05703c8a70285e64
--- /dev/null
+++ b/scripts/image_signing/convert_recovery_to_full_ssd.sh
@@ -0,0 +1,75 @@
+#!/bin/bash
+
+# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Script to convert a recovery image into an SSD image usable by factory.
+
+# TODO(gauravsh): crosbug.com/14790 (Merge this with
+# convert_recovery_to_ssd.sh)
+
+# Load common constants and variables.
+. "$(dirname "$0")/common_minimal.sh"
+
+usage() {
+ cat <<EOF
+Usage: $PROG <signed_recovery_image> <original_image_zip> <output_ssd_image>
+
+Converts <signed_recovery_image> into a full SSD image usable by factory. Uses
+stateful partition from SSD image <original_image_zip>.
+EOF
+}
+
+if [ $# -ne 3 ]; then
+ usage
+ exit 1
+fi
+
+type -P cgpt &>/dev/null ||
+ { echo "cgpt tool must be in the path"; exit 1; }
+
+# Abort on errors.
+set -e
+
+RECOVERY_IMAGE=$1
+IMAGE_ZIP=$2
+SSD_IMAGE=$3
+
+work_dir=$(make_temp_dir)
+
+echo "Extracting original SSD image."
+unzip -o $IMAGE_ZIP chromiumos_base_image.bin -d ${work_dir}
+
+mv ${work_dir}/chromiumos_base_image.bin ${SSD_IMAGE}
+
+kerna_offset=$(partoffset ${RECOVERY_IMAGE} 2)
+kernb_offset=$(partoffset ${RECOVERY_IMAGE} 4)
+# Kernel partition sizes should be the same.
+kern_size=$(partsize ${RECOVERY_IMAGE} 2)
+
+rootfs=$(make_temp_file)
+echo "Replacing RootFS on the SSD with that of the RECOVERY image"
+extract_image_partition ${RECOVERY_IMAGE} 3 ${rootfs}
+replace_image_partition ${SSD_IMAGE} 3 ${rootfs}
+
+kerna=$(make_temp_file)
+echo "Replacing KernelA on the SSD with that of the RECOVERY image"
+extract_image_partition ${RECOVERY_IMAGE} 4 ${kerna}
+replace_image_partition ${SSD_IMAGE} 2 ${kerna}
+
+# Overwrite the kernel vblock on the created SSD image.
+stateful_dir=$(make_temp_dir)
+tmp_vblock=$(make_temp_file)
+mount_image_partition_ro ${RECOVERY_IMAGE} 1 ${stateful_dir}
+sudo cp ${stateful_dir}/vmlinuz_hd.vblock ${tmp_vblock}
+echo "Overwriting kernel vblock with SSD kernel vblock"
+sudo dd if=${tmp_vblock} of=${SSD_IMAGE} seek=${kerna_offset} bs=512 \
+ conv=notrunc
+sudo umount -d ${stateful_dir}
+
+# Zero out Kernel B partition.
+echo "Zeroing out Kernel partition B"
+sudo dd if=/dev/zero of=${SSD_IMAGE} seek=${kernb_offset} bs=512 \
+ count=${kern_size} conv=notrunc
+echo "${RECOVERY_IMAGE} was converted to a factory SSD image: ${SSD_IMAGE}"
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698