Zynq Root File System Creation

Introduction

This page provides instructions on how to build a basic root filesystem for application development. The following process may or may not match the root file system that Xilinx provides with a release.

Pre-built ramdisk images are available in each release package and recommended for getting started with application development before attempting to built a custom root filesystem as directed by this page.

Prerequisites

This process requires a Linux development machine with root access along with the following tools:

Assumptions

The directions on this page assume:

  • The directory used for the root filesystem is "/home/devel/_rootfs".
  • The Xilinx ARM toolchain is located in "/opt/14.2/ISE_DS/EDK/gnu/arm/lin64/".
  • CROSS_COMPILE environment variable is set to arm-xilinx-linux-gnueabi-

Any references to these directories should be modified for specific design needs.

Build process

These instructions use BusyBox for common Unix tools, Dropbear to provide an SSH client/server, and the Xilinx Toolchain for the standard C library and helper applications such as gdb-server.

The root filesystem will be built in the following order:

  1. Building BusyBox
  2. Building Dropbear
  3. Toolchain Library and Application Setup
  4. Directory Creation and Configuration

Building BusyBox

Get a copy of BusyBox from git.xilinx.com and enter the new directory:

bash> git clone git://git.busybox.net/busybox
bash> cd busybox

Setup the initial default configuration for BusyBox:

bash> make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- defconfig

The build can be customized from the supplied defaults by running "make menuconfig".

In the menu options set the install location to "/home/devel/_rootfs" (BusyBox Settings->Installation Options->BusyBox installation prefix):

bash> make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- menuconfig

To setup the initial root filesystem directory for BusyBox run "make install":

bash> make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- install

Building Dropbear

This build uses Dropbear v0.53.1.

Get a copy from the Dropbear website, extract the tarball and enter the directory:

bash> wget http://matt.ucc.asn.au/dropbear/releases/dropbear-0.53.1.tar.gz
bash> tar xfvz dropbear-0.53.1.tar.gz
bash> cd dropbear-0.53.1

Configure the build as follows:

bash> ./configure --prefix=/home/devel/_rootfs --host=arm-xilinx-linux-gnueabi --disable-zlib CC=arm-xilinx-linux-gnueabi-gcc LDFLAGS="-Wl,--gc-sections" CFLAGS="-ffunction-sections -fdata-sections -Os"

Build Dropbear with the following command:

bash> make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" MULTI=1 strip

Finalize the Dropbear installation by running "make install" and create a symbolic link for scp in the root filesystem:

bash> sudo make install
bash> ln -s ../../sbin/dropbear /home/devel/_rootfs/usr/bin/scp

Toolchain Library and Application Setup

The Xilinx ARM tool-chain includes a pre-built standard C library along with some helper applications like gdb-server.

Enter the "_rootfs" directory and create a "lib" directory:

bash> cd /home/devel/_rootfs
bash> mkdir lib

Copy in the supplied libraries:

bash> cp /opt/14.2/ISE_DS/EDK/gnu/arm/lin64/arm-xilinx-linux-gnueabi/libc/lib/* lib -r

Strip the libraries of debug symbols:

bash> arm-xilinx-linux-gnueabi-strip lib/*

Copy in the supplied tools in libc/sbin and libc/usr/bin

bash> cp /opt/14.2/ISE_DS/EDK/gnu/arm/lin64/arm-xilinx-linux-gnueabi/libc/sbin/* sbin/ -r
bash> cp /opt/14.2/ISE_DS/EDK/gnu/arm/lin64/arm-xilinx-linux-gnueabi/libc/usr/bin/* usr/bin/ -r

Directory Creation and Configuration

This last portion of the root filesystem creation will setup the needed directory structure along with the miscellaneous configuration files needed to start the system up appropriately.

This step will be performed within the "_rootfs" directory.

Create the needed directory structure:

bash> mkdir dev etc etc/dropbear etc/init.d mnt opt proc root sys tmp var var/log var/www

Now that the directories are present etc needs to be populated.

Create "etc/fstab" containing the following:

LABEL=/     /           tmpfs   defaults        0 0
none        /dev/pts    devpts  gid=5,mode=620  0 0
none        /proc       proc    defaults        0 0
none        /sys        sysfs   defaults        0 0
none        /tmp        tmpfs   defaults        0 0

Create "etc/inittab"

::sysinit:/etc/init.d/rcS

# /bin/ash
# 
# Start an askfirst shell on the serial ports

ttyPS0::respawn:-/bin/ash

# What to do when restarting the init process

::restart:/sbin/init

# What to do before rebooting

::shutdown:/bin/umount -a -r

"etc/passwd" should contain:

root:$1$qC.CEbjC$SVJyqm.IG.gkElhaeM.FD0:0:0:root:/root:/bin/sh

"etc/init.d/rcS" needs the following:

#!/bin/sh

echo "Starting rcS..."

echo "++ Mounting filesystem"
mount -t proc none /proc
mount -t sysfs none /sys
mount -t tmpfs none /tmp

echo "++ Setting up mdev"

echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s

mkdir -p /dev/pts
mkdir -p /dev/i2c
mount -t devpts devpts /dev/pts

echo "++ Starting telnet daemon"
telnetd -l /bin/sh

echo "++ Starting http daemon"
httpd -h /var/www

echo "++ Starting ftp daemon"
tcpsvd 0:21 ftpd ftpd -w /&

echo "++ Starting dropbear (ssh) daemon"
dropbear

echo "rcS Complete"

Set the appropriate permissions on "etc/init.d/rcS":

bash> chmod 755 etc/init.d/rcS
bash> sudo chown root:root etc/init.d/rcS

Building the Ramdisk

Now that the root filesystem has been built the last step will create the final ramdisk image that can be used with QEMU or on the board.

Start by creating the file that will contain the final image and format it's contents with the desired filesystem.

bash> cd ~
bash> dd if=/dev/zero of=ramdisk.img bs=1024 count=8192
bash> mke2fs -F ramdisk.img -L "ramdisk" -b 1024 -m 0
bash> tune2fs ramdisk.img -i 0
bash> chmod 777 ramdisk.img

Mount the image to a folder and copy the "_rootfs" contents to the mounted image:

bash> mkdir ramdisk
bash> sudo mount -o loop ramdisk.img ramdisk/
bash> sudo cp -R _rootfs/* ramdisk
bash> sudo umount ramdisk/

Compress the image:

bash> gzip -9 ramdisk.img

Test the image

This step assumes that QEMU has already been installed and the Linux kernel has been built. To test the image run the following command:

bash> qemu-system-arm -M xilinx-zynq-a9 -m 1024 -kernel zImage -initrd ramdisk.img.gz -nographic -net nic,model=cadence_gem -net user

A command prompt will show where standard shell commands may be executed.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License