Ax5soc Build linux image from scratch

From Terasic Wiki

(Difference between revisions)
Jump to: navigation, search
(Created page with "reference: rocket https://www.rocketboards.org/foswiki/Documentation/BuildingBootloaderForAgilex5 OS: Ubuntu-22.04 (PC or Windows WLS) ---- '''1. Setting Up Environment''' * In...")
 
(9 intermediate revisions not shown)
Line 30: Line 30:
export CROSS_COMPILE=aarch64-none-linux-gnu-
export CROSS_COMPILE=aarch64-none-linux-gnu-
</pre>
</pre>
 +
 +
'''2. Build Arm Trusted Firmware'''
 +
<pre>
 +
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 ..
 +
</pre>
 +
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'''
 +
<pre>
 +
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)
 +
</pre>
 +
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'''
 +
<pre>
 +
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 ..
 +
</pre>
 +
 +
uboot.txt
 +
<pre>
 +
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
 +
</pre>
 +
The following files is created:
 +
$TOP_FOLDER/uboot-script/boot.scr.uimg
 +
Edit
 +
</pre>
 +
 +
 +
'''5. Build Linux Kernel'''
 +
<pre>
 +
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
 +
</pre>
 +
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'''
 +
<ol start="1">
 +
<li>Prepare rootfs folder</li>
 +
 +
<pre>
 +
cd $TOP_FOLDER
 +
mkdir -p rootfs
 +
cd rootfs
 +
</pre>
 +
<li>Switch to root privilege</li>
 +
<pre>
 +
sudo -s
 +
</pre>
 +
<li>Download the Ubuntu 22.04.3 root filesystem</li>
 +
<pre>
 +
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
 +
</pre>
 +
<li>Copy qemu-user-static</li>
 +
<pre>
 +
cp /usr/bin/qemu-aarch64-static usr/bin/
 +
</pre>
 +
<li>Modify etc/apt/sources.list to un-comment all the repositories except the ones starting with deb-src.</li>
 +
<pre>
 +
sed -i 's%^# deb %deb %' etc/apt/sources.list
 +
</pre>
 +
<li>copy your system’s (host machine’s) /etc/resolv.conf to etc/resolv.conf. Set proxies if necessary.</li>
 +
<pre>
 +
cp /etc/resolv.conf etc/resolv.conf
 +
</pre>
 +
<li>Download a simple bash script for devices mounting and un-mounting later.</li>
 +
cd ..
 +
wget https://raw.githubusercontent.com/psachin/bash_scripts/master/ch-mount.sh
 +
<li>Mount proc, sys, dev, dev/pts to the new filesystem.</li>
 +
<pre>
 +
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
 +
</pre>
 +
<li>Update the repositories</li>
 +
<pre>
 +
apt update
 +
</pre>
 +
<li>Install minimal packages required for core utils</li>
 +
<pre>
 +
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
 +
</pre>
 +
<li>Install tools</li>
 +
<pre>
 +
apt install usbutils --yes
 +
apt install gpiod --yes
 +
apt install memtester --yes
 +
apt install fdisk --yes
 +
apt clean
 +
</pre>
 +
<li>Install packages required for LXDE Desktop</li>
 +
<pre>
 +
apt install lxde xfce4-power-manager xinit xorg lightdm-gtk-greeter xserver-xorg-video-fbdev gnome-mplayer lightdm lxtask htop --yes
 +
</pre>
 +
<li>Install packagted requried for VNC XFCE Desktop</li>
 +
<pre>
 +
apt install xfce4 xfce4-goodies --yes
 +
apt install tightvncserver --yes
 +
apt clean
 +
</pre>
 +
<li>Install packagted requried for text edit, network test</li>
 +
<pre>
 +
apt install nano --yes
 +
apt install iperf3 --yes
 +
apt clean
 +
</pre>
 +
<li>Install packagted requried for WiFI USB Dongel. required 1GB</li>
 +
<pre>
 +
apt install --reinstall linux-firmware --yes
 +
apt clean
 +
</pre>
 +
<li>Install bluez package requried for Bluetooth USB Dongel.</li>
 +
<pre>
 +
apt install bluez --yes
 +
apt clean
 +
</pre>
 +
<li>sol RFCOMM issue</li>
 +
<pre>
 +
nano /lib/systemd/system/bluetooth.service ... modify ExecStart=/usr/lib/bluetooth/bluetoothd --compat
 +
</pre>
 +
<li>Add a user account and include it in suitable groups</li>
 +
<pre>
 +
useradd terasic -m -s /bin/bash
 +
echo terasic:123 | chpasswd
 +
addgroup terasic adm && addgroup terasic sudo
 +
addgroup terasic audio && addgroup terasic video
 +
</pre>
 +
<li>Add host entry to /etc/hosts</li>
 +
<pre>
 +
echo "127.0.0.1    localhost" >> /etc/hosts
 +
</pre>
 +
<li>Exit chroot and unmount proc, sys, dev, dev/pts</li>
 +
<pre>
 +
exit
 +
./ch-mount.sh -u rootfs/
 +
</pre>
 +
<li>Return to user privilege</li>
 +
<pre>
 +
exit
 +
</pre>
 +
 +
</ol>
 +
 +
'''7. Build SD Card Image'''
 +
<pre>
 +
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 ..
 +
</pre>
 +
'''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
 +
 +
[[Atum A5  How to rebuild Linux BSP V120|back]]

Latest revision as of 11:09, 18 October 2024

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

  1. Prepare rootfs folder
  2. cd $TOP_FOLDER
    mkdir -p rootfs
    cd rootfs
    
  3. Switch to root privilege
  4. sudo -s
    
  5. Download the Ubuntu 22.04.3 root filesystem
  6. 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
    
  7. Copy qemu-user-static
  8. cp /usr/bin/qemu-aarch64-static usr/bin/
    
  9. Modify etc/apt/sources.list to un-comment all the repositories except the ones starting with deb-src.
  10. sed -i 's%^# deb %deb %' etc/apt/sources.list
    
  11. copy your system’s (host machine’s) /etc/resolv.conf to etc/resolv.conf. Set proxies if necessary.
  12. cp /etc/resolv.conf etc/resolv.conf
    
  13. Download a simple bash script for devices mounting and un-mounting later.
  14. cd .. wget https://raw.githubusercontent.com/psachin/bash_scripts/master/ch-mount.sh

  15. Mount proc, sys, dev, dev/pts to the new filesystem.
  16. 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
    
  17. Update the repositories
  18. apt update
    
  19. Install minimal packages required for core utils
  20. 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
    
  21. Install tools
  22. apt install usbutils --yes
    apt install gpiod --yes
    apt install memtester --yes
    apt install fdisk --yes
    apt clean
    
  23. Install packages required for LXDE Desktop
  24. apt install lxde xfce4-power-manager xinit xorg lightdm-gtk-greeter xserver-xorg-video-fbdev gnome-mplayer lightdm lxtask htop --yes
    
  25. Install packagted requried for VNC XFCE Desktop
  26. apt install xfce4 xfce4-goodies --yes
    apt install tightvncserver --yes
    apt clean
    
  27. Install packagted requried for text edit, network test
  28. apt install nano --yes
    apt install iperf3 --yes
    apt clean
    
  29. Install packagted requried for WiFI USB Dongel. required 1GB
  30. apt install --reinstall linux-firmware --yes
    apt clean
    
  31. Install bluez package requried for Bluetooth USB Dongel.
  32. apt install bluez --yes
    apt clean
    
  33. sol RFCOMM issue
  34. nano /lib/systemd/system/bluetooth.service ... modify ExecStart=/usr/lib/bluetooth/bluetoothd --compat
    
  35. Add a user account and include it in suitable groups
  36. useradd terasic -m -s /bin/bash
    echo terasic:123 | chpasswd
    addgroup terasic adm && addgroup terasic sudo
    addgroup terasic audio && addgroup terasic video
    
  37. Add host entry to /etc/hosts
  38. echo "127.0.0.1    localhost" >> /etc/hosts
    
  39. Exit chroot and unmount proc, sys, dev, dev/pts
  40. exit
    ./ch-mount.sh -u rootfs/
    
  41. Return to user privilege
  42. 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

  1. Make sure Quartus Pro 24.2 is installed.
  2. Goto GHRD project directory (copy from Atum A5 System CD)
  3. copy $TOP_FOLDER/u-boot-socfpga/u-boot.itb to software/u-boot/u-boot.itb
  4. copy $TOP_FOLDER/u-boot-socfpga/spl/u-boot-spl-dtb.hex to #software/u-boot/spl/u-boot-spl-dtb.hex
  5. Execute sof_with_hps.bat to generate output_files/golden_top_hps.sof
  6. Execute sof_to_jic.bat to generate output_files/golden_top_hps.jic

back

Personal tools