blob: 8bc0c6179b814e9c9a4ca6de06618d9abdac10ed [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."
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."
robotboyb75eee32010-04-30 09:51:23 -070046DEFINE_string arm_extra_bootargs "" \
47 "Additional command line options to pass to the ARM kernel."
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() {
Chris Sosabde8c1b2010-04-29 14:02:35 -0700120 sudo umount -d "$ROOT_FS_DIR"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700121}
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"
Chris Sosabde8c1b2010-04-29 14:02:35 -0700126 sudo umount -d "${STATEFUL_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700127}
128
Bill Richardson8b3bd102010-04-06 15:00:10 -0700129cleanup_esp_loop() {
Chris Sosabde8c1b2010-04-29 14:02:35 -0700130 sudo umount -d "$ESP_DIR"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700131}
132
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700133cleanup() {
134 # Disable die on error.
135 set +e
136
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700137 if [[ -n "$STATEFUL_LOOP_DEV" ]]; then
138 cleanup_stateful_fs_loop
139 fi
140
141 if [[ -n "$LOOP_DEV" ]]; then
142 cleanup_rootfs_loop
143 fi
144
Bill Richardsona81df762010-04-09 08:12:05 -0700145 if [[ -n "$ESP_LOOP_DEV" ]]; then
Bill Richardson8b3bd102010-04-06 15:00:10 -0700146 cleanup_esp_loop
147 fi
148
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700149 # Turn die on error back on.
150 set -e
151}
152
Chris Sosabde8c1b2010-04-29 14:02:35 -0700153delete_prompt() {
154 echo "An error occurred in your build so your latest output directory" \
155 "is invalid."
156 read -p "Would you like to delete the output directory (y/N)? " SURE
157 SURE="${SURE:0:1}" # Get just the first character
158 if [ "${SURE}" == "y" ] ; then
159 sudo rm -rf "$OUTPUT_DIR"
160 echo "Deleted $OUTPUT_DIR"
161 else
162 echo "Not deleting $OUTPUT_DIR. Note dev server updates will not work" \
163 "until you successfully build another image or delete this directory"
164 fi
165}
166
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700167# ${DEV_IMAGE_ROOT} specifies the location of where developer packages will
168# be installed on the stateful dir. On a Chromium OS system, this will
169# translate to /usr/local
170DEV_IMAGE_ROOT=
171
172# Sets up symlinks for the stateful partition based on the root specified by
173# ${1} and var directory specified by ${2}.
174setup_symlinks_on_root() {
175 echo "Setting up symlinks on the stateful partition rooted at ${1} with"\
176 "var directory located at ${2}"
177
178 for path in usr local; do
179 if [ -h "${DEV_IMAGE_ROOT}/${path}" ] ; then
180 sudo unlink "${DEV_IMAGE_ROOT}/${path}"
181 elif [ -e "${DEV_IMAGE_ROOT}/${path}" ] ; then
182 echo "*** ERROR: ${DEV_IMAGE_ROOT}/${path} should be a symlink if exists"
183 return 1
184 fi
185 sudo ln -s ${1} "${DEV_IMAGE_ROOT}/${path}"
186 done
187
188 # Setup var. Var is on the stateful partition at /var for both non-developer
189 # builds and developer builds.
190 if [ -h "${DEV_IMAGE_ROOT}/var" ] ; then
191 sudo unlink "${DEV_IMAGE_ROOT}/var"
192 elif [ -e "${DEV_IMAGE_ROOT}/var" ] ; then
193 echo "*** ERROR: ${DEV_IMAGE_ROOT}/var should be a symlink if it exists"
194 return 1
195 fi
196
197 sudo ln -s "${2}" "${DEV_IMAGE_ROOT}/var"
198}
199
Chris Sosabde8c1b2010-04-29 14:02:35 -0700200trap "cleanup && delete_prompt" EXIT
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700201
202mkdir -p "$ROOT_FS_DIR"
203
204# Create and format the root file system.
205
206# Check for loop device before creating image.
207LOOP_DEV=$(sudo losetup -f)
208if [ -z "$LOOP_DEV" ] ; then
209 echo "No free loop device. Free up a loop device or reboot. exiting. "
210 exit 1
211fi
212
213# Create root file system disk image to fit on a 1GB memory stick.
214# 1 GB in hard-drive-manufacturer-speak is 10^9, not 2^30. 950MB < 10^9 bytes.
Chris Masone35a83f92010-04-05 16:51:53 -0700215ROOT_SIZE_BYTES=$((1024 * 1024 * 720))
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700216dd if=/dev/zero of="$ROOT_FS_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1))
217sudo losetup "$LOOP_DEV" "$ROOT_FS_IMG"
218sudo mkfs.ext3 "$LOOP_DEV"
219
220# Tune and mount rootfs.
221UUID=$(uuidgen)
222DISK_LABEL="C-KEYFOB"
223sudo tune2fs -L "$DISK_LABEL" -U "$UUID" -c 0 -i 0 "$LOOP_DEV"
224sudo mount "$LOOP_DEV" "$ROOT_FS_DIR"
225
226# Create stateful partition of the same size as the rootfs.
227STATEFUL_IMG="$OUTPUT_DIR/stateful_partition.image"
228STATEFUL_DIR="$OUTPUT_DIR/stateful_partition"
229STATEFUL_LOOP_DEV=$(sudo losetup -f)
230if [ -z "$STATEFUL_LOOP_DEV" ] ; then
231 echo "No free loop device. Free up a loop device or reboot. exiting. "
232 exit 1
233fi
234dd if=/dev/zero of="$STATEFUL_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1))
235sudo losetup "$STATEFUL_LOOP_DEV" "$STATEFUL_IMG"
236sudo mkfs.ext3 "$STATEFUL_LOOP_DEV"
237sudo tune2fs -L "C-STATE" -U "$UUID" -c 0 -i 0 \
238 "$STATEFUL_LOOP_DEV"
239
240# Mount the stateful partition.
241mkdir -p "$STATEFUL_DIR"
242sudo mount "$STATEFUL_LOOP_DEV" "$STATEFUL_DIR"
243
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700244# Set dev image root now that we have mounted the stateful partition we created
245DEV_IMAGE_ROOT="$STATEFUL_DIR/dev_image"
246
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700247# Turn root file system into bootable image.
248if [[ "$ARCH" = "x86" ]]; then
249 # Setup extlinux configuration.
250 # TODO: For some reason the /dev/disk/by-uuid is not being generated by udev
251 # in the initramfs. When we figure that out, switch to root=UUID=$UUID.
252 sudo mkdir -p "$ROOT_FS_DIR"/boot
253 # TODO(adlr): use initramfs for booting.
254 cat <<EOF | sudo dd of="$ROOT_FS_DIR"/boot/extlinux.conf
255DEFAULT chromeos-usb
256PROMPT 0
257TIMEOUT 0
258
259label chromeos-usb
260 menu label chromeos-usb
261 kernel vmlinuz
262 append quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sdb3 ro noresume noswap i915.modeset=1 loglevel=1
263
264label chromeos-hd
265 menu label chromeos-hd
266 kernel vmlinuz
267 append quiet console=tty2 init=/sbin/init boot=local rootwait root=HDROOT ro noresume noswap i915.modeset=1 loglevel=1
268EOF
269
270 # Make partition bootable and label it.
271 sudo extlinux -z --install "${ROOT_FS_DIR}/boot"
272fi
273
274# -- Install packages into the root file system --
275
276# We need to install libc manually from the cross toolchain.
277# TODO: Improve this? We only want libc and not the whole toolchain.
278PKGDIR="/var/lib/portage/pkgs/cross/"
279sudo tar jxvpf \
280 "${PKGDIR}/${CHOST}/cross-${CHOST}"/glibc-${LIBC_VERSION}.tbz2 \
281 -C "$ROOT_FS_DIR" --strip-components=3 \
282 --exclude=usr/include --exclude=sys-include --exclude=*.a --exclude=*.o
283
284# We need to install libstdc++ manually from the cross toolchain.
285# TODO: Figure out a better way of doing this?
286sudo cp -a "${BOARD_ROOT}"/lib/libgcc_s.so* "${ROOT_FS_DIR}/lib"
287sudo cp -a "${BOARD_ROOT}"/usr/lib/libstdc++.so* "${ROOT_FS_DIR}/usr/lib"
288
289INSTALL_MASK=""
Chris Sosa3d9a10b2010-04-13 15:00:46 -0700290if [[ $FLAGS_installmask -eq ${FLAGS_TRUE} ]] ; then
Chris Sosaaa1a7fd2010-04-02 14:06:29 -0700291 INSTALL_MASK="$DEFAULT_INSTALL_MASK"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700292fi
293
294if [[ $FLAGS_jobs -ne -1 ]]; then
295 EMERGE_JOBS="--jobs=$FLAGS_jobs"
296fi
297
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700298# Prepare stateful partition with some pre-created directories
299sudo mkdir -p "${DEV_IMAGE_ROOT}"
300sudo mkdir -p "${STATEFUL_DIR}/var"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700301
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700302# Create symlinks so that /usr/local/usr based directories are symlinked to
303# /usr/local/ directories e.g. /usr/local/usr/bin -> /usr/local/bin, etc.
304setup_symlinks_on_root "${DEV_IMAGE_ROOT}" "${STATEFUL_DIR}/var"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700305
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700306# Perform binding rather than symlinking because directories must exist
307# on rootfs so that we can bind at run-time since rootfs is read-only
308echo "Binding directories from stateful partition onto the rootfs"
309sudo mkdir -p "${ROOT_FS_DIR}/usr/local"
310sudo mount --bind "${DEV_IMAGE_ROOT}" "${ROOT_FS_DIR}/usr/local"
311sudo mkdir -p "${ROOT_FS_DIR}/var"
312sudo mount --bind "${STATEFUL_DIR}/var" "${ROOT_FS_DIR}/var"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700313
314# We "emerge --root=$ROOT_FS_DIR --root-deps=rdeps --usepkgonly" all of the
315# runtime packages for chrome os. This builds up a chrome os image from binary
316# packages with runtime dependencies only. We use INSTALL_MASK to trim the
317# image size as much as possible.
Ken Mixterd5c4b172010-04-16 10:11:02 -0700318sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700319 --root="$ROOT_FS_DIR" --root-deps=rdeps \
320 --usepkgonly chromeos $EMERGE_JOBS
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700321
Chris Sosa4bccd3c2010-03-15 13:23:14 -0700322# Determine the root dir for development packages.
323ROOT_DEV_DIR="$ROOT_FS_DIR"
324[ $FLAGS_statefuldev -eq $FLAGS_TRUE ] && ROOT_DEV_DIR="$ROOT_FS_DIR/usr/local"
325
326# Install development packages.
327if [[ $FLAGS_withdev -eq $FLAGS_TRUE ]] ; then
Ken Mixterd5c4b172010-04-16 10:11:02 -0700328 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
Chris Sosa4bccd3c2010-03-15 13:23:14 -0700329 --root="$ROOT_DEV_DIR" --root-deps=rdeps \
330 --usepkgonly chromeos-dev $EMERGE_JOBS
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700331
Chris Sosa3d9a10b2010-04-13 15:00:46 -0700332 # TODO(sosa@chromium.org) - Re-hide under statefuldev after switch
333 # Flag will mount /usr/local on target device
334 sudo mkdir -p "$ROOT_FS_DIR/root"
Chris Sosa3d9a10b2010-04-13 15:00:46 -0700335
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700336 # The ldd tool is a useful shell script but lives in glibc; just copy it.
Chris Sosa4bccd3c2010-03-15 13:23:14 -0700337 sudo cp -a "$(which ldd)" "${ROOT_DEV_DIR}/usr/bin"
338fi
339
Andrew de los Reyese7a04ad2010-04-08 15:58:17 -0700340if [ -n "$FLAGS_factory_server" ]; then
Ken Mixterd5c4b172010-04-16 10:11:02 -0700341 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
Andrew de los Reyese7a04ad2010-04-08 15:58:17 -0700342 --root="$ROOT_DEV_DIR" --root-deps=rdeps \
343 --usepkgonly chromeos-factoryinstall $EMERGE_JOBS
344fi
345
Chris Sosa4bccd3c2010-03-15 13:23:14 -0700346# Install packages required for testing.
347if [[ $FLAGS_withtest -eq $FLAGS_TRUE ]] ; then
Ken Mixterd5c4b172010-04-16 10:11:02 -0700348 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
Chris Sosa4bccd3c2010-03-15 13:23:14 -0700349 --root="$ROOT_DEV_DIR" --root-deps=rdeps \
350 --usepkgonly chromeos-test $EMERGE_JOBS
351fi
352
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700353# Perform any customizations on the root file system that are needed.
Andrew de los Reyese7a04ad2010-04-08 15:58:17 -0700354EXTRA_CUSTOMIZE_ROOTFS_FLAGS=""
355if [ $FLAGS_withdev -eq $FLAGS_TRUE ]; then
356 EXTRA_CUSTOMIZE_ROOTFS_FLAGS="--withdev"
357fi
358if [ -n "$FLAGS_factory_server" ]; then
359# Indentation off b/c of long line
360EXTRA_CUSTOMIZE_ROOTFS_FLAGS="$EXTRA_CUSTOMIZE_ROOTFS_FLAGS"\
361" --factory_server=$FLAGS_factory_server"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700362fi
363
Bill Richardson4364a2e2010-03-30 14:17:34 -0700364# Extract the kernel from the root filesystem for use by the GPT image. Legacy
Bill Richardson8b3bd102010-04-06 15:00:10 -0700365# BIOS will use the kernel in the rootfs (via syslinux), Chrome OS BIOS will
366# use the kernel partition.
Bill Richardson6dcea162010-03-31 19:20:24 -0700367sudo cp -f "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image"
Bill Richardson4364a2e2010-03-30 14:17:34 -0700368
Bill Richardson8b3bd102010-04-06 15:00:10 -0700369# Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI
370# BIOS). We only need this for x86, but it's simpler and safer to keep the disk
371# images the same for both x86 and ARM.
372ESP_IMG=${OUTPUT_DIR}/esp.image
373# NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. We'll hard-code
374# it to 16M for now.
375ESP_BLOCKS=16384
376/usr/sbin/mkfs.vfat -C ${OUTPUT_DIR}/esp.image ${ESP_BLOCKS}
377ESP_DIR=${OUTPUT_DIR}/esp
Bill Richardsona81df762010-04-09 08:12:05 -0700378ESP_LOOP_DEV=$(sudo losetup -f)
379if [ -z "$ESP_LOOP_DEV" ] ; then
380 echo "No free loop device. Free up a loop device or reboot. exiting. "
381 exit 1
382fi
383mkdir -p "${ESP_DIR}"
384sudo losetup "${ESP_LOOP_DEV}" "${ESP_IMG}"
385sudo mount "${ESP_LOOP_DEV}" "${ESP_DIR}"
386sudo mkdir -p "${ESP_DIR}/efi/boot"
387sudo grub-mkimage -p /efi/boot -o "${ESP_DIR}/efi/boot/bootx64.efi" \
Bill Richardson8b3bd102010-04-06 15:00:10 -0700388 part_gpt fat ext2 normal boot sh chain configfile linux
Bill Richardsona81df762010-04-09 08:12:05 -0700389sudo cp "${ROOT_FS_DIR}/boot/vmlinuz" "${ESP_DIR}/efi/boot/vmlinuz"
390cat <<EOF | sudo dd of="${ESP_DIR}/efi/boot/grub.cfg"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700391set timeout=2
392set default=0
393
Bill Richardson041bd712010-04-27 09:36:14 -0700394menuentry "boot from disk" {
Bill Richardsona81df762010-04-09 08:12:05 -0700395 linux /efi/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sda3 ro noresume noswap i915.modeset=1 loglevel=1
396}
397
Bill Richardson041bd712010-04-27 09:36:14 -0700398menuentry "boot from disk with serial debug" {
Bill Richardsonba9682a2010-04-13 13:02:32 -0700399 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
400}
401
Bill Richardson041bd712010-04-27 09:36:14 -0700402menuentry "boot from usb" {
403 linux /efi/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sdb3 ro noresume noswap i915.modeset=1 loglevel=1
404}
405
406menuentry "boot from usb with serial debug" {
407 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
408}
409
Bill Richardson8b3bd102010-04-06 15:00:10 -0700410EOF
411
Chris Sosa5c37ce22010-05-03 20:18:02 -0700412# By default, dev mode should be activated for either development builds or
413# test builds.
414if [[ $FLAGS_withdev -eq $FLAGS_TRUE ]] ||\
415 [[ $FLAGS_withtest -eq $FLAGS_TRUE ]]; then
416 sudo touch "$ROOT_FS_DIR/root/.dev_mode"
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700417
Chris Sosa5c37ce22010-05-03 20:18:02 -0700418 # Re-run ldconfig to fix /etc/ldconfig.so.cache.
419 sudo /sbin/ldconfig -r "$ROOT_FS_DIR"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700420fi
421
Chris Sosa503efe12010-04-08 10:05:46 -0700422"${SCRIPTS_DIR}/customize_rootfs" \
423 --root="$ROOT_FS_DIR" \
424 --target="$ARCH" \
425 --board="$BOARD" \
Andrew de los Reyese7a04ad2010-04-08 15:58:17 -0700426 $EXTRA_CUSTOMIZE_ROOTFS_FLAGS
Chris Sosa503efe12010-04-08 10:05:46 -0700427
428# Check that the image has been correctly created.
429"${SCRIPTS_DIR}/test_image" \
430 --root="$ROOT_FS_DIR" \
431 --target="$ARCH"
432
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700433# Clean up symlinks so they work on a running target rooted at "/".
434# Here development packages are rooted at /usr/local. However, do not
435# create /usr/local or /var on host (already exist on target).
436setup_symlinks_on_root "/usr/local" "/var"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700437
438# Cleanup loop devices.
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700439cleanup
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700440
Chris Sosabde8c1b2010-04-29 14:02:35 -0700441trap delete_prompt EXIT
442
Bill Richardson4364a2e2010-03-30 14:17:34 -0700443# Create the GPT-formatted image
444${SCRIPTS_DIR}/build_gpt.sh \
robotboyb75eee32010-04-30 09:51:23 -0700445 --arch=${ARCH} \
446 --board=${FLAGS_board} \
447 --arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \
448 "${OUTPUT_DIR}" \
449 "${OUTPUT_IMG}"
Bill Richardson4364a2e2010-03-30 14:17:34 -0700450
Bill Richardson6dcea162010-03-31 19:20:24 -0700451# Clean up temporary files.
Bill Richardson8b3bd102010-04-06 15:00:10 -0700452rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \
453 "${ESP_IMG}"
454rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" "${ESP_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700455
456OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}"
457echo "Done. Image created in ${OUTPUT_DIR}"
458echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:"
Daniel Eratdd9818a2010-04-26 09:16:44 -0700459echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700460echo "To convert to VMWare image, OUTSIDE the chroot, do something like:"
461echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}"
462echo "from the scripts directory where you entered the chroot."
463
464trap - EXIT