OLD | NEW |
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. |
(...skipping 26 matching lines...) Expand all Loading... |
37 "How many packages to build in parallel at maximum." | 37 "How many packages to build in parallel at maximum." |
38 DEFINE_boolean statefuldev ${FLAGS_TRUE} \ | 38 DEFINE_boolean statefuldev ${FLAGS_TRUE} \ |
39 "Install development packages on stateful partition rather than the rootfs" | 39 "Install development packages on stateful partition rather than the rootfs" |
40 DEFINE_string to "" \ | 40 DEFINE_string to "" \ |
41 "The target image file or device" | 41 "The target image file or device" |
42 DEFINE_boolean factory_install ${FLAGS_FALSE} \ | 42 DEFINE_boolean factory_install ${FLAGS_FALSE} \ |
43 "Build a smaller image to overlay the factory install shim on; this argument \ | 43 "Build a smaller image to overlay the factory install shim on; this argument \ |
44 is also required in image_to_usb." | 44 is also required in image_to_usb." |
45 DEFINE_string arm_extra_bootargs "" \ | 45 DEFINE_string arm_extra_bootargs "" \ |
46 "Additional command line options to pass to the ARM kernel." | 46 "Additional command line options to pass to the ARM kernel." |
47 DEFINE_boolean recovery ${FLAGS_FALSE} \ | |
48 "Build a recovery image. Default: False." | |
49 DEFINE_integer rootfs_partition_size 1024 \ | 47 DEFINE_integer rootfs_partition_size 1024 \ |
50 "rootfs parition size in MBs." | 48 "rootfs parition size in MBs." |
51 DEFINE_integer rootfs_size 720 \ | 49 DEFINE_integer rootfs_size 720 \ |
52 "rootfs filesystem size in MBs." | 50 "rootfs filesystem size in MBs." |
53 | 51 |
54 # Parse command line. | 52 # Parse command line. |
55 FLAGS "$@" || exit 1 | 53 FLAGS "$@" || exit 1 |
56 eval set -- "${FLAGS_ARGV}" | 54 eval set -- "${FLAGS_ARGV}" |
57 | 55 |
58 # Only now can we die on error. shflags functions leak non-zero error codes, | 56 # Only now can we die on error. shflags functions leak non-zero error codes, |
(...skipping 30 matching lines...) Expand all Loading... |
89 | 87 |
90 # If we are creating a developer image, also create a pristine image with a | 88 # If we are creating a developer image, also create a pristine image with a |
91 # different name. | 89 # different name. |
92 DEVELOPER_IMAGE_NAME= | 90 DEVELOPER_IMAGE_NAME= |
93 PRISTINE_IMAGE_NAME=chromiumos_image.bin | 91 PRISTINE_IMAGE_NAME=chromiumos_image.bin |
94 if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then | 92 if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then |
95 PRISTINE_IMAGE_NAME=chromiumos_base_image.bin | 93 PRISTINE_IMAGE_NAME=chromiumos_base_image.bin |
96 DEVELOPER_IMAGE_NAME=chromiumos_image.bin | 94 DEVELOPER_IMAGE_NAME=chromiumos_image.bin |
97 fi | 95 fi |
98 | 96 |
99 # If we are creating a recovery image, rename pristine image. | |
100 if [ "${FLAGS_recovery}" -eq "${FLAGS_TRUE}" ]; then | |
101 PRISTINE_IMAGE_NAME=recovery_image.bin | |
102 fi | |
103 | |
104 OUTPUT_IMG=${FLAGS_to:-${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}} | 97 OUTPUT_IMG=${FLAGS_to:-${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME}} |
105 | 98 |
106 BOARD="${FLAGS_board}" | 99 BOARD="${FLAGS_board}" |
107 BOARD_ROOT="${FLAGS_build_root}/${BOARD}" | 100 BOARD_ROOT="${FLAGS_build_root}/${BOARD}" |
108 | 101 |
109 ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" | 102 ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" |
110 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" | 103 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" |
111 | 104 |
112 STATEFUL_FS_IMG="${OUTPUT_DIR}/stateful_partition.image" | 105 STATEFUL_FS_IMG="${OUTPUT_DIR}/stateful_partition.image" |
113 STATEFUL_FS_DIR="${OUTPUT_DIR}/stateful_partition" | 106 STATEFUL_FS_DIR="${OUTPUT_DIR}/stateful_partition" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 "${SCRIPTS_DIR}/test_image" \ | 269 "${SCRIPTS_DIR}/test_image" \ |
277 --root="${ROOT_FS_DIR}" \ | 270 --root="${ROOT_FS_DIR}" \ |
278 --target="${ARCH}" | 271 --target="${ARCH}" |
279 fi | 272 fi |
280 echo "Developer image built and stored at ${image_name}" | 273 echo "Developer image built and stored at ${image_name}" |
281 | 274 |
282 trap - EXIT | 275 trap - EXIT |
283 ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" -s "${STATEFUL_FS_DIR
}" | 276 ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" -s "${STATEFUL_FS_DIR
}" |
284 } | 277 } |
285 | 278 |
286 | |
287 # Modifies an existing image to add recovery packages | |
288 update_recovery_packages() { | |
289 local image_name=$1 | |
290 | |
291 echo "Adding recovery packages to ${image_name}" | |
292 | |
293 # Create stateful partition of the same size as the rootfs. | |
294 trap "mount_gpt_cleanup \"${ROOT_FS_DIR}\" \"${STATEFUL_FS_DIR}\"" EXIT | |
295 | |
296 ${SCRIPTS_DIR}/mount_gpt_image.sh --from "${OUTPUT_DIR}" \ | |
297 --image "$( basename ${image_name} )" -r "${ROOT_FS_DIR}" \ | |
298 -s "${STATEFUL_FS_DIR}" | |
299 | |
300 # Install recovery installer. | |
301 sudo ${EMERGE_BOARD_CMD} --root=${ROOT_FS_DIR} --usepkg \ | |
302 --root-deps=rdeps --nodeps chromeos-recovery | |
303 | |
304 # Re-run ldconfig to fix /etc/ldconfig.so.cache. | |
305 sudo /sbin/ldconfig -r "${ROOT_FS_DIR}" | |
306 | |
307 # Mark the image as a developer image (input to chromeos_startup). | |
308 sudo mkdir -p "${ROOT_FS_DIR}/root" | |
309 sudo touch "${ROOT_FS_DIR}/root/.recovery_installer" | |
310 | |
311 trap - EXIT | |
312 ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" -s "${STATEFUL_FS_DIR
}" | |
313 } | |
314 | |
315 create_base_image() { | 279 create_base_image() { |
316 | 280 |
317 trap "cleanup && delete_prompt" EXIT | 281 trap "cleanup && delete_prompt" EXIT |
318 | 282 |
319 # Create and format the root file system. | 283 # Create and format the root file system. |
320 | 284 |
321 # Check for loop device before creating image. | 285 # Check for loop device before creating image. |
322 LOOP_DEV=$(sudo losetup -f) | 286 LOOP_DEV=$(sudo losetup -f) |
323 if [ -z "${LOOP_DEV}" ] ; then | 287 if [ -z "${LOOP_DEV}" ] ; then |
324 echo "No free loop device. Free up a loop device or reboot. exiting. " | 288 echo "No free loop device. Free up a loop device or reboot. exiting. " |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 # Clean up symlinks so they work on a running target rooted at "/". | 456 # Clean up symlinks so they work on a running target rooted at "/". |
493 # Here development packages are rooted at /usr/local. However, do not | 457 # Here development packages are rooted at /usr/local. However, do not |
494 # create /usr/local or /var on host (already exist on target). | 458 # create /usr/local or /var on host (already exist on target). |
495 setup_symlinks_on_root "/usr/local" "/var" "${STATEFUL_FS_DIR}" | 459 setup_symlinks_on_root "/usr/local" "/var" "${STATEFUL_FS_DIR}" |
496 | 460 |
497 # Cleanup loop devices. | 461 # Cleanup loop devices. |
498 cleanup | 462 cleanup |
499 | 463 |
500 trap delete_prompt EXIT | 464 trap delete_prompt EXIT |
501 | 465 |
502 RECOVERY="--norecovery" | |
503 if [[ ${FLAGS_recovery} -eq ${FLAGS_TRUE} ]]; then | |
504 RECOVERY="--recovery" | |
505 fi | |
506 | |
507 # Create the GPT-formatted image. | 466 # Create the GPT-formatted image. |
508 ${SCRIPTS_DIR}/build_gpt.sh \ | 467 ${SCRIPTS_DIR}/build_gpt.sh \ |
509 --arch=${ARCH} \ | 468 --arch=${ARCH} \ |
510 --board=${FLAGS_board} \ | 469 --board=${FLAGS_board} \ |
511 --arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \ | 470 --arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \ |
512 --rootfs_partition_size=${FLAGS_rootfs_partition_size} \ | 471 --rootfs_partition_size=${FLAGS_rootfs_partition_size} \ |
513 ${RECOVERY} \ | |
514 "${OUTPUT_DIR}" \ | 472 "${OUTPUT_DIR}" \ |
515 "${OUTPUT_IMG}" | 473 "${OUTPUT_IMG}" |
516 } | 474 } |
517 | 475 |
518 # Create the output directory. | 476 # Create the output directory. |
519 mkdir -p "${OUTPUT_DIR}" | 477 mkdir -p "${OUTPUT_DIR}" |
520 mkdir -p "${ROOT_FS_DIR}" | 478 mkdir -p "${ROOT_FS_DIR}" |
521 mkdir -p "${STATEFUL_FS_DIR}" | 479 mkdir -p "${STATEFUL_FS_DIR}" |
522 mkdir -p "${ESP_FS_DIR}" | 480 mkdir -p "${ESP_FS_DIR}" |
523 | 481 |
524 create_base_image ${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME} | 482 create_base_image ${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME} |
525 | 483 |
526 # Create a recovery image based on the chromium os base image. | |
527 if [ "${FLAGS_recovery}" -eq "${FLAGS_TRUE}" ] ; then | |
528 update_recovery_packages ${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME} | |
529 fi | |
530 trap - EXIT | |
531 | |
532 | |
533 # Create a developer image based on the chromium os base image. | 484 # Create a developer image based on the chromium os base image. |
534 if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ] ; then | 485 if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ] ; then |
535 echo "Creating developer image from base image ${OUTPUT_IMG}" | 486 echo "Creating developer image from base image ${OUTPUT_IMG}" |
536 cp ${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME} ${OUTPUT_DIR}/${DEVELOPER_IMAGE_NAME} | 487 cp ${OUTPUT_DIR}/${PRISTINE_IMAGE_NAME} ${OUTPUT_DIR}/${DEVELOPER_IMAGE_NAME} |
537 update_dev_packages ${OUTPUT_DIR}/${DEVELOPER_IMAGE_NAME} | 488 update_dev_packages ${OUTPUT_DIR}/${DEVELOPER_IMAGE_NAME} |
538 fi | 489 fi |
539 | 490 |
540 trap - EXIT | 491 trap - EXIT |
541 | 492 |
542 # FIXME: only signing things for x86 right now. | 493 # FIXME: only signing things for x86 right now. |
543 if [[ "${ARCH}" = "x86" ]]; then | 494 if [[ "${ARCH}" = "x86" ]]; then |
544 # Verify the final image. | 495 # Verify the final image. |
545 # key_alg8.vbpubk is generated by build_kernel_image.sh --keep_work | 496 # key_alg8.vbpubk is generated by build_kernel_image.sh --keep_work |
546 load_kernel_test "${OUTPUT_IMG}" "${OUTPUT_DIR}/key_alg8.vbpubk" | 497 load_kernel_test "${OUTPUT_IMG}" "${OUTPUT_DIR}/key_alg8.vbpubk" |
547 fi | 498 fi |
548 | 499 |
549 # Clean up temporary files. | 500 # Clean up temporary files. |
550 rm -f "${ROOT_FS_IMG}" "${STATEFUL_FS_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \ | 501 rm -f "${ROOT_FS_IMG}" "${STATEFUL_FS_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \ |
551 "${ESP_FS_IMG}" "${OUTPUT_DIR}/data4_sign8.keyblock" \ | 502 "${ESP_FS_IMG}" "${OUTPUT_DIR}/data4_sign8.keyblock" \ |
552 "${OUTPUT_DIR}/key_alg4.vbpubk" "${OUTPUT_DIR}/key_alg8.vbpubk" | 503 "${OUTPUT_DIR}/key_alg4.vbpubk" "${OUTPUT_DIR}/key_alg8.vbpubk" |
553 rmdir "${ROOT_FS_DIR}" "${STATEFUL_FS_DIR}" "${ESP_FS_DIR}" | 504 rmdir "${ROOT_FS_DIR}" "${STATEFUL_FS_DIR}" "${ESP_FS_DIR}" |
554 | 505 |
555 echo "Done. Image created in ${OUTPUT_DIR}" | 506 echo "Done. Image created in ${OUTPUT_DIR}" |
556 echo "Chromium OS image created as ${PRISTINE_IMAGE_NAME}" | 507 echo "Chromium OS image created as ${PRISTINE_IMAGE_NAME}" |
557 if [ "${FLAGS_recovery}" -eq "${FLAGS_TRUE}" ]; then | |
558 echo "Recovery image created as ${PRISTINE_IMAGE_NAME}" | |
559 fi | |
560 if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then | 508 if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then |
561 echo "Developer image created as ${DEVELOPER_IMAGE_NAME}" | 509 echo "Developer image created as ${DEVELOPER_IMAGE_NAME}" |
562 fi | 510 fi |
563 | 511 |
564 print_time_elapsed | 512 print_time_elapsed |
565 | 513 |
566 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" | 514 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" |
567 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" | 515 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" |
568 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" | 516 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" |
569 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" | 517 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" |
570 echo "from the scripts directory where you entered the chroot." | 518 echo "from the scripts directory where you entered the chroot." |
OLD | NEW |