Skip to content

Instantly share code, notes, and snippets.

@ramachas
Created August 21, 2026 22:35
Show Gist options
  • Save ramachas/72cf0931b2f6ea678fa968081f7048a1 to your computer and use it in GitHub Desktop.
Save ramachas/72cf0931b2f6ea678fa968081f7048a1 to your computer and use it in GitHub Desktop.
Atum A5 image builder
# Commands to build an Ubuntu SD card image for the Atum A5, from:
# https://www.terasic.com.tw/wiki/Atum_A5_:_Build_linux_image_from_scratch
#
# Sudo commands require a password.
# And there's some locale setting needed. It seems like the fix is to set some
# environment variables (serverfault.com/questions/949991/how-to-install-tzdata-on-a-ubuntu-docker-image)
#
# TODO: The targets should probably be specific build artifacts, rather than
# directories. Have an initial target to just fetch the repos.
#
# Note: We use "order-only prerequisites" (target: | prereq) for directories
# to only run those targets once.
export TOP_FOLDER=$(CURDIR)
export PATH:=$(TOP_FOLDER)/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin:$(PATH)
export ARCH:=arm64
export CROSS_COMPILE:=aarch64-none-linux-gnu-
export DEBIAN_FRONTEND=noninteractive
export TZ=America/New_York
SUDO=sudo
# Execute all commands in a recipe in one sub-shell. This makes `cd` work.
.ONESHELL:
.SHELLFLAGS += -e
#===============================================================================
.PHONY: all fetch clean
all: fetch sd_card
fetch: gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu arm-trusted-firmware linux-socfpga u-boot-socfpga uboot-script
clean:
# -rm -rf gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu
-rm -rf arm-trusted-firmware
-rm -rf uboot-socfpga
-rm -rf uboot-script
-rm -rf linux-socfpga
-sudo rm -rf rootfs
-sudo rm -rf sd_card
#===============================================================================
gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu:
wget https://developer.arm.com/-/media/Files/downloads/gnu/11.2-2022.02/binrel\
/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu.tar.xz
tar xf gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu.tar.xz
rm -f gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu.tar.xz
export PATH=`pwd`/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin:$PATH
export ARCH=arm64
export CROSS_COMPILE=aarch64-none-linux-gnu-
arm-trusted-firmware:
-rm -rf arm-trusted-firmware
git clone -b QPDS24.1_REL_AGILEX5_GSRD_PR https://github.com/altera-opensource/arm-trusted-firmware arm-trusted-firmware
arm-trusted-firmware/build/agilex5/release/bl31.bin: | arm-trusted-firmware
cd arm-trusted-firmware
make -j $$(nproc) PLAT=agilex5 bl31
u-boot-socfpga:
-rm -rf u-boot-socfpga
git clone -b atuma5_v1.1 https://github.com/terasic/u-boot-socfpga u-boot-socfpga
u-boot-socfpga/u-boot.itb: arm-trusted-firmware/build/agilex5/release/bl31.bin | u-boot-socfpga
cd u-boot-socfpga
make mrproper
cp atuma5.config .config
# link to ATF
ln -sf ../arm-trusted-firmware/build/agilex5/release/bl31.bin
make -j $$(nproc)
define UBOOT_TXT
echo "Trying to boot Linux from device $${target}";
if test $${target} = "mmc0"; then
bridge enable;
echo "Found kernel in mmc0";
mmc rescan;
fatload mmc 0:1 $${kernel_addr_r} Image;
fatload mmc 0:1 $${fdt_addr_r} socfpga_agilex5_terasic.dtb;
setenv bootargs "console=ttyS0,115200 root=$${mmcroot} rw rootwait";
booti $${kernel_addr_r} - $${fdt_addr_r};
exit;
fi
endef
uboot-script:
-rm -rf uboot-script
mkdir uboot-script && cd uboot-script
wget https://releases.rocketboards.org/2023.12/qspi/agilex5/agilex5_uboot.txt
wget https://releases.rocketboards.org/2021.11/uboot-script/agilex/uboot_script.its
uboot-script/boot.scr.uimg: | uboot-script
cd uboot-script
# mv agilex5_uboot.txt uboot.txt
# nano uboot.txt # content see bloew
echo '$(UBOOT_TXT)' > uboot.txt
mkimage -f uboot_script.its boot.scr.uimg
linux-socfpga:
-rm -rf linux-socfpga
git clone --filter=tree:0 -b atuma5_v1.2 https://github.com/terasic/linux-socfpga linux-socfpga
linux-socfpga/arch/arm64/boot/Image: | linux-socfpga
cd linux-socfpga
cp atuma5.config .config
make -j $$(nproc) Image && make intel/socfpga_agilex5_atuma5.dtb
make -j $$(nproc) modules
make -j $$(nproc) modules_install INSTALL_MOD_PATH=modules_install
rm -rf modules_install/lib/modules/*/build
rm -rf modules_install/lib/modules/*/source
rootfs:
-sudo rm -rf rootfs
mkdir -p rootfs
cd rootfs
$(SUDO) wget -c https://cdimage.ubuntu.com/ubuntu-base/releases/22.04.3/release/ubuntu-base-22.04.3-base-arm64.tar.gz
$(SUDO) tar xvf ubuntu-base-22.04.3-base-arm64.tar.gz
$(SUDO) rm ubuntu-base-22.04.3-base-arm64.tar.gz
$(SUDO) cp /usr/bin/qemu-aarch64-static usr/bin/
$(SUDO) sed -i 's%^# deb %deb %' etc/apt/sources.list
$(SUDO) cp /etc/resolv.conf etc/resolv.conf
cd ..
# mnt
$(SUDO) mount -t proc /proc rootfs/proc
$(SUDO) mount -t sysfs /sys rootfs/sys
$(SUDO) mount -o bind /dev rootfs/dev
$(SUDO) mount -o bind /dev/pts rootfs/dev/pts
$(SUDO) chroot rootfs/ bash -c "
export LANG=C.UTF-8
unset LC_NUMERIC
unset LC_TIME
unset LC_MEASUREMENT
unset LC_TELEPHONE
unset LC_IDENTIFICATION
unset LC_PAPER
unset LC_MONETARY
unset LC_NAME
unset LC_ADDRESS
apt update
apt install apt-utils dialog --yes
apt install language-pack-en-base sudo ssh net-tools ethtool iputils-ping rsyslog bash-completion vim-tiny kmod --yes
apt install isc-dhcp-client network-manager --yes
apt clean
cat <<EOF >/etc/NetworkManager/conf.d/allow-ethernet.conf
[keyfile]
unmanaged-devices=*,except:type:wifi,except:type:gsm,except:type:cdma,except:type:ethernet
EOF
apt install usbutils --yes
apt install gpiod --yes
apt install memtester --yes
apt install fdisk --yes
apt clean
apt install lxde xfce4-power-manager xinit xorg lightdm-gtk-greeter xserver-xorg-video-fbdev gnome-mplayer lightdm lxtask htop --yes
apt install xfce4 xfce4-goodies --yes
apt install tightvncserver --yes
apt clean
apt install nano --yes
apt install iperf3 --yes
apt clean
apt install --reinstall linux-firmware --yes
apt clean
# nano /lib/systemd/system/bluetooth.service ... modify ExecStart=/usr/lib/bluetooth/bluetoothd --compat
sed -i -e 's/bluetoothd/bluetoothd --compat/' /lib/systemd/system/bluetooth.service
useradd terasic -m -s /bin/bash
echo terasic:123 | chpasswd
addgroup terasic adm && addgroup terasic sudo
addgroup terasic audio && addgroup terasic video
echo '127.0.0.1 localhost' >> /etc/hosts
"
#umnt
$(SUDO) umount rootfs/proc
$(SUDO) umount rootfs/sys
$(SUDO) umount rootfs/dev/pts
$(SUDO) umount rootfs/dev
sd_card: u-boot-socfpga/u-boot.itb linux-socfpga/arch/arm64/boot/Image uboot-script/boot.scr.uimg rootfs
-sudo rm -rf sd_card
mkdir sd_card && cd sd_card
wget https://releases.rocketboards.org/release/2020.11/gsrd/tools/make_sdimage_p3.py
# remove mkfs.fat parameter which has some issues on Ubuntu 22.04
sed -i 's/\"\-F 32\",//g' make_sdimage_p3.py
chmod +x make_sdimage_p3.py
mkdir fatfs && cd fatfs
cp $$TOP_FOLDER/u-boot-socfpga/u-boot.itb .
cp $$TOP_FOLDER/linux-socfpga/arch/arm64/boot/Image .
cp $$TOP_FOLDER/linux-socfpga/arch/arm64/boot/dts/intel/socfpga_agilex5_atuma5.dtb socfpga_agilex5_terasic.dtb
cp $$TOP_FOLDER/uboot-script/boot.scr.uimg .
cd ..
mkdir rootfs && cd rootfs # renew: sudo rm -rf rootfs && mkdir rootfs && cd rootfs
sudo cp -a $$TOP_FOLDER/rootfs/* .
cd $$TOP_FOLDER/linux-socfpga
sudo make -j $$(nproc) modules_install INSTALL_MOD_PATH=$$TOP_FOLDER/sd_card/rootfs
cd $$TOP_FOLDER/sd_card
sudo python3 make_sdimage_p3.py -f \
-P fatfs/*,num=1,format=fat32,size=500M \
-P rootfs/*,num=2,format=ext3,size=3300M \
-s 3800M \
-n sdcard.img
cd ..
Sign in to join this conversation on GitHub.