Creating a Zynq-compatible bootgen

I recently needed to have a copy off bootgen I could build to run on my Zynq platform. I found an open-source version called zynq-mkbootgen here:

It needs two libraries: pcre and elf, which I found at:

I downloaded and unpacked the libraries onto my Linux box with the Petalinux 2016.2 tools installed. In each directory, I ran:

./configure --host=arm-linux-gnueabihf

Be aware that the host parameter for your system will vary depending on which version of Petalinux you have installed. For example, an earlier version might have been arm-xilinx-linux-gnueabi.

For libelf, despite using the configure command, you will need to manually edit:

  • Makefile
  • lib/Makefile
  • po/Makefile

In each of these, change the CC = gcc to read CC = arm-xilinx-linux-gnueab-gcc. In addition, in lib/Makefile, change AR = ar to AR = arm-xilinx-linux-gnueabi-ar. Note the gcc and ar prefix should match the one used in your ./configure command. Do a make in each of the library directories.

Now unpack your mkbootimage tarball and edit the Makefile there. Again, change CC=gcc to read CC=arm-xilinx-linux-gnueab-gcc. In addition, append to the CFLAGS after the –std=c11 pointers to the include directories and library directories:

-I../libelf-0.3.13/lib -L../libelf-0.3.13/lib -L../pcre-8.41/.libs

Do a make. and you should now have a functioning mkbootimage executable you can put on your Zynq platform. You can then do a:

mkbootimage boot.bif BOOT.BIN

to generate an appropriate BOOT.BIN.

All the files needed to build mkbootimage may be found at which includes a working executable for Petalinux 2016.2.



Tshark (Wireshark) for Petalinux

In my last post, I talked about how to build the libpcap ethernet packet capture library. In this post I will give a brief description of building the Tshark application, which is the non-GUI version of Wireshark. You can download my binary distribution (see link at end of post) or download the source code at Wireshark Source by clicking on the Source Code link.

Wireshark needs either bison or yacc to build. I cross-compiled bison using the Petalinux tools, and put a copy on my system. Wireshark also needs flex, which can be included in the rootfs by doing a petalinux-config -c rootfs. I have included the bison, yacc and flex binaries here: Binaries. You can extract them into your /usr/local/bin directory prior to trying to build Tshark. You will also need a working libpcap which I discussed how to build in my previous post. The binary distribution is found here: Libpcap binary distribution and can be installed in /usr/local/bin.

I put the wireshark source code on my Petalinux system and first, since the Zynq system has no real-time clock and config expects the current date to be after the creation date of the source distribution, I set the date:


then configured it with:

 ./configure CC=/mnt/ellcc/bin/ecc --disable-wireshark

The CC points to my compiler (see my original post Compiling on Petalinux). The –disable-wireshark flag says to skip building the the GUI version.

After completing this (it takes quite some time), you will have a Makefile. Now perform a make. With this version of Tshark (1.12.7 when I built it), there are some issues with some functions declared as static in the source, but not static in the header. This will cause errors when ecc tries to compile them. I commented out the static keyword from those sources and continued the build. A packaged distribution is found here: Tshark 1.12.7 binaries

Of course, after completing this, version 1.12.8 was released. I tried building these, and got link errors with some the Wireshark libraries, and haven’t followed up. The good news was that the static keyword issues appear to have been resolved. If I get around to getting this build to work, I’ll update this post and the binaries.


Building libpcap for Ethernet packet analysis

The libpcap library is a handy library for Ethernet packet analysis. It is used by both tcpdump and wireshark. Since wireshark is GUI-based, it will not work on Petalinux, but there is a non-GUI version of it called tshark which will run. More on that in my next blog post.

Building libpcap was a major pain. The source can be downloaded from libpcap-1.7.4. I tried cross-compiling it using the Petalinux tools, but there were issues in that the following symbols would not link:


The configuration I used was:

 ./configure --host=arm-xilinx-linux-gnueabi --with-pcap=linux --prefix=/libpcap

Looking more closely now, I see if I had included libgcc_eh.a in the list of libraries, it might have worked (i.e. changing the Makefile line LIBS = -lgcc_eh). But I prefer to do things the hard way…

So I tried to build it on the Zynq using ellcc, with the configuration:

 ./configure --with-pcap=linux

But there were include files missing such as <linux/types.h>. So using the cross-compiler, I created the directory PCAP and preprocessed all the source files by adding a line to Makefile:

 @rm -f $@
 + $(CC) $(FULL_CFLAGS) -E $(srcdir)/$*.c > PCAP/$*.c
 $(CC) $(FULL_CFLAGS) -c $(srcdir)/$*.c

I then copied all the source files to the Zynq build directory. Building it locally using ellcc worked for making libpcap.a, but the link failed for Scrt1.o with:

 /mnt/ellcc/bin/../libecc/lib/arm-linux-engeabi/Scrt1.o: In function `_start':
 undefined reference to `main'

which appears to be a common failing with ellcc. So I made a tarball of the directory, copied it to the Petalinux system in a new directory, copied the Makefile from the original Petalinux build and did a “make -n” to see what it needed to do to link. I then copied the actual link command for the .so.1 library file and executed it. And lo and behold, it linked properly. I then copied the resultant to my Zynq system and placed it in /usr/local/lib, then created a link:

 cd /usr/local/lib
 ln -s

I also copied the previously built libpcap.a to /usr/local/lib.

The following include files should be copied to /usr/local/include:

  • pcap.h
  • pcap-bpf.h
  • pcap-namedb.h
  • pcap (the directory)

Again, that’s the hard way. It is useful to show the possible routes you may have to pursue in order to get a working build. In the long run, the cross-compilation with libgcc_eh.a included would probably work. I never bothered to try it. A ‘make install’ would have copied all the useful files to the directory /libpcap, then you could transfer a tarball of that directory to your local Zynq /usr/local directory and life would be good. I have done just that, and you can find the results here: libpcap-1.7.4 Distribution. You can extract these into your /usr/local directory.


Compiling on Petalinux

I’ve been using the Zynq system for about a year now. For my first post, I thought I’d show you how to compile programs under Petalinux. It turns out there is a great ARM compiler available at which is based on the wonderful Clang compiler. To get a copy of ellcc, go to ellcc releases and download the latest copy of the appropriate version for the Zynq (at the time this was written, ellcc-arm-linux-engeabi-0.1.16.tgz. Note the ellcc-arm-lunux-engeabi prefix is the one you want. Install this on your Zynq system.

As a side-note, I use a 8-gig SD card with a 200MB FAT-32 partition with the remaining card formatted as an ext4 partition following the instructions at Prepare Boot Medium. I mount the /dev/mmcblk0p2 partition as /mnt, so I can save files there across any rebooting.

Now one trick is to get this file to your Petalinux box. Normally I ftp files there, but as the ellcc file is >300 Mb, I needed to cheat a bit:

  • cd /var
  • mv ftp ftp.tmp
  • ln -s /mnt ftp

Now I can ftp the file and there’s plenty of room to unpack it:

  • cd /mnt
  • tar xvf /var/ftp/ellcc-arm-linux-engeabi-0.1.16.tgz
  • rm /var/ftp
  • mv /var/ftp.tmp /var/ftp

When done, the entire build environment will be found in /mnt/ellcc. The following files are of particular interest:

  • /mnt/ellcc/bin/ecc – The C compiler
  • /mnt/ellcc/bin/ecc++ – The C++ compiler
  • /mnt/ellcc/bin/ecc-gdb – The GNU debugger

To use the compiler, you must specify the full path to it so that it can find the appropriate include and library directories. So to give it a try, create a hello world program (e.g., test.c) somewhere, then type:

  /mnt/ellcc/bin/ecc -g test.c -o test

You can now run or, even more fun, debug the executable:

  /mnt/ellcc/bin/ecc-gdb test

One thing missing from all this wonderful stuff is the ability to build large projects. No version of make is included. So I built version 4.1 of GNU make, and it can be found here: make executable

With the above tools, you can build many Linux tools without having to cross-compile. The big drawback is it’s a lot slower on an ARM. One big win is you can debug applications without having to resort to gdb-server.

Note again, for the compiler, you must use the full path, so creating a symbolic link to, say, /bin/gcc will not work. It will work for the debugger, so you can use:

  ln -s /mnt/ellcc/bin/ecc-gdb /bin/gdb

For building larger projects, you can set the CC variable prior to performing a make:

  export CC=/mnt/ellcc/bin/ecc; make


  export CXX=/mnt/ellcc/bin/ecc++; make

for C++ programs.

Note also, there are several other executables in /mnt/ellcc/bin such as versions of nm, ar, strings, etc. each with a prefix of either ecc- or llvm-.

The distribution is large, in part because support for other architectures is included in case you wish to cross-compile. As this seems unlikely, you can certainly free up space by removing the additional support directories.

In some future blogs, I will mention some packages I have built, along with problems encountered in doing so. I’ll also make these packages available to download, saving you the hassle.