Tuesday, August 6, 2019

Embedded Linux on Zynq, how to transfer files from a computer to Linux

How to run Linux on Zynq was described here.

By default, to transfer files to the Linux kernel from Xilinx, you can use several methods, which are described on their wiki: xilinx-wiki.atlassian.net.

Files can be transferred to the working system both via the Ethernet port and via the USB (UART) port. But since the file system is in RAM, when the power is turned off, added files will disappear. To save them you will need to change the rootfs file system. First, let's try transferring files via ethernet.

It is worth noting that by default, U-Boot will try to find the Linux kernel via the Ethernet port before searching for it on QSPI. If the cable is not connected, then U-Boot proceeds to the next step, otherwise boot process takes a lot of time, but still will be executed from QSPI.

Firstly, let's check how the network is configured. To do this, use the ifconfig command, which displays all the included network interfaces:


Fig. 1 Executing the ifconfig command
But in our case, nothing is running. Also, when connecting an Ethernet cable with Zynq and any other network device (such as a computer), the lights on the board do not light up and Linux does not react in any way to the new connection.

let's check which network interfaces are configured in the system with command
"ifconfig -a":

Fig.2 Executing the ifconfig -a command
As you can see in our case there are several network interfaces:
eth0 is the first ethernet interface,
lo - loopback, more details here,
sit0 - Simple Internet Transition, used to transmit IPv6 over IPv4, more details here.

We are interested in eth0, at the moment it is turned off, in order to turn it on we use the
"ifconfig eth0 up":

Fig. 3 Enabling the interface
Now, when viewing the enabled ethernet interfaces, it will be displayed:

Рис.4 Проверка включения интерфейса
And Linux responds to the connection of a new network device (Ethernet cable between the computer and Zybo, RJ-45 connector), with flashing lights and information output to the terminal:

Fig. 5 Terminal output when connecting an Ethernet device
But, by default, the IP address is not set, let's configure everything and check the ethernet connection.

First, configure the network device to which Zybo is connected, in my case it is a computer, it is necessary to set the correct IP address. The main thing is that both devices are on the same subnet. The settings are as follows:
IP address 192.168.1.11
Subnet mask 255.255.255.0

Fig. 6 Computer IP settings
To configure Zybo, use the command "ifconfig eth0 192.168.1.10":

Fig. 7 Interface settings
After that, you can check the connection from Zybo to the computer, for this, use the command "ping 192.168.1.11", in order to stop command execution, use the combination "CTRL + C", otherwise it will be running forever:

Fig. 8 test connection Zybo -> PC
Now you can check the connection computer -> Zybo. In Windows the same command is used, but now we use Zybo's IP address: "ping 192.168.1.10":

Fig. 9 Checking PC -> Zybo connection
Now the connection is established between the devices.

SFTP

1 Method to transfer files is via SFTP, SSH File Transfer Protocol. It is enabled by default in Zybo, ethernet is configured, so everything should work. To transfer files, you need to install some client on the transfer side. In Windows, I used "psftp". By default, the login and password for accessing Zybo is "root".

Move the file from computer D:/study/test_file.txt в Zybo /usr/:

Fig. 10 Moving a file through sftp

ROOTFS

Files can be transferred in both directions, but when the power is turned off, all changes made will be lost. It happens because the file system is located in random access memory (RAM). In order for the files to not disappear when the power is turned off, they must be added to the rootfs file system and the boot image BOOT.bin should be rewritten again. In the same way, additional programs are installed on our system.

A description of the required actions is indicated here: xilinx-wiki.atlassian.net.

If you are using rootfs with the U-boot header already added, then you must first remove it, otherwise you can’t unzip it. If the file is in the root directory, then use this command:

"dd if = uramdisk.image.gz bs = 64 skip = 1 of = ramdisk.gz", a file with a compressed file system with an added header is called "uramdisk.image.gz", a new file "ramdisk.gz", without U-boot title, will appear next to it .

Fig. 11 Removing a header from a file
Next, you need to unzip it using the command "gunzip ramdisk.gz"

Fig. 12 Unzipping a file

As a result, we got an image of the file system; to change it, you need to mount it. First, change the file permissions, you must allow it's execution:
"chmod u+rwx ramdisk".

Next, create the "tmp_mnt" folder into which the system will be mounted using the command:
"mkdir tmp_mnt".

The last thing is to mount the system with the command:
"sudo mount -o loop ramdisk tmp_mnt"

Fig. 13 Changing priorities and mounting an image

Now the file system is mounted and you can make changes to it. For the sake of example, let's create  "rootfs_test_file.txt" file and move it to the /usr/ directory, commands:

"cat > rootfs_test_file.txt" - create a new file and open it for writing
"CTRL+C" - stop writing to the file and close it
"sudo mv rootfs_test_file.txt tmp_mnt/usr/" - move the file
"ls tmp_mnt/usr" - output it's content for verification

Fig. 14 Creating a file and moving it
After the changes, you need to unmount the file, compress it and add the U-boot header to it:

"sudo umount tmp_mnt/"- unmount
"gzip ramdisk" - compression
"u-boot-xlnx/tools/mkimage -A arm -T ramdisk -C gzip -d ramdisk.gz uramdisk.image.gz" - adding a U-boot header, for this you need the mkimage utility supplied with U-boot. It was used in previous tutorial

Fig. 15 Archiving a file and adding a header
The file is ready, you can make a new boot file and check it. How to create boot image was explained in previous tutorial.

After starting Linux, you can verify that the file is in place:

Fig. 16 Checking the added file


No comments :

Post a Comment