blob: 2d31f437e116e12105f895d08564bd086d2ba2f6 [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."
Ken Mixterc223ba12010-04-16 09:08:26 -070038DEFINE_integer retries -1 \
39 "On image mastering failure, the number of times to retry"
Bill Richardsonc09b94f2010-03-15 11:40:30 -070040DEFINE_boolean statefuldev $FLAGS_FALSE \
Chris Sosa4bffb8b2010-04-07 17:23:54 -070041 "Install development packages on stateful partition rather than the rootfs"
Antoine Laboure9e585f2010-04-01 15:57:57 -070042DEFINE_string to "" \
43 "The target image file or device"
Chris Sosa77a29632010-03-15 14:12:15 -070044DEFINE_boolean withtest $FLAGS_FALSE \
Chris Sosa4bccd3c2010-03-15 13:23:14 -070045 "Include packages required for testing and prepare image for testing"
Chris Sosa1e5fe622010-04-08 20:51:53 -070046DEFINE_string factory_server "" \
Andrew de los Reyese7a04ad2010-04-08 15:58:17 -070047 "Build a factory install image pointing to given server."
Bill Richardsonc09b94f2010-03-15 11:40:30 -070048
49# Parse command line.
50FLAGS "$@" || exit 1
51eval set -- "${FLAGS_ARGV}"
52
53# Only now can we die on error. shflags functions leak non-zero error codes,
54# so will die prematurely if 'set -e' is specified before now.
55set -e
56
57if [ -z "$FLAGS_board" ] ; then
58 error "--board is required."
59 exit 1
60fi
61
Bill Richardsonc09b94f2010-03-15 11:40:30 -070062# Determine build version.
63. "${SCRIPTS_DIR}/chromeos_version.sh"
64
65# Use canonical path since some tools (e.g. mount) do not like symlinks.
66# Append build attempt to output directory.
67IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}"
68OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}"
69ROOT_FS_DIR="${OUTPUT_DIR}/rootfs"
70ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image"
Antoine Laboure9e585f2010-04-01 15:57:57 -070071OUTPUT_IMG=${FLAGS_to:-${OUTPUT_DIR}/chromiumos_image.bin}
Bill Richardsonc09b94f2010-03-15 11:40:30 -070072
73BOARD="${FLAGS_board}"
74BOARD_ROOT="${FLAGS_build_root}/${BOARD}"
75
76LOOP_DEV=
Chris Sosa4bffb8b2010-04-07 17:23:54 -070077STATEFUL_LOOP_DEV=
Bill Richardsona81df762010-04-09 08:12:05 -070078ESP_LOOP_DEV=
Bill Richardsonc09b94f2010-03-15 11:40:30 -070079
80# What cross-build are we targeting?
81. "${BOARD_ROOT}/etc/make.conf.board_setup"
82LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"}
83
84# Figure out ARCH from the given toolchain.
85# TODO: Move to common.sh as a function after scripts are switched over.
86TC_ARCH=$(echo "$CHOST" | awk -F'-' '{ print $1 }')
87case "$TC_ARCH" in
88 arm*)
89 ARCH="arm"
90 ;;
91 *86)
92 ARCH="x86"
93 ;;
94 *)
95 error "Unable to determine ARCH from toolchain: $CHOST"
96 exit 1
97esac
98
99# Hack to fix bug where x86_64 CHOST line gets incorrectly added.
100# ToDo(msb): remove this hack.
101PACKAGES_FILE="${BOARD_ROOT}/packages/Packages"
102sudo sed -e "s/CHOST: x86_64-pc-linux-gnu//" -i "${PACKAGES_FILE}"
103
104# Handle existing directory.
105if [[ -e "$OUTPUT_DIR" ]]; then
106 if [[ $FLAGS_replace -eq $FLAGS_TRUE ]]; then
107 sudo rm -rf "$OUTPUT_DIR"
108 else
109 echo "Directory $OUTPUT_DIR already exists."
110 echo "Use --build_attempt option to specify an unused attempt."
111 echo "Or use --replace if you want to overwrite this directory."
112 exit 1
113 fi
114fi
115
116# Create the output directory.
117mkdir -p "$OUTPUT_DIR"
118
119cleanup_rootfs_loop() {
120 sudo umount "$LOOP_DEV"
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700121 sleep 1 # in case $LOOP_DEV is in use.
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700122 sudo losetup -d "$LOOP_DEV"
123}
124
125cleanup_stateful_fs_loop() {
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700126 sudo umount "${ROOT_FS_DIR}/usr/local"
127 sudo umount "${ROOT_FS_DIR}/var"
128 sudo umount "${STATEFUL_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700129 sleep 1 # follows from cleanup_root_fs_loop.
130 sudo losetup -d "$STATEFUL_LOOP_DEV"
131}
132
Bill Richardson8b3bd102010-04-06 15:00:10 -0700133cleanup_esp_loop() {
134 sudo umount "$ESP_DIR"
Bill Richardsona81df762010-04-09 08:12:05 -0700135 sleep 1
136 sudo losetup -d "$ESP_LOOP_DEV"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700137}
138
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700139cleanup() {
140 # Disable die on error.
141 set +e
142
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700143 if [[ -n "$STATEFUL_LOOP_DEV" ]]; then
144 cleanup_stateful_fs_loop
145 fi
146
147 if [[ -n "$LOOP_DEV" ]]; then
148 cleanup_rootfs_loop
149 fi
150
Bill Richardsona81df762010-04-09 08:12:05 -0700151 if [[ -n "$ESP_LOOP_DEV" ]]; then
Bill Richardson8b3bd102010-04-06 15:00:10 -0700152 cleanup_esp_loop
153 fi
154
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700155 # Turn die on error back on.
156 set -e
157}
158
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700159# ${DEV_IMAGE_ROOT} specifies the location of where developer packages will
160# be installed on the stateful dir. On a Chromium OS system, this will
161# translate to /usr/local
162DEV_IMAGE_ROOT=
163
164# Sets up symlinks for the stateful partition based on the root specified by
165# ${1} and var directory specified by ${2}.
166setup_symlinks_on_root() {
167 echo "Setting up symlinks on the stateful partition rooted at ${1} with"\
168 "var directory located at ${2}"
169
170 for path in usr local; do
171 if [ -h "${DEV_IMAGE_ROOT}/${path}" ] ; then
172 sudo unlink "${DEV_IMAGE_ROOT}/${path}"
173 elif [ -e "${DEV_IMAGE_ROOT}/${path}" ] ; then
174 echo "*** ERROR: ${DEV_IMAGE_ROOT}/${path} should be a symlink if exists"
175 return 1
176 fi
177 sudo ln -s ${1} "${DEV_IMAGE_ROOT}/${path}"
178 done
179
180 # Setup var. Var is on the stateful partition at /var for both non-developer
181 # builds and developer builds.
182 if [ -h "${DEV_IMAGE_ROOT}/var" ] ; then
183 sudo unlink "${DEV_IMAGE_ROOT}/var"
184 elif [ -e "${DEV_IMAGE_ROOT}/var" ] ; then
185 echo "*** ERROR: ${DEV_IMAGE_ROOT}/var should be a symlink if it exists"
186 return 1
187 fi
188
189 sudo ln -s "${2}" "${DEV_IMAGE_ROOT}/var"
190}
191
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700192trap cleanup EXIT
193
194mkdir -p "$ROOT_FS_DIR"
195
196# Create and format the root file system.
197
198# Check for loop device before creating image.
199LOOP_DEV=$(sudo losetup -f)
200if [ -z "$LOOP_DEV" ] ; then
201 echo "No free loop device. Free up a loop device or reboot. exiting. "
202 exit 1
203fi
204
205# Create root file system disk image to fit on a 1GB memory stick.
206# 1 GB in hard-drive-manufacturer-speak is 10^9, not 2^30. 950MB < 10^9 bytes.
Chris Masone35a83f92010-04-05 16:51:53 -0700207ROOT_SIZE_BYTES=$((1024 * 1024 * 720))
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700208dd if=/dev/zero of="$ROOT_FS_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1))
209sudo losetup "$LOOP_DEV" "$ROOT_FS_IMG"
210sudo mkfs.ext3 "$LOOP_DEV"
211
212# Tune and mount rootfs.
213UUID=$(uuidgen)
214DISK_LABEL="C-KEYFOB"
215sudo tune2fs -L "$DISK_LABEL" -U "$UUID" -c 0 -i 0 "$LOOP_DEV"
216sudo mount "$LOOP_DEV" "$ROOT_FS_DIR"
217
218# Create stateful partition of the same size as the rootfs.
219STATEFUL_IMG="$OUTPUT_DIR/stateful_partition.image"
220STATEFUL_DIR="$OUTPUT_DIR/stateful_partition"
221STATEFUL_LOOP_DEV=$(sudo losetup -f)
222if [ -z "$STATEFUL_LOOP_DEV" ] ; then
223 echo "No free loop device. Free up a loop device or reboot. exiting. "
224 exit 1
225fi
226dd if=/dev/zero of="$STATEFUL_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1))
227sudo losetup "$STATEFUL_LOOP_DEV" "$STATEFUL_IMG"
228sudo mkfs.ext3 "$STATEFUL_LOOP_DEV"
229sudo tune2fs -L "C-STATE" -U "$UUID" -c 0 -i 0 \
230 "$STATEFUL_LOOP_DEV"
231
232# Mount the stateful partition.
233mkdir -p "$STATEFUL_DIR"
234sudo mount "$STATEFUL_LOOP_DEV" "$STATEFUL_DIR"
235
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700236# Set dev image root now that we have mounted the stateful partition we created
237DEV_IMAGE_ROOT="$STATEFUL_DIR/dev_image"
238
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700239# Turn root file system into bootable image.
240if [[ "$ARCH" = "x86" ]]; then
241 # Setup extlinux configuration.
242 # TODO: For some reason the /dev/disk/by-uuid is not being generated by udev
243 # in the initramfs. When we figure that out, switch to root=UUID=$UUID.
244 sudo mkdir -p "$ROOT_FS_DIR"/boot
245 # TODO(adlr): use initramfs for booting.
246 cat <<EOF | sudo dd of="$ROOT_FS_DIR"/boot/extlinux.conf
247DEFAULT chromeos-usb
248PROMPT 0
249TIMEOUT 0
250
251label chromeos-usb
252 menu label chromeos-usb
253 kernel vmlinuz
254 append quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sdb3 ro noresume noswap i915.modeset=1 loglevel=1
255
256label chromeos-hd
257 menu label chromeos-hd
258 kernel vmlinuz
259 append quiet console=tty2 init=/sbin/init boot=local rootwait root=HDROOT ro noresume noswap i915.modeset=1 loglevel=1
260EOF
261
262 # Make partition bootable and label it.
263 sudo extlinux -z --install "${ROOT_FS_DIR}/boot"
264fi
265
266# -- Install packages into the root file system --
267
268# We need to install libc manually from the cross toolchain.
269# TODO: Improve this? We only want libc and not the whole toolchain.
270PKGDIR="/var/lib/portage/pkgs/cross/"
271sudo tar jxvpf \
272 "${PKGDIR}/${CHOST}/cross-${CHOST}"/glibc-${LIBC_VERSION}.tbz2 \
273 -C "$ROOT_FS_DIR" --strip-components=3 \
274 --exclude=usr/include --exclude=sys-include --exclude=*.a --exclude=*.o
275
276# We need to install libstdc++ manually from the cross toolchain.
277# TODO: Figure out a better way of doing this?
278sudo cp -a "${BOARD_ROOT}"/lib/libgcc_s.so* "${ROOT_FS_DIR}/lib"
279sudo cp -a "${BOARD_ROOT}"/usr/lib/libstdc++.so* "${ROOT_FS_DIR}/usr/lib"
280
281INSTALL_MASK=""
Chris Sosa3d9a10b2010-04-13 15:00:46 -0700282if [[ $FLAGS_installmask -eq ${FLAGS_TRUE} ]] ; then
Chris Sosaaa1a7fd2010-04-02 14:06:29 -0700283 INSTALL_MASK="$DEFAULT_INSTALL_MASK"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700284fi
285
286if [[ $FLAGS_jobs -ne -1 ]]; then
287 EMERGE_JOBS="--jobs=$FLAGS_jobs"
Ken Mixterc223ba12010-04-16 09:08:26 -0700288 if [[ $FLAGS_retries -eq -1 ]]; then
289 # The jobs flag can be flaky. Retry once by default,
290 # without the jobs flag.
291 FLAGS_retries=1
292 fi
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700293fi
294
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700295# Prepare stateful partition with some pre-created directories
296sudo mkdir -p "${DEV_IMAGE_ROOT}"
297sudo mkdir -p "${STATEFUL_DIR}/var"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700298
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700299# Create symlinks so that /usr/local/usr based directories are symlinked to
300# /usr/local/ directories e.g. /usr/local/usr/bin -> /usr/local/bin, etc.
301setup_symlinks_on_root "${DEV_IMAGE_ROOT}" "${STATEFUL_DIR}/var"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700302
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700303# Perform binding rather than symlinking because directories must exist
304# on rootfs so that we can bind at run-time since rootfs is read-only
305echo "Binding directories from stateful partition onto the rootfs"
306sudo mkdir -p "${ROOT_FS_DIR}/usr/local"
307sudo mount --bind "${DEV_IMAGE_ROOT}" "${ROOT_FS_DIR}/usr/local"
308sudo mkdir -p "${ROOT_FS_DIR}/var"
309sudo mount --bind "${STATEFUL_DIR}/var" "${ROOT_FS_DIR}/var"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700310
311# We "emerge --root=$ROOT_FS_DIR --root-deps=rdeps --usepkgonly" all of the
312# runtime packages for chrome os. This builds up a chrome os image from binary
313# packages with runtime dependencies only. We use INSTALL_MASK to trim the
314# image size as much as possible.
Ken Mixterc223ba12010-04-16 09:08:26 -0700315eretry sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700316 --root="$ROOT_FS_DIR" --root-deps=rdeps \
317 --usepkgonly chromeos $EMERGE_JOBS
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700318
Chris Sosa4bccd3c2010-03-15 13:23:14 -0700319# Determine the root dir for development packages.
320ROOT_DEV_DIR="$ROOT_FS_DIR"
321[ $FLAGS_statefuldev -eq $FLAGS_TRUE ] && ROOT_DEV_DIR="$ROOT_FS_DIR/usr/local"
322
323# Install development packages.
324if [[ $FLAGS_withdev -eq $FLAGS_TRUE ]] ; then
Ken Mixterc223ba12010-04-16 09:08:26 -0700325 eretry sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
Chris Sosa4bccd3c2010-03-15 13:23:14 -0700326 --root="$ROOT_DEV_DIR" --root-deps=rdeps \
327 --usepkgonly chromeos-dev $EMERGE_JOBS
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700328
Chris Sosa3d9a10b2010-04-13 15:00:46 -0700329 # TODO(sosa@chromium.org) - Re-hide under statefuldev after switch
330 # Flag will mount /usr/local on target device
331 sudo mkdir -p "$ROOT_FS_DIR/root"
332 sudo touch "$ROOT_FS_DIR/root/.dev_mode"
333
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
Andrew de los Reyese7a04ad2010-04-08 15:58:17 -0700338if [ -n "$FLAGS_factory_server" ]; then
Ken Mixterc223ba12010-04-16 09:08:26 -0700339 eretry sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
Andrew de los Reyese7a04ad2010-04-08 15:58:17 -0700340 --root="$ROOT_DEV_DIR" --root-deps=rdeps \
341 --usepkgonly chromeos-factoryinstall $EMERGE_JOBS
342fi
343
Chris Sosa4bccd3c2010-03-15 13:23:14 -0700344# Install packages required for testing.
345if [[ $FLAGS_withtest -eq $FLAGS_TRUE ]] ; then
Ken Mixterc223ba12010-04-16 09:08:26 -0700346 eretry sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
Chris Sosa4bccd3c2010-03-15 13:23:14 -0700347 --root="$ROOT_DEV_DIR" --root-deps=rdeps \
348 --usepkgonly chromeos-test $EMERGE_JOBS
349fi
350
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700351# Perform any customizations on the root file system that are needed.
Andrew de los Reyese7a04ad2010-04-08 15:58:17 -0700352EXTRA_CUSTOMIZE_ROOTFS_FLAGS=""
353if [ $FLAGS_withdev -eq $FLAGS_TRUE ]; then
354 EXTRA_CUSTOMIZE_ROOTFS_FLAGS="--withdev"
355fi
356if [ -n "$FLAGS_factory_server" ]; then
357# Indentation off b/c of long line
358EXTRA_CUSTOMIZE_ROOTFS_FLAGS="$EXTRA_CUSTOMIZE_ROOTFS_FLAGS"\
359" --factory_server=$FLAGS_factory_server"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700360fi
361
Bill Richardson4364a2e2010-03-30 14:17:34 -0700362# Extract the kernel from the root filesystem for use by the GPT image. Legacy
Bill Richardson8b3bd102010-04-06 15:00:10 -0700363# BIOS will use the kernel in the rootfs (via syslinux), Chrome OS BIOS will
364# use the kernel partition.
Bill Richardson6dcea162010-03-31 19:20:24 -0700365sudo cp -f "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image"
Bill Richardson4364a2e2010-03-30 14:17:34 -0700366
Bill Richardson8b3bd102010-04-06 15:00:10 -0700367# Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI
368# BIOS). We only need this for x86, but it's simpler and safer to keep the disk
369# images the same for both x86 and ARM.
370ESP_IMG=${OUTPUT_DIR}/esp.image
371# NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. We'll hard-code
372# it to 16M for now.
373ESP_BLOCKS=16384
374/usr/sbin/mkfs.vfat -C ${OUTPUT_DIR}/esp.image ${ESP_BLOCKS}
375ESP_DIR=${OUTPUT_DIR}/esp
Bill Richardsona81df762010-04-09 08:12:05 -0700376ESP_LOOP_DEV=$(sudo losetup -f)
377if [ -z "$ESP_LOOP_DEV" ] ; then
378 echo "No free loop device. Free up a loop device or reboot. exiting. "
379 exit 1
380fi
381mkdir -p "${ESP_DIR}"
382sudo losetup "${ESP_LOOP_DEV}" "${ESP_IMG}"
383sudo mount "${ESP_LOOP_DEV}" "${ESP_DIR}"
384sudo mkdir -p "${ESP_DIR}/efi/boot"
385sudo grub-mkimage -p /efi/boot -o "${ESP_DIR}/efi/boot/bootx64.efi" \
Bill Richardson8b3bd102010-04-06 15:00:10 -0700386 part_gpt fat ext2 normal boot sh chain configfile linux
Bill Richardsona81df762010-04-09 08:12:05 -0700387sudo cp "${ROOT_FS_DIR}/boot/vmlinuz" "${ESP_DIR}/efi/boot/vmlinuz"
388cat <<EOF | sudo dd of="${ESP_DIR}/efi/boot/grub.cfg"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700389set timeout=2
390set default=0
391
Bill Richardsona81df762010-04-09 08:12:05 -0700392menuentry "normal" {
393 linux /efi/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sda3 ro noresume noswap i915.modeset=1 loglevel=1
394}
395
Bill Richardsonba9682a2010-04-13 13:02:32 -0700396menuentry "serial debug" {
397 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
398}
399
Bill Richardson8b3bd102010-04-06 15:00:10 -0700400EOF
401
Chris Sosa3d9a10b2010-04-13 15:00:46 -0700402# Run ldconfig for rootfs's ld.so.cache
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700403if [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] ; then
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700404 # Re-run ldconfig to fix /etc/ldconfig.so.cache
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700405 sudo /sbin/ldconfig -r "$ROOT_FS_DIR"
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700406
407 #TODO(sosa@chromium.org) - /usr/bin/xterm symlink not created in stateful.
408 sudo ln -sf "/usr/local/bin/aterm" "/usr/bin/xterm"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700409fi
410
Chris Sosa503efe12010-04-08 10:05:46 -0700411"${SCRIPTS_DIR}/customize_rootfs" \
412 --root="$ROOT_FS_DIR" \
413 --target="$ARCH" \
414 --board="$BOARD" \
Andrew de los Reyese7a04ad2010-04-08 15:58:17 -0700415 $EXTRA_CUSTOMIZE_ROOTFS_FLAGS
Chris Sosa503efe12010-04-08 10:05:46 -0700416
417# Check that the image has been correctly created.
418"${SCRIPTS_DIR}/test_image" \
419 --root="$ROOT_FS_DIR" \
420 --target="$ARCH"
421
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700422# Clean up symlinks so they work on a running target rooted at "/".
423# Here development packages are rooted at /usr/local. However, do not
424# create /usr/local or /var on host (already exist on target).
425setup_symlinks_on_root "/usr/local" "/var"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700426
427# Cleanup loop devices.
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700428cleanup
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700429
Bill Richardson4364a2e2010-03-30 14:17:34 -0700430# Create the GPT-formatted image
431${SCRIPTS_DIR}/build_gpt.sh \
Jie Sun96e2b092010-04-09 11:05:49 -0700432 --arch=${ARCH} --board=${FLAGS_board} "${OUTPUT_DIR}" "${OUTPUT_IMG}"
Bill Richardson4364a2e2010-03-30 14:17:34 -0700433
Bill Richardson6dcea162010-03-31 19:20:24 -0700434# Clean up temporary files.
Bill Richardson8b3bd102010-04-06 15:00:10 -0700435rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \
436 "${ESP_IMG}"
437rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" "${ESP_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700438
439OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}"
440echo "Done. Image created in ${OUTPUT_DIR}"
441echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:"
442echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdb"
443echo "To convert to VMWare image, OUTSIDE the chroot, do something like:"
444echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}"
445echo "from the scripts directory where you entered the chroot."
446
447trap - EXIT