Ax5soc Build linux image from scratch
From Terasic Wiki
reference: rocket https://www.rocketboards.org/foswiki/Documentation/BuildingBootloaderForAgilex5
OS: Ubuntu-22.04 (PC or Windows WLS)
1. Setting Up Environment
- Install the required packages on Ubuntu:
sudo apt-get update sudo apt-get upgrade sudo apt install make bison flex python3-dev libssl-dev swig sudo apt install u-boot-tools sudo apt install qemu-user-static
- Create top folder:
mkdir ATUM_A5_V1.2.sdmmc cd ATUM_A5_V1.2.sdmmc export TOP_FOLDER=`pwd`
- Download and setup the the toolchain as follows:
cd $TOP_FOLDER 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-
2. Build Arm Trusted Firmware
cd $TOP_FOLDER 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 cd arm-trusted-firmware make -j $(nproc) PLAT=agilex5 bl31 cd ..
The following files is created:
- $TOP_FOLDER/arm-trusted-firmware/build/agilex5/release/bl31.bin (to used for u-boot.itb generation)
3. Build U-Boot
cd $TOP_FOLDER rm -rf u-boot-socfpga git clone -b atuma5_v1.1 https://github.com/terasic/u-boot-socfpga u-boot-socfpga cd u-boot-socfpga make mrproper cp atuma5.config .config # link to ATF ln -s ../arm-trusted-firmware/build/agilex5/release/bl31.bin make -j $(nproc)
The following files is created:
- $TOP_FOLDER/u-boot-socfpga/u-boot.itb
- $TOP_FOLDER/u-boot-socfpga/spl/u-boot-spl-dtb.hex
4. Creating the Boot Script
cd $TOP_FOLDER 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 mv agilex5_uboot.txt uboot.txt nano uboot.txt # content see bloew mkimage -f uboot_script.its boot.scr.uimg cd ..
uboot.txt
echo "Trying to boot Linux from device ${target}"; if test ${target} = "mmc0"; then 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
The following files is created: $TOP_FOLDER/uboot-script/boot.scr.uimg Edit </pre>
5. Build Linux Kernel
cd $TOP_FOLDER rm -rf linux-socfpga git clone --filter=tree:0 -b atuma5_v1.2 https://github.com/terasic/linux-socfpga 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
The following files is created:
- $TOP_FOLDER/linux-socfpga/arch/arm64/boot/Image
- $TOP_FOLDER/linux-socfpga/arch/arm64/boot/dts/intel/socfpga_agilex5_atuma5.dtb
6. Build Ubuntu 22.04.3
- Prepare rootfs folder
- Switch to root privilege
- Download the Ubuntu 22.04.3 root filesystem
- Copy qemu-user-static
- Modify etc/apt/sources.list to un-comment all the repositories except the ones starting with deb-src.
- copy your system’s (host machine’s) /etc/resolv.conf to etc/resolv.conf. Set proxies if necessary.
- Download a simple bash script for devices mounting and un-mounting later.
- Mount proc, sys, dev, dev/pts to the new filesystem.
- Update the repositories
- Install minimal packages required for core utils
- Install tools
- Install packages required for LXDE Desktop
- Install packagted requried for VNC XFCE Desktop
- Install packagted requried for text edit, network test
- Install packagted requried for WiFI USB Dongel. required 1GB
- Install bluez package requried for Bluetooth USB Dongel.
- sol RFCOMM issue
- Add a user account and include it in suitable groups
- Add host entry to /etc/hosts
- Exit chroot and unmount proc, sys, dev, dev/pts
- Return to user privilege
cd $TOP_FOLDER mkdir -p rootfs cd rootfs
sudo -s
wget -c https://cdimage.ubuntu.com/ubuntu-base/releases/22.04.3/release/ubuntu-base-22.04.3-base-arm64.tar.gz tar xvf ubuntu-base-22.04.3-base-arm64.tar.gz rm ubuntu-base-22.04.3-base-arm64.tar.gz
cp /usr/bin/qemu-aarch64-static usr/bin/
sed -i 's%^# deb %deb %' etc/apt/sources.list
cp /etc/resolv.conf etc/resolv.conf
cd .. wget https://raw.githubusercontent.com/psachin/bash_scripts/master/ch-mount.sh
chmod a+x ch-mount.sh ./ch-mount.sh -m rootfs/ 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
apt install bluez --yes apt clean
nano /lib/systemd/system/bluetooth.service ... modify ExecStart=/usr/lib/bluetooth/bluetoothd --compat
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
exit ./ch-mount.sh -u rootfs/
exit
7. Build SD Card Image
cd $TOP_FOLDER 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 ..
8. Build QSPI Image
- Make sure Quartus Pro 24.2 is installed.
- Goto GHRD project directory (copy from Atum A5 System CD)
- copy $TOP_FOLDER/u-boot-socfpga/u-boot.itb to software/u-boot/u-boot.itb
- copy $TOP_FOLDER/u-boot-socfpga/spl/u-boot-spl-dtb.hex to #software/u-boot/spl/u-boot-spl-dtb.hex
- Execute sof_with_hps.bat to generate output_files/golden_top_hps.sof
- Execute sof_to_jic.bat to generate output_files/golden_top_hps.jic