blob: 3e001d2b3805f7aacf3ee47d446cc80640cd5dcc [file] [log] [blame]
#!/bin/bash
# Copyright 2015 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.
# This will add console=ttyS0 kernel cmdline flag, thus rerouting
# dmesg output to ttyS0 (serial port).
FLAGS_enable_serial=ttyS0
# Don't install upstart files.
INSTALL_MASK+=" /etc/init"
# Don't install symbol table for kdump kernel.
INSTALL_MASK+=" /boot/kdump/System.map-*"
TEMP_PACKAGE_LIST=""
cleanup_temp_package_list() {
if [[ -e "${TEMP_PACKAGE_LIST}" ]]; then
rm -f "${TEMP_PACKAGE_LIST}"
fi
}
# build_image script calls board_setup on the pristine base image.
board_make_image_bootable() {
local -r image="$1"
local -r script_root="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")"
. "${script_root}/bootloader_install.sh" || exit 1
if ! bootloader_install "${image}"; then
error "Could not install bootloaders on ${image}"
return 1
fi
}
create_package_info() {
trap cleanup_temp_package_list EXIT
TEMP_PACKAGE_LIST="$(mktemp -t package-list.XXXXXXXXXX)"
# The "emerge" command below generates the list of packages that
# virtual/target-os depends on. Its results look like
#
# ...
# [binary R ] app-arch/gzip-1.9 to /build/lakitu/
# [binary R ] dev-libs/popt-1.16-r2 to /build/lakitu/
# [binary R ] app-emulation/docker-credential-helpers-0.6.3-r1 to /build/lakitu/
# ...
#
# This command line is similar to what ListInstalledPackage function (in
# chromite/licensing/licenses_lib.py) does.
#
# The following "grep" command filters out extra messages to leave the package
# list only.
#
# And the "sed" command extracts the category name, the package name, and the
# version from each line. With that, the example above is converted to
#
# ...
# app-arch/gzip-1.9
# dev-libs/popt-1.16-r2
# app-emulation/docker-credential-helpers-0.6.3-r1
# ...
"emerge-${BOARD}" \
--with-bdeps=n --with-bdeps-auto=n --usepkgonly --emptytree --pretend \
--color=n virtual/target-os | \
grep --color=never "^\[" | \
sed -E 's/\[[^]]+R[^]]+\] (.+) to \/build\/.*/\1/' \
> "${TEMP_PACKAGE_LIST}"
local -r script_root="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")"
sudo "${script_root}/create_pkg_info.py" \
--input="${TEMP_PACKAGE_LIST}" \
--output="${root_fs_dir}"/etc/cos-package-info.json
cleanup_temp_package_list
trap - EXIT
}
write_toolchain_path() {
local -r cros_overlay="/mnt/host/source/src/third_party/chromiumos-overlay"
local -r sdk_ver_file="${cros_overlay}/chromeos/binhost/host/sdk_version.conf"
local -r ctarget="$(portageq-"${BOARD}" envvar CHOST)"
. "${sdk_ver_file}"
local -r toolchain_path="${TC_PATH/\%\(target\)s/${ctarget}}"
# Write toolchain path to image.
echo "${toolchain_path}" | \
sudo tee "${root_fs_dir}/etc/toolchain-path" > /dev/null
# Write toolchain path to build dir so it can be exported as an artifact.
echo "${toolchain_path}" | \
sudo tee "${BUILD_DIR}/toolchain_path" > /dev/null
}
# Moves the given rootfs file (a relative path to "root_fs_dir") to the given
# artifact location (a relative path to "BUILD_DIR"). The directory containing
# the rootfs file is deleted if it becomes empty after this move. If the
# rootfs file doesn't exist, this function puts an empty file at the given
# artifact location.
move_for_artifact() {
local rootfs_file="${root_fs_dir}/$1"
local artifact="${BUILD_DIR}/$2"
if [[ ! -f "${rootfs_file}" ]]; then
touch "${artifact}"
return
fi
cp "${rootfs_file}" "${artifact}"
sudo rm "${rootfs_file}"
if [[ -z "$(ls -A "$(dirname "${rootfs_file}")")" ]]; then
sudo rmdir "$(dirname "${rootfs_file}")"
fi
}
# Creates toolchain_env file in BUILD_DIR so that it can be exported as an
# artifact.
export_toolchain_env() {
# File that has kernel compiler information.
move_for_artifact "etc/toolchain_env" "toolchain_env"
}
# Creates kernel_info file in BUILD_DIR so that it can be exported as an
# artifact.
export_kernel_info() {
# File with kernel information.
move_for_artifact "etc/kernel_info" "kernel_info"
}
# Creates kernel_commit file in BUILD_DIR so that it can be exported as an
# artifact.
export_kernel_commit() {
# File with kernel commit ID.
move_for_artifact "etc/kernel_commit" "kernel_commit"
}
# Exports default GPU driver version file as an artifact.
export_gpu_default_version() {
local -r script_root="$1"
local -r default_driver_file="${script_root}/gpu_default_version"
local -r default_driver_artifact="${BUILD_DIR}/gpu_default_version"
# Copy scripts/gpu_default_version to BUILD artifact
cp "${default_driver_file}" "${default_driver_artifact}"
}
# board_finalize_base_image() gets invoked by the build scripts at the
# end of building base image.
board_finalize_base_image() {
local -r script_root="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")"
create_package_info
write_toolchain_path
move_for_artifact "opt/google/src/kernel-src.tar.gz" \
"kernel-src.tar.gz"
move_for_artifact "opt/google/src/kernel-headers.tgz" \
"kernel-headers.tgz"
export_toolchain_env
export_kernel_info
export_kernel_commit
cp "${BOARD_ROOT}/usr/lib/debug/boot/vmlinux" "${BUILD_DIR}/vmlinux"
export_gpu_default_version "${script_root}"
# /etc/machine-id gets installed by sys-apps/dbus and is a symlink.
# This conflicts with systemd's machine-id generation mechanism,
# so we remove the symlink and recreate it as an empty file.
sudo rm "${root_fs_dir}"/etc/machine-id
sudo touch "${root_fs_dir}"/etc/machine-id
info "Copying shim to bootx64.efi"
sudo cp \
"${root_fs_dir}"/boot/efi/boot/shimx64.efi \
"${root_fs_dir}"/boot/efi/boot/bootx64.efi
info "Successfully copied shim to bootx64.efi"
info "Deleting legacy EFI bootloaders"
# Don't delete bootx64.efi here, since the shim is now there
sudo rm -f "${root_fs_dir}"/boot/efi/boot/bootia32.efi
info "Successfully deleted legacy EFI bootloaders"
info "Populating dbx"
sudo mkdir -p "${esp_fs_dir}"/efi/Google/GSetup/dbx
sudo cp "${script_root}"/dbx/* "${esp_fs_dir}"/efi/Google/GSetup/dbx
sudo chmod -R 755 "${esp_fs_dir}"/efi/Google/GSetup/dbx
info "Successfully populated dbx"
}