# Copyright 2025 Stuart Winter, Donostia, Spain # All rights reserved. # # Redistribution and use of this script, with or without modification, is # permitted provided that the following conditions are met: # # 1. Redistributions of this script must retain the above copyright # notice, this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ########################################################################################## # Program: sair.conf/rpi_generic # Purpose: Raspberry Pi helper script for 'SAIR' (Slackware AArch64 Installer Respinner) # This script will adjust the Slackware AArch64 Installer image to function with # the Raspberry Pi Kernel fork package. # This can be used as a reference for other Hardware Models. # Author : Stuart Winter # Date...: 03-Sept-2025 # Version: 1.00 ########################################################################################## ########################################################################################## # Slackware AiO Installer image layout for RPi # ########################################################################################## #root@honey:/dev/shm# fdisk -l rpi.img #Disk rpi.img: 13 GiB, 13958643712 bytes, 27262976 sectors #Units: sectors of 1 * 512 = 512 bytes #Sector size (logical/physical): 512 bytes / 512 bytes #I/O size (minimum/optimal): 512 bytes / 512 bytes #Disklabel type: dos #Disk identifier: 0x982553fa # #Device Boot Start End Sectors Size Id Type #rpi.img1 2048 4196351 4194304 2G b W95 FAT32 #rpi.img2 * 4196352 7812499 3616148 1.7G 83 Linux #rpi.img3 9764864 27262975 17498112 8.3G 83 Linux # #rpi.img1 = fat32 partition for the Raspberry Pi's proprietary boot loader #rpi.img2 = ext4 partition for the Slackware OS /boot directory # #rpi.img3 = ext4 partition that contains the Slackware installation media (packages). #Location of packages: /slackware/slackwareaarch64-current/slackware # The .slktree file should be evaluated to discover the version of Slackware. #root@honey:/mnt/floppy/slackware# cat .slktree # slackwareaarch64-current/slackware #root@honey:/tmp# losetup --partscan --find --show rpi-aio.img #/dev/loop0 #root@honey:/tmp# blkid /dev/loop0p* #/dev/loop0p1: LABEL_FATBOOT="SLKhwm_bw" LABEL="SLKhwm_bw" UUID="733E-582F" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="982553fa-01" #/dev/loop0p2: LABEL="SLKboot" UUID="51943f6f-1617-4393-9272-6e597b51f350" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="982553fa-02" #/dev/loop0p3: LABEL="SLKins_aio-pkgs" UUID="672a8afd-1027-4dc2-8878-a92599d3d4f9" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="982553fa-03" ########################################################################################## # Initialisation function: function hwm_initialise() { pinfo "RPi helper: initialising ..." # Sanity check that we have available resources: # SLACKWAREVERSION is set within the slackkit config file - e.g. 'slackwareaarch64-current' # RPi Kernel fork packages: rpi_kernelpkgdir=${rpi_kernelpkgdir:-$HOME/armedslack/experimental/${SLACKWAREVERSION}/rpi-kernel-fork/} [ -d "${rpi_kernelpkgdir}" ] && { pinfo "RPi Kernel fork directory: ${rpi_kernelpkgdir}" ;} || { pinfo "Error: RPi Kernel fork directory is missing" ; return 1 ;} # HW_MODEL=the name of the RPi version you're building for - e.g. "rpi4", "rpi5". # This is specified to 'sair' through the '-H, --hardware-model' options and is # used to match the Slackware package files - e.g. 'kernel_armv8-6.12.44-aarch64-1_rpi4.txz' # and to control behaviour/settings of particular RPi Hardware Model versions. # # We will default to "rpi4" - change it by supplying SAIR with '-H rpi5' for example. : "${HW_MODEL:=rpi4}" kernel_base=kernel_armv?-+([^-])-+([^-])-+([^-])_${HW_MODEL} kernel_pkg="$(basename $rpi_kernelpkgdir/${kernel_base}.t?z )" pinfo "Kernel package: ${kernel_pkg}" # Slackware ARM platform artifacts store: [ -d "${SLACKPLATFORMDIR}" ] && { pinfo "Slackware ARM platform directory: ${SLACKPLATFORMDIR}" ;} || { pinfo "Error: Slackware ARM platform directory is missing" ; return 1 ;} # Determine the U-Boot binary we'll be using. # The version within the Slackware AArch64 AiO image will be an old build, # so we'll replace it with the latest build: # # RPi5 note: we don't yet build a separate U-Boot for the RPi5. We need to establish # whether it's required or whether we can use a generic one as you can with the rpi3&4. # If we cannot, we also need to update the a/hwm-bw-raspberrypi package's doinst.sh # to both package it, and install the correct version depending on which HWM is in use. # hwm_soc=bcm2711 ## RPi no longer uses U-Boot - migrated to native BL. # uboot_bin=$( echo ${SLACKPLATFORMDIR}/bootware/bin/${hwm_soc}/u-boot*/*u-boot.bin ) # [ -f ${uboot_bin} ] && { # pinfo "U-Boot binary: ${uboot_bin}" ;} || { # pinfo "Error: Unable to find U-Boot binary for ${HW_MODEL}/${hwm_soc}" ; return 1 ;} # Hardware Model Bootware package for the Raspberry Pi: # This is generic for all RPi models: hwm_bw_pkg=$( echo ${PKGSTORE}/a/hwm-bw-raspberrypi-*.t?z ) [ -f $hwm_bw_pkg ] && { pinfo "Hardware Model Bootware package: ${hwm_bw_pkg}" ;} || { pinfo "Error: unable to find Hardware Model Bootware package" ; return 1 ;} } ############################################################################################ # Handlers for the partitions we're working with ############################################################################################ # /boot file system: function fs_handler_SLKhwm_bw() { local fs_loc=$1 pinfo "RPi helper: Hardware Model Bootware file system ..." # RPi proprietary boot loader configuration files: # $fs_loc/config.txt # # Presently we don't need to adjust the settings within the RPi's proprietary # Boot Loader config, but we'll replace the existing one with the latest # from the Slackware ARM platform repository: pinfo "RPi helper: Updating RPi bootloader config ..." install -pm644 ${SLACKPLATFORMDIR}/bootware/src/platform/aarch64/rpi_generic/assets/config.txt ${fs_loc}/ install -pm644 ${SLACKPLATFORMDIR}/bootware/src/platform/aarch64/rpi_generic/assets/slk_config.txt ${fs_loc}/ # Raspberry Pi 4 Note: # We're not editing the console= settings for the RPi Kernel fork, as we do with the OS # (facilitated by the post install script : /usr/share/hwm-configure/platform/aarch64/installer/helper.scr/002-rpi_bl-configure ) # because the Installer does not set it - we use the Kernel defaults which enables both # HDMI and serial access. pinfo "RPi helper: Updating RPi bootloader Linux Kernel cmdline configs ..." install -pm644 ${SLACKPLATFORMDIR}/bootware/src/platform/aarch64/rpi_generic/assets/*cmdline.txt ${fs_loc}/ # Move the installer version of the cmdline.txt into place: mv -f ${fs_loc}/{slkinstaller.cmdline.txt,cmdline.txt} # The default 'cmdline.txt' contains some placeholder substitutions. # The 'inst_dskimg.sh' Installer build system substitutes this for the regular # Installer images. The only reason we need to do it here is because we just copied (above) # the default template files from the src repo. # # Hack for Linux 6.x - add 'irqpoll' to the Kernel cmdline: #sed -i 's?%CMDLINE%?irqpoll?g' ${fs_loc}/*cmdline*txt # I don't think we need irqpoll, so we'll just nullify the placeholder: #sed -i 's?%CMDLINE%??g' ${fs_loc}/*cmdline.txt # We'll use it to add the console settings, otherwise we don't have visibility or # control from the serial console. # The RPi4 with the kernel fork didn't require any settings. if [ "${HW_MODEL}" = "rpi5" ]; then pinfo "RPi helper: Setting console settings in cmdline.txt ..." # Hopefully we won't need any of this with mainline Linux! # With the RPi4 and the RPi Kernel fork we don't need to set this.. sed -i 's?%CMDLINE%?console=serial0,115200 console=tty1 tty1noaskfirst startgettyAMA0 startkbselector?g' ${fs_loc}/cmdline.txt # Remove it from the slkos.cmdline.txt file otherwise it persists: sed -i 's?%CMDLINE%??g' ${fs_loc}/*cmdline.txt else # All other RPi Hardware Models have no console setting, so we nullify the placeholder: # in all cmdline.txt configs: # The serial and virtual consoles are both active, even with the RPi Kernel fork. pinfo "RPi helper: Removing placeholders from cmdline.txt files ..." sed -i 's?%CMDLINE%??g' ${fs_loc}/*cmdline.txt fi # Purge the standard Slackware kernel artifacts (kernel, OS initrd, DTBs, Kernel config, System.map) # The initrd here is the Slackware Installer, not the OS: # The RPi Kernel fork Slackware package build process doesn't build a Slackware Installer image, # but essentially all we need to do is extract the standard one and replace the Kernel modules with # those from the RPi Kernel fork package. # purge_kernel_artifacts ${fs_loc} || return 1 # We can't use the generic function for this, since we have a separate naming scheme in place: # DTBs and other bits are handled further down. # Kernel: rm -f ${fs_loc}/slk_image-armv? # Installer: rm -f ${fs_loc}/slk_initrd-armv?.img # Replace the shipped RPi bootware stuff with the latest versions held within the Slackware package. # We'll just overwrite them rather than deleting first. pinfo "Updating RPi bootware ..." tar -xf ${hwm_bw_pkg} \ --wildcards \ --strip-components=4 \ -C "${fs_loc}" \ 'usr/share/hwm-bw-raspberrypi/bootloader-firmware/*' || return 1 # This is superfluous and is an excess from the tar above: #rm -f ${fs_loc}/*u-boot.bin # Replace the shipped U-Boot with the latest version from the Slackware ARM # "platform" directory. #pinfo "Updating U-Boot ..." #install -pm644 ${uboot_bin} ${fs_loc}/slk_u-boot.bin # Replace the DTBs with those held within the Slackware RPi Kernel fork package: # Only the RPi3 DTBs are shipped within the Slackware Hardware Model Bootware package # (see above), so we obtain the rest from the Kernel package. # References: # RPi Kernel package helper script: /boot/platform/aarch64/helper/pkg-kernel-rpi # Source download script: source/a/hwm-bw-raspberrypi/sources/get-firmware.sh pinfo "Updating DTBs ..." # Unpack the Kernel into temporary space: rm -rf $TMPDIR/extract/kernel mkdir -p $TMPDIR/extract/kernel tar xf ${rpi_kernelpkgdir}/${kernel_pkg} -C $TMPDIR/extract/kernel || return 1 # Note: the DTBs are duplicated within the SLKhwm_bw partition and the /boot partition. # This is because we use the RPi's proprietary boot loader to load DTBs and overlays # since there is ample documentation for it, and U-Boot doesn't seem to handle it well # on the RPi for some reason. We maintain them in /boot since that's the Slackware standard, # and if you want to use U-Boot to load DTBs, they're ready for use. cp -dpRfL $TMPDIR/extract/kernel/boot/dtb*/broadcom/* ${fs_loc}/ # Unpack RPi Kernel fork package and create symlinks from the package's install script: # This is a standard setup for the OS and/or Installer. # We don't need this now that we don't have an ext4 /boot partition to manage on the RPi. # Other Hardware Models will want this though, if they're replacing/updating the Kernel. #setup_kernel_artifacts ${fs_loc} ${rpi_kernelpkgdir}/${kernel_pkg} || return 1 # The reference for the following is here: /boot/platform/aarch64/helper/pkg-kernel-rpi # This is maintained within the 'source/k/boot-skeleton/platform/aarch64/helper/pkg-kernel-rpi' # Kernel package post install script helper. # # Update the Kernel with the latest RPi Kernel fork Kernel: # We use the glob here because we didn't won't extract the symlinks using the 'setup_kernel_artifacts' # function. # In the target directory ( ${fs_loc} = /boot/platform/hwm_bw/ ) we don't use symlinks # because it's a VFAT file system. pinfo "Updating Kernel ..." install -pm755 $TMPDIR/extract/kernel/boot/Image-armv?* ${fs_loc}/slk_image-armv8 #### Slackware Installer modifications ################################################# # Unpack the Slackware Installer that's contained within the Slackware tree. # This is the 'bare' installer. The 'purge_kernel_artifacts' function wipes the # version within the Slackware Installer sd card image, as there's no reason to ever # use an older version of the Slackware Installer. unpack_slk_installer ${PORTROOTDIR}/installer/initrd-armv8.img || return 1 # Replace the official Slackware Kernel package's Kernel modules with those from # the RPi Kernel fork package: setup_kernel_mods_installer ${rpi_kernelpkgdir}/${kernel_pkg} || return 1 # Filter the Kernel module list to include the standard set of module categories. # This is to load only what's required within the OSInitRD or Installer. # Note: For the moment we'll install all of the modules from the RPi Kernel fork # package since it's pretty light weight and has an entirely different Kernel # configuration. #setup_kernel_mods_filter # Rebuild Kernel module dependency map within the tmp dir containing the unpacked Installer: setup_kernel_mods_depmod || return 1 # Set a flag to enable the Slackware Installer to run the Raspberry Pi Kernel Fork # helper scripts, which adjust the settings to align with the Kernel fork - e.g. # changing the serial console address. # The Post setup script within the Installer checks for the presence of this file: # '/usr/share/hwm-configure/platform/aarch64/installer/helper.scr/rpi-kernel-fork-configure' touch $TMPDIR/installer-unpacked/.is-rpi-kernel-fork # For development purposes, cause the Installer to pause before running # the post installation scripts: [ "${SAIR_FLAGS_INSTPAUSE}" = "No" ] || touch $TMPDIR/installer-unpacked/.post-install-pause # Add a SAIR reconfiguration post-install script & tools: # This can probably be moved into a generic function when we add more HWMs # to SAIR. install -pm644 ${ASSETDIR}/generic/999-sair \ $TMPDIR/installer-unpacked/usr/share/hwm-configure/platform/aarch64/installer/helper.scr/ install -pm755 ${ASSETDIR}/tools/* \ $TMPDIR/installer-unpacked/tools/ # RPi modifications: install -pm644 ${ASSETDIR}/rpi/999-rpi-kernel-fork-configure \ $TMPDIR/installer-unpacked/usr/share/hwm-configure/platform/aarch64/installer/helper.scr/ # Repack the modified Installer image and store it within our mounted partition: # Note: no symlinks are used here - 'initrd-armv8.img' is the file. # Symlinked initrd's are only used for the OS InitRD and do not contain the '.img' extension. repack_slk_installer ${fs_loc}/slk_initrd-armv8.img || return 1 # TO VERIFY: # TO VERIFY: # Seems unnecessary - RPi Kernel fork seems fine with this set, and it's one less thing # to revert when migrating finally to mainline. #sed -i 's/^upstream_kernel=1$/#&/' ${fs_loc}/slk_config.txt ###################################################################################### # For development purposes, we'll copy the dev versions from a local repository: #[ -f ${ASSETDIR}/cmdline.txt ] && install -vpm644 ${ASSETDIR}/cmdline.txt $fs_loc/ #[ -f ${ASSETDIR}/config.txt ] && install -vpm644 ${ASSETDIR}/config.txt $fs_loc/ ###################################################################################### # Any RPi Hardware Model specific changes: #if [ "${HW_MODEL}" = "rpi4" ]; then # do stuff specific to rpi4 #fi #if [ "${HW_MODEL}" = "rpi5" ]; then # do stuff specific to rpi5 #fi } # Note: Slackware AArch64 no longer uses U-Boot on the RPi's, so we don't have a /boot # partition. This remains as a reference for other Hardware Models. # /boot file system: #function fs_handler_SLKboot() { # local fs_loc=$1 # pinfo "RPi helper: /boot file system ..." # # # Purge the standard Slackware kernel artifacts (kernel, OS initrd, DTBs, Kernel config, System.map) # # The initrd here is the Slackware Installer, not the OS: # purge_kernel_artifacts ${fs_loc} || return 1 # # # Unpack RPi Kernel fork package and create symlinks from the package's install script: # # This is a standard setup for the OS and/or Installer. # setup_kernel_artifacts ${fs_loc} ${rpi_kernelpkgdir}/${kernel_pkg} || return 1 # # #### Slackware Installer modifications ################################################# # # Unpack the Slackware Installer that's contained within the Slackware tree. # # This is the 'bare' installer. The 'purge_kernel_artifacts' function wipes the # # version within the Slackware Installer sd card image, as there's no reason to ever # # use an older version of the Slackware Installer. # unpack_slk_installer ${PORTROOTDIR}/installer/initrd-armv8.img || return 1 # # # Replace the official Slackware Kernel package's Kernel modules with those from # # the RPi Kernel fork package: # setup_kernel_mods_installer ${rpi_kernelpkgdir}/${kernel_pkg} || return 1 # # # Filter the Kernel module list to include the standard set of module categories. # # This is to load only what's required within the OSInitRD or Installer. # # Note: For the moment we'll install all of the modules from the RPi Kernel fork # # package since it's pretty light weight and has an entirely different Kernel # # configuration. # #setup_kernel_mods_filter # # # Rebuild Kernel module dependency map: # setup_kernel_mods_depmod || return 1 # # # Set a flag to enable the Slackware Installer to run the Raspberry Pi Kernel Fork # # helper scripts, which adjust the settings to align with the Kernel fork - e.g. # # changing the serial console address. # # The Post setup script within the Installer checks for the presence of this file: # # '/usr/share/hwm-configure/platform/aarch64/installer/helper.scr/rpi-kernel-fork-configure' # touch $TMPDIR/installer-unpacked/.is-rpi-kernel-fork # # # For development purposes, cause the Installer to pause before running # # the post installation scripts: # touch $TMPDIR/installer-unpacked/.post-install-pause # # # Repack the modified Installer image and store it within our mounted partition: # # Note: no symlinks are used here - 'initrd-armv8.img' is the file. # # Symlinked initrd's are only used for the OS InitRD and do not contain the '.img' extension. # repack_slk_installer ${fs_loc}/initrd-armv8.img || return 1 # ######################################################################################### # # # If you want to boot the Slackware OS using the Raspberry Pi's proprietary boot loader # # rather than U-Boot, you need to set this option. This will be picked up by the post # # install helper script: # # # # Note: this installer plugin hasn't been written yet.. # # /usr/share/hwm-configure/platform/aarch64/installer/helper.scr/003-rpip_bl-configure # # You can also touch a feature flag file within the Installer to achieve the same thing: # # touch /.rpi_conf_bl_native # #CONF_RPIP_BL="rpi_conf_bl_native" # # Default is to boot the OS using U-Boot. This option exists for testing, development # # & troubleshooting purposes only. # CONF_RPIP_BL="" # # # No longer required - not using U-Boot. # # With the RPi native BL, this config seems unnecessary. # # # # Modify the extlinux.conf of the installer image to set the kernel cmdline # # We add the standard stuff required for the RPi Kernel fork's non-standard settings: # #sed -i '/^[[:blank:]]*APPEND[[:blank:]]/ s/$/ 8250.nr_uarts=1 '"${CONF_RPIP_BL}"' /' \ # # ${fs_loc}/extlinux/extlinux.conf #} # Update/replace various Slackware packages with newer/alternate versions: function fs_handler_SLKins_aio-pkgs() { local fs_loc=$1 pinfo "RPi helper: AiO Slackware package store file system ..." # Determine the version of Slackware we're working with: # If this file is missing, the Installer will fail. No reason it shouldn't, but # who knows. [ ! -f ${fs_loc}/slackware/.slktree ] && { echo "ERROR: Cannot determine Slackware version within the AiO file system" ; return 1 ;} # Enter the root of the package repository: # Example of the pwd now: /tmp/sair/mnt/SLKins_aio-pkgs/slackware pushd ${fs_loc}/slackware > /dev/null || return 1 # Refresh the entire slackwareaarch64 tree? Normally we don't do this, as the SAIR image # is meant to replace just a few specific packages, but in this case I want the latest # package set. # SAIR_REPLACEPKGSET is set externally to SAIR. if [ "${SAIR_REPLACEPKGSET}" = "Yes" ]; then [ ! -d "${SLACKPUBTREEDIR}/$( <.slktree )" ] && { echo "ERROR: Slackware public tree not found" ; return 1 ;} pinfo "RPi helper: Replacing the entire package set" rm -rf $( dirname $( <.slktree ) ) rsync -PaL \ --exclude '*/source' \ --exclude '*/installer' \ $SLACKPUBTREEDIR/$( dirname $( <.slktree ) ) . fi # Enter the versioned Slackware tree: # ".slktree" contains the string (as an example): slackwareaarch64-current/slackware pushd $( <.slktree ) > /dev/null || return 1 # Example of the pwd now: /tmp/sair/mnt/SLKins_aio-pkgs/slackware/slackwareaarch64-current/slackware # Handle the 'a' series: pinfo "Handling 'a' series packages ..." pushd a > /dev/null # Replace standard Slackware kernel package with RPi Kernel fork version: # These packages live outside of the regular Slackware tree. rm -fv kernel_armv?-+([^-])-+([^-])-+([^-]).{t?z,txt,asc} install -pm644 ${rpi_kernelpkgdir}/${kernel_pkg} . # Generate .txt file. We could copy the one in the directory where the Kernel package lives # (if there is one), but we can easily make a new one using 'slackdtxt' from the 'slacktrack' # package: slackdtxt ${kernel_pkg} # We don't need to make a GPG signature since it's not considered by the Slackware Installer. # Users can rely on the GPG signature of the entire installer image. # Update standard Slackware kernel-firmware package: # The version of the package we're using resides within the regular/official Slackware tree # and is simply the latest version (versus the package within the AiO image which will likely # be much older) rm -f kernel-firmware-* install -pm644 ${PKGSTORE}/a/kernel-firmware-*.t* . # Update Raspberry Pi Hardware Model package which contains U-Boot and the RPi firmware: # Update the a/hwm-bw-raspberrypi-1.20250326-aarch64-1.txz rm -f hwm-hwm-bw-raspberrypi-* install -pm644 ${PKGSTORE}/a/hwm-bw-raspberrypi-* . # Leave package series directory: popd > /dev/null # Handle the 'k' series: pushd k > /dev/null rm -f kernel-source* install -pm644 ${rpi_kernelpkgdir}/kernel-source-*${HW_MODEL}*.t?z . slackdtxt kernel-source-*t?z # Leave package series directory: popd > /dev/null # Add any other package updates here. # Note that we don't replace the 'd/kernel-headers' package, since that should # remain the same version that the 'l/glibc' package was compiled against. # Re-enter the root of the repo # Example of the pwd now: /tmp/sair/mnt/SLKins_aio-pkgs/slackware popd > /dev/null } # Finalisation routine: # Anything final? No use cases at the moment. #function hwm_finalise() { # echo "Finalisation routine" #}