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 | |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 16 | . "$(dirname "$0")/chromeos-common.sh" # for partoffset |
| 17 | locate_gpt |
| 18 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 19 | # Script must be run inside the chroot. |
Don Garrett | 640a058 | 2010-05-04 16:54:28 -0700 | [diff] [blame] | 20 | restart_in_chroot_if_needed $* |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 21 | |
| 22 | get_default_board |
| 23 | |
| 24 | # Flags. |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 25 | DEFINE_string board "${DEFAULT_BOARD}" \ |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 26 | "The board to build an image for." |
| 27 | DEFINE_string build_root "/build" \ |
| 28 | "The root location for board sysroots." |
| 29 | DEFINE_integer build_attempt 1 \ |
| 30 | "The build attempt for this image build." |
| 31 | DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/images" \ |
| 32 | "Directory in which to place image result directories (named by version)" |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 33 | DEFINE_boolean replace ${FLAGS_FALSE} \ |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 34 | "Overwrite existing output, if any." |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 35 | DEFINE_boolean withdev ${FLAGS_TRUE} \ |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 36 | "Include useful developer friendly utilities in the image." |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 37 | DEFINE_boolean installmask ${FLAGS_TRUE} \ |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 38 | "Use INSTALL_MASK to shrink the resulting image." |
| 39 | DEFINE_integer jobs -1 \ |
| 40 | "How many packages to build in parallel at maximum." |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 41 | DEFINE_boolean statefuldev ${FLAGS_TRUE} \ |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 42 | "Install development packages on stateful partition rather than the rootfs" |
Antoine Labour | e9e585f | 2010-04-01 15:57:57 -0700 | [diff] [blame] | 43 | DEFINE_string to "" \ |
| 44 | "The target image file or device" |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 45 | DEFINE_boolean factory_install ${FLAGS_FALSE} \ |
Tom Wai-Hong Tam | f87a367 | 2010-05-17 16:06:33 +0800 | [diff] [blame] | 46 | "Build a smaller image to overlay the factory install shim on; this argument \ |
| 47 | is also required in image_to_usb." |
robotboy | b75eee3 | 2010-04-30 09:51:23 -0700 | [diff] [blame] | 48 | DEFINE_string arm_extra_bootargs "" \ |
| 49 | "Additional command line options to pass to the ARM kernel." |
Zelidrag Hornung | 1d12c1a | 2010-06-02 10:20:29 -0700 | [diff] [blame] | 50 | DEFINE_integer rootfs_partition_size 1024 \ |
| 51 | "rootfs parition size in MBs." |
| 52 | DEFINE_integer rootfs_size 720 \ |
| 53 | "rootfs filesystem size in MBs." |
Eric Li | 5cf288f | 2010-06-28 12:46:26 -0700 | [diff] [blame] | 54 | DEFINE_integer statefulfs_size 1024 \ |
| 55 | "stateful filesystem size in MBs." |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 56 | DEFINE_boolean preserve ${FLAGS_FALSE} \ |
| 57 | "Attempt to preserve the previous build image if one can be found (unstable, \ |
| 58 | kernel/firmware not updated)" |
Nick Sanders | f2dee6c | 2010-07-01 00:21:32 -0700 | [diff] [blame] | 59 | DEFINE_boolean fast ${FLAGS_FALSE} \ |
| 60 | "Call many emerges in parallel (unstable)" |
| 61 | |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 62 | DEFINE_string usb_disk /dev/sdb3 \ |
| 63 | "Path syslinux should use to do a usb boot. Default: /dev/sdb3" |
| 64 | |
Will Drewry | 1670d48 | 2010-07-09 13:08:38 -0700 | [diff] [blame] | 65 | DEFINE_boolean enable_rootfs_verification ${FLAGS_FALSE} \ |
| 66 | "Default all bootloaders to use kernel-based root fs integrity checking." |
| 67 | DEFINE_integer verity_error_behavior 2 \ |
| 68 | "Kernel verified boot error behavior (0: I/O errors, 1: reboot, 2: nothing) \ |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 69 | Default: 2" |
Will Drewry | 1670d48 | 2010-07-09 13:08:38 -0700 | [diff] [blame] | 70 | DEFINE_integer verity_depth 1 \ |
| 71 | "Kernel verified boot hash tree depth. Default: 1" |
| 72 | DEFINE_integer verity_max_ios 1024 \ |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 73 | "Number of outstanding I/O operations dm-verity caps at. Default: 1024" |
Will Drewry | 1670d48 | 2010-07-09 13:08:38 -0700 | [diff] [blame] | 74 | DEFINE_string verity_algorithm "sha1" \ |
| 75 | "Cryptographic hash algorithm used for kernel vboot. Default : sha1" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 76 | |
Denis Romanov | 95bdf47 | 2010-07-12 22:44:42 +0400 | [diff] [blame] | 77 | DEFINE_string oem_customization \ |
| 78 | "$GCLIENT_ROOT/src/platform/assets/oem_customization" \ |
| 79 | "Path to directory containing OEM partner partition contents" |
| 80 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 81 | # Parse command line. |
| 82 | FLAGS "$@" || exit 1 |
| 83 | eval set -- "${FLAGS_ARGV}" |
| 84 | |
| 85 | # Only now can we die on error. shflags functions leak non-zero error codes, |
| 86 | # so will die prematurely if 'set -e' is specified before now. |
| 87 | set -e |
| 88 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 89 | if [ -z "${FLAGS_board}" ] ; then |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 90 | error "--board is required." |
| 91 | exit 1 |
| 92 | fi |
| 93 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 94 | if [ "${FLAGS_rootfs_size}" -gt "${FLAGS_rootfs_partition_size}" ] ; then |
Zelidrag Hornung | 1d12c1a | 2010-06-02 10:20:29 -0700 | [diff] [blame] | 95 | error "rootfs (${FLAGS_rootfs_size} MB) is bigger than partition (${FLAGS_rootfs_partition_size} MB)." |
| 96 | exit 1 |
| 97 | fi |
| 98 | |
Nick Sanders | 8ab729a | 2010-06-16 03:15:17 -0700 | [diff] [blame] | 99 | EMERGE_BOARD_CMD="emerge-${FLAGS_board}" |
Nick Sanders | f2dee6c | 2010-07-01 00:21:32 -0700 | [diff] [blame] | 100 | if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then |
Nick Sanders | 8ab729a | 2010-06-16 03:15:17 -0700 | [diff] [blame] | 101 | echo "Using alternate emerge" |
Nick Sanders | f2dee6c | 2010-07-01 00:21:32 -0700 | [diff] [blame] | 102 | EMERGE_BOARD_CMD="${SCRIPTS_DIR}/parallel_emerge --board=${FLAGS_board}" |
Nick Sanders | 8ab729a | 2010-06-16 03:15:17 -0700 | [diff] [blame] | 103 | fi |
| 104 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 105 | # Determine build version. |
| 106 | . "${SCRIPTS_DIR}/chromeos_version.sh" |
| 107 | |
| 108 | # Use canonical path since some tools (e.g. mount) do not like symlinks. |
| 109 | # Append build attempt to output directory. |
| 110 | IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}" |
| 111 | OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}" |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 112 | |
| 113 | OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 114 | |
| 115 | # If we are creating a developer image, also create a pristine image with a |
| 116 | # different name. |
| 117 | DEVELOPER_IMAGE_NAME= |
| 118 | PRISTINE_IMAGE_NAME=chromiumos_image.bin |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 119 | if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 120 | PRISTINE_IMAGE_NAME=chromiumos_base_image.bin |
| 121 | DEVELOPER_IMAGE_NAME=chromiumos_image.bin |
| 122 | fi |
Tan Gao | a40ed44 | 2010-06-02 15:45:19 -0700 | [diff] [blame] | 123 | |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 124 | PRISTINE_IMG="${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}" |
| 125 | DEVELOPER_IMG="${OUTPUT_DIR}/${DEVELOPER_IMAGE_NAME}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 126 | |
| 127 | BOARD="${FLAGS_board}" |
| 128 | BOARD_ROOT="${FLAGS_build_root}/${BOARD}" |
| 129 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 130 | ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" |
| 131 | ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 132 | ROOT_FS_HASH="${OUTPUT_DIR}/rootfs.hash" |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 133 | |
| 134 | STATEFUL_FS_IMG="${OUTPUT_DIR}/stateful_partition.image" |
| 135 | STATEFUL_FS_DIR="${OUTPUT_DIR}/stateful_partition" |
| 136 | |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 137 | OEM_FS_IMG="${OUTPUT_DIR}/partner_partition.image" |
| 138 | OEM_FS_DIR="${OUTPUT_DIR}/partner_partition" |
| 139 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 140 | ESP_FS_IMG=${OUTPUT_DIR}/esp.image |
| 141 | ESP_FS_DIR=${OUTPUT_DIR}/esp |
| 142 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 143 | LOOP_DEV= |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 144 | STATEFUL_LOOP_DEV= |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 145 | OEM_LOOP_DEV= |
Bill Richardson | a81df76 | 2010-04-09 08:12:05 -0700 | [diff] [blame] | 146 | ESP_LOOP_DEV= |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 147 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 148 | # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will |
| 149 | # be installed on the stateful dir. On a Chromium OS system, this will |
| 150 | # translate to /usr/local. |
| 151 | DEV_IMAGE_ROOT="${STATEFUL_FS_DIR}/dev_image" |
| 152 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 153 | # What cross-build are we targeting? |
| 154 | . "${BOARD_ROOT}/etc/make.conf.board_setup" |
| 155 | LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"} |
| 156 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 157 | INSTALL_MASK="" |
| 158 | if [[ ${FLAGS_installmask} -eq ${FLAGS_TRUE} ]] ; then |
| 159 | INSTALL_MASK="${DEFAULT_INSTALL_MASK}" |
| 160 | fi |
| 161 | |
| 162 | # Reduce the size of factory install shim. |
| 163 | # TODO: Build a separated ebuild for the factory install shim to reduce size. |
| 164 | if [[ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]] ; then |
| 165 | INSTALL_MASK="${INSTALL_MASK} ${FACTORY_INSTALL_MASK}" |
| 166 | fi |
| 167 | |
David James | fd7403a | 2010-07-09 12:00:17 -0700 | [diff] [blame] | 168 | if [[ ${FLAGS_jobs} -ne -1 ]]; then |
| 169 | EMERGE_JOBS="--jobs=${FLAGS_jobs}" |
| 170 | fi |
| 171 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 172 | # Figure out ARCH from the given toolchain. |
| 173 | # 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] | 174 | TC_ARCH=$(echo "${CHOST}" | awk -F'-' '{ print $1 }') |
| 175 | case "${TC_ARCH}" in |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 176 | arm*) |
| 177 | ARCH="arm" |
| 178 | ;; |
| 179 | *86) |
| 180 | ARCH="x86" |
| 181 | ;; |
| 182 | *) |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 183 | error "Unable to determine ARCH from toolchain: ${CHOST}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 184 | exit 1 |
| 185 | esac |
| 186 | |
| 187 | # Hack to fix bug where x86_64 CHOST line gets incorrectly added. |
| 188 | # ToDo(msb): remove this hack. |
| 189 | PACKAGES_FILE="${BOARD_ROOT}/packages/Packages" |
| 190 | sudo sed -e "s/CHOST: x86_64-pc-linux-gnu//" -i "${PACKAGES_FILE}" |
| 191 | |
| 192 | # Handle existing directory. |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 193 | if [[ -e "${OUTPUT_DIR}" ]]; then |
| 194 | if [[ ${FLAGS_replace} -eq ${FLAGS_TRUE} ]]; then |
| 195 | sudo rm -rf "${OUTPUT_DIR}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 196 | else |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 197 | echo "Directory ${OUTPUT_DIR} already exists." |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 198 | echo "Use --build_attempt option to specify an unused attempt." |
| 199 | echo "Or use --replace if you want to overwrite this directory." |
| 200 | exit 1 |
| 201 | fi |
| 202 | fi |
| 203 | |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 204 | # Find previous build, if any... |
| 205 | PREVIOUS_DIR=$($SCRIPTS_DIR/get_latest_image.sh --board="$BOARD") |
| 206 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 207 | cleanup_rootfs_loop() { |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 208 | sudo umount -d "${ROOT_FS_DIR}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | cleanup_stateful_fs_loop() { |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 212 | sudo umount "${ROOT_FS_DIR}/usr/local" |
| 213 | sudo umount "${ROOT_FS_DIR}/var" |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 214 | sudo umount -d "${STATEFUL_FS_DIR}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 217 | cleanup_oem_fs_loop() { |
| 218 | sudo umount -d "${OEM_FS_DIR}" |
| 219 | } |
| 220 | |
| 221 | |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 222 | cleanup_esp_loop() { |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 223 | sudo umount -d "${ESP_FS_DIR}" |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 226 | cleanup() { |
| 227 | # Disable die on error. |
| 228 | set +e |
| 229 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 230 | if [[ -n "${STATEFUL_LOOP_DEV}" ]]; then |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 231 | cleanup_stateful_fs_loop |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 232 | STATEFUL_LOOP_DEV= |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 233 | fi |
| 234 | |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 235 | if [[ -n "${OEM_LOOP_DEV}" ]]; then |
| 236 | cleanup_oem_fs_loop |
| 237 | fi |
| 238 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 239 | if [[ -n "${LOOP_DEV}" ]]; then |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 240 | cleanup_rootfs_loop |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 241 | LOOP_DEV= |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 242 | fi |
| 243 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 244 | if [[ -n "${ESP_LOOP_DEV}" ]]; then |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 245 | cleanup_esp_loop |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 246 | ESP_LOOP_DEV= |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 247 | fi |
| 248 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 249 | # Turn die on error back on. |
| 250 | set -e |
| 251 | } |
| 252 | |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 253 | delete_prompt() { |
| 254 | echo "An error occurred in your build so your latest output directory" \ |
| 255 | "is invalid." |
| 256 | 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] | 257 | SURE="${SURE:0:1}" # Get just the first character. |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 258 | if [ "${SURE}" == "y" ] ; then |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 259 | sudo rm -rf "${OUTPUT_DIR}" |
| 260 | echo "Deleted ${OUTPUT_DIR}" |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 261 | else |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 262 | echo "Not deleting ${OUTPUT_DIR}. Note dev server updates will not work" \ |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 263 | "until you successfully build another image or delete this directory" |
| 264 | fi |
| 265 | } |
| 266 | |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 267 | # $1 - Directory where developer rootfs is mounted. |
| 268 | # $2 - Directory where developer stateful_partition is mounted. |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 269 | # $3 - Directory where the ESP partition is mounted. |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 270 | mount_gpt_cleanup() { |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 271 | local rootfs="${1-$ROOT_FS_DIR}" |
| 272 | local statefs="${2-$STATEFUL_FS_DIR}" |
| 273 | local espfs="${3-$ESP_FS_DIR}" |
| 274 | "${SCRIPTS_DIR}/mount_gpt_image.sh" \ |
| 275 | -u -r "${rootfs}" -s "${statefs}" -e "${espfs}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 276 | delete_prompt |
| 277 | } |
| 278 | |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 279 | make_image_bootable() { |
| 280 | local image_name="$1" |
| 281 | cros_root=/dev/sd%D%P |
| 282 | if [[ "${ARCH}" = "arm" ]]; then |
| 283 | # TODO(wad) assumed like in build_gpt for now. |
| 284 | cros_root=/dev/mmcblk1p3 |
| 285 | fi |
Will Drewry | 1670d48 | 2010-07-09 13:08:38 -0700 | [diff] [blame] | 286 | if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 287 | cros_root=/dev/dm-0 |
| 288 | fi |
| 289 | |
| 290 | # TODO(wad) mount the root fs to LOOP_DEV from the image |
| 291 | trap "mount_gpt_cleanup" EXIT |
| 292 | ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \ |
| 293 | --image "${image_name}" -r "${ROOT_FS_DIR}" \ |
Will Drewry | 721d94f | 2010-07-16 14:39:45 -0500 | [diff] [blame^] | 294 | -s "${STATEFUL_FS_DIR}" |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 295 | |
| 296 | sudo mount -o remount,ro "${ROOT_FS_DIR}" |
| 297 | root_dev=$(mount | grep -- "${ROOT_FS_DIR}" | cut -f1 -d' ' | tail -1) |
| 298 | |
Mandeep Singh Baines | 87b1694 | 2010-07-09 20:52:41 -0700 | [diff] [blame] | 299 | DEVKEYSDIR="/usr/share/vboot/devkeys" |
Louis Yung-Chieh Lo | 3602040 | 2010-07-05 13:23:34 +0800 | [diff] [blame] | 300 | |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 301 | # Builds the kernel partition image. The temporary files are kept around |
| 302 | # so that we can perform a load_kernel_test later on the final image. |
| 303 | ${SCRIPTS_DIR}/build_kernel_image.sh \ |
| 304 | --arch="${ARCH}" \ |
| 305 | --to="${OUTPUT_DIR}/vmlinuz.image" \ |
Louis Yung-Chieh Lo | 3602040 | 2010-07-05 13:23:34 +0800 | [diff] [blame] | 306 | --hd_vblock="${OUTPUT_DIR}/vmlinuz_hd.vblock" \ |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 307 | --vmlinuz="${OUTPUT_DIR}/boot/vmlinuz" \ |
| 308 | --working_dir="${OUTPUT_DIR}" \ |
| 309 | --keep_work \ |
| 310 | --rootfs_image=${root_dev} \ |
| 311 | --rootfs_hash=${OUTPUT_DIR}/rootfs.hash \ |
Will Drewry | 1670d48 | 2010-07-09 13:08:38 -0700 | [diff] [blame] | 312 | --verity_hash_alg=${FLAGS_verity_algorithm} \ |
| 313 | --verity_tree_depth=${FLAGS_verity_depth} \ |
| 314 | --verity_max_ios=${FLAGS_verity_max_ios} \ |
| 315 | --verity_error_behavior=${FLAGS_verity_error_behavior} \ |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 316 | --root=${cros_root} \ |
Louis Yung-Chieh Lo | 3602040 | 2010-07-05 13:23:34 +0800 | [diff] [blame] | 317 | --keys_dir="${DEVKEYSDIR}" |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 318 | |
Louis Yung-Chieh Lo | ca1c2b0 | 2010-07-05 17:37:05 +0800 | [diff] [blame] | 319 | # Move the verification block needed for the hard disk install to the |
| 320 | # stateful partition. Mount stateful fs, copy file, and umount fs. |
| 321 | # In original CL: http://codereview.chromium.org/2868044, this was done in |
| 322 | # create_base_image(). However, it could break the build if it is a clean |
| 323 | # build because vmlinuz_hd.vblock hasn't been created by build_kernel_image.sh |
Louis Yung-Chieh Lo | 85d49fc | 2010-07-05 22:55:31 +0800 | [diff] [blame] | 324 | if [[ "${ARCH}" = "x86" ]]; then |
Louis Yung-Chieh Lo | 85d49fc | 2010-07-05 22:55:31 +0800 | [diff] [blame] | 325 | sudo cp "${OUTPUT_DIR}/vmlinuz_hd.vblock" "${STATEFUL_FS_DIR}" |
Louis Yung-Chieh Lo | ca1c2b0 | 2010-07-05 17:37:05 +0800 | [diff] [blame] | 326 | fi |
Louis Yung-Chieh Lo | ca1c2b0 | 2010-07-05 17:37:05 +0800 | [diff] [blame] | 327 | |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 328 | # START_KERN_A is set by the first call to install the gpt. |
| 329 | local koffset="$(partoffset ${OUTPUT_DIR}/${image_name} 2)" |
| 330 | sudo dd if="${OUTPUT_DIR}/vmlinuz.image" of="${OUTPUT_DIR}/${image_name}" \ |
| 331 | conv=notrunc bs=512 seek=${koffset} |
| 332 | |
Will Drewry | 07e3505 | 2010-07-09 14:50:42 -0700 | [diff] [blame] | 333 | # Update the bootloaders. For legacy/efi x86, the EFI system partition |
| 334 | # will be updated and for arm, the mbr will be updated (for u-boot). |
Will Drewry | 721d94f | 2010-07-16 14:39:45 -0500 | [diff] [blame^] | 335 | local kernel_part= |
| 336 | local bootloader_to= |
| 337 | local bootloader_to_flags= |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 338 | local usb_disk="${FLAGS_usb_disk}" |
Will Drewry | 721d94f | 2010-07-16 14:39:45 -0500 | [diff] [blame^] | 339 | |
| 340 | if [[ "${ARCH}" = "x86" ]]; then |
| 341 | # x86 should update the esp in place in the image. |
| 342 | bootloader_to="${OUTPUT_DIR}/${image_name}" |
| 343 | local esp_offset="$(partoffset ${OUTPUT_DIR}/${image_name} 12)" |
| 344 | esp_offset=$((esp_offset * 512)) # sectors to bytes |
| 345 | local esp_size="$(partsize ${OUTPUT_DIR}/${image_name} 12)" |
| 346 | esp_size=$((esp_size * 512)) # sectors to bytes |
| 347 | bootloader_to_flags="--to_offset=${esp_offset} --to_size=${esp_size}" |
| 348 | # Use the kernel partition to acquire configuration flags. |
| 349 | kernel_part="--kernel_partition='${OUTPUT_DIR}/vmlinuz.image'" |
| 350 | # Install syslinux on the EFI System Partition. |
| 351 | kernel_part="${kernel_part} --install_syslinux" |
| 352 | elif [[ "${ARCH}" = "arm" ]]; then |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 353 | # TODO(wad) mmcblk1p3 is hardcoded for arm for now! |
| 354 | usb_disk="/dev/mmcblk1p3" |
Will Drewry | 721d94f | 2010-07-16 14:39:45 -0500 | [diff] [blame^] | 355 | # ARM doesn't support using the kernel image for kernel cmdline flags yet. |
Will Drewry | 82780e5 | 2010-07-03 18:27:10 -0700 | [diff] [blame] | 356 | kernel_part="--kernel_cmdline=\"${FLAGS_arm_extra_bootargs}\" " |
| 357 | # TODO(wad) Integrate dmtable extraction into the arm build |
| 358 | # E.g. $(cat ${OUTPUT_DIR}/boot.config | tr -s '\n' ' ')" |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 359 | local kpart_offset="--kernel_partition_offset=${koffset}" |
Will Drewry | 82780e5 | 2010-07-03 18:27:10 -0700 | [diff] [blame] | 360 | local kpart_size="--kernel_partition_sectors=" |
| 361 | kpart_size="${kpart_size}$(partsize ${OUTPUT_DIR}/${image_name} 2)" |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 362 | kernel_part="${kernel_part} ${kpart_size} ${kpart_offset}" |
Will Drewry | 82780e5 | 2010-07-03 18:27:10 -0700 | [diff] [blame] | 363 | info "Using addition bootloader arguments: ${kernel_part}" |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 364 | bootloader_to="${OUTPUT_DIR}/arm.mbr" |
| 365 | fi |
| 366 | |
| 367 | # Update partition 12 / legacy bootloaders and arm. |
| 368 | ${SCRIPTS_DIR}/update_bootloaders.sh \ |
| 369 | --arch=${ARCH} \ |
| 370 | --to="${bootloader_to}" \ |
| 371 | --from="${OUTPUT_DIR}"/boot \ |
| 372 | --vmlinuz="${OUTPUT_DIR}"/boot/vmlinuz \ |
| 373 | --usb_disk="${usb_disk}" \ |
Will Drewry | 721d94f | 2010-07-16 14:39:45 -0500 | [diff] [blame^] | 374 | ${bootloader_to_flags} \ |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 375 | $kernel_part |
| 376 | |
| 377 | if [[ "${ARCH}" == "arm" ]]; then |
| 378 | sudo dd bs=1 conv=notrunc if="${bootloader_to}" \ |
| 379 | of="${OUTPUT_DIR}/${image_name}" |
| 380 | sudo rm "${bootloader_to}" |
| 381 | fi |
| 382 | |
| 383 | trap - EXIT |
| 384 | ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \ |
Andrew de los Reyes | 3172b7e | 2010-07-15 22:10:47 -0700 | [diff] [blame] | 385 | -s "${STATEFUL_FS_DIR}" |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 386 | } |
| 387 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 388 | # Modifies an existing image to add development packages |
| 389 | update_dev_packages() { |
| 390 | local image_name=$1 |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 391 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 392 | echo "Adding developer packages to ${image_name}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 393 | |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 394 | trap "mount_gpt_cleanup" EXIT |
Tan Gao | a40ed44 | 2010-06-02 15:45:19 -0700 | [diff] [blame] | 395 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 396 | ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \ |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 397 | --image "${image_name}" -r "${ROOT_FS_DIR}" \ |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 398 | -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 399 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 400 | # Determine the root dir for developer packages. |
| 401 | local root_dev_dir="${ROOT_FS_DIR}" |
| 402 | [ ${FLAGS_statefuldev} -eq ${FLAGS_TRUE} ] && \ |
| 403 | root_dev_dir="${ROOT_FS_DIR}/usr/local" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 404 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 405 | # Install developer packages described in chromeos-dev. |
| 406 | sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ |
| 407 | --root="${root_dev_dir}" --root-deps=rdeps \ |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 408 | --usepkg -uDNv chromeos-dev ${EMERGE_JOBS} |
| 409 | |
| 410 | if [[ $FLAGS_preserve -eq ${FLAGS_TRUE} ]] ; then |
| 411 | # Clean out unused packages |
| 412 | sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ |
| 413 | --root="${ROOT_FS_DIR}" --root-deps=rdeps \ |
| 414 | --usepkg --depclean ${EMERGE_JOBS} |
| 415 | fi |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 416 | |
| 417 | # Re-run ldconfig to fix /etc/ldconfig.so.cache. |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 418 | sudo /sbin/ldconfig -r "${ROOT_FS_DIR}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 419 | |
| 420 | # Mark the image as a developer image (input to chromeos_startup). |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 421 | sudo mkdir -p "${ROOT_FS_DIR}/root" |
| 422 | sudo touch "${ROOT_FS_DIR}/root/.dev_mode" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 423 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 424 | # Additional changes to developer image. |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 425 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 426 | # The ldd tool is a useful shell script but lives in glibc; just copy it. |
| 427 | sudo cp -a "$(which ldd)" "${root_dev_dir}/usr/bin" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 428 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 429 | # If vim is installed, then a vi symlink would probably help. |
| 430 | if [[ -x "${ROOT_FS_DIR}/usr/local/bin/vim" ]]; then |
| 431 | sudo ln -sf vim "${ROOT_FS_DIR}/usr/local/bin/vi" |
Girts Folkmanis | 7a8a838 | 2010-05-18 22:52:25 -0700 | [diff] [blame] | 432 | fi |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 433 | |
Tammo Spalink | cfc0c64 | 2010-07-07 10:51:21 +0800 | [diff] [blame] | 434 | # If pygtk is installed in stateful-dev, then install a path. |
| 435 | if [[ -d \ |
| 436 | "${ROOT_FS_DIR}/usr/local/lib/python2.6/site-packages/gtk-2.0" ]]; then |
| 437 | sudo bash -c "\ |
| 438 | echo gtk-2.0 > \ |
| 439 | ${ROOT_FS_DIR}/usr/local/lib/python2.6/site-packages/pygtk.pth" |
| 440 | fi |
| 441 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 442 | # Check that the image has been correctly created. Only do it if not |
| 443 | # building a factory install image, as the INSTALL_MASK for it will |
| 444 | # make test_image fail. |
| 445 | if [[ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ]] ; then |
| 446 | "${SCRIPTS_DIR}/test_image" \ |
| 447 | --root="${ROOT_FS_DIR}" \ |
| 448 | --target="${ARCH}" |
| 449 | fi |
| 450 | echo "Developer image built and stored at ${image_name}" |
| 451 | |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 452 | trap - EXIT |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 453 | ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \ |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 454 | -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}" |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | # Update the base package on an existing image. |
| 458 | update_base_packages() { |
| 459 | local image_name=$1 |
| 460 | |
| 461 | echo "Updating base packages on ${image_name}" |
| 462 | |
| 463 | # Create stateful partition of the same size as the rootfs. |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 464 | trap "mount_gpt_cleanup" EXIT |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 465 | |
| 466 | ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \ |
| 467 | --image "${image_name}" -r "${ROOT_FS_DIR}" \ |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 468 | -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}" |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 469 | |
| 470 | # Emerge updated packages, exactly like when creating base image |
| 471 | sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ |
| 472 | --root="${ROOT_FS_DIR}" --root-deps=rdeps \ |
| 473 | --usepkg -uDNv chromeos ${EMERGE_JOBS} |
| 474 | |
| 475 | # Clean out unused packages |
| 476 | sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ |
| 477 | --root="${ROOT_FS_DIR}" --root-deps=rdeps \ |
| 478 | --usepkg --depclean ${EMERGE_JOBS} |
| 479 | |
| 480 | trap - EXIT |
| 481 | ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \ |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 482 | -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 485 | create_base_image() { |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 486 | local image_name=$1 |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 487 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 488 | trap "cleanup && delete_prompt" EXIT |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 489 | |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 490 | UUID=$(uuidgen) |
| 491 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 492 | # Create and format the root file system. |
| 493 | |
| 494 | # Check for loop device before creating image. |
| 495 | LOOP_DEV=$(sudo losetup -f) |
| 496 | if [ -z "${LOOP_DEV}" ] ; then |
| 497 | echo "No free loop device. Free up a loop device or reboot. exiting. " |
| 498 | exit 1 |
| 499 | fi |
| 500 | |
| 501 | # Create root file system disk image to fit on a 1GB memory stick. |
| 502 | # 1 GB in hard-drive-manufacturer-speak is 10^9, not 2^30. 950MB < 10^9 bytes. |
| 503 | if [[ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]] ; then |
| 504 | ROOT_SIZE_BYTES=$((1024 * 1024 * 300)) |
| 505 | else |
| 506 | ROOT_SIZE_BYTES=$((1024 * 1024 * ${FLAGS_rootfs_size})) |
| 507 | fi |
| 508 | |
| 509 | dd if=/dev/zero of="${ROOT_FS_IMG}" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1)) |
| 510 | sudo losetup "${LOOP_DEV}" "${ROOT_FS_IMG}" |
| 511 | sudo mkfs.ext3 "${LOOP_DEV}" |
| 512 | |
| 513 | # Tune and mount rootfs. |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 514 | DISK_LABEL="C-KEYFOB" |
| 515 | sudo tune2fs -L "${DISK_LABEL}" -U "${UUID}" -c 0 -i 0 "${LOOP_DEV}" |
| 516 | sudo mount "${LOOP_DEV}" "${ROOT_FS_DIR}" |
| 517 | |
| 518 | # Create stateful partition of the same size as the rootfs. |
| 519 | STATEFUL_LOOP_DEV=$(sudo losetup -f) |
| 520 | if [ -z "${STATEFUL_LOOP_DEV}" ] ; then |
| 521 | echo "No free loop device. Free up a loop device or reboot. exiting. " |
| 522 | exit 1 |
| 523 | fi |
Eric Li | 5cf288f | 2010-06-28 12:46:26 -0700 | [diff] [blame] | 524 | STATEFUL_SIZE_BYTES=$((1024 * 1024 * ${FLAGS_statefulfs_size})) |
| 525 | dd if=/dev/zero of="${STATEFUL_FS_IMG}" bs=1 count=1 \ |
| 526 | seek=$((STATEFUL_SIZE_BYTES - 1)) |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 527 | |
| 528 | # Tune and mount the stateful partition. |
| 529 | UUID=$(uuidgen) |
| 530 | DISK_LABEL="C-STATE" |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 531 | sudo losetup "${STATEFUL_LOOP_DEV}" "${STATEFUL_FS_IMG}" |
| 532 | sudo mkfs.ext3 "${STATEFUL_LOOP_DEV}" |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 533 | 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] | 534 | sudo mount "${STATEFUL_LOOP_DEV}" "${STATEFUL_FS_DIR}" |
| 535 | |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 536 | # Create OEM partner partition. |
| 537 | OEM_LOOP_DEV=$(sudo losetup -f) |
| 538 | if [ -z "${OEM_LOOP_DEV}" ] ; then |
| 539 | echo "No free loop device. Free up a loop device or reboot. exiting. " |
| 540 | exit 1 |
| 541 | fi |
| 542 | OEM_SIZE_BYTES=$((1024 * 1024 * 16)) |
| 543 | dd if=/dev/zero of="${OEM_FS_IMG}" bs=1 count=1 seek=$((OEM_SIZE_BYTES - 1)) |
| 544 | |
| 545 | # Tune and mount OEM partner partition. |
| 546 | UUID=$(uuidgen) |
| 547 | DISK_LABEL="C-OEM" |
| 548 | sudo losetup "${OEM_LOOP_DEV}" "${OEM_FS_IMG}" |
| 549 | sudo mkfs.ext3 "${OEM_LOOP_DEV}" |
| 550 | sudo tune2fs -L "${DISK_LABEL}" -U "${UUID}" -c 0 -i 0 "${OEM_LOOP_DEV}" |
| 551 | sudo mount "${OEM_LOOP_DEV}" "${OEM_FS_DIR}" |
| 552 | |
Denis Romanov | 95bdf47 | 2010-07-12 22:44:42 +0400 | [diff] [blame] | 553 | # Populate OEM partner partition. |
| 554 | if [ -n ${FLAGS_oem_customization} ]; then |
| 555 | if [ ! -d ${FLAGS_oem_customization} ]; then |
| 556 | echo "Specified OEM content directory does not exist. exiting." |
| 557 | exit 1 |
| 558 | fi |
| 559 | for ITEM in `ls -A ${FLAGS_oem_customization}` |
| 560 | do sudo cp -a "${FLAGS_oem_customization}/$ITEM" "${OEM_FS_DIR}" |
| 561 | done |
| 562 | sudo find "${OEM_FS_DIR}" -type d -exec chmod 755 "{}" \; |
| 563 | sudo find "${OEM_FS_DIR}" -type f -exec chmod 644 "{}" \; |
| 564 | sudo chown -R root:root "${OEM_FS_DIR}" |
| 565 | fi |
| 566 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 567 | # -- Install packages into the root file system -- |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 568 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 569 | # We need to install libc manually from the cross toolchain. |
| 570 | # TODO: Improve this? We only want libc and not the whole toolchain. |
| 571 | PKGDIR="/var/lib/portage/pkgs/cross/" |
| 572 | sudo tar jxvpf \ |
| 573 | "${PKGDIR}/${CHOST}/cross-${CHOST}"/glibc-${LIBC_VERSION}.tbz2 \ |
| 574 | -C "${ROOT_FS_DIR}" --strip-components=3 \ |
| 575 | --exclude=usr/include --exclude=sys-include --exclude=*.a --exclude=*.o |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 576 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 577 | # We need to install libstdc++ manually from the cross toolchain. |
| 578 | # TODO: Figure out a better way of doing this? |
| 579 | sudo cp -a "${BOARD_ROOT}"/lib/libgcc_s.so* "${ROOT_FS_DIR}/lib" |
| 580 | 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] | 581 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 582 | # Prepare stateful partition with some pre-created directories. |
| 583 | sudo mkdir -p "${DEV_IMAGE_ROOT}" |
| 584 | sudo mkdir -p "${STATEFUL_FS_DIR}/var" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 585 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 586 | # Create symlinks so that /usr/local/usr based directories are symlinked to |
| 587 | # /usr/local/ directories e.g. /usr/local/usr/bin -> /usr/local/bin, etc. |
| 588 | setup_symlinks_on_root "${DEV_IMAGE_ROOT}" "${STATEFUL_FS_DIR}/var" \ |
| 589 | "${STATEFUL_FS_DIR}" |
Tom Wai-Hong Tam | f87a367 | 2010-05-17 16:06:33 +0800 | [diff] [blame] | 590 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 591 | # Perform binding rather than symlinking because directories must exist |
| 592 | # on rootfs so that we can bind at run-time since rootfs is read-only. |
| 593 | echo "Binding directories from stateful partition onto the rootfs" |
| 594 | sudo mkdir -p "${ROOT_FS_DIR}/usr/local" |
| 595 | sudo mount --bind "${DEV_IMAGE_ROOT}" "${ROOT_FS_DIR}/usr/local" |
| 596 | sudo mkdir -p "${ROOT_FS_DIR}/var" |
| 597 | sudo mount --bind "${STATEFUL_FS_DIR}/var" "${ROOT_FS_DIR}/var" |
| 598 | sudo mkdir -p "${ROOT_FS_DIR}/dev" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 599 | |
Mandeep Singh Baines | 3dfa852 | 2010-06-24 15:00:49 -0700 | [diff] [blame] | 600 | # 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] | 601 | # runtime packages for chrome os. This builds up a chrome os image from |
| 602 | # binary packages with runtime dependencies only. We use INSTALL_MASK to |
| 603 | # trim the image size as much as possible. |
| 604 | sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ |
| 605 | --root="${ROOT_FS_DIR}" --root-deps=rdeps \ |
Mandeep Singh Baines | 3dfa852 | 2010-06-24 15:00:49 -0700 | [diff] [blame] | 606 | --usepkg chromeos ${EMERGE_JOBS} |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 607 | |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 608 | # Perform any customizations on the root file system that are needed. |
| 609 | "${SCRIPTS_DIR}/customize_rootfs" \ |
| 610 | --root="${ROOT_FS_DIR}" \ |
| 611 | --target="${ARCH}" \ |
| 612 | --board="${BOARD}" |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 613 | |
Will Drewry | 1ee156f | 2010-07-03 13:27:19 -0500 | [diff] [blame] | 614 | # Populates the root filesystem with legacy bootloader templates |
| 615 | # appropriate for the platform. The autoupdater and installer will |
| 616 | # use those templates to update the legacy boot partition (12/ESP) |
| 617 | # on update. |
| 618 | # (This script does not populate vmlinuz.A and .B needed by syslinux.) |
Will Drewry | 1670d48 | 2010-07-09 13:08:38 -0700 | [diff] [blame] | 619 | enable_rootfs_verification= |
| 620 | if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then |
| 621 | enable_rootfs_verification="--enable_rootfs_verification" |
| 622 | fi |
| 623 | |
Will Drewry | 1ee156f | 2010-07-03 13:27:19 -0500 | [diff] [blame] | 624 | ${SCRIPTS_DIR}/create_legacy_bootloader_templates.sh \ |
| 625 | --arch=${ARCH} \ |
| 626 | --to="${ROOT_FS_DIR}"/boot \ |
| 627 | --install \ |
Will Drewry | 1670d48 | 2010-07-09 13:08:38 -0700 | [diff] [blame] | 628 | ${enable_rootfs_verification} |
Bill Richardson | 9c5e5ec | 2010-05-14 17:00:21 -0700 | [diff] [blame] | 629 | |
Will Drewry | 1ee156f | 2010-07-03 13:27:19 -0500 | [diff] [blame] | 630 | # Create a working copy so we don't need the rootfs mounted |
| 631 | sudo mkdir -p "${OUTPUT_DIR}"/boot |
| 632 | # This will include any built files dropped in /boot as well. |
| 633 | # Like the current vmlinuz. |
| 634 | sudo cp -r "${ROOT_FS_DIR}"/boot/. "${OUTPUT_DIR}"/boot/ |
Will Drewry | 25861ee | 2010-07-04 05:09:41 -0700 | [diff] [blame] | 635 | sudo chmod -R a+r "${OUTPUT_DIR}"/boot/ |
Bill Richardson | a81df76 | 2010-04-09 08:12:05 -0700 | [diff] [blame] | 636 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 637 | # Don't test the factory install shim. |
| 638 | if [[ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ]] ; then |
| 639 | # Check that the image has been correctly created. |
| 640 | "${SCRIPTS_DIR}/test_image" \ |
| 641 | --root="${ROOT_FS_DIR}" \ |
| 642 | --target="${ARCH}" |
| 643 | fi |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 644 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 645 | # Clean up symlinks so they work on a running target rooted at "/". |
| 646 | # Here development packages are rooted at /usr/local. However, do not |
| 647 | # create /usr/local or /var on host (already exist on target). |
| 648 | setup_symlinks_on_root "/usr/local" "/var" "${STATEFUL_FS_DIR}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 649 | |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 650 | # make_image_bootable will clobber vmlinuz.image for x86. |
| 651 | # Until then, just copy the kernel to vmlinuz.image. It is |
| 652 | # expected in build_gpt.sh and needed by ARM until it supports the |
| 653 | # full, signed kernel partition format. |
| 654 | cp "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image" |
| 655 | |
| 656 | # Create an empty esp image to be updated in by update_bootloaders.sh. |
| 657 | ${SCRIPTS_DIR}/create_esp.sh --to="${ESP_FS_IMG}" |
| 658 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 659 | cleanup |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 660 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 661 | trap delete_prompt EXIT |
Tan Gao | 6df5aee | 2010-05-19 14:19:55 -0700 | [diff] [blame] | 662 | |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 663 | # Create the GPT-formatted image. |
| 664 | ${SCRIPTS_DIR}/build_gpt.sh \ |
| 665 | --arch=${ARCH} \ |
| 666 | --board=${FLAGS_board} \ |
| 667 | --arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \ |
| 668 | --rootfs_partition_size=${FLAGS_rootfs_partition_size} \ |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 669 | "${OUTPUT_DIR}" \ |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 670 | "${OUTPUT_DIR}/${image_name}" |
| 671 | |
| 672 | trap - EXIT |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | # Create the output directory. |
| 676 | mkdir -p "${OUTPUT_DIR}" |
| 677 | mkdir -p "${ROOT_FS_DIR}" |
| 678 | mkdir -p "${STATEFUL_FS_DIR}" |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 679 | mkdir -p "${OEM_FS_DIR}" |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 680 | mkdir -p "${ESP_FS_DIR}" |
| 681 | |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 682 | # Preserve old images by copying them forward for --preserve. |
| 683 | if [[ $FLAGS_preserve -eq ${FLAGS_TRUE} ]] ; then |
| 684 | if [[ -f ${PREVIOUS_DIR}/${PRISTINE_IMAGE_NAME} ]] ; then |
| 685 | # Copy forward pristine image, and associated files |
| 686 | cp ${PREVIOUS_DIR}/*.sh ${PREVIOUS_DIR}/config.txt ${OUTPUT_DIR} |
| 687 | cp ${PREVIOUS_DIR}/${PRISTINE_IMAGE_NAME} ${OUTPUT_DIR} |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 688 | cp -r ${PREVIOUS_DIR}/boot ${OUTPUT_DIR}/boot |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 689 | |
| 690 | # Copy forward the developer image, if we already copied forward the base. |
| 691 | if [[ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]] && \ |
| 692 | [[ -f ${PREVIOUS_DIR}/${DEVELOPER_IMAGE_NAME} ]] ; then |
| 693 | cp ${PREVIOUS_DIR}/${DEVELOPER_IMAGE_NAME} ${OUTPUT_DIR} |
| 694 | fi |
| 695 | fi |
| 696 | fi |
| 697 | |
| 698 | if [[ -f ${PRISTINE_IMG} ]] ; then |
| 699 | update_base_packages ${PRISTINE_IMAGE_NAME} |
| 700 | else |
| 701 | create_base_image ${PRISTINE_IMAGE_NAME} |
| 702 | fi |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 703 | make_image_bootable ${PRISTINE_IMAGE_NAME} |
| 704 | |
| 705 | # FIXME: only signing things for x86 right now. |
| 706 | if [[ "${ARCH}" = "x86" ]]; then |
| 707 | # Verify the final image. |
| 708 | load_kernel_test "${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}" \ |
Louis Yung-Chieh Lo | 3602040 | 2010-07-05 13:23:34 +0800 | [diff] [blame] | 709 | "${DEVKEYSDIR}/recovery_key.vbpubk" |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 710 | fi |
Bill Richardson | 4364a2e | 2010-03-30 14:17:34 -0700 | [diff] [blame] | 711 | |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 712 | # Create a developer image based on the chromium os base image. |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 713 | if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ] ; then |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 714 | if [[ ! -f ${DEVELOPER_IMG} ]] ; then |
| 715 | echo "Creating developer image from base image ${PRISTINE_IMAGE_NAME}" |
| 716 | cp ${PRISTINE_IMG} ${DEVELOPER_IMG} |
| 717 | fi |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 718 | |
David James | 868d7bb | 2010-06-24 21:48:14 -0700 | [diff] [blame] | 719 | update_dev_packages ${DEVELOPER_IMAGE_NAME} |
Will Drewry | 4a675e1 | 2010-07-03 13:35:02 -0500 | [diff] [blame] | 720 | make_image_bootable ${DEVELOPER_IMAGE_NAME} |
Bill Richardson | 6ed1358 | 2010-06-16 21:38:15 -0700 | [diff] [blame] | 721 | fi |
| 722 | |
| 723 | # Clean up temporary files. |
Don Garrett | 3f41e15 | 2010-06-21 14:54:34 -0700 | [diff] [blame] | 724 | 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] | 725 | "${ESP_FS_IMG}" "${OEM_FS_IMG}" "${OUTPUT_DIR}/vmlinuz_hd.vblock" |
Denis Romanov | 1106154 | 2010-06-29 04:23:53 +0400 | [diff] [blame] | 726 | 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] | 727 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 728 | echo "Done. Image created in ${OUTPUT_DIR}" |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 729 | echo "Chromium OS image created as ${PRISTINE_IMAGE_NAME}" |
Don Garrett | e0020b1 | 2010-06-17 15:55:35 -0700 | [diff] [blame] | 730 | if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then |
| 731 | echo "Developer image created as ${DEVELOPER_IMAGE_NAME}" |
Chris Sosa | 9673f3b | 2010-05-18 13:24:40 -0700 | [diff] [blame] | 732 | fi |
Nick Sanders | 8ab729a | 2010-06-16 03:15:17 -0700 | [diff] [blame] | 733 | |
Nick Sanders | d250927 | 2010-06-16 03:50:04 -0700 | [diff] [blame] | 734 | print_time_elapsed |
| 735 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 736 | echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" |
Daniel Erat | dd9818a | 2010-04-26 09:16:44 -0700 | [diff] [blame] | 737 | echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 738 | echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" |
Zelidrag Hornung | 478a0d4 | 2010-07-14 11:47:39 -0700 | [diff] [blame] | 739 | echo " ./image_to_vm.sh --from=${OUTSIDE_OUTPUT_DIR}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 740 | echo "from the scripts directory where you entered the chroot." |