#!/bin/bash # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # Script to build a bootable keyfob-based chromeos system image from within # a chromiumos setup. This assumes that all needed packages have been built into # the given target's root with binary packages turned on. This script will # build the Chrome OS image using only pre-built binary packages. SCRIPT_ROOT=$(dirname $(readlink -f "$0")) . "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1 # Developer-visible flags. DEFINE_string board "${DEFAULT_BOARD}" \ "The board to build an image for." DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/containers" \ "Directory in which to place image result directories (named by version)" FLAGS_HELP="USAGE: build_image [flags] [list of images to build]. This script is used to build a CoreOS container. CoreOS comes in many different forms. This scripts can be used to build the following: base - Pristine Chromium OS image. As similar to Chrome OS as possible. dev - Developer image. Like base but with additional developer packages. test - Like dev, but with additional test specific packages and can be easily used for automated testing using scripts like run_remote_tests, etc. Examples: build_image --board= dev test - builds developer and test images. build_image --board= factory_install - builds a factory install shim. ... " show_help_if_requested "$@" # The following options are advanced options, only available to those willing # to read the source code. They are not shown in help output, since they are # not needed for the typical developer workflow. DEFINE_integer build_attempt 1 \ "The build attempt for this image build." DEFINE_integer jobs -1 \ "How many packages to build in parallel at maximum." DEFINE_boolean replace ${FLAGS_FALSE} \ "Overwrite existing output, if any." DEFINE_string symlink "latest" \ "Symlink name to use for this image." DEFINE_string version "" \ "Overrides version number in name to this version." # Parse command line. FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" # Only now can we die on error. shflags functions leak non-zero error codes, # so will die prematurely if 'switch_to_strict_mode' is specified before now. switch_to_strict_mode # Determine build version. OVERLAY_CHROMEOS_DIR="${SRC_ROOT}/third_party/coreos-overlay/coreos" . "${OVERLAY_CHROMEOS_DIR}/config/coreos_version.sh" || exit 1 # N.B. Ordering matters for some of the libraries below, because # some of the files contain initialization used by later files. . "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1 . "${BUILD_LIBRARY_DIR}/disk_layout_util.sh" || exit 1 . "${BUILD_LIBRARY_DIR}/mount_gpt_util.sh" || exit 1 . "${BUILD_LIBRARY_DIR}/build_image_util.sh" || exit 1 . "${BUILD_LIBRARY_DIR}/base_image_util.sh" || exit 1 . "${BUILD_LIBRARY_DIR}/dev_image_util.sh" || exit 1 . "${BUILD_LIBRARY_DIR}/test_image_util.sh" || exit 1 . "${BUILD_LIBRARY_DIR}/test_image_content.sh" || exit 1 . "${BUILD_LIBRARY_DIR}/base_container_util.sh" || exit 1 parse_build_image_args for overlay in $(cros_list_overlays --board "$BOARD"); do setup_sh="${overlay}/scripts/board_specific_setup.sh" if [[ -e ${setup_sh} ]]; then source "${setup_sh}" fi done # TODO: BASE_PACKAGE="coreos-base/coreos" # Tweak flags, configure extra USE flags, and set base packages for the factory # install shim. if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then # TODO: Build a separated ebuild for the install shim to reduce size. INSTALL_MASK="${FACTORY_SHIM_INSTALL_MASK}" # Add the cros_factory_install boot arg. FLAGS_boot_args="${FLAGS_boot_args} cros_factory_install" BASE_PACKAGE="coreos-base/chromeos-installshim" export USE="${USE} initramfs vfat tpm i2cdev" # On ARM, fbconsole is required to fix a display driver bug. if [ "${ARCH}" = "arm" ] ; then export USE="${USE} fbconsole" fi fi if should_build_image ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then # Disable module restrictions on factory test image to allow for # external third party drivers in /usr/local. FLAGS_boot_args="${FLAGS_boot_args} lsm.module_locking=0" fi # TODO: # If we are creating a developer image, also create a pristine image with a # different name. PRISTINE_IMAGE_NAME= if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then PRISTINE_IMAGE_NAME=${CHROMEOS_FACTORY_INSTALL_SHIM_NAME} else PRISTINE_IMAGE_NAME=${CHROMEOS_BASE_IMAGE_NAME} fi DEVKEYSDIR="/usr/share/vboot/devkeys" eclean-$BOARD -d packages if [[ ${skip_blacklist_check} -ne 1 ]]; then check_blacklist fi # Check that the build root is sane. if [[ ${skip_test_build_root} -ne 1 ]]; then "${BUILD_LIBRARY_DIR}/test_build_root" --root="${BOARD_ROOT}" fi # Hack to fix bug where x86_64 CHOST line gets incorrectly added. # ToDo(msb): remove this hack. PACKAGES_FILE="${BOARD_ROOT}/packages/Packages" sudo sed -e "s/CHOST: x86_64-pc-linux-gnu//" -i "${PACKAGES_FILE}" # Handle existing directory. if [[ -e "${BUILD_DIR}" ]]; then if [[ ${FLAGS_replace} -eq ${FLAGS_TRUE} ]]; then sudo rm -rf "${BUILD_DIR}" else error "Directory ${BUILD_DIR} already exists." error "Use --build_attempt option to specify an unused attempt." error "Or use --replace if you want to overwrite this directory." die "Unwilling to overwrite ${BUILD_DIR}." fi fi # Create the output directory and temporary mount points. mkdir -p "${BUILD_DIR}" # Create the base image. create_base_container ${PRISTINE_IMAGE_NAME} ${FLAGS_enable_rootfs_verification} \ ${FLAGS_enable_bootcache} # Running board-specific setup if any exists. if type board_setup &>/dev/null; then board_setup "${BUILD_DIR}/${PRISTINE_IMAGE_NAME}" fi # Create a developer image if an image that is based on it is requested. if should_build_image ${CHROMEOS_DEVELOPER_IMAGE_NAME} \ ${CHROMEOS_TEST_IMAGE_NAME} ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then install_dev_packages ${CHROMEOS_DEVELOPER_IMAGE_NAME} fi # Generating AU generator zip file to run outside chroot generate_au_zip || echo "Failed generating AU zip file - ignoring Error..." # Create a named symlink. LINK_NAME="${FLAGS_output_root}/${BOARD}/${FLAGS_symlink}" ln -sfT $(basename ${BUILD_DIR}) ${LINK_NAME} echo "Done. Image(s) created in ${BUILD_DIR}" # Print out the images we generated. if should_build_image ${CHROMEOS_BASE_IMAGE_NAME}; then echo "Non-developer Chromium OS container created as ${PRISTINE_IMAGE_NAME}" fi if should_build_image ${CHROMEOS_DEVELOPER_IMAGE_NAME}; then echo "Developer container created as ${CHROMEOS_DEVELOPER_IMAGE_NAME}" fi if should_build_image ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then echo "Factory test container created as ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}" fi if should_build_image ${CHROMEOS_TEST_IMAGE_NAME}; then echo "Test container created as ${CHROMEOS_TEST_IMAGE_NAME}" fi command_completed cat << EOF systemd-nspawn -b -D ${OUTSIDE_OUTPUT_DIR} EOF