Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 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 |
| 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 | |
Greg Spencer | 798d75f | 2011-02-01 22:04:49 -0800 | [diff] [blame] | 12 | # Load common CrOS utilities. Inside the chroot this file is installed in |
| 13 | # /usr/lib/crosutils. Outside the chroot we find it relative to the script's |
| 14 | # location. |
| 15 | find_common_sh() { |
David James | 17d44e3 | 2011-02-08 14:48:51 -0800 | [diff] [blame^] | 16 | local common_paths=(/usr/lib/crosutils $(dirname "$0")) |
Greg Spencer | 798d75f | 2011-02-01 22:04:49 -0800 | [diff] [blame] | 17 | local path |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 18 | |
Greg Spencer | 798d75f | 2011-02-01 22:04:49 -0800 | [diff] [blame] | 19 | SCRIPT_ROOT= |
| 20 | for path in "${common_paths[@]}"; do |
David James | 17d44e3 | 2011-02-08 14:48:51 -0800 | [diff] [blame^] | 21 | local common="${path}/common.sh" |
| 22 | if ([ -r "${common}" ] && . "${common}" && [ -d "${SCRIPTS_DIR}" ]); then |
Greg Spencer | 798d75f | 2011-02-01 22:04:49 -0800 | [diff] [blame] | 23 | SCRIPT_ROOT=${path} |
| 24 | break |
| 25 | fi |
| 26 | done |
| 27 | } |
| 28 | |
| 29 | find_common_sh |
David James | 17d44e3 | 2011-02-08 14:48:51 -0800 | [diff] [blame^] | 30 | . "${SCRIPT_ROOT}/common.sh" || ! echo "Unable to load common.sh" || exit 1 |
Greg Spencer | 798d75f | 2011-02-01 22:04:49 -0800 | [diff] [blame] | 31 | |
| 32 | # Load functions and constants for chromeos-install |
| 33 | [ -f /usr/lib/installer/chromeos-common.sh ] && \ |
| 34 | INSTALLER_ROOT=/usr/lib/installer || \ |
| 35 | INSTALLER_ROOT=$(dirname "$(readlink -f "$0")") |
| 36 | |
| 37 | . "${INSTALLER_ROOT}/chromeos-common.sh" || \ |
| 38 | die "Unable to load chromeos-common.sh" |
| 39 | |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 40 | locate_gpt |
| 41 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 42 | # Script must be run inside the chroot. |
Greg Spencer | 798d75f | 2011-02-01 22:04:49 -0800 | [diff] [blame] | 43 | restart_in_chroot_if_needed "$@" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 44 | |
| 45 | get_default_board |
| 46 | |
| 47 | # Flags. |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 48 | DEFINE_string board "${DEFAULT_BOARD}" \ |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 49 | "The board to build an image for." |
| 50 | DEFINE_string build_root "/build" \ |
| 51 | "The root location for board sysroots." |
| 52 | DEFINE_integer build_attempt 1 \ |
| 53 | "The build attempt for this image build." |
| 54 | DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/images" \ |
| 55 | "Directory in which to place image result directories (named by version)" |
David James | ffede3b | 2010-09-07 14:22:38 -0700 | [diff] [blame] | 56 | DEFINE_boolean eclean ${FLAGS_TRUE} \ |
| 57 | "Perform eclean-<board> -d as part of this script to remove obsolete packages" |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 58 | DEFINE_boolean replace ${FLAGS_FALSE} \ |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 59 | "Overwrite existing output, if any." |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 60 | DEFINE_boolean withdev ${FLAGS_TRUE} \ |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 61 | "Include useful developer friendly utilities in the image." |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 62 | DEFINE_boolean installmask ${FLAGS_TRUE} \ |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 63 | "Use INSTALL_MASK to shrink the resulting image." |
| 64 | DEFINE_integer jobs -1 \ |
| 65 | "How many packages to build in parallel at maximum." |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 66 | DEFINE_boolean statefuldev ${FLAGS_TRUE} \ |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 67 | "Install development packages on stateful partition rather than the rootfs" |
Antoine Labour | e9e585f | 2010-04-01 15:57:57 -0700 | [diff] [blame] | 68 | DEFINE_string to "" \ |
| 69 | "The target image file or device" |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 70 | DEFINE_boolean factory_install ${FLAGS_FALSE} \ |
Tom Wai-Hong Tam | f87a367 | 2010-05-17 16:06:33 +0800 | [diff] [blame] | 71 | "Build a smaller image to overlay the factory install shim on; this argument \ |
| 72 | is also required in image_to_usb." |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 73 | DEFINE_boolean dev_install ${FLAGS_FALSE} \ |
| 74 | "Build a smaller image to overlay the dev recovery install shim on" |
Zelidrag Hornung | 1d12c1a | 2010-06-02 10:20:29 -0700 | [diff] [blame] | 75 | DEFINE_integer rootfs_partition_size 1024 \ |
Will Drewry | d253bad | 2010-08-17 14:09:41 -0500 | [diff] [blame] | 76 | "rootfs partition size in MiBs." |
Andrew de los Reyes | 0eb6d76 | 2010-11-01 18:27:53 -0700 | [diff] [blame] | 77 | DEFINE_integer rootfs_size 850 \ |
Will Drewry | d253bad | 2010-08-17 14:09:41 -0500 | [diff] [blame] | 78 | "rootfs filesystem size in MiBs." |
Will Drewry | 78992a3 | 2010-07-21 14:02:20 -0500 | [diff] [blame] | 79 | # ceil(0.1 * rootfs_size) is a good minimum. |
| 80 | DEFINE_integer rootfs_hash_pad 8 \ |
Will Drewry | d253bad | 2010-08-17 14:09:41 -0500 | [diff] [blame] | 81 | "MiBs reserved at the end of the rootfs image." |
Eric Li | 5cf288f | 2010-06-28 12:46:26 -0700 | [diff] [blame] | 82 | DEFINE_integer statefulfs_size 1024 \ |
Will Drewry | d253bad | 2010-08-17 14:09:41 -0500 | [diff] [blame] | 83 | "stateful filesystem size in MiBs." |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 84 | DEFINE_boolean preserve ${FLAGS_FALSE} \ |
| 85 | "Attempt to preserve the previous build image if one can be found (unstable, \ |
| 86 | kernel/firmware not updated)" |
David James | 0366864 | 2010-07-28 17:08:29 -0700 | [diff] [blame] | 87 | DEFINE_boolean fast ${DEFAULT_FAST} \ |
| 88 | "Call many emerges in parallel" |
Will Drewry | 32d8c11 | 2010-10-11 15:37:17 -0500 | [diff] [blame] | 89 | DEFINE_string boot_args "noinitrd" \ |
| 90 | "Additional boot arguments to pass to the commandline" |
Nick Sanders | f2dee6c | 2010-07-01 00:21:32 -0700 | [diff] [blame] | 91 | |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 92 | DEFINE_string usb_disk /dev/sdb3 \ |
| 93 | "Path syslinux should use to do a usb boot. Default: /dev/sdb3" |
| 94 | |
Will Drewry | 12f14ce | 2010-08-17 17:27:16 -0500 | [diff] [blame] | 95 | DEFINE_boolean enable_rootfs_verification ${FLAGS_TRUE} \ |
Will Drewry | 1670d48 | 2010-07-09 13:08:38 -0700 | [diff] [blame] | 96 | "Default all bootloaders to use kernel-based root fs integrity checking." |
Will Drewry | d07f61d | 2011-01-12 10:39:54 -0600 | [diff] [blame] | 97 | DEFINE_integer verity_error_behavior 3 \ |
Will Drewry | 137eab6 | 2010-11-04 22:06:41 -0500 | [diff] [blame] | 98 | "Kernel verified boot error behavior (0: I/O errors, 1: panic, 2: nothing, \ |
Will Drewry | d07f61d | 2011-01-12 10:39:54 -0600 | [diff] [blame] | 99 | 3: cros) Default: 3" |
Will Drewry | 1670d48 | 2010-07-09 13:08:38 -0700 | [diff] [blame] | 100 | DEFINE_integer verity_depth 1 \ |
| 101 | "Kernel verified boot hash tree depth. Default: 1" |
Will Drewry | 52c40f8 | 2010-10-06 14:54:38 -0500 | [diff] [blame] | 102 | DEFINE_integer verity_max_ios -1 \ |
| 103 | "Number of outstanding I/O operations dm-verity caps at. Default: -1" |
Will Drewry | 1670d48 | 2010-07-09 13:08:38 -0700 | [diff] [blame] | 104 | DEFINE_string verity_algorithm "sha1" \ |
| 105 | "Cryptographic hash algorithm used for kernel vboot. Default : sha1" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 106 | |
Nikita Kostylev | c8bba90 | 2010-07-28 17:05:26 +0400 | [diff] [blame] | 107 | DEFINE_string oem_customization "" \ |
Denis Romanov | 95bdf47 | 2010-07-12 22:44:42 +0400 | [diff] [blame] | 108 | "Path to directory containing OEM partner partition contents" |
| 109 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 110 | # Parse command line. |
| 111 | FLAGS "$@" || exit 1 |
| 112 | eval set -- "${FLAGS_ARGV}" |
| 113 | |
| 114 | # Only now can we die on error. shflags functions leak non-zero error codes, |
| 115 | # so will die prematurely if 'set -e' is specified before now. |
| 116 | set -e |
| 117 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 118 | if [ -z "${FLAGS_board}" ] ; then |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 119 | error "--board is required." |
| 120 | exit 1 |
| 121 | fi |
| 122 | |
Chris Sosa | e38f90f | 2010-10-20 16:04:23 -0700 | [diff] [blame] | 123 | check_blacklist() { |
| 124 | info "Verifying that the base image does not contain a blacklisted package." |
| 125 | info "Generating list of packages for chromeos-base/chromeos." |
| 126 | local package_blacklist_file="${SCRIPTS_DIR}/chromeos_blacklist" |
| 127 | if [ ! -e "${package_blacklist_file}" ]; then |
| 128 | warn "Missing blacklist file." |
| 129 | return |
| 130 | fi |
| 131 | local blacklisted_packages=$(${SCRIPTS_DIR}/get_package_list \ |
| 132 | --board="${FLAGS_board}" chromeos-base/chromeos \ |
| 133 | | grep -x -f "${package_blacklist_file}") |
| 134 | if [ -n "${blacklisted_packages}" ]; then |
| 135 | die "Blacklisted packages found: ${blacklisted_packages}." |
| 136 | fi |
| 137 | info "No blacklisted packages found." |
| 138 | } |
| 139 | |
| 140 | check_blacklist |
| 141 | |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 142 | # Verify user didn't specify incompatible flags for dev install shim |
Nick Sanders | c8cb336 | 2010-09-01 21:31:30 -0700 | [diff] [blame] | 143 | if [ "${FLAGS_factory_install}" -eq "${FLAGS_TRUE}" ] && |
| 144 | [ "${FLAGS_dev_install}" -eq "${FLAGS_TRUE}" ] ; then |
| 145 | die "Incompatible flags: --factory_install and --dev_install cannot be \ |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 146 | both set to True. Please specify one or none." |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 147 | fi |
| 148 | |
Nick Sanders | ae26a5c | 2010-08-30 21:59:50 -0700 | [diff] [blame] | 149 | INSTALL_MASK="" |
Nick Sanders | c8cb336 | 2010-09-01 21:31:30 -0700 | [diff] [blame] | 150 | if [ "${FLAGS_installmask}" -eq "${FLAGS_TRUE}" ] ; then |
Nick Sanders | ae26a5c | 2010-08-30 21:59:50 -0700 | [diff] [blame] | 151 | INSTALL_MASK="${DEFAULT_INSTALL_MASK}" |
| 152 | fi |
| 153 | |
| 154 | # Reduce the size of factory install shim. |
Nick Sanders | c8cb336 | 2010-09-01 21:31:30 -0700 | [diff] [blame] | 155 | if [ "${FLAGS_factory_install}" -eq "${FLAGS_TRUE}" ] || |
| 156 | [ "${FLAGS_dev_install}" -eq "${FLAGS_TRUE}" ] ; then |
Nick Sanders | ae26a5c | 2010-08-30 21:59:50 -0700 | [diff] [blame] | 157 | # Disable --withdev flag when --*_install is set to True. Otherwise, the |
| 158 | # dev image produced will be based on install shim, rather than a pristine |
| 159 | # image |
Nick Sanders | c8cb336 | 2010-09-01 21:31:30 -0700 | [diff] [blame] | 160 | if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then |
Nick Sanders | ae26a5c | 2010-08-30 21:59:50 -0700 | [diff] [blame] | 161 | info "Incompatible flags: --withdev and --dev_install or --factory_install \ |
| 162 | cannot be both set to True. Reset --withdev to False." |
| 163 | FLAGS_withdev=${FLAGS_FALSE} |
| 164 | fi |
| 165 | |
| 166 | # TODO: Build a separated ebuild for the install shim to reduce size. |
| 167 | INSTALL_MASK="${INSTALL_MASK} ${FACTORY_INSTALL_MASK}" |
| 168 | |
| 169 | info "Fixing the rootfs size at 300 MiB for install shim" |
| 170 | FLAGS_rootfs_size=280 |
| 171 | FLAGS_rootfs_partition_size=300 |
| 172 | info "Fixing the statefulfs size at 140 MiB for install shim" |
| 173 | FLAGS_statefulfs_size=140 |
| 174 | fi |
| 175 | |
| 176 | if [ "$((FLAGS_rootfs_size + FLAGS_rootfs_hash_pad))" -gt \ |
| 177 | "${FLAGS_rootfs_partition_size}" ] ; then |
| 178 | die "rootfs ($((FLAGS_rootfs_size + FLAGS_rootfs_hash_pad)) MiB) is \ |
| 179 | bigger than partition (${FLAGS_rootfs_partition_size} MiB)." |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 180 | fi |
| 181 | |
Nick Sanders | 8ab729a | 2010-06-16 03:15:17 -0700 | [diff] [blame] | 182 | EMERGE_BOARD_CMD="emerge-${FLAGS_board}" |
Nick Sanders | f2dee6c | 2010-07-01 00:21:32 -0700 | [diff] [blame] | 183 | if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then |
Nick Sanders | 8ab729a | 2010-06-16 03:15:17 -0700 | [diff] [blame] | 184 | echo "Using alternate emerge" |
Nick Sanders | f2dee6c | 2010-07-01 00:21:32 -0700 | [diff] [blame] | 185 | EMERGE_BOARD_CMD="${SCRIPTS_DIR}/parallel_emerge --board=${FLAGS_board}" |
Nick Sanders | 8ab729a | 2010-06-16 03:15:17 -0700 | [diff] [blame] | 186 | fi |
| 187 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 188 | # Determine build version. |
David McMahon | 48db5d2 | 2010-12-14 16:19:24 -0800 | [diff] [blame] | 189 | . ${SRC_ROOT}/third_party/chromiumos-overlay/chromeos/config/chromeos_version.sh |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 190 | |
Nick Sanders | c8cb336 | 2010-09-01 21:31:30 -0700 | [diff] [blame] | 191 | # Configure extra USE or packages for this type of build. |
| 192 | EXTRA_PACKAGES="" |
| 193 | EXTRA_USE="" |
| 194 | if [ "${FLAGS_factory_install}" -eq "${FLAGS_TRUE}" ] ; then |
| 195 | # Factory install needs to have the kernel initrmafs enabled, |
| 196 | # and the factory installer added. |
Nick Sanders | ebce854 | 2010-09-02 14:57:34 -0700 | [diff] [blame] | 197 | EXTRA_PACKAGES="${EXTRA_PACKAGES} chromeos-base/chromeos-factoryinstall" |
| 198 | EXTRA_USE="${EXTRA_USE} initramfs" |
Nick Sanders | c8cb336 | 2010-09-01 21:31:30 -0700 | [diff] [blame] | 199 | fi |
| 200 | |
| 201 | # Freshen kernel with correct USE flags. This is a noop if we have |
| 202 | # the right kernel prebuilt. Factory install uses USE="initramfs". |
| 203 | # We don't allow building from source with the image as a target, |
| 204 | # and it's not possible to store prebuilts for the same package |
| 205 | # with different use flags. |
Mandeep Singh Baines | 4ea330f | 2010-11-17 18:11:58 -0800 | [diff] [blame] | 206 | USE="${EXTRA_USE} ${USE}" emerge-${FLAGS_board} \ |
Anush Elangovan | bc2aaf6 | 2010-09-09 19:40:30 -0700 | [diff] [blame] | 207 | -uNDvg --binpkg-respect-use=y virtual/kernel |
Nick Sanders | c8cb336 | 2010-09-01 21:31:30 -0700 | [diff] [blame] | 208 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 209 | # Use canonical path since some tools (e.g. mount) do not like symlinks. |
| 210 | # Append build attempt to output directory. |
| 211 | IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}" |
| 212 | OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}" |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 213 | |
| 214 | OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 215 | |
| 216 | # If we are creating a developer image, also create a pristine image with a |
| 217 | # different name. |
| 218 | DEVELOPER_IMAGE_NAME= |
| 219 | PRISTINE_IMAGE_NAME=chromiumos_image.bin |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 220 | if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 221 | PRISTINE_IMAGE_NAME=chromiumos_base_image.bin |
| 222 | DEVELOPER_IMAGE_NAME=chromiumos_image.bin |
Nick Sanders | ae26a5c | 2010-08-30 21:59:50 -0700 | [diff] [blame] | 223 | elif [ "${FLAGS_dev_install}" -eq "${FLAGS_TRUE}" ]; then |
| 224 | # Rename pristine images for install shims |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 225 | PRISTINE_IMAGE_NAME=dev_install_shim.bin |
Nick Sanders | ae26a5c | 2010-08-30 21:59:50 -0700 | [diff] [blame] | 226 | elif [ "${FLAGS_factory_install}" -eq "${FLAGS_TRUE}" ]; then |
| 227 | PRISTINE_IMAGE_NAME=factory_install_shim.bin |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 228 | fi |
| 229 | |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 230 | PRISTINE_IMG="${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}" |
| 231 | DEVELOPER_IMG="${OUTPUT_DIR}/${DEVELOPER_IMAGE_NAME}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 232 | |
| 233 | BOARD="${FLAGS_board}" |
| 234 | BOARD_ROOT="${FLAGS_build_root}/${BOARD}" |
| 235 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 236 | ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" |
| 237 | ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 238 | ROOT_FS_HASH="${OUTPUT_DIR}/rootfs.hash" |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 239 | |
| 240 | STATEFUL_FS_IMG="${OUTPUT_DIR}/stateful_partition.image" |
| 241 | STATEFUL_FS_DIR="${OUTPUT_DIR}/stateful_partition" |
| 242 | |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 243 | OEM_FS_IMG="${OUTPUT_DIR}/partner_partition.image" |
| 244 | OEM_FS_DIR="${OUTPUT_DIR}/partner_partition" |
| 245 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 246 | ESP_FS_IMG=${OUTPUT_DIR}/esp.image |
| 247 | ESP_FS_DIR=${OUTPUT_DIR}/esp |
| 248 | |
Will Drewry | 7ab698d | 2010-08-05 13:57:52 -0500 | [diff] [blame] | 249 | DEVKEYSDIR="/usr/share/vboot/devkeys" |
| 250 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 251 | LOOP_DEV= |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 252 | STATEFUL_LOOP_DEV= |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 253 | OEM_LOOP_DEV= |
Bill Richardson | a81df76 | 2010-04-09 08:12:05 -0700 | [diff] [blame] | 254 | ESP_LOOP_DEV= |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 255 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 256 | # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will |
| 257 | # be installed on the stateful dir. On a Chromium OS system, this will |
| 258 | # translate to /usr/local. |
| 259 | DEV_IMAGE_ROOT="${STATEFUL_FS_DIR}/dev_image" |
| 260 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 261 | # What cross-build are we targeting? |
| 262 | . "${BOARD_ROOT}/etc/make.conf.board_setup" |
| 263 | LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"} |
| 264 | |
Nick Sanders | ae26a5c | 2010-08-30 21:59:50 -0700 | [diff] [blame] | 265 | if [ ${FLAGS_jobs} -ne -1 ]; then |
David James | fd7403a | 2010-07-09 12:00:17 -0700 | [diff] [blame] | 266 | EMERGE_JOBS="--jobs=${FLAGS_jobs}" |
| 267 | fi |
| 268 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 269 | # Figure out ARCH from the given toolchain. |
| 270 | # TODO: Move to common.sh as a function after scripts are switched over. |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 271 | TC_ARCH=$(echo "${CHOST}" | awk -F'-' '{ print $1 }') |
| 272 | case "${TC_ARCH}" in |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 273 | arm*) |
| 274 | ARCH="arm" |
| 275 | ;; |
| 276 | *86) |
| 277 | ARCH="x86" |
| 278 | ;; |
| 279 | *) |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 280 | error "Unable to determine ARCH from toolchain: ${CHOST}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 281 | exit 1 |
| 282 | esac |
| 283 | |
Will Drewry | 12f14ce | 2010-08-17 17:27:16 -0500 | [diff] [blame] | 284 | if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then |
| 285 | enable_rootfs_verification_flag="--enable_rootfs_verification" |
Will Drewry | 12f14ce | 2010-08-17 17:27:16 -0500 | [diff] [blame] | 286 | fi |
| 287 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 288 | # Hack to fix bug where x86_64 CHOST line gets incorrectly added. |
| 289 | # ToDo(msb): remove this hack. |
| 290 | PACKAGES_FILE="${BOARD_ROOT}/packages/Packages" |
| 291 | sudo sed -e "s/CHOST: x86_64-pc-linux-gnu//" -i "${PACKAGES_FILE}" |
| 292 | |
| 293 | # Handle existing directory. |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 294 | if [[ -e "${OUTPUT_DIR}" ]]; then |
| 295 | if [[ ${FLAGS_replace} -eq ${FLAGS_TRUE} ]]; then |
| 296 | sudo rm -rf "${OUTPUT_DIR}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 297 | else |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 298 | echo "Directory ${OUTPUT_DIR} already exists." |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 299 | echo "Use --build_attempt option to specify an unused attempt." |
| 300 | echo "Or use --replace if you want to overwrite this directory." |
| 301 | exit 1 |
| 302 | fi |
| 303 | fi |
| 304 | |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 305 | # Find previous build, if any... |
| 306 | PREVIOUS_DIR=$($SCRIPTS_DIR/get_latest_image.sh --board="$BOARD") |
| 307 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 308 | cleanup_rootfs_loop() { |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 309 | sudo umount -d "${ROOT_FS_DIR}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | cleanup_stateful_fs_loop() { |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 313 | sudo umount "${ROOT_FS_DIR}/usr/local" |
| 314 | sudo umount "${ROOT_FS_DIR}/var" |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 315 | sudo umount -d "${STATEFUL_FS_DIR}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 318 | cleanup_oem_fs_loop() { |
| 319 | sudo umount -d "${OEM_FS_DIR}" |
| 320 | } |
| 321 | |
| 322 | |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 323 | cleanup_esp_loop() { |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 324 | sudo umount -d "${ESP_FS_DIR}" |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 327 | cleanup() { |
| 328 | # Disable die on error. |
| 329 | set +e |
| 330 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 331 | if [[ -n "${STATEFUL_LOOP_DEV}" ]]; then |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 332 | cleanup_stateful_fs_loop |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 333 | STATEFUL_LOOP_DEV= |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 334 | fi |
| 335 | |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 336 | if [[ -n "${OEM_LOOP_DEV}" ]]; then |
| 337 | cleanup_oem_fs_loop |
| 338 | fi |
| 339 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 340 | if [[ -n "${LOOP_DEV}" ]]; then |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 341 | cleanup_rootfs_loop |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 342 | LOOP_DEV= |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 343 | fi |
| 344 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 345 | if [[ -n "${ESP_LOOP_DEV}" ]]; then |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 346 | cleanup_esp_loop |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 347 | ESP_LOOP_DEV= |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 348 | fi |
| 349 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 350 | # Turn die on error back on. |
| 351 | set -e |
| 352 | } |
| 353 | |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 354 | delete_prompt() { |
| 355 | echo "An error occurred in your build so your latest output directory" \ |
| 356 | "is invalid." |
Tan Gao | 74a07ca | 2010-09-09 11:41:30 -0700 | [diff] [blame] | 357 | |
| 358 | # Only prompt if both stdin and stdout are a tty. If either is not a tty, |
| 359 | # then the user may not be present, so we shouldn't bother prompting. |
Chris Sosa | 3ee8b17 | 2011-01-24 15:55:46 -0800 | [diff] [blame] | 360 | if tty -s && tty -s <&1 && [ "${USER}" -ne 'chrome-bot' ]; then |
Tan Gao | 74a07ca | 2010-09-09 11:41:30 -0700 | [diff] [blame] | 361 | read -p "Would you like to delete the output directory (y/N)? " SURE |
| 362 | SURE="${SURE:0:1}" # Get just the first character. |
| 363 | else |
| 364 | SURE="y" |
| 365 | echo "Running in non-interactive mode so deleting output directory." |
| 366 | fi |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 367 | if [ "${SURE}" == "y" ] ; then |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 368 | sudo rm -rf "${OUTPUT_DIR}" |
| 369 | echo "Deleted ${OUTPUT_DIR}" |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 370 | else |
Tan Gao | 74a07ca | 2010-09-09 11:41:30 -0700 | [diff] [blame] | 371 | echo "Not deleting ${OUTPUT_DIR}." |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 372 | fi |
| 373 | } |
| 374 | |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 375 | # $1 - Directory where developer rootfs is mounted. |
| 376 | # $2 - Directory where developer stateful_partition is mounted. |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 377 | # $3 - Directory where the ESP partition is mounted. |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 378 | mount_gpt_cleanup() { |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 379 | local rootfs="${1-$ROOT_FS_DIR}" |
| 380 | local statefs="${2-$STATEFUL_FS_DIR}" |
| 381 | local espfs="${3-$ESP_FS_DIR}" |
| 382 | "${SCRIPTS_DIR}/mount_gpt_image.sh" \ |
| 383 | -u -r "${rootfs}" -s "${statefs}" -e "${espfs}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 384 | delete_prompt |
| 385 | } |
| 386 | |
Will Drewry | 7ab698d | 2010-08-05 13:57:52 -0500 | [diff] [blame] | 387 | # Takes no arguments and populates the configuration for |
| 388 | # cros_make_image_bootable. |
| 389 | create_boot_desc() { |
| 390 | cat <<EOF > ${OUTPUT_DIR}/boot.desc |
| 391 | --arch="${ARCH}" |
| 392 | --output_dir="${OUTPUT_DIR}" |
Will Drewry | 32d8c11 | 2010-10-11 15:37:17 -0500 | [diff] [blame] | 393 | --boot_args="${FLAGS_boot_args}" |
Will Drewry | 7ab698d | 2010-08-05 13:57:52 -0500 | [diff] [blame] | 394 | --rootfs_size="${FLAGS_rootfs_size}" |
| 395 | --rootfs_hash_pad="${FLAGS_rootfs_hash_pad}" |
| 396 | --rootfs_hash="${ROOT_FS_HASH}" |
| 397 | --rootfs_mountpoint="${ROOT_FS_DIR}" |
| 398 | --statefulfs_mountpoint="${STATEFUL_FS_DIR}" |
| 399 | --espfs_mountpoint="${ESP_FS_DIR}" |
| 400 | --verity_error_behavior="${FLAGS_verity_error_behavior}" |
| 401 | --verity_depth="${FLAGS_verity_depth}" |
| 402 | --verity_max_ios="${FLAGS_verity_max_ios}" |
| 403 | --verity_algorithm="${FLAGS_verity_algorithm}" |
| 404 | --keys_dir="${DEVKEYSDIR}" |
| 405 | --usb_disk="${FLAGS_usb_disk}" |
| 406 | --nocleanup_dirs |
| 407 | ${enable_rootfs_verification_flag} |
| 408 | EOF |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 409 | } |
| 410 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 411 | # Modifies an existing image to add development packages |
| 412 | update_dev_packages() { |
| 413 | local image_name=$1 |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 414 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 415 | echo "Adding developer packages to ${image_name}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 416 | |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 417 | trap "mount_gpt_cleanup" EXIT |
Tan Gao | a40ed44 | 2010-06-02 15:45:19 -0700 | [diff] [blame] | 418 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 419 | ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \ |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 420 | --image "${image_name}" -r "${ROOT_FS_DIR}" \ |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 421 | -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 422 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 423 | # Determine the root dir for developer packages. |
| 424 | local root_dev_dir="${ROOT_FS_DIR}" |
| 425 | [ ${FLAGS_statefuldev} -eq ${FLAGS_TRUE} ] && \ |
| 426 | root_dev_dir="${ROOT_FS_DIR}/usr/local" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 427 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 428 | # Install developer packages described in chromeos-dev. |
| 429 | sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ |
| 430 | --root="${root_dev_dir}" --root-deps=rdeps \ |
David James | ffede3b | 2010-09-07 14:22:38 -0700 | [diff] [blame] | 431 | --usepkgonly -uDNv chromeos-dev ${EMERGE_JOBS} |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 432 | |
| 433 | if [[ $FLAGS_preserve -eq ${FLAGS_TRUE} ]] ; then |
| 434 | # Clean out unused packages |
| 435 | sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ |
| 436 | --root="${ROOT_FS_DIR}" --root-deps=rdeps \ |
David James | ffede3b | 2010-09-07 14:22:38 -0700 | [diff] [blame] | 437 | --usepkgonly --depclean ${EMERGE_JOBS} |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 438 | fi |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 439 | |
Paul Stewart | 12973e5 | 2010-09-09 20:04:11 -0700 | [diff] [blame] | 440 | # Install the bare necessary files so that the "emerge" command works |
Trevor Bourget | 8e6abb0 | 2010-12-13 09:44:32 -0700 | [diff] [blame] | 441 | [ ${FLAGS_statefuldev} -eq ${FLAGS_TRUE} ] && \ |
| 442 | sudo cp ${root_dev_dir}/etc/make.globals ${ROOT_FS_DIR}/etc/ |
Chris Sosa | 765db0f | 2010-10-25 15:08:55 -0700 | [diff] [blame] | 443 | sudo sed -i s,/usr/bin/wget,wget, ${ROOT_FS_DIR}/etc/make.globals |
Paul Stewart | 12973e5 | 2010-09-09 20:04:11 -0700 | [diff] [blame] | 444 | sudo mkdir -p ${ROOT_FS_DIR}/etc/make.profile |
| 445 | |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 446 | # Re-run ldconfig to fix /etc/ldconfig.so.cache. |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 447 | sudo /sbin/ldconfig -r "${ROOT_FS_DIR}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 448 | |
| 449 | # Mark the image as a developer image (input to chromeos_startup). |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 450 | sudo mkdir -p "${ROOT_FS_DIR}/root" |
| 451 | sudo touch "${ROOT_FS_DIR}/root/.dev_mode" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 452 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 453 | # Additional changes to developer image. |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 454 | |
Ken Mixter | 1334788 | 2010-08-12 16:51:52 -0700 | [diff] [blame] | 455 | # Leave core files for developers to inspect. |
Ken Mixter | 0d11563 | 2010-08-13 15:51:07 -0700 | [diff] [blame] | 456 | sudo touch "${ROOT_FS_DIR}/root/.leave_core" |
Ken Mixter | 1334788 | 2010-08-12 16:51:52 -0700 | [diff] [blame] | 457 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 458 | # The ldd tool is a useful shell script but lives in glibc; just copy it. |
| 459 | sudo cp -a "$(which ldd)" "${root_dev_dir}/usr/bin" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 460 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 461 | # If vim is installed, then a vi symlink would probably help. |
| 462 | if [[ -x "${ROOT_FS_DIR}/usr/local/bin/vim" ]]; then |
| 463 | sudo ln -sf vim "${ROOT_FS_DIR}/usr/local/bin/vi" |
Girts Folkmanis | 7a8a838 | 2010-05-18 22:52:25 -0700 | [diff] [blame] | 464 | fi |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 465 | |
Tammo Spalink | cfc0c64 | 2010-07-07 10:51:21 +0800 | [diff] [blame] | 466 | # If pygtk is installed in stateful-dev, then install a path. |
| 467 | if [[ -d \ |
| 468 | "${ROOT_FS_DIR}/usr/local/lib/python2.6/site-packages/gtk-2.0" ]]; then |
| 469 | sudo bash -c "\ |
| 470 | echo gtk-2.0 > \ |
| 471 | ${ROOT_FS_DIR}/usr/local/lib/python2.6/site-packages/pygtk.pth" |
| 472 | fi |
| 473 | |
Chris Sosa | 6304adc | 2010-10-20 13:40:33 -0700 | [diff] [blame] | 474 | # If python is installed on stateful-dev, fix python symlinks. |
| 475 | local python_path="/usr/local/bin/python2.6" |
| 476 | if [ -e "${ROOT_FS_DIR}${python_path}" ]; then |
| 477 | info "Fixing python symlinks for developer and test images." |
| 478 | local python_paths="/usr/bin/python /usr/local/bin/python \ |
| 479 | /usr/bin/python2 /usr/local/bin/python2" |
| 480 | for path in ${python_paths}; do |
| 481 | sudo rm -f "${ROOT_FS_DIR}${path}" |
| 482 | sudo ln -s ${python_path} "${ROOT_FS_DIR}${path}" |
| 483 | done |
| 484 | fi |
| 485 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 486 | # Check that the image has been correctly created. Only do it if not |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 487 | # building a factory install image and not a dev install shim, as the |
| 488 | # INSTALL_MASK for it will make test_image fail. |
| 489 | if [ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ] && |
| 490 | [ ${FLAGS_dev_install} -eq ${FLAGS_FALSE} ] ; then |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 491 | "${SCRIPTS_DIR}/test_image" \ |
| 492 | --root="${ROOT_FS_DIR}" \ |
| 493 | --target="${ARCH}" |
| 494 | fi |
| 495 | echo "Developer image built and stored at ${image_name}" |
| 496 | |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 497 | trap - EXIT |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 498 | ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \ |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 499 | -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}" |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | # Update the base package on an existing image. |
| 503 | update_base_packages() { |
| 504 | local image_name=$1 |
| 505 | |
| 506 | echo "Updating base packages on ${image_name}" |
| 507 | |
| 508 | # Create stateful partition of the same size as the rootfs. |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 509 | trap "mount_gpt_cleanup" EXIT |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 510 | |
| 511 | ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \ |
| 512 | --image "${image_name}" -r "${ROOT_FS_DIR}" \ |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 513 | -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}" |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 514 | |
| 515 | # Emerge updated packages, exactly like when creating base image |
Nick Sanders | c8cb336 | 2010-09-01 21:31:30 -0700 | [diff] [blame] | 516 | sudo USE="${EXTRA_USE}" INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 517 | --root="${ROOT_FS_DIR}" --root-deps=rdeps \ |
David James | ffede3b | 2010-09-07 14:22:38 -0700 | [diff] [blame] | 518 | --usepkgonly -uDNv chromeos ${EXTRA_PACKAGES} ${EMERGE_JOBS} |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 519 | |
| 520 | # Clean out unused packages |
| 521 | sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ |
| 522 | --root="${ROOT_FS_DIR}" --root-deps=rdeps \ |
David James | ffede3b | 2010-09-07 14:22:38 -0700 | [diff] [blame] | 523 | --usepkgonly --depclean ${EMERGE_JOBS} |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 524 | |
| 525 | trap - EXIT |
| 526 | ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \ |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 527 | -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 528 | } |
| 529 | |
Thieu Le | 171321f | 2010-12-13 11:37:42 -0800 | [diff] [blame] | 530 | zero_free_space() { |
| 531 | local fs_mount_point=$1 |
| 532 | info "Zeroing freespace in ${fs_mount_point}" |
| 533 | sudo dd if=/dev/zero of="${fs_mount_point}/filler" oflag=sync bs=4096 || true |
| 534 | sudo rm -f "${fs_mount_point}/filler" |
| 535 | sudo sync |
| 536 | } |
| 537 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 538 | create_base_image() { |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 539 | local image_name=$1 |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 540 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 541 | trap "cleanup && delete_prompt" EXIT |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 542 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 543 | # Create and format the root file system. |
| 544 | |
| 545 | # Check for loop device before creating image. |
| 546 | LOOP_DEV=$(sudo losetup -f) |
| 547 | if [ -z "${LOOP_DEV}" ] ; then |
| 548 | echo "No free loop device. Free up a loop device or reboot. exiting. " |
| 549 | exit 1 |
| 550 | fi |
| 551 | |
Will Drewry | d253bad | 2010-08-17 14:09:41 -0500 | [diff] [blame] | 552 | # Create root file system disk image. |
| 553 | ROOT_SIZE_BYTES=$((1024 * 1024 * ${FLAGS_rootfs_size})) |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 554 | |
Will Drewry | 9926ee2 | 2010-07-21 15:11:10 -0500 | [diff] [blame] | 555 | # Pad out for the hash tree. |
Will Drewry | 78992a3 | 2010-07-21 14:02:20 -0500 | [diff] [blame] | 556 | ROOT_HASH_PAD=$((FLAGS_rootfs_hash_pad * 1024 * 1024)) |
| 557 | info "Padding the rootfs image by ${ROOT_HASH_PAD} bytes for hash data" |
Will Drewry | 9926ee2 | 2010-07-21 15:11:10 -0500 | [diff] [blame] | 558 | |
Will Drewry | 78992a3 | 2010-07-21 14:02:20 -0500 | [diff] [blame] | 559 | dd if=/dev/zero of="${ROOT_FS_IMG}" bs=1 count=1 \ |
| 560 | seek=$((ROOT_SIZE_BYTES + ROOT_HASH_PAD - 1)) |
Will Drewry | 9926ee2 | 2010-07-21 15:11:10 -0500 | [diff] [blame] | 561 | sudo losetup "${LOOP_DEV}" "${ROOT_FS_IMG}" |
| 562 | # Specify a block size and block count to avoid using the hash pad. |
Will Drewry | 55b42c9 | 2010-10-20 15:44:11 -0500 | [diff] [blame] | 563 | sudo mkfs.ext2 -b 4096 "${LOOP_DEV}" "$((ROOT_SIZE_BYTES / 4096))" |
Will Drewry | 78992a3 | 2010-07-21 14:02:20 -0500 | [diff] [blame] | 564 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 565 | # Tune and mount rootfs. |
Will Drewry | 55b42c9 | 2010-10-20 15:44:11 -0500 | [diff] [blame] | 566 | DISK_LABEL="C-ROOT" |
| 567 | # Disable checking and minimize metadata differences across builds |
| 568 | # and wasted reserved space. |
| 569 | sudo tune2fs -L "${DISK_LABEL}" \ |
| 570 | -U clear \ |
| 571 | -T 20091119110000 \ |
| 572 | -c 0 \ |
| 573 | -i 0 \ |
| 574 | -m 0 \ |
| 575 | -r 0 \ |
| 576 | -e remount-ro \ |
| 577 | "${LOOP_DEV}" |
| 578 | # TODO(wad) call tune2fs prior to finalization to set the mount count to 0. |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 579 | sudo mount "${LOOP_DEV}" "${ROOT_FS_DIR}" |
| 580 | |
| 581 | # Create stateful partition of the same size as the rootfs. |
| 582 | STATEFUL_LOOP_DEV=$(sudo losetup -f) |
| 583 | if [ -z "${STATEFUL_LOOP_DEV}" ] ; then |
| 584 | echo "No free loop device. Free up a loop device or reboot. exiting. " |
| 585 | exit 1 |
| 586 | fi |
Eric Li | 5cf288f | 2010-06-28 12:46:26 -0700 | [diff] [blame] | 587 | STATEFUL_SIZE_BYTES=$((1024 * 1024 * ${FLAGS_statefulfs_size})) |
| 588 | dd if=/dev/zero of="${STATEFUL_FS_IMG}" bs=1 count=1 \ |
| 589 | seek=$((STATEFUL_SIZE_BYTES - 1)) |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 590 | |
| 591 | # Tune and mount the stateful partition. |
| 592 | UUID=$(uuidgen) |
| 593 | DISK_LABEL="C-STATE" |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 594 | sudo losetup "${STATEFUL_LOOP_DEV}" "${STATEFUL_FS_IMG}" |
| 595 | sudo mkfs.ext3 "${STATEFUL_LOOP_DEV}" |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 596 | sudo tune2fs -L "${DISK_LABEL}" -U "${UUID}" -c 0 -i 0 "${STATEFUL_LOOP_DEV}" |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 597 | sudo mount "${STATEFUL_LOOP_DEV}" "${STATEFUL_FS_DIR}" |
| 598 | |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 599 | # Create OEM partner partition. |
| 600 | OEM_LOOP_DEV=$(sudo losetup -f) |
| 601 | if [ -z "${OEM_LOOP_DEV}" ] ; then |
| 602 | echo "No free loop device. Free up a loop device or reboot. exiting. " |
| 603 | exit 1 |
| 604 | fi |
| 605 | OEM_SIZE_BYTES=$((1024 * 1024 * 16)) |
| 606 | dd if=/dev/zero of="${OEM_FS_IMG}" bs=1 count=1 seek=$((OEM_SIZE_BYTES - 1)) |
| 607 | |
| 608 | # Tune and mount OEM partner partition. |
| 609 | UUID=$(uuidgen) |
| 610 | DISK_LABEL="C-OEM" |
| 611 | sudo losetup "${OEM_LOOP_DEV}" "${OEM_FS_IMG}" |
| 612 | sudo mkfs.ext3 "${OEM_LOOP_DEV}" |
| 613 | sudo tune2fs -L "${DISK_LABEL}" -U "${UUID}" -c 0 -i 0 "${OEM_LOOP_DEV}" |
| 614 | sudo mount "${OEM_LOOP_DEV}" "${OEM_FS_DIR}" |
| 615 | |
Denis Romanov | 95bdf47 | 2010-07-12 22:44:42 +0400 | [diff] [blame] | 616 | # Populate OEM partner partition. |
Nikita Kostylev | c8bba90 | 2010-07-28 17:05:26 +0400 | [diff] [blame] | 617 | if [ ! -z "${FLAGS_oem_customization}" ]; then |
Denis Romanov | 95bdf47 | 2010-07-12 22:44:42 +0400 | [diff] [blame] | 618 | if [ ! -d ${FLAGS_oem_customization} ]; then |
| 619 | echo "Specified OEM content directory does not exist. exiting." |
| 620 | exit 1 |
| 621 | fi |
| 622 | for ITEM in `ls -A ${FLAGS_oem_customization}` |
| 623 | do sudo cp -a "${FLAGS_oem_customization}/$ITEM" "${OEM_FS_DIR}" |
| 624 | done |
| 625 | sudo find "${OEM_FS_DIR}" -type d -exec chmod 755 "{}" \; |
| 626 | sudo find "${OEM_FS_DIR}" -type f -exec chmod 644 "{}" \; |
| 627 | sudo chown -R root:root "${OEM_FS_DIR}" |
Nikita Kostylev | c8bba90 | 2010-07-28 17:05:26 +0400 | [diff] [blame] | 628 | else |
| 629 | echo "Empty OEM partition: OEM customizations will not be applied." |
Denis Romanov | 95bdf47 | 2010-07-12 22:44:42 +0400 | [diff] [blame] | 630 | fi |
| 631 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 632 | # -- Install packages into the root file system -- |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 633 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 634 | # We need to install libc manually from the cross toolchain. |
| 635 | # TODO: Improve this? We only want libc and not the whole toolchain. |
| 636 | PKGDIR="/var/lib/portage/pkgs/cross/" |
| 637 | sudo tar jxvpf \ |
| 638 | "${PKGDIR}/${CHOST}/cross-${CHOST}"/glibc-${LIBC_VERSION}.tbz2 \ |
| 639 | -C "${ROOT_FS_DIR}" --strip-components=3 \ |
| 640 | --exclude=usr/include --exclude=sys-include --exclude=*.a --exclude=*.o |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 641 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 642 | # We need to install libstdc++ manually from the cross toolchain. |
| 643 | # TODO: Figure out a better way of doing this? |
| 644 | sudo cp -a "${BOARD_ROOT}"/lib/libgcc_s.so* "${ROOT_FS_DIR}/lib" |
| 645 | sudo cp -a "${BOARD_ROOT}"/usr/lib/libstdc++.so* "${ROOT_FS_DIR}/usr/lib" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 646 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 647 | # Prepare stateful partition with some pre-created directories. |
| 648 | sudo mkdir -p "${DEV_IMAGE_ROOT}" |
| 649 | sudo mkdir -p "${STATEFUL_FS_DIR}/var" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 650 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 651 | # Create symlinks so that /usr/local/usr based directories are symlinked to |
| 652 | # /usr/local/ directories e.g. /usr/local/usr/bin -> /usr/local/bin, etc. |
| 653 | setup_symlinks_on_root "${DEV_IMAGE_ROOT}" "${STATEFUL_FS_DIR}/var" \ |
| 654 | "${STATEFUL_FS_DIR}" |
Tom Wai-Hong Tam | f87a367 | 2010-05-17 16:06:33 +0800 | [diff] [blame] | 655 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 656 | # Perform binding rather than symlinking because directories must exist |
| 657 | # on rootfs so that we can bind at run-time since rootfs is read-only. |
| 658 | echo "Binding directories from stateful partition onto the rootfs" |
| 659 | sudo mkdir -p "${ROOT_FS_DIR}/usr/local" |
| 660 | sudo mount --bind "${DEV_IMAGE_ROOT}" "${ROOT_FS_DIR}/usr/local" |
| 661 | sudo mkdir -p "${ROOT_FS_DIR}/var" |
| 662 | sudo mount --bind "${STATEFUL_FS_DIR}/var" "${ROOT_FS_DIR}/var" |
| 663 | sudo mkdir -p "${ROOT_FS_DIR}/dev" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 664 | |
David James | ffede3b | 2010-09-07 14:22:38 -0700 | [diff] [blame] | 665 | # We "emerge --root=${ROOT_FS_DIR} --root-deps=rdeps --usepkgonly" all of the |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 666 | # runtime packages for chrome os. This builds up a chrome os image from |
| 667 | # binary packages with runtime dependencies only. We use INSTALL_MASK to |
| 668 | # trim the image size as much as possible. |
Nick Sanders | c8cb336 | 2010-09-01 21:31:30 -0700 | [diff] [blame] | 669 | sudo USE="${EXTRA_USE}" INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 670 | --root="${ROOT_FS_DIR}" --root-deps=rdeps \ |
David James | ffede3b | 2010-09-07 14:22:38 -0700 | [diff] [blame] | 671 | --usepkgonly chromeos ${EXTRA_PACKAGES} ${EMERGE_JOBS} |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 672 | |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 673 | # Perform any customizations on the root file system that are needed. |
| 674 | "${SCRIPTS_DIR}/customize_rootfs" \ |
| 675 | --root="${ROOT_FS_DIR}" \ |
| 676 | --target="${ARCH}" \ |
| 677 | --board="${BOARD}" |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 678 | |
Will Drewry | 1ee156f | 2010-07-03 13:27:19 -0500 | [diff] [blame] | 679 | # Populates the root filesystem with legacy bootloader templates |
| 680 | # appropriate for the platform. The autoupdater and installer will |
| 681 | # use those templates to update the legacy boot partition (12/ESP) |
| 682 | # on update. |
| 683 | # (This script does not populate vmlinuz.A and .B needed by syslinux.) |
Will Drewry | 1670d48 | 2010-07-09 13:08:38 -0700 | [diff] [blame] | 684 | enable_rootfs_verification= |
| 685 | if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then |
| 686 | enable_rootfs_verification="--enable_rootfs_verification" |
| 687 | fi |
| 688 | |
Will Drewry | 1ee156f | 2010-07-03 13:27:19 -0500 | [diff] [blame] | 689 | ${SCRIPTS_DIR}/create_legacy_bootloader_templates.sh \ |
| 690 | --arch=${ARCH} \ |
| 691 | --to="${ROOT_FS_DIR}"/boot \ |
Will Drewry | 32d8c11 | 2010-10-11 15:37:17 -0500 | [diff] [blame] | 692 | --boot_args="${FLAGS_boot_args}" \ |
Will Drewry | 1ee156f | 2010-07-03 13:27:19 -0500 | [diff] [blame] | 693 | --install \ |
Will Drewry | 1670d48 | 2010-07-09 13:08:38 -0700 | [diff] [blame] | 694 | ${enable_rootfs_verification} |
Bill Richardson | 9c5e5ec | 2010-05-14 17:00:21 -0700 | [diff] [blame] | 695 | |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 696 | # Don't test the factory install shim or the dev install shim |
| 697 | if [ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ] && |
| 698 | [ ${FLAGS_dev_install} -eq ${FLAGS_FALSE} ]; then |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 699 | # Check that the image has been correctly created. |
| 700 | "${SCRIPTS_DIR}/test_image" \ |
| 701 | --root="${ROOT_FS_DIR}" \ |
| 702 | --target="${ARCH}" |
| 703 | fi |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 704 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 705 | # Clean up symlinks so they work on a running target rooted at "/". |
| 706 | # Here development packages are rooted at /usr/local. However, do not |
| 707 | # create /usr/local or /var on host (already exist on target). |
| 708 | setup_symlinks_on_root "/usr/local" "/var" "${STATEFUL_FS_DIR}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 709 | |
Will Drewry | 7ab698d | 2010-08-05 13:57:52 -0500 | [diff] [blame] | 710 | # cros_make_image_bootable will clobber vmlinuz.image for x86. |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 711 | # Until then, just copy the kernel to vmlinuz.image. It is |
Kenneth Waters | e3049de | 2010-09-30 14:20:34 -0700 | [diff] [blame] | 712 | # expected in build_gpt.sh. |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 713 | cp "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image" |
| 714 | |
| 715 | # Create an empty esp image to be updated in by update_bootloaders.sh. |
| 716 | ${SCRIPTS_DIR}/create_esp.sh --to="${ESP_FS_IMG}" |
| 717 | |
Thieu Le | 171321f | 2010-12-13 11:37:42 -0800 | [diff] [blame] | 718 | # Zero rootfs free space to make it more compressible so auto-update |
| 719 | # payloads become smaller |
| 720 | zero_free_space "${ROOT_FS_DIR}" |
| 721 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 722 | cleanup |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 723 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 724 | trap delete_prompt EXIT |
Tan Gao | 6df5aee | 2010-05-19 14:19:55 -0700 | [diff] [blame] | 725 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 726 | # Create the GPT-formatted image. |
| 727 | ${SCRIPTS_DIR}/build_gpt.sh \ |
| 728 | --arch=${ARCH} \ |
| 729 | --board=${FLAGS_board} \ |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 730 | --rootfs_partition_size=${FLAGS_rootfs_partition_size} \ |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 731 | "${OUTPUT_DIR}" \ |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 732 | "${OUTPUT_DIR}/${image_name}" |
| 733 | |
Nick Sanders | 446c211 | 2010-09-03 18:15:35 -0700 | [diff] [blame] | 734 | # Pre-set "sucessful" bit in gpt, so we will never mark-for-death |
| 735 | # a partition on an SDCard/USB stick. |
| 736 | ${GPT} add -i 2 -S 1 "${OUTPUT_DIR}/${image_name}" |
| 737 | |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 738 | trap - EXIT |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 739 | } |
| 740 | |
Raja Aluri | aeb1048 | 2010-12-10 13:03:09 -0800 | [diff] [blame] | 741 | generate_au_zip () { |
| 742 | local lgenerateauzip="${SCRIPTS_DIR}/generate_au_zip.py" |
| 743 | local largs="-o ${OUTPUT_DIR}" |
Raja Aluri | 888e07c | 2010-12-14 10:36:34 -0800 | [diff] [blame] | 744 | test ! -d "${OUTPUT_DIR}" && mkdir -p "${OUTPUT_DIR}" |
Raja Aluri | aeb1048 | 2010-12-10 13:03:09 -0800 | [diff] [blame] | 745 | info "Running ${lgenerateauzip} ${largs} for generating AU updater zip file" |
| 746 | $lgenerateauzip $largs |
| 747 | } |
| 748 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 749 | # Create the output directory. |
| 750 | mkdir -p "${OUTPUT_DIR}" |
| 751 | mkdir -p "${ROOT_FS_DIR}" |
| 752 | mkdir -p "${STATEFUL_FS_DIR}" |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 753 | mkdir -p "${OEM_FS_DIR}" |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 754 | mkdir -p "${ESP_FS_DIR}" |
| 755 | |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 756 | # Preserve old images by copying them forward for --preserve. |
| 757 | if [[ $FLAGS_preserve -eq ${FLAGS_TRUE} ]] ; then |
| 758 | if [[ -f ${PREVIOUS_DIR}/${PRISTINE_IMAGE_NAME} ]] ; then |
| 759 | # Copy forward pristine image, and associated files |
| 760 | cp ${PREVIOUS_DIR}/*.sh ${PREVIOUS_DIR}/config.txt ${OUTPUT_DIR} |
| 761 | cp ${PREVIOUS_DIR}/${PRISTINE_IMAGE_NAME} ${OUTPUT_DIR} |
| 762 | |
| 763 | # Copy forward the developer image, if we already copied forward the base. |
| 764 | if [[ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]] && \ |
| 765 | [[ -f ${PREVIOUS_DIR}/${DEVELOPER_IMAGE_NAME} ]] ; then |
| 766 | cp ${PREVIOUS_DIR}/${DEVELOPER_IMAGE_NAME} ${OUTPUT_DIR} |
| 767 | fi |
| 768 | fi |
| 769 | fi |
| 770 | |
David James | ffede3b | 2010-09-07 14:22:38 -0700 | [diff] [blame] | 771 | # Perform an eclean to remove packages which are not installed |
| 772 | if [[ "${FLAGS_eclean}" -eq "${FLAGS_TRUE}" ]]; then |
| 773 | eclean-${FLAGS_board} -d packages |
| 774 | fi |
| 775 | |
Will Drewry | 7ab698d | 2010-08-05 13:57:52 -0500 | [diff] [blame] | 776 | # Create the boot.desc file which stores the build-time configuration |
| 777 | # information needed for making the image bootable after creation with |
| 778 | # cros_make_image_bootable. |
| 779 | create_boot_desc |
| 780 | |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 781 | if [[ -f ${PRISTINE_IMG} ]] ; then |
| 782 | update_base_packages ${PRISTINE_IMAGE_NAME} |
| 783 | else |
| 784 | create_base_image ${PRISTINE_IMAGE_NAME} |
| 785 | fi |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 786 | |
| 787 | USE_DEV_KEYS= |
Nick Sanders | ae26a5c | 2010-08-30 21:59:50 -0700 | [diff] [blame] | 788 | if [ "${FLAGS_dev_install}" -eq "${FLAGS_TRUE}" ] || \ |
| 789 | [ "${FLAGS_factory_install}" -eq "${FLAGS_TRUE}" ]; then |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 790 | USE_DEV_KEYS="--use_dev_keys" |
| 791 | fi |
| 792 | |
| 793 | # Place flags before positional args |
Will Drewry | 7ab698d | 2010-08-05 13:57:52 -0500 | [diff] [blame] | 794 | ${SCRIPTS_DIR}/bin/cros_make_image_bootable "${OUTPUT_DIR}" \ |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 795 | "${PRISTINE_IMAGE_NAME}" \ |
| 796 | ${USE_DEV_KEYS} |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 797 | |
| 798 | # FIXME: only signing things for x86 right now. |
| 799 | if [[ "${ARCH}" = "x86" ]]; then |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 800 | BOOT_FLAG= |
Nick Sanders | ae26a5c | 2010-08-30 21:59:50 -0700 | [diff] [blame] | 801 | if [ "${FLAGS_dev_install}" -eq "${FLAGS_TRUE}" ] || |
| 802 | [ "${FLAGS_factory_install}" -eq "${FLAGS_TRUE}" ]; then |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 803 | BOOT_FLAG="-b 1" # BOOT_FLAG_DEVELOPER value defined in load_kernel_fw.h |
| 804 | info "--dev_install set, pass BOOT_FLAG_DEVELOPER flag to load_kernel_test" |
| 805 | fi |
| 806 | |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 807 | # Verify the final image. |
| 808 | load_kernel_test "${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}" \ |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 809 | "${DEVKEYSDIR}/recovery_key.vbpubk" ${BOOT_FLAG} |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 810 | fi |
Bill Richardson | 4364a2e | 2010-03-30 14:17:34 -0700 | [diff] [blame] | 811 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 812 | # Create a developer image based on the chromium os base image. |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 813 | if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ] ; then |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 814 | if [[ ! -f ${DEVELOPER_IMG} ]] ; then |
| 815 | echo "Creating developer image from base image ${PRISTINE_IMAGE_NAME}" |
| 816 | cp ${PRISTINE_IMG} ${DEVELOPER_IMG} |
| 817 | fi |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 818 | |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 819 | update_dev_packages ${DEVELOPER_IMAGE_NAME} |
Will Drewry | 7ab698d | 2010-08-05 13:57:52 -0500 | [diff] [blame] | 820 | ${SCRIPTS_DIR}/bin/cros_make_image_bootable "${OUTPUT_DIR}" \ |
| 821 | "${DEVELOPER_IMAGE_NAME}" |
Bill Richardson | 6ed1358 | 2010-06-16 21:38:15 -0700 | [diff] [blame] | 822 | fi |
| 823 | |
| 824 | # Clean up temporary files. |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 825 | rm -f "${ROOT_FS_IMG}" "${STATEFUL_FS_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \ |
Louis Yung-Chieh Lo | 3602040 | 2010-07-05 13:23:34 +0800 | [diff] [blame] | 826 | "${ESP_FS_IMG}" "${OEM_FS_IMG}" "${OUTPUT_DIR}/vmlinuz_hd.vblock" |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 827 | rmdir "${ROOT_FS_DIR}" "${STATEFUL_FS_DIR}" "${OEM_FS_DIR}" "${ESP_FS_DIR}" |
Bill Richardson | 6795622 | 2010-05-28 15:38:56 -0700 | [diff] [blame] | 828 | |
Raja Aluri | aeb1048 | 2010-12-10 13:03:09 -0800 | [diff] [blame] | 829 | # Generating AU generator zip file to run outside chroot |
| 830 | generate_au_zip || echo "Failed generating AU zip file - ignoring Error..." |
Olof Johansson | 58f25cc | 2010-08-04 21:18:49 -0700 | [diff] [blame] | 831 | # Create a 'latest' link |
| 832 | rm -f ${FLAGS_output_root}/${FLAGS_board}/latest |
| 833 | ln -s $(basename ${OUTPUT_DIR}) ${FLAGS_output_root}/${FLAGS_board}/latest |
| 834 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 835 | echo "Done. Image created in ${OUTPUT_DIR}" |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 836 | echo "Chromium OS image created as ${PRISTINE_IMAGE_NAME}" |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 837 | if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then |
| 838 | echo "Developer image created as ${DEVELOPER_IMAGE_NAME}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 839 | fi |
Nick Sanders | 8ab729a | 2010-06-16 03:15:17 -0700 | [diff] [blame] | 840 | |
Nick Sanders | d250927 | 2010-06-16 03:50:04 -0700 | [diff] [blame] | 841 | print_time_elapsed |
| 842 | |
Hung-Te Lin | 2ffe2be | 2010-10-05 08:15:40 +0800 | [diff] [blame] | 843 | echo "To copy to USB keyfob, do something like:" |
Daniel Erat | dd9818a | 2010-04-26 09:16:44 -0700 | [diff] [blame] | 844 | echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" |
Will Drewry | efce668 | 2010-07-23 19:43:27 -0500 | [diff] [blame] | 845 | echo "To convert to VMWare image, INSIDE the chroot, do something like:" |
Olof Johansson | 1f5e84d | 2010-08-24 20:26:49 -0500 | [diff] [blame] | 846 | echo " ./image_to_vm.sh --from=${OUTSIDE_OUTPUT_DIR} --board=${BOARD}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 847 | echo "from the scripts directory where you entered the chroot." |