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 | |
| 12 | # Load common constants. This should be the first executable line. |
| 13 | # The path to common.sh should be relative to your script's location. |
| 14 | . "$(dirname "$0")/common.sh" |
| 15 | |
| 16 | # Script must be run inside the chroot. |
Don Garrett | 640a058 | 2010-05-04 16:54:28 -0700 | [diff] [blame] | 17 | restart_in_chroot_if_needed $* |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 18 | |
| 19 | get_default_board |
| 20 | |
| 21 | # Flags. |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 22 | DEFINE_string board "${DEFAULT_BOARD}" \ |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 23 | "The board to build an image for." |
| 24 | DEFINE_string build_root "/build" \ |
| 25 | "The root location for board sysroots." |
| 26 | DEFINE_integer build_attempt 1 \ |
| 27 | "The build attempt for this image build." |
| 28 | DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/images" \ |
| 29 | "Directory in which to place image result directories (named by version)" |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 30 | DEFINE_boolean replace ${FLAGS_FALSE} \ |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 31 | "Overwrite existing output, if any." |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 32 | DEFINE_boolean withdev ${FLAGS_TRUE} \ |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 33 | "Include useful developer friendly utilities in the image." |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 34 | DEFINE_boolean installmask ${FLAGS_TRUE} \ |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 35 | "Use INSTALL_MASK to shrink the resulting image." |
| 36 | DEFINE_integer jobs -1 \ |
| 37 | "How many packages to build in parallel at maximum." |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 38 | DEFINE_boolean statefuldev ${FLAGS_TRUE} \ |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 39 | "Install development packages on stateful partition rather than the rootfs" |
Antoine Labour | e9e585f | 2010-04-01 15:57:57 -0700 | [diff] [blame] | 40 | DEFINE_string to "" \ |
| 41 | "The target image file or device" |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 42 | DEFINE_boolean factory_install ${FLAGS_FALSE} \ |
Tom Wai-Hong Tam | f87a367 | 2010-05-17 16:06:33 +0800 | [diff] [blame] | 43 | "Build a smaller image to overlay the factory install shim on; this argument \ |
| 44 | is also required in image_to_usb." |
robotboy | b75eee3 | 2010-04-30 09:51:23 -0700 | [diff] [blame] | 45 | DEFINE_string arm_extra_bootargs "" \ |
| 46 | "Additional command line options to pass to the ARM kernel." |
Zelidrag Hornung | 1d12c1a | 2010-06-02 10:20:29 -0700 | [diff] [blame] | 47 | DEFINE_integer rootfs_partition_size 1024 \ |
| 48 | "rootfs parition size in MBs." |
| 49 | DEFINE_integer rootfs_size 720 \ |
| 50 | "rootfs filesystem size in MBs." |
Eric Li | 5cf288f | 2010-06-28 12:46:26 -0700 | [diff] [blame] | 51 | DEFINE_integer statefulfs_size 1024 \ |
| 52 | "stateful filesystem size in MBs." |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 53 | DEFINE_boolean preserve ${FLAGS_FALSE} \ |
| 54 | "Attempt to preserve the previous build image if one can be found (unstable, \ |
| 55 | kernel/firmware not updated)" |
Nick Sanders | f2dee6c | 2010-07-01 00:21:32 -0700 | [diff] [blame] | 56 | DEFINE_boolean fast ${FLAGS_FALSE} \ |
| 57 | "Call many emerges in parallel (unstable)" |
| 58 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 59 | |
| 60 | # Parse command line. |
| 61 | FLAGS "$@" || exit 1 |
| 62 | eval set -- "${FLAGS_ARGV}" |
| 63 | |
| 64 | # Only now can we die on error. shflags functions leak non-zero error codes, |
| 65 | # so will die prematurely if 'set -e' is specified before now. |
| 66 | set -e |
| 67 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 68 | if [ -z "${FLAGS_board}" ] ; then |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 69 | error "--board is required." |
| 70 | exit 1 |
| 71 | fi |
| 72 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 73 | if [ "${FLAGS_rootfs_size}" -gt "${FLAGS_rootfs_partition_size}" ] ; then |
Zelidrag Hornung | 1d12c1a | 2010-06-02 10:20:29 -0700 | [diff] [blame] | 74 | error "rootfs (${FLAGS_rootfs_size} MB) is bigger than partition (${FLAGS_rootfs_partition_size} MB)." |
| 75 | exit 1 |
| 76 | fi |
| 77 | |
Nick Sanders | 8ab729a | 2010-06-16 03:15:17 -0700 | [diff] [blame] | 78 | EMERGE_BOARD_CMD="emerge-${FLAGS_board}" |
Nick Sanders | f2dee6c | 2010-07-01 00:21:32 -0700 | [diff] [blame] | 79 | if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then |
Nick Sanders | 8ab729a | 2010-06-16 03:15:17 -0700 | [diff] [blame] | 80 | echo "Using alternate emerge" |
Nick Sanders | f2dee6c | 2010-07-01 00:21:32 -0700 | [diff] [blame] | 81 | EMERGE_BOARD_CMD="${SCRIPTS_DIR}/parallel_emerge --board=${FLAGS_board}" |
Nick Sanders | 8ab729a | 2010-06-16 03:15:17 -0700 | [diff] [blame] | 82 | fi |
| 83 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 84 | # Determine build version. |
| 85 | . "${SCRIPTS_DIR}/chromeos_version.sh" |
| 86 | |
| 87 | # Use canonical path since some tools (e.g. mount) do not like symlinks. |
| 88 | # Append build attempt to output directory. |
| 89 | IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}" |
| 90 | OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}" |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 91 | |
| 92 | OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 93 | |
| 94 | # If we are creating a developer image, also create a pristine image with a |
| 95 | # different name. |
| 96 | DEVELOPER_IMAGE_NAME= |
| 97 | PRISTINE_IMAGE_NAME=chromiumos_image.bin |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 98 | if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 99 | PRISTINE_IMAGE_NAME=chromiumos_base_image.bin |
| 100 | DEVELOPER_IMAGE_NAME=chromiumos_image.bin |
| 101 | fi |
Tan Gao | a40ed44 | 2010-06-02 15:45:19 -0700 | [diff] [blame] | 102 | |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 103 | PRISTINE_IMG="${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}" |
| 104 | DEVELOPER_IMG="${OUTPUT_DIR}/${DEVELOPER_IMAGE_NAME}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 105 | |
| 106 | BOARD="${FLAGS_board}" |
| 107 | BOARD_ROOT="${FLAGS_build_root}/${BOARD}" |
| 108 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 109 | ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" |
| 110 | ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" |
| 111 | |
| 112 | STATEFUL_FS_IMG="${OUTPUT_DIR}/stateful_partition.image" |
| 113 | STATEFUL_FS_DIR="${OUTPUT_DIR}/stateful_partition" |
| 114 | |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 115 | OEM_FS_IMG="${OUTPUT_DIR}/partner_partition.image" |
| 116 | OEM_FS_DIR="${OUTPUT_DIR}/partner_partition" |
| 117 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 118 | ESP_FS_IMG=${OUTPUT_DIR}/esp.image |
| 119 | ESP_FS_DIR=${OUTPUT_DIR}/esp |
| 120 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 121 | LOOP_DEV= |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 122 | STATEFUL_LOOP_DEV= |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 123 | OEM_LOOP_DEV= |
Bill Richardson | a81df76 | 2010-04-09 08:12:05 -0700 | [diff] [blame] | 124 | ESP_LOOP_DEV= |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 125 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 126 | # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will |
| 127 | # be installed on the stateful dir. On a Chromium OS system, this will |
| 128 | # translate to /usr/local. |
| 129 | DEV_IMAGE_ROOT="${STATEFUL_FS_DIR}/dev_image" |
| 130 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 131 | # What cross-build are we targeting? |
| 132 | . "${BOARD_ROOT}/etc/make.conf.board_setup" |
| 133 | LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"} |
| 134 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 135 | INSTALL_MASK="" |
| 136 | if [[ ${FLAGS_installmask} -eq ${FLAGS_TRUE} ]] ; then |
| 137 | INSTALL_MASK="${DEFAULT_INSTALL_MASK}" |
| 138 | fi |
| 139 | |
| 140 | # Reduce the size of factory install shim. |
| 141 | # TODO: Build a separated ebuild for the factory install shim to reduce size. |
| 142 | if [[ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]] ; then |
| 143 | INSTALL_MASK="${INSTALL_MASK} ${FACTORY_INSTALL_MASK}" |
| 144 | fi |
| 145 | |
| 146 | if [[ ${FLAGS_jobs} -ne -1 ]]; then |
| 147 | EMERGE_JOBS="--jobs=${FLAGS_jobs}" |
| 148 | fi |
| 149 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 150 | # Figure out ARCH from the given toolchain. |
| 151 | # 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] | 152 | TC_ARCH=$(echo "${CHOST}" | awk -F'-' '{ print $1 }') |
| 153 | case "${TC_ARCH}" in |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 154 | arm*) |
| 155 | ARCH="arm" |
| 156 | ;; |
| 157 | *86) |
| 158 | ARCH="x86" |
| 159 | ;; |
| 160 | *) |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 161 | error "Unable to determine ARCH from toolchain: ${CHOST}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 162 | exit 1 |
| 163 | esac |
| 164 | |
| 165 | # Hack to fix bug where x86_64 CHOST line gets incorrectly added. |
| 166 | # ToDo(msb): remove this hack. |
| 167 | PACKAGES_FILE="${BOARD_ROOT}/packages/Packages" |
| 168 | sudo sed -e "s/CHOST: x86_64-pc-linux-gnu//" -i "${PACKAGES_FILE}" |
| 169 | |
| 170 | # Handle existing directory. |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 171 | if [[ -e "${OUTPUT_DIR}" ]]; then |
| 172 | if [[ ${FLAGS_replace} -eq ${FLAGS_TRUE} ]]; then |
| 173 | sudo rm -rf "${OUTPUT_DIR}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 174 | else |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 175 | echo "Directory ${OUTPUT_DIR} already exists." |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 176 | echo "Use --build_attempt option to specify an unused attempt." |
| 177 | echo "Or use --replace if you want to overwrite this directory." |
| 178 | exit 1 |
| 179 | fi |
| 180 | fi |
| 181 | |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 182 | # Find previous build, if any... |
| 183 | PREVIOUS_DIR=$($SCRIPTS_DIR/get_latest_image.sh --board="$BOARD") |
| 184 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 185 | cleanup_rootfs_loop() { |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 186 | sudo umount -d "${ROOT_FS_DIR}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | cleanup_stateful_fs_loop() { |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 190 | sudo umount "${ROOT_FS_DIR}/usr/local" |
| 191 | sudo umount "${ROOT_FS_DIR}/var" |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 192 | sudo umount -d "${STATEFUL_FS_DIR}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 195 | cleanup_oem_fs_loop() { |
| 196 | sudo umount -d "${OEM_FS_DIR}" |
| 197 | } |
| 198 | |
| 199 | |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 200 | cleanup_esp_loop() { |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 201 | sudo umount -d "${ESP_FS_DIR}" |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 204 | cleanup() { |
| 205 | # Disable die on error. |
| 206 | set +e |
| 207 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 208 | if [[ -n "${STATEFUL_LOOP_DEV}" ]]; then |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 209 | cleanup_stateful_fs_loop |
| 210 | fi |
| 211 | |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 212 | if [[ -n "${OEM_LOOP_DEV}" ]]; then |
| 213 | cleanup_oem_fs_loop |
| 214 | fi |
| 215 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 216 | if [[ -n "${LOOP_DEV}" ]]; then |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 217 | cleanup_rootfs_loop |
| 218 | fi |
| 219 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 220 | if [[ -n "${ESP_LOOP_DEV}" ]]; then |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 221 | cleanup_esp_loop |
| 222 | fi |
| 223 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 224 | # Turn die on error back on. |
| 225 | set -e |
| 226 | } |
| 227 | |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 228 | delete_prompt() { |
| 229 | echo "An error occurred in your build so your latest output directory" \ |
| 230 | "is invalid." |
| 231 | read -p "Would you like to delete the output directory (y/N)? " SURE |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 232 | SURE="${SURE:0:1}" # Get just the first character. |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 233 | if [ "${SURE}" == "y" ] ; then |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 234 | sudo rm -rf "${OUTPUT_DIR}" |
| 235 | echo "Deleted ${OUTPUT_DIR}" |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 236 | else |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 237 | echo "Not deleting ${OUTPUT_DIR}. Note dev server updates will not work" \ |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 238 | "until you successfully build another image or delete this directory" |
| 239 | fi |
| 240 | } |
| 241 | |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 242 | # $1 - Directory where developer rootfs is mounted. |
| 243 | # $2 - Directory where developer stateful_partition is mounted. |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 244 | mount_gpt_cleanup() { |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 245 | "${SCRIPTS_DIR}/mount_gpt_image.sh" -u -r "$1" -s "$2" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 246 | delete_prompt |
| 247 | } |
| 248 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 249 | # Modifies an existing image to add development packages |
| 250 | update_dev_packages() { |
| 251 | local image_name=$1 |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 252 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 253 | echo "Adding developer packages to ${image_name}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 254 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 255 | trap "mount_gpt_cleanup \"${ROOT_FS_DIR}\" \"${STATEFUL_FS_DIR}\"" EXIT |
Tan Gao | a40ed44 | 2010-06-02 15:45:19 -0700 | [diff] [blame] | 256 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 257 | ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \ |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 258 | --image "${image_name}" -r "${ROOT_FS_DIR}" \ |
Chris Sosa | 6c587b0 | 2010-06-21 17:36:18 -0700 | [diff] [blame] | 259 | -s "${STATEFUL_FS_DIR}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 260 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 261 | # Determine the root dir for developer packages. |
| 262 | local root_dev_dir="${ROOT_FS_DIR}" |
| 263 | [ ${FLAGS_statefuldev} -eq ${FLAGS_TRUE} ] && \ |
| 264 | root_dev_dir="${ROOT_FS_DIR}/usr/local" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 265 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 266 | # Install developer packages described in chromeos-dev. |
| 267 | sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ |
| 268 | --root="${root_dev_dir}" --root-deps=rdeps \ |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 269 | --usepkg -uDNv chromeos-dev ${EMERGE_JOBS} |
| 270 | |
| 271 | if [[ $FLAGS_preserve -eq ${FLAGS_TRUE} ]] ; then |
| 272 | # Clean out unused packages |
| 273 | sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ |
| 274 | --root="${ROOT_FS_DIR}" --root-deps=rdeps \ |
| 275 | --usepkg --depclean ${EMERGE_JOBS} |
| 276 | fi |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 277 | |
| 278 | # Re-run ldconfig to fix /etc/ldconfig.so.cache. |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 279 | sudo /sbin/ldconfig -r "${ROOT_FS_DIR}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 280 | |
| 281 | # Mark the image as a developer image (input to chromeos_startup). |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 282 | sudo mkdir -p "${ROOT_FS_DIR}/root" |
| 283 | sudo touch "${ROOT_FS_DIR}/root/.dev_mode" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 284 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 285 | # Additional changes to developer image. |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 286 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 287 | # The ldd tool is a useful shell script but lives in glibc; just copy it. |
| 288 | sudo cp -a "$(which ldd)" "${root_dev_dir}/usr/bin" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 289 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 290 | # If vim is installed, then a vi symlink would probably help. |
| 291 | if [[ -x "${ROOT_FS_DIR}/usr/local/bin/vim" ]]; then |
| 292 | sudo ln -sf vim "${ROOT_FS_DIR}/usr/local/bin/vi" |
Girts Folkmanis | 7a8a838 | 2010-05-18 22:52:25 -0700 | [diff] [blame] | 293 | fi |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 294 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 295 | # Check that the image has been correctly created. Only do it if not |
| 296 | # building a factory install image, as the INSTALL_MASK for it will |
| 297 | # make test_image fail. |
| 298 | if [[ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ]] ; then |
| 299 | "${SCRIPTS_DIR}/test_image" \ |
| 300 | --root="${ROOT_FS_DIR}" \ |
| 301 | --target="${ARCH}" |
| 302 | fi |
| 303 | echo "Developer image built and stored at ${image_name}" |
| 304 | |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 305 | trap - EXIT |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 306 | ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \ |
| 307 | -s "${STATEFUL_FS_DIR}" |
| 308 | } |
| 309 | |
| 310 | # Update the base package on an existing image. |
| 311 | update_base_packages() { |
| 312 | local image_name=$1 |
| 313 | |
| 314 | echo "Updating base packages on ${image_name}" |
| 315 | |
| 316 | # Create stateful partition of the same size as the rootfs. |
| 317 | trap "mount_gpt_cleanup \"${ROOT_FS_DIR}\" \"${STATEFUL_FS_DIR}\"" EXIT |
| 318 | |
| 319 | ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \ |
| 320 | --image "${image_name}" -r "${ROOT_FS_DIR}" \ |
| 321 | -s "${STATEFUL_FS_DIR}" |
| 322 | |
| 323 | # Emerge updated packages, exactly like when creating base image |
| 324 | sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ |
| 325 | --root="${ROOT_FS_DIR}" --root-deps=rdeps \ |
| 326 | --usepkg -uDNv chromeos ${EMERGE_JOBS} |
| 327 | |
| 328 | # Clean out unused packages |
| 329 | sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ |
| 330 | --root="${ROOT_FS_DIR}" --root-deps=rdeps \ |
| 331 | --usepkg --depclean ${EMERGE_JOBS} |
| 332 | |
| 333 | trap - EXIT |
| 334 | ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \ |
| 335 | -s "${STATEFUL_FS_DIR}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 338 | create_base_image() { |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 339 | local image_name=$1 |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 340 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 341 | trap "cleanup && delete_prompt" EXIT |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 342 | |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 343 | UUID=$(uuidgen) |
| 344 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 345 | # Create and format the root file system. |
| 346 | |
| 347 | # Check for loop device before creating image. |
| 348 | LOOP_DEV=$(sudo losetup -f) |
| 349 | if [ -z "${LOOP_DEV}" ] ; then |
| 350 | echo "No free loop device. Free up a loop device or reboot. exiting. " |
| 351 | exit 1 |
| 352 | fi |
| 353 | |
| 354 | # Create root file system disk image to fit on a 1GB memory stick. |
| 355 | # 1 GB in hard-drive-manufacturer-speak is 10^9, not 2^30. 950MB < 10^9 bytes. |
| 356 | if [[ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]] ; then |
| 357 | ROOT_SIZE_BYTES=$((1024 * 1024 * 300)) |
| 358 | else |
| 359 | ROOT_SIZE_BYTES=$((1024 * 1024 * ${FLAGS_rootfs_size})) |
| 360 | fi |
| 361 | |
| 362 | dd if=/dev/zero of="${ROOT_FS_IMG}" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1)) |
| 363 | sudo losetup "${LOOP_DEV}" "${ROOT_FS_IMG}" |
| 364 | sudo mkfs.ext3 "${LOOP_DEV}" |
| 365 | |
| 366 | # Tune and mount rootfs. |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 367 | DISK_LABEL="C-KEYFOB" |
| 368 | sudo tune2fs -L "${DISK_LABEL}" -U "${UUID}" -c 0 -i 0 "${LOOP_DEV}" |
| 369 | sudo mount "${LOOP_DEV}" "${ROOT_FS_DIR}" |
| 370 | |
| 371 | # Create stateful partition of the same size as the rootfs. |
| 372 | STATEFUL_LOOP_DEV=$(sudo losetup -f) |
| 373 | if [ -z "${STATEFUL_LOOP_DEV}" ] ; then |
| 374 | echo "No free loop device. Free up a loop device or reboot. exiting. " |
| 375 | exit 1 |
| 376 | fi |
Eric Li | 5cf288f | 2010-06-28 12:46:26 -0700 | [diff] [blame] | 377 | STATEFUL_SIZE_BYTES=$((1024 * 1024 * ${FLAGS_statefulfs_size})) |
| 378 | dd if=/dev/zero of="${STATEFUL_FS_IMG}" bs=1 count=1 \ |
| 379 | seek=$((STATEFUL_SIZE_BYTES - 1)) |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 380 | |
| 381 | # Tune and mount the stateful partition. |
| 382 | UUID=$(uuidgen) |
| 383 | DISK_LABEL="C-STATE" |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 384 | sudo losetup "${STATEFUL_LOOP_DEV}" "${STATEFUL_FS_IMG}" |
| 385 | sudo mkfs.ext3 "${STATEFUL_LOOP_DEV}" |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 386 | 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] | 387 | sudo mount "${STATEFUL_LOOP_DEV}" "${STATEFUL_FS_DIR}" |
| 388 | |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 389 | # Create OEM partner partition. |
| 390 | OEM_LOOP_DEV=$(sudo losetup -f) |
| 391 | if [ -z "${OEM_LOOP_DEV}" ] ; then |
| 392 | echo "No free loop device. Free up a loop device or reboot. exiting. " |
| 393 | exit 1 |
| 394 | fi |
| 395 | OEM_SIZE_BYTES=$((1024 * 1024 * 16)) |
| 396 | dd if=/dev/zero of="${OEM_FS_IMG}" bs=1 count=1 seek=$((OEM_SIZE_BYTES - 1)) |
| 397 | |
| 398 | # Tune and mount OEM partner partition. |
| 399 | UUID=$(uuidgen) |
| 400 | DISK_LABEL="C-OEM" |
| 401 | sudo losetup "${OEM_LOOP_DEV}" "${OEM_FS_IMG}" |
| 402 | sudo mkfs.ext3 "${OEM_LOOP_DEV}" |
| 403 | sudo tune2fs -L "${DISK_LABEL}" -U "${UUID}" -c 0 -i 0 "${OEM_LOOP_DEV}" |
| 404 | sudo mount "${OEM_LOOP_DEV}" "${OEM_FS_DIR}" |
| 405 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 406 | # -- Install packages into the root file system -- |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 407 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 408 | # We need to install libc manually from the cross toolchain. |
| 409 | # TODO: Improve this? We only want libc and not the whole toolchain. |
| 410 | PKGDIR="/var/lib/portage/pkgs/cross/" |
| 411 | sudo tar jxvpf \ |
| 412 | "${PKGDIR}/${CHOST}/cross-${CHOST}"/glibc-${LIBC_VERSION}.tbz2 \ |
| 413 | -C "${ROOT_FS_DIR}" --strip-components=3 \ |
| 414 | --exclude=usr/include --exclude=sys-include --exclude=*.a --exclude=*.o |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 415 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 416 | # We need to install libstdc++ manually from the cross toolchain. |
| 417 | # TODO: Figure out a better way of doing this? |
| 418 | sudo cp -a "${BOARD_ROOT}"/lib/libgcc_s.so* "${ROOT_FS_DIR}/lib" |
| 419 | 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] | 420 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 421 | # Prepare stateful partition with some pre-created directories. |
| 422 | sudo mkdir -p "${DEV_IMAGE_ROOT}" |
| 423 | sudo mkdir -p "${STATEFUL_FS_DIR}/var" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 424 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 425 | # Create symlinks so that /usr/local/usr based directories are symlinked to |
| 426 | # /usr/local/ directories e.g. /usr/local/usr/bin -> /usr/local/bin, etc. |
| 427 | setup_symlinks_on_root "${DEV_IMAGE_ROOT}" "${STATEFUL_FS_DIR}/var" \ |
| 428 | "${STATEFUL_FS_DIR}" |
Tom Wai-Hong Tam | f87a367 | 2010-05-17 16:06:33 +0800 | [diff] [blame] | 429 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 430 | # Perform binding rather than symlinking because directories must exist |
| 431 | # on rootfs so that we can bind at run-time since rootfs is read-only. |
| 432 | echo "Binding directories from stateful partition onto the rootfs" |
| 433 | sudo mkdir -p "${ROOT_FS_DIR}/usr/local" |
| 434 | sudo mount --bind "${DEV_IMAGE_ROOT}" "${ROOT_FS_DIR}/usr/local" |
| 435 | sudo mkdir -p "${ROOT_FS_DIR}/var" |
| 436 | sudo mount --bind "${STATEFUL_FS_DIR}/var" "${ROOT_FS_DIR}/var" |
| 437 | sudo mkdir -p "${ROOT_FS_DIR}/dev" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 438 | |
Mandeep Singh Baines | 3dfa852 | 2010-06-24 15:00:49 -0700 | [diff] [blame] | 439 | # We "emerge --root=${ROOT_FS_DIR} --root-deps=rdeps --usepkg" all of the |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 440 | # runtime packages for chrome os. This builds up a chrome os image from |
| 441 | # binary packages with runtime dependencies only. We use INSTALL_MASK to |
| 442 | # trim the image size as much as possible. |
| 443 | sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ |
| 444 | --root="${ROOT_FS_DIR}" --root-deps=rdeps \ |
Mandeep Singh Baines | 3dfa852 | 2010-06-24 15:00:49 -0700 | [diff] [blame] | 445 | --usepkg chromeos ${EMERGE_JOBS} |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 446 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 447 | # Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI |
| 448 | # BIOS). We only need this for x86, but it's simpler and safer to keep the |
| 449 | # disk images the same for both x86 and ARM. |
| 450 | # NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. |
| 451 | # We'll hard-code it to 16M for now. |
| 452 | ESP_BLOCKS=16384 |
| 453 | /usr/sbin/mkfs.vfat -C ${OUTPUT_DIR}/esp.image ${ESP_BLOCKS} |
| 454 | ESP_LOOP_DEV=$(sudo losetup -f) |
| 455 | if [ -z "${ESP_LOOP_DEV}" ] ; then |
| 456 | echo "No free loop device. Free up a loop device or reboot. exiting. " |
| 457 | exit 1 |
| 458 | fi |
| 459 | sudo losetup "${ESP_LOOP_DEV}" "${ESP_FS_IMG}" |
| 460 | sudo mount "${ESP_LOOP_DEV}" "${ESP_FS_DIR}" |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 461 | |
Will Drewry | 1ee156f | 2010-07-03 13:27:19 -0500 | [diff] [blame] | 462 | # Populates the root filesystem with legacy bootloader templates |
| 463 | # appropriate for the platform. The autoupdater and installer will |
| 464 | # use those templates to update the legacy boot partition (12/ESP) |
| 465 | # on update. |
| 466 | # (This script does not populate vmlinuz.A and .B needed by syslinux.) |
| 467 | use_vboot= |
| 468 | ${SCRIPTS_DIR}/create_legacy_bootloader_templates.sh \ |
| 469 | --arch=${ARCH} \ |
| 470 | --to="${ROOT_FS_DIR}"/boot \ |
| 471 | --install \ |
| 472 | ${use_vboot} |
Bill Richardson | 9c5e5ec | 2010-05-14 17:00:21 -0700 | [diff] [blame] | 473 | |
Will Drewry | 1ee156f | 2010-07-03 13:27:19 -0500 | [diff] [blame] | 474 | # Create a working copy so we don't need the rootfs mounted |
| 475 | sudo mkdir -p "${OUTPUT_DIR}"/boot |
| 476 | # This will include any built files dropped in /boot as well. |
| 477 | # Like the current vmlinuz. |
| 478 | sudo cp -r "${ROOT_FS_DIR}"/boot/. "${OUTPUT_DIR}"/boot/ |
Bill Richardson | a81df76 | 2010-04-09 08:12:05 -0700 | [diff] [blame] | 479 | |
Will Drewry | 1ee156f | 2010-07-03 13:27:19 -0500 | [diff] [blame] | 480 | # Until bootloader management is unified, copy EFI in here. |
| 481 | sudo mkdir -p "${ESP_FS_IMG}"/efi |
| 482 | sudo cp -r "${ROOT_FS_DIR}"/boot/efi/. "${ESP_FS_IMG}"/efi |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 483 | |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 484 | # Builds the kernel partition image. The temporary files are kept around |
| 485 | # so that we can perform a load_kernel_test later on the final image. |
| 486 | # TODO(wad) add dm-verity boot args (--boot_args, --root) |
| 487 | ${SCRIPTS_DIR}/build_kernel_image.sh \ |
| 488 | --arch="${ARCH}" \ |
| 489 | --to="${OUTPUT_DIR}/vmlinuz.image" \ |
| 490 | --vmlinuz="${ROOT_FS_DIR}/boot/vmlinuz" \ |
| 491 | --working_dir="${OUTPUT_DIR}" \ |
| 492 | --keep_work \ |
| 493 | --keys_dir="${SRC_ROOT}/platform/vboot_reference/tests/testkeys" |
Bill Richardson | 6795622 | 2010-05-28 15:38:56 -0700 | [diff] [blame] | 494 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 495 | # Perform any customizations on the root file system that are needed. |
| 496 | "${SCRIPTS_DIR}/customize_rootfs" \ |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 497 | --root="${ROOT_FS_DIR}" \ |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 498 | --target="${ARCH}" \ |
| 499 | --board="${BOARD}" |
Chris Sosa | 503efe1 | 2010-04-08 10:05:46 -0700 | [diff] [blame] | 500 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 501 | # Don't test the factory install shim. |
| 502 | if [[ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ]] ; then |
| 503 | # Check that the image has been correctly created. |
| 504 | "${SCRIPTS_DIR}/test_image" \ |
| 505 | --root="${ROOT_FS_DIR}" \ |
| 506 | --target="${ARCH}" |
| 507 | fi |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 508 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 509 | # Clean up symlinks so they work on a running target rooted at "/". |
| 510 | # Here development packages are rooted at /usr/local. However, do not |
| 511 | # create /usr/local or /var on host (already exist on target). |
| 512 | setup_symlinks_on_root "/usr/local" "/var" "${STATEFUL_FS_DIR}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 513 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 514 | # Cleanup loop devices. |
| 515 | cleanup |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 516 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 517 | trap delete_prompt EXIT |
Tan Gao | 6df5aee | 2010-05-19 14:19:55 -0700 | [diff] [blame] | 518 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 519 | # Create the GPT-formatted image. |
| 520 | ${SCRIPTS_DIR}/build_gpt.sh \ |
| 521 | --arch=${ARCH} \ |
| 522 | --board=${FLAGS_board} \ |
| 523 | --arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \ |
| 524 | --rootfs_partition_size=${FLAGS_rootfs_partition_size} \ |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 525 | "${OUTPUT_DIR}" \ |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 526 | "${OUTPUT_DIR}/${image_name}" |
| 527 | |
| 528 | trap - EXIT |
| 529 | |
| 530 | # FIXME: only signing things for x86 right now. |
| 531 | if [[ "${ARCH}" = "x86" ]]; then |
| 532 | # Verify the final image. |
| 533 | load_kernel_test "${OUTPUT_DIR}/${image_name}" \ |
Bill Richardson | 2ace49e | 2010-07-01 10:23:27 -0700 | [diff] [blame] | 534 | "${OUTPUT_DIR}/kernel_subkey.vbpubk" |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 535 | fi |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | # Create the output directory. |
| 539 | mkdir -p "${OUTPUT_DIR}" |
| 540 | mkdir -p "${ROOT_FS_DIR}" |
| 541 | mkdir -p "${STATEFUL_FS_DIR}" |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 542 | mkdir -p "${OEM_FS_DIR}" |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 543 | mkdir -p "${ESP_FS_DIR}" |
| 544 | |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 545 | # Preserve old images by copying them forward for --preserve. |
| 546 | if [[ $FLAGS_preserve -eq ${FLAGS_TRUE} ]] ; then |
| 547 | if [[ -f ${PREVIOUS_DIR}/${PRISTINE_IMAGE_NAME} ]] ; then |
| 548 | # Copy forward pristine image, and associated files |
| 549 | cp ${PREVIOUS_DIR}/*.sh ${PREVIOUS_DIR}/config.txt ${OUTPUT_DIR} |
| 550 | cp ${PREVIOUS_DIR}/${PRISTINE_IMAGE_NAME} ${OUTPUT_DIR} |
| 551 | |
| 552 | # Copy forward the developer image, if we already copied forward the base. |
| 553 | if [[ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]] && \ |
| 554 | [[ -f ${PREVIOUS_DIR}/${DEVELOPER_IMAGE_NAME} ]] ; then |
| 555 | cp ${PREVIOUS_DIR}/${DEVELOPER_IMAGE_NAME} ${OUTPUT_DIR} |
| 556 | fi |
| 557 | fi |
| 558 | fi |
| 559 | |
| 560 | if [[ -f ${PRISTINE_IMG} ]] ; then |
| 561 | update_base_packages ${PRISTINE_IMAGE_NAME} |
| 562 | else |
| 563 | create_base_image ${PRISTINE_IMAGE_NAME} |
| 564 | fi |
Bill Richardson | 4364a2e | 2010-03-30 14:17:34 -0700 | [diff] [blame] | 565 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 566 | # Create a developer image based on the chromium os base image. |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 567 | if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ] ; then |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 568 | if [[ ! -f ${DEVELOPER_IMG} ]] ; then |
| 569 | echo "Creating developer image from base image ${PRISTINE_IMAGE_NAME}" |
| 570 | cp ${PRISTINE_IMG} ${DEVELOPER_IMG} |
| 571 | fi |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 572 | |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 573 | update_dev_packages ${DEVELOPER_IMAGE_NAME} |
Bill Richardson | 6ed1358 | 2010-06-16 21:38:15 -0700 | [diff] [blame] | 574 | fi |
| 575 | |
| 576 | # Clean up temporary files. |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 577 | rm -f "${ROOT_FS_IMG}" "${STATEFUL_FS_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \ |
Bill Richardson | 2ace49e | 2010-07-01 10:23:27 -0700 | [diff] [blame] | 578 | "${ESP_FS_IMG}" "${OUTPUT_DIR}/kernel.keyblock" \ |
| 579 | "${OUTPUT_DIR}/kernel_subkey.vbpubk" \ |
| 580 | "${OUTPUT_DIR}/kernel_subkey.vbprivk" \ |
| 581 | "${OUTPUT_DIR}/kernel_data_key.vbpubk" \ |
| 582 | "${OUTPUT_DIR}/kernel_data_key.vbprivk" \ |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 583 | "${OEM_FS_IMG}" |
| 584 | 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] | 585 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 586 | echo "Done. Image created in ${OUTPUT_DIR}" |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 587 | echo "Chromium OS image created as ${PRISTINE_IMAGE_NAME}" |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 588 | if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then |
| 589 | echo "Developer image created as ${DEVELOPER_IMAGE_NAME}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 590 | fi |
Nick Sanders | 8ab729a | 2010-06-16 03:15:17 -0700 | [diff] [blame] | 591 | |
Nick Sanders | d250927 | 2010-06-16 03:50:04 -0700 | [diff] [blame] | 592 | print_time_elapsed |
| 593 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 594 | echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" |
Daniel Erat | dd9818a | 2010-04-26 09:16:44 -0700 | [diff] [blame] | 595 | echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 596 | echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" |
| 597 | echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" |
| 598 | echo "from the scripts directory where you entered the chroot." |