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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 DEFINE_integer verity_error_behavior 3 \ | 101 DEFINE_integer verity_error_behavior 3 \ |
102 "Kernel verified boot error behavior (0: I/O errors, 1: panic, 2: nothing, \ | 102 "Kernel verified boot error behavior (0: I/O errors, 1: panic, 2: nothing, \ |
103 3: cros) Default: 3" | 103 3: cros) Default: 3" |
104 DEFINE_integer verity_depth 1 \ | 104 DEFINE_integer verity_depth 1 \ |
105 "Kernel verified boot hash tree depth. Default: 1" | 105 "Kernel verified boot hash tree depth. Default: 1" |
106 DEFINE_integer verity_max_ios -1 \ | 106 DEFINE_integer verity_max_ios -1 \ |
107 "Number of outstanding I/O operations dm-verity caps at. Default: -1" | 107 "Number of outstanding I/O operations dm-verity caps at. Default: -1" |
108 DEFINE_string verity_algorithm "sha1" \ | 108 DEFINE_string verity_algorithm "sha1" \ |
109 "Cryptographic hash algorithm used for kernel vboot. Default : sha1" | 109 "Cryptographic hash algorithm used for kernel vboot. Default : sha1" |
110 | 110 |
111 DEFINE_string oem_customization "" \ | |
112 "Path to directory containing OEM partner partition contents" | |
113 | |
114 # Parse command line. | 111 # Parse command line. |
115 FLAGS "$@" || exit 1 | 112 FLAGS "$@" || exit 1 |
116 eval set -- "${FLAGS_ARGV}" | 113 eval set -- "${FLAGS_ARGV}" |
117 | 114 |
118 # Only now can we die on error. shflags functions leak non-zero error codes, | 115 # Only now can we die on error. shflags functions leak non-zero error codes, |
119 # so will die prematurely if 'set -e' is specified before now. | 116 # so will die prematurely if 'set -e' is specified before now. |
120 set -e | 117 set -e |
121 | 118 |
122 if [ -z "${FLAGS_board}" ] ; then | 119 if [ -z "${FLAGS_board}" ] ; then |
123 error "--board is required." | 120 error "--board is required." |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 BOARD="${FLAGS_board}" | 239 BOARD="${FLAGS_board}" |
243 BOARD_ROOT="${FLAGS_build_root}/${BOARD}" | 240 BOARD_ROOT="${FLAGS_build_root}/${BOARD}" |
244 | 241 |
245 ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" | 242 ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" |
246 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" | 243 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" |
247 ROOT_FS_HASH="${OUTPUT_DIR}/rootfs.hash" | 244 ROOT_FS_HASH="${OUTPUT_DIR}/rootfs.hash" |
248 | 245 |
249 STATEFUL_FS_IMG="${OUTPUT_DIR}/stateful_partition.image" | 246 STATEFUL_FS_IMG="${OUTPUT_DIR}/stateful_partition.image" |
250 STATEFUL_FS_DIR="${OUTPUT_DIR}/stateful_partition" | 247 STATEFUL_FS_DIR="${OUTPUT_DIR}/stateful_partition" |
251 | 248 |
252 OEM_FS_IMG="${OUTPUT_DIR}/partner_partition.image" | |
253 OEM_FS_DIR="${OUTPUT_DIR}/partner_partition" | |
254 | |
255 ESP_FS_IMG=${OUTPUT_DIR}/esp.image | 249 ESP_FS_IMG=${OUTPUT_DIR}/esp.image |
256 ESP_FS_DIR=${OUTPUT_DIR}/esp | 250 ESP_FS_DIR=${OUTPUT_DIR}/esp |
257 | 251 |
258 DEVKEYSDIR="/usr/share/vboot/devkeys" | 252 DEVKEYSDIR="/usr/share/vboot/devkeys" |
259 | 253 |
260 LOOP_DEV= | 254 LOOP_DEV= |
261 STATEFUL_LOOP_DEV= | 255 STATEFUL_LOOP_DEV= |
262 OEM_LOOP_DEV= | |
263 ESP_LOOP_DEV= | 256 ESP_LOOP_DEV= |
264 | 257 |
265 # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will | 258 # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will |
266 # be installed on the stateful dir. On a Chromium OS system, this will | 259 # be installed on the stateful dir. On a Chromium OS system, this will |
267 # translate to /usr/local. | 260 # translate to /usr/local. |
268 DEV_IMAGE_ROOT="${STATEFUL_FS_DIR}/dev_image" | 261 DEV_IMAGE_ROOT="${STATEFUL_FS_DIR}/dev_image" |
269 | 262 |
270 # What cross-build are we targeting? | 263 # What cross-build are we targeting? |
271 . "${BOARD_ROOT}/etc/make.conf.board_setup" | 264 . "${BOARD_ROOT}/etc/make.conf.board_setup" |
272 LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"} | 265 LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"} |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 cleanup_rootfs_loop() { | 315 cleanup_rootfs_loop() { |
323 sudo umount -d "${ROOT_FS_DIR}" | 316 sudo umount -d "${ROOT_FS_DIR}" |
324 } | 317 } |
325 | 318 |
326 cleanup_stateful_fs_loop() { | 319 cleanup_stateful_fs_loop() { |
327 sudo umount "${ROOT_FS_DIR}/usr/local" | 320 sudo umount "${ROOT_FS_DIR}/usr/local" |
328 sudo umount "${ROOT_FS_DIR}/var" | 321 sudo umount "${ROOT_FS_DIR}/var" |
329 sudo umount -d "${STATEFUL_FS_DIR}" | 322 sudo umount -d "${STATEFUL_FS_DIR}" |
330 } | 323 } |
331 | 324 |
332 cleanup_oem_fs_loop() { | |
333 sudo umount -d "${OEM_FS_DIR}" | |
334 } | |
335 | |
336 | |
337 cleanup_esp_loop() { | 325 cleanup_esp_loop() { |
338 sudo umount -d "${ESP_FS_DIR}" | 326 sudo umount -d "${ESP_FS_DIR}" |
339 } | 327 } |
340 | 328 |
341 cleanup() { | 329 cleanup() { |
342 # Disable die on error. | 330 # Disable die on error. |
343 set +e | 331 set +e |
344 | 332 |
345 if [[ -n "${STATEFUL_LOOP_DEV}" ]]; then | 333 if [[ -n "${STATEFUL_LOOP_DEV}" ]]; then |
346 cleanup_stateful_fs_loop | 334 cleanup_stateful_fs_loop |
347 STATEFUL_LOOP_DEV= | 335 STATEFUL_LOOP_DEV= |
348 fi | 336 fi |
349 | 337 |
350 if [[ -n "${OEM_LOOP_DEV}" ]]; then | |
351 cleanup_oem_fs_loop | |
352 fi | |
353 | |
354 if [[ -n "${LOOP_DEV}" ]]; then | 338 if [[ -n "${LOOP_DEV}" ]]; then |
355 cleanup_rootfs_loop | 339 cleanup_rootfs_loop |
356 LOOP_DEV= | 340 LOOP_DEV= |
357 fi | 341 fi |
358 | 342 |
359 if [[ -n "${ESP_LOOP_DEV}" ]]; then | 343 if [[ -n "${ESP_LOOP_DEV}" ]]; then |
360 cleanup_esp_loop | 344 cleanup_esp_loop |
361 ESP_LOOP_DEV= | 345 ESP_LOOP_DEV= |
362 fi | 346 fi |
363 | 347 |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 seek=$((STATEFUL_SIZE_BYTES - 1)) | 590 seek=$((STATEFUL_SIZE_BYTES - 1)) |
607 | 591 |
608 # Tune and mount the stateful partition. | 592 # Tune and mount the stateful partition. |
609 UUID=$(uuidgen) | 593 UUID=$(uuidgen) |
610 DISK_LABEL="C-STATE" | 594 DISK_LABEL="C-STATE" |
611 sudo losetup "${STATEFUL_LOOP_DEV}" "${STATEFUL_FS_IMG}" | 595 sudo losetup "${STATEFUL_LOOP_DEV}" "${STATEFUL_FS_IMG}" |
612 sudo mkfs.ext3 "${STATEFUL_LOOP_DEV}" | 596 sudo mkfs.ext3 "${STATEFUL_LOOP_DEV}" |
613 sudo tune2fs -L "${DISK_LABEL}" -U "${UUID}" -c 0 -i 0 "${STATEFUL_LOOP_DEV}" | 597 sudo tune2fs -L "${DISK_LABEL}" -U "${UUID}" -c 0 -i 0 "${STATEFUL_LOOP_DEV}" |
614 sudo mount "${STATEFUL_LOOP_DEV}" "${STATEFUL_FS_DIR}" | 598 sudo mount "${STATEFUL_LOOP_DEV}" "${STATEFUL_FS_DIR}" |
615 | 599 |
616 # Create OEM partner partition. | |
617 OEM_LOOP_DEV=$(sudo losetup -f) | |
618 if [ -z "${OEM_LOOP_DEV}" ] ; then | |
619 echo "No free loop device. Free up a loop device or reboot. exiting. " | |
620 exit 1 | |
621 fi | |
622 OEM_SIZE_BYTES=$((1024 * 1024 * 16)) | |
623 dd if=/dev/zero of="${OEM_FS_IMG}" bs=1 count=1 seek=$((OEM_SIZE_BYTES - 1)) | |
624 | |
625 # Tune and mount OEM partner partition. | |
626 UUID=$(uuidgen) | |
627 DISK_LABEL="C-OEM" | |
628 sudo losetup "${OEM_LOOP_DEV}" "${OEM_FS_IMG}" | |
629 sudo mkfs.ext3 "${OEM_LOOP_DEV}" | |
630 sudo tune2fs -L "${DISK_LABEL}" -U "${UUID}" -c 0 -i 0 "${OEM_LOOP_DEV}" | |
631 sudo mount "${OEM_LOOP_DEV}" "${OEM_FS_DIR}" | |
632 | |
633 # Populate OEM partner partition. | |
634 if [ ! -z "${FLAGS_oem_customization}" ]; then | |
635 if [ ! -d ${FLAGS_oem_customization} ]; then | |
636 echo "Specified OEM content directory does not exist. exiting." | |
637 exit 1 | |
638 fi | |
639 for ITEM in `ls -A ${FLAGS_oem_customization}` | |
640 do sudo cp -a "${FLAGS_oem_customization}/$ITEM" "${OEM_FS_DIR}" | |
641 done | |
642 sudo find "${OEM_FS_DIR}" -type d -exec chmod 755 "{}" \; | |
643 sudo find "${OEM_FS_DIR}" -type f -exec chmod 644 "{}" \; | |
644 sudo chown -R root:root "${OEM_FS_DIR}" | |
645 else | |
646 echo "Empty OEM partition: OEM customizations will not be applied." | |
647 fi | |
648 | |
649 # -- Install packages into the root file system -- | 600 # -- Install packages into the root file system -- |
650 | 601 |
651 # We need to install libc manually from the cross toolchain. | 602 # We need to install libc manually from the cross toolchain. |
652 # TODO: Improve this? We only want libc and not the whole toolchain. | 603 # TODO: Improve this? We only want libc and not the whole toolchain. |
653 PKGDIR="/var/lib/portage/pkgs/cross/" | 604 PKGDIR="/var/lib/portage/pkgs/cross/" |
654 sudo tar jxvpf \ | 605 sudo tar jxvpf \ |
655 "${PKGDIR}/${CHOST}/cross-${CHOST}"/glibc-${LIBC_VERSION}.tbz2 \ | 606 "${PKGDIR}/${CHOST}/cross-${CHOST}"/glibc-${LIBC_VERSION}.tbz2 \ |
656 -C "${ROOT_FS_DIR}" --strip-components=3 \ | 607 -C "${ROOT_FS_DIR}" --strip-components=3 \ |
657 --exclude=usr/include --exclude=sys-include --exclude=*.a --exclude=*.o | 608 --exclude=usr/include --exclude=sys-include --exclude=*.a --exclude=*.o |
658 | 609 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 local largs="-o ${OUTPUT_DIR}" | 711 local largs="-o ${OUTPUT_DIR}" |
761 test ! -d "${OUTPUT_DIR}" && mkdir -p "${OUTPUT_DIR}" | 712 test ! -d "${OUTPUT_DIR}" && mkdir -p "${OUTPUT_DIR}" |
762 info "Running ${lgenerateauzip} ${largs} for generating AU updater zip file" | 713 info "Running ${lgenerateauzip} ${largs} for generating AU updater zip file" |
763 $lgenerateauzip $largs | 714 $lgenerateauzip $largs |
764 } | 715 } |
765 | 716 |
766 # Create the output directory. | 717 # Create the output directory. |
767 mkdir -p "${OUTPUT_DIR}" | 718 mkdir -p "${OUTPUT_DIR}" |
768 mkdir -p "${ROOT_FS_DIR}" | 719 mkdir -p "${ROOT_FS_DIR}" |
769 mkdir -p "${STATEFUL_FS_DIR}" | 720 mkdir -p "${STATEFUL_FS_DIR}" |
770 mkdir -p "${OEM_FS_DIR}" | |
771 mkdir -p "${ESP_FS_DIR}" | 721 mkdir -p "${ESP_FS_DIR}" |
772 | 722 |
773 # Preserve old images by copying them forward for --preserve. | 723 # Preserve old images by copying them forward for --preserve. |
774 if [[ $FLAGS_preserve -eq ${FLAGS_TRUE} ]] ; then | 724 if [[ $FLAGS_preserve -eq ${FLAGS_TRUE} ]] ; then |
775 if [[ -f ${PREVIOUS_DIR}/${PRISTINE_IMAGE_NAME} ]] ; then | 725 if [[ -f ${PREVIOUS_DIR}/${PRISTINE_IMAGE_NAME} ]] ; then |
776 # Copy forward pristine image, and associated files | 726 # Copy forward pristine image, and associated files |
777 cp ${PREVIOUS_DIR}/*.sh ${PREVIOUS_DIR}/config.txt ${OUTPUT_DIR} | 727 cp ${PREVIOUS_DIR}/*.sh ${PREVIOUS_DIR}/config.txt ${OUTPUT_DIR} |
778 cp ${PREVIOUS_DIR}/${PRISTINE_IMAGE_NAME} ${OUTPUT_DIR} | 728 cp ${PREVIOUS_DIR}/${PRISTINE_IMAGE_NAME} ${OUTPUT_DIR} |
779 | 729 |
780 # Copy forward the developer image, if we already copied forward the base. | 730 # Copy forward the developer image, if we already copied forward the base. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 fi | 788 fi |
839 | 789 |
840 update_dev_packages ${DEVELOPER_IMAGE_NAME} | 790 update_dev_packages ${DEVELOPER_IMAGE_NAME} |
841 ${SCRIPTS_DIR}/bin/cros_make_image_bootable "${OUTPUT_DIR}" \ | 791 ${SCRIPTS_DIR}/bin/cros_make_image_bootable "${OUTPUT_DIR}" \ |
842 "${DEVELOPER_IMAGE_NAME}" \ | 792 "${DEVELOPER_IMAGE_NAME}" \ |
843 ${crosbug12352_flag} | 793 ${crosbug12352_flag} |
844 fi | 794 fi |
845 | 795 |
846 # Clean up temporary files. | 796 # Clean up temporary files. |
847 rm -f "${ROOT_FS_IMG}" "${STATEFUL_FS_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \ | 797 rm -f "${ROOT_FS_IMG}" "${STATEFUL_FS_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \ |
848 "${ESP_FS_IMG}" "${OEM_FS_IMG}" "${OUTPUT_DIR}/vmlinuz_hd.vblock" | 798 "${ESP_FS_IMG}" "${OUTPUT_DIR}/vmlinuz_hd.vblock" |
849 rmdir "${ROOT_FS_DIR}" "${STATEFUL_FS_DIR}" "${OEM_FS_DIR}" "${ESP_FS_DIR}" | 799 rmdir "${ROOT_FS_DIR}" "${STATEFUL_FS_DIR}" "${ESP_FS_DIR}" |
850 | 800 |
851 # Generating AU generator zip file to run outside chroot | 801 # Generating AU generator zip file to run outside chroot |
852 generate_au_zip || echo "Failed generating AU zip file - ignoring Error..." | 802 generate_au_zip || echo "Failed generating AU zip file - ignoring Error..." |
853 # Create a 'latest' link | 803 # Create a 'latest' link |
854 rm -f ${FLAGS_output_root}/${FLAGS_board}/latest | 804 rm -f ${FLAGS_output_root}/${FLAGS_board}/latest |
855 ln -s $(basename ${OUTPUT_DIR}) ${FLAGS_output_root}/${FLAGS_board}/latest | 805 ln -s $(basename ${OUTPUT_DIR}) ${FLAGS_output_root}/${FLAGS_board}/latest |
856 | 806 |
857 echo "Done. Image created in ${OUTPUT_DIR}" | 807 echo "Done. Image created in ${OUTPUT_DIR}" |
858 echo "Chromium OS image created as ${PRISTINE_IMAGE_NAME}" | 808 echo "Chromium OS image created as ${PRISTINE_IMAGE_NAME}" |
859 if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then | 809 if [ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]; then |
860 echo "Developer image created as ${DEVELOPER_IMAGE_NAME}" | 810 echo "Developer image created as ${DEVELOPER_IMAGE_NAME}" |
861 fi | 811 fi |
862 | 812 |
863 print_time_elapsed | 813 print_time_elapsed |
864 | 814 |
865 echo "To copy to USB keyfob, do something like:" | 815 echo "To copy to USB keyfob, do something like:" |
866 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" | 816 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" |
867 echo "To convert to VMWare image, INSIDE the chroot, do something like:" | 817 echo "To convert to VMWare image, INSIDE the chroot, do something like:" |
868 echo " ./image_to_vm.sh --from=${OUTSIDE_OUTPUT_DIR} --board=${BOARD}" | 818 echo " ./image_to_vm.sh --from=${OUTSIDE_OUTPUT_DIR} --board=${BOARD}" |
869 echo "from the scripts directory where you entered the chroot." | 819 echo "from the scripts directory where you entered the chroot." |
OLD | NEW |