This project contains cmake and dependent bash scripts for de0-nano-soc debian boot SD-Card.
- Linux (debian 10 buster or 11 bullseye) host (amd64).
- Multiarch for armhf enabled on host.
- QEMU arm
sudo dpkg --add-architecture armhf
sudo apt-get -y install crossbuild-essential-armhf
sudo apt-get -y install build-essential bc libncurses5-dev cmake dkms git
sudo apt-get -y install flex bison u-boot-tools
- Get u-boot source from source.denx.de git repo into the sibling (adjacent) directory to socfpga_debian.
SOCFPGA=~/src/de0-nano-soc
mkdir -p $SOCFPGA
cd $SOCFPGA
git clone https://github.com/qtplatz/socfpga_debian
git clone https://source.denx.de/u-boot/u-boot.git- Configure u-boot, apply a patch and build (A patch adds -@ option for dt-overlay ready dtb file, so that is not necessary if you do not use dt-overlay.
cd $SOCFPGA/u-boot/
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- distclean
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- socfpga_de0_nano_soc_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
patch -p1 < ../socfpga_debian/u-boot.patch
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j`nproc`You should have the following u-boot files by now, which are required to make an SDCard image. The .dtb file generated here is enough to boot the soc; it will be overridden with the FPGA configuration later.
u-boot/u-boot.dtbu-boot/u-boot-with-spl.sfpu-boot/u-boot.img
The most effortless procedure is to obtain a kernel source from Debian to avoid kernel-header issues discussed later. This only works if your target and your build host use the same Debian version. Use 'apt source linux` command to get source package.
Option 1. Obtain from Debian source package
$ cd $SOCFPGA
$ apt source linux
$ KERNELRELEASE=`make -C linux-5.10.84 kernelversion` # <-- a value "5.10.84" need to be replaced with actual value.Option 2. Obtain from the Altera provided git-repo, which support device-tree overlay.
$ git clone https://github.com/altera-opensource/linux-socfpga
$ KERNELRELEASE=`make -C linux-socfpga kernelversion`Option 3. Obtain from the kernel.org
KERNELRELEASE=5.15.10
$ wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-${KERNELRELEASE}.tar.xz
$ tar xvf linux-${KERNELRELEASE}.tar.xzLinux kernel can configure the "socfpga" target by following three lines of commands. It will generate a file zImage.
cd linux-${KERNELRELEASE}
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- socfpga_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j`nproc`The kernel supported by Altera only be able to configure with device-tree overlay via /sys/kernel/config/device-tree interface.
The dynamic module configuration (DKMS) need a Linux-header module installation, which can generate by the following command;
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j`nproc` deb-pkgHowever, the built .deb package contains amd64 binary that causes an error of
scripts/basic/fixdep: Exec format errorwhen install dkms driver module on the target device. Indeed, fixdep is compiled with HOSTCC, which is amd64 binary. An attempt to rebuild by "make scripts" on /usr/src/linux-XX-headers directory caused "no Kconfig found" error.
Quick dirty hack of this hell is as follows:
- Make a full copy of linux-kernel build directory to the /usr/src directory on the target device
$ cd ${SOCFPGA}/${KERNELRELEASE}; make clean
$ cd ..
$ tar -acvf linux-${KERNELRELEASE}.tar.xz ./linux-${KERNELRELEASE}- Make (or replace) symbolic link bellow
nano # cd cd /lib/modules/$(uname -r)
nano # ln -s /usr/src/linux-$(uname -r) source
nano # ln -s /usr/src/linux-$(uname -r) buildYou can install the header module via apt-get if you pick the kernel release from one of the official Debian distributions. You also have to make a symbolic links corresponding to above.
The symbolic links can be created on the
rootfsorimgfile will create on the next section. Easy way is make a copy torootfs, which is usual directory tree on the Linux.
$ distro=bullseye
$ mkdir $SOCFPGA/build-${distro}
$ cd $SOCFPGA/build-${distro}
$ cmake -DKERNELRELEASE=${KERNELRELEASE} -Ddistro=${distro} $SOCFPGA/socfpga_debianThe success of the cmake command creates a Makefile in the build directory. You can find a list of make sub-commands by typing make help.
It will generate a Debian rootfs (root file system) directory tree under the current directory with a top directory name of 'arm-linux-gnueabihf-rootfs-${distro}.' This step takes a few minutes. This process requires root privilege due to elevated commands being in script files.
After rootfs is created, copy and merge boot files and rootfs into a single .img file by the following step.
This step also requires root privilege for the 'sudo' command.
You have a .img file such as 'socfpga_bullseye-5.10.84.img', which is ready to copy to micro SD card for boot the SoC; however, it is a minimum set of files to boot SoC using standard device-tree provided from u-boot. Of course, you can make a boot SD card image now and then add the FPGA configuration, device-tree (.dtb), altered Linux boot file (zImage), and your application files to the target device after booting up. In addition, you have an option where you can install all the above before .img copy to the micro SD card. It would be handy to generate several micro SD cards ready to go with the application.
- Run 'make mount' command will mount .img file under '/mnt/bootfs' and '/mnt/rootfs' folders of host system. (Don't forget to run 'make umount' after necessary tasks are done.)
- Do 'sudo chroot /mnt/rootfs' to access the target root filesystem with root privilege. You can use almost all Linux shell commands, including apt-get and the dpkg commands.
Following is an example walkthrough to install socfpga_modules application setup.
## on build host (amd64)
$ cd ${SOCFPGA}/build-${distro)
$ make socfpga-modules # <-- this command copies files from socfpga_modules (it must be built in advance)
$ make mount
$ sudo chroot /mnt/rootfs
# cd /root
# dpkg -i *dkms*.deb # <-- install all kernel modules
# dpkg -i qtplatz-5.2.4.39-Linux-Runtime.deb # <-- install qtplatz core libraries
# dpkg -i socfpga_modules-5.0.1.25-Linux-httpd.deb # <-- sample httpd
# dpkg -i socfpga_modules-5.0.1.25-Linux-tools.deb # <-- command line tools for testing
# exit
$ make umount # <-- unmounting /mnt/bootfs and /mnt/rootfs- Using dd command, copy generated img file to micro SD Card.
dd if=socfpga_buster-${KERNELRELEASE}.img of=/dev/sdX bs=1M; sync- Set SDCard to
de0-nano-soc - Connect USB cable to
de0-nano-soc - And, connect terminal using
screen /dev/ttyUSB0 115200, and then power on. - You can login as root without password
- Initial SDCard allocates only 2.5GB image, it can be expanded to full SDCard size by executing
/root/resizefs.shscript, and reboot.
At this moment, no FPGA configuration has applied. At this moment, no FPGA configuration has been applied yet. Continue to process socfpga_modules for it.
-
The file system utilizes 4 GB on the micro SD card. You can run '/root/resizefs.sh` script and reboot that will be expanding file system size to a maximum of physical micro SD card.
-
Network is configured with traditional ifup/ifdown (not the modern NetworkManager). You can change IP address (DHCP by default) by editing /etc/network/interface file.
-
In case you have socfpga_modules installed, you can access SoC from web broswer by "http:///"
-
You can also test ADC via a command "/usr/local/bin/adc -c 99" etc.
END-of-FILE