# 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/rpi4 # Purpose: Raspberry Pi 4 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 ;} # This handler relates to the Raspberry Pi 4. This string is used to match # the Slackware package files - e.g. 'kernel_armv8-6.12.44-aarch64-1_rpi4.txz' rpi_hwm=rpi4 kernel_base=kernel_armv?-+([^-])-+([^-])-+([^-])_${rpi_hwm} 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 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 ${rpi_hwm}/${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/bcm2711/assets/config.txt ${fs_loc}/ # RPi's proprietary Linux Kernel cmdline settings: # $fs_loc/cmdline.txt # If you plan on not using U-Boot, you will need to modify this file. # When using U-Boot (the standard Slackware approach for the RPis) you should never need to edit this file, # and it's shipped empty in Slackware. # Slackware uses U-Boot to set these, and are handled within this script's handler function # 'fs_handler_SLKboot'. # 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}/ # 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: install -pm755 $TMPDIR/extract/kernel/boot/Image-armv* ${fs_loc}/slk_image-armv8 ###################################################################################### # For development purposes, we'll copy the dev versions from a local repository: #[ -f ${SAIRDATA}/cmdline.txt ] && install -vpm644 ${SAIRDATA}/cmdline.txt $fs_loc/ #[ -f ${SAIRDATA}/config.txt ] && install -vpm644 ${SAIRDATA}/config.txt $fs_loc/ ###################################################################################### } # /boot/platform/hwm_bw 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="" # 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 # Enter the versioned Slackware tree: 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-*${rpi_hwm}*.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" #}