blob: d96ddf8270121cefadbca44d8f37232af1d8a793 [file] [log] [blame]
J. Richard Barnette84477772011-07-25 13:41:33 -07001#!/bin/bash
Bill Richardsonc09b94f2010-03-15 11:40:30 -07002
Darin Petkov61173f62011-04-29 10:24:26 -07003# Copyright (c) 2011 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
J. Richard Barnette84477772011-07-25 13:41:33 -070012SCRIPT_ROOT=$(dirname "$0")
13. "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1
Bill Richardsonc09b94f2010-03-15 11:40:30 -070014
Greg Spencer798d75f2011-02-01 22:04:49 -080015
Don Garrette0020b12010-06-17 15:55:35 -070016DEFINE_string board "${DEFAULT_BOARD}" \
Bill Richardsonc09b94f2010-03-15 11:40:30 -070017 "The board to build an image for."
18DEFINE_string build_root "/build" \
19 "The root location for board sysroots."
20DEFINE_integer build_attempt 1 \
21 "The build attempt for this image build."
22DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/images" \
23 "Directory in which to place image result directories (named by version)"
David Jamesffede3b2010-09-07 14:22:38 -070024DEFINE_boolean eclean ${FLAGS_TRUE} \
25 "Perform eclean-<board> -d as part of this script to remove obsolete packages"
Don Garrette0020b12010-06-17 15:55:35 -070026DEFINE_boolean replace ${FLAGS_FALSE} \
Bill Richardsonc09b94f2010-03-15 11:40:30 -070027 "Overwrite existing output, if any."
Don Garrette0020b12010-06-17 15:55:35 -070028DEFINE_boolean withdev ${FLAGS_TRUE} \
Bill Richardsonc09b94f2010-03-15 11:40:30 -070029 "Include useful developer friendly utilities in the image."
Don Garrette0020b12010-06-17 15:55:35 -070030DEFINE_boolean installmask ${FLAGS_TRUE} \
Bill Richardsonc09b94f2010-03-15 11:40:30 -070031 "Use INSTALL_MASK to shrink the resulting image."
32DEFINE_integer jobs -1 \
33 "How many packages to build in parallel at maximum."
Don Garrette0020b12010-06-17 15:55:35 -070034DEFINE_boolean statefuldev ${FLAGS_TRUE} \
Chris Sosa4bffb8b2010-04-07 17:23:54 -070035 "Install development packages on stateful partition rather than the rootfs"
Vince Laviano6aebf312011-06-01 15:27:31 -070036DEFINE_boolean test ${FLAGS_FALSE} \
Hung-Te Lin54a83b72011-06-30 12:00:55 +080037 "Modify the image for automated testing"
Vince Laviano6aebf312011-06-01 15:27:31 -070038DEFINE_boolean factory ${FLAGS_FALSE} \
39 "Modify the image for manufacturing testing"
Don Garrette0020b12010-06-17 15:55:35 -070040DEFINE_boolean factory_install ${FLAGS_FALSE} \
Tom Wai-Hong Tamf87a3672010-05-17 16:06:33 +080041 "Build a smaller image to overlay the factory install shim on; this argument \
42is also required in image_to_usb."
Zelidrag Hornung1d12c1a2010-06-02 10:20:29 -070043DEFINE_integer rootfs_partition_size 1024 \
Will Drewryd253bad2010-08-17 14:09:41 -050044 "rootfs partition size in MiBs."
Andrew de los Reyes0eb6d762010-11-01 18:27:53 -070045DEFINE_integer rootfs_size 850 \
Will Drewryd253bad2010-08-17 14:09:41 -050046 "rootfs filesystem size in MiBs."
Will Drewry78992a32010-07-21 14:02:20 -050047# ceil(0.1 * rootfs_size) is a good minimum.
48DEFINE_integer rootfs_hash_pad 8 \
Will Drewryd253bad2010-08-17 14:09:41 -050049 "MiBs reserved at the end of the rootfs image."
Eric Li5cf288f2010-06-28 12:46:26 -070050DEFINE_integer statefulfs_size 1024 \
Will Drewryd253bad2010-08-17 14:09:41 -050051 "stateful filesystem size in MiBs."
David James03668642010-07-28 17:08:29 -070052DEFINE_boolean fast ${DEFAULT_FAST} \
53 "Call many emerges in parallel"
Will Drewry32d8c112010-10-11 15:37:17 -050054DEFINE_string boot_args "noinitrd" \
55 "Additional boot arguments to pass to the commandline"
Nick Sandersf2dee6c2010-07-01 00:21:32 -070056
Will Drewry4a675e12010-07-03 13:35:02 -050057DEFINE_string usb_disk /dev/sdb3 \
58 "Path syslinux should use to do a usb boot. Default: /dev/sdb3"
59
Will Drewry12f14ce2010-08-17 17:27:16 -050060DEFINE_boolean enable_rootfs_verification ${FLAGS_TRUE} \
Will Drewry1670d482010-07-09 13:08:38 -070061 "Default all bootloaders to use kernel-based root fs integrity checking."
Will Drewryd07f61d2011-01-12 10:39:54 -060062DEFINE_integer verity_error_behavior 3 \
Will Drewry137eab62010-11-04 22:06:41 -050063 "Kernel verified boot error behavior (0: I/O errors, 1: panic, 2: nothing, \
Will Drewryd07f61d2011-01-12 10:39:54 -0600643: cros) Default: 3"
Will Drewry52c40f82010-10-06 14:54:38 -050065DEFINE_integer verity_max_ios -1 \
66 "Number of outstanding I/O operations dm-verity caps at. Default: -1"
Will Drewry1670d482010-07-09 13:08:38 -070067DEFINE_string verity_algorithm "sha1" \
68 "Cryptographic hash algorithm used for kernel vboot. Default : sha1"
David Rochbergcf932372011-06-30 21:25:08 -040069DEFINE_boolean standard_backdoor ${FLAGS_TRUE} \
70 "Install standard backdoor credentials for testing"
David James4dd4c542011-08-10 10:19:47 -070071DEFINE_string symlink "latest" \
72 "Symlink name to use for this image."
Bill Richardsonc09b94f2010-03-15 11:40:30 -070073
Che-Liang Chiou611d5b72011-07-27 16:03:26 +080074# TODO(clchiou): Remove this flag after buildbot is fixed
75DEFINE_boolean crosbug12352_arm_kernel_signing ${FLAGS_TRUE} \
76 "A dummy this flag for preventing buildbot fail"
77
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,
83# so will die prematurely if 'set -e' is specified before now.
84set -e
85
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
89
J. Richard Barnettea308b392011-08-29 13:53:34 -070090# N.B. Ordering matters for some of the libraries below, because
91# some of the files contain initialization used by later files.
J. Richard Barnetteaaef7612011-08-11 17:10:28 -070092. "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1
93. "${BUILD_LIBRARY_DIR}/build_gpt.sh" || exit 1
J. Richard Barnette5f9dbe42011-08-22 14:31:33 -070094. "${BUILD_LIBRARY_DIR}/mount_gpt_util.sh" || exit 1
J. Richard Barnettea308b392011-08-29 13:53:34 -070095. "${BUILD_LIBRARY_DIR}/build_image_util.sh" || exit 1
96. "${BUILD_LIBRARY_DIR}/base_image_util.sh" || exit 1
97. "${BUILD_LIBRARY_DIR}/dev_image_util.sh" || exit 1
98. "${BUILD_LIBRARY_DIR}/test_image_util.sh" || exit 1
J. Richard Barnetteaaef7612011-08-11 17:10:28 -070099. "${BUILD_LIBRARY_DIR}/test_image_content.sh" || exit 1
J. Richard Barnettee4e3dec2011-08-08 16:35:02 -0700100
Vince Laviano6aebf312011-06-01 15:27:31 -0700101# Look at flags to determine which image types we should build
J. Richard Barnetteeb5246f2011-04-08 10:34:31 -0700102if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]; then
Vince Laviano6aebf312011-06-01 15:27:31 -0700103 if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then
104 info "Incompatible flags: --factory and --factory_install cannot both be \
105set to True. Resetting --factory to False."
106 FLAGS_factory=${FLAGS_FALSE}
107 fi
108 if [ ${FLAGS_test} -eq ${FLAGS_TRUE} ]; then
109 info "Incompatible flags: --test and --factory_install cannot both be \
110set to True. Resetting --test to False."
111 FLAGS_test=${FLAGS_FALSE}
112 fi
Vince Laviano96d116d2011-03-17 11:32:07 -0700113 # Disable --withdev flag when --factory_install is set to True. Otherwise, the
Nick Sandersae26a5c2010-08-30 21:59:50 -0700114 # dev image produced will be based on install shim, rather than a pristine
115 # image
J. Richard Barnetteeb5246f2011-04-08 10:34:31 -0700116 if [ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]; then
Vince Laviano96d116d2011-03-17 11:32:07 -0700117 info "Incompatible flags: --withdev and --factory_install cannot both be \
118set to True. Resetting --withdev to False."
Nick Sandersae26a5c2010-08-30 21:59:50 -0700119 FLAGS_withdev=${FLAGS_FALSE}
120 fi
Vince Laviano6aebf312011-06-01 15:27:31 -0700121fi
122if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then
123 if [ ${FLAGS_test} -eq ${FLAGS_FALSE} ]; then
124 info "Incompatible flags: --factory implies --test. Resetting --test to \
125True."
126 FLAGS_test=${FLAGS_TRUE}
127 fi
128fi
129if [ ${FLAGS_test} -eq ${FLAGS_TRUE} ]; then
130 if [ ${FLAGS_withdev} -eq ${FLAGS_FALSE} ]; then
131 info "Incompatible flags: --test implies --withdev. Resetting --withdev \
132to True."
133 FLAGS_withdev=${FLAGS_TRUE}
134 fi
135fi
Nick Sandersae26a5c2010-08-30 21:59:50 -0700136
Vince Laviano6aebf312011-06-01 15:27:31 -0700137# Reduce the size of factory install shim.
138if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]; then
Nick Sandersae26a5c2010-08-30 21:59:50 -0700139 # TODO: Build a separated ebuild for the install shim to reduce size.
140 INSTALL_MASK="${INSTALL_MASK} ${FACTORY_INSTALL_MASK}"
141
142 info "Fixing the rootfs size at 300 MiB for install shim"
143 FLAGS_rootfs_size=280
144 FLAGS_rootfs_partition_size=300
145 info "Fixing the statefulfs size at 140 MiB for install shim"
146 FLAGS_statefulfs_size=140
147fi
148
J. Richard Barnetteeb5246f2011-04-08 10:34:31 -0700149if [ $((FLAGS_rootfs_size + FLAGS_rootfs_hash_pad)) -gt \
150 ${FLAGS_rootfs_partition_size} ] ; then
Nick Sandersae26a5c2010-08-30 21:59:50 -0700151 die "rootfs ($((FLAGS_rootfs_size + FLAGS_rootfs_hash_pad)) MiB) is \
152bigger than partition (${FLAGS_rootfs_partition_size} MiB)."
Tan Gao843b70a2010-08-17 09:41:48 -0700153fi
154
Chris Sosa9673f3b2010-05-18 13:24:40 -0700155# If we are creating a developer image, also create a pristine image with a
156# different name.
Vince Laviano6aebf312011-06-01 15:27:31 -0700157# TODO(vlaviano): fix all image names to match those in uploaded archive
Chris Sosa9673f3b2010-05-18 13:24:40 -0700158DEVELOPER_IMAGE_NAME=
159PRISTINE_IMAGE_NAME=chromiumos_image.bin
J. Richard Barnetteeb5246f2011-04-08 10:34:31 -0700160if [ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]; then
Chris Sosa9673f3b2010-05-18 13:24:40 -0700161 PRISTINE_IMAGE_NAME=chromiumos_base_image.bin
162 DEVELOPER_IMAGE_NAME=chromiumos_image.bin
Vince Laviano96d116d2011-03-17 11:32:07 -0700163# Rename pristine image for factory install shim
J. Richard Barnetteeb5246f2011-04-08 10:34:31 -0700164elif [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]; then
Nick Sandersae26a5c2010-08-30 21:59:50 -0700165 PRISTINE_IMAGE_NAME=factory_install_shim.bin
Tan Gao843b70a2010-08-17 09:41:48 -0700166fi
167
David James868d7bb2010-06-24 21:48:14 -0700168PRISTINE_IMG="${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}"
169DEVELOPER_IMG="${OUTPUT_DIR}/${DEVELOPER_IMAGE_NAME}"
Vince Laviano6aebf312011-06-01 15:27:31 -0700170TEST_IMG="${OUTPUT_DIR}/${CHROMEOS_TEST_IMAGE_NAME}"
171FACTORY_IMG="${OUTPUT_DIR}/${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700172
Don Garrett3f41e152010-06-21 14:54:34 -0700173ROOT_FS_DIR="${OUTPUT_DIR}/rootfs"
Don Garrett3f41e152010-06-21 14:54:34 -0700174STATEFUL_FS_DIR="${OUTPUT_DIR}/stateful_partition"
Don Garrett3f41e152010-06-21 14:54:34 -0700175ESP_FS_DIR=${OUTPUT_DIR}/esp
176
Will Drewry7ab698d2010-08-05 13:57:52 -0500177DEVKEYSDIR="/usr/share/vboot/devkeys"
178
Don Garrett3f41e152010-06-21 14:54:34 -0700179# ${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
181# translate to /usr/local.
182DEV_IMAGE_ROOT="${STATEFUL_FS_DIR}/dev_image"
183
J. Richard Barnettea308b392011-08-29 13:53:34 -0700184# Perform an eclean to remove packages which are not installed
185if [ $FLAGS_eclean -eq $FLAGS_TRUE ]; then
186 eclean-$BOARD -d packages
Will Drewry12f14ce2010-08-17 17:27:16 -0500187fi
188
J. Richard Barnettea308b392011-08-29 13:53:34 -0700189check_blacklist
190
191# Check that the build root is sane.
192"${BUILD_LIBRARY_DIR}/test_build_root" --root="${BOARD_ROOT}"
193
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700194# Hack to fix bug where x86_64 CHOST line gets incorrectly added.
195# ToDo(msb): remove this hack.
196PACKAGES_FILE="${BOARD_ROOT}/packages/Packages"
197sudo sed -e "s/CHOST: x86_64-pc-linux-gnu//" -i "${PACKAGES_FILE}"
198
199# Handle existing directory.
Don Garrette0020b12010-06-17 15:55:35 -0700200if [[ -e "${OUTPUT_DIR}" ]]; then
201 if [[ ${FLAGS_replace} -eq ${FLAGS_TRUE} ]]; then
202 sudo rm -rf "${OUTPUT_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700203 else
Don Garrette0020b12010-06-17 15:55:35 -0700204 echo "Directory ${OUTPUT_DIR} already exists."
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700205 echo "Use --build_attempt option to specify an unused attempt."
206 echo "Or use --replace if you want to overwrite this directory."
207 exit 1
208 fi
209fi
210
J. Richard Barnettea308b392011-08-29 13:53:34 -0700211# Create the output directory and temporary mount points.
Don Garrett3f41e152010-06-21 14:54:34 -0700212mkdir -p "${OUTPUT_DIR}"
J. Richard Barnettea308b392011-08-29 13:53:34 -0700213mkdir -p "${ROOT_FS_DIR}" "${STATEFUL_FS_DIR}" "${ESP_FS_DIR}"
Don Garrett3f41e152010-06-21 14:54:34 -0700214
Will Drewry7ab698d2010-08-05 13:57:52 -0500215# Create the boot.desc file which stores the build-time configuration
216# information needed for making the image bootable after creation with
217# cros_make_image_bootable.
218create_boot_desc
219
J. Richard Barnettea308b392011-08-29 13:53:34 -0700220create_base_image "$PRISTINE_IMAGE_NAME"
Tan Gao843b70a2010-08-17 09:41:48 -0700221
Will Drewry4a675e12010-07-03 13:35:02 -0500222
Che-Liang Chioue51bdf22011-07-26 21:19:24 +0800223BOOT_FLAG=
224if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]; then
225 BOOT_FLAG="-b 1" # BOOT_FLAG_DEVELOPER value defined in load_kernel_fw.h
226 info "--factory_install set, pass BOOT_FLAG_DEVELOPER flag to \
Vince Laviano96d116d2011-03-17 11:32:07 -0700227load_kernel_test"
Che-Liang Chiou451f36e2011-07-21 19:53:37 +0800228fi
Che-Liang Chiou2d2e8252011-06-18 17:38:59 -0700229
Che-Liang Chioue51bdf22011-07-26 21:19:24 +0800230# Verify the final image.
231load_kernel_test "${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}" \
232 "${DEVKEYSDIR}/recovery_key.vbpubk" ${BOOT_FLAG}
233
Don Garrette0020b12010-06-17 15:55:35 -0700234# Create a developer image based on the chromium os base image.
J. Richard Barnettea308b392011-08-29 13:53:34 -0700235if [ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]; then
236 copy_image "$PRISTINE_IMG" "$DEVELOPER_IMG"
237 install_dev_packages "$DEVELOPER_IMAGE_NAME"
Bill Richardson6ed13582010-06-16 21:38:15 -0700238fi
239
Vince Laviano6aebf312011-06-01 15:27:31 -0700240# Create a test or factory test image if desired
J. Richard Barnettea308b392011-08-29 13:53:34 -0700241if [ ${FLAGS_test} -eq ${FLAGS_TRUE} ]; then
242 copy_image "$DEVELOPER_IMG" "$TEST_IMG"
243 mod_image_for_test "${TEST_IMG}"
Vince Laviano6aebf312011-06-01 15:27:31 -0700244fi
245
Dmitry Polukhin0a649b52011-02-24 13:02:52 +0300246rmdir "${ROOT_FS_DIR}" "${STATEFUL_FS_DIR}" "${ESP_FS_DIR}"
Bill Richardson67956222010-05-28 15:38:56 -0700247
Raja Aluriaeb10482010-12-10 13:03:09 -0800248# Generating AU generator zip file to run outside chroot
249generate_au_zip || echo "Failed generating AU zip file - ignoring Error..."
David James4dd4c542011-08-10 10:19:47 -0700250
251# Create a named symlink.
252LINK_NAME="${FLAGS_output_root}/${BOARD}/${FLAGS_symlink}"
253ln -sfT $(basename ${OUTPUT_DIR}) ${LINK_NAME}
Olof Johansson58f25cc2010-08-04 21:18:49 -0700254
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700255echo "Done. Image created in ${OUTPUT_DIR}"
Don Garrette0020b12010-06-17 15:55:35 -0700256echo "Chromium OS image created as ${PRISTINE_IMAGE_NAME}"
J. Richard Barnetteeb5246f2011-04-08 10:34:31 -0700257if [ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]; then
Don Garrette0020b12010-06-17 15:55:35 -0700258 echo "Developer image created as ${DEVELOPER_IMAGE_NAME}"
Chris Sosa9673f3b2010-05-18 13:24:40 -0700259fi
Vince Laviano6aebf312011-06-01 15:27:31 -0700260if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then
261 echo "Factory test image created as ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"
262elif [ ${FLAGS_test} -eq ${FLAGS_TRUE} ]; then
263 echo "Test image created as ${CHROMEOS_TEST_IMAGE_NAME}"
264fi
Nick Sanders8ab729a2010-06-16 03:15:17 -0700265
Nick Sandersd2509272010-06-16 03:50:04 -0700266print_time_elapsed
267
Hung-Te Lin2ffe2be2010-10-05 08:15:40 +0800268echo "To copy to USB keyfob, do something like:"
Daniel Eratdd9818a2010-04-26 09:16:44 -0700269echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX"
Will Drewryefce6682010-07-23 19:43:27 -0500270echo "To convert to VMWare image, INSIDE the chroot, do something like:"
Olof Johansson1f5e84d2010-08-24 20:26:49 -0500271echo " ./image_to_vm.sh --from=${OUTSIDE_OUTPUT_DIR} --board=${BOARD}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700272echo "from the scripts directory where you entered the chroot."