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