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. |
| 22 | DEFINE_string board "$DEFAULT_BOARD" \ |
| 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)" |
| 30 | DEFINE_boolean replace $FLAGS_FALSE \ |
| 31 | "Overwrite existing output, if any." |
| 32 | DEFINE_boolean withdev $FLAGS_TRUE \ |
| 33 | "Include useful developer friendly utilities in the image." |
| 34 | DEFINE_boolean installmask $FLAGS_TRUE \ |
| 35 | "Use INSTALL_MASK to shrink the resulting image." |
| 36 | DEFINE_integer jobs -1 \ |
| 37 | "How many packages to build in parallel at maximum." |
Chris Sosa | b9f2d2e | 2010-05-05 16:42:44 -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" |
robotboy | b75eee3 | 2010-04-30 09:51:23 -0700 | [diff] [blame] | 42 | DEFINE_string arm_extra_bootargs "" \ |
| 43 | "Additional command line options to pass to the ARM kernel." |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 44 | |
| 45 | # Parse command line. |
| 46 | FLAGS "$@" || exit 1 |
| 47 | eval set -- "${FLAGS_ARGV}" |
| 48 | |
| 49 | # Only now can we die on error. shflags functions leak non-zero error codes, |
| 50 | # so will die prematurely if 'set -e' is specified before now. |
| 51 | set -e |
| 52 | |
| 53 | if [ -z "$FLAGS_board" ] ; then |
| 54 | error "--board is required." |
| 55 | exit 1 |
| 56 | fi |
| 57 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 58 | # Determine build version. |
| 59 | . "${SCRIPTS_DIR}/chromeos_version.sh" |
| 60 | |
| 61 | # Use canonical path since some tools (e.g. mount) do not like symlinks. |
| 62 | # Append build attempt to output directory. |
| 63 | IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}" |
| 64 | OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}" |
| 65 | ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" |
| 66 | ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" |
Antoine Labour | e9e585f | 2010-04-01 15:57:57 -0700 | [diff] [blame] | 67 | OUTPUT_IMG=${FLAGS_to:-${OUTPUT_DIR}/chromiumos_image.bin} |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 68 | |
| 69 | BOARD="${FLAGS_board}" |
| 70 | BOARD_ROOT="${FLAGS_build_root}/${BOARD}" |
| 71 | |
| 72 | LOOP_DEV= |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 73 | STATEFUL_LOOP_DEV= |
Bill Richardson | a81df76 | 2010-04-09 08:12:05 -0700 | [diff] [blame] | 74 | ESP_LOOP_DEV= |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 75 | |
| 76 | # What cross-build are we targeting? |
| 77 | . "${BOARD_ROOT}/etc/make.conf.board_setup" |
| 78 | LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"} |
| 79 | |
| 80 | # Figure out ARCH from the given toolchain. |
| 81 | # TODO: Move to common.sh as a function after scripts are switched over. |
| 82 | TC_ARCH=$(echo "$CHOST" | awk -F'-' '{ print $1 }') |
| 83 | case "$TC_ARCH" in |
| 84 | arm*) |
| 85 | ARCH="arm" |
| 86 | ;; |
| 87 | *86) |
| 88 | ARCH="x86" |
| 89 | ;; |
| 90 | *) |
| 91 | error "Unable to determine ARCH from toolchain: $CHOST" |
| 92 | exit 1 |
| 93 | esac |
| 94 | |
| 95 | # Hack to fix bug where x86_64 CHOST line gets incorrectly added. |
| 96 | # ToDo(msb): remove this hack. |
| 97 | PACKAGES_FILE="${BOARD_ROOT}/packages/Packages" |
| 98 | sudo sed -e "s/CHOST: x86_64-pc-linux-gnu//" -i "${PACKAGES_FILE}" |
| 99 | |
| 100 | # Handle existing directory. |
| 101 | if [[ -e "$OUTPUT_DIR" ]]; then |
| 102 | if [[ $FLAGS_replace -eq $FLAGS_TRUE ]]; then |
| 103 | sudo rm -rf "$OUTPUT_DIR" |
| 104 | else |
| 105 | echo "Directory $OUTPUT_DIR already exists." |
| 106 | echo "Use --build_attempt option to specify an unused attempt." |
| 107 | echo "Or use --replace if you want to overwrite this directory." |
| 108 | exit 1 |
| 109 | fi |
| 110 | fi |
| 111 | |
| 112 | # Create the output directory. |
| 113 | mkdir -p "$OUTPUT_DIR" |
| 114 | |
| 115 | cleanup_rootfs_loop() { |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 116 | sudo umount -d "$ROOT_FS_DIR" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | cleanup_stateful_fs_loop() { |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 120 | sudo umount "${ROOT_FS_DIR}/usr/local" |
| 121 | sudo umount "${ROOT_FS_DIR}/var" |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 122 | sudo umount -d "${STATEFUL_DIR}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 125 | cleanup_esp_loop() { |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 126 | sudo umount -d "$ESP_DIR" |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 129 | cleanup() { |
| 130 | # Disable die on error. |
| 131 | set +e |
| 132 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 133 | if [[ -n "$STATEFUL_LOOP_DEV" ]]; then |
| 134 | cleanup_stateful_fs_loop |
| 135 | fi |
| 136 | |
| 137 | if [[ -n "$LOOP_DEV" ]]; then |
| 138 | cleanup_rootfs_loop |
| 139 | fi |
| 140 | |
Bill Richardson | a81df76 | 2010-04-09 08:12:05 -0700 | [diff] [blame] | 141 | if [[ -n "$ESP_LOOP_DEV" ]]; then |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 142 | cleanup_esp_loop |
| 143 | fi |
| 144 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 145 | # Turn die on error back on. |
| 146 | set -e |
| 147 | } |
| 148 | |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 149 | delete_prompt() { |
| 150 | echo "An error occurred in your build so your latest output directory" \ |
| 151 | "is invalid." |
| 152 | read -p "Would you like to delete the output directory (y/N)? " SURE |
| 153 | SURE="${SURE:0:1}" # Get just the first character |
| 154 | if [ "${SURE}" == "y" ] ; then |
| 155 | sudo rm -rf "$OUTPUT_DIR" |
| 156 | echo "Deleted $OUTPUT_DIR" |
| 157 | else |
| 158 | echo "Not deleting $OUTPUT_DIR. Note dev server updates will not work" \ |
| 159 | "until you successfully build another image or delete this directory" |
| 160 | fi |
| 161 | } |
| 162 | |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 163 | # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will |
| 164 | # be installed on the stateful dir. On a Chromium OS system, this will |
| 165 | # translate to /usr/local |
| 166 | DEV_IMAGE_ROOT= |
| 167 | |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 168 | trap "cleanup && delete_prompt" EXIT |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 169 | |
| 170 | mkdir -p "$ROOT_FS_DIR" |
| 171 | |
| 172 | # Create and format the root file system. |
| 173 | |
| 174 | # Check for loop device before creating image. |
| 175 | LOOP_DEV=$(sudo losetup -f) |
| 176 | if [ -z "$LOOP_DEV" ] ; then |
| 177 | echo "No free loop device. Free up a loop device or reboot. exiting. " |
| 178 | exit 1 |
| 179 | fi |
| 180 | |
| 181 | # Create root file system disk image to fit on a 1GB memory stick. |
| 182 | # 1 GB in hard-drive-manufacturer-speak is 10^9, not 2^30. 950MB < 10^9 bytes. |
Chris Masone | 35a83f9 | 2010-04-05 16:51:53 -0700 | [diff] [blame] | 183 | ROOT_SIZE_BYTES=$((1024 * 1024 * 720)) |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 184 | dd if=/dev/zero of="$ROOT_FS_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1)) |
| 185 | sudo losetup "$LOOP_DEV" "$ROOT_FS_IMG" |
| 186 | sudo mkfs.ext3 "$LOOP_DEV" |
| 187 | |
| 188 | # Tune and mount rootfs. |
| 189 | UUID=$(uuidgen) |
| 190 | DISK_LABEL="C-KEYFOB" |
| 191 | sudo tune2fs -L "$DISK_LABEL" -U "$UUID" -c 0 -i 0 "$LOOP_DEV" |
| 192 | sudo mount "$LOOP_DEV" "$ROOT_FS_DIR" |
| 193 | |
| 194 | # Create stateful partition of the same size as the rootfs. |
| 195 | STATEFUL_IMG="$OUTPUT_DIR/stateful_partition.image" |
| 196 | STATEFUL_DIR="$OUTPUT_DIR/stateful_partition" |
| 197 | STATEFUL_LOOP_DEV=$(sudo losetup -f) |
| 198 | if [ -z "$STATEFUL_LOOP_DEV" ] ; then |
| 199 | echo "No free loop device. Free up a loop device or reboot. exiting. " |
| 200 | exit 1 |
| 201 | fi |
| 202 | dd if=/dev/zero of="$STATEFUL_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1)) |
| 203 | sudo losetup "$STATEFUL_LOOP_DEV" "$STATEFUL_IMG" |
| 204 | sudo mkfs.ext3 "$STATEFUL_LOOP_DEV" |
| 205 | sudo tune2fs -L "C-STATE" -U "$UUID" -c 0 -i 0 \ |
| 206 | "$STATEFUL_LOOP_DEV" |
| 207 | |
| 208 | # Mount the stateful partition. |
| 209 | mkdir -p "$STATEFUL_DIR" |
| 210 | sudo mount "$STATEFUL_LOOP_DEV" "$STATEFUL_DIR" |
| 211 | |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 212 | # Set dev image root now that we have mounted the stateful partition we created |
| 213 | DEV_IMAGE_ROOT="$STATEFUL_DIR/dev_image" |
| 214 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 215 | # Turn root file system into bootable image. |
| 216 | if [[ "$ARCH" = "x86" ]]; then |
| 217 | # Setup extlinux configuration. |
| 218 | # TODO: For some reason the /dev/disk/by-uuid is not being generated by udev |
| 219 | # in the initramfs. When we figure that out, switch to root=UUID=$UUID. |
| 220 | sudo mkdir -p "$ROOT_FS_DIR"/boot |
| 221 | # TODO(adlr): use initramfs for booting. |
| 222 | cat <<EOF | sudo dd of="$ROOT_FS_DIR"/boot/extlinux.conf |
| 223 | DEFAULT chromeos-usb |
| 224 | PROMPT 0 |
| 225 | TIMEOUT 0 |
| 226 | |
| 227 | label chromeos-usb |
| 228 | menu label chromeos-usb |
| 229 | kernel vmlinuz |
| 230 | append quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sdb3 ro noresume noswap i915.modeset=1 loglevel=1 |
| 231 | |
| 232 | label chromeos-hd |
| 233 | menu label chromeos-hd |
| 234 | kernel vmlinuz |
| 235 | append quiet console=tty2 init=/sbin/init boot=local rootwait root=HDROOT ro noresume noswap i915.modeset=1 loglevel=1 |
| 236 | EOF |
| 237 | |
| 238 | # Make partition bootable and label it. |
| 239 | sudo extlinux -z --install "${ROOT_FS_DIR}/boot" |
| 240 | fi |
| 241 | |
| 242 | # -- Install packages into the root file system -- |
| 243 | |
| 244 | # We need to install libc manually from the cross toolchain. |
| 245 | # TODO: Improve this? We only want libc and not the whole toolchain. |
| 246 | PKGDIR="/var/lib/portage/pkgs/cross/" |
| 247 | sudo tar jxvpf \ |
| 248 | "${PKGDIR}/${CHOST}/cross-${CHOST}"/glibc-${LIBC_VERSION}.tbz2 \ |
| 249 | -C "$ROOT_FS_DIR" --strip-components=3 \ |
| 250 | --exclude=usr/include --exclude=sys-include --exclude=*.a --exclude=*.o |
| 251 | |
| 252 | # We need to install libstdc++ manually from the cross toolchain. |
| 253 | # TODO: Figure out a better way of doing this? |
| 254 | sudo cp -a "${BOARD_ROOT}"/lib/libgcc_s.so* "${ROOT_FS_DIR}/lib" |
| 255 | sudo cp -a "${BOARD_ROOT}"/usr/lib/libstdc++.so* "${ROOT_FS_DIR}/usr/lib" |
| 256 | |
| 257 | INSTALL_MASK="" |
Chris Sosa | 3d9a10b | 2010-04-13 15:00:46 -0700 | [diff] [blame] | 258 | if [[ $FLAGS_installmask -eq ${FLAGS_TRUE} ]] ; then |
Chris Sosa | aa1a7fd | 2010-04-02 14:06:29 -0700 | [diff] [blame] | 259 | INSTALL_MASK="$DEFAULT_INSTALL_MASK" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 260 | fi |
| 261 | |
| 262 | if [[ $FLAGS_jobs -ne -1 ]]; then |
| 263 | EMERGE_JOBS="--jobs=$FLAGS_jobs" |
| 264 | fi |
| 265 | |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 266 | # Prepare stateful partition with some pre-created directories |
| 267 | sudo mkdir -p "${DEV_IMAGE_ROOT}" |
| 268 | sudo mkdir -p "${STATEFUL_DIR}/var" |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 269 | |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 270 | # Create symlinks so that /usr/local/usr based directories are symlinked to |
| 271 | # /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] | 272 | setup_symlinks_on_root "${DEV_IMAGE_ROOT}" "${STATEFUL_DIR}/var" \ |
| 273 | "${STATEFUL_DIR}" |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 274 | |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 275 | # Perform binding rather than symlinking because directories must exist |
| 276 | # on rootfs so that we can bind at run-time since rootfs is read-only |
| 277 | echo "Binding directories from stateful partition onto the rootfs" |
| 278 | sudo mkdir -p "${ROOT_FS_DIR}/usr/local" |
| 279 | sudo mount --bind "${DEV_IMAGE_ROOT}" "${ROOT_FS_DIR}/usr/local" |
| 280 | sudo mkdir -p "${ROOT_FS_DIR}/var" |
| 281 | sudo mount --bind "${STATEFUL_DIR}/var" "${ROOT_FS_DIR}/var" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 282 | |
| 283 | # We "emerge --root=$ROOT_FS_DIR --root-deps=rdeps --usepkgonly" all of the |
| 284 | # runtime packages for chrome os. This builds up a chrome os image from binary |
| 285 | # packages with runtime dependencies only. We use INSTALL_MASK to trim the |
| 286 | # image size as much as possible. |
Ken Mixter | d5c4b17 | 2010-04-16 10:11:02 -0700 | [diff] [blame] | 287 | sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \ |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 288 | --root="$ROOT_FS_DIR" --root-deps=rdeps \ |
| 289 | --usepkgonly chromeos $EMERGE_JOBS |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 290 | |
Chris Sosa | 4bccd3c | 2010-03-15 13:23:14 -0700 | [diff] [blame] | 291 | # Determine the root dir for development packages. |
| 292 | ROOT_DEV_DIR="$ROOT_FS_DIR" |
| 293 | [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] && ROOT_DEV_DIR="$ROOT_FS_DIR/usr/local" |
| 294 | |
| 295 | # Install development packages. |
| 296 | if [[ $FLAGS_withdev -eq $FLAGS_TRUE ]] ; then |
Ken Mixter | d5c4b17 | 2010-04-16 10:11:02 -0700 | [diff] [blame] | 297 | sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \ |
Chris Sosa | 4bccd3c | 2010-03-15 13:23:14 -0700 | [diff] [blame] | 298 | --root="$ROOT_DEV_DIR" --root-deps=rdeps \ |
| 299 | --usepkgonly chromeos-dev $EMERGE_JOBS |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 300 | |
Chris Sosa | 3d9a10b | 2010-04-13 15:00:46 -0700 | [diff] [blame] | 301 | # TODO(sosa@chromium.org) - Re-hide under statefuldev after switch |
| 302 | # Flag will mount /usr/local on target device |
| 303 | sudo mkdir -p "$ROOT_FS_DIR/root" |
Chris Sosa | 3d9a10b | 2010-04-13 15:00:46 -0700 | [diff] [blame] | 304 | |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 305 | # The ldd tool is a useful shell script but lives in glibc; just copy it. |
Chris Sosa | 4bccd3c | 2010-03-15 13:23:14 -0700 | [diff] [blame] | 306 | sudo cp -a "$(which ldd)" "${ROOT_DEV_DIR}/usr/bin" |
| 307 | fi |
| 308 | |
Bill Richardson | 4364a2e | 2010-03-30 14:17:34 -0700 | [diff] [blame] | 309 | # Extract the kernel from the root filesystem for use by the GPT image. Legacy |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 310 | # BIOS will use the kernel in the rootfs (via syslinux), Chrome OS BIOS will |
| 311 | # use the kernel partition. |
Bill Richardson | 6dcea16 | 2010-03-31 19:20:24 -0700 | [diff] [blame] | 312 | sudo cp -f "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image" |
Bill Richardson | 4364a2e | 2010-03-30 14:17:34 -0700 | [diff] [blame] | 313 | |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 314 | # Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI |
| 315 | # BIOS). We only need this for x86, but it's simpler and safer to keep the disk |
| 316 | # images the same for both x86 and ARM. |
| 317 | ESP_IMG=${OUTPUT_DIR}/esp.image |
| 318 | # NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. We'll hard-code |
| 319 | # it to 16M for now. |
| 320 | ESP_BLOCKS=16384 |
| 321 | /usr/sbin/mkfs.vfat -C ${OUTPUT_DIR}/esp.image ${ESP_BLOCKS} |
| 322 | ESP_DIR=${OUTPUT_DIR}/esp |
Bill Richardson | a81df76 | 2010-04-09 08:12:05 -0700 | [diff] [blame] | 323 | ESP_LOOP_DEV=$(sudo losetup -f) |
| 324 | if [ -z "$ESP_LOOP_DEV" ] ; then |
| 325 | echo "No free loop device. Free up a loop device or reboot. exiting. " |
| 326 | exit 1 |
| 327 | fi |
| 328 | mkdir -p "${ESP_DIR}" |
| 329 | sudo losetup "${ESP_LOOP_DEV}" "${ESP_IMG}" |
| 330 | sudo mount "${ESP_LOOP_DEV}" "${ESP_DIR}" |
| 331 | sudo mkdir -p "${ESP_DIR}/efi/boot" |
| 332 | 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] | 333 | part_gpt fat ext2 normal boot sh chain configfile linux |
Bill Richardson | a81df76 | 2010-04-09 08:12:05 -0700 | [diff] [blame] | 334 | sudo cp "${ROOT_FS_DIR}/boot/vmlinuz" "${ESP_DIR}/efi/boot/vmlinuz" |
| 335 | cat <<EOF | sudo dd of="${ESP_DIR}/efi/boot/grub.cfg" |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 336 | set timeout=2 |
| 337 | set default=0 |
| 338 | |
Bill Richardson | 041bd71 | 2010-04-27 09:36:14 -0700 | [diff] [blame] | 339 | menuentry "boot from disk" { |
Bill Richardson | a81df76 | 2010-04-09 08:12:05 -0700 | [diff] [blame] | 340 | linux /efi/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sda3 ro noresume noswap i915.modeset=1 loglevel=1 |
| 341 | } |
| 342 | |
Bill Richardson | 041bd71 | 2010-04-27 09:36:14 -0700 | [diff] [blame] | 343 | menuentry "boot from disk with serial debug" { |
Bill Richardson | ba9682a | 2010-04-13 13:02:32 -0700 | [diff] [blame] | 344 | linux /efi/boot/vmlinuz earlyprintk=serial,ttyS0,115200 console=ttyS0,115200 init=/sbin/init boot=local rootwait root=/dev/sda3 ro noresume noswap i915.modeset=1 loglevel=7 |
| 345 | } |
| 346 | |
Bill Richardson | 041bd71 | 2010-04-27 09:36:14 -0700 | [diff] [blame] | 347 | menuentry "boot from usb" { |
| 348 | linux /efi/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sdb3 ro noresume noswap i915.modeset=1 loglevel=1 |
| 349 | } |
| 350 | |
| 351 | menuentry "boot from usb with serial debug" { |
| 352 | linux /efi/boot/vmlinuz earlyprintk=serial,ttyS0,115200 console=ttyS0,115200 init=/sbin/init boot=local rootwait root=/dev/sdb3 ro noresume noswap i915.modeset=1 loglevel=7 |
| 353 | } |
| 354 | |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 355 | EOF |
| 356 | |
Chris Sosa | 5c37ce2 | 2010-05-03 20:18:02 -0700 | [diff] [blame] | 357 | # By default, dev mode should be activated for either development builds or |
| 358 | # test builds. |
| 359 | if [[ $FLAGS_withdev -eq $FLAGS_TRUE ]] ||\ |
| 360 | [[ $FLAGS_withtest -eq $FLAGS_TRUE ]]; then |
| 361 | sudo touch "$ROOT_FS_DIR/root/.dev_mode" |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 362 | |
Chris Sosa | 5c37ce2 | 2010-05-03 20:18:02 -0700 | [diff] [blame] | 363 | # Re-run ldconfig to fix /etc/ldconfig.so.cache. |
| 364 | sudo /sbin/ldconfig -r "$ROOT_FS_DIR" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 365 | fi |
| 366 | |
Chris Sosa | 3f21b99 | 2010-05-10 16:34:47 -0700 | [diff] [blame] | 367 | # Perform any customizations on the root file system that are needed. |
Chris Sosa | 503efe1 | 2010-04-08 10:05:46 -0700 | [diff] [blame] | 368 | "${SCRIPTS_DIR}/customize_rootfs" \ |
| 369 | --root="$ROOT_FS_DIR" \ |
| 370 | --target="$ARCH" \ |
Chris Sosa | 3f21b99 | 2010-05-10 16:34:47 -0700 | [diff] [blame] | 371 | --board="$BOARD" |
Chris Sosa | 503efe1 | 2010-04-08 10:05:46 -0700 | [diff] [blame] | 372 | |
| 373 | # Check that the image has been correctly created. |
| 374 | "${SCRIPTS_DIR}/test_image" \ |
| 375 | --root="$ROOT_FS_DIR" \ |
| 376 | --target="$ARCH" |
| 377 | |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 378 | # Clean up symlinks so they work on a running target rooted at "/". |
| 379 | # Here development packages are rooted at /usr/local. However, do not |
| 380 | # create /usr/local or /var on host (already exist on target). |
Chris Sosa | 702618f | 2010-05-14 12:52:32 -0700 | [diff] [blame] | 381 | setup_symlinks_on_root "/usr/local" "/var" "${STATEFUL_DIR}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 382 | |
| 383 | # Cleanup loop devices. |
Chris Sosa | 4bffb8b | 2010-04-07 17:23:54 -0700 | [diff] [blame] | 384 | cleanup |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 385 | |
Chris Sosa | bde8c1b | 2010-04-29 14:02:35 -0700 | [diff] [blame] | 386 | trap delete_prompt EXIT |
| 387 | |
Bill Richardson | 4364a2e | 2010-03-30 14:17:34 -0700 | [diff] [blame] | 388 | # Create the GPT-formatted image |
| 389 | ${SCRIPTS_DIR}/build_gpt.sh \ |
robotboy | b75eee3 | 2010-04-30 09:51:23 -0700 | [diff] [blame] | 390 | --arch=${ARCH} \ |
| 391 | --board=${FLAGS_board} \ |
| 392 | --arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \ |
| 393 | "${OUTPUT_DIR}" \ |
| 394 | "${OUTPUT_IMG}" |
Bill Richardson | 4364a2e | 2010-03-30 14:17:34 -0700 | [diff] [blame] | 395 | |
Bill Richardson | 6dcea16 | 2010-03-31 19:20:24 -0700 | [diff] [blame] | 396 | # Clean up temporary files. |
Bill Richardson | 8b3bd10 | 2010-04-06 15:00:10 -0700 | [diff] [blame] | 397 | rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \ |
| 398 | "${ESP_IMG}" |
| 399 | rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" "${ESP_DIR}" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 400 | |
| 401 | OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" |
| 402 | echo "Done. Image created in ${OUTPUT_DIR}" |
| 403 | echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" |
Daniel Erat | dd9818a | 2010-04-26 09:16:44 -0700 | [diff] [blame] | 404 | echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" |
Bill Richardson | c09b94f | 2010-03-15 11:40:30 -0700 | [diff] [blame] | 405 | echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" |
| 406 | echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" |
| 407 | echo "from the scripts directory where you entered the chroot." |
| 408 | |
| 409 | trap - EXIT |