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