flatcar-scripts/build_library/dev_image_util.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

118 lines
4.4 KiB
Bash
Executable File

# 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.
# Shell function library for functions specific to creating dev
# images from base images. The main function for export in this
# library is 'install_dev_packages'.
# Modifies an existing image to add development packages.
# Takes as an arg the name of the image to be created.
install_dev_packages() {
local image_name=$1
info "Adding developer packages to ${image_name}"
trap "unmount_image ; delete_prompt" EXIT
mount_image "${BUILD_DIR}/${image_name}" "${root_fs_dir}" \
"${stateful_fs_dir}" "${esp_fs_dir}"
# Determine the root dir for developer packages.
local root_dev_dir="${root_fs_dir}/usr/local"
# Install dev-specific init scripts into / from chromeos-dev-init.
emerge_to_image --root="${root_fs_dir}" chromeos-dev-init
# Install developer packages described in chromeos-dev.
emerge_to_image --root="${root_dev_dir}" chromeos-dev
# Copy over the libc debug info so that gdb
# works with threads and also for a better debugging experience.
sudo mkdir -p "${root_fs_dir}/usr/local/usr/lib/debug"
pbzip2 -dc --ignore-trailing-garbage=1 "${LIBC_PATH}" | \
sudo tar xpf - -C "${root_fs_dir}/usr/local/usr/lib/debug" \
./usr/lib/debug/usr/${CHOST} --strip-components=6
# Since gdb only looks in /usr/lib/debug, symlink the /usr/local
# path so that it is found automatically.
sudo ln -s /usr/local/usr/lib/debug "${root_fs_dir}/usr/lib/debug"
# Install the bare necessary files so that the "emerge" command works
sudo cp -a ${root_dev_dir}/share/portage ${root_fs_dir}/usr/share
sudo sed -i s,/usr/bin/wget,wget, \
${root_fs_dir}/usr/share/portage/config/make.globals
sudo mkdir -p ${root_fs_dir}/etc/make.profile
# Re-run ldconfig to fix /etc/ldconfig.so.cache.
sudo /sbin/ldconfig -r "${root_fs_dir}"
# Mark the image as a developer image (input to chromeos_startup).
# TODO(arkaitzr): Remove this file when applications no longer rely on it
# (crosbug.com/16648). The preferred way of determining developer mode status
# is via crossystem cros_debug?1 (checks boot args for "cros_debug").
sudo mkdir -p "${root_fs_dir}/root"
sudo touch "${root_fs_dir}/root/.dev_mode"
# Additional changes to developer image.
# Leave core files for developers to inspect.
sudo touch "${root_fs_dir}/root/.leave_core"
# This hack is only needed for devs who have old versions of glibc, which
# filtered out ldd when cross-compiling. TODO(davidjames): Remove this hack
# once everybody has upgraded to a new version of glibc.
if [[ ! -x "${root_fs_dir}/usr/bin/ldd" ]]; then
sudo cp -a "$(which ldd)" "${root_fs_dir}/usr/bin"
fi
# If vim is installed, then a vi symlink would probably help.
if [[ -x "${root_fs_dir}/usr/local/bin/vim" ]]; then
sudo ln -sf vim "${root_fs_dir}/usr/local/bin/vi"
fi
# If pygtk is installed in stateful-dev, then install a path.
if [[ -d \
"${root_fs_dir}/usr/local/lib/python2.6/site-packages/gtk-2.0" ]]; then
sudo bash -c "\
echo gtk-2.0 > \
${root_fs_dir}/usr/local/lib/python2.6/site-packages/pygtk.pth"
fi
# File searches /usr/share by default, so add a wrapper script so it
# can find the right path in /usr/local.
local path="${root_fs_dir}/usr/local/bin/file"
if [[ -x ${path} ]]; then
sudo mv "${path}" "${path}.bin"
sudo_clobber "${path}" <<EOF
#!/bin/sh
exec file.bin -m /usr/local/share/misc/magic.mgc "\$@"
EOF
sudo chmod a+rx "${path}"
fi
# If python is installed on stateful-dev, fix python symlinks.
local python_path="/usr/local/bin/python2.6"
if [ -e "${root_fs_dir}${python_path}" ]; then
info "Fixing python symlinks for developer and test images."
local python_paths="/usr/bin/python /usr/local/bin/python \
/usr/bin/python2 /usr/local/bin/python2"
for path in ${python_paths}; do
sudo rm -f "${root_fs_dir}${path}"
sudo ln -s ${python_path} "${root_fs_dir}${path}"
done
fi
info "Developer image built and stored at ${image_name}"
cleanup_mounts
trap - EXIT
if should_build_image ${image_name}; then
${SCRIPTS_DIR}/bin/cros_make_image_bootable "${BUILD_DIR}" \
${image_name} \
--force_developer_mode
fi
}