2014年7月9日 星期三

[Xilinx] Booting Petalinux on Zynq through JTAG+TFTP, w/o an SD Card


Hi all,
I am quite new to Zynq System and spend a few days to port a working Linux on the chip. Xilinx provides both XSDK for baremetal developments and petalinux for linux deployment. Personally I hate keep plugging the SD for every single time especially when I deal with linux development.
However, The "petalinux-boot" utility always fail to boot a working linux or we can't even transfer the image to the DRAM. I would like to make all the stuff done with JTAG,LAN and standard tools like XMD. I would like to share the solution I have realized after a few days of struggling. Hope this helps your development.

We assume:
1. You have finished the "petalinux-create" for a petalinux file system.
2. You have configured the system through "petalinux-config"
3. You have finished the compilation of your system through "petalinux-build".
If you failed to build the rootfs, please try to run the build for TWICE MORE. It works.
4. You have exported your hardware and they can be accessed by XSDK.

You will have the following files in "<PetaLinux Dir>/images/linux"
1. image.ub > Kernel Image for u-boot
2. urootfs.cpio.gz > RootFS for linux in u-boot format
3. system.dtb > Device Tree Blob
They should be also located in "/tftpboot". They should be identical.

You will need two more files for the setup.
1. The bit stream of your PL/FPGA Design
You can find them through [find . -name "*.bit"]
2. The TCL Script to initialize the PS/ARM.
It is located at the "someDesign.sdk/hardware platform" under your Vivado project folder.
You can find them through [find . -name "*ps7_init.tcl"].
Copy these files to the "<PetaLinux Dir>/images/linux" is recommended.

After that, you can use XMD to boot the system. You also need an UART connection to your FPGA.

Steps:
1. > xmd
2. xmd> source ps7_init.tcl
3. xmd> connect arm hw
5. xmd> ps7_init
6. xmd> ps7_post_conf
7. xmd> dow u-boot.elf
8. xmd> run
9. xmd> fpga -f bitstream.bit

Step 5 and 6 enable the DDR-RAM PLL for DDR-RAM access. And these routine is located in the "ps7_init.tcl" mentioned.
Step 7 and 8 launch u-boot through JTAG.
Connecting the UART through a terminal application (e.g. Putty) and stop the auto boot process.
Step 9 downloads the bitstream to the FPGA. Without this, the kernel might stuck because it can't find the custom device through AXI ports and fail the process.

9. uboot> tftpboot 0x1000000 /tftpboot/image.ub
10. uboot> tftpboot 0x2000000 /tftpboot/urootfs.cpio.gz
11. uboot> tftpboot 0x3000000 /tftpboot/system.dtb
12. uboot> bootm 0x1000000 0x2000000 0x3000000

Step 9-11 load all the kernel related files to the DDR-RAM through tftp and bootm will start the boot.
The addresses (0x1,2,3000000) can be adjusted according to the file size.
The linux should be ready for access.

As a final remark, you might have to modify:
1. "bootargs" to boot the kernel. Most likely the ip should be included. For static IP setting, you will need: ip=DeviceIP:ServerIP:NetMask:GatewayIP:HostName:InterfaceName
It can be used during the boot process but you still need to modify "/etc/network/interfaces"
2. "tftpboot" needs a device IP and also the server IP. Make sure you have set the correct IP setting in uboot env. Furthermore, TFTP runs in UDP and no gateway is needed. You might check if the tftp server listens the correct port through: ">netstat -nulp"

Now, you can deploy your system without using SD Card. This allows me to perform remote development even I am working somewhere else. Hope you enjoy the development.