blob: 4723ed22be3729f442f2a452b1ad9a2b98f2f789 [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"
Tom Wai-Hong Tamf87a3672010-05-17 16:06:33 +080042DEFINE_boolean factory_install $FLAGS_FALSE \
43 "Build a smaller image to overlay the factory install shim on; this argument \
44is also required in image_to_usb."
robotboyb75eee32010-04-30 09:51:23 -070045DEFINE_string arm_extra_bootargs "" \
46 "Additional command line options to pass to the ARM kernel."
Bill Richardsonc09b94f2010-03-15 11:40:30 -070047
48# Parse command line.
49FLAGS "$@" || exit 1
50eval set -- "${FLAGS_ARGV}"
51
52# Only now can we die on error. shflags functions leak non-zero error codes,
53# so will die prematurely if 'set -e' is specified before now.
54set -e
55
56if [ -z "$FLAGS_board" ] ; then
57 error "--board is required."
58 exit 1
59fi
60
Bill Richardsonc09b94f2010-03-15 11:40:30 -070061# Determine build version.
62. "${SCRIPTS_DIR}/chromeos_version.sh"
63
64# Use canonical path since some tools (e.g. mount) do not like symlinks.
65# Append build attempt to output directory.
66IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}"
67OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}"
68ROOT_FS_DIR="${OUTPUT_DIR}/rootfs"
69ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image"
Chris Sosa9673f3b2010-05-18 13:24:40 -070070
71# If we are creating a developer image, also create a pristine image with a
72# different name.
73DEVELOPER_IMAGE_NAME=
74PRISTINE_IMAGE_NAME=chromiumos_image.bin
75if [ "$FLAGS_withdev" -eq "$FLAGS_TRUE" ]; then
76 PRISTINE_IMAGE_NAME=chromiumos_base_image.bin
77 DEVELOPER_IMAGE_NAME=chromiumos_image.bin
78fi
79OUTPUT_IMG=${FLAGS_to:-${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}}
Bill Richardsonc09b94f2010-03-15 11:40:30 -070080
81BOARD="${FLAGS_board}"
82BOARD_ROOT="${FLAGS_build_root}/${BOARD}"
83
84LOOP_DEV=
Chris Sosa4bffb8b2010-04-07 17:23:54 -070085STATEFUL_LOOP_DEV=
Bill Richardsona81df762010-04-09 08:12:05 -070086ESP_LOOP_DEV=
Bill Richardsonc09b94f2010-03-15 11:40:30 -070087
88# What cross-build are we targeting?
89. "${BOARD_ROOT}/etc/make.conf.board_setup"
90LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"}
91
92# Figure out ARCH from the given toolchain.
93# TODO: Move to common.sh as a function after scripts are switched over.
94TC_ARCH=$(echo "$CHOST" | awk -F'-' '{ print $1 }')
95case "$TC_ARCH" in
96 arm*)
97 ARCH="arm"
98 ;;
99 *86)
100 ARCH="x86"
101 ;;
102 *)
103 error "Unable to determine ARCH from toolchain: $CHOST"
104 exit 1
105esac
106
107# Hack to fix bug where x86_64 CHOST line gets incorrectly added.
108# ToDo(msb): remove this hack.
109PACKAGES_FILE="${BOARD_ROOT}/packages/Packages"
110sudo sed -e "s/CHOST: x86_64-pc-linux-gnu//" -i "${PACKAGES_FILE}"
111
112# Handle existing directory.
113if [[ -e "$OUTPUT_DIR" ]]; then
114 if [[ $FLAGS_replace -eq $FLAGS_TRUE ]]; then
115 sudo rm -rf "$OUTPUT_DIR"
116 else
117 echo "Directory $OUTPUT_DIR already exists."
118 echo "Use --build_attempt option to specify an unused attempt."
119 echo "Or use --replace if you want to overwrite this directory."
120 exit 1
121 fi
122fi
123
124# Create the output directory.
125mkdir -p "$OUTPUT_DIR"
126
127cleanup_rootfs_loop() {
Chris Sosabde8c1b2010-04-29 14:02:35 -0700128 sudo umount -d "$ROOT_FS_DIR"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700129}
130
131cleanup_stateful_fs_loop() {
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700132 sudo umount "${ROOT_FS_DIR}/usr/local"
133 sudo umount "${ROOT_FS_DIR}/var"
Chris Sosabde8c1b2010-04-29 14:02:35 -0700134 sudo umount -d "${STATEFUL_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700135}
136
Bill Richardson8b3bd102010-04-06 15:00:10 -0700137cleanup_esp_loop() {
Chris Sosabde8c1b2010-04-29 14:02:35 -0700138 sudo umount -d "$ESP_DIR"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700139}
140
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700141cleanup() {
142 # Disable die on error.
143 set +e
144
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700145 if [[ -n "$STATEFUL_LOOP_DEV" ]]; then
146 cleanup_stateful_fs_loop
147 fi
148
149 if [[ -n "$LOOP_DEV" ]]; then
150 cleanup_rootfs_loop
151 fi
152
Bill Richardsona81df762010-04-09 08:12:05 -0700153 if [[ -n "$ESP_LOOP_DEV" ]]; then
Bill Richardson8b3bd102010-04-06 15:00:10 -0700154 cleanup_esp_loop
155 fi
156
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700157 # Turn die on error back on.
158 set -e
159}
160
Chris Sosabde8c1b2010-04-29 14:02:35 -0700161delete_prompt() {
162 echo "An error occurred in your build so your latest output directory" \
163 "is invalid."
164 read -p "Would you like to delete the output directory (y/N)? " SURE
165 SURE="${SURE:0:1}" # Get just the first character
166 if [ "${SURE}" == "y" ] ; then
167 sudo rm -rf "$OUTPUT_DIR"
168 echo "Deleted $OUTPUT_DIR"
169 else
170 echo "Not deleting $OUTPUT_DIR. Note dev server updates will not work" \
171 "until you successfully build another image or delete this directory"
172 fi
173}
174
Chris Sosa9673f3b2010-05-18 13:24:40 -0700175# $1 - Directory where developer rootfs is mounted.
176# $2 - Directory where developer stateful_partition is mounted.
177developer_cleanup() {
178 "$SCRIPTS_DIR/mount_gpt_image.sh" -u -r "$1" -s "$2"
179 delete_prompt
180}
181
182# Creates a new image based on $OUTPUT_IMG with additional developer packages.
183create_developer_image() {
184 local root_fs_dir="${OUTPUT_DIR}/rootfs_dev"
185 local root_fs_img="${OUTPUT_DIR}/rootfs_dev.image"
186 local output_img="${OUTPUT_DIR}/${DEVELOPER_IMAGE_NAME}"
187
188 # Create stateful partition of the same size as the rootfs.
189 local stateful_img="$OUTPUT_DIR/stateful_partition_dev.image"
190 local stateful_dir="$OUTPUT_DIR/stateful_partition_dev"
191
192 trap "developer_cleanup \"$root_fs_dir\" \"$stateful_dir\"" EXIT
193
194 # Mount a new copy of the base image.
195 echo "Creating developer image from base image $OUTPUT_IMG"
196 cp "$OUTPUT_IMG" "$output_img"
197 $SCRIPTS_DIR/mount_gpt_image.sh --from "$OUTPUT_DIR" \
198 --image "$DEVELOPER_IMAGE_NAME" -r "$root_fs_dir" -s "$stateful_dir"
199
200 # Determine the root dir for developer packages.
201 local root_dev_dir="$root_fs_dir"
202 [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] && \
203 root_dev_dir="$root_fs_dir/usr/local"
204
205 # Install developer packages described in chromeos-dev.
206 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
207 --root="$root_dev_dir" --root-deps=rdeps \
208 --usepkgonly chromeos-dev $EMERGE_JOBS
209
210 # Re-run ldconfig to fix /etc/ldconfig.so.cache.
211 sudo /sbin/ldconfig -r "$root_fs_dir"
212
213 # Mark the image as a developer image (input to chromeos_startup).
214 sudo mkdir -p "$root_fs_dir/root"
215 sudo touch "$root_fs_dir/root/.dev_mode"
216
217 # Additional changes to developer image.
218
219 # The ldd tool is a useful shell script but lives in glibc; just copy it.
220 sudo cp -a "$(which ldd)" "${root_dev_dir}/usr/bin"
221
222 # If vim is installed, then a vi symlink would probably help.
223 if [[ -x "${ROOT_FS_DIR}/usr/local/bin/vim" ]]; then
224 sudo ln -sf vim "${ROOT_FS_DIR}/usr/local/bin/vi"
225 fi
226
227 # Check that the image has been correctly created.
228 "${SCRIPTS_DIR}/test_image" \
229 --root="$root_fs_dir" \
230 --target="$ARCH"
231
232 trap - EXIT
233 $SCRIPTS_DIR/mount_gpt_image.sh -u -r "$root_fs_dir" -s "$stateful_dir"
234 echo "Developer image built and stored at $output_img"
235}
236
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700237# ${DEV_IMAGE_ROOT} specifies the location of where developer packages will
238# be installed on the stateful dir. On a Chromium OS system, this will
239# translate to /usr/local
240DEV_IMAGE_ROOT=
241
Chris Sosabde8c1b2010-04-29 14:02:35 -0700242trap "cleanup && delete_prompt" EXIT
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700243
244mkdir -p "$ROOT_FS_DIR"
245
246# Create and format the root file system.
247
248# Check for loop device before creating image.
249LOOP_DEV=$(sudo losetup -f)
250if [ -z "$LOOP_DEV" ] ; then
251 echo "No free loop device. Free up a loop device or reboot. exiting. "
252 exit 1
253fi
254
255# Create root file system disk image to fit on a 1GB memory stick.
256# 1 GB in hard-drive-manufacturer-speak is 10^9, not 2^30. 950MB < 10^9 bytes.
Tom Wai-Hong Tamf87a3672010-05-17 16:06:33 +0800257if [[ $FLAGS_factory_install -eq ${FLAGS_TRUE} ]] ; then
258 ROOT_SIZE_BYTES=$((1024 * 1024 * 180))
259else
260 ROOT_SIZE_BYTES=$((1024 * 1024 * 720))
261fi
262
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700263dd if=/dev/zero of="$ROOT_FS_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1))
264sudo losetup "$LOOP_DEV" "$ROOT_FS_IMG"
265sudo mkfs.ext3 "$LOOP_DEV"
266
267# Tune and mount rootfs.
268UUID=$(uuidgen)
269DISK_LABEL="C-KEYFOB"
270sudo tune2fs -L "$DISK_LABEL" -U "$UUID" -c 0 -i 0 "$LOOP_DEV"
271sudo mount "$LOOP_DEV" "$ROOT_FS_DIR"
272
273# Create stateful partition of the same size as the rootfs.
274STATEFUL_IMG="$OUTPUT_DIR/stateful_partition.image"
275STATEFUL_DIR="$OUTPUT_DIR/stateful_partition"
276STATEFUL_LOOP_DEV=$(sudo losetup -f)
277if [ -z "$STATEFUL_LOOP_DEV" ] ; then
278 echo "No free loop device. Free up a loop device or reboot. exiting. "
279 exit 1
280fi
281dd if=/dev/zero of="$STATEFUL_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1))
282sudo losetup "$STATEFUL_LOOP_DEV" "$STATEFUL_IMG"
283sudo mkfs.ext3 "$STATEFUL_LOOP_DEV"
284sudo tune2fs -L "C-STATE" -U "$UUID" -c 0 -i 0 \
285 "$STATEFUL_LOOP_DEV"
286
287# Mount the stateful partition.
288mkdir -p "$STATEFUL_DIR"
289sudo mount "$STATEFUL_LOOP_DEV" "$STATEFUL_DIR"
290
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700291# Set dev image root now that we have mounted the stateful partition we created
292DEV_IMAGE_ROOT="$STATEFUL_DIR/dev_image"
293
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700294# Turn root file system into bootable image.
295if [[ "$ARCH" = "x86" ]]; then
296 # Setup extlinux configuration.
297 # TODO: For some reason the /dev/disk/by-uuid is not being generated by udev
298 # in the initramfs. When we figure that out, switch to root=UUID=$UUID.
299 sudo mkdir -p "$ROOT_FS_DIR"/boot
300 # TODO(adlr): use initramfs for booting.
301 cat <<EOF | sudo dd of="$ROOT_FS_DIR"/boot/extlinux.conf
302DEFAULT chromeos-usb
303PROMPT 0
304TIMEOUT 0
305
306label chromeos-usb
307 menu label chromeos-usb
308 kernel vmlinuz
309 append quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sdb3 ro noresume noswap i915.modeset=1 loglevel=1
310
311label chromeos-hd
312 menu label chromeos-hd
313 kernel vmlinuz
314 append quiet console=tty2 init=/sbin/init boot=local rootwait root=HDROOT ro noresume noswap i915.modeset=1 loglevel=1
315EOF
316
317 # Make partition bootable and label it.
318 sudo extlinux -z --install "${ROOT_FS_DIR}/boot"
319fi
320
321# -- Install packages into the root file system --
322
323# We need to install libc manually from the cross toolchain.
324# TODO: Improve this? We only want libc and not the whole toolchain.
325PKGDIR="/var/lib/portage/pkgs/cross/"
326sudo tar jxvpf \
327 "${PKGDIR}/${CHOST}/cross-${CHOST}"/glibc-${LIBC_VERSION}.tbz2 \
328 -C "$ROOT_FS_DIR" --strip-components=3 \
329 --exclude=usr/include --exclude=sys-include --exclude=*.a --exclude=*.o
330
331# We need to install libstdc++ manually from the cross toolchain.
332# TODO: Figure out a better way of doing this?
333sudo cp -a "${BOARD_ROOT}"/lib/libgcc_s.so* "${ROOT_FS_DIR}/lib"
334sudo cp -a "${BOARD_ROOT}"/usr/lib/libstdc++.so* "${ROOT_FS_DIR}/usr/lib"
335
336INSTALL_MASK=""
Chris Sosa3d9a10b2010-04-13 15:00:46 -0700337if [[ $FLAGS_installmask -eq ${FLAGS_TRUE} ]] ; then
Chris Sosaaa1a7fd2010-04-02 14:06:29 -0700338 INSTALL_MASK="$DEFAULT_INSTALL_MASK"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700339fi
340
Tom Wai-Hong Tamf87a3672010-05-17 16:06:33 +0800341# Reduce the size of factory install shim.
342# TODO: Build a separated ebuild for the factory install shim to reduce size.
343if [[ $FLAGS_factory_install -eq ${FLAGS_TRUE} ]] ; then
344 INSTALL_MASK="$INSTALL_MASK $FACTORY_INSTALL_MASK"
345fi
346
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700347if [[ $FLAGS_jobs -ne -1 ]]; then
348 EMERGE_JOBS="--jobs=$FLAGS_jobs"
349fi
350
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700351# Prepare stateful partition with some pre-created directories
352sudo mkdir -p "${DEV_IMAGE_ROOT}"
353sudo mkdir -p "${STATEFUL_DIR}/var"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700354
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700355# Create symlinks so that /usr/local/usr based directories are symlinked to
356# /usr/local/ directories e.g. /usr/local/usr/bin -> /usr/local/bin, etc.
Chris Sosa702618f2010-05-14 12:52:32 -0700357setup_symlinks_on_root "${DEV_IMAGE_ROOT}" "${STATEFUL_DIR}/var" \
358 "${STATEFUL_DIR}"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700359
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700360# Perform binding rather than symlinking because directories must exist
361# on rootfs so that we can bind at run-time since rootfs is read-only
362echo "Binding directories from stateful partition onto the rootfs"
363sudo mkdir -p "${ROOT_FS_DIR}/usr/local"
364sudo mount --bind "${DEV_IMAGE_ROOT}" "${ROOT_FS_DIR}/usr/local"
365sudo mkdir -p "${ROOT_FS_DIR}/var"
366sudo mount --bind "${STATEFUL_DIR}/var" "${ROOT_FS_DIR}/var"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700367
368# We "emerge --root=$ROOT_FS_DIR --root-deps=rdeps --usepkgonly" all of the
369# runtime packages for chrome os. This builds up a chrome os image from binary
370# packages with runtime dependencies only. We use INSTALL_MASK to trim the
371# image size as much as possible.
Ken Mixterd5c4b172010-04-16 10:11:02 -0700372sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700373 --root="$ROOT_FS_DIR" --root-deps=rdeps \
374 --usepkgonly chromeos $EMERGE_JOBS
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700375
Bill Richardson4364a2e2010-03-30 14:17:34 -0700376# Extract the kernel from the root filesystem for use by the GPT image. Legacy
Bill Richardson8b3bd102010-04-06 15:00:10 -0700377# BIOS will use the kernel in the rootfs (via syslinux), Chrome OS BIOS will
378# use the kernel partition.
Bill Richardson6dcea162010-03-31 19:20:24 -0700379sudo cp -f "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image"
Bill Richardson4364a2e2010-03-30 14:17:34 -0700380
Bill Richardson8b3bd102010-04-06 15:00:10 -0700381# Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI
382# BIOS). We only need this for x86, but it's simpler and safer to keep the disk
383# images the same for both x86 and ARM.
384ESP_IMG=${OUTPUT_DIR}/esp.image
385# NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. We'll hard-code
386# it to 16M for now.
387ESP_BLOCKS=16384
388/usr/sbin/mkfs.vfat -C ${OUTPUT_DIR}/esp.image ${ESP_BLOCKS}
389ESP_DIR=${OUTPUT_DIR}/esp
Bill Richardsona81df762010-04-09 08:12:05 -0700390ESP_LOOP_DEV=$(sudo losetup -f)
391if [ -z "$ESP_LOOP_DEV" ] ; then
392 echo "No free loop device. Free up a loop device or reboot. exiting. "
393 exit 1
394fi
395mkdir -p "${ESP_DIR}"
396sudo losetup "${ESP_LOOP_DEV}" "${ESP_IMG}"
397sudo mount "${ESP_LOOP_DEV}" "${ESP_DIR}"
398sudo mkdir -p "${ESP_DIR}/efi/boot"
399sudo grub-mkimage -p /efi/boot -o "${ESP_DIR}/efi/boot/bootx64.efi" \
Bill Richardson8b3bd102010-04-06 15:00:10 -0700400 part_gpt fat ext2 normal boot sh chain configfile linux
Bill Richardson9c5e5ec2010-05-14 17:00:21 -0700401cat <<'EOF' | sudo dd of="${ESP_DIR}/efi/boot/grub.cfg"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700402set default=0
Bill Richardson9c5e5ec2010-05-14 17:00:21 -0700403set timeout=2
Bill Richardson8b3bd102010-04-06 15:00:10 -0700404
Bill Richardson9c5e5ec2010-05-14 17:00:21 -0700405# NOTE: These magic grub variables are a Chrome OS hack. They are not portable.
406
407menuentry "local image A" {
408 linux $grubpartA/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/$linuxpartA ro noresume noswap i915.modeset=1 loglevel=1
Bill Richardsona81df762010-04-09 08:12:05 -0700409}
410
Bill Richardson9c5e5ec2010-05-14 17:00:21 -0700411menuentry "local image B" {
412 linux $grubpartB/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/$linuxpartB ro noresume noswap i915.modeset=1 loglevel=1
Bill Richardson041bd712010-04-27 09:36:14 -0700413}
414
Bill Richardson8b3bd102010-04-06 15:00:10 -0700415EOF
416
Chris Sosa3f21b992010-05-10 16:34:47 -0700417# Perform any customizations on the root file system that are needed.
Chris Sosa503efe12010-04-08 10:05:46 -0700418"${SCRIPTS_DIR}/customize_rootfs" \
419 --root="$ROOT_FS_DIR" \
420 --target="$ARCH" \
Chris Sosa3f21b992010-05-10 16:34:47 -0700421 --board="$BOARD"
Chris Sosa503efe12010-04-08 10:05:46 -0700422
Tom Wai-Hong Tamf87a3672010-05-17 16:06:33 +0800423# Don't test the factory install shim.
424if [[ $FLAGS_factory_install -eq ${FLAGS_FALSE} ]] ; then
425 # Check that the image has been correctly created.
426 "${SCRIPTS_DIR}/test_image" \
427 --root="$ROOT_FS_DIR" \
428 --target="$ARCH"
429fi
Chris Sosa503efe12010-04-08 10:05:46 -0700430
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700431# Clean up symlinks so they work on a running target rooted at "/".
432# Here development packages are rooted at /usr/local. However, do not
433# create /usr/local or /var on host (already exist on target).
Chris Sosa702618f2010-05-14 12:52:32 -0700434setup_symlinks_on_root "/usr/local" "/var" "${STATEFUL_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700435
436# Cleanup loop devices.
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700437cleanup
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700438
Chris Sosabde8c1b2010-04-29 14:02:35 -0700439trap delete_prompt EXIT
440
Bill Richardson4364a2e2010-03-30 14:17:34 -0700441# Create the GPT-formatted image
442${SCRIPTS_DIR}/build_gpt.sh \
robotboyb75eee32010-04-30 09:51:23 -0700443 --arch=${ARCH} \
444 --board=${FLAGS_board} \
445 --arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \
446 "${OUTPUT_DIR}" \
447 "${OUTPUT_IMG}"
Bill Richardson4364a2e2010-03-30 14:17:34 -0700448
Bill Richardson6dcea162010-03-31 19:20:24 -0700449# Clean up temporary files.
Bill Richardson8b3bd102010-04-06 15:00:10 -0700450rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \
451 "${ESP_IMG}"
452rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" "${ESP_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700453
454OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}"
Chris Sosa9673f3b2010-05-18 13:24:40 -0700455
456# Create a developer image based on the chromium os base image
457[ "$FLAGS_withdev" -eq "$FLAGS_TRUE" ] && create_developer_image
458trap - EXIT
459
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700460echo "Done. Image created in ${OUTPUT_DIR}"
Chris Sosa9673f3b2010-05-18 13:24:40 -0700461echo "Chromium OS image created as $PRISTINE_IMAGE_NAME"
462if [ "$FLAGS_withdev" -eq "$FLAGS_TRUE" ]; then
463 echo "Developer image created as $DEVELOPER_IMAGE_NAME"
464fi
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700465echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:"
Daniel Eratdd9818a2010-04-26 09:16:44 -0700466echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700467echo "To convert to VMWare image, OUTSIDE the chroot, do something like:"
468echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}"
469echo "from the scripts directory where you entered the chroot."