From 9dcfcdb9aa2da833a3b86b87fbbb22b60e5d7e3c Mon Sep 17 00:00:00 2001 From: Yevgeny Popovych Date: Tue, 19 Jun 2018 13:08:50 +0300 Subject: classes, images: Use standard variables for initramfs This will reduce the level of indirection and improve compatibility with the rest of OE. For example, FIT that includes initramfs may now be built. Signed-off-by: Yevgeny Popovych --- README.adoc | 2 +- classes/image_types_ostree.bbclass | 6 ++---- classes/sota.bbclass | 4 ++-- classes/sota_qemux86-64.bbclass | 2 +- classes/sota_raspberrypi.bbclass | 1 + recipes-core/images/initramfs-ostree-image.bb | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/README.adoc b/README.adoc index d2bd4b5..7ffdde2 100644 --- a/README.adoc +++ b/README.adoc @@ -78,7 +78,7 @@ Although we have used U-Boot so far, other boot loaders can be configured work w * `OSTREE_REPO` - path to your OSTree repository. Defaults to `$\{DEPLOY_DIR_IMAGE}/ostree_repo` * `OSTREE_OSNAME` - OS deployment name on your target device. For more information about deployments and osnames see the https://ostree.readthedocs.io/en/latest/manual/deployment/[OSTree documentation]. Defaults to "poky". -* `OSTREE_INITRAMFS_IMAGE` - initramfs/initrd image that is used as a proxy while booting into OSTree deployment. Do not change this setting unless you are sure that your initramfs can serve as such a proxy. +* `INITRAMFS_IMAGE` - initramfs/initrd image that is used as a proxy while booting into OSTree deployment. Do not change this setting unless you are sure that your initramfs can serve as such a proxy. * `SOTA_PACKED_CREDENTIALS` - when set, your ostree commit will be pushed to a remote repo as a bitbake step. This should be the path to a zipped credentials file in https://github.com/advancedtelematic/aktualizr/blob/master/docs/credentials.adoc[the format accepted by garage-push]. * `SOTA_CLIENT_PROV` - which provisioning method to use. Valid options are https://github.com/advancedtelematic/aktualizr/blob/master/docs/automatic-provisioning.adoc[`aktualizr-auto-prov`], https://github.com/advancedtelematic/aktualizr/blob/master/docs/implicit-provisioning.adoc[`aktualizr-implicit-prov`], and https://github.com/advancedtelematic/aktualizr/blob/master/docs/hsm-provisioning.adoc[`aktualizr-hsm-prov`]. The default is `aktualizr-auto-prov`. This can also be set to an empty string to avoid using a provisioning recipe. * `SOTA_CLIENT_FEATURES` - extensions to aktualizr. The only valid options are `hsm` (to build with HSM support) and `secondary-network` (to set up a simulated 'in-vehicle' network with support for a primary node with a DHCP server and a secondary node with a DHCP client). diff --git a/classes/image_types_ostree.bbclass b/classes/image_types_ostree.bbclass index ca8aee3..ba3e868 100644 --- a/classes/image_types_ostree.bbclass +++ b/classes/image_types_ostree.bbclass @@ -5,14 +5,12 @@ do_image_ostree[depends] += "ostree-native:do_populate_sysroot \ coreutils-native:do_populate_sysroot \ unzip-native:do_populate_sysroot \ virtual/kernel:do_deploy \ - ${OSTREE_INITRAMFS_IMAGE}:do_image_complete" +" export OSTREE_REPO export OSTREE_BRANCHNAME export GARAGE_TARGET_NAME -RAMDISK_EXT ?= ".${OSTREE_INITRAMFS_FSTYPES}" - OSTREE_KERNEL ??= "${KERNEL_IMAGETYPE}" export SYSTEMD_USED = "${@oe.utils.ifelse(d.getVar('VIRTUAL-RUNTIME_init_manager', True) == 'systemd', 'true', '')}" @@ -124,7 +122,7 @@ IMAGE_CMD_ostree () { checksum=`sha256sum ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} | cut -f 1 -d " "` cp ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} boot/vmlinuz-${checksum} - cp ${DEPLOY_DIR_IMAGE}/${OSTREE_INITRAMFS_IMAGE}-${MACHINE}${RAMDISK_EXT} boot/initramfs-${checksum} + cp ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.${INITRAMFS_FSTYPES} boot/initramfs-${checksum} # Copy image manifest cat ${IMAGE_MANIFEST} | cut -d " " -f1,3 > usr/package.manifest diff --git a/classes/sota.bbclass b/classes/sota.bbclass index 3aca92c..0eb8981 100644 --- a/classes/sota.bbclass +++ b/classes/sota.bbclass @@ -23,13 +23,13 @@ WKS_FILE_sota ?= "sdimage-sota.wks" EXTRA_IMAGEDEPENDS_append_sota = " parted-native mtools-native dosfstools-native" -OSTREE_INITRAMFS_FSTYPES ??= "${@oe.utils.ifelse(d.getVar('OSTREE_BOOTLOADER', True) == 'u-boot', 'ext4.gz.u-boot', 'ext4.gz')}" +INITRAMFS_FSTYPES ??= "${@oe.utils.ifelse(d.getVar('OSTREE_BOOTLOADER', True) == 'u-boot', 'ext4.gz.u-boot', 'ext4.gz')}" # Please redefine OSTREE_REPO in order to have a persistent OSTree repo OSTREE_REPO ?= "${DEPLOY_DIR_IMAGE}/ostree_repo" OSTREE_BRANCHNAME ?= "${MACHINE}" OSTREE_OSNAME ?= "poky" -OSTREE_INITRAMFS_IMAGE ?= "initramfs-ostree-image" +INITRAMFS_IMAGE ?= "initramfs-ostree-image" OSTREE_BOOTLOADER ??= 'u-boot' GARAGE_SIGN_REPO ?= "${DEPLOY_DIR_IMAGE}/garage_sign_repo" diff --git a/classes/sota_qemux86-64.bbclass b/classes/sota_qemux86-64.bbclass index 82efe52..9ef531d 100644 --- a/classes/sota_qemux86-64.bbclass +++ b/classes/sota_qemux86-64.bbclass @@ -4,7 +4,7 @@ IMAGE_FSTYPES_remove = "wic" PREFERRED_PROVIDER_virtual/bootloader_sota = "u-boot" UBOOT_MACHINE_sota = "qemu-x86_defconfig" OSTREE_BOOTLOADER ?= "u-boot" -OSTREE_INITRAMFS_FSTYPES ?= "ext4.gz" +INITRAMFS_FSTYPES ?= "ext4.gz" OSTREE_KERNEL_ARGS ?= "ramdisk_size=16384 rw rootfstype=ext4 rootwait rootdelay=2 ostree_root=/dev/hda" diff --git a/classes/sota_raspberrypi.bbclass b/classes/sota_raspberrypi.bbclass index a5558b4..e69ccf8 100644 --- a/classes/sota_raspberrypi.bbclass +++ b/classes/sota_raspberrypi.bbclass @@ -2,6 +2,7 @@ RPI_USE_U_BOOT_sota = "1" KERNEL_CLASSES_append_sota = " kernel-fitimage" KERNEL_IMAGETYPE_sota = "fitImage" +OSTREE_KERNEL = "${KERNEL_IMAGETYPE}-${INITRAMFS_IMAGE}-${MACHINE}.bin" PREFERRED_PROVIDER_virtual/bootloader_sota ?= "u-boot" UBOOT_ENTRYPOINT_sota ?= "0x00008000" diff --git a/recipes-core/images/initramfs-ostree-image.bb b/recipes-core/images/initramfs-ostree-image.bb index b2d9e27..e77499e 100644 --- a/recipes-core/images/initramfs-ostree-image.bb +++ b/recipes-core/images/initramfs-ostree-image.bb @@ -13,7 +13,7 @@ IMAGE_LINGUAS = "" LICENSE = "MIT" -IMAGE_FSTYPES = "${OSTREE_INITRAMFS_FSTYPES}" +IMAGE_FSTYPES = "${INITRAMFS_FSTYPES}" inherit core-image -- cgit v1.2.3-54-g00ecf From 625c3a3a7b7390012c26b34ce4bb4cd277d9ed07 Mon Sep 17 00:00:00 2001 From: Yevgeny Popovych Date: Tue, 19 Jun 2018 14:41:50 +0300 Subject: classes: image_types_ostree: A hack to allow initramfs in FIT The issue is that when only vmlinuz-* file is present (the case when both DTB and initramfs are in FIT), libostree will assume that there is no initramfs at all and will supply different init= parameter on the kernel command line (aimed to boot directly from sysroot). This effectively breaks boot process as init specified on the kernel cmdline is not present in initramfs. Solution is to basically create an empty initramfs-* file when we use FIT. The proper solution would be to make libostree aware of whether we use FIT or not. Note, to actually boot with initramfs in FIT - a change to u-boot script (env) is needed which will remove explicit usage of initramfs. Signed-off-by: Yevgeny Popovych --- classes/image_types_ostree.bbclass | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/classes/image_types_ostree.bbclass b/classes/image_types_ostree.bbclass index ba3e868..5f2bf26 100644 --- a/classes/image_types_ostree.bbclass +++ b/classes/image_types_ostree.bbclass @@ -122,7 +122,14 @@ IMAGE_CMD_ostree () { checksum=`sha256sum ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} | cut -f 1 -d " "` cp ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} boot/vmlinuz-${checksum} - cp ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.${INITRAMFS_FSTYPES} boot/initramfs-${checksum} + + if [ "${KERNEL_IMAGETYPE}" = "fitImage" ]; then + # this is a hack for ostree not to override init= in kernel cmdline - + # make it think that the initramfs is present (while it is in FIT image) + touch boot/initramfs-${checksum} + else + cp ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.${INITRAMFS_FSTYPES} boot/initramfs-${checksum} + fi # Copy image manifest cat ${IMAGE_MANIFEST} | cut -d " " -f1,3 > usr/package.manifest -- cgit v1.2.3-54-g00ecf From 212d71d273023470b82854c363854b301bd11314 Mon Sep 17 00:00:00 2001 From: Yevgeny Popovych Date: Fri, 20 Jul 2018 18:14:20 +0300 Subject: ostree-initrd: Make it an initramfs, not initrd The reasoning here is to allow initramfs generated by this recipe to be included in FIT. To do so w/o changing openembedded-core (it allows only cpio format) - init script should be able to execute from a rootfs (i.e. true initramfs), not ramdisk (initrd). See [1] for more information on these keywords. The gist of this change is switch from `pivot_root` to `switch_root`. This also allows to get rid of some clutter, since `switch_root` handles transition to new sysroot all by itself. Again, see [1] for details on these utility/syscall. [1] https://www.kernel.org/doc/Documentation/filesystems/ramfs-rootfs-initramfs.txt Signed-off-by: Yevgeny Popovych --- classes/sota.bbclass | 2 +- classes/sota_qemux86-64.bbclass | 2 +- classes/sota_raspberrypi.bbclass | 1 + recipes-sota/ostree-initrd/files/init.sh | 22 ++++------------------ recipes-sota/ostree-initrd/ostree-initrd.bb | 10 +++++----- 5 files changed, 12 insertions(+), 25 deletions(-) diff --git a/classes/sota.bbclass b/classes/sota.bbclass index 0eb8981..f5c6247 100644 --- a/classes/sota.bbclass +++ b/classes/sota.bbclass @@ -23,7 +23,7 @@ WKS_FILE_sota ?= "sdimage-sota.wks" EXTRA_IMAGEDEPENDS_append_sota = " parted-native mtools-native dosfstools-native" -INITRAMFS_FSTYPES ??= "${@oe.utils.ifelse(d.getVar('OSTREE_BOOTLOADER', True) == 'u-boot', 'ext4.gz.u-boot', 'ext4.gz')}" +INITRAMFS_FSTYPES ??= "${@oe.utils.ifelse(d.getVar('OSTREE_BOOTLOADER', True) == 'u-boot', 'cpio.gz.u-boot', 'cpio.gz')}" # Please redefine OSTREE_REPO in order to have a persistent OSTree repo OSTREE_REPO ?= "${DEPLOY_DIR_IMAGE}/ostree_repo" diff --git a/classes/sota_qemux86-64.bbclass b/classes/sota_qemux86-64.bbclass index 9ef531d..0850af6 100644 --- a/classes/sota_qemux86-64.bbclass +++ b/classes/sota_qemux86-64.bbclass @@ -4,7 +4,7 @@ IMAGE_FSTYPES_remove = "wic" PREFERRED_PROVIDER_virtual/bootloader_sota = "u-boot" UBOOT_MACHINE_sota = "qemu-x86_defconfig" OSTREE_BOOTLOADER ?= "u-boot" -INITRAMFS_FSTYPES ?= "ext4.gz" +INITRAMFS_FSTYPES ?= "cpio.gz" OSTREE_KERNEL_ARGS ?= "ramdisk_size=16384 rw rootfstype=ext4 rootwait rootdelay=2 ostree_root=/dev/hda" diff --git a/classes/sota_raspberrypi.bbclass b/classes/sota_raspberrypi.bbclass index e69ccf8..e5f002d 100644 --- a/classes/sota_raspberrypi.bbclass +++ b/classes/sota_raspberrypi.bbclass @@ -3,6 +3,7 @@ RPI_USE_U_BOOT_sota = "1" KERNEL_CLASSES_append_sota = " kernel-fitimage" KERNEL_IMAGETYPE_sota = "fitImage" OSTREE_KERNEL = "${KERNEL_IMAGETYPE}-${INITRAMFS_IMAGE}-${MACHINE}.bin" +INITRAMFS_FSTYPES = "cpio.gz" PREFERRED_PROVIDER_virtual/bootloader_sota ?= "u-boot" UBOOT_ENTRYPOINT_sota ?= "0x00008000" diff --git a/recipes-sota/ostree-initrd/files/init.sh b/recipes-sota/ostree-initrd/files/init.sh index d7e0429..4818a07 100644 --- a/recipes-sota/ostree-initrd/files/init.sh +++ b/recipes-sota/ostree-initrd/files/init.sh @@ -41,7 +41,6 @@ do_mount_fs sysfs /sys do_mount_fs devtmpfs /dev do_mount_fs devpts /dev/pts do_mount_fs tmpfs /dev/shm -do_mount_fs tmpfs /tmp do_mount_fs tmpfs /run # check if smack is active (and if so, mount smackfs) @@ -63,23 +62,10 @@ mount "$ostree_sysroot" /sysroot || { sleep 5 mount "$ostree_sysroot" /sysroot || bail_out "Unable to mount $ostree_sysroot as physical sysroot" } -ostree-prepare-root /sysroot - -# move mounted devices to new root -cd /sysroot -for x in dev proc run; do - log_info "Moving /$x to new rootfs" - mount -o move "/$x" "$x" -done - -# switch to new rootfs -log_info "Switching to new rootfs" -mkdir -p run/initramfs -pivot_root . run/initramfs || bail_out "pivot_root failed." - -log_info "Launching target init" +ostree-prepare-root /sysroot -exec chroot . sh -c 'umount /run/initramfs; exec /sbin/init' \ - dev/console 2>&1 +log_info "Switching to rootfs" +exec switch_root /sysroot /sbin/init +bail_out "Failed to switch_root to $ostree_sysroot" diff --git a/recipes-sota/ostree-initrd/ostree-initrd.bb b/recipes-sota/ostree-initrd/ostree-initrd.bb index 6046c81..26525c8 100644 --- a/recipes-sota/ostree-initrd/ostree-initrd.bb +++ b/recipes-sota/ostree-initrd/ostree-initrd.bb @@ -1,20 +1,20 @@ -SUMMARY = "Extremely basic live image init script" +SUMMARY = "Initramfs for booting into libostree managed system" LICENSE = "MIT" LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" + SRC_URI = "file://init.sh" S = "${WORKDIR}" -PV = "3" +PV = "4" do_install() { install -dm 0755 ${D}/etc touch ${D}/etc/initrd-release install -dm 0755 ${D}/dev - install -dm 0755 ${D}/sbin - install -m 0755 ${WORKDIR}/init.sh ${D}/sbin/init + install -m 0755 ${WORKDIR}/init.sh ${D}/init } inherit allarch -FILES_${PN} += " /dev /etc/initrd-release /sbin/init " +FILES_${PN} += " /dev /etc/initrd-release /init " -- cgit v1.2.3-54-g00ecf From 9927446d002b1154faae67ff990176a02f69e7e7 Mon Sep 17 00:00:00 2001 From: Yevgeny Popovych Date: Thu, 9 Aug 2018 13:16:07 +0300 Subject: classes: image_types_ostree: Fix copying standalone initramfs Signed-off-by: Yevgeny Popovych --- classes/image_types_ostree.bbclass | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/image_types_ostree.bbclass b/classes/image_types_ostree.bbclass index 5f2bf26..dac3580 100644 --- a/classes/image_types_ostree.bbclass +++ b/classes/image_types_ostree.bbclass @@ -128,7 +128,7 @@ IMAGE_CMD_ostree () { # make it think that the initramfs is present (while it is in FIT image) touch boot/initramfs-${checksum} else - cp ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.${INITRAMFS_FSTYPES} boot/initramfs-${checksum} + cp ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE}-${MACHINE}.${INITRAMFS_FSTYPES} boot/initramfs-${checksum} fi # Copy image manifest -- cgit v1.2.3-54-g00ecf From 7d657d0cbec360cafb94952fcd652fd084579204 Mon Sep 17 00:00:00 2001 From: Phil Wise Date: Fri, 10 Aug 2018 13:42:36 +0200 Subject: Add back dependency on INITRAMFS_IMAGE:do_image_complete Without this the build fails because the initramfs hasn't been build before do_image_ostree. There should be a dependency through virtual/kernel:do_deploy, but there is clearly some reason why this isn't enough. --- classes/image_types_ostree.bbclass | 1 + 1 file changed, 1 insertion(+) diff --git a/classes/image_types_ostree.bbclass b/classes/image_types_ostree.bbclass index dac3580..b525738 100644 --- a/classes/image_types_ostree.bbclass +++ b/classes/image_types_ostree.bbclass @@ -5,6 +5,7 @@ do_image_ostree[depends] += "ostree-native:do_populate_sysroot \ coreutils-native:do_populate_sysroot \ unzip-native:do_populate_sysroot \ virtual/kernel:do_deploy \ + ${INITRAMFS_IMAGE}:do_image_complete \ " export OSTREE_REPO -- cgit v1.2.3-54-g00ecf