Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: build_image

Issue 2834038: [PATCH 5/5] build_image: refactor bootloaders and enable vboot config paths (Closed)
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash
2 2
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. 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 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 # Script to build a bootable keyfob-based chromeos system image from within 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 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 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. 10 # build the Chrome OS image using only pre-built binary packages.
11 11
12 # Load common constants. This should be the first executable line. 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. 13 # The path to common.sh should be relative to your script's location.
14 . "$(dirname "$0")/common.sh" 14 . "$(dirname "$0")/common.sh"
15 15
16 . "$(dirname "$0")/chromeos-common.sh" # for partoffset
17 locate_gpt
18
16 # Script must be run inside the chroot. 19 # Script must be run inside the chroot.
17 restart_in_chroot_if_needed $* 20 restart_in_chroot_if_needed $*
18 21
19 get_default_board 22 get_default_board
20 23
21 # Flags. 24 # Flags.
22 DEFINE_string board "${DEFAULT_BOARD}" \ 25 DEFINE_string board "${DEFAULT_BOARD}" \
23 "The board to build an image for." 26 "The board to build an image for."
24 DEFINE_string build_root "/build" \ 27 DEFINE_string build_root "/build" \
25 "The root location for board sysroots." 28 "The root location for board sysroots."
(...skipping 23 matching lines...) Expand all
49 DEFINE_integer rootfs_size 720 \ 52 DEFINE_integer rootfs_size 720 \
50 "rootfs filesystem size in MBs." 53 "rootfs filesystem size in MBs."
51 DEFINE_integer statefulfs_size 1024 \ 54 DEFINE_integer statefulfs_size 1024 \
52 "stateful filesystem size in MBs." 55 "stateful filesystem size in MBs."
53 DEFINE_boolean preserve ${FLAGS_FALSE} \ 56 DEFINE_boolean preserve ${FLAGS_FALSE} \
54 "Attempt to preserve the previous build image if one can be found (unstable, \ 57 "Attempt to preserve the previous build image if one can be found (unstable, \
55 kernel/firmware not updated)" 58 kernel/firmware not updated)"
56 DEFINE_boolean fast ${FLAGS_FALSE} \ 59 DEFINE_boolean fast ${FLAGS_FALSE} \
57 "Call many emerges in parallel (unstable)" 60 "Call many emerges in parallel (unstable)"
58 61
62 DEFINE_string usb_disk /dev/sdb3 \
63 "Path syslinux should use to do a usb boot. Default: /dev/sdb3"
64
65 DEFINE_boolean use_vboot ${FLAGS_FALSE} \
66 "Default the bootloaders to booting a verifying kernel. Default: False."
67 DEFINE_integer vboot_behavior 2 \
68 "Verified boot error behavior (0: I/O errors, 1: reboot, 2: nothing) \
69 Default: 2"
70 DEFINE_integer vboot_depth 1 \
71 "Verified boot hash tree depth. Default: 1"
72 DEFINE_integer vboot_max_ios 1024 \
73 "Number of outstanding I/O operations dm-verity caps at. Default: 1024"
74 DEFINE_string vboot_algorithm "sha1" \
75 "Cryptographic hash algorithm used for vboot. Default : sha1"
59 76
60 # Parse command line. 77 # Parse command line.
61 FLAGS "$@" || exit 1 78 FLAGS "$@" || exit 1
62 eval set -- "${FLAGS_ARGV}" 79 eval set -- "${FLAGS_ARGV}"
63 80
64 # Only now can we die on error. shflags functions leak non-zero error codes, 81 # Only now can we die on error. shflags functions leak non-zero error codes,
65 # so will die prematurely if 'set -e' is specified before now. 82 # so will die prematurely if 'set -e' is specified before now.
66 set -e 83 set -e
67 84
68 if [ -z "${FLAGS_board}" ] ; then 85 if [ -z "${FLAGS_board}" ] ; then
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 fi 118 fi
102 119
103 PRISTINE_IMG="${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}" 120 PRISTINE_IMG="${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}"
104 DEVELOPER_IMG="${OUTPUT_DIR}/${DEVELOPER_IMAGE_NAME}" 121 DEVELOPER_IMG="${OUTPUT_DIR}/${DEVELOPER_IMAGE_NAME}"
105 122
106 BOARD="${FLAGS_board}" 123 BOARD="${FLAGS_board}"
107 BOARD_ROOT="${FLAGS_build_root}/${BOARD}" 124 BOARD_ROOT="${FLAGS_build_root}/${BOARD}"
108 125
109 ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" 126 ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image"
110 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" 127 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs"
128 ROOT_FS_HASH="${OUTPUT_DIR}/rootfs.hash"
111 129
112 STATEFUL_FS_IMG="${OUTPUT_DIR}/stateful_partition.image" 130 STATEFUL_FS_IMG="${OUTPUT_DIR}/stateful_partition.image"
113 STATEFUL_FS_DIR="${OUTPUT_DIR}/stateful_partition" 131 STATEFUL_FS_DIR="${OUTPUT_DIR}/stateful_partition"
114 132
115 OEM_FS_IMG="${OUTPUT_DIR}/partner_partition.image" 133 OEM_FS_IMG="${OUTPUT_DIR}/partner_partition.image"
116 OEM_FS_DIR="${OUTPUT_DIR}/partner_partition" 134 OEM_FS_DIR="${OUTPUT_DIR}/partner_partition"
117 135
118 ESP_FS_IMG=${OUTPUT_DIR}/esp.image 136 ESP_FS_IMG=${OUTPUT_DIR}/esp.image
119 ESP_FS_DIR=${OUTPUT_DIR}/esp 137 ESP_FS_DIR=${OUTPUT_DIR}/esp
120 138
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 cleanup_esp_loop() { 218 cleanup_esp_loop() {
201 sudo umount -d "${ESP_FS_DIR}" 219 sudo umount -d "${ESP_FS_DIR}"
202 } 220 }
203 221
204 cleanup() { 222 cleanup() {
205 # Disable die on error. 223 # Disable die on error.
206 set +e 224 set +e
207 225
208 if [[ -n "${STATEFUL_LOOP_DEV}" ]]; then 226 if [[ -n "${STATEFUL_LOOP_DEV}" ]]; then
209 cleanup_stateful_fs_loop 227 cleanup_stateful_fs_loop
228 STATEFUL_LOOP_DEV=
210 fi 229 fi
211 230
212 if [[ -n "${OEM_LOOP_DEV}" ]]; then 231 if [[ -n "${OEM_LOOP_DEV}" ]]; then
213 cleanup_oem_fs_loop 232 cleanup_oem_fs_loop
214 fi 233 fi
215 234
216 if [[ -n "${LOOP_DEV}" ]]; then 235 if [[ -n "${LOOP_DEV}" ]]; then
217 cleanup_rootfs_loop 236 cleanup_rootfs_loop
237 LOOP_DEV=
218 fi 238 fi
219 239
220 if [[ -n "${ESP_LOOP_DEV}" ]]; then 240 if [[ -n "${ESP_LOOP_DEV}" ]]; then
221 cleanup_esp_loop 241 cleanup_esp_loop
242 ESP_LOOP_DEV=
222 fi 243 fi
223 244
224 # Turn die on error back on. 245 # Turn die on error back on.
225 set -e 246 set -e
226 } 247 }
227 248
228 delete_prompt() { 249 delete_prompt() {
229 echo "An error occurred in your build so your latest output directory" \ 250 echo "An error occurred in your build so your latest output directory" \
230 "is invalid." 251 "is invalid."
231 read -p "Would you like to delete the output directory (y/N)? " SURE 252 read -p "Would you like to delete the output directory (y/N)? " SURE
232 SURE="${SURE:0:1}" # Get just the first character. 253 SURE="${SURE:0:1}" # Get just the first character.
233 if [ "${SURE}" == "y" ] ; then 254 if [ "${SURE}" == "y" ] ; then
234 sudo rm -rf "${OUTPUT_DIR}" 255 sudo rm -rf "${OUTPUT_DIR}"
235 echo "Deleted ${OUTPUT_DIR}" 256 echo "Deleted ${OUTPUT_DIR}"
236 else 257 else
237 echo "Not deleting ${OUTPUT_DIR}. Note dev server updates will not work" \ 258 echo "Not deleting ${OUTPUT_DIR}. Note dev server updates will not work" \
238 "until you successfully build another image or delete this directory" 259 "until you successfully build another image or delete this directory"
239 fi 260 fi
240 } 261 }
241 262
242 # $1 - Directory where developer rootfs is mounted. 263 # $1 - Directory where developer rootfs is mounted.
243 # $2 - Directory where developer stateful_partition is mounted. 264 # $2 - Directory where developer stateful_partition is mounted.
265 # $3 - Directory where the ESP partition is mounted.
244 mount_gpt_cleanup() { 266 mount_gpt_cleanup() {
245 "${SCRIPTS_DIR}/mount_gpt_image.sh" -u -r "$1" -s "$2" 267 local rootfs="${1-$ROOT_FS_DIR}"
268 local statefs="${2-$STATEFUL_FS_DIR}"
269 local espfs="${3-$ESP_FS_DIR}"
270 "${SCRIPTS_DIR}/mount_gpt_image.sh" \
271 -u -r "${rootfs}" -s "${statefs}" -e "${espfs}"
246 delete_prompt 272 delete_prompt
247 } 273 }
248 274
275 make_image_bootable() {
276 local image_name="$1"
277 cros_root=/dev/sd%D%P
278 if [[ "${ARCH}" = "arm" ]]; then
279 # TODO(wad) assumed like in build_gpt for now.
280 cros_root=/dev/mmcblk1p3
281 fi
282 if [[ ${FLAGS_use_vboot} -eq ${FLAGS_TRUE} ]]; then
283 cros_root=/dev/dm-0
284 fi
285
286 # TODO(wad) mount the root fs to LOOP_DEV from the image
287 trap "mount_gpt_cleanup" EXIT
288 ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \
289 --image "${image_name}" -r "${ROOT_FS_DIR}" \
290 -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}"
291
292 sudo mount -o remount,ro "${ROOT_FS_DIR}"
293 root_dev=$(mount | grep -- "${ROOT_FS_DIR}" | cut -f1 -d' ' | tail -1)
294
295 # Builds the kernel partition image. The temporary files are kept around
296 # so that we can perform a load_kernel_test later on the final image.
297 ${SCRIPTS_DIR}/build_kernel_image.sh \
298 --arch="${ARCH}" \
299 --to="${OUTPUT_DIR}/vmlinuz.image" \
300 --vmlinuz="${OUTPUT_DIR}/boot/vmlinuz" \
301 --working_dir="${OUTPUT_DIR}" \
302 --keep_work \
303 --rootfs_image=${root_dev} \
304 --rootfs_hash=${OUTPUT_DIR}/rootfs.hash \
305 --vboot_hash_alg=${FLAGS_vboot_algorithm} \
306 --vboot_tree_depth=${FLAGS_vboot_depth} \
307 --vboot_max_ios=${FLAGS_vboot_max_ios} \
308 --vboot_error_behavior=${FLAGS_vboot_behavior} \
309 --root=${cros_root} \
310 --keys_dir="${SRC_ROOT}/platform/vboot_reference/tests/testkeys"
311
312 # START_KERN_A is set by the first call to install the gpt.
313 local koffset="$(partoffset ${OUTPUT_DIR}/${image_name} 2)"
314 sudo dd if="${OUTPUT_DIR}/vmlinuz.image" of="${OUTPUT_DIR}/${image_name}" \
315 conv=notrunc bs=512 seek=${koffset}
316
317 # Populate the legacy/efi bootloader partition.
318 local kernel_part="--kernel_partition='${OUTPUT_DIR}/vmlinuz.image'"
319 local bootloader_to="${ESP_FS_IMG}"
320 local usb_disk="${FLAGS_usb_disk}"
321 local bootloader_to="$(mount | grep ${ESP_FS_DIR} | cut -f1 -d' ')"
322 if [[ "${ARCH}" == "arm" ]]; then
323 # TODO(wad) mmcblk1p3 is hardcoded for arm for now!
324 usb_disk="/dev/mmcblk1p3"
325 kernel_part="--kernel_cmdline='"
326 kernel_part="${kernel_part}\
327 $(cat ${OUTPUT_DIR}/boot.config | tr -s '\n' ' ')"
328 kernel_part="${kernel_part} ${FLAGS_arm_extra_bootargs}'"
329 local kpart_offset="--kernel_partition_offset=${koffset}"
330 local kpart_size="--kernel_partition_sectors=$(partsize ${image_name} 2)"
331 kernel_part="${kernel_part} ${kpart_size} ${kpart_offset}"
332 bootloader_to="${OUTPUT_DIR}/arm.mbr"
333 fi
334
335 # Update partition 12 / legacy bootloaders and arm.
336 ${SCRIPTS_DIR}/update_bootloaders.sh \
337 --arch=${ARCH} \
338 --to="${bootloader_to}" \
339 --from="${OUTPUT_DIR}"/boot \
340 --vmlinuz="${OUTPUT_DIR}"/boot/vmlinuz \
341 --usb_disk="${usb_disk}" \
342 $kernel_part
343
344 if [[ "${ARCH}" == "arm" ]]; then
345 sudo dd bs=1 conv=notrunc if="${bootloader_to}" \
346 of="${OUTPUT_DIR}/${image_name}"
347 sudo rm "${bootloader_to}"
348 fi
349
350 trap - EXIT
351 ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \
352 -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}"
353 }
354
249 # Modifies an existing image to add development packages 355 # Modifies an existing image to add development packages
250 update_dev_packages() { 356 update_dev_packages() {
251 local image_name=$1 357 local image_name=$1
252 358
253 echo "Adding developer packages to ${image_name}" 359 echo "Adding developer packages to ${image_name}"
254 360
255 trap "mount_gpt_cleanup \"${ROOT_FS_DIR}\" \"${STATEFUL_FS_DIR}\"" EXIT 361 trap "mount_gpt_cleanup" EXIT
256 362
257 ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \ 363 ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \
258 --image "${image_name}" -r "${ROOT_FS_DIR}" \ 364 --image "${image_name}" -r "${ROOT_FS_DIR}" \
259 -s "${STATEFUL_FS_DIR}" 365 -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}"
260 366
261 # Determine the root dir for developer packages. 367 # Determine the root dir for developer packages.
262 local root_dev_dir="${ROOT_FS_DIR}" 368 local root_dev_dir="${ROOT_FS_DIR}"
263 [ ${FLAGS_statefuldev} -eq ${FLAGS_TRUE} ] && \ 369 [ ${FLAGS_statefuldev} -eq ${FLAGS_TRUE} ] && \
264 root_dev_dir="${ROOT_FS_DIR}/usr/local" 370 root_dev_dir="${ROOT_FS_DIR}/usr/local"
265 371
266 # Install developer packages described in chromeos-dev. 372 # Install developer packages described in chromeos-dev.
267 sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ 373 sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \
268 --root="${root_dev_dir}" --root-deps=rdeps \ 374 --root="${root_dev_dir}" --root-deps=rdeps \
269 --usepkg -uDNv chromeos-dev ${EMERGE_JOBS} 375 --usepkg -uDNv chromeos-dev ${EMERGE_JOBS}
(...skipping 27 matching lines...) Expand all
297 # make test_image fail. 403 # make test_image fail.
298 if [[ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ]] ; then 404 if [[ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ]] ; then
299 "${SCRIPTS_DIR}/test_image" \ 405 "${SCRIPTS_DIR}/test_image" \
300 --root="${ROOT_FS_DIR}" \ 406 --root="${ROOT_FS_DIR}" \
301 --target="${ARCH}" 407 --target="${ARCH}"
302 fi 408 fi
303 echo "Developer image built and stored at ${image_name}" 409 echo "Developer image built and stored at ${image_name}"
304 410
305 trap - EXIT 411 trap - EXIT
306 ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \ 412 ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \
307 -s "${STATEFUL_FS_DIR}" 413 -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}"
308 } 414 }
309 415
310 # Update the base package on an existing image. 416 # Update the base package on an existing image.
311 update_base_packages() { 417 update_base_packages() {
312 local image_name=$1 418 local image_name=$1
313 419
314 echo "Updating base packages on ${image_name}" 420 echo "Updating base packages on ${image_name}"
315 421
316 # Create stateful partition of the same size as the rootfs. 422 # Create stateful partition of the same size as the rootfs.
317 trap "mount_gpt_cleanup \"${ROOT_FS_DIR}\" \"${STATEFUL_FS_DIR}\"" EXIT 423 trap "mount_gpt_cleanup" EXIT
318 424
319 ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \ 425 ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \
320 --image "${image_name}" -r "${ROOT_FS_DIR}" \ 426 --image "${image_name}" -r "${ROOT_FS_DIR}" \
321 -s "${STATEFUL_FS_DIR}" 427 -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}"
322 428
323 # Emerge updated packages, exactly like when creating base image 429 # Emerge updated packages, exactly like when creating base image
324 sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ 430 sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \
325 --root="${ROOT_FS_DIR}" --root-deps=rdeps \ 431 --root="${ROOT_FS_DIR}" --root-deps=rdeps \
326 --usepkg -uDNv chromeos ${EMERGE_JOBS} 432 --usepkg -uDNv chromeos ${EMERGE_JOBS}
327 433
328 # Clean out unused packages 434 # Clean out unused packages
329 sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ 435 sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \
330 --root="${ROOT_FS_DIR}" --root-deps=rdeps \ 436 --root="${ROOT_FS_DIR}" --root-deps=rdeps \
331 --usepkg --depclean ${EMERGE_JOBS} 437 --usepkg --depclean ${EMERGE_JOBS}
332 438
333 trap - EXIT 439 trap - EXIT
334 ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \ 440 ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \
335 -s "${STATEFUL_FS_DIR}" 441 -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}"
336 } 442 }
337 443
338 create_base_image() { 444 create_base_image() {
339 local image_name=$1 445 local image_name=$1
340 446
341 trap "cleanup && delete_prompt" EXIT 447 trap "cleanup && delete_prompt" EXIT
342 448
343 UUID=$(uuidgen) 449 UUID=$(uuidgen)
344 450
345 # Create and format the root file system. 451 # Create and format the root file system.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 sudo mkdir -p "${ROOT_FS_DIR}/dev" 543 sudo mkdir -p "${ROOT_FS_DIR}/dev"
438 544
439 # We "emerge --root=${ROOT_FS_DIR} --root-deps=rdeps --usepkg" all of the 545 # We "emerge --root=${ROOT_FS_DIR} --root-deps=rdeps --usepkg" all of the
440 # runtime packages for chrome os. This builds up a chrome os image from 546 # runtime packages for chrome os. This builds up a chrome os image from
441 # binary packages with runtime dependencies only. We use INSTALL_MASK to 547 # binary packages with runtime dependencies only. We use INSTALL_MASK to
442 # trim the image size as much as possible. 548 # trim the image size as much as possible.
443 sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ 549 sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \
444 --root="${ROOT_FS_DIR}" --root-deps=rdeps \ 550 --root="${ROOT_FS_DIR}" --root-deps=rdeps \
445 --usepkg chromeos ${EMERGE_JOBS} 551 --usepkg chromeos ${EMERGE_JOBS}
446 552
447 # Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI 553 # Perform any customizations on the root file system that are needed.
448 # BIOS). We only need this for x86, but it's simpler and safer to keep the 554 "${SCRIPTS_DIR}/customize_rootfs" \
449 # disk images the same for both x86 and ARM. 555 --root="${ROOT_FS_DIR}" \
450 # NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. 556 --target="${ARCH}" \
451 # We'll hard-code it to 16M for now. 557 --board="${BOARD}"
452 ESP_BLOCKS=16384
453 /usr/sbin/mkfs.vfat -C ${OUTPUT_DIR}/esp.image ${ESP_BLOCKS}
454 ESP_LOOP_DEV=$(sudo losetup -f)
455 if [ -z "${ESP_LOOP_DEV}" ] ; then
456 echo "No free loop device. Free up a loop device or reboot. exiting. "
457 exit 1
458 fi
459 sudo losetup "${ESP_LOOP_DEV}" "${ESP_FS_IMG}"
460 sudo mount "${ESP_LOOP_DEV}" "${ESP_FS_DIR}"
461 558
462 # Populates the root filesystem with legacy bootloader templates 559 # Populates the root filesystem with legacy bootloader templates
463 # appropriate for the platform. The autoupdater and installer will 560 # appropriate for the platform. The autoupdater and installer will
464 # use those templates to update the legacy boot partition (12/ESP) 561 # use those templates to update the legacy boot partition (12/ESP)
465 # on update. 562 # on update.
466 # (This script does not populate vmlinuz.A and .B needed by syslinux.) 563 # (This script does not populate vmlinuz.A and .B needed by syslinux.)
467 use_vboot= 564 use_vboot=
565 [[ ${FLAGS_use_vboot} -eq ${FLAGS_TRUE} ]] && use_vboot="--use_vboot"
468 ${SCRIPTS_DIR}/create_legacy_bootloader_templates.sh \ 566 ${SCRIPTS_DIR}/create_legacy_bootloader_templates.sh \
469 --arch=${ARCH} \ 567 --arch=${ARCH} \
470 --to="${ROOT_FS_DIR}"/boot \ 568 --to="${ROOT_FS_DIR}"/boot \
471 --install \ 569 --install \
472 ${use_vboot} 570 ${use_vboot}
473 571
474 # Create a working copy so we don't need the rootfs mounted 572 # Create a working copy so we don't need the rootfs mounted
475 sudo mkdir -p "${OUTPUT_DIR}"/boot 573 sudo mkdir -p "${OUTPUT_DIR}"/boot
476 # This will include any built files dropped in /boot as well. 574 # This will include any built files dropped in /boot as well.
477 # Like the current vmlinuz. 575 # Like the current vmlinuz.
478 sudo cp -r "${ROOT_FS_DIR}"/boot/. "${OUTPUT_DIR}"/boot/ 576 sudo cp -r "${ROOT_FS_DIR}"/boot/. "${OUTPUT_DIR}"/boot/
479 577
480 # Until bootloader management is unified, copy EFI in here.
481 sudo mkdir -p "${ESP_FS_IMG}"/efi
482 sudo cp -r "${ROOT_FS_DIR}"/boot/efi/. "${ESP_FS_IMG}"/efi
483
484 # Builds the kernel partition image. The temporary files are kept around
485 # so that we can perform a load_kernel_test later on the final image.
486 # TODO(wad) add dm-verity boot args (--boot_args, --root)
487 ${SCRIPTS_DIR}/build_kernel_image.sh \
488 --arch="${ARCH}" \
489 --to="${OUTPUT_DIR}/vmlinuz.image" \
490 --vmlinuz="${ROOT_FS_DIR}/boot/vmlinuz" \
491 --working_dir="${OUTPUT_DIR}" \
492 --keep_work \
493 --keys_dir="${SRC_ROOT}/platform/vboot_reference/tests/testkeys"
494
495 # Perform any customizations on the root file system that are needed.
496 "${SCRIPTS_DIR}/customize_rootfs" \
497 --root="${ROOT_FS_DIR}" \
498 --target="${ARCH}" \
499 --board="${BOARD}"
500
501 # Don't test the factory install shim. 578 # Don't test the factory install shim.
502 if [[ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ]] ; then 579 if [[ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ]] ; then
503 # Check that the image has been correctly created. 580 # Check that the image has been correctly created.
504 "${SCRIPTS_DIR}/test_image" \ 581 "${SCRIPTS_DIR}/test_image" \
505 --root="${ROOT_FS_DIR}" \ 582 --root="${ROOT_FS_DIR}" \
506 --target="${ARCH}" 583 --target="${ARCH}"
507 fi 584 fi
508 585
509 # Clean up symlinks so they work on a running target rooted at "/". 586 # Clean up symlinks so they work on a running target rooted at "/".
510 # Here development packages are rooted at /usr/local. However, do not 587 # Here development packages are rooted at /usr/local. However, do not
511 # create /usr/local or /var on host (already exist on target). 588 # create /usr/local or /var on host (already exist on target).
512 setup_symlinks_on_root "/usr/local" "/var" "${STATEFUL_FS_DIR}" 589 setup_symlinks_on_root "/usr/local" "/var" "${STATEFUL_FS_DIR}"
513 590
514 # Cleanup loop devices. 591 # make_image_bootable will clobber vmlinuz.image for x86.
592 # Until then, just copy the kernel to vmlinuz.image. It is
593 # expected in build_gpt.sh and needed by ARM until it supports the
594 # full, signed kernel partition format.
595 cp "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image"
596
597 # Create an empty esp image to be updated in by update_bootloaders.sh.
598 ${SCRIPTS_DIR}/create_esp.sh --to="${ESP_FS_IMG}"
599
515 cleanup 600 cleanup
516 601
517 trap delete_prompt EXIT 602 trap delete_prompt EXIT
518 603
519 # Create the GPT-formatted image. 604 # Create the GPT-formatted image.
520 ${SCRIPTS_DIR}/build_gpt.sh \ 605 ${SCRIPTS_DIR}/build_gpt.sh \
521 --arch=${ARCH} \ 606 --arch=${ARCH} \
522 --board=${FLAGS_board} \ 607 --board=${FLAGS_board} \
523 --arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \ 608 --arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \
524 --rootfs_partition_size=${FLAGS_rootfs_partition_size} \ 609 --rootfs_partition_size=${FLAGS_rootfs_partition_size} \
525 "${OUTPUT_DIR}" \ 610 "${OUTPUT_DIR}" \
526 "${OUTPUT_DIR}/${image_name}" 611 "${OUTPUT_DIR}/${image_name}"
527 612
528 trap - EXIT 613 trap - EXIT
529
530 # FIXME: only signing things for x86 right now.
531 if [[ "${ARCH}" = "x86" ]]; then
532 # Verify the final image.
533 load_kernel_test "${OUTPUT_DIR}/${image_name}" \
534 "${OUTPUT_DIR}/kernel_subkey.vbpubk"
535 fi
536 } 614 }
537 615
538 # Create the output directory. 616 # Create the output directory.
539 mkdir -p "${OUTPUT_DIR}" 617 mkdir -p "${OUTPUT_DIR}"
540 mkdir -p "${ROOT_FS_DIR}" 618 mkdir -p "${ROOT_FS_DIR}"
541 mkdir -p "${STATEFUL_FS_DIR}" 619 mkdir -p "${STATEFUL_FS_DIR}"
542 mkdir -p "${OEM_FS_DIR}" 620 mkdir -p "${OEM_FS_DIR}"
543 mkdir -p "${ESP_FS_DIR}" 621 mkdir -p "${ESP_FS_DIR}"
544 622
545 # Preserve old images by copying them forward for --preserve. 623 # Preserve old images by copying them forward for --preserve.
546 if [[ $FLAGS_preserve -eq ${FLAGS_TRUE} ]] ; then 624 if [[ $FLAGS_preserve -eq ${FLAGS_TRUE} ]] ; then
547 if [[ -f ${PREVIOUS_DIR}/${PRISTINE_IMAGE_NAME} ]] ; then 625 if [[ -f ${PREVIOUS_DIR}/${PRISTINE_IMAGE_NAME} ]] ; then
548 # Copy forward pristine image, and associated files 626 # Copy forward pristine image, and associated files
549 cp ${PREVIOUS_DIR}/*.sh ${PREVIOUS_DIR}/config.txt ${OUTPUT_DIR} 627 cp ${PREVIOUS_DIR}/*.sh ${PREVIOUS_DIR}/config.txt ${OUTPUT_DIR}
550 cp ${PREVIOUS_DIR}/${PRISTINE_IMAGE_NAME} ${OUTPUT_DIR} 628 cp ${PREVIOUS_DIR}/${PRISTINE_IMAGE_NAME} ${OUTPUT_DIR}
629 cp -r ${PREVIOUS_DIR}/boot ${OUTPUT_DIR}/boot
551 630
552 # Copy forward the developer image, if we already copied forward the base. 631 # Copy forward the developer image, if we already copied forward the base.
553 if [[ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]] && \ 632 if [[ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]] && \
554 [[ -f ${PREVIOUS_DIR}/${DEVELOPER_IMAGE_NAME} ]] ; then 633 [[ -f ${PREVIOUS_DIR}/${DEVELOPER_IMAGE_NAME} ]] ; then
555 cp ${PREVIOUS_DIR}/${DEVELOPER_IMAGE_NAME} ${OUTPUT_DIR} 634 cp ${PREVIOUS_DIR}/${DEVELOPER_IMAGE_NAME} ${OUTPUT_DIR}
556 fi 635 fi
557 fi 636 fi
558 fi 637 fi
559 638
560 if [[ -f ${PRISTINE_IMG} ]] ; then 639 if [[ -f ${PRISTINE_IMG} ]] ; then
561 update_base_packages ${PRISTINE_IMAGE_NAME} 640 update_base_packages ${PRISTINE_IMAGE_NAME}
562 else 641 else
563 create_base_image ${PRISTINE_IMAGE_NAME} 642 create_base_image ${PRISTINE_IMAGE_NAME}
564 fi 643 fi
644 make_image_bootable ${PRISTINE_IMAGE_NAME}
645
646 # FIXME: only signing things for x86 right now.
647 if [[ "${ARCH}" = "x86" ]]; then
648 # Verify the final image.
649 load_kernel_test "${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}" \
650 "${OUTPUT_DIR}/kernel_subkey.vbpubk"
651 fi
565 652
566 # Create a developer image based on the chromium os base image. 653 # Create a developer image based on the chromium os base image.
567 if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ] ; then 654 if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ] ; then
568 if [[ ! -f ${DEVELOPER_IMG} ]] ; then 655 if [[ ! -f ${DEVELOPER_IMG} ]] ; then
569 echo "Creating developer image from base image ${PRISTINE_IMAGE_NAME}" 656 echo "Creating developer image from base image ${PRISTINE_IMAGE_NAME}"
570 cp ${PRISTINE_IMG} ${DEVELOPER_IMG} 657 cp ${PRISTINE_IMG} ${DEVELOPER_IMG}
571 fi 658 fi
572 659
573 update_dev_packages ${DEVELOPER_IMAGE_NAME} 660 update_dev_packages ${DEVELOPER_IMAGE_NAME}
661 make_image_bootable ${DEVELOPER_IMAGE_NAME}
574 fi 662 fi
575 663
576 # Clean up temporary files. 664 # Clean up temporary files.
577 rm -f "${ROOT_FS_IMG}" "${STATEFUL_FS_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \ 665 rm -f "${ROOT_FS_IMG}" "${STATEFUL_FS_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \
578 "${ESP_FS_IMG}" "${OUTPUT_DIR}/kernel.keyblock" \ 666 "${ESP_FS_IMG}" "${OUTPUT_DIR}/kernel.keyblock" \
579 "${OUTPUT_DIR}/kernel_subkey.vbpubk" \ 667 "${OUTPUT_DIR}/kernel_subkey.vbpubk" \
580 "${OUTPUT_DIR}/kernel_subkey.vbprivk" \ 668 "${OUTPUT_DIR}/kernel_subkey.vbprivk" \
581 "${OUTPUT_DIR}/kernel_data_key.vbpubk" \ 669 "${OUTPUT_DIR}/kernel_data_key.vbpubk" \
582 "${OUTPUT_DIR}/kernel_data_key.vbprivk" \ 670 "${OUTPUT_DIR}/kernel_data_key.vbprivk" \
583 "${OEM_FS_IMG}" 671 "${OEM_FS_IMG}"
584 rmdir "${ROOT_FS_DIR}" "${STATEFUL_FS_DIR}" "${OEM_FS_DIR}" "${ESP_FS_DIR}" 672 rmdir "${ROOT_FS_DIR}" "${STATEFUL_FS_DIR}" "${OEM_FS_DIR}" "${ESP_FS_DIR}"
585 673
586 echo "Done. Image created in ${OUTPUT_DIR}" 674 echo "Done. Image created in ${OUTPUT_DIR}"
587 echo "Chromium OS image created as ${PRISTINE_IMAGE_NAME}" 675 echo "Chromium OS image created as ${PRISTINE_IMAGE_NAME}"
588 if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then 676 if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then
589 echo "Developer image created as ${DEVELOPER_IMAGE_NAME}" 677 echo "Developer image created as ${DEVELOPER_IMAGE_NAME}"
590 fi 678 fi
591 679
592 print_time_elapsed 680 print_time_elapsed
593 681
594 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" 682 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:"
595 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" 683 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX"
596 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" 684 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:"
597 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" 685 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}"
598 echo "from the scripts directory where you entered the chroot." 686 echo "from the scripts directory where you entered the chroot."
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698