summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorGaurav Shah <gauravsh@chromium.org>2011-02-23 16:35:42 -0800
committerGaurav Shah <gauravsh@chromium.org>2011-02-23 16:35:42 -0800
commite77bec95d57ad8937e005ec7ebf183c925e656d9 (patch)
tree6c807947ea33db7b387d4c0f6a5f4d111004f31e /scripts
parentb47ed5a8fb6aed29fdb2830300c25ca5862a25ec (diff)
downloadvboot-e77bec95d57ad8937e005ec7ebf183c925e656d9.tar.gz
Add script to in-place modify a recovery image to ssd
Change-Id: I6435a4b0f40a571f8e44830e6d32f42d2d3213ff BUG=none TEST=manually tested with a signed image and comparing the kernel, and rootfs partitions. Review URL: http://codereview.chromium.org/6533015
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/image_signing/convert_recovery_to_ssd.sh68
-rwxr-xr-xscripts/image_signing/sign_official_build.sh2
2 files changed, 70 insertions, 0 deletions
diff --git a/scripts/image_signing/convert_recovery_to_ssd.sh b/scripts/image_signing/convert_recovery_to_ssd.sh
new file mode 100755
index 00000000..9b078afe
--- /dev/null
+++ b/scripts/image_signing/convert_recovery_to_ssd.sh
@@ -0,0 +1,68 @@
+#!/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. Changes are made in-
+# place.
+
+# Load common constants and variables.
+. "$(dirname "$0")/common_minimal.sh"
+
+usage() {
+ cat <<EOF
+Usage: $PROG <image> [--force]
+
+In-place converts recovery <image> into an SSD image. With --force, does not ask for
+confirmation from the user.
+
+EOF
+}
+
+if [ $# -gt 2 ]; 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
+
+IMAGE=$1
+IS_FORCE=$2
+
+if [ "${IS_FORCE}" != "--force" ]; then
+ echo "This will modify ${IMAGE} in-place and convert it into an SSD image."
+ read -p "Are you sure you want to continue (y/N)?" SURE
+ SURE="${SURE:0:1}"
+ [ "${SURE}" != "y" ] && exit 1
+fi
+
+kerna_offset=$(partoffset ${IMAGE} 2)
+kernb_offset=$(partoffset ${IMAGE} 4)
+# Kernel partition sizes should be the same.
+kern_size=$(partsize ${IMAGE} 2)
+
+# Move Kernel B to Kernel A.
+kernb=$(make_temp_file)
+echo "Replacing Kernel partition A with Kernel partition B"
+extract_image_partition ${IMAGE} 4 ${kernb}
+replace_image_partition ${IMAGE} 2 ${kernb}
+
+# Overwrite the vblock.
+stateful_dir=$(make_temp_dir)
+tmp_vblock=$(make_temp_file)
+mount_image_partition_ro ${IMAGE} 1 ${stateful_dir}
+sudo cp ${stateful_dir}/vmlinuz_hd.vblock ${tmp_vblock}
+# Unmount before overwriting image to avoid sync issues.
+sudo umount -d ${stateful_dir}
+echo "Overwriting kernel partition A vblock with SSD vblock"
+sudo dd if=${tmp_vblock} of=${IMAGE} seek=${kerna_offset} bs=512 conv=notrunc
+
+# Zero out Kernel B partition.
+echo "Zeroing out Kernel partition B"
+sudo dd if=/dev/zero of=${IMAGE} seek=${kernb_offset} bs=512 count=${kern_size} conv=notrunc
+echo "${IMAGE} was converted to an SSD image."
diff --git a/scripts/image_signing/sign_official_build.sh b/scripts/image_signing/sign_official_build.sh
index 3737d943..da9db062 100755
--- a/scripts/image_signing/sign_official_build.sh
+++ b/scripts/image_signing/sign_official_build.sh
@@ -412,6 +412,8 @@ sign_for_recovery() {
# TODO(gauravsh): Remove this if we get rid of the need to overwrite
# the vblock during installs. Kern B could directly be signed by the
# SSD keys.
+ # Note: This vblock is also needed for the ability to convert a recovery
+ # image into the equivalent SSD image (convert_recovery_to_ssd.sh)
local stateful_dir=$(make_temp_dir)
mount_image_partition ${OUTPUT_IMAGE} 1 ${stateful_dir}
sudo cp ${temp_out_vb} ${stateful_dir}/vmlinuz_hd.vblock