From 045e6a65af1844d8334f6294aee7f0c576677e70 Mon Sep 17 00:00:00 2001 From: Louis Abel Date: Fri, 3 May 2024 12:56:11 -0700 Subject: [PATCH] sbc: add more pi steps --- config.sh | 27 +++++ ...ocky-rpi.xml => rocky-sbc-raspberrypi.xml} | 0 sbc-build.sh | 98 +++++++++++++++++++ sbc/editbootinstall_rpi.sh | 31 +++++- sbc/pi.xml | 3 +- 5 files changed, 155 insertions(+), 4 deletions(-) rename configs/{rocky-rpi.xml => rocky-sbc-raspberrypi.xml} (100%) create mode 100755 sbc-build.sh diff --git a/config.sh b/config.sh index 97cda15..4bb1825 100644 --- a/config.sh +++ b/config.sh @@ -696,6 +696,25 @@ PERSISTENT_DHCLIENT="yes" EOF } +################################################################################ +# SBC +function common_sbc_steps() { + :> /etc/machine-id + rm -f /etc/sysconfig/network-scripts/ifcfg-link + rm -f /etc/ssh/*_key* + dnf clean all + chown -R sssd:sssd /var/lib/sss/{db,pipes,mc,pubconf,gpo_cache} + cat > /etc/sysconfig/cpupower << EOF +CPUPOWER_START_OPTS="frequency-set -g ondemand" +CPUPOWER_STOP_OPTS="frequency-set -g ondemand" +EOF +} + +function raspberrypi_sbc_steps() { + cd /lib/firmware/brcm + xz -d -k brcmfmac43430-sdio.raspberrypi,3-model-b.txt.xz +} + # ################################################################################ @@ -801,3 +820,11 @@ if [[ "$kiwi_profiles" == *"Vagrant"* ]]; then vbox_vagrant_steps fi fi + +# SBC Only +if [[ "$kiwi_profiles" == *"SBC"* ]]; then + common_sbc_steps + if [[ "$kiwi_profiles" == *"SBC-RaspberryPi"* ]]; then + raspberrypi_sbc_steps + fi +fi diff --git a/configs/rocky-rpi.xml b/configs/rocky-sbc-raspberrypi.xml similarity index 100% rename from configs/rocky-rpi.xml rename to configs/rocky-sbc-raspberrypi.xml diff --git a/sbc-build.sh b/sbc-build.sh new file mode 100755 index 0000000..5723447 --- /dev/null +++ b/sbc-build.sh @@ -0,0 +1,98 @@ +#!/bin/bash +# helps build a quick sbc image. that way a user doesn't have to use emapandas +# nor some other method. mock is probably not necessary, but it's up to you. +# label@resf.org + +set -o errexit +set -o pipefail + +SCRNAME="$(basename "$0")" +SCRDIR="$(dirname "${BASH_SOURCE[0]}")" + +export __usage +__usage=" +usage: $SCRNAME [OPTIONS] + +Options: + -o, --output-dir DIR + -c, --sbc-image NAME + -p, --peridot ID # optional. will use peridot repos. + -d, --debug # optional + +" + +OPTS=$(getopt -a -n sbc-build -o c:,o:,p:,d,h \ + -l sbc-image:,output-dir:,peridot:,debug,help -- "$@") + +function is_in_path() { + builtin type -P "${1}" +} + +function usage() { + echo "$__usage" +} + +eval set -- "$OPTS" +while :; do + case "$1" in + -c | --sbc-image) SBC="$2" ; shift 2 ;; + -o | --output-dir) OUTPUTDIR="$2" ; shift 2 ;; + -p | --peridot) PERIDOTID="$2" ; shift 2 ;; + -d | --debug) DEBUG="--debug" ; shift ;; + -h | --help) usage ;; + --) shift ; break ;; + esac +done + +if [ -z "$SBC" ] || [ -z "$OUTPUTDIR" ]; then + echo "Options are not set properly." + usage + exit 12 +fi + +if [ -e "/sys/fs/selinux/enforce" ]; then + enforce_check="$(cat /sys/fs/selinux/enforce)" + if [ "$enforce_check" -eq "1" ]; then + echo "Running with selinux enforcing is not recommended." + exit 22 + fi +fi + +is_in_path kiwi-ng &> /dev/null +ret_val=$? + +if [ "$ret_val" -ne "0" ]; then + echo "kiwi-ng not found. kiwi packages are likely not installed on this system." + exit 32 +fi + +function switch_repo_to_peridot() { + ID="$1" + # https://yumrepofs.build.resf.org/v1/projects/${ID}/repo/ + pushd repositories || { echo "not found"; exit 1; } + sed -i "s;ZZ_INTERNAL_BaseOS_REPO_URL_ZZ;https://yumrepofs.build.resf.org/v1/projects/${ID}/repo/BaseOS/\$basearch;g" core-peridot.xml + sed -i "s;ZZ_INTERNAL_AppStream_REPO_URL_ZZ;https://yumrepofs.build.resf.org/v1/projects/${ID}/repo/AppStream/\$basearch;g" core-peridot.xml + sed -i "s;ZZ_INTERNAL_CRB_REPO_URL_ZZ;https://yumrepofs.build.resf.org/v1/projects/${ID}/repo/CRB/\$basearch;g" core-peridot.xml + sed -i "s;ZZ_INTERNAL_extras_REPO_URL_ZZ;https://yumrepofs.build.resf.org/v1/projects/${ID}/repo/extras/\$basearch;g" core-peridot.xml + rm core.xml + ln -sf core-peridot.xml core.xml + popd +} + +function main() { + /bin/rm config.xml + if [ ! -f "configs/rocky-sbc-${SBC,,}.xml" ]; then + echo "${LIVE} was not found. Is it supported?" + exit 42 + fi + ln -sf "configs/rocky-sbc-${SBC,,}.xml" config.xml + + if [ -n "$PERIDOTID" ]; then + switch_repo_to_peridot "${PERIDOTID}" + fi + + # shellcheck disable=SC2086 + kiwi-ng $DEBUG --type="oem" --profile="SBC-$SBC" --color-output system build --description="$SCRDIR" --target-dir "$OUTPUTDIR" +} + +main diff --git a/sbc/editbootinstall_rpi.sh b/sbc/editbootinstall_rpi.sh index 48653b1..332676a 100644 --- a/sbc/editbootinstall_rpi.sh +++ b/sbc/editbootinstall_rpi.sh @@ -1,11 +1,36 @@ #!/bin/bash # Modify this script to handle disk changes as needed. -# This means the relevant parts of %post can be brought over and adapted. -# example portions are commented out. +# Some of this may be incorrect or not needed. You will need to verify this. -set -x +set -ex #diskname="$1" #devname="$2" #loopname="${devname%*p2}" #loopdev=/dev/${loopname#/dev/mapper/*} + +# shellcheck disable=SC2034 +image_fs="$1" +root_partnum="$2" +root_device="/dev/mapper/loop*p${root_partnum}" +loop_name="$(basename $root_device | cut -f 1-2 -d 'p')" +disk_device="/dev/${loop_name}" + +# pi's probably don't support GPT. + +cat > gdisk.tmp <<-'EOF' + x + r + g + t + 1 + c + w + y + EOF + + dd if="$disk_device" of=mbrid.bin bs=1 skip=440 count=4 + gdisk "$disk_device" < gdisk.tmp + dd of="$disk_device" if=mbrid.bin bs=1 seek=440 count=4 + rm -f mbrid.bin + rm -rf gdisk.tmp diff --git a/sbc/pi.xml b/sbc/pi.xml index c7b6be1..e703ef6 100644 --- a/sbc/pi.xml +++ b/sbc/pi.xml @@ -15,7 +15,7 @@ @@ -40,6 +40,7 @@ +