| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 # Only now can we die on error. shflags functions leak non-zero error codes, | 89 # Only now can we die on error. shflags functions leak non-zero error codes, |
| 90 # so will die prematurely if 'set -e' is specified before now. | 90 # so will die prematurely if 'set -e' is specified before now. |
| 91 set -e | 91 set -e |
| 92 | 92 |
| 93 if [ -z "${FLAGS_board}" ] ; then | 93 if [ -z "${FLAGS_board}" ] ; then |
| 94 error "--board is required." | 94 error "--board is required." |
| 95 exit 1 | 95 exit 1 |
| 96 fi | 96 fi |
| 97 | 97 |
| 98 if [ "$((FLAGS_rootfs_size + FLAGS_rootfs_hash_pad))" -gt \ | |
| 99 "${FLAGS_rootfs_partition_size}" ] ; then | |
| 100 error "rootfs ($((FLAGS_rootfs_size + FLAGS_rootfs_hash_pad)) MiB) is \ | |
| 101 bigger than partition (${FLAGS_rootfs_partition_size} MiB)." | |
| 102 exit 1 | |
| 103 fi | |
| 104 | |
| 105 # Verify user didn't specify incompatible flags for dev install shim | 98 # Verify user didn't specify incompatible flags for dev install shim |
| 106 if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] && | 99 if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] && |
| 107 [ ${FLAGS_dev_install} -eq ${FLAGS_TRUE} ] ; then | 100 [ ${FLAGS_dev_install} -eq ${FLAGS_TRUE} ] ; then |
| 108 error "Incompatible flags: --factory_install and --dev_install cannot be \ | 101 error "Incompatible flags: --factory_install and --dev_install cannot be \ |
| 109 both set to True. Please specify one or none." | 102 both set to True. Please specify one or none." |
| 110 exit 1 | 103 exit 1 |
| 111 fi | 104 fi |
| 112 | 105 |
| 113 # Disable --withdev flag when --dev_install is set to True. Otherwise, the | 106 INSTALL_MASK="" |
| 114 # dev image produced will be based on dev install shim, rather than a pristine | 107 if [ ${FLAGS_installmask} -eq ${FLAGS_TRUE} ] ; then |
| 115 # image | 108 INSTALL_MASK="${DEFAULT_INSTALL_MASK}" |
| 116 if [ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ] && | 109 fi |
| 110 |
| 111 # Reduce the size of factory install shim. |
| 112 if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] || |
| 117 [ ${FLAGS_dev_install} -eq ${FLAGS_TRUE} ] ; then | 113 [ ${FLAGS_dev_install} -eq ${FLAGS_TRUE} ] ; then |
| 118 info "Incompatible flags: --withdev and --dev_install cannot be both set to \ | 114 # Disable --withdev flag when --*_install is set to True. Otherwise, the |
| 119 True. Reset --withdev to False." | 115 # dev image produced will be based on install shim, rather than a pristine |
| 120 FLAGS_withdev=${FLAGS_FALSE} | 116 # image |
| 117 if [ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]; then |
| 118 info "Incompatible flags: --withdev and --dev_install or --factory_install \ |
| 119 cannot be both set to True. Reset --withdev to False." |
| 120 FLAGS_withdev=${FLAGS_FALSE} |
| 121 fi |
| 122 |
| 123 # TODO: Build a separated ebuild for the install shim to reduce size. |
| 124 INSTALL_MASK="${INSTALL_MASK} ${FACTORY_INSTALL_MASK}" |
| 125 |
| 126 info "Fixing the rootfs size at 300 MiB for install shim" |
| 127 FLAGS_rootfs_size=280 |
| 128 FLAGS_rootfs_partition_size=300 |
| 129 info "Fixing the statefulfs size at 140 MiB for install shim" |
| 130 FLAGS_statefulfs_size=140 |
| 131 fi |
| 132 |
| 133 if [ "$((FLAGS_rootfs_size + FLAGS_rootfs_hash_pad))" -gt \ |
| 134 "${FLAGS_rootfs_partition_size}" ] ; then |
| 135 die "rootfs ($((FLAGS_rootfs_size + FLAGS_rootfs_hash_pad)) MiB) is \ |
| 136 bigger than partition (${FLAGS_rootfs_partition_size} MiB)." |
| 121 fi | 137 fi |
| 122 | 138 |
| 123 EMERGE_BOARD_CMD="emerge-${FLAGS_board}" | 139 EMERGE_BOARD_CMD="emerge-${FLAGS_board}" |
| 124 if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then | 140 if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then |
| 125 echo "Using alternate emerge" | 141 echo "Using alternate emerge" |
| 126 EMERGE_BOARD_CMD="${SCRIPTS_DIR}/parallel_emerge --board=${FLAGS_board}" | 142 EMERGE_BOARD_CMD="${SCRIPTS_DIR}/parallel_emerge --board=${FLAGS_board}" |
| 127 fi | 143 fi |
| 128 | 144 |
| 129 # Determine build version. | 145 # Determine build version. |
| 130 . "${SCRIPTS_DIR}/chromeos_version.sh" | 146 . "${SCRIPTS_DIR}/chromeos_version.sh" |
| 131 | 147 |
| 132 # Use canonical path since some tools (e.g. mount) do not like symlinks. | 148 # Use canonical path since some tools (e.g. mount) do not like symlinks. |
| 133 # Append build attempt to output directory. | 149 # Append build attempt to output directory. |
| 134 IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}" | 150 IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}" |
| 135 OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}" | 151 OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}" |
| 136 | 152 |
| 137 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" | 153 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" |
| 138 | 154 |
| 139 # If we are creating a developer image, also create a pristine image with a | 155 # If we are creating a developer image, also create a pristine image with a |
| 140 # different name. | 156 # different name. |
| 141 DEVELOPER_IMAGE_NAME= | 157 DEVELOPER_IMAGE_NAME= |
| 142 PRISTINE_IMAGE_NAME=chromiumos_image.bin | 158 PRISTINE_IMAGE_NAME=chromiumos_image.bin |
| 143 if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then | 159 if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then |
| 144 PRISTINE_IMAGE_NAME=chromiumos_base_image.bin | 160 PRISTINE_IMAGE_NAME=chromiumos_base_image.bin |
| 145 DEVELOPER_IMAGE_NAME=chromiumos_image.bin | 161 DEVELOPER_IMAGE_NAME=chromiumos_image.bin |
| 146 fi | 162 elif [ "${FLAGS_dev_install}" -eq "${FLAGS_TRUE}" ]; then |
| 147 | 163 # Rename pristine images for install shims |
| 148 # Rename pristine image for dev install shim | |
| 149 if [ "${FLAGS_dev_install}" -eq "${FLAGS_TRUE}" ]; then | |
| 150 PRISTINE_IMAGE_NAME=dev_install_shim.bin | 164 PRISTINE_IMAGE_NAME=dev_install_shim.bin |
| 165 elif [ "${FLAGS_factory_install}" -eq "${FLAGS_TRUE}" ]; then |
| 166 PRISTINE_IMAGE_NAME=factory_install_shim.bin |
| 151 fi | 167 fi |
| 152 | 168 |
| 153 PRISTINE_IMG="${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}" | 169 PRISTINE_IMG="${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}" |
| 154 DEVELOPER_IMG="${OUTPUT_DIR}/${DEVELOPER_IMAGE_NAME}" | 170 DEVELOPER_IMG="${OUTPUT_DIR}/${DEVELOPER_IMAGE_NAME}" |
| 155 | 171 |
| 156 BOARD="${FLAGS_board}" | 172 BOARD="${FLAGS_board}" |
| 157 BOARD_ROOT="${FLAGS_build_root}/${BOARD}" | 173 BOARD_ROOT="${FLAGS_build_root}/${BOARD}" |
| 158 | 174 |
| 159 ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" | 175 ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" |
| 160 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" | 176 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 178 | 194 |
| 179 # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will | 195 # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will |
| 180 # be installed on the stateful dir. On a Chromium OS system, this will | 196 # be installed on the stateful dir. On a Chromium OS system, this will |
| 181 # translate to /usr/local. | 197 # translate to /usr/local. |
| 182 DEV_IMAGE_ROOT="${STATEFUL_FS_DIR}/dev_image" | 198 DEV_IMAGE_ROOT="${STATEFUL_FS_DIR}/dev_image" |
| 183 | 199 |
| 184 # What cross-build are we targeting? | 200 # What cross-build are we targeting? |
| 185 . "${BOARD_ROOT}/etc/make.conf.board_setup" | 201 . "${BOARD_ROOT}/etc/make.conf.board_setup" |
| 186 LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"} | 202 LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"} |
| 187 | 203 |
| 188 INSTALL_MASK="" | 204 if [ ${FLAGS_jobs} -ne -1 ]; then |
| 189 if [[ ${FLAGS_installmask} -eq ${FLAGS_TRUE} ]] ; then | |
| 190 INSTALL_MASK="${DEFAULT_INSTALL_MASK}" | |
| 191 fi | |
| 192 | |
| 193 # Reduce the size of factory install shim. | |
| 194 # TODO: Build a separated ebuild for the factory install shim to reduce size. | |
| 195 if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] || | |
| 196 [ ${FLAGS_dev_install} -eq ${FLAGS_TRUE} ] ; then | |
| 197 INSTALL_MASK="${INSTALL_MASK} ${FACTORY_INSTALL_MASK}" | |
| 198 fi | |
| 199 | |
| 200 if [[ ${FLAGS_jobs} -ne -1 ]]; then | |
| 201 EMERGE_JOBS="--jobs=${FLAGS_jobs}" | 205 EMERGE_JOBS="--jobs=${FLAGS_jobs}" |
| 202 fi | 206 fi |
| 203 | 207 |
| 204 # Figure out ARCH from the given toolchain. | 208 # Figure out ARCH from the given toolchain. |
| 205 # TODO: Move to common.sh as a function after scripts are switched over. | 209 # TODO: Move to common.sh as a function after scripts are switched over. |
| 206 TC_ARCH=$(echo "${CHOST}" | awk -F'-' '{ print $1 }') | 210 TC_ARCH=$(echo "${CHOST}" | awk -F'-' '{ print $1 }') |
| 207 case "${TC_ARCH}" in | 211 case "${TC_ARCH}" in |
| 208 arm*) | 212 arm*) |
| 209 ARCH="arm" | 213 ARCH="arm" |
| 210 ;; | 214 ;; |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 cp ${PREVIOUS_DIR}/${PRISTINE_IMAGE_NAME} ${OUTPUT_DIR} | 652 cp ${PREVIOUS_DIR}/${PRISTINE_IMAGE_NAME} ${OUTPUT_DIR} |
| 649 | 653 |
| 650 # Copy forward the developer image, if we already copied forward the base. | 654 # Copy forward the developer image, if we already copied forward the base. |
| 651 if [[ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]] && \ | 655 if [[ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]] && \ |
| 652 [[ -f ${PREVIOUS_DIR}/${DEVELOPER_IMAGE_NAME} ]] ; then | 656 [[ -f ${PREVIOUS_DIR}/${DEVELOPER_IMAGE_NAME} ]] ; then |
| 653 cp ${PREVIOUS_DIR}/${DEVELOPER_IMAGE_NAME} ${OUTPUT_DIR} | 657 cp ${PREVIOUS_DIR}/${DEVELOPER_IMAGE_NAME} ${OUTPUT_DIR} |
| 654 fi | 658 fi |
| 655 fi | 659 fi |
| 656 fi | 660 fi |
| 657 | 661 |
| 658 # Minimize rootfs size for factory installer | |
| 659 if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]; then | |
| 660 info "Fixing the rootfs size at 300 MiB for the factory installer" | |
| 661 FLAGS_rootfs_size=300 | |
| 662 fi | |
| 663 | |
| 664 # Minimize rootfs size and statefulfs size for dev install shim | |
| 665 if [ ${FLAGS_dev_install} -eq ${FLAGS_TRUE} ] ; then | |
| 666 info "Fixing the rootfs size at 300 MiB for dev install shim" | |
| 667 FLAGS_rootfs_size=300 | |
| 668 info "Fixing the statefulfs size at 140 MiB for dev install shim" | |
| 669 FLAGS_statefulfs_size=140 | |
| 670 fi | |
| 671 | |
| 672 # Create the boot.desc file which stores the build-time configuration | 662 # Create the boot.desc file which stores the build-time configuration |
| 673 # information needed for making the image bootable after creation with | 663 # information needed for making the image bootable after creation with |
| 674 # cros_make_image_bootable. | 664 # cros_make_image_bootable. |
| 675 create_boot_desc | 665 create_boot_desc |
| 676 | 666 |
| 677 if [[ -f ${PRISTINE_IMG} ]] ; then | 667 if [[ -f ${PRISTINE_IMG} ]] ; then |
| 678 update_base_packages ${PRISTINE_IMAGE_NAME} | 668 update_base_packages ${PRISTINE_IMAGE_NAME} |
| 679 else | 669 else |
| 680 create_base_image ${PRISTINE_IMAGE_NAME} | 670 create_base_image ${PRISTINE_IMAGE_NAME} |
| 681 fi | 671 fi |
| 682 | 672 |
| 683 USE_DEV_KEYS= | 673 USE_DEV_KEYS= |
| 684 if [ "${FLAGS_dev_install}" -eq "${FLAGS_TRUE}" ]; then | 674 if [ "${FLAGS_dev_install}" -eq "${FLAGS_TRUE}" ] || \ |
| 675 [ "${FLAGS_factory_install}" -eq "${FLAGS_TRUE}" ]; then |
| 685 USE_DEV_KEYS="--use_dev_keys" | 676 USE_DEV_KEYS="--use_dev_keys" |
| 686 fi | 677 fi |
| 687 | 678 |
| 688 # Place flags before positional args | 679 # Place flags before positional args |
| 689 ${SCRIPTS_DIR}/bin/cros_make_image_bootable "${OUTPUT_DIR}" \ | 680 ${SCRIPTS_DIR}/bin/cros_make_image_bootable "${OUTPUT_DIR}" \ |
| 690 "${PRISTINE_IMAGE_NAME}" \ | 681 "${PRISTINE_IMAGE_NAME}" \ |
| 691 ${USE_DEV_KEYS} | 682 ${USE_DEV_KEYS} |
| 692 | 683 |
| 693 # FIXME: only signing things for x86 right now. | 684 # FIXME: only signing things for x86 right now. |
| 694 if [[ "${ARCH}" = "x86" ]]; then | 685 if [[ "${ARCH}" = "x86" ]]; then |
| 695 BOOT_FLAG= | 686 BOOT_FLAG= |
| 696 if [ "${FLAGS_dev_install}" -eq "${FLAGS_TRUE}" ] ; then | 687 if [ "${FLAGS_dev_install}" -eq "${FLAGS_TRUE}" ] || |
| 688 [ "${FLAGS_factory_install}" -eq "${FLAGS_TRUE}" ]; then |
| 697 BOOT_FLAG="-b 1" # BOOT_FLAG_DEVELOPER value defined in load_kernel_fw.h | 689 BOOT_FLAG="-b 1" # BOOT_FLAG_DEVELOPER value defined in load_kernel_fw.h |
| 698 info "--dev_install set, pass BOOT_FLAG_DEVELOPER flag to load_kernel_test" | 690 info "--dev_install set, pass BOOT_FLAG_DEVELOPER flag to load_kernel_test" |
| 699 fi | 691 fi |
| 700 | 692 |
| 701 # Verify the final image. | 693 # Verify the final image. |
| 702 load_kernel_test "${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}" \ | 694 load_kernel_test "${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}" \ |
| 703 "${DEVKEYSDIR}/recovery_key.vbpubk" ${BOOT_FLAG} | 695 "${DEVKEYSDIR}/recovery_key.vbpubk" ${BOOT_FLAG} |
| 704 fi | 696 fi |
| 705 | 697 |
| 706 # Create a developer image based on the chromium os base image. | 698 # Create a developer image based on the chromium os base image. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 730 echo "Developer image created as ${DEVELOPER_IMAGE_NAME}" | 722 echo "Developer image created as ${DEVELOPER_IMAGE_NAME}" |
| 731 fi | 723 fi |
| 732 | 724 |
| 733 print_time_elapsed | 725 print_time_elapsed |
| 734 | 726 |
| 735 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" | 727 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" |
| 736 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" | 728 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" |
| 737 echo "To convert to VMWare image, INSIDE the chroot, do something like:" | 729 echo "To convert to VMWare image, INSIDE the chroot, do something like:" |
| 738 echo " ./image_to_vm.sh --from=${OUTSIDE_OUTPUT_DIR} --board=${BOARD}" | 730 echo " ./image_to_vm.sh --from=${OUTSIDE_OUTPUT_DIR} --board=${BOARD}" |
| 739 echo "from the scripts directory where you entered the chroot." | 731 echo "from the scripts directory where you entered the chroot." |
| OLD | NEW |