flatcar-scripts/build_library/build_common.sh
Liam McLoughlin 5b37c5443a Simplify and add flexibility to image creation process
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>
2012-09-23 10:05:12 -07:00

50 lines
1.4 KiB
Bash

# 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.
# Common library file to be sourced by build_image,
# mod_image_for_test.sh, and mod_image_for_recovery.sh. This
# file ensures that library source files needed by all the scripts
# are included once, and also takes care of certain bookeeping tasks
# common to all the scripts.
# SCRIPT_ROOT must be set prior to sourcing this file
. "${SCRIPT_ROOT}/common.sh" || exit 1
# All scripts using this file must be run inside the chroot.
restart_in_chroot_if_needed "$@"
INSTALLER_ROOT=/usr/lib/installer
. "${INSTALLER_ROOT}/chromeos-common.sh" || exit 1
locate_gpt
should_build_image() {
# Fast pass back if we should build all incremental images.
local image_name
local image_to_build
for image_name in "$@"; do
for image_to_build in ${IMAGES_TO_BUILD}; do
[ "${image_to_build}" = "${image_name}" ] && return 0
done
done
return 1
}
# Utility function for creating a copy of an image prior to
# modification from the BUILD_DIR:
# $1: source filename
# $2: destination filename
copy_image() {
local src="${BUILD_DIR}/$1"
local dst="${BUILD_DIR}/$2"
if should_build_image $1; then
echo "Creating $2 from $1..."
$COMMON_PV_CAT "${src}" >"${dst}" || die "Cannot copy $1 to $2"
else
mv "${src}" "${dst}" || die "Cannot move $1 to $2"
fi
}