| OLD | NEW |
| (Empty) | |
| 1 #!/bin/bash |
| 2 |
| 3 # Copyright (c) 2011 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 convert a recovery image into an SSD image usable by factory. |
| 8 |
| 9 # TODO(gauravsh): crosbug.com/14790 (Merge this with |
| 10 # convert_recovery_to_ssd.sh) |
| 11 |
| 12 # Load common constants and variables. |
| 13 . "$(dirname "$0")/common_minimal.sh" |
| 14 |
| 15 usage() { |
| 16 cat <<EOF |
| 17 Usage: $PROG <signed_recovery_image> <original_image_zip> <output_ssd_image> |
| 18 |
| 19 Converts <signed_recovery_image> into a full SSD image usable by factory. Uses |
| 20 stateful partition from SSD image <original_image_zip>. |
| 21 EOF |
| 22 } |
| 23 |
| 24 if [ $# -ne 3 ]; then |
| 25 usage |
| 26 exit 1 |
| 27 fi |
| 28 |
| 29 type -P cgpt &>/dev/null || |
| 30 { echo "cgpt tool must be in the path"; exit 1; } |
| 31 |
| 32 # Abort on errors. |
| 33 set -e |
| 34 |
| 35 RECOVERY_IMAGE=$1 |
| 36 IMAGE_ZIP=$2 |
| 37 SSD_IMAGE=$3 |
| 38 |
| 39 work_dir=$(make_temp_dir) |
| 40 |
| 41 echo "Extracting original SSD image." |
| 42 unzip -o $IMAGE_ZIP chromiumos_base_image.bin -d ${work_dir} |
| 43 |
| 44 mv ${work_dir}/chromiumos_base_image.bin ${SSD_IMAGE} |
| 45 |
| 46 kerna_offset=$(partoffset ${RECOVERY_IMAGE} 2) |
| 47 kernb_offset=$(partoffset ${RECOVERY_IMAGE} 4) |
| 48 # Kernel partition sizes should be the same. |
| 49 kern_size=$(partsize ${RECOVERY_IMAGE} 2) |
| 50 |
| 51 rootfs=$(make_temp_file) |
| 52 echo "Replacing RootFS on the SSD with that of the RECOVERY image" |
| 53 extract_image_partition ${RECOVERY_IMAGE} 3 ${rootfs} |
| 54 replace_image_partition ${SSD_IMAGE} 3 ${rootfs} |
| 55 |
| 56 kerna=$(make_temp_file) |
| 57 echo "Replacing KernelA on the SSD with that of the RECOVERY image" |
| 58 extract_image_partition ${RECOVERY_IMAGE} 4 ${kerna} |
| 59 replace_image_partition ${SSD_IMAGE} 2 ${kerna} |
| 60 |
| 61 # Overwrite the kernel vblock on the created SSD image. |
| 62 stateful_dir=$(make_temp_dir) |
| 63 tmp_vblock=$(make_temp_file) |
| 64 mount_image_partition_ro ${RECOVERY_IMAGE} 1 ${stateful_dir} |
| 65 sudo cp ${stateful_dir}/vmlinuz_hd.vblock ${tmp_vblock} |
| 66 echo "Overwriting kernel vblock with SSD kernel vblock" |
| 67 sudo dd if=${tmp_vblock} of=${SSD_IMAGE} seek=${kerna_offset} bs=512 \ |
| 68 conv=notrunc |
| 69 sudo umount -d ${stateful_dir} |
| 70 |
| 71 # Zero out Kernel B partition. |
| 72 echo "Zeroing out Kernel partition B" |
| 73 sudo dd if=/dev/zero of=${SSD_IMAGE} seek=${kernb_offset} bs=512 \ |
| 74 count=${kern_size} conv=notrunc |
| 75 echo "${RECOVERY_IMAGE} was converted to a factory SSD image: ${SSD_IMAGE}" |
| OLD | NEW |