commit 7109fc401244ff4cd1dc08c5ae57886243a1ee64 Author: Adrian Schröter Date: Mon Apr 15 17:15:44 2024 +0200 Sync from SUSE:ALP:Source:Standard:1.0 elemental-post-build-generate-rpi-image revision 712c20e573d8828fb06f7518c75a52ee diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fecc750 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,23 @@ +## Default LFS +*.7z filter=lfs diff=lfs merge=lfs -text +*.bsp filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.gem filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.jar filter=lfs diff=lfs merge=lfs -text +*.lz filter=lfs diff=lfs merge=lfs -text +*.lzma filter=lfs diff=lfs merge=lfs -text +*.obscpio filter=lfs diff=lfs merge=lfs -text +*.oxt filter=lfs diff=lfs merge=lfs -text +*.pdf filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.rpm filter=lfs diff=lfs merge=lfs -text +*.tbz filter=lfs diff=lfs merge=lfs -text +*.tbz2 filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.ttf filter=lfs diff=lfs merge=lfs -text +*.txz filter=lfs diff=lfs merge=lfs -text +*.whl filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text diff --git a/elemental-post-build-generate-rpi-image.changes b/elemental-post-build-generate-rpi-image.changes new file mode 100644 index 0000000..5b5a123 --- /dev/null +++ b/elemental-post-build-generate-rpi-image.changes @@ -0,0 +1,91 @@ +------------------------------------------------------------------- +Tue Apr 2 09:39:22 UTC 2024 - Klaus Kämpf + +- install to /usr/lib/build/post_build.d + +------------------------------------------------------------------- +Thu Mar 28 10:07:17 UTC 2024 - Klaus Kämpf + +- fix flavor extraction (micro version was added to filename) + +------------------------------------------------------------------- +Thu Mar 14 13:49:59 UTC 2024 - David Cassany + +- Fix generator script: Do not patch partition label setup from + grub.cfg. + +------------------------------------------------------------------- +Thu Jan 4 14:18:23 UTC 2024 - Klaus Kämpf + +- fix grub2 root partition (rancher/elemental#1151) + +------------------------------------------------------------------- +Wed Jan 3 14:21:11 UTC 2024 - Klaus Kämpf + +- switch ttyS0 baudrate to 115200 (standard for Raspberry Pi) + (rancher/elemental#1139) + +------------------------------------------------------------------- +Wed Dec 27 15:32:01 UTC 2023 - Klaus Kämpf + +- iso name changed, adapt flavor extraction + +- handle empty flavor + +------------------------------------------------------------------- +Thu Sep 21 15:22:16 UTC 2023 - Klaus Kämpf + +- fix copying of 'systemready' firmware + +------------------------------------------------------------------- +Wed Sep 20 09:46:16 UTC 2023 - Klaus Kämpf + +- move from parted to sfdisk (from util-linux) +- fix loop device setup + +------------------------------------------------------------------- +Mon Apr 24 13:46:16 UTC 2023 - David Cassany + +- Adapt generation script to rancher/elemental-cli#404 so it makes + use of the proper paths in after-install hooks. + +------------------------------------------------------------------- +Tue Dec 27 10:58:02 UTC 2022 - Klaus Kämpf + +- create checksum with .raw file. + +------------------------------------------------------------------- +Wed Dec 7 13:00:30 UTC 2022 - Klaus Kämpf + +- add last project name element to image name. + +------------------------------------------------------------------- +Wed Dec 7 12:13:00 UTC 2022 - Klaus Kämpf + +- create a timestamped image name. + +------------------------------------------------------------------- +Thu Dec 1 10:41:52 UTC 2022 - Klaus Kämpf + +- label the boot partition as RPI_BOOT. + +------------------------------------------------------------------- +Tue Nov 29 11:05:20 UTC 2022 - Klaus Kämpf + +- faking an .iso extension was a bad idea, breaks build service + trying to sign the image. + +------------------------------------------------------------------- +Mon Nov 28 15:27:36 UTC 2022 - Klaus Kämpf + +- get image size from ~/.rpmmacros (Macros: in project config) + +------------------------------------------------------------------- +Mon Nov 28 10:56:13 UTC 2022 - Klaus Kämpf + +- make it downloadable (by faking an .iso extension) + +------------------------------------------------------------------- +Sat Nov 26 12:17:56 UTC 2022 - Klaus Kämpf + +- Initial version 0.1 diff --git a/elemental-post-build-generate-rpi-image.spec b/elemental-post-build-generate-rpi-image.spec new file mode 100644 index 0000000..450805f --- /dev/null +++ b/elemental-post-build-generate-rpi-image.spec @@ -0,0 +1,59 @@ +# +# spec file for package elemental-post-build-generate-rpi-image +# +# Copyright (c) 2022 SUSE LLC +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# + +Name: elemental-post-build-generate-rpi-image +Summary: Post build script to generate RPi image from Elemental ISO from a container +License: GPL-2.0-or-later +Group: Development/Tools/Building +Version: 0.3 +Release: 0 +Requires: buildah +# for truncate +Requires: coreutils +# for mkfs.vfat +Requires: dosfstools +# for sfdisk +Requires: util-linux +# for grub manipulation +Requires: sed + +%define post_build_dir /usr/lib/build/post_build.d + +Source0: generate-rpi-image.sh +BuildArch: noarch +BuildRoot: %{_tmppath}/%{name}-%{version}-build + +%description +An OBS post build hook that generates a RPi boot image from the Elemental ISO from a container. +The image is expected to be found at "/image/*.img". + +%prep +cp %{S:0} . + +%build + +%install +install -D -m 755 generate-rpi-image.sh $RPM_BUILD_ROOT%{post_build_dir}/50-elemental-generate-rpi-image + +%files +%defattr(-, root, root) +%dir /usr/lib/build +%dir %{post_build_dir} +%{post_build_dir}/50-elemental-generate-rpi-image + +%changelog + diff --git a/generate-rpi-image.sh b/generate-rpi-image.sh new file mode 100644 index 0000000..e4ee9d6 --- /dev/null +++ b/generate-rpi-image.sh @@ -0,0 +1,182 @@ +#!/bin/bash -x + +: ${TOPDIR:=/usr/src/packages} + +container="buildcont" + +set -e + +# Only run the post build check for aarch64 +[ "$(uname -m)" == "aarch64" ] || exit 0 + +# Build service provides the container image as a .tar file + +img=$(ls ${TOPDIR}/DOCKER/*.tar) + +echo "Found image '" ${img} "'" + +[ -f "${img}" ] || exit 1 +# Only consider images with 'iso' as part of the name +echo "${img}" | grep -q iso || exit 0 + +# import .tar with buildah + +buildah from --name "${container}" "docker-archive:${img}" + +# mount container to access its content + +mnt=$(buildah mount "${container}") + +# there must be an .iso file within + +iso=$(ls "${mnt}"/elemental-iso/*.iso) + +echo "Found ISO '" ${iso} "'" + +# exit here if not + +[ -f "${iso}" ] || exit 1 + +# something like sl-micro-6.0-base.aarch64-2.2.0-Build14.2 +basename=$(basename ${iso} .iso) +# split at '.' into DOTS[] +IFS='.' read -ra DOTS <<< "${basename}" +# split "0-base" at '-' into DASHES[] +IFS='-' read -ra DASHES <<< "${DOTS[1]}" +# extract the flavor (base, rt, kvm, ...) +flavor="${DASHES[1]}" +# prepend dash if flavor is non-empty +# covers rpi.raw (for empty flavor) vs rpi-${flavor}.raw (for non-empty) +[ -n "$flavor" ] && flavor="-${flavor}" + +mkdir -p "${TOPDIR}/OTHER/image" + +# create a mountpoint and mount the iso +mkdir iso +mount -o loop "${iso}" iso + +# create a mountpoint and mount the rootfs.squashfs that's inside the iso +mkdir rootfs +mount -o loop iso/rootfs.squashfs rootfs + +# extract the image size from the "build config" + +img_size=$(grep -m 1 "%img_size" ~/.rpmmacros | tr -d "\n" | cut -d " " -f 2) + +# extract two last project path elements ({Stable,Staging,Dev}:TealXX) +# replace colon with dash +project=$(grep -m 1 "%_project" ~/.rpmmacros | tr -d "\n" | rev | cut -d ":" -f 1,2 | rev | tr ":" "-") + +# create an empty image file and a respective loop device +truncate -s $((${img_size}*1024*1024)) rpi.img + +# create a primary FAT partition with 256MB (for kernel + firmware) +# create a primary Linux partition covering the remainder +sfdisk rpi.img < img/iso-config/01_rpi-install-hook.yaml +name: "Raspberry Pi after install hook" +stages: + after-install: + - ©firmware + name: "Copy firmware to EFI partition" + commands: + - cp -a /run/elemental/workingtree/boot/vc/* /run/elemental/efi + after-reset: + - <<: *copyfirmware +HOOK +else +cat << HOOK > img/iso-config/01_rpi-install-hook.yaml +name: "Raspberry Pi after install hook" +stages: + after-install: + - ©firmware + name: "Copy firmware to EFI partition" + commands: + - cp /run/elemental/workingtree/boot/*.fd /run/elemental/efi + - cp /run/elemental/workingtree/boot/*.dtb /run/elemental/efi + - cp /run/elemental/workingtree/boot/config.txt /run/elemental/efi + - cp /run/elemental/workingtree/boot/fixup4.dat /run/elemental/efi + - cp /run/elemental/workingtree/boot/start4.elf /run/elemental/efi + - cp -a /run/elemental/workingtree/boot/firmware /run/elemental/efi + - cp -a /run/elemental/workingtree/boot/overlays /run/elemental/efi + after-reset: + - <<: *copyfirmware +HOOK +fi +# undo all mounts, loopback devices, etc. + +umount img +rmdir img +umount rootfs +rmdir rootfs + +losetup -d ${loop} +umount iso +rmdir iso + +# copy the image as rpi.raw (buildservice checks extensions) + +mkdir -p "${TOPDIR}/OTHER" +rawname="rpi${flavor}.raw" +mv rpi.img ${rawname} +sha256sum ${rawname} > "${TOPDIR}/OTHER/${rawname}.sha256" +mv ${rawname} "${TOPDIR}/OTHER" +ln "${TOPDIR}/OTHER/${rawname}" "${TOPDIR}/OTHER/rpi${flavor}-${project}-`date +'%Y%m%d%H%M%S'`.raw" + +# release the container + +buildah umount "${container}" +buildah rm "${container}"