So in the previous steps we’ve built the bitstream and the first stage bootloader now all we need is to build u-boot and we’ll have something to run on our Zybo. If you’ve been working on a windows machine you’ll need to switch to a Linux machine for these next steps. It does look like you can build u-boot on windows using the Xilinx SDK software but I used Linux, maybe building u-boot with Windows will be another blog post. Once you have a virtual machine running Linux or a system running Linux we’ll need to install a couple items before we can start getting and building u-boot. First, if you have a 64-bit system you’ll have to install the 32-bit libraries for your Linux distro before we can use the code sorcery toolchain. This link will show you what commands to use based on the flavour of Linux you’ve chosen. Next make sure you have git installed, we’ll need to use git to download the sources needed to build u-boot and later Linux and Xenomai. To install Linux on Ubuntu , go to the terminal and type in:
bash> sudo apt-get install git
on red hat based distro
bash> sudo yum install git
Once we’ve got those tools installed it’s time to get our toolchain from Xilinx. Follow the steps on the Xilinx wiki follow the steps to download and install the command line tools. We’ll be building u-boot, linux and xenomai all from the command line. After completing the toolchain install and adding the xilinx tools into our PATH variables we should be able to type
on the command line and get an error saying no input files specified.
If we see this error then everything is setup and we are ready to download U-boot, if not then you’ve probably forgot to add the toolchain location to your PATH variable. Take a look back at the Xilinx wiki to make sure you’ve exported bothe CROSS_COMPILER variable and your modified PATH variable.
We are now ready to configure u-boot from source for Zybo. The Xilinx wiki on u-boot is a great resource to get us started. It’s gear towards the Zed board which is okay because the Zybo is very similar. I only had to change one piece of source code to get it to work. I’ve been able to configure u-boot from both the Zed board config and the generic one. I’ll go over it modifying the Zedboard config. Let’s fetch the source:
bash> git clone git://github.com/Xilinx/u-boot-xlnx.git
Let’s take a look at the config files, in include/configs we should see a file called zynq_zed.h, this file is how u-boot knows how to configure the system. Let’s edit this file for zybo, all we have to do is add the following line:
#define CONFIG_ZYNQ_PS_CLK_FREQ 50000000UL
We need to add this because the peripheral clock on the Zybo is 50Mhz, on the Zedboard it’s 33.3Mhz. I got u-boot to work with and without this change but I’ll add it in here since we need to keep this in mind when we try to get the Linux debug console to work.
Once we’ve saved that file, let’s configure u-boot to build for our target by entering :
type ‘make’ and we should be able to watch the build output and hopefully see no errors.
So u-boot is now built, now we need to gather the bitstream from step 1, the first stage boot loader elf file from step 2 and the u-boot executable into one location that the SDK can see. So if you are doing this on two machines like I am make sure there is a shared folder somewhere that we can put the files.
If we do an ‘ls’ in the u-boot directory we should see a file with no extension named ‘u-boot’. Copy this file to a separate location. Rename this file to u-boot.elf
Open the Xilinx SDK, and under the Xilinx tools drop down menu, select ‘Create Zynq Boot Image’
I called the bif file zybo, next add the first stage bootloader first, with the partition type bootlader. Order is important so make add this file first. Next add the bitstream file with partition type datafile and then u-boot.elf again add it as datafile. Make sure you’ve specified an output directory and then click create image. We should now see u-boot.bin in that directory. Rename that file BOOT.bin, this is the file that the processor will look for when power is applied.
We have the boot image that will boot the board, all we need now is the create an SD Card to hold the files. Grab a 4GB (or larger) SD Card, hopefully your system has an SD Card reader or you have a USB one. Pop the SD Card in and make sure your OS can see it. We’ll need to use a Linux utility called Gparted to create the partitions on the SD Card. If you have a Linux distro that allows you to download programs from a software repo, use that to find gparted, if not follow this link for instructions on how install it.
Once Gparted is installed run it and we should be able to see the hard drivers on the system. We should be able to use the drop down in the top right to find our SD Card. Once we’ve found it we can go ahead and erase all the current partitions. WARNING!!! This will erase all the contents of the SD Card so if you have something you want to keep copy somewhere safe before this step! WARNING!!!
Unmount the partition if needs and highlight the current partitions, delete those partitions (right click) and we should see all the space on the SD Card as unallocated. Click the check mark to apply those changes. Click the unallocated space and right click and select new, the size of this partition can be small since it only holds the bootfile, but we also could have a RAM disk here so let’s make it atleast 512MB, the file system HAS TO BE FAT32. Make sure to give it a label name so we can identify it later. Click add to finish. Highlight and right click the unallocated space and select new, the size should be the rest of the SD Card, and make the file system type ext4. We can use this as the rootfs when Linux starts up. Click the green check mark again and the operations should be applied. The SD Card is now ready we can eject it safely from the OS.
Insert the SD Card again so the host sees it and then copy over the BOOT.bin file to the FAT32 partition. Safely eject the SD Card, we are almost done.
On the Zybo make sure the boot jumper is set for SD Card boot. Insert the SDCard, connect the Zybo to the host machine using a USB cable, and apply power. You should see the green and red LED light up and then some yellow LED activity on the UART to show U-boot is sending data to the UART.
Open a terminal program like minicom on Linux or Teraterm on windows and configure it according to our UART settings:
We should see something similar for U-boot output:
I will post some short videos and more pictures shortly from my zybo booting into u-boot. The next step is to build the Linux kernel with the Xenomai patches, and compile our device tree. I should have this up in the next couple of days. There were numerous manual merges I had to make when applying the xenomai patches for some reason. I may split it into two steps.
As always leave questions or comments here and I will do my best to get answer them!
12 thoughts on “Building U-boot and boot image”
Hi there, thanks so much for the tutorial. I’m looking forward to seeing the next step. I noticed that my ZYBO came with a version of Linux pre-installed, but with absolutly no information given and no link to the image file on Digilent’s website should I ever want to restore it.
I’m going to try building u-boot this weekend, and then hopefully get the device tree figured out.
So far yours is the only clear guide to get me started.
No problem, I’m a little busy this week but I hope to get the Linux and Xenomai steps up this weekend. Thanks for the comments, post any questions you have and I’ll be glad to help out.
Can you provide an example of a sample application running under Linux (such as 1 thread in each core) ?
Regular Linux or Linux patched with Xenomai?
Regular Linux just a sample example that shows using linux on both CPU.
What have you done is a pre-buildind using an u-boot, so you have used only one CPU et not 2. I mean a pre-built linux that boots only on one Core.
So far we’ve build u-boot and it’s running on a single core. The Linux kernel will bring up both cores during it’s boot process. I will put together step 4a tonight which will be how to build and run stock Linux on Zybo. This will show both cores running.
Ok i am waitting for that 🙂 thanks
when will you post an example for turnning both CPU under Linux ?
Just finishing it up, should be up tonight
Needs to export CROSS_COMPILE variable instead of CROSS_COMPILER variable
good catch my mistake
Thanks for this the very nice tutorial series, your posts are very well prepared…
One can format their SD card using command line instead of using GParted(SD cards will be partitioned by default):
$>sudo mkfs.vfat -n “ZYBO_BOOT” /dev/sddevX
Here ‘/dev/sddevX’ refers to the 1st SD card partition. It can be found with the following command:
$>sudo fdisk -l
My two cents…