| OLD | NEW |
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 | 2 |
| 3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2009 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 # Script to build a bootable keyfob-based chromeos system image from within | 7 # Script to build a bootable keyfob-based chromeos system image from within |
| 8 # a chromiumos setup. This assumes that all needed packages have been built into | 8 # a chromiumos setup. This assumes that all needed packages have been built into |
| 9 # the given target's root with binary packages turned on. This script will | 9 # the given target's root with binary packages turned on. This script will |
| 10 # build the Chrome OS image using only pre-built binary packages. | 10 # build the Chrome OS image using only pre-built binary packages. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 "stateful filesystem size in MBs." | 55 "stateful filesystem size in MBs." |
| 56 DEFINE_boolean preserve ${FLAGS_FALSE} \ | 56 DEFINE_boolean preserve ${FLAGS_FALSE} \ |
| 57 "Attempt to preserve the previous build image if one can be found (unstable, \ | 57 "Attempt to preserve the previous build image if one can be found (unstable, \ |
| 58 kernel/firmware not updated)" | 58 kernel/firmware not updated)" |
| 59 DEFINE_boolean fast ${FLAGS_FALSE} \ | 59 DEFINE_boolean fast ${FLAGS_FALSE} \ |
| 60 "Call many emerges in parallel (unstable)" | 60 "Call many emerges in parallel (unstable)" |
| 61 | 61 |
| 62 DEFINE_string usb_disk /dev/sdb3 \ | 62 DEFINE_string usb_disk /dev/sdb3 \ |
| 63 "Path syslinux should use to do a usb boot. Default: /dev/sdb3" | 63 "Path syslinux should use to do a usb boot. Default: /dev/sdb3" |
| 64 | 64 |
| 65 DEFINE_boolean use_vboot ${FLAGS_FALSE} \ | 65 DEFINE_boolean enable_rootfs_verification ${FLAGS_FALSE} \ |
| 66 "Default the bootloaders to booting a verifying kernel. Default: False." | 66 "Default all bootloaders to use kernel-based root fs integrity checking." |
| 67 DEFINE_integer vboot_behavior 2 \ | 67 DEFINE_integer verity_error_behavior 2 \ |
| 68 "Verified boot error behavior (0: I/O errors, 1: reboot, 2: nothing) \ | 68 "Kernel verified boot error behavior (0: I/O errors, 1: reboot, 2: nothing) \ |
| 69 Default: 2" | 69 Default: 2" |
| 70 DEFINE_integer vboot_depth 1 \ | 70 DEFINE_integer verity_depth 1 \ |
| 71 "Verified boot hash tree depth. Default: 1" | 71 "Kernel verified boot hash tree depth. Default: 1" |
| 72 DEFINE_integer vboot_max_ios 1024 \ | 72 DEFINE_integer verity_max_ios 1024 \ |
| 73 "Number of outstanding I/O operations dm-verity caps at. Default: 1024" | 73 "Number of outstanding I/O operations dm-verity caps at. Default: 1024" |
| 74 DEFINE_string vboot_algorithm "sha1" \ | 74 DEFINE_string verity_algorithm "sha1" \ |
| 75 "Cryptographic hash algorithm used for vboot. Default : sha1" | 75 "Cryptographic hash algorithm used for kernel vboot. Default : sha1" |
| 76 | 76 |
| 77 # Parse command line. | 77 # Parse command line. |
| 78 FLAGS "$@" || exit 1 | 78 FLAGS "$@" || exit 1 |
| 79 eval set -- "${FLAGS_ARGV}" | 79 eval set -- "${FLAGS_ARGV}" |
| 80 | 80 |
| 81 # Only now can we die on error. shflags functions leak non-zero error codes, | 81 # Only now can we die on error. shflags functions leak non-zero error codes, |
| 82 # so will die prematurely if 'set -e' is specified before now. | 82 # so will die prematurely if 'set -e' is specified before now. |
| 83 set -e | 83 set -e |
| 84 | 84 |
| 85 if [ -z "${FLAGS_board}" ] ; then | 85 if [ -z "${FLAGS_board}" ] ; then |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 delete_prompt | 272 delete_prompt |
| 273 } | 273 } |
| 274 | 274 |
| 275 make_image_bootable() { | 275 make_image_bootable() { |
| 276 local image_name="$1" | 276 local image_name="$1" |
| 277 cros_root=/dev/sd%D%P | 277 cros_root=/dev/sd%D%P |
| 278 if [[ "${ARCH}" = "arm" ]]; then | 278 if [[ "${ARCH}" = "arm" ]]; then |
| 279 # TODO(wad) assumed like in build_gpt for now. | 279 # TODO(wad) assumed like in build_gpt for now. |
| 280 cros_root=/dev/mmcblk1p3 | 280 cros_root=/dev/mmcblk1p3 |
| 281 fi | 281 fi |
| 282 if [[ ${FLAGS_use_vboot} -eq ${FLAGS_TRUE} ]]; then | 282 if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then |
| 283 cros_root=/dev/dm-0 | 283 cros_root=/dev/dm-0 |
| 284 fi | 284 fi |
| 285 | 285 |
| 286 # TODO(wad) mount the root fs to LOOP_DEV from the image | 286 # TODO(wad) mount the root fs to LOOP_DEV from the image |
| 287 trap "mount_gpt_cleanup" EXIT | 287 trap "mount_gpt_cleanup" EXIT |
| 288 ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \ | 288 ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \ |
| 289 --image "${image_name}" -r "${ROOT_FS_DIR}" \ | 289 --image "${image_name}" -r "${ROOT_FS_DIR}" \ |
| 290 -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}" | 290 -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}" |
| 291 | 291 |
| 292 sudo mount -o remount,ro "${ROOT_FS_DIR}" | 292 sudo mount -o remount,ro "${ROOT_FS_DIR}" |
| 293 root_dev=$(mount | grep -- "${ROOT_FS_DIR}" | cut -f1 -d' ' | tail -1) | 293 root_dev=$(mount | grep -- "${ROOT_FS_DIR}" | cut -f1 -d' ' | tail -1) |
| 294 | 294 |
| 295 DEVKEYSDIR="${SRC_ROOT}/platform/vboot_reference/tests/devkeys" | 295 DEVKEYSDIR="${SRC_ROOT}/platform/vboot_reference/tests/devkeys" |
| 296 | 296 |
| 297 # Builds the kernel partition image. The temporary files are kept around | 297 # Builds the kernel partition image. The temporary files are kept around |
| 298 # so that we can perform a load_kernel_test later on the final image. | 298 # so that we can perform a load_kernel_test later on the final image. |
| 299 ${SCRIPTS_DIR}/build_kernel_image.sh \ | 299 ${SCRIPTS_DIR}/build_kernel_image.sh \ |
| 300 --arch="${ARCH}" \ | 300 --arch="${ARCH}" \ |
| 301 --to="${OUTPUT_DIR}/vmlinuz.image" \ | 301 --to="${OUTPUT_DIR}/vmlinuz.image" \ |
| 302 --hd_vblock="${OUTPUT_DIR}/vmlinuz_hd.vblock" \ | 302 --hd_vblock="${OUTPUT_DIR}/vmlinuz_hd.vblock" \ |
| 303 --vmlinuz="${OUTPUT_DIR}/boot/vmlinuz" \ | 303 --vmlinuz="${OUTPUT_DIR}/boot/vmlinuz" \ |
| 304 --working_dir="${OUTPUT_DIR}" \ | 304 --working_dir="${OUTPUT_DIR}" \ |
| 305 --keep_work \ | 305 --keep_work \ |
| 306 --rootfs_image=${root_dev} \ | 306 --rootfs_image=${root_dev} \ |
| 307 --rootfs_hash=${OUTPUT_DIR}/rootfs.hash \ | 307 --rootfs_hash=${OUTPUT_DIR}/rootfs.hash \ |
| 308 --vboot_hash_alg=${FLAGS_vboot_algorithm} \ | 308 --verity_hash_alg=${FLAGS_verity_algorithm} \ |
| 309 --vboot_tree_depth=${FLAGS_vboot_depth} \ | 309 --verity_tree_depth=${FLAGS_verity_depth} \ |
| 310 --vboot_max_ios=${FLAGS_vboot_max_ios} \ | 310 --verity_max_ios=${FLAGS_verity_max_ios} \ |
| 311 --vboot_error_behavior=${FLAGS_vboot_behavior} \ | 311 --verity_error_behavior=${FLAGS_verity_error_behavior} \ |
| 312 --root=${cros_root} \ | 312 --root=${cros_root} \ |
| 313 --keys_dir="${DEVKEYSDIR}" | 313 --keys_dir="${DEVKEYSDIR}" |
| 314 | 314 |
| 315 # Move the verification block needed for the hard disk install to the | 315 # Move the verification block needed for the hard disk install to the |
| 316 # stateful partition. Mount stateful fs, copy file, and umount fs. | 316 # stateful partition. Mount stateful fs, copy file, and umount fs. |
| 317 # In original CL: http://codereview.chromium.org/2868044, this was done in | 317 # In original CL: http://codereview.chromium.org/2868044, this was done in |
| 318 # create_base_image(). However, it could break the build if it is a clean | 318 # create_base_image(). However, it could break the build if it is a clean |
| 319 # build because vmlinuz_hd.vblock hasn't been created by build_kernel_image.sh | 319 # build because vmlinuz_hd.vblock hasn't been created by build_kernel_image.sh |
| 320 if [[ "${ARCH}" = "x86" ]]; then | 320 if [[ "${ARCH}" = "x86" ]]; then |
| 321 sudo cp "${OUTPUT_DIR}/vmlinuz_hd.vblock" "${STATEFUL_FS_DIR}" | 321 sudo cp "${OUTPUT_DIR}/vmlinuz_hd.vblock" "${STATEFUL_FS_DIR}" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 "${SCRIPTS_DIR}/customize_rootfs" \ | 575 "${SCRIPTS_DIR}/customize_rootfs" \ |
| 576 --root="${ROOT_FS_DIR}" \ | 576 --root="${ROOT_FS_DIR}" \ |
| 577 --target="${ARCH}" \ | 577 --target="${ARCH}" \ |
| 578 --board="${BOARD}" | 578 --board="${BOARD}" |
| 579 | 579 |
| 580 # Populates the root filesystem with legacy bootloader templates | 580 # Populates the root filesystem with legacy bootloader templates |
| 581 # appropriate for the platform. The autoupdater and installer will | 581 # appropriate for the platform. The autoupdater and installer will |
| 582 # use those templates to update the legacy boot partition (12/ESP) | 582 # use those templates to update the legacy boot partition (12/ESP) |
| 583 # on update. | 583 # on update. |
| 584 # (This script does not populate vmlinuz.A and .B needed by syslinux.) | 584 # (This script does not populate vmlinuz.A and .B needed by syslinux.) |
| 585 use_vboot= | 585 enable_rootfs_verification= |
| 586 [[ ${FLAGS_use_vboot} -eq ${FLAGS_TRUE} ]] && use_vboot="--use_vboot" | 586 if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then |
| 587 enable_rootfs_verification="--enable_rootfs_verification" |
| 588 fi |
| 589 |
| 587 ${SCRIPTS_DIR}/create_legacy_bootloader_templates.sh \ | 590 ${SCRIPTS_DIR}/create_legacy_bootloader_templates.sh \ |
| 588 --arch=${ARCH} \ | 591 --arch=${ARCH} \ |
| 589 --to="${ROOT_FS_DIR}"/boot \ | 592 --to="${ROOT_FS_DIR}"/boot \ |
| 590 --install \ | 593 --install \ |
| 591 ${use_vboot} | 594 ${enable_rootfs_verification} |
| 592 | 595 |
| 593 # Create a working copy so we don't need the rootfs mounted | 596 # Create a working copy so we don't need the rootfs mounted |
| 594 sudo mkdir -p "${OUTPUT_DIR}"/boot | 597 sudo mkdir -p "${OUTPUT_DIR}"/boot |
| 595 # This will include any built files dropped in /boot as well. | 598 # This will include any built files dropped in /boot as well. |
| 596 # Like the current vmlinuz. | 599 # Like the current vmlinuz. |
| 597 sudo cp -r "${ROOT_FS_DIR}"/boot/. "${OUTPUT_DIR}"/boot/ | 600 sudo cp -r "${ROOT_FS_DIR}"/boot/. "${OUTPUT_DIR}"/boot/ |
| 598 sudo chmod -R a+r "${OUTPUT_DIR}"/boot/ | 601 sudo chmod -R a+r "${OUTPUT_DIR}"/boot/ |
| 599 | 602 |
| 600 # Don't test the factory install shim. | 603 # Don't test the factory install shim. |
| 601 if [[ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ]] ; then | 604 if [[ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ]] ; then |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 echo "Developer image created as ${DEVELOPER_IMAGE_NAME}" | 697 echo "Developer image created as ${DEVELOPER_IMAGE_NAME}" |
| 695 fi | 698 fi |
| 696 | 699 |
| 697 print_time_elapsed | 700 print_time_elapsed |
| 698 | 701 |
| 699 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" | 702 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" |
| 700 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" | 703 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" |
| 701 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" | 704 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" |
| 702 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" | 705 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" |
| 703 echo "from the scripts directory where you entered the chroot." | 706 echo "from the scripts directory where you entered the chroot." |
| OLD | NEW |