If I say Linux and Zynq MPSOC, I am pretty sure that most of you think of Petalinux. Petalinux is the official AMD’s tool that eases the build of a Linux distribution for FPGA and SoCs. What Petalinux gives us is a set of pre-configurations or recipes for Yocto, which is the tool running behind Petalinux, actually, it is Yocto that makes almost all the job. Yocto allows the users to create Linux distributions for many architectures, but it is not the one that allow this. On the other hand, we have Buildroot.Buildroot is also a tool that allows one to create Linux distributions but in an even easier way. Although AMD does not support Buildroot officially, Buildroot works also with a kind of recipe, that tells the tool how it has to compile Linux for a specific board, so if we have the correct recipe to build Linux for your board, you can use Buildroot in the same way as you can use Petalinux. In this article, we are going to build a Linux distribution for the Kria KD240 Drives Starter Kit using Buildroot.

First, we need to navigate to the downloads page of Buildroot, and download the last stable or LTS version available. Today, the latest version is 2024.02.5. If you want to test different versions of Buildroot, in its Github repository you can find either older or newer versions of the tool.

When the tool is downloaded, we can navigate to <buildroot path>/board/zynqmp/kria, and you will find that the three Kria starter kits are already supported for the tool, so to compile a Linux distribution or any of them we just need to navigate to<buildroot path>/, and execute the next line.

make zynqmp_kria_kd240_defconfig

This will generate all the default configurations for the board. If we want to review them or change them, we can open the menuconfig and modify whatever we need.

make menuconfig

When the configuration is complete, we have to execute the make command and wait.

make

This process takes some time, more or less the same as the petalinux-build command. Once it is finished, we can navigate to the folder output/images/, and we will find all the files generated by Buildroot.

pablo@miercoles:~/workspace_local/kd240_matlab_platform/buildroot-2024.02.5/output/images$ ls -la
total 118440
drwxr-xr-x 2 pablo pablo     4096 ago 15 20:39 .
drwxrwxr-x 6 pablo pablo     4096 ago 15 19:39 ..
-rw-r--r-- 1 pablo pablo    49362 ago 15 19:26 atf-uboot.ub
-rwxr-xr-x 1 pablo pablo    49298 ago 15 19:26 bl31.bin
-rw-r--r-- 1 pablo pablo   296372 ago 15 19:34 boot.bin
-rw-r--r-- 1 pablo pablo 33554432 ago 15 20:39 boot.vfat
-rw-r--r-- 1 pablo pablo      115 ago 15 20:39 extlinux.conf
-rw-r--r-- 1 pablo pablo 22305280 ago 15 19:39 Image
-rw-r--r-- 1 pablo pablo 62914560 ago 15 20:39 rootfs.ext2
lrwxrwxrwx 1 pablo pablo       11 ago 15 20:39 rootfs.ext4 -> rootfs.ext2
-rw-r--r-- 1 pablo pablo 96469504 ago 15 20:39 sdcard.img
lrwxrwxrwx 1 pablo pablo       37 ago 15 20:39 system.dtb -> zynqmp-smk-k24-revA-sck-kd-g-revA.dtb
-rw-r--r-- 1 pablo pablo  2922200 ago 15 19:34 u-boot.bin
-rw-r--r-- 1 pablo pablo  1439192 ago 15 20:39 u-boot.itb

Using Buildroot, the package process is executed at the same time as the build, so in this folder, we will find the sdcard.img file, which is the file that we have to copy to an SD card using the Disks tool of Ubuntu or Balena Etcher. When the SD card is ready, we can insert the SD card in the KD240 Kit, and Linux will boot.

By default, the Ethernet interface in down. To enable it, we can execute the next command.

# ifconfig eth0 up
[   62.352274] macb ff0c0000.ethernet eth0: PHY [ff0c0000.ethernet-ffffffff:08] driver [ADIN1300] (irq=POLL)
[   62.361879] macb ff0c0000.ethernet eth0: configuring for phy/rgmii-id link mode
[   62.370145] pps pps0: new PPS source ptp0
[   62.374247] macb ff0c0000.ethernet: gem-ptp-timer ptp clock registered.
[   65.442342] macb ff0c0000.ethernet eth0: Link is Up - 1Gbps/Full - flow control tx
[   65.449963] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready

Now, we need to configure the DHCP client for receiving an IP from the router, to do this we need to open the interfaces file with the command vi.

# cd /etc/network
# vi interfaces

In the interfaces file, we are going to add the configuration for the interface eth0.

# interface file auto-generated by buildroot

auto lo
iface lo inet loopback
 
auto eth0
iface eth inet dhcp

To save this file, we need to press the Esc button, and type :wq to save and exit. With this file updated, we can reboot the system to update the IP configuration.

# reboot

When the system is booted again, with the command ifconfig we can check that the IP is correct for the interface eth0.

# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0A:35:16:A9:E0  
          inet addr:192.168.100.149  Bcast:192.168.100.255  Mask:255.255.255.0
          inet6 addr: fe80::20a:35ff:fe16:a9e0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:656 (656.0 B)  TX bytes:1306 (1.2 KiB)
          Interrupt:44 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Now, we are going to enable the SSH access as root. Buildroot, by default, does not allow the root login over SSH, so it has to be enabled in the file sshd_config.

# cd /etc/ssh
# vi sshd_config

In this file, we need to modify the parameter permit root login to yes.

#LoginGraceTime 2m  
PermitRootLogin yes               
#StrictModes yes    
#MaxAuthTries 6                   
#MaxSessions 10   

With this parameter updated, we can log in over SSH as a root using the Linux terminal.

pablo@miercoles:~$ ssh [email protected]
[email protected]'s password: 
# 

Or even from Matlab with the next command.

>> h = zynq('linux', '192.168.100.149','root', 'kria', '/home/root')

h = 

  LinuxShell with properties:

    IPAddress: '192.168.100.149'
     Username: 'root'
         Port: 22

Unlike Petalinux, Buildroot uses the SD card as root file system by default, so all the configuration and files saved into the file tree are saved into the SD card, allowing the user to have a non-volatile storage. This can also be configured in Petalinux following this Note. Buildroot is another way of building Linux for AMD devices, it needs fewer commands than Petalinux to build a basic distribution however, what makes me try it is that Mathworks has an official Linux distribution for Zynq devices that allows them to be connected to Simulink through the PS, and it is based on Buildroot, so in future articles I will try to build the Matlab Linux distribution using Buildroot.