blob: b03b6f4726b16cd01315b3a7f0373887bef71eb4 [file] [log] [blame]
J. Richard Barnette84477772011-07-25 13:41:33 -07001#!/bin/bash
Bill Richardsonc09b94f2010-03-15 11:40:30 -07002
Peter Mayo82975f92012-05-01 11:03:31 -04003# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Bill Richardsonc09b94f2010-03-15 11:40:30 -07004# 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 Harringaa13ea42012-03-15 18:31:03 -070012SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
J. Richard Barnette84477772011-07-25 13:41:33 -070013. "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1
Bill Richardsonc09b94f2010-03-15 11:40:30 -070014
David James855afb72012-03-14 20:04:59 -070015# Developer-visible flags.
Liam McLoughlin12a9a842012-10-10 10:37:06 -040016DEFINE_string adjust_part "" \
17 "Adjustments to apply to the partition table"
Don Garrette0020b12010-06-17 15:55:35 -070018DEFINE_string board "${DEFAULT_BOARD}" \
Bill Richardsonc09b94f2010-03-15 11:40:30 -070019 "The board to build an image for."
David James855afb72012-03-14 20:04:59 -070020DEFINE_string boot_args "noinitrd" \
21 "Additional boot arguments to pass to the commandline"
Paul Taysom00df6f62012-11-20 12:35:40 -080022DEFINE_boolean enable_bootcache ${FLAGS_FALSE} \
23 "Default all bootloaders to NOT use boot cache."
David James855afb72012-03-14 20:04:59 -070024DEFINE_boolean enable_rootfs_verification ${FLAGS_TRUE} \
25 "Default all bootloaders to use kernel-based root fs integrity checking."
Bill Richardsonc09b94f2010-03-15 11:40:30 -070026DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/images" \
27 "Directory in which to place image result directories (named by version)"
Liam McLoughlin5b37c542012-08-16 11:09:37 -070028DEFINE_string disk_layout "default" \
Liam McLoughlinb78a7c32012-11-06 20:19:05 -050029 "The disk layout type to use for this image."
David Rochbergcf932372011-06-30 21:25:08 -040030DEFINE_boolean standard_backdoor ${FLAGS_TRUE} \
31 "Install standard backdoor credentials for testing"
David James855afb72012-03-14 20:04:59 -070032DEFINE_string usb_disk /dev/sdb3 \
33 "Path syslinux should use to do a usb boot. Default: /dev/sdb3"
Che-Liang Chiou611d5b72011-07-27 16:03:26 +080034
Paul Taysom00df6f62012-11-20 12:35:40 -080035FLAGS_bootcache_use_board_default=${FLAGS_TRUE}
36case " $* " in
37 *" --enable_bootcache "*|\
38 *" --noenable_bootcache "*)
39 FLAGS_bootcache_use_board_default=${FLAGS_FALSE}
40 ;;
41esac
42
Chris Sosaef4a6452011-10-27 16:01:07 -070043FLAGS_HELP="USAGE: build_image [flags] [list of images to build].
44This script is used to build a Chromium OS image. Chromium OS comes in many
45different forms. This scripts can be used to build the following:
46
47base - Pristine Chromium OS image. As similar to Chrome OS as possible.
48dev - Developer image. Like base but with additional developer packages.
49test - Like dev, but with additional test specific packages and can be easily
50 used for automated testing using scripts like run_remote_tests, etc.
51factory_test - Like test but with extra packages and modifications used to
52 test images in a factory setting. Cannot be built along with a test image.
53factory_install - Install shim for bootstrapping the factory test process.
54 Cannot be built along with any other image.
55
David James855afb72012-03-14 20:04:59 -070056Examples:
Chris Sosaef4a6452011-10-27 16:01:07 -070057
58build_image --board=<board> dev test - builds developer and test images.
59build_image --board=<board> factory_install - builds a factory install shim.
60...
61"
David James855afb72012-03-14 20:04:59 -070062show_help_if_requested "$@"
63
64# The following options are advanced options, only available to those willing
65# to read the source code. They are not shown in help output, since they are
66# not needed for the typical developer workflow.
David James855afb72012-03-14 20:04:59 -070067DEFINE_integer build_attempt 1 \
68 "The build attempt for this image build."
69DEFINE_integer jobs -1 \
70 "How many packages to build in parallel at maximum."
71DEFINE_boolean replace ${FLAGS_FALSE} \
72 "Overwrite existing output, if any."
73DEFINE_string symlink "latest" \
74 "Symlink name to use for this image."
Liam McLoughlin07279032012-06-25 17:31:11 -070075DEFINE_string version "" \
76 "Overrides version number in name to this version."
Chris Sosaef4a6452011-10-27 16:01:07 -070077
Bill Richardsonc09b94f2010-03-15 11:40:30 -070078# Parse command line.
79FLAGS "$@" || exit 1
80eval set -- "${FLAGS_ARGV}"
81
82# Only now can we die on error. shflags functions leak non-zero error codes,
Brian Harring7f175a52012-03-02 05:37:00 -080083# so will die prematurely if 'switch_to_strict_mode' is specified before now.
84switch_to_strict_mode
Bill Richardsonc09b94f2010-03-15 11:40:30 -070085
J. Richard Barnettee4e3dec2011-08-08 16:35:02 -070086# Determine build version.
87OVERLAY_CHROMEOS_DIR="${SRC_ROOT}/third_party/chromiumos-overlay/chromeos"
88. "${OVERLAY_CHROMEOS_DIR}/config/chromeos_version.sh" || exit 1
J. Richard Barnettea308b392011-08-29 13:53:34 -070089# N.B. Ordering matters for some of the libraries below, because
90# some of the files contain initialization used by later files.
J. Richard Barnetteaaef7612011-08-11 17:10:28 -070091. "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1
Liam McLoughlin5b37c542012-08-16 11:09:37 -070092. "${BUILD_LIBRARY_DIR}/disk_layout_util.sh" || exit 1
J. Richard Barnette5f9dbe42011-08-22 14:31:33 -070093. "${BUILD_LIBRARY_DIR}/mount_gpt_util.sh" || exit 1
J. Richard Barnettea308b392011-08-29 13:53:34 -070094. "${BUILD_LIBRARY_DIR}/build_image_util.sh" || exit 1
95. "${BUILD_LIBRARY_DIR}/base_image_util.sh" || exit 1
96. "${BUILD_LIBRARY_DIR}/dev_image_util.sh" || exit 1
97. "${BUILD_LIBRARY_DIR}/test_image_util.sh" || exit 1
J. Richard Barnetteaaef7612011-08-11 17:10:28 -070098. "${BUILD_LIBRARY_DIR}/test_image_content.sh" || exit 1
J. Richard Barnettee4e3dec2011-08-08 16:35:02 -070099
Chris Sosab0f57322011-10-25 03:07:23 +0000100parse_build_image_args
Peter Mayo82975f92012-05-01 11:03:31 -0400101
David James18a9c252012-10-19 16:16:38 -0700102for overlay in $(cros_list_overlays --board "$BOARD"); do
Liam McLoughlind606ee22012-07-03 16:48:57 -0700103 setup_sh="${overlay}/scripts/board_specific_setup.sh"
104 if [[ -e ${setup_sh} ]]; then
105 source "${setup_sh}"
106 fi
107done
108
Liam McLoughlin5b37c542012-08-16 11:09:37 -0700109# TODO: <prebuild hook>
Peter Mayo82975f92012-05-01 11:03:31 -0400110
Chris Sosa4299eb92011-11-01 12:54:01 -0700111# Tweak flags, configure extra USE flags, and add packages for the factory
112# install shim.
113EXTRA_PACKAGES=""
Chris Sosac9422fa2012-03-05 15:58:07 -0800114if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then
Nick Sandersae26a5c2010-08-30 21:59:50 -0700115 # TODO: Build a separated ebuild for the install shim to reduce size.
Hung-Te Lind32c59f2012-01-19 19:54:01 +0800116 INSTALL_MASK="${FACTORY_SHIM_INSTALL_MASK}"
Nick Sandersae26a5c2010-08-30 21:59:50 -0700117
Jon Salz67145df2011-10-20 14:05:06 +0800118 # Add the cros_factory_install boot arg.
119 FLAGS_boot_args="${FLAGS_boot_args} cros_factory_install"
Chris Sosa4299eb92011-11-01 12:54:01 -0700120
121 # Factory install needs to have the factory installer added.
122 EXTRA_PACKAGES="${EXTRA_PACKAGES} chromeos-base/chromeos-factoryinstall"
Hung-Te Lin7119cb12012-03-07 22:29:13 +0800123 # On x86/amd64, we boot the factory install shim from an SD card using
124 # initramfs for our root. On ARM, we boot the factory install shim over the
125 # network, so we don't require initramfs, but we do require fbconsole to fix
126 # a display driver bug.
127 if [ "${ARCH}" = "x86" -o "${ARCH}" = "amd64" ] ; then
Vic Yang40514052012-05-22 14:27:40 +0800128 export USE="${USE} initramfs vfat"
Chris Sosa4299eb92011-11-01 12:54:01 -0700129 fi
130 # CONFIG_BLK_DEV_RAM is disabled by default.
131 # But tftp install needs it to mount rootfs in ram
132 if [ "${ARCH}" = "arm" ] ; then
133 export USE="${USE} fbconsole blkdevram"
134 fi
Nick Sandersae26a5c2010-08-30 21:59:50 -0700135fi
136
Kees Cook8df86b22012-09-28 18:15:49 -0700137if should_build_image ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then
138 # Disable module restrictions on factory test image to allow for
139 # external third party drivers in /usr/local.
140 FLAGS_boot_args="${FLAGS_boot_args} lsm.module_locking=0"
141fi
142
Liam McLoughlin5b37c542012-08-16 11:09:37 -0700143# TODO: </prebuild hook>
Tan Gao843b70a2010-08-17 09:41:48 -0700144
Chris Sosa9673f3b2010-05-18 13:24:40 -0700145# If we are creating a developer image, also create a pristine image with a
146# different name.
Chris Sosa93e7b782012-01-03 15:52:12 -0800147PRISTINE_IMAGE_NAME=
Chris Sosac9422fa2012-03-05 15:58:07 -0800148if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then
Chris Sosab0f57322011-10-25 03:07:23 +0000149 PRISTINE_IMAGE_NAME=${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}
Chris Sosa93e7b782012-01-03 15:52:12 -0800150else
Chris Sosac9422fa2012-03-05 15:58:07 -0800151 PRISTINE_IMAGE_NAME=${CHROMEOS_BASE_IMAGE_NAME}
Tan Gao843b70a2010-08-17 09:41:48 -0700152fi
153
Will Drewry7ab698d2010-08-05 13:57:52 -0500154DEVKEYSDIR="/usr/share/vboot/devkeys"
155
J. Richard Barnette8e480952011-08-30 16:00:59 -0700156eclean-$BOARD -d packages
Will Drewry12f14ce2010-08-17 17:27:16 -0500157
Liam McLoughlind606ee22012-07-03 16:48:57 -0700158if [[ ${skip_blacklist_check} -ne 1 ]]; then
159 check_blacklist
160fi
J. Richard Barnettea308b392011-08-29 13:53:34 -0700161
162# Check that the build root is sane.
Liam McLoughlind606ee22012-07-03 16:48:57 -0700163if [[ ${skip_test_build_root} -ne 1 ]]; then
164 "${BUILD_LIBRARY_DIR}/test_build_root" --root="${BOARD_ROOT}"
165fi
J. Richard Barnettea308b392011-08-29 13:53:34 -0700166
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700167# Hack to fix bug where x86_64 CHOST line gets incorrectly added.
168# ToDo(msb): remove this hack.
169PACKAGES_FILE="${BOARD_ROOT}/packages/Packages"
170sudo sed -e "s/CHOST: x86_64-pc-linux-gnu//" -i "${PACKAGES_FILE}"
171
172# Handle existing directory.
Chris Sosab0f57322011-10-25 03:07:23 +0000173if [[ -e "${BUILD_DIR}" ]]; then
Don Garrette0020b12010-06-17 15:55:35 -0700174 if [[ ${FLAGS_replace} -eq ${FLAGS_TRUE} ]]; then
Chris Sosab0f57322011-10-25 03:07:23 +0000175 sudo rm -rf "${BUILD_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700176 else
Chris Sosab0f57322011-10-25 03:07:23 +0000177 error "Directory ${BUILD_DIR} already exists."
178 error "Use --build_attempt option to specify an unused attempt."
Brian Harring7f175a52012-03-02 05:37:00 -0800179 error "Or use --replace if you want to overwrite this directory."
180 die "Unwilling to overwrite ${BUILD_DIR}."
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700181 fi
182fi
183
J. Richard Barnettea308b392011-08-29 13:53:34 -0700184# Create the output directory and temporary mount points.
Chris Sosab0f57322011-10-25 03:07:23 +0000185mkdir -p "${BUILD_DIR}"
Don Garrett3f41e152010-06-21 14:54:34 -0700186
Liam McLoughlin5b37c542012-08-16 11:09:37 -0700187# Create the base image.
Paul Taysom00df6f62012-11-20 12:35:40 -0800188create_base_image ${PRISTINE_IMAGE_NAME} ${FLAGS_enable_rootfs_verification} \
189 ${FLAGS_enable_bootcache}
Tan Gao843b70a2010-08-17 09:41:48 -0700190
Liam McLoughlind606ee22012-07-03 16:48:57 -0700191# Running board-specific setup if any exists.
192if type board_setup &>/dev/null; then
193 board_setup "${BUILD_DIR}/${PRISTINE_IMAGE_NAME}"
194fi
195
Chris Sosac9422fa2012-03-05 15:58:07 -0800196# Create a developer image if an image that is based on it is requested.
197if should_build_image ${CHROMEOS_DEVELOPER_IMAGE_NAME} \
198 ${CHROMEOS_TEST_IMAGE_NAME} ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then
Chris Sosab0f57322011-10-25 03:07:23 +0000199 copy_image ${CHROMEOS_BASE_IMAGE_NAME} ${CHROMEOS_DEVELOPER_IMAGE_NAME}
Chris Sosac9422fa2012-03-05 15:58:07 -0800200 install_dev_packages ${CHROMEOS_DEVELOPER_IMAGE_NAME}
Bill Richardson6ed13582010-06-16 21:38:15 -0700201fi
202
Chris Sosac9422fa2012-03-05 15:58:07 -0800203# From a developer image create a test|factory_test image.
204if should_build_image ${CHROMEOS_TEST_IMAGE_NAME}; then
205 copy_image ${CHROMEOS_DEVELOPER_IMAGE_NAME} ${CHROMEOS_TEST_IMAGE_NAME}
206 mod_image_for_test ${CHROMEOS_TEST_IMAGE_NAME}
207fi
208if should_build_image ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then
Chris Sosab0f57322011-10-25 03:07:23 +0000209 copy_image ${CHROMEOS_DEVELOPER_IMAGE_NAME} \
210 ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}
211 mod_image_for_test ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}
Vince Laviano6aebf312011-06-01 15:27:31 -0700212fi
213
Raja Aluriaeb10482010-12-10 13:03:09 -0800214# Generating AU generator zip file to run outside chroot
215generate_au_zip || echo "Failed generating AU zip file - ignoring Error..."
David James4dd4c542011-08-10 10:19:47 -0700216
217# Create a named symlink.
218LINK_NAME="${FLAGS_output_root}/${BOARD}/${FLAGS_symlink}"
Chris Sosab0f57322011-10-25 03:07:23 +0000219ln -sfT $(basename ${BUILD_DIR}) ${LINK_NAME}
Olof Johansson58f25cc2010-08-04 21:18:49 -0700220
Liam McLoughlin5b37c542012-08-16 11:09:37 -0700221echo "Done. Image(s) created in ${BUILD_DIR}"
Chris Sosac9422fa2012-03-05 15:58:07 -0800222
223# Print out the images we generated.
224if should_build_image ${CHROMEOS_BASE_IMAGE_NAME}; then
225 echo "Non-developer Chromium OS image created as ${PRISTINE_IMAGE_NAME}"
226fi
227if should_build_image ${CHROMEOS_FACTORY_SHIM_NAME}; then
228 echo "Chromium OS Factory install shim created as ${PRISTINE_IMAGE_NAME}"
229fi
230if should_build_image ${CHROMEOS_DEVELOPER_IMAGE_NAME}; then
Chris Sosab0f57322011-10-25 03:07:23 +0000231 echo "Developer image created as ${CHROMEOS_DEVELOPER_IMAGE_NAME}"
Chris Sosa9673f3b2010-05-18 13:24:40 -0700232fi
Chris Sosac9422fa2012-03-05 15:58:07 -0800233if should_build_image ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then
Vince Laviano6aebf312011-06-01 15:27:31 -0700234 echo "Factory test image created as ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"
Chris Sosac9422fa2012-03-05 15:58:07 -0800235fi
236if should_build_image ${CHROMEOS_TEST_IMAGE_NAME}; then
Vince Laviano6aebf312011-06-01 15:27:31 -0700237 echo "Test image created as ${CHROMEOS_TEST_IMAGE_NAME}"
238fi
Nick Sanders8ab729a2010-06-16 03:15:17 -0700239
Matt Tennant0a9d32d2012-07-30 16:51:37 -0700240command_completed
Nick Sandersd2509272010-06-16 03:50:04 -0700241
Gilad Arnolda7536ef2012-06-20 18:43:39 -0700242cat << EOF
243To copy the image to a USB key, use:
244 ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR}
245To convert it to a VMWare image, use:
246 ./image_to_vm.sh --from=${OUTSIDE_OUTPUT_DIR} --board=${BOARD}
247EOF