Setup flow of Debian Linux on Zynq
Copyright (C) 2015, Shinya Takamaeda-Yamazaki
E-mail: shinya_at_is.naist.jp
Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
- README.md: This file
- config: configuration files for building software
- setting: setting files on Linux
- lib: user-level library
- sample: sample applications
- compiled_file: compiled binary files
Debian Linux on Zynq Setup Flow
Under development.
If you use bash (default) and zsh
source /opt/xilinx/Vivado/2015.4/setting64.sh
export CROSS_COMPILE=arm-xilinx-linux-gnueabi-
export ARCH=arm
If you use tcsh
source /opt/xilinx/Vivado/2015.4/setting64.csh
setenv CROSS_COMPILE arm-xilinx-linux-gnueabi-
setenv ARCH arm
Download U-Boot
git clone https://github.com/Xilinx/u-boot-xlnx.git
cd u-boot-xlnx
git checkout xilinx-v2015.4
Edit zynq_common.h
emacs include/configs/zynq-common.h
diff --git a/include/configs/zynq-common.h b/include/configs/zynq-common.h
Build U-boot image.
for Zybo
make zynq_zybo_config
for ZedBoard
make zynq_zed_config
Then "make"
make
You have "u-boot-xlnx/u-boot.img" and "u-boot-xlnx/boot.bin".
Download the linux kernel image. Revision 3590cfe88b1a2d418d59e0ed9c928eb8c094c7cf works well for ZC706 and ZedBoard.
git clone https://github.com/analogdevicesinc/linux.git ; cd linux
git checkout xcomm_zynq
git checkout 3590cfe88b1a2d418d59e0ed9c928eb8c094c7cf
Load the default setting
make zynq_xcomm_adv7511_defconfig
Configure the kernel. Edit each option as following.
Or, replace ".config" with "zynq-linux/config/linug.config".
make menuconfig
- UIO
Follow "Device Drivers" —> "Userspace I/O drivers". Then select <*> for three itmes there.
- CMA
Follow "Device Drivers" —> "Generic Driver Options" —> select <*> for DMA Contiguous Memory Allocator. Then set 260 (not 256) for "Size in Mega Bytes" and 8 for "Maximum PAGE_SIZE order of alignment for contiguous buffers".
- NFS
For NFS users, follow "File systems" —> select <> for "Network file systems". Then select <> for some related items of NFS.
Check ".config" has lines as below.
for UIO
CONFIG_UIO=y
CONFIG_UIO_PDRV=y
CONFIG_UIO_PDRV_GENIRQ=y
for CMA
#
# Default contiguous memory area size:
#
CONFIG_CMA_SIZE_MBYTES=260
CONFIG_CMA_SIZE_SEL_MBYTES=y
# CONFIG_CMA_SIZE_SEL_PERCENTAGE is not set
# CONFIG_CMA_SIZE_SEL_MIN is not set
# CONFIG_CMA_SIZE_SEL_MAX is not set
CONFIG_CMA_ALIGNMENT=8
for NFS
CONFIG_NETWORK_FILESYSTEMS=y
CONFIG_NFS_FS=y
CONFIG_NFS_V2=y
CONFIG_NFS_V3=y
CONFIG_NFS_V3_ACL=y
CONFIG_NFS_V4=y
CONFIG_NFS_SWAP=y
CONFIG_NFS_V4_1=y
CONFIG_NFS_V4_2=y
CONFIG_PNFS_FILE_LAYOUT=y
CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN="kernel.org"
CONFIG_NFS_V4_1_MIGRATION=y
# CONFIG_ROOT_NFS is not set
CONFIG_NFS_USE_LEGACY_DNS=y
# CONFIG_NFSD is not set
CONFIG_GRACE_PERIOD=y
CONFIG_LOCKD=y
CONFIG_LOCKD_V4=y
CONFIG_NFS_ACL_SUPPORT=y
CONFIG_NFS_COMMON=y
Expand PATH variable with "u-boot-xlnx/tools"
for bash or zsh
export PATH=/home/yourname/u-boot-xlnx/tools:$PATH
for tcsh or csh
setenv PATH /home/yourname/u-boot-xlnx/tools:$PATH
Build a kernel image.
make uImage LOADADDR=0x00008000
You have "uImage" at "linux/arch/arm/boot". Copy it to somewhere.
cp linux/arch/arm/boot/uImage ~/work/uImage
This package includes the custom ".dts" and ".dtsi" files. In those, "bootargs" option is modified, and several "dmem-uio" interfaces are appended.
Copy "zynq-linux/config/.dts" and "zynq-linux/config/.dtsi" into "linux/arch/arm/boot/dts/"
cp zynq-linux/config/*.dts* ~/work/linux/arch/arm/boot/dts
for ZedBoard
make zynq-zed-empty-custom.dtb
make zynq-zed-empty-custom-cma.dtb
for ZC706
make zynq-zc706-empty-custom.dtb
make zynq-zc706-empty-custom-cma.dtb
zynq-*-empty-custom.dtb is a separated design that uses the first half of DRAM as linux-managed region and the second half as the accelerator reserved region. The second half region can be accessed via "/dev/uio0" from linux. Note that the cache memory of ARM processor for the second region is disabled, because it uses /dev/uio0.
zynq-*-empty-custom-cma.dtb is a more sophisticated design that uses the entire DRAM as linux-managed region, but some contigunous physical spaces (260 MB) of that region can be allocated for accelerator use by using udmabuf driver. Note that the region has contigunous physical spaces on DRAM, so that the accelerator can access easily that region without a complex address translation. Additionally, that region can be cached by the cache memory. If you use ACP port to access the DRAM from an accelerator, enabling the cache memory will improve the performance.
Copy the corresponding dtb file on "linux/arch/arm/boot/dts/" as "devicetree.dtb" on somewhere.
For example
cp linux/arch/arm/boot/dts/zynq-zed-empty-custom-cma.dtb ~/work/devicetree.dtb
If you use "zynq-*-empty-custom.dtb (for /dev/uio0)", prepare "uEnv.txt" as below.
touch ~/work/uEnv.txt
emacs ~/work/uEnv.txt
for ZedBoard
fdt_high=0x10000000
initrd_high=0x10000000
for ZC706
fdt_high=0x20000000
initrd_high=0x20000000
cd ~/work/
sudo apt-get install qemu-user-static debootstrap binfmt-support
export targetdir=rootfs
export distro=jessie
mkdir $targetdir
sudo debootstrap --arch=armhf --foreign $distro $targetdir
sudo cp /usr/bin/qemu-arm-static $targetdir/usr/bin
sudo cp /etc/resolv.conf $targetdir/etc
sudo chroot $targetdir
distro=jessie
export LANG=C
/debootstrap/debootstrap --second-stage
cat <<EOT > /etc/apt/sources.list
deb http://ftp.jp.debian.org/debian $distro main contrib non-free
deb-src http://ftp.jp.debian.org/debian $distro main contrib non-free
deb http://ftp.debian.org/debian $distro-updates main contrib non-free
deb-src http://ftp.debian.org/debian $distro-updates main contrib non-free
deb http://security.debian.org/debian-security $distro/updates main contrib non-free
deb-src http://security.debian.org/debian-security $distro/updates main contrib non-free
EOT
cat << EOT > /etc/apt/apt.conf.d/71-no-recommends
APT::Install-Recommends "0";
APT::Install-Suggests "0";
EOT
apt-get update
apt-get install locales dialog
dpkg-reconfigure locales
apt-get install openssh-server ntpdate resolvconf sudo less hwinfo ntp tcsh zsh
passwd
If you have multiple Zynq-linux systems, assign an appropriate hwaddress value for each system.
echo <<EOT >> /etc/network/interfaces
auto eth0
iface eth0 inet static
hwaddress ether 00:0a:35:00:01:??
address 192.168.0.xxx
netmask 255.255.255.0
gateway 192.168.0.yyy
dns-nameservers 192.168.0.aaa 192.168.0.bbb
dns-domain foo.bar.jp
dns-search foo.bar.jp
EOT
echo <<EOT >> /etc/resolv.conf
nameserver 192.168.0.aaa
nameserver 192.168.0.bbb
EOT
Create a new admin user.
adduser yourname
Enter, enter, enter, ... . Then edit sudoers.
editor=vi visudo
Edit like this.
# User privilege specification
root ALL=(ALL:ALL) ALL
yourname ALL=(ALL:ALL) ALL
Open "/etc/rc.local".
vi /etc/rc.local
Then add 3 lines to use NTP at boot time.
service ntp stop
ntpdate ntp.nict.jp
service ntp start
exit 0
Setup hostname.
echo debian-zynq > /etc/hostname
echo T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt1000 >> /etc/inittab
echo 127.0.0.1 debian-zynq >> /etc/hosts
Install some applications as you like.
apt-get install build-essential
apt-get install screen bash-completion time
apt-get install python python-pip python3 python3-pip
apt-get install nis nfs-common
Finish.
exit
sudo rm -f $targetdir/usr/bin/qemu-arm-static
Setup a disk partition by using gparted or fdisk as below.
- 1st partition: empty (4MB)
- 2nd partition: BOOT (64MB, FAT32, bootable)
- 3rd partition: rootfs (entire rest, ext4)
Copy "BOOT.BIN", "devicetree.dtb", "uImage", and "uEnv.txt (If you need)" into the "BOOT" partition.
cp ~/work/BOOT.BIN /media/yourname/BOOT/
cp ~/work/devicetree.dtb /media/yourname/BOOT/
cp ~/work/uEnv.txt /media/yourname/BOOT/
cp ~/work/uImage /media/yourname/BOOT/
Copy all the contentes in "rootfs" directory you created above into "rootfs" on SD card.
sudo cp -a ~/work/rootfs/* /media/yourname/rootfs/
Boot the Zynq linux system with the prepared SD card.
Jumper-pin setting should be as below.
H __
L _ __
Login the system via ssh.
After you login the Debian on Zynq, please set up NTP and Timezone.
(on Zynq) sudo emacs /etc/ntp.conf
Comment out the orignal lines and insert a new line as below.
#server 0.debian.pool.ntp.org iburst
#server 1.debian.pool.ntp.org iburst
#server 2.debian.pool.ntp.org iburst
#server 3.debian.pool.ntp.org iburst
server ntp.nict.jp
Restart NTP.
(on Zynq) sudo service ntp restart
Change the time zone to Asia/Tokyo
(on Zynq) sudo dpkg-reconfigure tzdata
Select "Asia", then "Tokyo".
Mount the 1st partition of SD card on /sdcard .
(on Zynq) sudo mkdir /sdcard
(on Zynq) sudo vi /etc/fstab
Insert 1 line.
/dev/mmcblk0p1 /sdcard auto defaults 0 0
(on Zynq) sudo dpkg-reconfigure locales
select "en_US.UTF-8", "ja_JP.UTF-8", and "ja_JP.EUC-JP". Then select "en_US.UTF-8" as default.
Reboot
(on Zynq) sudo reboot
Copy the "linux" directory used above from the host computer to "/usr/src/" on Zynq-linux system.
scp -r ~/work/linux [email protected]:
Then create a symbolic link named "/usr/src/kernel" to it on Zynq-linux system.
(on Zynq) sudo mv linux /usr/src/linux
(on Zynq) sudo ln -s /usr/src/linux /usr/src/kernel
Go to "/usr/src/kernel" and "make modules_prepare"
(on Zynq) sudo make modules_prepare
Download the CMA memory driver from GitHub, and copy it to Zynq-linux system.
git clone https://github.com/shtaxxx/udmabuf.git
scp -r udmabuf [email protected]:
(on Zynq) cd udmabuf
(on Zynq) make
You will have "udmabuf.ko".
Or use "zynq-linux/compiled_file/udmabuf.ko".
Copy it into "/drivers/".
(on Zynq) sudo mkdir /drivers
(on Zynq) sudo cp udmabuf.ko /drivers
Go to "zynq-linux/sample/. Then compile a sample program that uses user-level library (zynq-linux/lib/cma.h).
scp -r zynq-linux [email protected]
(on Zynq) cd zynq-linux/sample
(on Zynq) make
(on Zynq) ./a.out 10000 1
The second argument of a.out is the run mode:
- 0: standard memory space (malloc, fastest)
- 1: CMA space (cma_malloc without O_SYNC, CPU cache enabled, very fast but no consistent to accelerators)
- 2: CMA space (cma_malloc with O_SYNC, CPU cache disabled, slow)
- 3: CMA space (cma_malloc with O_SYNC, CPU cache disabled, write combined, fast)
- 4: CMA space (cma_malloc with O_SYNC, CPU cache disabled, DMA coherent, fast)
You can find other user-level libraries ("axis.h" and "umem.h").
Yet Another Guide to Running Linaro Ubuntu Linux Desktop on Xilinx Zynq on the ZedBoard
Building a pure Debian armhf rootfs
ADI Reference Designs HDL User Guide If you need HDMI, download the FPGA reference design from GitHub: git clone https://github.com/analogdevicesinc/hdl.git
ADI Reference Designs HDL User Guide