| OLD | NEW |
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 | 2 |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 # This script modifies a base image to act as a recovery installer. | 7 # This script modifies a base image to act as a recovery installer. |
| 8 # If no kernel image is supplied, it will build a devkeys signed recovery | 8 # If no kernel image is supplied, it will build a devkeys signed recovery |
| 9 # kernel. Alternatively, a signed recovery kernel can be used to | 9 # kernel. Alternatively, a signed recovery kernel can be used to |
| 10 # create a Chromium OS recovery image. | 10 # create a Chromium OS recovery image. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 DEFINE_string rootfs_hash "/tmp/rootfs.hash" \ | 74 DEFINE_string rootfs_hash "/tmp/rootfs.hash" \ |
| 75 "Path where the rootfs hash should be stored." | 75 "Path where the rootfs hash should be stored." |
| 76 | 76 |
| 77 DEFINE_boolean verbose $FLAGS_FALSE \ | 77 DEFINE_boolean verbose $FLAGS_FALSE \ |
| 78 "Log all commands to stdout." v | 78 "Log all commands to stdout." v |
| 79 | 79 |
| 80 # Keep in sync with build_image. | 80 # Keep in sync with build_image. |
| 81 DEFINE_string keys_dir "/usr/share/vboot/devkeys" \ | 81 DEFINE_string keys_dir "/usr/share/vboot/devkeys" \ |
| 82 "Directory containing the signing keys." | 82 "Directory containing the signing keys." |
| 83 | 83 |
| 84 # TODO(clchiou): Remove this flag after arm verified boot is stable |
| 85 DEFINE_boolean crosbug12352_arm_kernel_signing ${FLAGS_FALSE} \ |
| 86 "Sign kernel partition for ARM images (temporary hack)." |
| 87 |
| 84 # Parse command line | 88 # Parse command line |
| 85 FLAGS "$@" || exit 1 | 89 FLAGS "$@" || exit 1 |
| 86 eval set -- "${FLAGS_ARGV}" | 90 eval set -- "${FLAGS_ARGV}" |
| 87 | 91 |
| 88 if [ $FLAGS_verbose -eq $FLAGS_FALSE ]; then | 92 if [ $FLAGS_verbose -eq $FLAGS_FALSE ]; then |
| 89 exec 2>/dev/null | 93 exec 2>/dev/null |
| 90 # Redirecting to stdout instead of stderr since | 94 # Redirecting to stdout instead of stderr since |
| 91 # we silence stderr above. | 95 # we silence stderr above. |
| 92 die() { | 96 die() { |
| 93 echo -e "${V_BOLD_RED}ERROR : $1${V_VIDOFF}" | 97 echo -e "${V_BOLD_RED}ERROR : $1${V_VIDOFF}" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 error "ARM recovery mode is still in the works. Use a normal image for now." | 136 error "ARM recovery mode is still in the works. Use a normal image for now." |
| 133 ;; | 137 ;; |
| 134 *86) | 138 *86) |
| 135 ARCH="x86" | 139 ARCH="x86" |
| 136 ;; | 140 ;; |
| 137 *) | 141 *) |
| 138 error "Unable to determine ARCH from toolchain: ${CHOST}" | 142 error "Unable to determine ARCH from toolchain: ${CHOST}" |
| 139 exit 1 | 143 exit 1 |
| 140 esac | 144 esac |
| 141 | 145 |
| 146 if [[ ${FLAGS_crosbug12352_arm_kernel_signing} -eq ${FLAGS_TRUE} ]]; then |
| 147 crosbug12352_flag="--crosbug12352_arm_kernel_signing" |
| 148 else |
| 149 crosbug12352_flag="--nocrosbug12352_arm_kernel_signing" |
| 150 fi |
| 151 |
| 142 get_install_vblock() { | 152 get_install_vblock() { |
| 143 # If it exists, we need to copy the vblock over to stateful | 153 # If it exists, we need to copy the vblock over to stateful |
| 144 # This is the real vblock and not the recovery vblock. | 154 # This is the real vblock and not the recovery vblock. |
| 145 local stateful_offset=$(partoffset "$FLAGS_image" 1) | 155 local stateful_offset=$(partoffset "$FLAGS_image" 1) |
| 146 local stateful_mnt=$(mktemp -d) | 156 local stateful_mnt=$(mktemp -d) |
| 147 local out=$(mktemp) | 157 local out=$(mktemp) |
| 148 | 158 |
| 149 set +e | 159 set +e |
| 150 sudo mount -o ro,loop,offset=$((stateful_offset * 512)) \ | 160 sudo mount -o ro,loop,offset=$((stateful_offset * 512)) \ |
| 151 "$FLAGS_image" $stateful_mnt | 161 "$FLAGS_image" $stateful_mnt |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 --hd_vblock="$RECOVERY_KERNEL_VBLOCK" \ | 242 --hd_vblock="$RECOVERY_KERNEL_VBLOCK" \ |
| 233 --vmlinuz="$vmlinuz" \ | 243 --vmlinuz="$vmlinuz" \ |
| 234 --working_dir="${IMAGE_DIR}" \ | 244 --working_dir="${IMAGE_DIR}" \ |
| 235 --boot_args="panic=60 cros_recovery kern_b_hash=$kern_hash" \ | 245 --boot_args="panic=60 cros_recovery kern_b_hash=$kern_hash" \ |
| 236 --keep_work \ | 246 --keep_work \ |
| 237 --rootfs_image=${root_dev} \ | 247 --rootfs_image=${root_dev} \ |
| 238 --rootfs_hash=${FLAGS_rootfs_hash} \ | 248 --rootfs_hash=${FLAGS_rootfs_hash} \ |
| 239 --root=${cros_root} \ | 249 --root=${cros_root} \ |
| 240 --keys_dir="${FLAGS_keys_dir}" \ | 250 --keys_dir="${FLAGS_keys_dir}" \ |
| 241 --nouse_dev_keys \ | 251 --nouse_dev_keys \ |
| 252 ${crosbug12352_flag} \ |
| 242 ${verity_args} 1>&2 | 253 ${verity_args} 1>&2 |
| 243 sudo rm "$FLAGS_rootfs_hash" | 254 sudo rm "$FLAGS_rootfs_hash" |
| 244 sudo losetup -d "$root_dev" | 255 sudo losetup -d "$root_dev" |
| 245 trap - RETURN | 256 trap - RETURN |
| 246 | 257 |
| 247 # Update the EFI System Partition configuration so that the kern_hash check | 258 # Update the EFI System Partition configuration so that the kern_hash check |
| 248 # passes. | 259 # passes. |
| 249 local efi_dev=$(sudo losetup -f) | 260 local efi_dev=$(sudo losetup -f) |
| 250 local efi_offset=$(partoffset "$FLAGS_image" 12) | 261 local efi_offset=$(partoffset "$FLAGS_image" 12) |
| 251 local efi_size=$(partsize "$FLAGS_image" 12) | 262 local efi_size=$(partsize "$FLAGS_image" 12) |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 | 449 |
| 439 trap cleanup EXIT | 450 trap cleanup EXIT |
| 440 | 451 |
| 441 maybe_resize_stateful # Also copies the image if needed. | 452 maybe_resize_stateful # Also copies the image if needed. |
| 442 | 453 |
| 443 install_recovery_kernel | 454 install_recovery_kernel |
| 444 | 455 |
| 445 echo "Recovery image created at $RECOVERY_IMAGE" | 456 echo "Recovery image created at $RECOVERY_IMAGE" |
| 446 print_time_elapsed | 457 print_time_elapsed |
| 447 trap - EXIT | 458 trap - EXIT |
| OLD | NEW |