Skip to content

Commit

Permalink
meta/classes/image: implement ROOTFS_POSTPROCESS_COMMAND
Browse files Browse the repository at this point in the history
Signed-off-by: Claudius Heine <ch@denx.de>
  • Loading branch information
cmhe authored and myo73 committed Apr 12, 2019
1 parent 0f9ae5b commit 13ce96e
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 68 deletions.
46 changes: 46 additions & 0 deletions meta/classes/image-postproc-extension.bbclass
@@ -0,0 +1,46 @@
# This software is a part of ISAR.
# Copyright (C) Siemens AG, 2019

update_etc_os_release() {
OS_RELEASE_BUILD_ID=""
OS_RELEASE_VARIANT=""
while true; do
case "$1" in
--build-id) OS_RELEASE_BUILD_ID=$2; shift ;;
--variant) OS_RELEASE_VARIANT=$2; shift ;;
-*) bbfatal "$0: invalid option specified: $1" ;;
*) break ;;
esac
shift
done

if [ -n "${OS_RELEASE_BUILD_ID}" ]; then
sudo sed -i '/^BUILD_ID=.*/d' '${IMAGE_ROOTFS}/etc/os-release'
echo "BUILD_ID=\"${OS_RELEASE_BUILD_ID}\"" | \
sudo tee -a '${IMAGE_ROOTFS}/etc/os-release'
fi
if [ -n "${OS_RELEASE_VARIANT}" ]; then
sudo sed -i '/^VARIANT=.*/d' '${IMAGE_ROOTFS}/etc/os-release'
echo "VARIANT=\"${OS_RELEASE_VARIANT}\"" | \
sudo tee -a '${IMAGE_ROOTFS}/etc/os-release'
fi
}

ROOTFS_POSTPROCESS_COMMAND =+ "image_postprocess_configure image_postprocess_mark"

image_postprocess_configure() {
# Configure root filesystem
if [ -n "${DISTRO_CONFIG_SCRIPT}" ]; then
sudo install -m 755 "${WORKDIR}/${DISTRO_CONFIG_SCRIPT}" "${IMAGE_ROOTFS}"
TARGET_DISTRO_CONFIG_SCRIPT="$(basename ${DISTRO_CONFIG_SCRIPT})"
sudo chroot ${IMAGE_ROOTFS} "/$TARGET_DISTRO_CONFIG_SCRIPT" \
"${MACHINE_SERIAL}" "${BAUDRATE_TTY}"
sudo rm "${IMAGE_ROOTFS}/$TARGET_DISTRO_CONFIG_SCRIPT"
fi
}

image_postprocess_mark() {
BUILD_ID=$(get_build_id)
update_etc_os_release \
--build-id "${BUILD_ID}" --variant "${DESCRIPTION}"
}
76 changes: 8 additions & 68 deletions meta/classes/image.bbclass
Expand Up @@ -54,9 +54,12 @@ image_do_mounts() {
}

inherit isar-bootstrap-helper
ROOTFS_FEATURES += "finalize-rootfs"
inherit rootfs
inherit image-sdk-extension
inherit image-cache-extension
inherit image-tools-extension
inherit image-postproc-extension

# Extra space for rootfs in MB
ROOTFS_EXTRA ?= "64"
Expand Down Expand Up @@ -118,7 +121,7 @@ python set_image_size () {
d.setVarFlag('ROOTFS_SIZE', 'export', '1')
}

isar_image_gen_fstab() {
do_image_gen_fstab() {
cat > ${WORKDIR}/fstab << EOF
# Begin /etc/fstab
/dev/root / auto defaults 0 0
Expand All @@ -131,70 +134,19 @@ devtmpfs /dev devtmpfs mode=0755,nosuid 0 0
# End /etc/fstab
EOF
}

isar_image_gen_rootfs() {
setup_root_file_system --clean --keep-apt-cache \
--fstab "${WORKDIR}/fstab" \
"${IMAGE_ROOTFS}" ${IMAGE_PREINSTALL} ${IMAGE_INSTALL}
}

isar_image_conf_rootfs() {
# Configure root filesystem
if [ -n "${DISTRO_CONFIG_SCRIPT}" ]; then
sudo install -m 755 "${WORKDIR}/${DISTRO_CONFIG_SCRIPT}" "${IMAGE_ROOTFS}"
TARGET_DISTRO_CONFIG_SCRIPT="$(basename ${DISTRO_CONFIG_SCRIPT})"
sudo chroot ${IMAGE_ROOTFS} "/$TARGET_DISTRO_CONFIG_SCRIPT" \
"${MACHINE_SERIAL}" "${BAUDRATE_TTY}"
sudo rm "${IMAGE_ROOTFS}/$TARGET_DISTRO_CONFIG_SCRIPT"
fi
}

isar_image_cleanup() {
# Cleanup
sudo sh -c ' \
rm "${IMAGE_ROOTFS}/etc/apt/sources.list.d/isar-apt.list"
test ! -e "${IMAGE_ROOTFS}/usr/share/doc/qemu-user-static" && \
find "${IMAGE_ROOTFS}/usr/bin" \
-maxdepth 1 -name 'qemu-*-static' -type f -delete
umount -l ${IMAGE_ROOTFS}/isar-apt
rmdir ${IMAGE_ROOTFS}/isar-apt
umount -l ${IMAGE_ROOTFS}/dev
umount -l ${IMAGE_ROOTFS}/proc
umount -l ${IMAGE_ROOTFS}/sys
rm -f "${IMAGE_ROOTFS}/etc/apt/apt.conf.d/55isar-fallback.conf"
if [ "${ISAR_USE_CACHED_BASE_REPO}" = "1" ]; then
umount -l ${IMAGE_ROOTFS}/base-apt
rmdir ${IMAGE_ROOTFS}/base-apt
# Replace the local apt we bootstrapped with the
# APT sources initially defined in DISTRO_APT_SOURCES
rm -f "${IMAGE_ROOTFS}/etc/apt/sources.list.d/base-apt.list"
mv "${IMAGE_ROOTFS}/etc/apt/sources-list" \
"${IMAGE_ROOTFS}/etc/apt/sources.list.d/bootstrap.list"
fi
rm -f "${IMAGE_ROOTFS}/etc/apt/sources-list"
'
}
addtask image_gen_fstab before do_rootfs_install

do_rootfs_install[depends] = "isar-apt:do_cache_config isar-bootstrap-target:do_bootstrap"
do_rootfs_install[deptask] = "do_deploy_deb"
do_rootfs_install[root_cleandirs] = "${IMAGE_ROOTFS} \
${IMAGE_ROOTFS}/isar-apt"
do_rootfs_install() {
isar_image_gen_fstab
isar_image_gen_rootfs
isar_image_conf_rootfs
isar_image_cleanup
setup_root_file_system --clean --keep-apt-cache \
--fstab "${WORKDIR}/fstab" \
"${IMAGE_ROOTFS}" ${IMAGE_PREINSTALL} ${IMAGE_INSTALL}
}
addtask rootfs_install before do_build after do_unpack

do_mark_rootfs() {
BUILD_ID=$(get_build_id)
update_etc_os_release \
--build-id "${BUILD_ID}" --variant "${DESCRIPTION}" \
"${IMAGE_ROOTFS}"
}
addtask mark_rootfs before do_rootfs_postprocess after do_rootfs_install

do_copy_boot_files[dirs] = "${DEPLOY_DIR_IMAGE}"
do_copy_boot_files() {
if [ -n "${KERNEL_IMAGE}" ]; then
Expand All @@ -219,18 +171,6 @@ do_copy_boot_files() {
}
addtask copy_boot_files before do_rootfs_postprocess after do_rootfs_install

python do_rootfs_postprocess() {
"""Virtual task"""
pass
}
addtask rootfs_postprocess before do_build after do_rootfs_install

python do_rootfs() {
"""Virtual task"""
pass
}
addtask rootfs before do_build after do_rootfs_postprocess

python do_image_tools() {
"""Virtual task"""
pass
Expand Down
58 changes: 58 additions & 0 deletions meta/classes/rootfs.bbclass
@@ -0,0 +1,58 @@
# This software is a part of ISAR.
# Copyright (c) Siemens AG, 2019

# Features of the rootfs creation:
# available features are:
# 'finalize-rootfs' - delete files needed to chroot into the rootfs
ROOTFS_FEATURES ?= ""

ROOTFS_POSTPROCESS_COMMAND += "${@bb.utils.contains('ROOTFS_FEATURES', 'finalize-rootfs', 'rootfs_postprocess_finalize', '', d)}"
rootfs_postprocess_finalize() {
sudo -s <<'EOSUDO'
test ! -e "${ROOTFSDIR}/usr/share/doc/qemu-user-static" && \
find "${ROOTFSDIR}/usr/bin" \
-maxdepth 1 -name 'qemu-*-static' -type f -delete

mountpoint -q '${ROOTFSDIR}/isar-apt' && \
umount -l ${ROOTFSDIR}/isar-apt
rmdir --ignore-fail-on-non-empty ${ROOTFSDIR}/isar-apt

mountpoint -q '${ROOTFSDIR}/base-apt' && \
umount -l ${ROOTFSDIR}/base-apt
rmdir --ignore-fail-on-non-empty ${ROOTFSDIR}/base-apt

mountpoint -q '${ROOTFSDIR}/dev' && \
umount -l ${ROOTFSDIR}/dev
mountpoint -q '${ROOTFSDIR}/sys' && \
umount -l ${ROOTFSDIR}/proc
mountpoint -q '${ROOTFSDIR}/sys' && \
umount -l ${ROOTFSDIR}/sys

rm -f "${ROOTFSDIR}/etc/apt/apt.conf.d/55isar-fallback.conf"

rm -f "${ROOTFSDIR}/etc/apt/sources.list.d/isar-apt.list"
rm -f "${ROOTFSDIR}/etc/apt/sources.list.d/base-apt.list"

mv "${ROOTFSDIR}/etc/apt/sources-list" \
"${ROOTFSDIR}/etc/apt/sources.list.d/bootstrap.list"

rm -f "${ROOTFSDIR}/etc/apt/sources-list"
EOSUDO
}

do_rootfs_postprocess[vardeps] = "${ROOTFS_POSTPROCESS_COMMAND}"
python do_rootfs_postprocess() {
cmds = d.getVar("ROOTFS_POSTPROCESS_COMMAND")
if cmds is None or not cmds.strip():
return
cmds = cmds.split()
for cmd in cmds:
bb.build.exec_func(cmd, d)
}
addtask rootfs_postprocess before do_rootfs after do_rootfs_install

python do_rootfs() {
"""Virtual task"""
pass
}
addtask rootfs before do_build

0 comments on commit 13ce96e

Please sign in to comment.