blob: 8d0e7ccdd14d54d92fecb0e80a7fcd6b451a1921 [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
Will Drewry4a675e12010-07-03 13:35:02 -050016. "$(dirname "$0")/chromeos-common.sh" # for partoffset
17locate_gpt
18
Bill Richardsonc09b94f2010-03-15 11:40:30 -070019# Script must be run inside the chroot.
Don Garrett640a0582010-05-04 16:54:28 -070020restart_in_chroot_if_needed $*
Bill Richardsonc09b94f2010-03-15 11:40:30 -070021
22get_default_board
23
24# Flags.
Don Garrette0020b12010-06-17 15:55:35 -070025DEFINE_string board "${DEFAULT_BOARD}" \
Bill Richardsonc09b94f2010-03-15 11:40:30 -070026 "The board to build an image for."
27DEFINE_string build_root "/build" \
28 "The root location for board sysroots."
29DEFINE_integer build_attempt 1 \
30 "The build attempt for this image build."
31DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/images" \
32 "Directory in which to place image result directories (named by version)"
Don Garrette0020b12010-06-17 15:55:35 -070033DEFINE_boolean replace ${FLAGS_FALSE} \
Bill Richardsonc09b94f2010-03-15 11:40:30 -070034 "Overwrite existing output, if any."
Don Garrette0020b12010-06-17 15:55:35 -070035DEFINE_boolean withdev ${FLAGS_TRUE} \
Bill Richardsonc09b94f2010-03-15 11:40:30 -070036 "Include useful developer friendly utilities in the image."
Don Garrette0020b12010-06-17 15:55:35 -070037DEFINE_boolean installmask ${FLAGS_TRUE} \
Bill Richardsonc09b94f2010-03-15 11:40:30 -070038 "Use INSTALL_MASK to shrink the resulting image."
39DEFINE_integer jobs -1 \
40 "How many packages to build in parallel at maximum."
Don Garrette0020b12010-06-17 15:55:35 -070041DEFINE_boolean statefuldev ${FLAGS_TRUE} \
Chris Sosa4bffb8b2010-04-07 17:23:54 -070042 "Install development packages on stateful partition rather than the rootfs"
Antoine Laboure9e585f2010-04-01 15:57:57 -070043DEFINE_string to "" \
44 "The target image file or device"
Don Garrette0020b12010-06-17 15:55:35 -070045DEFINE_boolean factory_install ${FLAGS_FALSE} \
Tom Wai-Hong Tamf87a3672010-05-17 16:06:33 +080046 "Build a smaller image to overlay the factory install shim on; this argument \
47is also required in image_to_usb."
robotboyb75eee32010-04-30 09:51:23 -070048DEFINE_string arm_extra_bootargs "" \
49 "Additional command line options to pass to the ARM kernel."
Zelidrag Hornung1d12c1a2010-06-02 10:20:29 -070050DEFINE_integer rootfs_partition_size 1024 \
51 "rootfs parition size in MBs."
52DEFINE_integer rootfs_size 720 \
53 "rootfs filesystem size in MBs."
Eric Li5cf288f2010-06-28 12:46:26 -070054DEFINE_integer statefulfs_size 1024 \
55 "stateful filesystem size in MBs."
David James868d7bb2010-06-24 21:48:14 -070056DEFINE_boolean preserve ${FLAGS_FALSE} \
57 "Attempt to preserve the previous build image if one can be found (unstable, \
58kernel/firmware not updated)"
Nick Sandersf2dee6c2010-07-01 00:21:32 -070059DEFINE_boolean fast ${FLAGS_FALSE} \
60 "Call many emerges in parallel (unstable)"
61
Will Drewry4a675e12010-07-03 13:35:02 -050062DEFINE_string usb_disk /dev/sdb3 \
63 "Path syslinux should use to do a usb boot. Default: /dev/sdb3"
64
Will Drewry1670d482010-07-09 13:08:38 -070065DEFINE_boolean enable_rootfs_verification ${FLAGS_FALSE} \
66 "Default all bootloaders to use kernel-based root fs integrity checking."
67DEFINE_integer verity_error_behavior 2 \
68 "Kernel verified boot error behavior (0: I/O errors, 1: reboot, 2: nothing) \
Will Drewry4a675e12010-07-03 13:35:02 -050069Default: 2"
Will Drewry1670d482010-07-09 13:08:38 -070070DEFINE_integer verity_depth 1 \
71 "Kernel verified boot hash tree depth. Default: 1"
72DEFINE_integer verity_max_ios 1024 \
Will Drewry4a675e12010-07-03 13:35:02 -050073 "Number of outstanding I/O operations dm-verity caps at. Default: 1024"
Will Drewry1670d482010-07-09 13:08:38 -070074DEFINE_string verity_algorithm "sha1" \
75 "Cryptographic hash algorithm used for kernel vboot. Default : sha1"
Bill Richardsonc09b94f2010-03-15 11:40:30 -070076
Denis Romanov95bdf472010-07-12 22:44:42 +040077DEFINE_string oem_customization \
78 "$GCLIENT_ROOT/src/platform/assets/oem_customization" \
79 "Path to directory containing OEM partner partition contents"
80
Bill Richardsonc09b94f2010-03-15 11:40:30 -070081# Parse command line.
82FLAGS "$@" || exit 1
83eval set -- "${FLAGS_ARGV}"
84
85# Only now can we die on error. shflags functions leak non-zero error codes,
86# so will die prematurely if 'set -e' is specified before now.
87set -e
88
Don Garrette0020b12010-06-17 15:55:35 -070089if [ -z "${FLAGS_board}" ] ; then
Bill Richardsonc09b94f2010-03-15 11:40:30 -070090 error "--board is required."
91 exit 1
92fi
93
Don Garrette0020b12010-06-17 15:55:35 -070094if [ "${FLAGS_rootfs_size}" -gt "${FLAGS_rootfs_partition_size}" ] ; then
Zelidrag Hornung1d12c1a2010-06-02 10:20:29 -070095 error "rootfs (${FLAGS_rootfs_size} MB) is bigger than partition (${FLAGS_rootfs_partition_size} MB)."
96 exit 1
97fi
98
Nick Sanders8ab729a2010-06-16 03:15:17 -070099EMERGE_BOARD_CMD="emerge-${FLAGS_board}"
Nick Sandersf2dee6c2010-07-01 00:21:32 -0700100if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then
Nick Sanders8ab729a2010-06-16 03:15:17 -0700101 echo "Using alternate emerge"
Nick Sandersf2dee6c2010-07-01 00:21:32 -0700102 EMERGE_BOARD_CMD="${SCRIPTS_DIR}/parallel_emerge --board=${FLAGS_board}"
Nick Sanders8ab729a2010-06-16 03:15:17 -0700103fi
104
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700105# Determine build version.
106. "${SCRIPTS_DIR}/chromeos_version.sh"
107
108# Use canonical path since some tools (e.g. mount) do not like symlinks.
109# Append build attempt to output directory.
110IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}"
111OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}"
Don Garrett3f41e152010-06-21 14:54:34 -0700112
113OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}"
Chris Sosa9673f3b2010-05-18 13:24:40 -0700114
115# If we are creating a developer image, also create a pristine image with a
116# different name.
117DEVELOPER_IMAGE_NAME=
118PRISTINE_IMAGE_NAME=chromiumos_image.bin
Don Garrette0020b12010-06-17 15:55:35 -0700119if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then
Chris Sosa9673f3b2010-05-18 13:24:40 -0700120 PRISTINE_IMAGE_NAME=chromiumos_base_image.bin
121 DEVELOPER_IMAGE_NAME=chromiumos_image.bin
122fi
Tan Gaoa40ed442010-06-02 15:45:19 -0700123
David James868d7bb2010-06-24 21:48:14 -0700124PRISTINE_IMG="${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}"
125DEVELOPER_IMG="${OUTPUT_DIR}/${DEVELOPER_IMAGE_NAME}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700126
127BOARD="${FLAGS_board}"
128BOARD_ROOT="${FLAGS_build_root}/${BOARD}"
129
Don Garrett3f41e152010-06-21 14:54:34 -0700130ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image"
131ROOT_FS_DIR="${OUTPUT_DIR}/rootfs"
Will Drewry4a675e12010-07-03 13:35:02 -0500132ROOT_FS_HASH="${OUTPUT_DIR}/rootfs.hash"
Don Garrett3f41e152010-06-21 14:54:34 -0700133
134STATEFUL_FS_IMG="${OUTPUT_DIR}/stateful_partition.image"
135STATEFUL_FS_DIR="${OUTPUT_DIR}/stateful_partition"
136
Denis Romanov11061542010-06-29 04:23:53 +0400137OEM_FS_IMG="${OUTPUT_DIR}/partner_partition.image"
138OEM_FS_DIR="${OUTPUT_DIR}/partner_partition"
139
Don Garrett3f41e152010-06-21 14:54:34 -0700140ESP_FS_IMG=${OUTPUT_DIR}/esp.image
141ESP_FS_DIR=${OUTPUT_DIR}/esp
142
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700143LOOP_DEV=
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700144STATEFUL_LOOP_DEV=
Denis Romanov11061542010-06-29 04:23:53 +0400145OEM_LOOP_DEV=
Bill Richardsona81df762010-04-09 08:12:05 -0700146ESP_LOOP_DEV=
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700147
Don Garrett3f41e152010-06-21 14:54:34 -0700148# ${DEV_IMAGE_ROOT} specifies the location of where developer packages will
149# be installed on the stateful dir. On a Chromium OS system, this will
150# translate to /usr/local.
151DEV_IMAGE_ROOT="${STATEFUL_FS_DIR}/dev_image"
152
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700153# What cross-build are we targeting?
154. "${BOARD_ROOT}/etc/make.conf.board_setup"
155LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"}
156
Don Garrett3f41e152010-06-21 14:54:34 -0700157INSTALL_MASK=""
158if [[ ${FLAGS_installmask} -eq ${FLAGS_TRUE} ]] ; then
159 INSTALL_MASK="${DEFAULT_INSTALL_MASK}"
160fi
161
162# Reduce the size of factory install shim.
163# TODO: Build a separated ebuild for the factory install shim to reduce size.
164if [[ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]] ; then
165 INSTALL_MASK="${INSTALL_MASK} ${FACTORY_INSTALL_MASK}"
166fi
167
David Jamesfd7403a2010-07-09 12:00:17 -0700168if [[ ${FLAGS_jobs} -ne -1 ]]; then
169 EMERGE_JOBS="--jobs=${FLAGS_jobs}"
170fi
171
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700172# Figure out ARCH from the given toolchain.
173# TODO: Move to common.sh as a function after scripts are switched over.
Don Garrette0020b12010-06-17 15:55:35 -0700174TC_ARCH=$(echo "${CHOST}" | awk -F'-' '{ print $1 }')
175case "${TC_ARCH}" in
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700176 arm*)
177 ARCH="arm"
178 ;;
179 *86)
180 ARCH="x86"
181 ;;
182 *)
Don Garrette0020b12010-06-17 15:55:35 -0700183 error "Unable to determine ARCH from toolchain: ${CHOST}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700184 exit 1
185esac
186
187# Hack to fix bug where x86_64 CHOST line gets incorrectly added.
188# ToDo(msb): remove this hack.
189PACKAGES_FILE="${BOARD_ROOT}/packages/Packages"
190sudo sed -e "s/CHOST: x86_64-pc-linux-gnu//" -i "${PACKAGES_FILE}"
191
192# Handle existing directory.
Don Garrette0020b12010-06-17 15:55:35 -0700193if [[ -e "${OUTPUT_DIR}" ]]; then
194 if [[ ${FLAGS_replace} -eq ${FLAGS_TRUE} ]]; then
195 sudo rm -rf "${OUTPUT_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700196 else
Don Garrette0020b12010-06-17 15:55:35 -0700197 echo "Directory ${OUTPUT_DIR} already exists."
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700198 echo "Use --build_attempt option to specify an unused attempt."
199 echo "Or use --replace if you want to overwrite this directory."
200 exit 1
201 fi
202fi
203
David James868d7bb2010-06-24 21:48:14 -0700204# Find previous build, if any...
205PREVIOUS_DIR=$($SCRIPTS_DIR/get_latest_image.sh --board="$BOARD")
206
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700207cleanup_rootfs_loop() {
Don Garrette0020b12010-06-17 15:55:35 -0700208 sudo umount -d "${ROOT_FS_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700209}
210
211cleanup_stateful_fs_loop() {
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700212 sudo umount "${ROOT_FS_DIR}/usr/local"
213 sudo umount "${ROOT_FS_DIR}/var"
Don Garrett3f41e152010-06-21 14:54:34 -0700214 sudo umount -d "${STATEFUL_FS_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700215}
216
Denis Romanov11061542010-06-29 04:23:53 +0400217cleanup_oem_fs_loop() {
218 sudo umount -d "${OEM_FS_DIR}"
219}
220
221
Bill Richardson8b3bd102010-04-06 15:00:10 -0700222cleanup_esp_loop() {
Don Garrett3f41e152010-06-21 14:54:34 -0700223 sudo umount -d "${ESP_FS_DIR}"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700224}
225
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700226cleanup() {
227 # Disable die on error.
228 set +e
229
Don Garrette0020b12010-06-17 15:55:35 -0700230 if [[ -n "${STATEFUL_LOOP_DEV}" ]]; then
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700231 cleanup_stateful_fs_loop
Will Drewry4a675e12010-07-03 13:35:02 -0500232 STATEFUL_LOOP_DEV=
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700233 fi
234
Denis Romanov11061542010-06-29 04:23:53 +0400235 if [[ -n "${OEM_LOOP_DEV}" ]]; then
236 cleanup_oem_fs_loop
237 fi
238
Don Garrette0020b12010-06-17 15:55:35 -0700239 if [[ -n "${LOOP_DEV}" ]]; then
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700240 cleanup_rootfs_loop
Will Drewry4a675e12010-07-03 13:35:02 -0500241 LOOP_DEV=
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700242 fi
243
Don Garrette0020b12010-06-17 15:55:35 -0700244 if [[ -n "${ESP_LOOP_DEV}" ]]; then
Bill Richardson8b3bd102010-04-06 15:00:10 -0700245 cleanup_esp_loop
Will Drewry4a675e12010-07-03 13:35:02 -0500246 ESP_LOOP_DEV=
Bill Richardson8b3bd102010-04-06 15:00:10 -0700247 fi
248
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700249 # Turn die on error back on.
250 set -e
251}
252
Chris Sosabde8c1b2010-04-29 14:02:35 -0700253delete_prompt() {
254 echo "An error occurred in your build so your latest output directory" \
255 "is invalid."
256 read -p "Would you like to delete the output directory (y/N)? " SURE
Don Garrette0020b12010-06-17 15:55:35 -0700257 SURE="${SURE:0:1}" # Get just the first character.
Chris Sosabde8c1b2010-04-29 14:02:35 -0700258 if [ "${SURE}" == "y" ] ; then
Don Garrette0020b12010-06-17 15:55:35 -0700259 sudo rm -rf "${OUTPUT_DIR}"
260 echo "Deleted ${OUTPUT_DIR}"
Chris Sosabde8c1b2010-04-29 14:02:35 -0700261 else
Don Garrette0020b12010-06-17 15:55:35 -0700262 echo "Not deleting ${OUTPUT_DIR}. Note dev server updates will not work" \
Chris Sosabde8c1b2010-04-29 14:02:35 -0700263 "until you successfully build another image or delete this directory"
264 fi
265}
266
Chris Sosa9673f3b2010-05-18 13:24:40 -0700267# $1 - Directory where developer rootfs is mounted.
268# $2 - Directory where developer stateful_partition is mounted.
Will Drewry4a675e12010-07-03 13:35:02 -0500269# $3 - Directory where the ESP partition is mounted.
Don Garrett3f41e152010-06-21 14:54:34 -0700270mount_gpt_cleanup() {
Will Drewry4a675e12010-07-03 13:35:02 -0500271 local rootfs="${1-$ROOT_FS_DIR}"
272 local statefs="${2-$STATEFUL_FS_DIR}"
273 local espfs="${3-$ESP_FS_DIR}"
274 "${SCRIPTS_DIR}/mount_gpt_image.sh" \
275 -u -r "${rootfs}" -s "${statefs}" -e "${espfs}"
Chris Sosa9673f3b2010-05-18 13:24:40 -0700276 delete_prompt
277}
278
Will Drewry4a675e12010-07-03 13:35:02 -0500279make_image_bootable() {
280 local image_name="$1"
281 cros_root=/dev/sd%D%P
282 if [[ "${ARCH}" = "arm" ]]; then
283 # TODO(wad) assumed like in build_gpt for now.
284 cros_root=/dev/mmcblk1p3
285 fi
Will Drewry1670d482010-07-09 13:08:38 -0700286 if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then
Will Drewry4a675e12010-07-03 13:35:02 -0500287 cros_root=/dev/dm-0
288 fi
289
290 # TODO(wad) mount the root fs to LOOP_DEV from the image
291 trap "mount_gpt_cleanup" EXIT
292 ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \
293 --image "${image_name}" -r "${ROOT_FS_DIR}" \
294 -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}"
295
296 sudo mount -o remount,ro "${ROOT_FS_DIR}"
297 root_dev=$(mount | grep -- "${ROOT_FS_DIR}" | cut -f1 -d' ' | tail -1)
298
Mandeep Singh Baines87b16942010-07-09 20:52:41 -0700299 DEVKEYSDIR="/usr/share/vboot/devkeys"
Louis Yung-Chieh Lo36020402010-07-05 13:23:34 +0800300
Will Drewry4a675e12010-07-03 13:35:02 -0500301 # Builds the kernel partition image. The temporary files are kept around
302 # so that we can perform a load_kernel_test later on the final image.
303 ${SCRIPTS_DIR}/build_kernel_image.sh \
304 --arch="${ARCH}" \
305 --to="${OUTPUT_DIR}/vmlinuz.image" \
Louis Yung-Chieh Lo36020402010-07-05 13:23:34 +0800306 --hd_vblock="${OUTPUT_DIR}/vmlinuz_hd.vblock" \
Will Drewry4a675e12010-07-03 13:35:02 -0500307 --vmlinuz="${OUTPUT_DIR}/boot/vmlinuz" \
308 --working_dir="${OUTPUT_DIR}" \
309 --keep_work \
310 --rootfs_image=${root_dev} \
311 --rootfs_hash=${OUTPUT_DIR}/rootfs.hash \
Will Drewry1670d482010-07-09 13:08:38 -0700312 --verity_hash_alg=${FLAGS_verity_algorithm} \
313 --verity_tree_depth=${FLAGS_verity_depth} \
314 --verity_max_ios=${FLAGS_verity_max_ios} \
315 --verity_error_behavior=${FLAGS_verity_error_behavior} \
Will Drewry4a675e12010-07-03 13:35:02 -0500316 --root=${cros_root} \
Louis Yung-Chieh Lo36020402010-07-05 13:23:34 +0800317 --keys_dir="${DEVKEYSDIR}"
Will Drewry4a675e12010-07-03 13:35:02 -0500318
Louis Yung-Chieh Loca1c2b02010-07-05 17:37:05 +0800319 # Move the verification block needed for the hard disk install to the
320 # stateful partition. Mount stateful fs, copy file, and umount fs.
321 # In original CL: http://codereview.chromium.org/2868044, this was done in
322 # create_base_image(). However, it could break the build if it is a clean
323 # build because vmlinuz_hd.vblock hasn't been created by build_kernel_image.sh
Louis Yung-Chieh Lo85d49fc2010-07-05 22:55:31 +0800324 if [[ "${ARCH}" = "x86" ]]; then
Louis Yung-Chieh Lo85d49fc2010-07-05 22:55:31 +0800325 sudo cp "${OUTPUT_DIR}/vmlinuz_hd.vblock" "${STATEFUL_FS_DIR}"
Louis Yung-Chieh Loca1c2b02010-07-05 17:37:05 +0800326 fi
Louis Yung-Chieh Loca1c2b02010-07-05 17:37:05 +0800327
Will Drewry4a675e12010-07-03 13:35:02 -0500328 # START_KERN_A is set by the first call to install the gpt.
329 local koffset="$(partoffset ${OUTPUT_DIR}/${image_name} 2)"
330 sudo dd if="${OUTPUT_DIR}/vmlinuz.image" of="${OUTPUT_DIR}/${image_name}" \
331 conv=notrunc bs=512 seek=${koffset}
332
Will Drewry07e35052010-07-09 14:50:42 -0700333 # Update the bootloaders. For legacy/efi x86, the EFI system partition
334 # will be updated and for arm, the mbr will be updated (for u-boot).
Will Drewry4a675e12010-07-03 13:35:02 -0500335 local kernel_part="--kernel_partition='${OUTPUT_DIR}/vmlinuz.image'"
Will Drewry07e35052010-07-09 14:50:42 -0700336 kernel_part="${kernel_part} --install_syslinux"
Will Drewry4a675e12010-07-03 13:35:02 -0500337 local bootloader_to="${ESP_FS_IMG}"
338 local usb_disk="${FLAGS_usb_disk}"
339 local bootloader_to="$(mount | grep ${ESP_FS_DIR} | cut -f1 -d' ')"
340 if [[ "${ARCH}" == "arm" ]]; then
341 # TODO(wad) mmcblk1p3 is hardcoded for arm for now!
342 usb_disk="/dev/mmcblk1p3"
Will Drewry82780e52010-07-03 18:27:10 -0700343 kernel_part="--kernel_cmdline=\"${FLAGS_arm_extra_bootargs}\" "
344 # TODO(wad) Integrate dmtable extraction into the arm build
345 # E.g. $(cat ${OUTPUT_DIR}/boot.config | tr -s '\n' ' ')"
Will Drewry4a675e12010-07-03 13:35:02 -0500346 local kpart_offset="--kernel_partition_offset=${koffset}"
Will Drewry82780e52010-07-03 18:27:10 -0700347 local kpart_size="--kernel_partition_sectors="
348 kpart_size="${kpart_size}$(partsize ${OUTPUT_DIR}/${image_name} 2)"
Will Drewry4a675e12010-07-03 13:35:02 -0500349 kernel_part="${kernel_part} ${kpart_size} ${kpart_offset}"
Will Drewry82780e52010-07-03 18:27:10 -0700350 info "Using addition bootloader arguments: ${kernel_part}"
Will Drewry4a675e12010-07-03 13:35:02 -0500351 bootloader_to="${OUTPUT_DIR}/arm.mbr"
352 fi
353
354 # Update partition 12 / legacy bootloaders and arm.
355 ${SCRIPTS_DIR}/update_bootloaders.sh \
356 --arch=${ARCH} \
357 --to="${bootloader_to}" \
358 --from="${OUTPUT_DIR}"/boot \
359 --vmlinuz="${OUTPUT_DIR}"/boot/vmlinuz \
360 --usb_disk="${usb_disk}" \
361 $kernel_part
362
363 if [[ "${ARCH}" == "arm" ]]; then
364 sudo dd bs=1 conv=notrunc if="${bootloader_to}" \
365 of="${OUTPUT_DIR}/${image_name}"
366 sudo rm "${bootloader_to}"
367 fi
368
369 trap - EXIT
370 ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \
371 -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}"
372}
373
Don Garrett3f41e152010-06-21 14:54:34 -0700374# Modifies an existing image to add development packages
375update_dev_packages() {
376 local image_name=$1
Chris Sosa9673f3b2010-05-18 13:24:40 -0700377
Don Garrett3f41e152010-06-21 14:54:34 -0700378 echo "Adding developer packages to ${image_name}"
Chris Sosa9673f3b2010-05-18 13:24:40 -0700379
Will Drewry4a675e12010-07-03 13:35:02 -0500380 trap "mount_gpt_cleanup" EXIT
Tan Gaoa40ed442010-06-02 15:45:19 -0700381
Don Garrette0020b12010-06-17 15:55:35 -0700382 ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \
David James868d7bb2010-06-24 21:48:14 -0700383 --image "${image_name}" -r "${ROOT_FS_DIR}" \
Will Drewry4a675e12010-07-03 13:35:02 -0500384 -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}"
Chris Sosa9673f3b2010-05-18 13:24:40 -0700385
Don Garrett3f41e152010-06-21 14:54:34 -0700386 # Determine the root dir for developer packages.
387 local root_dev_dir="${ROOT_FS_DIR}"
388 [ ${FLAGS_statefuldev} -eq ${FLAGS_TRUE} ] && \
389 root_dev_dir="${ROOT_FS_DIR}/usr/local"
Chris Sosa9673f3b2010-05-18 13:24:40 -0700390
Don Garrett3f41e152010-06-21 14:54:34 -0700391 # Install developer packages described in chromeos-dev.
392 sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \
393 --root="${root_dev_dir}" --root-deps=rdeps \
David James868d7bb2010-06-24 21:48:14 -0700394 --usepkg -uDNv chromeos-dev ${EMERGE_JOBS}
395
396 if [[ $FLAGS_preserve -eq ${FLAGS_TRUE} ]] ; then
397 # Clean out unused packages
398 sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \
399 --root="${ROOT_FS_DIR}" --root-deps=rdeps \
400 --usepkg --depclean ${EMERGE_JOBS}
401 fi
Chris Sosa9673f3b2010-05-18 13:24:40 -0700402
403 # Re-run ldconfig to fix /etc/ldconfig.so.cache.
Don Garrett3f41e152010-06-21 14:54:34 -0700404 sudo /sbin/ldconfig -r "${ROOT_FS_DIR}"
Chris Sosa9673f3b2010-05-18 13:24:40 -0700405
406 # Mark the image as a developer image (input to chromeos_startup).
Don Garrett3f41e152010-06-21 14:54:34 -0700407 sudo mkdir -p "${ROOT_FS_DIR}/root"
408 sudo touch "${ROOT_FS_DIR}/root/.dev_mode"
Chris Sosa9673f3b2010-05-18 13:24:40 -0700409
Don Garrett3f41e152010-06-21 14:54:34 -0700410 # Additional changes to developer image.
Chris Sosa9673f3b2010-05-18 13:24:40 -0700411
Don Garrett3f41e152010-06-21 14:54:34 -0700412 # The ldd tool is a useful shell script but lives in glibc; just copy it.
413 sudo cp -a "$(which ldd)" "${root_dev_dir}/usr/bin"
Chris Sosa9673f3b2010-05-18 13:24:40 -0700414
Don Garrett3f41e152010-06-21 14:54:34 -0700415 # If vim is installed, then a vi symlink would probably help.
416 if [[ -x "${ROOT_FS_DIR}/usr/local/bin/vim" ]]; then
417 sudo ln -sf vim "${ROOT_FS_DIR}/usr/local/bin/vi"
Girts Folkmanis7a8a8382010-05-18 22:52:25 -0700418 fi
Chris Sosa9673f3b2010-05-18 13:24:40 -0700419
Tammo Spalinkcfc0c642010-07-07 10:51:21 +0800420 # If pygtk is installed in stateful-dev, then install a path.
421 if [[ -d \
422 "${ROOT_FS_DIR}/usr/local/lib/python2.6/site-packages/gtk-2.0" ]]; then
423 sudo bash -c "\
424 echo gtk-2.0 > \
425 ${ROOT_FS_DIR}/usr/local/lib/python2.6/site-packages/pygtk.pth"
426 fi
427
Don Garrett3f41e152010-06-21 14:54:34 -0700428 # Check that the image has been correctly created. Only do it if not
429 # building a factory install image, as the INSTALL_MASK for it will
430 # make test_image fail.
431 if [[ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ]] ; then
432 "${SCRIPTS_DIR}/test_image" \
433 --root="${ROOT_FS_DIR}" \
434 --target="${ARCH}"
435 fi
436 echo "Developer image built and stored at ${image_name}"
437
Chris Sosa9673f3b2010-05-18 13:24:40 -0700438 trap - EXIT
David James868d7bb2010-06-24 21:48:14 -0700439 ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \
Will Drewry4a675e12010-07-03 13:35:02 -0500440 -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}"
David James868d7bb2010-06-24 21:48:14 -0700441}
442
443# Update the base package on an existing image.
444update_base_packages() {
445 local image_name=$1
446
447 echo "Updating base packages on ${image_name}"
448
449 # Create stateful partition of the same size as the rootfs.
Will Drewry4a675e12010-07-03 13:35:02 -0500450 trap "mount_gpt_cleanup" EXIT
David James868d7bb2010-06-24 21:48:14 -0700451
452 ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \
453 --image "${image_name}" -r "${ROOT_FS_DIR}" \
Will Drewry4a675e12010-07-03 13:35:02 -0500454 -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}"
David James868d7bb2010-06-24 21:48:14 -0700455
456 # Emerge updated packages, exactly like when creating base image
457 sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \
458 --root="${ROOT_FS_DIR}" --root-deps=rdeps \
459 --usepkg -uDNv chromeos ${EMERGE_JOBS}
460
461 # Clean out unused packages
462 sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \
463 --root="${ROOT_FS_DIR}" --root-deps=rdeps \
464 --usepkg --depclean ${EMERGE_JOBS}
465
466 trap - EXIT
467 ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \
Will Drewry4a675e12010-07-03 13:35:02 -0500468 -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}"
Chris Sosa9673f3b2010-05-18 13:24:40 -0700469}
470
Don Garrett3f41e152010-06-21 14:54:34 -0700471create_base_image() {
David James868d7bb2010-06-24 21:48:14 -0700472 local image_name=$1
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700473
Don Garrett3f41e152010-06-21 14:54:34 -0700474 trap "cleanup && delete_prompt" EXIT
Chris Sosa4bffb8b2010-04-07 17:23:54 -0700475
David James868d7bb2010-06-24 21:48:14 -0700476 UUID=$(uuidgen)
477
Don Garrett3f41e152010-06-21 14:54:34 -0700478 # Create and format the root file system.
479
480 # Check for loop device before creating image.
481 LOOP_DEV=$(sudo losetup -f)
482 if [ -z "${LOOP_DEV}" ] ; then
483 echo "No free loop device. Free up a loop device or reboot. exiting. "
484 exit 1
485 fi
486
487 # Create root file system disk image to fit on a 1GB memory stick.
488 # 1 GB in hard-drive-manufacturer-speak is 10^9, not 2^30. 950MB < 10^9 bytes.
489 if [[ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]] ; then
490 ROOT_SIZE_BYTES=$((1024 * 1024 * 300))
491 else
492 ROOT_SIZE_BYTES=$((1024 * 1024 * ${FLAGS_rootfs_size}))
493 fi
494
495 dd if=/dev/zero of="${ROOT_FS_IMG}" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1))
496 sudo losetup "${LOOP_DEV}" "${ROOT_FS_IMG}"
497 sudo mkfs.ext3 "${LOOP_DEV}"
498
499 # Tune and mount rootfs.
Don Garrett3f41e152010-06-21 14:54:34 -0700500 DISK_LABEL="C-KEYFOB"
501 sudo tune2fs -L "${DISK_LABEL}" -U "${UUID}" -c 0 -i 0 "${LOOP_DEV}"
502 sudo mount "${LOOP_DEV}" "${ROOT_FS_DIR}"
503
504 # Create stateful partition of the same size as the rootfs.
505 STATEFUL_LOOP_DEV=$(sudo losetup -f)
506 if [ -z "${STATEFUL_LOOP_DEV}" ] ; then
507 echo "No free loop device. Free up a loop device or reboot. exiting. "
508 exit 1
509 fi
Eric Li5cf288f2010-06-28 12:46:26 -0700510 STATEFUL_SIZE_BYTES=$((1024 * 1024 * ${FLAGS_statefulfs_size}))
511 dd if=/dev/zero of="${STATEFUL_FS_IMG}" bs=1 count=1 \
512 seek=$((STATEFUL_SIZE_BYTES - 1))
Denis Romanov11061542010-06-29 04:23:53 +0400513
514 # Tune and mount the stateful partition.
515 UUID=$(uuidgen)
516 DISK_LABEL="C-STATE"
Don Garrett3f41e152010-06-21 14:54:34 -0700517 sudo losetup "${STATEFUL_LOOP_DEV}" "${STATEFUL_FS_IMG}"
518 sudo mkfs.ext3 "${STATEFUL_LOOP_DEV}"
Denis Romanov11061542010-06-29 04:23:53 +0400519 sudo tune2fs -L "${DISK_LABEL}" -U "${UUID}" -c 0 -i 0 "${STATEFUL_LOOP_DEV}"
Don Garrett3f41e152010-06-21 14:54:34 -0700520 sudo mount "${STATEFUL_LOOP_DEV}" "${STATEFUL_FS_DIR}"
521
Denis Romanov11061542010-06-29 04:23:53 +0400522 # Create OEM partner partition.
523 OEM_LOOP_DEV=$(sudo losetup -f)
524 if [ -z "${OEM_LOOP_DEV}" ] ; then
525 echo "No free loop device. Free up a loop device or reboot. exiting. "
526 exit 1
527 fi
528 OEM_SIZE_BYTES=$((1024 * 1024 * 16))
529 dd if=/dev/zero of="${OEM_FS_IMG}" bs=1 count=1 seek=$((OEM_SIZE_BYTES - 1))
530
531 # Tune and mount OEM partner partition.
532 UUID=$(uuidgen)
533 DISK_LABEL="C-OEM"
534 sudo losetup "${OEM_LOOP_DEV}" "${OEM_FS_IMG}"
535 sudo mkfs.ext3 "${OEM_LOOP_DEV}"
536 sudo tune2fs -L "${DISK_LABEL}" -U "${UUID}" -c 0 -i 0 "${OEM_LOOP_DEV}"
537 sudo mount "${OEM_LOOP_DEV}" "${OEM_FS_DIR}"
538
Denis Romanov95bdf472010-07-12 22:44:42 +0400539 # Populate OEM partner partition.
540 if [ -n ${FLAGS_oem_customization} ]; then
541 if [ ! -d ${FLAGS_oem_customization} ]; then
542 echo "Specified OEM content directory does not exist. exiting."
543 exit 1
544 fi
545 for ITEM in `ls -A ${FLAGS_oem_customization}`
546 do sudo cp -a "${FLAGS_oem_customization}/$ITEM" "${OEM_FS_DIR}"
547 done
548 sudo find "${OEM_FS_DIR}" -type d -exec chmod 755 "{}" \;
549 sudo find "${OEM_FS_DIR}" -type f -exec chmod 644 "{}" \;
550 sudo chown -R root:root "${OEM_FS_DIR}"
551 fi
552
Don Garrett3f41e152010-06-21 14:54:34 -0700553 # -- Install packages into the root file system --
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700554
Don Garrett3f41e152010-06-21 14:54:34 -0700555 # We need to install libc manually from the cross toolchain.
556 # TODO: Improve this? We only want libc and not the whole toolchain.
557 PKGDIR="/var/lib/portage/pkgs/cross/"
558 sudo tar jxvpf \
559 "${PKGDIR}/${CHOST}/cross-${CHOST}"/glibc-${LIBC_VERSION}.tbz2 \
560 -C "${ROOT_FS_DIR}" --strip-components=3 \
561 --exclude=usr/include --exclude=sys-include --exclude=*.a --exclude=*.o
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700562
Don Garrett3f41e152010-06-21 14:54:34 -0700563 # We need to install libstdc++ manually from the cross toolchain.
564 # TODO: Figure out a better way of doing this?
565 sudo cp -a "${BOARD_ROOT}"/lib/libgcc_s.so* "${ROOT_FS_DIR}/lib"
566 sudo cp -a "${BOARD_ROOT}"/usr/lib/libstdc++.so* "${ROOT_FS_DIR}/usr/lib"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700567
Don Garrett3f41e152010-06-21 14:54:34 -0700568 # Prepare stateful partition with some pre-created directories.
569 sudo mkdir -p "${DEV_IMAGE_ROOT}"
570 sudo mkdir -p "${STATEFUL_FS_DIR}/var"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700571
Don Garrett3f41e152010-06-21 14:54:34 -0700572 # Create symlinks so that /usr/local/usr based directories are symlinked to
573 # /usr/local/ directories e.g. /usr/local/usr/bin -> /usr/local/bin, etc.
574 setup_symlinks_on_root "${DEV_IMAGE_ROOT}" "${STATEFUL_FS_DIR}/var" \
575 "${STATEFUL_FS_DIR}"
Tom Wai-Hong Tamf87a3672010-05-17 16:06:33 +0800576
Don Garrett3f41e152010-06-21 14:54:34 -0700577 # Perform binding rather than symlinking because directories must exist
578 # on rootfs so that we can bind at run-time since rootfs is read-only.
579 echo "Binding directories from stateful partition onto the rootfs"
580 sudo mkdir -p "${ROOT_FS_DIR}/usr/local"
581 sudo mount --bind "${DEV_IMAGE_ROOT}" "${ROOT_FS_DIR}/usr/local"
582 sudo mkdir -p "${ROOT_FS_DIR}/var"
583 sudo mount --bind "${STATEFUL_FS_DIR}/var" "${ROOT_FS_DIR}/var"
584 sudo mkdir -p "${ROOT_FS_DIR}/dev"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700585
Mandeep Singh Baines3dfa8522010-06-24 15:00:49 -0700586 # We "emerge --root=${ROOT_FS_DIR} --root-deps=rdeps --usepkg" all of the
Don Garrett3f41e152010-06-21 14:54:34 -0700587 # runtime packages for chrome os. This builds up a chrome os image from
588 # binary packages with runtime dependencies only. We use INSTALL_MASK to
589 # trim the image size as much as possible.
590 sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \
591 --root="${ROOT_FS_DIR}" --root-deps=rdeps \
Mandeep Singh Baines3dfa8522010-06-24 15:00:49 -0700592 --usepkg chromeos ${EMERGE_JOBS}
Bill Richardson8b3bd102010-04-06 15:00:10 -0700593
Will Drewry4a675e12010-07-03 13:35:02 -0500594 # Perform any customizations on the root file system that are needed.
595 "${SCRIPTS_DIR}/customize_rootfs" \
596 --root="${ROOT_FS_DIR}" \
597 --target="${ARCH}" \
598 --board="${BOARD}"
Bill Richardson8b3bd102010-04-06 15:00:10 -0700599
Will Drewry1ee156f2010-07-03 13:27:19 -0500600 # Populates the root filesystem with legacy bootloader templates
601 # appropriate for the platform. The autoupdater and installer will
602 # use those templates to update the legacy boot partition (12/ESP)
603 # on update.
604 # (This script does not populate vmlinuz.A and .B needed by syslinux.)
Will Drewry1670d482010-07-09 13:08:38 -0700605 enable_rootfs_verification=
606 if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then
607 enable_rootfs_verification="--enable_rootfs_verification"
608 fi
609
Will Drewry1ee156f2010-07-03 13:27:19 -0500610 ${SCRIPTS_DIR}/create_legacy_bootloader_templates.sh \
611 --arch=${ARCH} \
612 --to="${ROOT_FS_DIR}"/boot \
613 --install \
Will Drewry1670d482010-07-09 13:08:38 -0700614 ${enable_rootfs_verification}
Bill Richardson9c5e5ec2010-05-14 17:00:21 -0700615
Will Drewry1ee156f2010-07-03 13:27:19 -0500616 # Create a working copy so we don't need the rootfs mounted
617 sudo mkdir -p "${OUTPUT_DIR}"/boot
618 # This will include any built files dropped in /boot as well.
619 # Like the current vmlinuz.
620 sudo cp -r "${ROOT_FS_DIR}"/boot/. "${OUTPUT_DIR}"/boot/
Will Drewry25861ee2010-07-04 05:09:41 -0700621 sudo chmod -R a+r "${OUTPUT_DIR}"/boot/
Bill Richardsona81df762010-04-09 08:12:05 -0700622
Don Garrett3f41e152010-06-21 14:54:34 -0700623 # Don't test the factory install shim.
624 if [[ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ]] ; then
625 # Check that the image has been correctly created.
626 "${SCRIPTS_DIR}/test_image" \
627 --root="${ROOT_FS_DIR}" \
628 --target="${ARCH}"
629 fi
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700630
Don Garrett3f41e152010-06-21 14:54:34 -0700631 # Clean up symlinks so they work on a running target rooted at "/".
632 # Here development packages are rooted at /usr/local. However, do not
633 # create /usr/local or /var on host (already exist on target).
634 setup_symlinks_on_root "/usr/local" "/var" "${STATEFUL_FS_DIR}"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700635
Will Drewry4a675e12010-07-03 13:35:02 -0500636 # make_image_bootable will clobber vmlinuz.image for x86.
637 # Until then, just copy the kernel to vmlinuz.image. It is
638 # expected in build_gpt.sh and needed by ARM until it supports the
639 # full, signed kernel partition format.
640 cp "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image"
641
642 # Create an empty esp image to be updated in by update_bootloaders.sh.
643 ${SCRIPTS_DIR}/create_esp.sh --to="${ESP_FS_IMG}"
644
Don Garrett3f41e152010-06-21 14:54:34 -0700645 cleanup
Chris Sosabde8c1b2010-04-29 14:02:35 -0700646
Don Garrett3f41e152010-06-21 14:54:34 -0700647 trap delete_prompt EXIT
Tan Gao6df5aee2010-05-19 14:19:55 -0700648
Don Garrett3f41e152010-06-21 14:54:34 -0700649 # Create the GPT-formatted image.
650 ${SCRIPTS_DIR}/build_gpt.sh \
651 --arch=${ARCH} \
652 --board=${FLAGS_board} \
653 --arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \
654 --rootfs_partition_size=${FLAGS_rootfs_partition_size} \
Don Garrett3f41e152010-06-21 14:54:34 -0700655 "${OUTPUT_DIR}" \
David James868d7bb2010-06-24 21:48:14 -0700656 "${OUTPUT_DIR}/${image_name}"
657
658 trap - EXIT
Don Garrett3f41e152010-06-21 14:54:34 -0700659}
660
661# Create the output directory.
662mkdir -p "${OUTPUT_DIR}"
663mkdir -p "${ROOT_FS_DIR}"
664mkdir -p "${STATEFUL_FS_DIR}"
Denis Romanov11061542010-06-29 04:23:53 +0400665mkdir -p "${OEM_FS_DIR}"
Don Garrett3f41e152010-06-21 14:54:34 -0700666mkdir -p "${ESP_FS_DIR}"
667
David James868d7bb2010-06-24 21:48:14 -0700668# Preserve old images by copying them forward for --preserve.
669if [[ $FLAGS_preserve -eq ${FLAGS_TRUE} ]] ; then
670 if [[ -f ${PREVIOUS_DIR}/${PRISTINE_IMAGE_NAME} ]] ; then
671 # Copy forward pristine image, and associated files
672 cp ${PREVIOUS_DIR}/*.sh ${PREVIOUS_DIR}/config.txt ${OUTPUT_DIR}
673 cp ${PREVIOUS_DIR}/${PRISTINE_IMAGE_NAME} ${OUTPUT_DIR}
Will Drewry4a675e12010-07-03 13:35:02 -0500674 cp -r ${PREVIOUS_DIR}/boot ${OUTPUT_DIR}/boot
David James868d7bb2010-06-24 21:48:14 -0700675
676 # Copy forward the developer image, if we already copied forward the base.
677 if [[ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]] && \
678 [[ -f ${PREVIOUS_DIR}/${DEVELOPER_IMAGE_NAME} ]] ; then
679 cp ${PREVIOUS_DIR}/${DEVELOPER_IMAGE_NAME} ${OUTPUT_DIR}
680 fi
681 fi
682fi
683
684if [[ -f ${PRISTINE_IMG} ]] ; then
685 update_base_packages ${PRISTINE_IMAGE_NAME}
686else
687 create_base_image ${PRISTINE_IMAGE_NAME}
688fi
Will Drewry4a675e12010-07-03 13:35:02 -0500689make_image_bootable ${PRISTINE_IMAGE_NAME}
690
691# FIXME: only signing things for x86 right now.
692if [[ "${ARCH}" = "x86" ]]; then
693 # Verify the final image.
694 load_kernel_test "${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}" \
Louis Yung-Chieh Lo36020402010-07-05 13:23:34 +0800695 "${DEVKEYSDIR}/recovery_key.vbpubk"
Will Drewry4a675e12010-07-03 13:35:02 -0500696fi
Bill Richardson4364a2e2010-03-30 14:17:34 -0700697
Don Garrette0020b12010-06-17 15:55:35 -0700698# Create a developer image based on the chromium os base image.
Don Garrett3f41e152010-06-21 14:54:34 -0700699if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ] ; then
David James868d7bb2010-06-24 21:48:14 -0700700 if [[ ! -f ${DEVELOPER_IMG} ]] ; then
701 echo "Creating developer image from base image ${PRISTINE_IMAGE_NAME}"
702 cp ${PRISTINE_IMG} ${DEVELOPER_IMG}
703 fi
Don Garrett3f41e152010-06-21 14:54:34 -0700704
David James868d7bb2010-06-24 21:48:14 -0700705 update_dev_packages ${DEVELOPER_IMAGE_NAME}
Will Drewry4a675e12010-07-03 13:35:02 -0500706 make_image_bootable ${DEVELOPER_IMAGE_NAME}
Bill Richardson6ed13582010-06-16 21:38:15 -0700707fi
708
709# Clean up temporary files.
Don Garrett3f41e152010-06-21 14:54:34 -0700710rm -f "${ROOT_FS_IMG}" "${STATEFUL_FS_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \
Louis Yung-Chieh Lo36020402010-07-05 13:23:34 +0800711 "${ESP_FS_IMG}" "${OEM_FS_IMG}" "${OUTPUT_DIR}/vmlinuz_hd.vblock"
Denis Romanov11061542010-06-29 04:23:53 +0400712rmdir "${ROOT_FS_DIR}" "${STATEFUL_FS_DIR}" "${OEM_FS_DIR}" "${ESP_FS_DIR}"
Bill Richardson67956222010-05-28 15:38:56 -0700713
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700714echo "Done. Image created in ${OUTPUT_DIR}"
Don Garrette0020b12010-06-17 15:55:35 -0700715echo "Chromium OS image created as ${PRISTINE_IMAGE_NAME}"
Don Garrette0020b12010-06-17 15:55:35 -0700716if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then
717 echo "Developer image created as ${DEVELOPER_IMAGE_NAME}"
Chris Sosa9673f3b2010-05-18 13:24:40 -0700718fi
Nick Sanders8ab729a2010-06-16 03:15:17 -0700719
Nick Sandersd2509272010-06-16 03:50:04 -0700720print_time_elapsed
721
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700722echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:"
Daniel Eratdd9818a2010-04-26 09:16:44 -0700723echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX"
Bill Richardsonc09b94f2010-03-15 11:40:30 -0700724echo "To convert to VMWare image, OUTSIDE the chroot, do something like:"
725echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}"
726echo "from the scripts directory where you entered the chroot."