blob: 3eb32e4a8c41e44a01b6d66d3824a4fa0c95e2bf [file] [log] [blame]
Bill Richardsonc09b94f2010-03-15 11:40:30 -07001#!/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 Garrett640a0582010-05-04 16:54:28 -070017restart_in_chroot_if_needed $*
Bill Richardsonc09b94f2010-03-15 11:40:30 -070018
19get_default_board
20
21# Flags.
22DEFINE_string board "$DEFAULT_BOARD" \
23 "The board to build an image for."
24DEFINE_string build_root "/build" \
25 "The root location for board sysroots."
26DEFINE_integer build_attempt 1 \
27 "The build attempt for this image build."
28DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/images" \
29 "Directory in which to place image result directories (named by version)"
30DEFINE_boolean replace $FLAGS_FALSE \
31 "Overwrite existing output, if any."
32DEFINE_boolean withdev $FLAGS_TRUE \
33 "Include useful developer friendly utilities in the image."
34DEFINE_boolean installmask $FLAGS_TRUE \
35 "Use INSTALL_MASK to shrink the resulting image."
36DEFINE_integer jobs -1 \
37 "How many packages to build in parallel at maximum."
Chris Sosab9f2d2e2010-05-05 16:42:44 -070038DEFINE_boolean statefuldev $FLAGS_TRUE \
Chris Sosa4bffb8b2010-04-07 17:23:54 -070039 "Install development packages on stateful partition rather than the rootfs"
Antoine Laboure9e585f2010-04-01 15:57:57 -070040DEFINE_string to "" \
41 "The target image file or device"
Chris Sosa77a29632010-03-15 14:12:15 -070042DEFINE_boolean withtest $FLAGS_FALSE \
Chris Sosa4bccd3c2010-03-15 13:23:14 -070043 "Include packages required for testing and prepare image for testing"
robotboyb75eee32010-04-30 09:51:23 -070044DEFINE_string arm_extra_bootargs "" \
45 "Additional command line options to pass to the ARM kernel."
Bill Richardsonc09b94f2010-03-15 11:40:30 -070046
47# Parse command line.
48FLAGS "$@" || exit 1
49eval set -- "${FLAGS_ARGV}"
50
51# Only now can we die on error. shflags functions leak non-zero error codes,
52# so will die prematurely if 'set -e' is specified before now.
53set -e
54
55if [ -z "$FLAGS_board" ] ; then
56 error "--board is required."
57 exit 1
58fi
59
Bill Richardsonc09b94f2010-03-15 11:40:30 -070060# Determine build version.
61. "${SCRIPTS_DIR}/chromeos_version.sh"
62
63# Use canonical path since some tools (e.g. mount) do not like symlinks.
64# Append build attempt to output directory.
65IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}"
66OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}"
67ROOT_FS_DIR="${OUTPUT_DIR}/rootfs"
68ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image"
Antoine Laboure9e585f2010-04-01 15:57:57 -070069OUTPUT_IMG=${FLAGS_to:-${OUTPUT_DIR}/chromiumos_image.bin}
Bill Richardsonc09b94f2010-03-15 11:40:30 -070070
71BOARD="${FLAGS_board}"
72BOARD_ROOT="${FLAGS_build_root}/${BOARD}"
73
74LOOP_DEV=
Chris Sosa4bffb8b2010-04-07 17:23:54 -070075STATEFUL_LOOP_DEV=
Bill Richardsona81df762010-04-09 08:12:05 -070076ESP_LOOP_DEV=
Bill Richardsonc09b94f2010-03-15 11:40:30 -070077
78# What cross-build are we targeting?
79. "${BOARD_ROOT}/etc/make.conf.board_setup"
80LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"}
81
82# Figure out ARCH from the given toolchain.
83# TODO: Move to common.sh as a function after scripts are switched over.
84TC_ARCH=$(echo "$CHOST" | awk -F'-' '{ print $1 }')
85case "$TC_ARCH" in
86 arm*)
87 ARCH="arm"
88 ;;
89 *86)
90 ARCH="x86"
91 ;;
92 *)
93 error "Unable to determine ARCH from toolchain: $CHOST"
94 exit 1
95esac
96
97# Hack to fix bug where x86_64 CHOST line gets incorrectly added.
98# ToDo(msb): remove this hack.
99PACKAGES_FILE="${BOARD_ROOT}/packages/Packages"
100sudo sed -e "s/CHOST: x86_64-pc-linux-gnu//" -i "${PACKAGES_FILE}"
101
102# Handle existing directory.
103if [[ -e "$OUTPUT_DIR" ]]; then
104 if [[ $FLAGS_replace -eq $FLAGS_TRUE ]]; then
105 sudo rm -rf "$OUTPUT_DIR"
106 else
107 echo "Directory $OUTPUT_DIR already exists."
108 echo "Use --build_attempt option to specify an unused attempt."
109 echo "Or use --replace if you want to overwrite this directory."
110 exit 1
111 fi
112fi
113
114# Create the output directory.
115mkdir -p "$OUTPUT_DIR"
116
117cleanup_rootfs_loop() {
Chris Sosabde8c1b2010-04-29 14:02:35 -0700118 sudo umount -d "$ROOT_FS_DIR"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700119}
120
121cleanup_stateful_fs_loop() {
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700122 sudo umount "${ROOT_FS_DIR}/usr/local"
123 sudo umount "${ROOT_FS_DIR}/var"
Chris Sosabde8c1b2010-04-29 14:02:35 -0700124 sudo umount -d "${STATEFUL_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700125}
126
Bill Richardson8b3bd102010-04-06 15:00:10 -0700127cleanup_esp_loop() {
Chris Sosabde8c1b2010-04-29 14:02:35 -0700128 sudo umount -d "$ESP_DIR"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700129}
130
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700131cleanup() {
132 # Disable die on error.
133 set +e
134
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700135 if [[ -n "$STATEFUL_LOOP_DEV" ]]; then
136 cleanup_stateful_fs_loop
137 fi
138
139 if [[ -n "$LOOP_DEV" ]]; then
140 cleanup_rootfs_loop
141 fi
142
Bill Richardsona81df762010-04-09 08:12:05 -0700143 if [[ -n "$ESP_LOOP_DEV" ]]; then
Bill Richardson8b3bd102010-04-06 15:00:10 -0700144 cleanup_esp_loop
145 fi
146
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700147 # Turn die on error back on.
148 set -e
149}
150
Chris Sosabde8c1b2010-04-29 14:02:35 -0700151delete_prompt() {
152 echo "An error occurred in your build so your latest output directory" \
153 "is invalid."
154 read -p "Would you like to delete the output directory (y/N)? " SURE
155 SURE="${SURE:0:1}" # Get just the first character
156 if [ "${SURE}" == "y" ] ; then
157 sudo rm -rf "$OUTPUT_DIR"
158 echo "Deleted $OUTPUT_DIR"
159 else
160 echo "Not deleting $OUTPUT_DIR. Note dev server updates will not work" \
161 "until you successfully build another image or delete this directory"
162 fi
163}
164
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700165# ${DEV_IMAGE_ROOT} specifies the location of where developer packages will
166# be installed on the stateful dir. On a Chromium OS system, this will
167# translate to /usr/local
168DEV_IMAGE_ROOT=
169
170# Sets up symlinks for the stateful partition based on the root specified by
171# ${1} and var directory specified by ${2}.
172setup_symlinks_on_root() {
173 echo "Setting up symlinks on the stateful partition rooted at ${1} with"\
174 "var directory located at ${2}"
175
176 for path in usr local; do
177 if [ -h "${DEV_IMAGE_ROOT}/${path}" ] ; then
178 sudo unlink "${DEV_IMAGE_ROOT}/${path}"
179 elif [ -e "${DEV_IMAGE_ROOT}/${path}" ] ; then
180 echo "*** ERROR: ${DEV_IMAGE_ROOT}/${path} should be a symlink if exists"
181 return 1
182 fi
183 sudo ln -s ${1} "${DEV_IMAGE_ROOT}/${path}"
184 done
185
186 # Setup var. Var is on the stateful partition at /var for both non-developer
187 # builds and developer builds.
188 if [ -h "${DEV_IMAGE_ROOT}/var" ] ; then
189 sudo unlink "${DEV_IMAGE_ROOT}/var"
190 elif [ -e "${DEV_IMAGE_ROOT}/var" ] ; then
191 echo "*** ERROR: ${DEV_IMAGE_ROOT}/var should be a symlink if it exists"
192 return 1
193 fi
194
195 sudo ln -s "${2}" "${DEV_IMAGE_ROOT}/var"
196}
197
Chris Sosabde8c1b2010-04-29 14:02:35 -0700198trap "cleanup && delete_prompt" EXIT
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700199
200mkdir -p "$ROOT_FS_DIR"
201
202# Create and format the root file system.
203
204# Check for loop device before creating image.
205LOOP_DEV=$(sudo losetup -f)
206if [ -z "$LOOP_DEV" ] ; then
207 echo "No free loop device. Free up a loop device or reboot. exiting. "
208 exit 1
209fi
210
211# Create root file system disk image to fit on a 1GB memory stick.
212# 1 GB in hard-drive-manufacturer-speak is 10^9, not 2^30. 950MB < 10^9 bytes.
Chris Masone35a83f92010-04-05 16:51:53 -0700213ROOT_SIZE_BYTES=$((1024 * 1024 * 720))
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700214dd if=/dev/zero of="$ROOT_FS_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1))
215sudo losetup "$LOOP_DEV" "$ROOT_FS_IMG"
216sudo mkfs.ext3 "$LOOP_DEV"
217
218# Tune and mount rootfs.
219UUID=$(uuidgen)
220DISK_LABEL="C-KEYFOB"
221sudo tune2fs -L "$DISK_LABEL" -U "$UUID" -c 0 -i 0 "$LOOP_DEV"
222sudo mount "$LOOP_DEV" "$ROOT_FS_DIR"
223
224# Create stateful partition of the same size as the rootfs.
225STATEFUL_IMG="$OUTPUT_DIR/stateful_partition.image"
226STATEFUL_DIR="$OUTPUT_DIR/stateful_partition"
227STATEFUL_LOOP_DEV=$(sudo losetup -f)
228if [ -z "$STATEFUL_LOOP_DEV" ] ; then
229 echo "No free loop device. Free up a loop device or reboot. exiting. "
230 exit 1
231fi
232dd if=/dev/zero of="$STATEFUL_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1))
233sudo losetup "$STATEFUL_LOOP_DEV" "$STATEFUL_IMG"
234sudo mkfs.ext3 "$STATEFUL_LOOP_DEV"
235sudo tune2fs -L "C-STATE" -U "$UUID" -c 0 -i 0 \
236 "$STATEFUL_LOOP_DEV"
237
238# Mount the stateful partition.
239mkdir -p "$STATEFUL_DIR"
240sudo mount "$STATEFUL_LOOP_DEV" "$STATEFUL_DIR"
241
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700242# Set dev image root now that we have mounted the stateful partition we created
243DEV_IMAGE_ROOT="$STATEFUL_DIR/dev_image"
244
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700245# Turn root file system into bootable image.
246if [[ "$ARCH" = "x86" ]]; then
247 # Setup extlinux configuration.
248 # TODO: For some reason the /dev/disk/by-uuid is not being generated by udev
249 # in the initramfs. When we figure that out, switch to root=UUID=$UUID.
250 sudo mkdir -p "$ROOT_FS_DIR"/boot
251 # TODO(adlr): use initramfs for booting.
252 cat <<EOF | sudo dd of="$ROOT_FS_DIR"/boot/extlinux.conf
253DEFAULT chromeos-usb
254PROMPT 0
255TIMEOUT 0
256
257label chromeos-usb
258 menu label chromeos-usb
259 kernel vmlinuz
260 append quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sdb3 ro noresume noswap i915.modeset=1 loglevel=1
261
262label chromeos-hd
263 menu label chromeos-hd
264 kernel vmlinuz
265 append quiet console=tty2 init=/sbin/init boot=local rootwait root=HDROOT ro noresume noswap i915.modeset=1 loglevel=1
266EOF
267
268 # Make partition bootable and label it.
269 sudo extlinux -z --install "${ROOT_FS_DIR}/boot"
270fi
271
272# -- Install packages into the root file system --
273
274# We need to install libc manually from the cross toolchain.
275# TODO: Improve this? We only want libc and not the whole toolchain.
276PKGDIR="/var/lib/portage/pkgs/cross/"
277sudo tar jxvpf \
278 "${PKGDIR}/${CHOST}/cross-${CHOST}"/glibc-${LIBC_VERSION}.tbz2 \
279 -C "$ROOT_FS_DIR" --strip-components=3 \
280 --exclude=usr/include --exclude=sys-include --exclude=*.a --exclude=*.o
281
282# We need to install libstdc++ manually from the cross toolchain.
283# TODO: Figure out a better way of doing this?
284sudo cp -a "${BOARD_ROOT}"/lib/libgcc_s.so* "${ROOT_FS_DIR}/lib"
285sudo cp -a "${BOARD_ROOT}"/usr/lib/libstdc++.so* "${ROOT_FS_DIR}/usr/lib"
286
287INSTALL_MASK=""
Chris Sosa3d9a10b2010-04-13 15:00:46 -0700288if [[ $FLAGS_installmask -eq ${FLAGS_TRUE} ]] ; then
Chris Sosaaa1a7fd2010-04-02 14:06:29 -0700289 INSTALL_MASK="$DEFAULT_INSTALL_MASK"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700290fi
291
292if [[ $FLAGS_jobs -ne -1 ]]; then
293 EMERGE_JOBS="--jobs=$FLAGS_jobs"
294fi
295
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700296# Prepare stateful partition with some pre-created directories
297sudo mkdir -p "${DEV_IMAGE_ROOT}"
298sudo mkdir -p "${STATEFUL_DIR}/var"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700299
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700300# Create symlinks so that /usr/local/usr based directories are symlinked to
301# /usr/local/ directories e.g. /usr/local/usr/bin -> /usr/local/bin, etc.
302setup_symlinks_on_root "${DEV_IMAGE_ROOT}" "${STATEFUL_DIR}/var"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700303
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700304# Perform binding rather than symlinking because directories must exist
305# on rootfs so that we can bind at run-time since rootfs is read-only
306echo "Binding directories from stateful partition onto the rootfs"
307sudo mkdir -p "${ROOT_FS_DIR}/usr/local"
308sudo mount --bind "${DEV_IMAGE_ROOT}" "${ROOT_FS_DIR}/usr/local"
309sudo mkdir -p "${ROOT_FS_DIR}/var"
310sudo mount --bind "${STATEFUL_DIR}/var" "${ROOT_FS_DIR}/var"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700311
312# We "emerge --root=$ROOT_FS_DIR --root-deps=rdeps --usepkgonly" all of the
313# runtime packages for chrome os. This builds up a chrome os image from binary
314# packages with runtime dependencies only. We use INSTALL_MASK to trim the
315# image size as much as possible.
Ken Mixterd5c4b172010-04-16 10:11:02 -0700316sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700317 --root="$ROOT_FS_DIR" --root-deps=rdeps \
318 --usepkgonly chromeos $EMERGE_JOBS
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700319
Chris Sosa4bccd3c2010-03-15 13:23:14 -0700320# Determine the root dir for development packages.
321ROOT_DEV_DIR="$ROOT_FS_DIR"
322[ $FLAGS_statefuldev -eq $FLAGS_TRUE ] && ROOT_DEV_DIR="$ROOT_FS_DIR/usr/local"
323
324# Install development packages.
325if [[ $FLAGS_withdev -eq $FLAGS_TRUE ]] ; then
Ken Mixterd5c4b172010-04-16 10:11:02 -0700326 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
Chris Sosa4bccd3c2010-03-15 13:23:14 -0700327 --root="$ROOT_DEV_DIR" --root-deps=rdeps \
328 --usepkgonly chromeos-dev $EMERGE_JOBS
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700329
Chris Sosa3d9a10b2010-04-13 15:00:46 -0700330 # TODO(sosa@chromium.org) - Re-hide under statefuldev after switch
331 # Flag will mount /usr/local on target device
332 sudo mkdir -p "$ROOT_FS_DIR/root"
Chris Sosa3d9a10b2010-04-13 15:00:46 -0700333
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700334 # The ldd tool is a useful shell script but lives in glibc; just copy it.
Chris Sosa4bccd3c2010-03-15 13:23:14 -0700335 sudo cp -a "$(which ldd)" "${ROOT_DEV_DIR}/usr/bin"
336fi
337
338# Install packages required for testing.
339if [[ $FLAGS_withtest -eq $FLAGS_TRUE ]] ; then
Ken Mixterd5c4b172010-04-16 10:11:02 -0700340 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
Chris Sosa4bccd3c2010-03-15 13:23:14 -0700341 --root="$ROOT_DEV_DIR" --root-deps=rdeps \
342 --usepkgonly chromeos-test $EMERGE_JOBS
343fi
344
Bill Richardson4364a2e2010-03-30 14:17:34 -0700345# Extract the kernel from the root filesystem for use by the GPT image. Legacy
Bill Richardson8b3bd102010-04-06 15:00:10 -0700346# BIOS will use the kernel in the rootfs (via syslinux), Chrome OS BIOS will
347# use the kernel partition.
Bill Richardson6dcea162010-03-31 19:20:24 -0700348sudo cp -f "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image"
Bill Richardson4364a2e2010-03-30 14:17:34 -0700349
Bill Richardson8b3bd102010-04-06 15:00:10 -0700350# Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI
351# BIOS). We only need this for x86, but it's simpler and safer to keep the disk
352# images the same for both x86 and ARM.
353ESP_IMG=${OUTPUT_DIR}/esp.image
354# NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. We'll hard-code
355# it to 16M for now.
356ESP_BLOCKS=16384
357/usr/sbin/mkfs.vfat -C ${OUTPUT_DIR}/esp.image ${ESP_BLOCKS}
358ESP_DIR=${OUTPUT_DIR}/esp
Bill Richardsona81df762010-04-09 08:12:05 -0700359ESP_LOOP_DEV=$(sudo losetup -f)
360if [ -z "$ESP_LOOP_DEV" ] ; then
361 echo "No free loop device. Free up a loop device or reboot. exiting. "
362 exit 1
363fi
364mkdir -p "${ESP_DIR}"
365sudo losetup "${ESP_LOOP_DEV}" "${ESP_IMG}"
366sudo mount "${ESP_LOOP_DEV}" "${ESP_DIR}"
367sudo mkdir -p "${ESP_DIR}/efi/boot"
368sudo grub-mkimage -p /efi/boot -o "${ESP_DIR}/efi/boot/bootx64.efi" \
Bill Richardson8b3bd102010-04-06 15:00:10 -0700369 part_gpt fat ext2 normal boot sh chain configfile linux
Bill Richardsona81df762010-04-09 08:12:05 -0700370sudo cp "${ROOT_FS_DIR}/boot/vmlinuz" "${ESP_DIR}/efi/boot/vmlinuz"
371cat <<EOF | sudo dd of="${ESP_DIR}/efi/boot/grub.cfg"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700372set timeout=2
373set default=0
374
Bill Richardson041bd712010-04-27 09:36:14 -0700375menuentry "boot from disk" {
Bill Richardsona81df762010-04-09 08:12:05 -0700376 linux /efi/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sda3 ro noresume noswap i915.modeset=1 loglevel=1
377}
378
Bill Richardson041bd712010-04-27 09:36:14 -0700379menuentry "boot from disk with serial debug" {
Bill Richardsonba9682a2010-04-13 13:02:32 -0700380 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
381}
382
Bill Richardson041bd712010-04-27 09:36:14 -0700383menuentry "boot from usb" {
384 linux /efi/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sdb3 ro noresume noswap i915.modeset=1 loglevel=1
385}
386
387menuentry "boot from usb with serial debug" {
388 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
389}
390
Bill Richardson8b3bd102010-04-06 15:00:10 -0700391EOF
392
Chris Sosa5c37ce22010-05-03 20:18:02 -0700393# By default, dev mode should be activated for either development builds or
394# test builds.
395if [[ $FLAGS_withdev -eq $FLAGS_TRUE ]] ||\
396 [[ $FLAGS_withtest -eq $FLAGS_TRUE ]]; then
397 sudo touch "$ROOT_FS_DIR/root/.dev_mode"
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700398
Chris Sosa5c37ce22010-05-03 20:18:02 -0700399 # Re-run ldconfig to fix /etc/ldconfig.so.cache.
400 sudo /sbin/ldconfig -r "$ROOT_FS_DIR"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700401fi
402
Chris Sosa3f21b992010-05-10 16:34:47 -0700403# Perform any customizations on the root file system that are needed.
Chris Sosa503efe12010-04-08 10:05:46 -0700404"${SCRIPTS_DIR}/customize_rootfs" \
405 --root="$ROOT_FS_DIR" \
406 --target="$ARCH" \
Chris Sosa3f21b992010-05-10 16:34:47 -0700407 --board="$BOARD"
Chris Sosa503efe12010-04-08 10:05:46 -0700408
409# Check that the image has been correctly created.
410"${SCRIPTS_DIR}/test_image" \
411 --root="$ROOT_FS_DIR" \
412 --target="$ARCH"
413
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700414# Clean up symlinks so they work on a running target rooted at "/".
415# Here development packages are rooted at /usr/local. However, do not
416# create /usr/local or /var on host (already exist on target).
417setup_symlinks_on_root "/usr/local" "/var"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700418
419# Cleanup loop devices.
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700420cleanup
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700421
Chris Sosabde8c1b2010-04-29 14:02:35 -0700422trap delete_prompt EXIT
423
Bill Richardson4364a2e2010-03-30 14:17:34 -0700424# Create the GPT-formatted image
425${SCRIPTS_DIR}/build_gpt.sh \
robotboyb75eee32010-04-30 09:51:23 -0700426 --arch=${ARCH} \
427 --board=${FLAGS_board} \
428 --arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \
429 "${OUTPUT_DIR}" \
430 "${OUTPUT_IMG}"
Bill Richardson4364a2e2010-03-30 14:17:34 -0700431
Bill Richardson6dcea162010-03-31 19:20:24 -0700432# Clean up temporary files.
Bill Richardson8b3bd102010-04-06 15:00:10 -0700433rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \
434 "${ESP_IMG}"
435rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" "${ESP_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700436
437OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}"
438echo "Done. Image created in ${OUTPUT_DIR}"
439echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:"
Daniel Eratdd9818a2010-04-26 09:16:44 -0700440echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700441echo "To convert to VMWare image, OUTSIDE the chroot, do something like:"
442echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}"
443echo "from the scripts directory where you entered the chroot."
444
445trap - EXIT