Building a Linux 5.5.0-rc1 kernel for SPARC-32 for christmas

Most of the files mentionned are available at: dashie/sparc32: Dashie's various sparc32 things - sparc32 - Dashie's gitea

This git repository also contains a bootable gentoo-sparc-2005.0-20050413.tftpboot with a 2.x kernel, the rootfs contained into that tftpboot file has been extracted to gentoo-sparc-2005.0-20050413.initrd that you can use, without any kernel modules or newer busybox because of space restriction, but it does have an init and dropbear and more tools than juste a busybox.

So you can uses it as your root.img file, and skipping the kernel modules.

Building elftoaout, needed to convert the kernel elf to a a.out file

mkdir linux
cd linux
wget https://ftp.osuosl.org/pub/clfs/conglomeration/elftoaout/elftoaout-2.3-64bit_fixes-1.patch
wget http://113.35.21.242/debian-mirror/squeeze_20120726/pool/main/s/sparc-utils/sparc-utils_1.9-4.diff.gz
wget http://113.35.21.242/debian-mirror/squeeze_20120726/pool/main/s/sparc-utils/sparc-utils_1.9.orig.tar.gz
wget https://gitweb.gentoo.org/repo/gentoo.git/plain/sys-apps/sparc-utils/files/sparc-utils-1.9-no-implicit.patch
wget https://busybox.net/downloads/binaries/1.21.1/busybox-sparc

# Extract archive
tar xvf sparc-utils_1.9.orig.tar.gz

# Apply various patches
patch -p0 < sparc-utils_1.9-4.diff
cd sparc-utils-1.9.orig
patch -p1 < ../sparc-utils-1.9-no-implicit.patch
patch -p0 < ../elftoaout-2.3-64bit_fixes-1.patch

# Build and install
cd elftoaout-2.3
make
sudo cp elftoaout /usr/local/bin
sudo cp elftoaout.1 /usr/local/man/man1/elftoaout.1

Building a GCC Toolchain

Use: GitHub - crosstool-ng/crosstool-ng: A versatile (cross-)toolchain generator.

And build a sparc-unknown-linux-gnu toolchain.

Build kernel

# Generate the default config:
ARCH=sparc CROSS_COMPILE=/home/dashie/x-tools/sparc-unknown-linux-gnu/bin/sparc-unknown-linux-gnu- make sparc32_defconfig

# Then edit it
ARCH=sparc CROSS_COMPILE=/home/dashie/x-tools/sparc-unknown-linux-gnu/bin/sparc-unknown-linux-gnu- make menuconfig

# And set:
# General Setup
#  Compiler optimization level (set to -Os)
#
# It takes the size down from 5M to 4.4M.

# Build the kernel
ARCH=sparc CROSS_COMPILE=/home/dashie/x-tools/sparc-unknown-linux-gnu/bin/sparc-unknown-linux-gnu- make

# Start the rootfs procedure until it told you to go back to "modules_install"
# Install the kernel modules:
sudo ARCH=sparc 
 CROSS_COMPILE=/home/dashie/x-tools/sparc-unknown-linux-gnu/bin/sparc-unknown-linux-gnu- make modules_install INSTALL_MOD_PATH=/mnt/

# Then you can finish making your final "tftpboot.img" file
ARCH=sparc CROSS_COMPILE=/usr/local/cross/sparc32/bin/sparc-leon3-linux-gnu- make tftpboot.img

Creating the rootfs: root.img

# Create a 4M file, there is some restrictions of size with the OpenBoot PROM and >4M seems to make it burp
dd if=/dev/zero of=/usr/src/root.img bs=1M count=4

# Format in EXT2
mkfs.ext2 /usr/src/root.img

# Mount the file partition
mount -o loop /usr/src/root.img /mnt/
cd /mnt/

# Create some required files
mkdir -p bin dev dev/pts etc sbin usr/bin usr/sbin tmp proc sys
cp ~dashie/linux/busybox-sparc bin/busybox
chmod +x bin/busybox
cd bin
# This will create a bunch of symbolic links for busybox
for i in $(busybox --list)
 do
   ln -s busybox $i
 done
# Proc mount
cd ..
echo "proc                    /proc    proc            defaults               0 0" > etc/fstab

cd /usr/src

# Here you need to do the "modules_install" command then:
umount /mnt

# I choosed a gzip, but you can do either a xz or gzip, as you wish
# To create a "xz" rootfs:
xz --check=none --lzma2=dict=1MiB root.img
mv root.img.xz root.img
# To create a "gzip" one:
gzip -v9 root.img
mv root.img.gz root.img

Booting on sparc32

On my OpenBoot PROM I booted it with, where 192.168.10.106 is my TFTP/RARP server:

boot net-aui:192.168.10.106,tftpboot.img

You can specify a kernel command line too:

boot net-aui:192.168.10.106,tftpboot.img init=/bin/sh

For TFTP/RARP you can refer to this tutorial by me.