blob: 17afa28d2e5d5a33c13dc4e2430ec09d7e401de8 [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."
Tan Gao6df5aee2010-05-19 14:19:55 -070047DEFINE_boolean recovery $FLAGS_FALSE \
48 "Build a recovery image. Default: False."
Bill Richardsonc09b94f2010-03-15 11:40:30 -070049
50# Parse command line.
51FLAGS "$@" || exit 1
52eval set -- "${FLAGS_ARGV}"
53
54# Only now can we die on error. shflags functions leak non-zero error codes,
55# so will die prematurely if 'set -e' is specified before now.
56set -e
57
58if [ -z "$FLAGS_board" ] ; then
59 error "--board is required."
60 exit 1
61fi
62
Bill Richardsonc09b94f2010-03-15 11:40:30 -070063# Determine build version.
64. "${SCRIPTS_DIR}/chromeos_version.sh"
65
66# Use canonical path since some tools (e.g. mount) do not like symlinks.
67# Append build attempt to output directory.
68IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}"
69OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}"
70ROOT_FS_DIR="${OUTPUT_DIR}/rootfs"
71ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image"
Chris Sosa9673f3b2010-05-18 13:24:40 -070072
73# If we are creating a developer image, also create a pristine image with a
74# different name.
75DEVELOPER_IMAGE_NAME=
76PRISTINE_IMAGE_NAME=chromiumos_image.bin
77if [ "$FLAGS_withdev" -eq "$FLAGS_TRUE" ]; then
78 PRISTINE_IMAGE_NAME=chromiumos_base_image.bin
79 DEVELOPER_IMAGE_NAME=chromiumos_image.bin
80fi
81OUTPUT_IMG=${FLAGS_to:-${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}}
Bill Richardsonc09b94f2010-03-15 11:40:30 -070082
83BOARD="${FLAGS_board}"
84BOARD_ROOT="${FLAGS_build_root}/${BOARD}"
85
86LOOP_DEV=
Chris Sosa4bffb8b2010-04-07 17:23:54 -070087STATEFUL_LOOP_DEV=
Bill Richardsona81df762010-04-09 08:12:05 -070088ESP_LOOP_DEV=
Bill Richardsonc09b94f2010-03-15 11:40:30 -070089
90# What cross-build are we targeting?
91. "${BOARD_ROOT}/etc/make.conf.board_setup"
92LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"}
93
94# Figure out ARCH from the given toolchain.
95# TODO: Move to common.sh as a function after scripts are switched over.
96TC_ARCH=$(echo "$CHOST" | awk -F'-' '{ print $1 }')
97case "$TC_ARCH" in
98 arm*)
99 ARCH="arm"
100 ;;
101 *86)
102 ARCH="x86"
103 ;;
104 *)
105 error "Unable to determine ARCH from toolchain: $CHOST"
106 exit 1
107esac
108
109# Hack to fix bug where x86_64 CHOST line gets incorrectly added.
110# ToDo(msb): remove this hack.
111PACKAGES_FILE="${BOARD_ROOT}/packages/Packages"
112sudo sed -e "s/CHOST: x86_64-pc-linux-gnu//" -i "${PACKAGES_FILE}"
113
114# Handle existing directory.
115if [[ -e "$OUTPUT_DIR" ]]; then
116 if [[ $FLAGS_replace -eq $FLAGS_TRUE ]]; then
117 sudo rm -rf "$OUTPUT_DIR"
118 else
119 echo "Directory $OUTPUT_DIR already exists."
120 echo "Use --build_attempt option to specify an unused attempt."
121 echo "Or use --replace if you want to overwrite this directory."
122 exit 1
123 fi
124fi
125
Bill Richardson67956222010-05-28 15:38:56 -0700126# Be verbose to help debug failures.
127set -x
128
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700129# Create the output directory.
130mkdir -p "$OUTPUT_DIR"
131
132cleanup_rootfs_loop() {
Chris Sosabde8c1b2010-04-29 14:02:35 -0700133 sudo umount -d "$ROOT_FS_DIR"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700134}
135
136cleanup_stateful_fs_loop() {
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700137 sudo umount "${ROOT_FS_DIR}/usr/local"
138 sudo umount "${ROOT_FS_DIR}/var"
Chris Sosabde8c1b2010-04-29 14:02:35 -0700139 sudo umount -d "${STATEFUL_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700140}
141
Bill Richardson8b3bd102010-04-06 15:00:10 -0700142cleanup_esp_loop() {
Chris Sosabde8c1b2010-04-29 14:02:35 -0700143 sudo umount -d "$ESP_DIR"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700144}
145
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700146cleanup() {
147 # Disable die on error.
148 set +e
149
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700150 if [[ -n "$STATEFUL_LOOP_DEV" ]]; then
151 cleanup_stateful_fs_loop
152 fi
153
154 if [[ -n "$LOOP_DEV" ]]; then
155 cleanup_rootfs_loop
156 fi
157
Bill Richardsona81df762010-04-09 08:12:05 -0700158 if [[ -n "$ESP_LOOP_DEV" ]]; then
Bill Richardson8b3bd102010-04-06 15:00:10 -0700159 cleanup_esp_loop
160 fi
161
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700162 # Turn die on error back on.
163 set -e
164}
165
Chris Sosabde8c1b2010-04-29 14:02:35 -0700166delete_prompt() {
167 echo "An error occurred in your build so your latest output directory" \
168 "is invalid."
169 read -p "Would you like to delete the output directory (y/N)? " SURE
170 SURE="${SURE:0:1}" # Get just the first character
171 if [ "${SURE}" == "y" ] ; then
172 sudo rm -rf "$OUTPUT_DIR"
173 echo "Deleted $OUTPUT_DIR"
174 else
175 echo "Not deleting $OUTPUT_DIR. Note dev server updates will not work" \
176 "until you successfully build another image or delete this directory"
177 fi
178}
179
Chris Sosa9673f3b2010-05-18 13:24:40 -0700180# $1 - Directory where developer rootfs is mounted.
181# $2 - Directory where developer stateful_partition is mounted.
182developer_cleanup() {
183 "$SCRIPTS_DIR/mount_gpt_image.sh" -u -r "$1" -s "$2"
184 delete_prompt
185}
186
187# Creates a new image based on $OUTPUT_IMG with additional developer packages.
188create_developer_image() {
189 local root_fs_dir="${OUTPUT_DIR}/rootfs_dev"
190 local root_fs_img="${OUTPUT_DIR}/rootfs_dev.image"
191 local output_img="${OUTPUT_DIR}/${DEVELOPER_IMAGE_NAME}"
192
193 # Create stateful partition of the same size as the rootfs.
194 local stateful_img="$OUTPUT_DIR/stateful_partition_dev.image"
195 local stateful_dir="$OUTPUT_DIR/stateful_partition_dev"
196
197 trap "developer_cleanup \"$root_fs_dir\" \"$stateful_dir\"" EXIT
198
199 # Mount a new copy of the base image.
200 echo "Creating developer image from base image $OUTPUT_IMG"
201 cp "$OUTPUT_IMG" "$output_img"
202 $SCRIPTS_DIR/mount_gpt_image.sh --from "$OUTPUT_DIR" \
203 --image "$DEVELOPER_IMAGE_NAME" -r "$root_fs_dir" -s "$stateful_dir"
204
205 # Determine the root dir for developer packages.
206 local root_dev_dir="$root_fs_dir"
207 [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] && \
208 root_dev_dir="$root_fs_dir/usr/local"
209
210 # Install developer packages described in chromeos-dev.
211 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
212 --root="$root_dev_dir" --root-deps=rdeps \
Anush Elangovanbb85f8f2010-05-27 11:00:57 -0700213 --usepkgonly chromeos-dev $EMERGE_JOBS
Chris Sosa9673f3b2010-05-18 13:24:40 -0700214
215 # Re-run ldconfig to fix /etc/ldconfig.so.cache.
216 sudo /sbin/ldconfig -r "$root_fs_dir"
217
218 # Mark the image as a developer image (input to chromeos_startup).
219 sudo mkdir -p "$root_fs_dir/root"
220 sudo touch "$root_fs_dir/root/.dev_mode"
221
222 # Additional changes to developer image.
223
224 # The ldd tool is a useful shell script but lives in glibc; just copy it.
225 sudo cp -a "$(which ldd)" "${root_dev_dir}/usr/bin"
226
Chris Sosab6895772010-05-25 17:47:51 -0700227 # TODO: Temporarily create fake xterm symlink until we do proper xinitrc
228 local aterm="$root_fs_dir/usr/local/bin/aterm"
229 if [[ -f "${aterm}" ]]; then
230 sudo chmod 0755 "$aterm"
231 sudo ln -s aterm "${root_fs_dir}/usr/local/bin/xterm"
232 fi
233
Chris Sosa9673f3b2010-05-18 13:24:40 -0700234 # If vim is installed, then a vi symlink would probably help.
Chris Sosab6895772010-05-25 17:47:51 -0700235 if [[ -x "${root_fs_dir}/usr/local/bin/vim" ]]; then
236 sudo ln -sf vim "${root_fs_dir}/usr/local/bin/vi"
Chris Sosa9673f3b2010-05-18 13:24:40 -0700237 fi
238
Girts Folkmanis7a8a8382010-05-18 22:52:25 -0700239 # Check that the image has been correctly created. Only do it if not
240 # building a factory install image, as the INSTALL_MASK for it will
241 # make test_image fail.
242 if [[ $FLAGS_factory_install -eq ${FLAGS_FALSE} ]] ; then
243 "${SCRIPTS_DIR}/test_image" \
244 --root="$root_fs_dir" \
245 --target="$ARCH"
246 fi
Chris Sosa9673f3b2010-05-18 13:24:40 -0700247
248 trap - EXIT
249 $SCRIPTS_DIR/mount_gpt_image.sh -u -r "$root_fs_dir" -s "$stateful_dir"
Chris Sosad4455022010-05-20 10:14:06 -0700250 sudo rm -rf "$root_fs_dir" "$stateful_dir"
Chris Sosa9673f3b2010-05-18 13:24:40 -0700251 echo "Developer image built and stored at $output_img"
252}
253
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700254# ${DEV_IMAGE_ROOT} specifies the location of where developer packages will
255# be installed on the stateful dir. On a Chromium OS system, this will
256# translate to /usr/local
257DEV_IMAGE_ROOT=
258
Chris Sosabde8c1b2010-04-29 14:02:35 -0700259trap "cleanup && delete_prompt" EXIT
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700260
261mkdir -p "$ROOT_FS_DIR"
262
263# Create and format the root file system.
264
265# Check for loop device before creating image.
266LOOP_DEV=$(sudo losetup -f)
267if [ -z "$LOOP_DEV" ] ; then
268 echo "No free loop device. Free up a loop device or reboot. exiting. "
269 exit 1
270fi
271
272# Create root file system disk image to fit on a 1GB memory stick.
273# 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 +0800274if [[ $FLAGS_factory_install -eq ${FLAGS_TRUE} ]] ; then
Girts Folkmanis7a8a8382010-05-18 22:52:25 -0700275 ROOT_SIZE_BYTES=$((1024 * 1024 * 300))
Tom Wai-Hong Tamf87a3672010-05-17 16:06:33 +0800276else
277 ROOT_SIZE_BYTES=$((1024 * 1024 * 720))
278fi
279
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700280dd if=/dev/zero of="$ROOT_FS_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1))
281sudo losetup "$LOOP_DEV" "$ROOT_FS_IMG"
282sudo mkfs.ext3 "$LOOP_DEV"
283
284# Tune and mount rootfs.
285UUID=$(uuidgen)
286DISK_LABEL="C-KEYFOB"
287sudo tune2fs -L "$DISK_LABEL" -U "$UUID" -c 0 -i 0 "$LOOP_DEV"
288sudo mount "$LOOP_DEV" "$ROOT_FS_DIR"
289
290# Create stateful partition of the same size as the rootfs.
291STATEFUL_IMG="$OUTPUT_DIR/stateful_partition.image"
292STATEFUL_DIR="$OUTPUT_DIR/stateful_partition"
293STATEFUL_LOOP_DEV=$(sudo losetup -f)
294if [ -z "$STATEFUL_LOOP_DEV" ] ; then
295 echo "No free loop device. Free up a loop device or reboot. exiting. "
296 exit 1
297fi
298dd if=/dev/zero of="$STATEFUL_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1))
299sudo losetup "$STATEFUL_LOOP_DEV" "$STATEFUL_IMG"
300sudo mkfs.ext3 "$STATEFUL_LOOP_DEV"
301sudo tune2fs -L "C-STATE" -U "$UUID" -c 0 -i 0 \
302 "$STATEFUL_LOOP_DEV"
303
304# Mount the stateful partition.
305mkdir -p "$STATEFUL_DIR"
306sudo mount "$STATEFUL_LOOP_DEV" "$STATEFUL_DIR"
307
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700308# Set dev image root now that we have mounted the stateful partition we created
309DEV_IMAGE_ROOT="$STATEFUL_DIR/dev_image"
310
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700311# Turn root file system into bootable image.
312if [[ "$ARCH" = "x86" ]]; then
313 # Setup extlinux configuration.
314 # TODO: For some reason the /dev/disk/by-uuid is not being generated by udev
315 # in the initramfs. When we figure that out, switch to root=UUID=$UUID.
316 sudo mkdir -p "$ROOT_FS_DIR"/boot
317 # TODO(adlr): use initramfs for booting.
318 cat <<EOF | sudo dd of="$ROOT_FS_DIR"/boot/extlinux.conf
319DEFAULT chromeos-usb
320PROMPT 0
321TIMEOUT 0
322
323label chromeos-usb
324 menu label chromeos-usb
325 kernel vmlinuz
326 append quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sdb3 ro noresume noswap i915.modeset=1 loglevel=1
327
328label chromeos-hd
329 menu label chromeos-hd
330 kernel vmlinuz
331 append quiet console=tty2 init=/sbin/init boot=local rootwait root=HDROOT ro noresume noswap i915.modeset=1 loglevel=1
332EOF
333
334 # Make partition bootable and label it.
335 sudo extlinux -z --install "${ROOT_FS_DIR}/boot"
336fi
337
338# -- Install packages into the root file system --
339
340# We need to install libc manually from the cross toolchain.
341# TODO: Improve this? We only want libc and not the whole toolchain.
342PKGDIR="/var/lib/portage/pkgs/cross/"
343sudo tar jxvpf \
344 "${PKGDIR}/${CHOST}/cross-${CHOST}"/glibc-${LIBC_VERSION}.tbz2 \
345 -C "$ROOT_FS_DIR" --strip-components=3 \
346 --exclude=usr/include --exclude=sys-include --exclude=*.a --exclude=*.o
347
348# We need to install libstdc++ manually from the cross toolchain.
349# TODO: Figure out a better way of doing this?
350sudo cp -a "${BOARD_ROOT}"/lib/libgcc_s.so* "${ROOT_FS_DIR}/lib"
351sudo cp -a "${BOARD_ROOT}"/usr/lib/libstdc++.so* "${ROOT_FS_DIR}/usr/lib"
352
353INSTALL_MASK=""
Chris Sosa3d9a10b2010-04-13 15:00:46 -0700354if [[ $FLAGS_installmask -eq ${FLAGS_TRUE} ]] ; then
Chris Sosaaa1a7fd2010-04-02 14:06:29 -0700355 INSTALL_MASK="$DEFAULT_INSTALL_MASK"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700356fi
357
Tom Wai-Hong Tamf87a3672010-05-17 16:06:33 +0800358# Reduce the size of factory install shim.
359# TODO: Build a separated ebuild for the factory install shim to reduce size.
360if [[ $FLAGS_factory_install -eq ${FLAGS_TRUE} ]] ; then
361 INSTALL_MASK="$INSTALL_MASK $FACTORY_INSTALL_MASK"
362fi
363
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700364if [[ $FLAGS_jobs -ne -1 ]]; then
365 EMERGE_JOBS="--jobs=$FLAGS_jobs"
366fi
367
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700368# Prepare stateful partition with some pre-created directories
369sudo mkdir -p "${DEV_IMAGE_ROOT}"
370sudo mkdir -p "${STATEFUL_DIR}/var"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700371
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700372# Create symlinks so that /usr/local/usr based directories are symlinked to
373# /usr/local/ directories e.g. /usr/local/usr/bin -> /usr/local/bin, etc.
Chris Sosa702618f2010-05-14 12:52:32 -0700374setup_symlinks_on_root "${DEV_IMAGE_ROOT}" "${STATEFUL_DIR}/var" \
375 "${STATEFUL_DIR}"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700376
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700377# Perform binding rather than symlinking because directories must exist
378# on rootfs so that we can bind at run-time since rootfs is read-only
379echo "Binding directories from stateful partition onto the rootfs"
380sudo mkdir -p "${ROOT_FS_DIR}/usr/local"
381sudo mount --bind "${DEV_IMAGE_ROOT}" "${ROOT_FS_DIR}/usr/local"
382sudo mkdir -p "${ROOT_FS_DIR}/var"
383sudo mount --bind "${STATEFUL_DIR}/var" "${ROOT_FS_DIR}/var"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700384
385# We "emerge --root=$ROOT_FS_DIR --root-deps=rdeps --usepkgonly" all of the
386# runtime packages for chrome os. This builds up a chrome os image from binary
387# packages with runtime dependencies only. We use INSTALL_MASK to trim the
388# image size as much as possible.
Ken Mixterd5c4b172010-04-16 10:11:02 -0700389sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700390 --root="$ROOT_FS_DIR" --root-deps=rdeps \
Anush Elangovanbb85f8f2010-05-27 11:00:57 -0700391 --usepkgonly chromeos $EMERGE_JOBS
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700392
Bill Richardson8b3bd102010-04-06 15:00:10 -0700393# Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI
394# BIOS). We only need this for x86, but it's simpler and safer to keep the disk
395# images the same for both x86 and ARM.
396ESP_IMG=${OUTPUT_DIR}/esp.image
397# NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. We'll hard-code
398# it to 16M for now.
399ESP_BLOCKS=16384
400/usr/sbin/mkfs.vfat -C ${OUTPUT_DIR}/esp.image ${ESP_BLOCKS}
401ESP_DIR=${OUTPUT_DIR}/esp
Bill Richardsona81df762010-04-09 08:12:05 -0700402ESP_LOOP_DEV=$(sudo losetup -f)
403if [ -z "$ESP_LOOP_DEV" ] ; then
404 echo "No free loop device. Free up a loop device or reboot. exiting. "
405 exit 1
406fi
407mkdir -p "${ESP_DIR}"
408sudo losetup "${ESP_LOOP_DEV}" "${ESP_IMG}"
409sudo mount "${ESP_LOOP_DEV}" "${ESP_DIR}"
410sudo mkdir -p "${ESP_DIR}/efi/boot"
411sudo grub-mkimage -p /efi/boot -o "${ESP_DIR}/efi/boot/bootx64.efi" \
Bill Richardson8b3bd102010-04-06 15:00:10 -0700412 part_gpt fat ext2 normal boot sh chain configfile linux
Bill Richardson9c5e5ec2010-05-14 17:00:21 -0700413cat <<'EOF' | sudo dd of="${ESP_DIR}/efi/boot/grub.cfg"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700414set default=0
Bill Richardson9c5e5ec2010-05-14 17:00:21 -0700415set timeout=2
Bill Richardson8b3bd102010-04-06 15:00:10 -0700416
Bill Richardson9c5e5ec2010-05-14 17:00:21 -0700417# NOTE: These magic grub variables are a Chrome OS hack. They are not portable.
418
419menuentry "local image A" {
420 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 -0700421}
422
Bill Richardson9c5e5ec2010-05-14 17:00:21 -0700423menuentry "local image B" {
424 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 -0700425}
426
Bill Richardson8b3bd102010-04-06 15:00:10 -0700427EOF
428
Bill Richardson67956222010-05-28 15:38:56 -0700429# Legacy BIOS will use the kernel in the rootfs (via syslinux), as will
430# standard EFI BIOS (via grub, from the EFI System Partition). Chrome OS BIOS
431# will use a separate signed kernel partition, which we'll create now.
432# FIXME: remove serial output, debugging messages
433cat <<'EOF' > "${OUTPUT_DIR}/config.txt"
434earlyprintk=serial,ttyS0,115200
435console=ttyS0,115200
436init=/sbin/init
437add_efi_memmap
438boot=local
439rootwait
440root=/dev/sd%D%P
441ro
442noresume
443noswap
444i915.modeset=1
445loglevel=7
446Hi_Mom
447EOF
448
449# FIXME: We need to specify the real keys and certs here!
450SIG_DIR="${SRC_ROOT}/platform/vboot_reference/tests/testkeys"
451
452# Create the kernel partition image.
453kernel_utility --generate \
454 --firmware_key "${SIG_DIR}/key_rsa4096.pem" \
455 --kernel_key "${SIG_DIR}/key_rsa1024.pem" \
456 --kernel_key_pub "${SIG_DIR}/key_rsa1024.keyb" \
457 --firmware_sign_algorithm 8 \
458 --kernel_sign_algorithm 2 \
459 --kernel_key_version 1 \
460 --kernel_version 1 \
461 --config "${OUTPUT_DIR}/config.txt" \
462 --bootloader /lib64/bootstub/bootstub.efi \
463 --vmlinuz "${ROOT_FS_DIR}/boot/vmlinuz" \
464 --out "${OUTPUT_DIR}/vmlinuz.image"
465
Chris Sosa3f21b992010-05-10 16:34:47 -0700466# Perform any customizations on the root file system that are needed.
Chris Sosa503efe12010-04-08 10:05:46 -0700467"${SCRIPTS_DIR}/customize_rootfs" \
468 --root="$ROOT_FS_DIR" \
469 --target="$ARCH" \
Chris Sosa3f21b992010-05-10 16:34:47 -0700470 --board="$BOARD"
Chris Sosa503efe12010-04-08 10:05:46 -0700471
Tom Wai-Hong Tamf87a3672010-05-17 16:06:33 +0800472# Don't test the factory install shim.
473if [[ $FLAGS_factory_install -eq ${FLAGS_FALSE} ]] ; then
474 # Check that the image has been correctly created.
475 "${SCRIPTS_DIR}/test_image" \
476 --root="$ROOT_FS_DIR" \
477 --target="$ARCH"
478fi
Chris Sosa503efe12010-04-08 10:05:46 -0700479
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700480# Clean up symlinks so they work on a running target rooted at "/".
481# Here development packages are rooted at /usr/local. However, do not
482# create /usr/local or /var on host (already exist on target).
Chris Sosa702618f2010-05-14 12:52:32 -0700483setup_symlinks_on_root "/usr/local" "/var" "${STATEFUL_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700484
485# Cleanup loop devices.
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700486cleanup
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700487
Chris Sosabde8c1b2010-04-29 14:02:35 -0700488trap delete_prompt EXIT
489
Tan Gao6df5aee2010-05-19 14:19:55 -0700490RECOVERY="--norecovery"
491if [[ ${FLAGS_recovery} -eq $FLAGS_TRUE ]]; then
492 RECOVERY="--recovery"
493fi
494
Bill Richardson4364a2e2010-03-30 14:17:34 -0700495# Create the GPT-formatted image
496${SCRIPTS_DIR}/build_gpt.sh \
robotboyb75eee32010-04-30 09:51:23 -0700497 --arch=${ARCH} \
498 --board=${FLAGS_board} \
499 --arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \
Tan Gao6df5aee2010-05-19 14:19:55 -0700500 ${RECOVERY} \
robotboyb75eee32010-04-30 09:51:23 -0700501 "${OUTPUT_DIR}" \
502 "${OUTPUT_IMG}"
Bill Richardson4364a2e2010-03-30 14:17:34 -0700503
Bill Richardson6dcea162010-03-31 19:20:24 -0700504# Clean up temporary files.
Bill Richardson8b3bd102010-04-06 15:00:10 -0700505rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \
506 "${ESP_IMG}"
507rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" "${ESP_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700508
509OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}"
Chris Sosa9673f3b2010-05-18 13:24:40 -0700510
511# Create a developer image based on the chromium os base image
512[ "$FLAGS_withdev" -eq "$FLAGS_TRUE" ] && create_developer_image
513trap - EXIT
514
Bill Richardson67956222010-05-28 15:38:56 -0700515# be quiet again
516set +x
517
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700518echo "Done. Image created in ${OUTPUT_DIR}"
Chris Sosa9673f3b2010-05-18 13:24:40 -0700519echo "Chromium OS image created as $PRISTINE_IMAGE_NAME"
520if [ "$FLAGS_withdev" -eq "$FLAGS_TRUE" ]; then
521 echo "Developer image created as $DEVELOPER_IMAGE_NAME"
522fi
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700523echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:"
Daniel Eratdd9818a2010-04-26 09:16:44 -0700524echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700525echo "To convert to VMWare image, OUTSIDE the chroot, do something like:"
526echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}"
527echo "from the scripts directory where you entered the chroot."