Extract some common code for sharing with build_image, et al.

BUG=None
TEST=build regular, test, and recovery images

Change-Id: I2d7d073c27d14fb88be6a63953dcc77fc76a0807
Reviewed-on: http://gerrit.chromium.org/gerrit/5512
Tested-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Reviewed-by: David James <davidjames@chromium.org>
This commit is contained in:
J. Richard Barnette 2011-08-08 16:35:02 -07:00 committed by Richard Barnette
parent 2027ca8dfb
commit e4e3decfc0
4 changed files with 97 additions and 134 deletions

View File

@ -12,8 +12,6 @@
SCRIPT_ROOT=$(dirname "$0") SCRIPT_ROOT=$(dirname "$0")
. "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1 . "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1
. "${SCRIPT_ROOT}/build_library/build_gpt.sh" || exit 1
DEFINE_string board "${DEFAULT_BOARD}" \ DEFINE_string board "${DEFAULT_BOARD}" \
"The board to build an image for." "The board to build an image for."
@ -83,14 +81,28 @@ eval set -- "${FLAGS_ARGV}"
# so will die prematurely if 'set -e' is specified before now. # so will die prematurely if 'set -e' is specified before now.
set -e set -e
if [ -z "${FLAGS_board}" ] ; then . "${SCRIPT_ROOT}/build_library/board_options.sh" || exit 1
error "--board is required."
exit 1 # Determine build version.
OVERLAY_CHROMEOS_DIR="${SRC_ROOT}/third_party/chromiumos-overlay/chromeos"
. "${OVERLAY_CHROMEOS_DIR}/config/chromeos_version.sh" || exit 1
. "${SCRIPT_ROOT}/build_library/build_gpt.sh" || exit 1
EMERGE_BOARD_CMD="emerge-$BOARD"
if [ $FLAGS_fast -eq $FLAGS_TRUE ]; then
echo "Using alternate emerge"
EMERGE_BOARD_CMD="$GCLIENT_ROOT/chromite/bin/parallel_emerge"
EMERGE_BOARD_CMD="$EMERGE_BOARD_CMD --board=$BOARD"
fi
if [ $FLAGS_jobs -ne -1 ]; then
EMERGE_JOBS="--jobs=$FLAGS_jobs"
fi fi
# Perform an eclean to remove packages which are not installed # Perform an eclean to remove packages which are not installed
if [[ ${FLAGS_eclean} -eq ${FLAGS_TRUE} ]]; then if [ $FLAGS_eclean -eq $FLAGS_TRUE ]; then
eclean-${FLAGS_board} -d packages eclean-$BOARD -d packages
fi fi
check_blacklist() { check_blacklist() {
@ -102,7 +114,7 @@ check_blacklist() {
return return
fi fi
local blacklisted_packages=$(${SCRIPTS_DIR}/get_package_list \ local blacklisted_packages=$(${SCRIPTS_DIR}/get_package_list \
--board="${FLAGS_board}" chromeos-base/chromeos \ --board="${BOARD}" chromeos-base/chromeos \
| grep -x -f "${package_blacklist_file}") | grep -x -f "${package_blacklist_file}")
if [ -n "${blacklisted_packages}" ]; then if [ -n "${blacklisted_packages}" ]; then
die "Blacklisted packages found: ${blacklisted_packages}." die "Blacklisted packages found: ${blacklisted_packages}."
@ -171,43 +183,6 @@ if [ $((FLAGS_rootfs_size + FLAGS_rootfs_hash_pad)) -gt \
bigger than partition (${FLAGS_rootfs_partition_size} MiB)." bigger than partition (${FLAGS_rootfs_partition_size} MiB)."
fi fi
EMERGE_BOARD_CMD="emerge-${FLAGS_board}"
if [ ${FLAGS_fast} -eq ${FLAGS_TRUE} ]; then
echo "Using alternate emerge"
EMERGE_CMD="${GCLIENT_ROOT}/chromite/bin/parallel_emerge"
EMERGE_BOARD_CMD="${EMERGE_CMD} --board=${FLAGS_board}"
fi
OVERLAY_CHROMEOS_DIR="${SRC_ROOT}/third_party/chromiumos-overlay/chromeos/"
# Determine build version.
. "${OVERLAY_CHROMEOS_DIR}/config/chromeos_version.sh"
BOARD="${FLAGS_board}"
BOARD_ROOT="${FLAGS_build_root}/${BOARD}"
# What cross-build are we targeting?
. "${BOARD_ROOT}/etc/make.conf.board_setup"
LIBC_VERSION=${LIBC_VERSION}
# Figure out ARCH from the given toolchain.
# TODO: Move to common.sh as a function after scripts are switched over.
TC_ARCH=$(echo "${CHOST}" | awk -F'-' '{ print $1 }')
case "${TC_ARCH}" in
arm*)
ARCH="arm"
;;
*86)
ARCH="x86"
;;
*x86_64)
ARCH="amd64"
;;
*)
error "Unable to determine ARCH from toolchain: ${CHOST}"
exit 1
esac
# Configure extra USE or packages for this type of build. # Configure extra USE or packages for this type of build.
EXTRA_PACKAGES="" EXTRA_PACKAGES=""
if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then
@ -238,9 +213,9 @@ emerge_to_image() {
# Use canonical path since some tools (e.g. mount) do not like symlinks. # Use canonical path since some tools (e.g. mount) do not like symlinks.
# Append build attempt to output directory. # Append build attempt to output directory.
IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}" IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}"
OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}" OUTPUT_DIR="${FLAGS_output_root}/${BOARD}/${IMAGE_SUBDIR}"
OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" OUTSIDE_OUTPUT_DIR="../build/images/${BOARD}/${IMAGE_SUBDIR}"
# If we are creating a developer image, also create a pristine image with a # If we are creating a developer image, also create a pristine image with a
# different name. # different name.
@ -280,10 +255,6 @@ STATEFUL_LOOP_DEV=
# translate to /usr/local. # translate to /usr/local.
DEV_IMAGE_ROOT="${STATEFUL_FS_DIR}/dev_image" DEV_IMAGE_ROOT="${STATEFUL_FS_DIR}/dev_image"
if [ ${FLAGS_jobs} -ne -1 ]; then
EMERGE_JOBS="--jobs=${FLAGS_jobs}"
fi
if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then
enable_rootfs_verification_flag="--enable_rootfs_verification" enable_rootfs_verification_flag="--enable_rootfs_verification"
fi fi
@ -688,7 +659,7 @@ emerge_chromeos_test() {
} }
install_autotest_for_factory() { install_autotest_for_factory() {
local autotest_src="${FLAGS_build_root}/${FLAGS_board}/usr/local/autotest" local autotest_src="${BOARD_ROOT}/usr/local/autotest"
local stateful_root="${ROOT_FS_DIR}/usr/local" local stateful_root="${ROOT_FS_DIR}/usr/local"
local autotest_client="${stateful_root}/autotest" local autotest_client="${stateful_root}/autotest"
@ -769,7 +740,7 @@ mod_image_for_test () {
mod_factory_script="${SCRIPTS_DIR}/mod_for_factory_scripts/factory_setup.sh" mod_factory_script="${SCRIPTS_DIR}/mod_for_factory_scripts/factory_setup.sh"
# Run factory setup script to modify the image # Run factory setup script to modify the image
sudo -E GCLIENT_ROOT="${GCLIENT_ROOT}" ROOT_FS_DIR="${ROOT_FS_DIR}" \ sudo -E GCLIENT_ROOT="${GCLIENT_ROOT}" ROOT_FS_DIR="${ROOT_FS_DIR}" \
BOARD="${FLAGS_board}" "${mod_factory_script}" BOARD="${BOARD}" "${mod_factory_script}"
fi fi
# Re-run ldconfig to fix /etc/ldconfig.so.cache. # Re-run ldconfig to fix /etc/ldconfig.so.cache.
@ -841,8 +812,8 @@ rmdir "${ROOT_FS_DIR}" "${STATEFUL_FS_DIR}" "${ESP_FS_DIR}"
# Generating AU generator zip file to run outside chroot # Generating AU generator zip file to run outside chroot
generate_au_zip || echo "Failed generating AU zip file - ignoring Error..." generate_au_zip || echo "Failed generating AU zip file - ignoring Error..."
# Create a 'latest' link # Create a 'latest' link
rm -f ${FLAGS_output_root}/${FLAGS_board}/latest rm -f ${FLAGS_output_root}/${BOARD}/latest
ln -s $(basename ${OUTPUT_DIR}) ${FLAGS_output_root}/${FLAGS_board}/latest ln -s $(basename ${OUTPUT_DIR}) ${FLAGS_output_root}/${BOARD}/latest
echo "Done. Image created in ${OUTPUT_DIR}" echo "Done. Image created in ${OUTPUT_DIR}"
echo "Chromium OS image created as ${PRISTINE_IMAGE_NAME}" echo "Chromium OS image created as ${PRISTINE_IMAGE_NAME}"

View File

@ -0,0 +1,32 @@
# Copyright (c) 2011 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.
if [ -z "${FLAGS_board}" ]; then
error "--board is required."
exit 1
fi
BOARD="${FLAGS_board}"
BOARD_ROOT="${FLAGS_build_root}/${BOARD}"
# What cross-build are we targeting?
. "${BOARD_ROOT}/etc/make.conf.board_setup"
# Figure out ARCH from the given toolchain.
# TODO(jrbarnette): There's a copy of this code in setup_board;
# it should be shared.
case "$(echo "${CHOST}" | awk -F'-' '{ print $1 }')" in
arm*)
ARCH="arm"
;;
*86)
ARCH="x86"
;;
*x86_64)
ARCH="amd64"
;;
*)
error "Unable to determine ARCH from toolchain: ${CHOST}"
exit 1
esac

View File

@ -55,6 +55,10 @@ DEFINE_string keys_dir "/usr/share/vboot/devkeys" \
FLAGS "$@" || exit 1 FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}" eval set -- "${FLAGS_ARGV}"
# Only now can we die on error. shflags functions leak non-zero error codes,
# so will die prematurely if 'set -e' is specified before now.
set -e
if [ $FLAGS_verbose -eq $FLAGS_FALSE ]; then if [ $FLAGS_verbose -eq $FLAGS_FALSE ]; then
exec 2>/dev/null exec 2>/dev/null
# Redirecting to stdout instead of stderr since # Redirecting to stdout instead of stderr since
@ -66,52 +70,28 @@ if [ $FLAGS_verbose -eq $FLAGS_FALSE ]; then
fi fi
set -x # Make debugging with -v easy. set -x # Make debugging with -v easy.
EMERGE_CMD="emerge"
EMERGE_BOARD_CMD="emerge-${FLAGS_board}"
# No board, no default and no image set then we can't find the image . "${SCRIPT_ROOT}/build_library/board_options.sh" || exit 1
if [ -z $FLAGS_image ] && [ -z $FLAGS_board ] ; then
setup_board_warning
die "mod_image_for_recovery failed. No board set and no image set" EMERGE_BOARD_CMD="emerge-$BOARD"
fi
# We have a board name but no image set. Use image at default location # We have a board name but no image set. Use image at default location
if [ -z $FLAGS_image ] ; then if [ -z "$FLAGS_image" ]; then
IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" IMAGES_DIR="$DEFAULT_BUILD_ROOT/images/$BOARD"
FILENAME="chromiumos_image.bin" FILENAME="$CHROMEOS_IMAGE_NAME"
FLAGS_image="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/${FILENAME}" FLAGS_image="$IMAGES_DIR/$(ls -t $IMAGES_DIR 2>&-| head -1)/$FILENAME"
fi fi
# Turn path into an absolute path. # Turn path into an absolute path.
FLAGS_image=`eval readlink -f ${FLAGS_image}` FLAGS_image=$(eval readlink -f "$FLAGS_image")
# Abort early if we can't find the image # Abort early if we can't find the image
if [ ! -f $FLAGS_image ] ; then if [ ! -f "$FLAGS_image" ]; then
echo "No image found at $FLAGS_image" echo "No image found at $FLAGS_image"
exit 1 exit 1
fi fi
# What cross-build are we targeting?
. "${FLAGS_build_root}/${FLAGS_board}/etc/make.conf.board_setup"
# Figure out ARCH from the given toolchain.
# TODO: Move to common.sh as a function after scripts are switched over.
TC_ARCH=$(echo "${CHOST}" | awk -F'-' '{ print $1 }')
case "${TC_ARCH}" in
arm*)
ARCH="arm"
error "ARM recovery mode is still in the works. Use a normal image for now."
;;
*86)
ARCH="x86"
;;
*x86_64)
ARCH="amd64"
;;
*)
error "Unable to determine ARCH from toolchain: ${CHOST}"
exit 1
esac
get_install_vblock() { get_install_vblock() {
# If it exists, we need to copy the vblock over to stateful # If it exists, we need to copy the vblock over to stateful
# This is the real vblock and not the recovery vblock. # This is the real vblock and not the recovery vblock.
@ -390,8 +370,6 @@ cleanup() {
} }
# main process begins here. # main process begins here.
set -e
set -u set -u
IMAGE_DIR="$(dirname "$FLAGS_image")" IMAGE_DIR="$(dirname "$FLAGS_image")"
@ -431,9 +409,9 @@ if [ -z "$INSTALL_VBLOCK" ]; then
fi fi
# Build the recovery kernel. # Build the recovery kernel.
FACTORY_ROOT="${FLAGS_build_root}/${FLAGS_board}/factory-root" FACTORY_ROOT="${BOARD_ROOT}/factory-root"
USE="fbconsole initramfs" emerge_custom_kernel "$FACTORY_ROOT" \ USE="fbconsole initramfs" emerge_custom_kernel "$FACTORY_ROOT" ||
|| failboat "Cannot emerge custom kernel" failboat "Cannot emerge custom kernel"
if [ -z "$FLAGS_kernel_image" ]; then if [ -z "$FLAGS_kernel_image" ]; then
create_recovery_kernel_image create_recovery_kernel_image

View File

@ -49,49 +49,38 @@ DEFINE_boolean standard_backdoor ${FLAGS_TRUE} \
FLAGS "$@" || exit 1 FLAGS "$@" || exit 1
eval set -- "$FLAGS_ARGV" eval set -- "$FLAGS_ARGV"
EMERGE_CMD="emerge" # Only now can we die on error. shflags functions leak non-zero error codes,
EMERGE_BOARD_CMD="emerge-$FLAGS_board" # so will die prematurely if 'set -e' is specified before now.
set -e
. "${SCRIPT_ROOT}/build_library/board_options.sh" || exit 1
EMERGE_BOARD_CMD="emerge-$BOARD"
if [ $FLAGS_fast -eq $FLAGS_TRUE ]; then if [ $FLAGS_fast -eq $FLAGS_TRUE ]; then
echo "Using alternate emerge" echo "Using alternate emerge"
EMERGE_CMD="$GCLIENT_ROOT/chromite/bin/parallel_emerge" EMERGE_BOARD_CMD="$GCLIENT_ROOT/chromite/bin/parallel_emerge"
EMERGE_BOARD_CMD="$EMERGE_CMD --board=$FLAGS_board" EMERGE_BOARD_CMD="$EMERGE_BOARD_CMD --board=$BOARD"
fi fi
if [ $FLAGS_jobs -ne -1 ]; then
# No board, no default and no image set then we can't find the image EMERGE_JOBS="--jobs=$FLAGS_jobs"
if [ -z "$FLAGS_image" -a -z "$FLAGS_board" ] ; then
setup_board_warning
die "mod_image_for_test failed. No board set and no image set"
fi fi
# We have a board name but no image set. Use image at default location # We have a board name but no image set. Use image at default location
if [ -z "$FLAGS_image" ] ; then if [ -z "$FLAGS_image" ]; then
IMAGES_DIR="$DEFAULT_BUILD_ROOT/images/$FLAGS_board" IMAGES_DIR="$DEFAULT_BUILD_ROOT/images/$BOARD"
FILENAME="$CHROMEOS_IMAGE_NAME" FILENAME="$CHROMEOS_IMAGE_NAME"
FLAGS_image="$IMAGES_DIR/$(ls -t $IMAGES_DIR 2>&-| head -1)/$FILENAME" FLAGS_image="$IMAGES_DIR/$(ls -t $IMAGES_DIR 2>&-| head -1)/$FILENAME"
fi fi
# Turn path into an absolute path. # Turn path into an absolute path.
FLAGS_image=$(eval readlink -f $FLAGS_image) FLAGS_image=$(eval readlink -f "$FLAGS_image")
# What cross-build are we targeting? # Abort early if we can't find the image
. "$FLAGS_build_root/$FLAGS_board/etc/make.conf.board_setup" if [ ! -f "$FLAGS_image" ]; then
# Figure out ARCH from the given toolchain. echo "No image found at $FLAGS_image"
# TODO: Move to common.sh as a function after scripts are switched over. exit 1
TC_ARCH=$(echo "$CHOST" | awk -F'-' '{ print $1 }') fi
case "$TC_ARCH" in
arm*)
ARCH="arm"
;;
*86)
ARCH="x86"
;;
*x86_64)
ARCH="amd64"
;;
*)
error "Unable to determine ARCH from toolchain: $CHOST"
exit 1
esac
# Make sure anything mounted in the rootfs/stateful is cleaned up ok on exit. # Make sure anything mounted in the rootfs/stateful is cleaned up ok on exit.
cleanup_mounts() { cleanup_mounts() {
@ -127,7 +116,7 @@ emerge_chromeos_test() {
install_autotest() { install_autotest() {
local autotest_src="$FLAGS_build_root/$FLAGS_board/usr/local/autotest" local autotest_src="${BOARD_ROOT}/usr/local/autotest"
local stateful_root="$ROOT_FS_DIR/usr/local" local stateful_root="$ROOT_FS_DIR/usr/local"
local autotest_client="$stateful_root/autotest" local autotest_client="$stateful_root/autotest"
@ -196,13 +185,6 @@ else
echo "Modifying image $FLAGS_image for test..." echo "Modifying image $FLAGS_image for test..."
fi fi
# Abort early if we can't find the image
if [ ! -f $FLAGS_image -a $FLAGS_inplace -eq $FLAGS_TRUE ] ; then
die "No image found at $FLAGS_image to modify"
fi
set -e
IMAGE_DIR=$(dirname "$FLAGS_image") IMAGE_DIR=$(dirname "$FLAGS_image")
IMAGE_NAME=$(basename "$FLAGS_image") IMAGE_NAME=$(basename "$FLAGS_image")
ROOT_FS_DIR="$IMAGE_DIR/rootfs" ROOT_FS_DIR="$IMAGE_DIR/rootfs"
@ -236,7 +218,7 @@ if [ $FLAGS_factory -eq $FLAGS_TRUE ]; then
MOD_FACTORY_SCRIPT="$SCRIPTS_DIR/mod_for_factory_scripts/factory_setup.sh" MOD_FACTORY_SCRIPT="$SCRIPTS_DIR/mod_for_factory_scripts/factory_setup.sh"
# Run factory setup script to modify the image # Run factory setup script to modify the image
sudo GCLIENT_ROOT="$GCLIENT_ROOT" ROOT_FS_DIR="$ROOT_FS_DIR" \ sudo GCLIENT_ROOT="$GCLIENT_ROOT" ROOT_FS_DIR="$ROOT_FS_DIR" \
BOARD=$FLAGS_board "$MOD_FACTORY_SCRIPT" BOARD="$BOARD" "$MOD_FACTORY_SCRIPT"
fi fi
# Re-run ldconfig to fix /etc/ldconfig.so.cache. # Re-run ldconfig to fix /etc/ldconfig.so.cache.