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