mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-07 21:16:57 +02:00
This change adds support for building the disk layout from a configuration file. It also cleans up much of the image creation code. install_gpt no longer exists, and has been replaced by cgpt.py's write action. This spits out a file that has two functions that can be called to write a partition layout to a disk/file. This gets rid of the gigantic nest of calculations that built the layout previously. All instances of partition/filesystem sizes in build scripts should now be gone in favour of calls to the cgpt.py tool. create_boot_desc has moved inside the base image creation, in an effort to simplify build_image. load_kernel_test is gone since it's apparently not supposed to be called here anyway (asked wfrichar/rspangler about this one). Base image creation now uses files rather than loop devices when building an image. This means we can simply umount them once we're done and not worry about cleaning up the loop device, since it's been done for us. Hash pad calculation has been removed. This is now set manually inside the partition config file. Hybrid MBR creation is gone, since it's now possible to do that in a board specific hook (see overlay-beaglebone/scripts/board_specific_setup.sh). OEM partition now has a filesystem, which is mounted at /usr/share/oem during emerge so that packages can stash files here. root_fs_dir and friends are still globals, but the long-term idea is to make this not the case. BUG=chromium-os:33817 TEST=All types of images and their respective flows (VM, recovery, test, factory etc) Change-Id: I8a596728a4d1845c930e837bea627f5b6a11c098 Reviewed-on: https://gerrit.chromium.org/gerrit/29931 Commit-Ready: Liam McLoughlin <lmcloughlin@chromium.org> Reviewed-by: Liam McLoughlin <lmcloughlin@chromium.org> Tested-by: Liam McLoughlin <lmcloughlin@chromium.org>
174 lines
5.8 KiB
Bash
Executable File
174 lines
5.8 KiB
Bash
Executable File
# 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.
|
|
|
|
# Shell library for functions and initialization private to
|
|
# build_image, and not specific to any particular kind of image.
|
|
#
|
|
# TODO(jrbarnette): There's nothing holding this code together in
|
|
# one file aside from its lack of anywhere else to go. Probably,
|
|
# this file should get broken up or otherwise reorganized.
|
|
|
|
# Use canonical path since some tools (e.g. mount) do not like symlinks.
|
|
# Append build attempt to output directory.
|
|
IMAGE_SUBDIR="R${CHROME_BRANCH}"
|
|
if [ -z "${FLAGS_version}" ]; then
|
|
IMAGE_SUBDIR="${IMAGE_SUBDIR}-${CHROMEOS_VERSION_STRING}-a\
|
|
${FLAGS_build_attempt}"
|
|
else
|
|
IMAGE_SUBDIR="${IMAGE_SUBDIR}-${FLAGS_version}"
|
|
fi
|
|
BUILD_DIR="${FLAGS_output_root}/${BOARD}/${IMAGE_SUBDIR}"
|
|
OUTSIDE_OUTPUT_DIR="../build/images/${BOARD}/${IMAGE_SUBDIR}"
|
|
IMAGES_TO_BUILD=
|
|
|
|
EMERGE_BOARD_CMD="$GCLIENT_ROOT/chromite/bin/parallel_emerge"
|
|
EMERGE_BOARD_CMD="$EMERGE_BOARD_CMD --board=$BOARD"
|
|
|
|
export INSTALL_MASK="${DEFAULT_INSTALL_MASK}"
|
|
|
|
if [[ $FLAGS_jobs -ne -1 ]]; then
|
|
EMERGE_JOBS="--jobs=$FLAGS_jobs"
|
|
fi
|
|
|
|
# Populates list of IMAGES_TO_BUILD from args passed in.
|
|
# Arguments should be the shortnames of images we want to build.
|
|
get_images_to_build() {
|
|
local image_to_build
|
|
for image_to_build in $*; do
|
|
# Shflags leaves "'"s around ARGV.
|
|
case ${image_to_build} in
|
|
\'base\' )
|
|
IMAGES_TO_BUILD="${IMAGES_TO_BUILD} ${CHROMEOS_BASE_IMAGE_NAME}"
|
|
;;
|
|
\'dev\' )
|
|
IMAGES_TO_BUILD="${IMAGES_TO_BUILD} ${CHROMEOS_DEVELOPER_IMAGE_NAME}"
|
|
;;
|
|
\'test\' )
|
|
IMAGES_TO_BUILD="${IMAGES_TO_BUILD} ${CHROMEOS_TEST_IMAGE_NAME}"
|
|
;;
|
|
\'factory_test\' )
|
|
IMAGES_TO_BUILD="${IMAGES_TO_BUILD} ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"
|
|
;;
|
|
\'factory_install\' )
|
|
IMAGES_TO_BUILD="${IMAGES_TO_BUILD} \
|
|
${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}"
|
|
;;
|
|
* )
|
|
die "${image_to_build} is not an image specification."
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Set default if none specified.
|
|
if [ -z "${IMAGES_TO_BUILD}" ]; then
|
|
IMAGES_TO_BUILD=${CHROMEOS_DEVELOPER_IMAGE_NAME}
|
|
fi
|
|
|
|
info "The following images will be built ${IMAGES_TO_BUILD}."
|
|
}
|
|
|
|
# Look at flags to determine which image types we should build.
|
|
parse_build_image_args() {
|
|
get_images_to_build ${FLAGS_ARGV}
|
|
if should_build_image ${CHROMEOS_TEST_IMAGE_NAME}; then
|
|
if should_build_image "${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"; then
|
|
die_notrace "Cannot build both the test and factory_test images."
|
|
fi
|
|
fi
|
|
if should_build_image ${CHROMEOS_BASE_IMAGE_NAME} \
|
|
${CHROMEOS_DEVELOPER_IMAGE_NAME} ${CHROMEOS_TEST_IMAGE_NAME} \
|
|
${CHROMEOS_FACTORY_TEST_IMAGE_NAME} &&
|
|
should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then
|
|
die_notrace \
|
|
"Can't build ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME} with any other" \
|
|
"image."
|
|
fi
|
|
if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then
|
|
FLAGS_enable_rootfs_verification=${FLAGS_FALSE}
|
|
fi
|
|
}
|
|
|
|
check_blacklist() {
|
|
info "Verifying that the base image does not contain a blacklisted package."
|
|
info "Generating list of packages for chromeos-base/chromeos."
|
|
local package_blacklist_file="${BUILD_LIBRARY_DIR}/chromeos_blacklist"
|
|
if [ ! -e "${package_blacklist_file}" ]; then
|
|
warn "Missing blacklist file."
|
|
return
|
|
fi
|
|
local blacklisted_packages=$(${SCRIPTS_DIR}/get_package_list \
|
|
--board="${BOARD}" chromeos-base/chromeos \
|
|
| grep -x -f "${package_blacklist_file}")
|
|
if [ -n "${blacklisted_packages}" ]; then
|
|
die "Blacklisted packages found: ${blacklisted_packages}."
|
|
fi
|
|
info "No blacklisted packages found."
|
|
}
|
|
|
|
make_salt() {
|
|
# It is not important that the salt be cryptographically strong; it just needs
|
|
# to be different for each release. The purpose of the salt is just to ensure
|
|
# that if someone collides a block in one release, they can't reuse it in
|
|
# future releases.
|
|
xxd -l 32 -p -c 32 /dev/urandom
|
|
}
|
|
|
|
create_boot_desc() {
|
|
local image_type=$1
|
|
|
|
local enable_rootfs_verification_flag=""
|
|
if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then
|
|
enable_rootfs_verification_flag="--enable_rootfs_verification"
|
|
fi
|
|
|
|
[ -z "${FLAGS_verity_salt}" ] && FLAGS_verity_salt=$(make_salt)
|
|
cat <<EOF > ${BUILD_DIR}/boot.desc
|
|
--board=${BOARD}
|
|
--image_type=${image_type}
|
|
--arch="${ARCH}"
|
|
--keys_dir="${DEVKEYSDIR}"
|
|
--usb_disk="${FLAGS_usb_disk}"
|
|
--nocleanup_dirs
|
|
--verity_algorithm=sha1
|
|
${enable_rootfs_verification_flag}
|
|
EOF
|
|
}
|
|
|
|
delete_prompt() {
|
|
echo "An error occurred in your build so your latest output directory" \
|
|
"is invalid."
|
|
|
|
# Only prompt if both stdin and stdout are a tty. If either is not a tty,
|
|
# then the user may not be present, so we shouldn't bother prompting.
|
|
if [ -t 0 -a -t 1 -a "${USER}" != 'chrome-bot' ]; then
|
|
read -p "Would you like to delete the output directory (y/N)? " SURE
|
|
SURE="${SURE:0:1}" # Get just the first character.
|
|
else
|
|
SURE="y"
|
|
echo "Running in non-interactive mode so deleting output directory."
|
|
fi
|
|
if [ "${SURE}" == "y" ] ; then
|
|
sudo rm -rf "${BUILD_DIR}"
|
|
echo "Deleted ${BUILD_DIR}"
|
|
else
|
|
echo "Not deleting ${BUILD_DIR}."
|
|
fi
|
|
}
|
|
|
|
generate_au_zip () {
|
|
local lgenerateauzip="${BUILD_LIBRARY_DIR}/generate_au_zip.py"
|
|
local largs="-o ${BUILD_DIR}"
|
|
test ! -d "${BUILD_DIR}" && mkdir -p "${BUILD_DIR}"
|
|
info "Running ${lgenerateauzip} ${largs} for generating AU updater zip file"
|
|
$lgenerateauzip $largs
|
|
}
|
|
|
|
# Basic command to emerge binary packages into the target image.
|
|
# Arguments to this command are passed as addition options/arguments
|
|
# to the basic emerge command.
|
|
emerge_to_image() {
|
|
sudo -E ${EMERGE_BOARD_CMD} --root-deps=rdeps --usepkgonly -v \
|
|
"$@" ${EMERGE_JOBS}
|
|
}
|