J. Richard Barnette | 8447777 | 2011-07-25 13:41:33 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 2 | |
Peter Mayo | 82975f9 | 2012-05-01 11:03:31 -0400 | [diff] [blame] | 3 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 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 build a bootable keyfob-based chromeos system image from within |
| 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 |
| 10 | # build the Chrome OS image using only pre-built binary packages. |
| 11 | |
Brian Harring | aa13ea4 | 2012-03-15 18:31:03 -0700 | [diff] [blame] | 12 | SCRIPT_ROOT=$(dirname $(readlink -f "$0")) |
J. Richard Barnette | 8447777 | 2011-07-25 13:41:33 -0700 | [diff] [blame] | 13 | . "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1 |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 14 | |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 15 | # Developer-visible flags. |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 16 | DEFINE_string board "${DEFAULT_BOARD}" \ |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 17 | "The board to build an image for." |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 18 | DEFINE_string boot_args "noinitrd" \ |
| 19 | "Additional boot arguments to pass to the commandline" |
| 20 | DEFINE_boolean enable_rootfs_verification ${FLAGS_TRUE} \ |
| 21 | "Default all bootloaders to use kernel-based root fs integrity checking." |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 22 | DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/images" \ |
| 23 | "Directory in which to place image result directories (named by version)" |
Liam McLoughlin | 5b37c54 | 2012-08-16 11:09:37 -0700 | [diff] [blame] | 24 | DEFINE_string disk_layout "default" \ |
| 25 | "The board to build an image for." |
David Rochberg | cf93237 | 2011-06-30 21:25:08 -0400 | [diff] [blame] | 26 | DEFINE_boolean standard_backdoor ${FLAGS_TRUE} \ |
| 27 | "Install standard backdoor credentials for testing" |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 28 | DEFINE_string usb_disk /dev/sdb3 \ |
| 29 | "Path syslinux should use to do a usb boot. Default: /dev/sdb3" |
Che-Liang Chiou | 611d5b7 | 2011-07-27 16:03:26 +0800 | [diff] [blame] | 30 | |
Chris Sosa | ef4a645 | 2011-10-27 16:01:07 -0700 | [diff] [blame] | 31 | FLAGS_HELP="USAGE: build_image [flags] [list of images to build]. |
| 32 | This script is used to build a Chromium OS image. Chromium OS comes in many |
| 33 | different forms. This scripts can be used to build the following: |
| 34 | |
| 35 | base - Pristine Chromium OS image. As similar to Chrome OS as possible. |
| 36 | dev - Developer image. Like base but with additional developer packages. |
| 37 | test - Like dev, but with additional test specific packages and can be easily |
| 38 | used for automated testing using scripts like run_remote_tests, etc. |
| 39 | factory_test - Like test but with extra packages and modifications used to |
| 40 | test images in a factory setting. Cannot be built along with a test image. |
| 41 | factory_install - Install shim for bootstrapping the factory test process. |
| 42 | Cannot be built along with any other image. |
| 43 | |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 44 | Examples: |
Chris Sosa | ef4a645 | 2011-10-27 16:01:07 -0700 | [diff] [blame] | 45 | |
| 46 | build_image --board=<board> dev test - builds developer and test images. |
| 47 | build_image --board=<board> factory_install - builds a factory install shim. |
| 48 | ... |
| 49 | " |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 50 | show_help_if_requested "$@" |
| 51 | |
| 52 | # The following options are advanced options, only available to those willing |
| 53 | # to read the source code. They are not shown in help output, since they are |
| 54 | # not needed for the typical developer workflow. |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 55 | DEFINE_integer build_attempt 1 \ |
| 56 | "The build attempt for this image build." |
| 57 | DEFINE_integer jobs -1 \ |
| 58 | "How many packages to build in parallel at maximum." |
| 59 | DEFINE_boolean replace ${FLAGS_FALSE} \ |
| 60 | "Overwrite existing output, if any." |
| 61 | DEFINE_string symlink "latest" \ |
| 62 | "Symlink name to use for this image." |
Liam McLoughlin | 0727903 | 2012-06-25 17:31:11 -0700 | [diff] [blame] | 63 | DEFINE_string version "" \ |
| 64 | "Overrides version number in name to this version." |
Chris Sosa | ef4a645 | 2011-10-27 16:01:07 -0700 | [diff] [blame] | 65 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 66 | # Parse command line. |
| 67 | FLAGS "$@" || exit 1 |
| 68 | eval set -- "${FLAGS_ARGV}" |
| 69 | |
| 70 | # Only now can we die on error. shflags functions leak non-zero error codes, |
Brian Harring | 7f175a5 | 2012-03-02 05:37:00 -0800 | [diff] [blame] | 71 | # so will die prematurely if 'switch_to_strict_mode' is specified before now. |
| 72 | switch_to_strict_mode |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 73 | |
J. Richard Barnette | e4e3dec | 2011-08-08 16:35:02 -0700 | [diff] [blame] | 74 | # Determine build version. |
| 75 | OVERLAY_CHROMEOS_DIR="${SRC_ROOT}/third_party/chromiumos-overlay/chromeos" |
| 76 | . "${OVERLAY_CHROMEOS_DIR}/config/chromeos_version.sh" || exit 1 |
J. Richard Barnette | a308b39 | 2011-08-29 13:53:34 -0700 | [diff] [blame] | 77 | # N.B. Ordering matters for some of the libraries below, because |
| 78 | # some of the files contain initialization used by later files. |
J. Richard Barnette | aaef761 | 2011-08-11 17:10:28 -0700 | [diff] [blame] | 79 | . "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1 |
Liam McLoughlin | 5b37c54 | 2012-08-16 11:09:37 -0700 | [diff] [blame] | 80 | . "${BUILD_LIBRARY_DIR}/disk_layout_util.sh" || exit 1 |
J. Richard Barnette | 5f9dbe4 | 2011-08-22 14:31:33 -0700 | [diff] [blame] | 81 | . "${BUILD_LIBRARY_DIR}/mount_gpt_util.sh" || exit 1 |
J. Richard Barnette | a308b39 | 2011-08-29 13:53:34 -0700 | [diff] [blame] | 82 | . "${BUILD_LIBRARY_DIR}/build_image_util.sh" || exit 1 |
| 83 | . "${BUILD_LIBRARY_DIR}/base_image_util.sh" || exit 1 |
| 84 | . "${BUILD_LIBRARY_DIR}/dev_image_util.sh" || exit 1 |
| 85 | . "${BUILD_LIBRARY_DIR}/test_image_util.sh" || exit 1 |
J. Richard Barnette | aaef761 | 2011-08-11 17:10:28 -0700 | [diff] [blame] | 86 | . "${BUILD_LIBRARY_DIR}/test_image_content.sh" || exit 1 |
J. Richard Barnette | e4e3dec | 2011-08-08 16:35:02 -0700 | [diff] [blame] | 87 | |
Chris Sosa | b0f5732 | 2011-10-25 03:07:23 +0000 | [diff] [blame] | 88 | parse_build_image_args |
Peter Mayo | 82975f9 | 2012-05-01 11:03:31 -0400 | [diff] [blame] | 89 | |
David James | 18a9c25 | 2012-10-19 16:16:38 -0700 | [diff] [blame^] | 90 | for overlay in $(cros_list_overlays --board "$BOARD"); do |
Liam McLoughlin | d606ee2 | 2012-07-03 16:48:57 -0700 | [diff] [blame] | 91 | setup_sh="${overlay}/scripts/board_specific_setup.sh" |
| 92 | if [[ -e ${setup_sh} ]]; then |
| 93 | source "${setup_sh}" |
| 94 | fi |
| 95 | done |
| 96 | |
Liam McLoughlin | 5b37c54 | 2012-08-16 11:09:37 -0700 | [diff] [blame] | 97 | # TODO: <prebuild hook> |
Peter Mayo | 82975f9 | 2012-05-01 11:03:31 -0400 | [diff] [blame] | 98 | |
Chris Sosa | 4299eb9 | 2011-11-01 12:54:01 -0700 | [diff] [blame] | 99 | # Tweak flags, configure extra USE flags, and add packages for the factory |
| 100 | # install shim. |
| 101 | EXTRA_PACKAGES="" |
Chris Sosa | c9422fa | 2012-03-05 15:58:07 -0800 | [diff] [blame] | 102 | if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then |
Nick Sanders | ae26a5c | 2010-08-30 21:59:50 -0700 | [diff] [blame] | 103 | # TODO: Build a separated ebuild for the install shim to reduce size. |
Hung-Te Lin | d32c59f | 2012-01-19 19:54:01 +0800 | [diff] [blame] | 104 | INSTALL_MASK="${FACTORY_SHIM_INSTALL_MASK}" |
Nick Sanders | ae26a5c | 2010-08-30 21:59:50 -0700 | [diff] [blame] | 105 | |
Jon Salz | 67145df | 2011-10-20 14:05:06 +0800 | [diff] [blame] | 106 | # Add the cros_factory_install boot arg. |
| 107 | FLAGS_boot_args="${FLAGS_boot_args} cros_factory_install" |
Chris Sosa | 4299eb9 | 2011-11-01 12:54:01 -0700 | [diff] [blame] | 108 | |
| 109 | # Factory install needs to have the factory installer added. |
| 110 | EXTRA_PACKAGES="${EXTRA_PACKAGES} chromeos-base/chromeos-factoryinstall" |
Hung-Te Lin | 7119cb1 | 2012-03-07 22:29:13 +0800 | [diff] [blame] | 111 | # On x86/amd64, we boot the factory install shim from an SD card using |
| 112 | # initramfs for our root. On ARM, we boot the factory install shim over the |
| 113 | # network, so we don't require initramfs, but we do require fbconsole to fix |
| 114 | # a display driver bug. |
| 115 | if [ "${ARCH}" = "x86" -o "${ARCH}" = "amd64" ] ; then |
Vic Yang | 4051405 | 2012-05-22 14:27:40 +0800 | [diff] [blame] | 116 | export USE="${USE} initramfs vfat" |
Chris Sosa | 4299eb9 | 2011-11-01 12:54:01 -0700 | [diff] [blame] | 117 | fi |
| 118 | # CONFIG_BLK_DEV_RAM is disabled by default. |
| 119 | # But tftp install needs it to mount rootfs in ram |
| 120 | if [ "${ARCH}" = "arm" ] ; then |
| 121 | export USE="${USE} fbconsole blkdevram" |
| 122 | fi |
Nick Sanders | ae26a5c | 2010-08-30 21:59:50 -0700 | [diff] [blame] | 123 | fi |
| 124 | |
Kees Cook | 8df86b2 | 2012-09-28 18:15:49 -0700 | [diff] [blame] | 125 | if should_build_image ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then |
| 126 | # Disable module restrictions on factory test image to allow for |
| 127 | # external third party drivers in /usr/local. |
| 128 | FLAGS_boot_args="${FLAGS_boot_args} lsm.module_locking=0" |
| 129 | fi |
| 130 | |
Liam McLoughlin | 5b37c54 | 2012-08-16 11:09:37 -0700 | [diff] [blame] | 131 | # TODO: </prebuild hook> |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 132 | |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 133 | # If we are creating a developer image, also create a pristine image with a |
| 134 | # different name. |
Chris Sosa | 93e7b78 | 2012-01-03 15:52:12 -0800 | [diff] [blame] | 135 | PRISTINE_IMAGE_NAME= |
Chris Sosa | c9422fa | 2012-03-05 15:58:07 -0800 | [diff] [blame] | 136 | if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then |
Chris Sosa | b0f5732 | 2011-10-25 03:07:23 +0000 | [diff] [blame] | 137 | PRISTINE_IMAGE_NAME=${CHROMEOS_FACTORY_INSTALL_SHIM_NAME} |
Chris Sosa | 93e7b78 | 2012-01-03 15:52:12 -0800 | [diff] [blame] | 138 | else |
Chris Sosa | c9422fa | 2012-03-05 15:58:07 -0800 | [diff] [blame] | 139 | PRISTINE_IMAGE_NAME=${CHROMEOS_BASE_IMAGE_NAME} |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 140 | fi |
| 141 | |
Will Drewry | 7ab698d | 2010-08-05 13:57:52 -0500 | [diff] [blame] | 142 | DEVKEYSDIR="/usr/share/vboot/devkeys" |
| 143 | |
J. Richard Barnette | 8e48095 | 2011-08-30 16:00:59 -0700 | [diff] [blame] | 144 | eclean-$BOARD -d packages |
Will Drewry | 12f14ce | 2010-08-17 17:27:16 -0500 | [diff] [blame] | 145 | |
Liam McLoughlin | d606ee2 | 2012-07-03 16:48:57 -0700 | [diff] [blame] | 146 | if [[ ${skip_blacklist_check} -ne 1 ]]; then |
| 147 | check_blacklist |
| 148 | fi |
J. Richard Barnette | a308b39 | 2011-08-29 13:53:34 -0700 | [diff] [blame] | 149 | |
| 150 | # Check that the build root is sane. |
Liam McLoughlin | d606ee2 | 2012-07-03 16:48:57 -0700 | [diff] [blame] | 151 | if [[ ${skip_test_build_root} -ne 1 ]]; then |
| 152 | "${BUILD_LIBRARY_DIR}/test_build_root" --root="${BOARD_ROOT}" |
| 153 | fi |
J. Richard Barnette | a308b39 | 2011-08-29 13:53:34 -0700 | [diff] [blame] | 154 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 155 | # Hack to fix bug where x86_64 CHOST line gets incorrectly added. |
| 156 | # ToDo(msb): remove this hack. |
| 157 | PACKAGES_FILE="${BOARD_ROOT}/packages/Packages" |
| 158 | sudo sed -e "s/CHOST: x86_64-pc-linux-gnu//" -i "${PACKAGES_FILE}" |
| 159 | |
| 160 | # Handle existing directory. |
Chris Sosa | b0f5732 | 2011-10-25 03:07:23 +0000 | [diff] [blame] | 161 | if [[ -e "${BUILD_DIR}" ]]; then |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 162 | if [[ ${FLAGS_replace} -eq ${FLAGS_TRUE} ]]; then |
Chris Sosa | b0f5732 | 2011-10-25 03:07:23 +0000 | [diff] [blame] | 163 | sudo rm -rf "${BUILD_DIR}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 164 | else |
Chris Sosa | b0f5732 | 2011-10-25 03:07:23 +0000 | [diff] [blame] | 165 | error "Directory ${BUILD_DIR} already exists." |
| 166 | error "Use --build_attempt option to specify an unused attempt." |
Brian Harring | 7f175a5 | 2012-03-02 05:37:00 -0800 | [diff] [blame] | 167 | error "Or use --replace if you want to overwrite this directory." |
| 168 | die "Unwilling to overwrite ${BUILD_DIR}." |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 169 | fi |
| 170 | fi |
| 171 | |
J. Richard Barnette | a308b39 | 2011-08-29 13:53:34 -0700 | [diff] [blame] | 172 | # Create the output directory and temporary mount points. |
Chris Sosa | b0f5732 | 2011-10-25 03:07:23 +0000 | [diff] [blame] | 173 | mkdir -p "${BUILD_DIR}" |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 174 | |
Liam McLoughlin | 5b37c54 | 2012-08-16 11:09:37 -0700 | [diff] [blame] | 175 | # Create the base image. |
Chris Sosa | b0f5732 | 2011-10-25 03:07:23 +0000 | [diff] [blame] | 176 | create_base_image ${PRISTINE_IMAGE_NAME} |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 177 | |
Liam McLoughlin | d606ee2 | 2012-07-03 16:48:57 -0700 | [diff] [blame] | 178 | # Running board-specific setup if any exists. |
| 179 | if type board_setup &>/dev/null; then |
| 180 | board_setup "${BUILD_DIR}/${PRISTINE_IMAGE_NAME}" |
| 181 | fi |
| 182 | |
Chris Sosa | c9422fa | 2012-03-05 15:58:07 -0800 | [diff] [blame] | 183 | # Create a developer image if an image that is based on it is requested. |
| 184 | if should_build_image ${CHROMEOS_DEVELOPER_IMAGE_NAME} \ |
| 185 | ${CHROMEOS_TEST_IMAGE_NAME} ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then |
Chris Sosa | b0f5732 | 2011-10-25 03:07:23 +0000 | [diff] [blame] | 186 | copy_image ${CHROMEOS_BASE_IMAGE_NAME} ${CHROMEOS_DEVELOPER_IMAGE_NAME} |
Chris Sosa | c9422fa | 2012-03-05 15:58:07 -0800 | [diff] [blame] | 187 | install_dev_packages ${CHROMEOS_DEVELOPER_IMAGE_NAME} |
Bill Richardson | 6ed1358 | 2010-06-16 21:38:15 -0700 | [diff] [blame] | 188 | fi |
| 189 | |
Chris Sosa | c9422fa | 2012-03-05 15:58:07 -0800 | [diff] [blame] | 190 | # From a developer image create a test|factory_test image. |
| 191 | if should_build_image ${CHROMEOS_TEST_IMAGE_NAME}; then |
| 192 | copy_image ${CHROMEOS_DEVELOPER_IMAGE_NAME} ${CHROMEOS_TEST_IMAGE_NAME} |
| 193 | mod_image_for_test ${CHROMEOS_TEST_IMAGE_NAME} |
| 194 | fi |
| 195 | if should_build_image ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then |
Chris Sosa | b0f5732 | 2011-10-25 03:07:23 +0000 | [diff] [blame] | 196 | copy_image ${CHROMEOS_DEVELOPER_IMAGE_NAME} \ |
| 197 | ${CHROMEOS_FACTORY_TEST_IMAGE_NAME} |
| 198 | mod_image_for_test ${CHROMEOS_FACTORY_TEST_IMAGE_NAME} |
Vince Laviano | 6aebf31 | 2011-06-01 15:27:31 -0700 | [diff] [blame] | 199 | fi |
| 200 | |
Raja Aluri | aeb1048 | 2010-12-10 13:03:09 -0800 | [diff] [blame] | 201 | # Generating AU generator zip file to run outside chroot |
| 202 | generate_au_zip || echo "Failed generating AU zip file - ignoring Error..." |
David James | 4dd4c54 | 2011-08-10 10:19:47 -0700 | [diff] [blame] | 203 | |
| 204 | # Create a named symlink. |
| 205 | LINK_NAME="${FLAGS_output_root}/${BOARD}/${FLAGS_symlink}" |
Chris Sosa | b0f5732 | 2011-10-25 03:07:23 +0000 | [diff] [blame] | 206 | ln -sfT $(basename ${BUILD_DIR}) ${LINK_NAME} |
Olof Johansson | 58f25cc | 2010-08-04 21:18:49 -0700 | [diff] [blame] | 207 | |
Liam McLoughlin | 5b37c54 | 2012-08-16 11:09:37 -0700 | [diff] [blame] | 208 | echo "Done. Image(s) created in ${BUILD_DIR}" |
Chris Sosa | c9422fa | 2012-03-05 15:58:07 -0800 | [diff] [blame] | 209 | |
| 210 | # Print out the images we generated. |
| 211 | if should_build_image ${CHROMEOS_BASE_IMAGE_NAME}; then |
| 212 | echo "Non-developer Chromium OS image created as ${PRISTINE_IMAGE_NAME}" |
| 213 | fi |
| 214 | if should_build_image ${CHROMEOS_FACTORY_SHIM_NAME}; then |
| 215 | echo "Chromium OS Factory install shim created as ${PRISTINE_IMAGE_NAME}" |
| 216 | fi |
| 217 | if should_build_image ${CHROMEOS_DEVELOPER_IMAGE_NAME}; then |
Chris Sosa | b0f5732 | 2011-10-25 03:07:23 +0000 | [diff] [blame] | 218 | echo "Developer image created as ${CHROMEOS_DEVELOPER_IMAGE_NAME}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 219 | fi |
Chris Sosa | c9422fa | 2012-03-05 15:58:07 -0800 | [diff] [blame] | 220 | if should_build_image ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then |
Vince Laviano | 6aebf31 | 2011-06-01 15:27:31 -0700 | [diff] [blame] | 221 | echo "Factory test image created as ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}" |
Chris Sosa | c9422fa | 2012-03-05 15:58:07 -0800 | [diff] [blame] | 222 | fi |
| 223 | if should_build_image ${CHROMEOS_TEST_IMAGE_NAME}; then |
Vince Laviano | 6aebf31 | 2011-06-01 15:27:31 -0700 | [diff] [blame] | 224 | echo "Test image created as ${CHROMEOS_TEST_IMAGE_NAME}" |
| 225 | fi |
Nick Sanders | 8ab729a | 2010-06-16 03:15:17 -0700 | [diff] [blame] | 226 | |
Matt Tennant | 0a9d32d | 2012-07-30 16:51:37 -0700 | [diff] [blame] | 227 | command_completed |
Nick Sanders | d250927 | 2010-06-16 03:50:04 -0700 | [diff] [blame] | 228 | |
Gilad Arnold | a7536ef | 2012-06-20 18:43:39 -0700 | [diff] [blame] | 229 | cat << EOF |
| 230 | To copy the image to a USB key, use: |
| 231 | ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} |
| 232 | To convert it to a VMWare image, use: |
| 233 | ./image_to_vm.sh --from=${OUTSIDE_OUTPUT_DIR} --board=${BOARD} |
| 234 | EOF |