blob: a7f2366382ca796e7523b1cfd09a187b86f7e500 [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.
17assert_inside_chroot
18
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."
38DEFINE_boolean statefuldev $FLAGS_FALSE \
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"
Chris Sosa1e5fe622010-04-08 20:51:53 -070044DEFINE_string factory_server "" \
Andrew de los Reyese7a04ad2010-04-08 15:58:17 -070045 "Build a factory install image pointing to given server."
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() {
118 sudo umount "$LOOP_DEV"
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700119 sleep 1 # in case $LOOP_DEV is in use.
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700120 sudo losetup -d "$LOOP_DEV"
121}
122
123cleanup_stateful_fs_loop() {
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700124 sudo umount "${ROOT_FS_DIR}/usr/local"
125 sudo umount "${ROOT_FS_DIR}/var"
126 sudo umount "${STATEFUL_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700127 sleep 1 # follows from cleanup_root_fs_loop.
128 sudo losetup -d "$STATEFUL_LOOP_DEV"
129}
130
Bill Richardson8b3bd102010-04-06 15:00:10 -0700131cleanup_esp_loop() {
132 sudo umount "$ESP_DIR"
Bill Richardsona81df762010-04-09 08:12:05 -0700133 sleep 1
134 sudo losetup -d "$ESP_LOOP_DEV"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700135}
136
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700137cleanup() {
138 # Disable die on error.
139 set +e
140
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700141 if [[ -n "$STATEFUL_LOOP_DEV" ]]; then
142 cleanup_stateful_fs_loop
143 fi
144
145 if [[ -n "$LOOP_DEV" ]]; then
146 cleanup_rootfs_loop
147 fi
148
Bill Richardsona81df762010-04-09 08:12:05 -0700149 if [[ -n "$ESP_LOOP_DEV" ]]; then
Bill Richardson8b3bd102010-04-06 15:00:10 -0700150 cleanup_esp_loop
151 fi
152
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700153 # Turn die on error back on.
154 set -e
155}
156
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700157# ${DEV_IMAGE_ROOT} specifies the location of where developer packages will
158# be installed on the stateful dir. On a Chromium OS system, this will
159# translate to /usr/local
160DEV_IMAGE_ROOT=
161
162# Sets up symlinks for the stateful partition based on the root specified by
163# ${1} and var directory specified by ${2}.
164setup_symlinks_on_root() {
165 echo "Setting up symlinks on the stateful partition rooted at ${1} with"\
166 "var directory located at ${2}"
167
168 for path in usr local; do
169 if [ -h "${DEV_IMAGE_ROOT}/${path}" ] ; then
170 sudo unlink "${DEV_IMAGE_ROOT}/${path}"
171 elif [ -e "${DEV_IMAGE_ROOT}/${path}" ] ; then
172 echo "*** ERROR: ${DEV_IMAGE_ROOT}/${path} should be a symlink if exists"
173 return 1
174 fi
175 sudo ln -s ${1} "${DEV_IMAGE_ROOT}/${path}"
176 done
177
178 # Setup var. Var is on the stateful partition at /var for both non-developer
179 # builds and developer builds.
180 if [ -h "${DEV_IMAGE_ROOT}/var" ] ; then
181 sudo unlink "${DEV_IMAGE_ROOT}/var"
182 elif [ -e "${DEV_IMAGE_ROOT}/var" ] ; then
183 echo "*** ERROR: ${DEV_IMAGE_ROOT}/var should be a symlink if it exists"
184 return 1
185 fi
186
187 sudo ln -s "${2}" "${DEV_IMAGE_ROOT}/var"
188}
189
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700190trap cleanup EXIT
191
192mkdir -p "$ROOT_FS_DIR"
193
194# Create and format the root file system.
195
196# Check for loop device before creating image.
197LOOP_DEV=$(sudo losetup -f)
198if [ -z "$LOOP_DEV" ] ; then
199 echo "No free loop device. Free up a loop device or reboot. exiting. "
200 exit 1
201fi
202
203# Create root file system disk image to fit on a 1GB memory stick.
204# 1 GB in hard-drive-manufacturer-speak is 10^9, not 2^30. 950MB < 10^9 bytes.
Chris Masone35a83f92010-04-05 16:51:53 -0700205ROOT_SIZE_BYTES=$((1024 * 1024 * 720))
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700206dd if=/dev/zero of="$ROOT_FS_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1))
207sudo losetup "$LOOP_DEV" "$ROOT_FS_IMG"
208sudo mkfs.ext3 "$LOOP_DEV"
209
210# Tune and mount rootfs.
211UUID=$(uuidgen)
212DISK_LABEL="C-KEYFOB"
213sudo tune2fs -L "$DISK_LABEL" -U "$UUID" -c 0 -i 0 "$LOOP_DEV"
214sudo mount "$LOOP_DEV" "$ROOT_FS_DIR"
215
216# Create stateful partition of the same size as the rootfs.
217STATEFUL_IMG="$OUTPUT_DIR/stateful_partition.image"
218STATEFUL_DIR="$OUTPUT_DIR/stateful_partition"
219STATEFUL_LOOP_DEV=$(sudo losetup -f)
220if [ -z "$STATEFUL_LOOP_DEV" ] ; then
221 echo "No free loop device. Free up a loop device or reboot. exiting. "
222 exit 1
223fi
224dd if=/dev/zero of="$STATEFUL_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1))
225sudo losetup "$STATEFUL_LOOP_DEV" "$STATEFUL_IMG"
226sudo mkfs.ext3 "$STATEFUL_LOOP_DEV"
227sudo tune2fs -L "C-STATE" -U "$UUID" -c 0 -i 0 \
228 "$STATEFUL_LOOP_DEV"
229
230# Mount the stateful partition.
231mkdir -p "$STATEFUL_DIR"
232sudo mount "$STATEFUL_LOOP_DEV" "$STATEFUL_DIR"
233
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700234# Set dev image root now that we have mounted the stateful partition we created
235DEV_IMAGE_ROOT="$STATEFUL_DIR/dev_image"
236
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700237# Turn root file system into bootable image.
238if [[ "$ARCH" = "x86" ]]; then
239 # Setup extlinux configuration.
240 # TODO: For some reason the /dev/disk/by-uuid is not being generated by udev
241 # in the initramfs. When we figure that out, switch to root=UUID=$UUID.
242 sudo mkdir -p "$ROOT_FS_DIR"/boot
243 # TODO(adlr): use initramfs for booting.
244 cat <<EOF | sudo dd of="$ROOT_FS_DIR"/boot/extlinux.conf
245DEFAULT chromeos-usb
246PROMPT 0
247TIMEOUT 0
248
249label chromeos-usb
250 menu label chromeos-usb
251 kernel vmlinuz
252 append quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sdb3 ro noresume noswap i915.modeset=1 loglevel=1
253
254label chromeos-hd
255 menu label chromeos-hd
256 kernel vmlinuz
257 append quiet console=tty2 init=/sbin/init boot=local rootwait root=HDROOT ro noresume noswap i915.modeset=1 loglevel=1
258EOF
259
260 # Make partition bootable and label it.
261 sudo extlinux -z --install "${ROOT_FS_DIR}/boot"
262fi
263
264# -- Install packages into the root file system --
265
266# We need to install libc manually from the cross toolchain.
267# TODO: Improve this? We only want libc and not the whole toolchain.
268PKGDIR="/var/lib/portage/pkgs/cross/"
269sudo tar jxvpf \
270 "${PKGDIR}/${CHOST}/cross-${CHOST}"/glibc-${LIBC_VERSION}.tbz2 \
271 -C "$ROOT_FS_DIR" --strip-components=3 \
272 --exclude=usr/include --exclude=sys-include --exclude=*.a --exclude=*.o
273
274# We need to install libstdc++ manually from the cross toolchain.
275# TODO: Figure out a better way of doing this?
276sudo cp -a "${BOARD_ROOT}"/lib/libgcc_s.so* "${ROOT_FS_DIR}/lib"
277sudo cp -a "${BOARD_ROOT}"/usr/lib/libstdc++.so* "${ROOT_FS_DIR}/usr/lib"
278
279INSTALL_MASK=""
Chris Sosa3d9a10b2010-04-13 15:00:46 -0700280if [[ $FLAGS_installmask -eq ${FLAGS_TRUE} ]] ; then
Chris Sosaaa1a7fd2010-04-02 14:06:29 -0700281 INSTALL_MASK="$DEFAULT_INSTALL_MASK"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700282fi
283
284if [[ $FLAGS_jobs -ne -1 ]]; then
285 EMERGE_JOBS="--jobs=$FLAGS_jobs"
286fi
287
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700288# Prepare stateful partition with some pre-created directories
289sudo mkdir -p "${DEV_IMAGE_ROOT}"
290sudo mkdir -p "${STATEFUL_DIR}/var"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700291
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700292# Create symlinks so that /usr/local/usr based directories are symlinked to
293# /usr/local/ directories e.g. /usr/local/usr/bin -> /usr/local/bin, etc.
294setup_symlinks_on_root "${DEV_IMAGE_ROOT}" "${STATEFUL_DIR}/var"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700295
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700296# Perform binding rather than symlinking because directories must exist
297# on rootfs so that we can bind at run-time since rootfs is read-only
298echo "Binding directories from stateful partition onto the rootfs"
299sudo mkdir -p "${ROOT_FS_DIR}/usr/local"
300sudo mount --bind "${DEV_IMAGE_ROOT}" "${ROOT_FS_DIR}/usr/local"
301sudo mkdir -p "${ROOT_FS_DIR}/var"
302sudo mount --bind "${STATEFUL_DIR}/var" "${ROOT_FS_DIR}/var"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700303
304# We "emerge --root=$ROOT_FS_DIR --root-deps=rdeps --usepkgonly" all of the
305# runtime packages for chrome os. This builds up a chrome os image from binary
306# packages with runtime dependencies only. We use INSTALL_MASK to trim the
307# image size as much as possible.
Ken Mixterd5c4b172010-04-16 10:11:02 -0700308sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700309 --root="$ROOT_FS_DIR" --root-deps=rdeps \
310 --usepkgonly chromeos $EMERGE_JOBS
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700311
Chris Sosa4bccd3c2010-03-15 13:23:14 -0700312# Determine the root dir for development packages.
313ROOT_DEV_DIR="$ROOT_FS_DIR"
314[ $FLAGS_statefuldev -eq $FLAGS_TRUE ] && ROOT_DEV_DIR="$ROOT_FS_DIR/usr/local"
315
316# Install development packages.
317if [[ $FLAGS_withdev -eq $FLAGS_TRUE ]] ; then
Ken Mixterd5c4b172010-04-16 10:11:02 -0700318 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
Chris Sosa4bccd3c2010-03-15 13:23:14 -0700319 --root="$ROOT_DEV_DIR" --root-deps=rdeps \
320 --usepkgonly chromeos-dev $EMERGE_JOBS
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700321
Chris Sosa3d9a10b2010-04-13 15:00:46 -0700322 # TODO(sosa@chromium.org) - Re-hide under statefuldev after switch
323 # Flag will mount /usr/local on target device
324 sudo mkdir -p "$ROOT_FS_DIR/root"
325 sudo touch "$ROOT_FS_DIR/root/.dev_mode"
326
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700327 # The ldd tool is a useful shell script but lives in glibc; just copy it.
Chris Sosa4bccd3c2010-03-15 13:23:14 -0700328 sudo cp -a "$(which ldd)" "${ROOT_DEV_DIR}/usr/bin"
329fi
330
Andrew de los Reyese7a04ad2010-04-08 15:58:17 -0700331if [ -n "$FLAGS_factory_server" ]; then
Ken Mixterd5c4b172010-04-16 10:11:02 -0700332 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
Andrew de los Reyese7a04ad2010-04-08 15:58:17 -0700333 --root="$ROOT_DEV_DIR" --root-deps=rdeps \
334 --usepkgonly chromeos-factoryinstall $EMERGE_JOBS
335fi
336
Chris Sosa4bccd3c2010-03-15 13:23:14 -0700337# Install packages required for testing.
338if [[ $FLAGS_withtest -eq $FLAGS_TRUE ]] ; then
Ken Mixterd5c4b172010-04-16 10:11:02 -0700339 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
Chris Sosa4bccd3c2010-03-15 13:23:14 -0700340 --root="$ROOT_DEV_DIR" --root-deps=rdeps \
341 --usepkgonly chromeos-test $EMERGE_JOBS
342fi
343
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700344# Perform any customizations on the root file system that are needed.
Andrew de los Reyese7a04ad2010-04-08 15:58:17 -0700345EXTRA_CUSTOMIZE_ROOTFS_FLAGS=""
346if [ $FLAGS_withdev -eq $FLAGS_TRUE ]; then
347 EXTRA_CUSTOMIZE_ROOTFS_FLAGS="--withdev"
348fi
349if [ -n "$FLAGS_factory_server" ]; then
350# Indentation off b/c of long line
351EXTRA_CUSTOMIZE_ROOTFS_FLAGS="$EXTRA_CUSTOMIZE_ROOTFS_FLAGS"\
352" --factory_server=$FLAGS_factory_server"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700353fi
354
Bill Richardson4364a2e2010-03-30 14:17:34 -0700355# Extract the kernel from the root filesystem for use by the GPT image. Legacy
Bill Richardson8b3bd102010-04-06 15:00:10 -0700356# BIOS will use the kernel in the rootfs (via syslinux), Chrome OS BIOS will
357# use the kernel partition.
Bill Richardson6dcea162010-03-31 19:20:24 -0700358sudo cp -f "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image"
Bill Richardson4364a2e2010-03-30 14:17:34 -0700359
Bill Richardson8b3bd102010-04-06 15:00:10 -0700360# Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI
361# BIOS). We only need this for x86, but it's simpler and safer to keep the disk
362# images the same for both x86 and ARM.
363ESP_IMG=${OUTPUT_DIR}/esp.image
364# NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. We'll hard-code
365# it to 16M for now.
366ESP_BLOCKS=16384
367/usr/sbin/mkfs.vfat -C ${OUTPUT_DIR}/esp.image ${ESP_BLOCKS}
368ESP_DIR=${OUTPUT_DIR}/esp
Bill Richardsona81df762010-04-09 08:12:05 -0700369ESP_LOOP_DEV=$(sudo losetup -f)
370if [ -z "$ESP_LOOP_DEV" ] ; then
371 echo "No free loop device. Free up a loop device or reboot. exiting. "
372 exit 1
373fi
374mkdir -p "${ESP_DIR}"
375sudo losetup "${ESP_LOOP_DEV}" "${ESP_IMG}"
376sudo mount "${ESP_LOOP_DEV}" "${ESP_DIR}"
377sudo mkdir -p "${ESP_DIR}/efi/boot"
378sudo grub-mkimage -p /efi/boot -o "${ESP_DIR}/efi/boot/bootx64.efi" \
Bill Richardson8b3bd102010-04-06 15:00:10 -0700379 part_gpt fat ext2 normal boot sh chain configfile linux
Bill Richardsona81df762010-04-09 08:12:05 -0700380sudo cp "${ROOT_FS_DIR}/boot/vmlinuz" "${ESP_DIR}/efi/boot/vmlinuz"
381cat <<EOF | sudo dd of="${ESP_DIR}/efi/boot/grub.cfg"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700382set timeout=2
383set default=0
384
Bill Richardsona81df762010-04-09 08:12:05 -0700385menuentry "normal" {
386 linux /efi/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sda3 ro noresume noswap i915.modeset=1 loglevel=1
387}
388
Bill Richardsonba9682a2010-04-13 13:02:32 -0700389menuentry "serial debug" {
390 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
391}
392
Bill Richardson8b3bd102010-04-06 15:00:10 -0700393EOF
394
Chris Sosa3d9a10b2010-04-13 15:00:46 -0700395# Run ldconfig for rootfs's ld.so.cache
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700396if [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] ; then
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700397 # Re-run ldconfig to fix /etc/ldconfig.so.cache
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700398 sudo /sbin/ldconfig -r "$ROOT_FS_DIR"
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700399
400 #TODO(sosa@chromium.org) - /usr/bin/xterm symlink not created in stateful.
401 sudo ln -sf "/usr/local/bin/aterm" "/usr/bin/xterm"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700402fi
403
Chris Sosa503efe12010-04-08 10:05:46 -0700404"${SCRIPTS_DIR}/customize_rootfs" \
405 --root="$ROOT_FS_DIR" \
406 --target="$ARCH" \
407 --board="$BOARD" \
Andrew de los Reyese7a04ad2010-04-08 15:58:17 -0700408 $EXTRA_CUSTOMIZE_ROOTFS_FLAGS
Chris Sosa503efe12010-04-08 10:05:46 -0700409
410# Check that the image has been correctly created.
411"${SCRIPTS_DIR}/test_image" \
412 --root="$ROOT_FS_DIR" \
413 --target="$ARCH"
414
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700415# Clean up symlinks so they work on a running target rooted at "/".
416# Here development packages are rooted at /usr/local. However, do not
417# create /usr/local or /var on host (already exist on target).
418setup_symlinks_on_root "/usr/local" "/var"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700419
420# Cleanup loop devices.
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700421cleanup
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700422
Bill Richardson4364a2e2010-03-30 14:17:34 -0700423# Create the GPT-formatted image
424${SCRIPTS_DIR}/build_gpt.sh \
Jie Sun96e2b092010-04-09 11:05:49 -0700425 --arch=${ARCH} --board=${FLAGS_board} "${OUTPUT_DIR}" "${OUTPUT_IMG}"
Bill Richardson4364a2e2010-03-30 14:17:34 -0700426
Bill Richardson6dcea162010-03-31 19:20:24 -0700427# Clean up temporary files.
Bill Richardson8b3bd102010-04-06 15:00:10 -0700428rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \
429 "${ESP_IMG}"
430rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" "${ESP_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700431
432OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}"
433echo "Done. Image created in ${OUTPUT_DIR}"
434echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:"
Daniel Eratdd9818a2010-04-26 09:16:44 -0700435echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700436echo "To convert to VMWare image, OUTSIDE the chroot, do something like:"
437echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}"
438echo "from the scripts directory where you entered the chroot."
439
440trap - EXIT