OLD | NEW |
(Empty) | |
| 1 #!/bin/bash |
| 2 |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 |
| 7 # Script to modify a pristine/dev Chrome OS image to be used for recovery |
| 8 |
| 9 . "$(dirname "$0")/common.sh" |
| 10 |
| 11 # Script must be run inside the chroot. |
| 12 restart_in_chroot_if_needed $* |
| 13 |
| 14 DEFINE_string image_dir "" \ |
| 15 "Directory to pristine/base image." |
| 16 DEFINE_string image_name "chromiumos_image.bin" \ |
| 17 "Name of Chrome OS image to modify." |
| 18 |
| 19 # Parse command line |
| 20 FLAGS "$@" || exit 1 |
| 21 eval set -- "${FLAGS_ARGV}" |
| 22 |
| 23 set -e |
| 24 |
| 25 if [ -z $FLAGS_image_dir ] || [ ! -d $FLAGS_image_dir ]; then |
| 26 echo "Error: invalid flag --image_dir" |
| 27 exit 1 |
| 28 fi |
| 29 |
| 30 SRC_PATH="${FLAGS_image_dir}/${FLAGS_image_name}" |
| 31 if [ -z $FLAGS_image_name ] || [ ! -f $SRC_PATH ]; then |
| 32 echo "Error: invalid flag --image_name" |
| 33 exit 1 |
| 34 fi |
| 35 |
| 36 # Constants |
| 37 OUTPUT_DIR=$FLAGS_image_dir |
| 38 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" |
| 39 STATEFUL_FS_DIR="${OUTPUT_DIR}/stateful_partition" |
| 40 RECOVERY_IMAGE="recovery_image.bin" |
| 41 |
| 42 mount_gpt_cleanup() { |
| 43 "${SCRIPTS_DIR}/mount_gpt_image.sh" -u -r "$1" -s "$2" |
| 44 } |
| 45 |
| 46 # Modifies an existing image for recovery use |
| 47 update_recovery_packages() { |
| 48 local image_name=$1 |
| 49 local sector_size=512 # sector size in bytes |
| 50 local num_sectors_vb=128 # number of sectors in kernel verification blob |
| 51 # Start offset of kernel A (aligned to 4096-sector boundary) |
| 52 local start_kern_a=4096 |
| 53 local vb_file="${STATEFUL_FS_DIR}/verification_blob.kernel" |
| 54 |
| 55 echo "Modifying image ${image_name} for recovery use" |
| 56 |
| 57 trap "mount_gpt_cleanup \"${ROOT_FS_DIR}\" \"${STATEFUL_FS_DIR}\"" EXIT |
| 58 |
| 59 ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \ |
| 60 --image "$( basename ${image_name} )" -r "${ROOT_FS_DIR}" \ |
| 61 -s "${STATEFUL_FS_DIR}" |
| 62 |
| 63 # Mark the image as a recovery image (needed for recovery boot) |
| 64 sudo touch "${STATEFUL_FS_DIR}/.recovery" |
| 65 |
| 66 # Copy verification blob out of kernel A into stateful partition |
| 67 # so that we can restore it during recovery |
| 68 sudo touch $vb_file |
| 69 echo "Backing up kernel verification blob onto stateful partition ..." |
| 70 sudo dd if="$image_name" of="$vb_file" skip=$start_kern_a bs=$sector_size \ |
| 71 count=$num_sectors_vb conv=notrunc |
| 72 |
| 73 # Overwrite verification blob with recovery image verification blob |
| 74 # TODO(tgao): resign kernel for recovery image |
| 75 echo "Overwrite kernel verification blob with resigned blob for recovery..." |
| 76 sudo dd if=/dev/zero of="$image_name" seek=$start_kern_a bs=$sector_size \ |
| 77 count=$num_sectors_vb conv=notrunc |
| 78 |
| 79 trap - EXIT |
| 80 ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \ |
| 81 -s "${STATEFUL_FS_DIR}" |
| 82 } |
| 83 |
| 84 # Main |
| 85 |
| 86 DST_PATH="${OUTPUT_DIR}/${RECOVERY_IMAGE}" |
| 87 echo "Making a copy of original image ${SRC_PATH}" |
| 88 cp $SRC_PATH $DST_PATH |
| 89 update_recovery_packages $DST_PATH |
| 90 echo "Recovery image created at ${DST_PATH}" |
OLD | NEW |