U-Boot Secondary Program Loader On Zybo

Hi Everyone,

Today I’ll take you through how to create the U-Boot SPL for our Zybo board.  The SPL is able to replace the FSBL but currently may not support secure boot or encrypted bitstream.  The SPL isn’t supported by Xilinx so like I mentioned above it could be missing some features that the FSBL supports.  Let’s get started!

If you haven’t done so before let’s clone the U-Boot repo, for this example we will need the Xilinx repo, to the best of my knowledge mainline u-boot is missing a python script that creates boot.bin (more on boot.bin later).

git clone https://github.com/Xilinx/u-boot-xlnx.git

We should have the SDK arm cross compiler installed from our previous steps, if you don’t you’ll have to install the Xilinx SDK.  The good news is there is a command line version of the tools that is slightly smaller.  If you’re not sure if the compiler is installed we can check.   If you are using Linux the tools should be located here:

/$(PATH TO SDK TOOLS)/Xilinx/SDK/2015.3/gnu/arm/lin/bin/

If we can see the executable arm-xilinx-linux-eabi-gcc then the tools are installed, the above line will be different depending on the location and the version of the SDK that you have installed.

To create the secondary program loader we need to copy two very important files to the u-boot source tree.  These files are our ps7_init files, these files are extremely important they initialize our processor and are needed so that boot.bin works properly.  If we forget to copy the files over or we don’t copy them to the correct location the build will still work and boot.bin will be generated but it won’t work.  This can be frustrating and is hard to debug.  I’m going to assume that you have ps7_init.c and ps7_init.h files and you either got generic ones from Xilinx git repository (https://github.com/Xilinx/embeddedsw) or you generated them when you exported your hardware design.

We’ll need to copy them to u-boot-xlnx/board/xilinx/zynq/custom_hw_platform.  If we were using another board like a ZedBoard, MicroZed, ZC706 or ZC702 we would need to copy them to another location.  Look under board/xilinx/zynq in the u-boot source tree for more info.  When we copy the files over we need to rename them to ps7_init_gpl.c and ps7_init_gpl.h, the need for the name change is based on what u-boot expects for the files to be named.  I’m not sure if these files need to be under GPL licence to be properly  included in the build if you were going to use this in a commercial product.  I’ll keep researching and hopefully find an answer and post back here when I do.

Let’s go ahead and copy those files, assuming the ps7_init files are in your PWD

cp ./ps7_init.c $(PATH_TO_UBOOT_SRC)/u-boot-xlnx/board/xilinx/zynq/custom_hw_platform/ps7_init_gpl.c

cp ./ps7_init.h $(PATH_TO_UBOOT_SRC)/u-boot-xlnx/board/xilinx/zynq/custom_hw_platform/ps7_init_gpl.h

Make sure we update our new ps7_init_gpl.c to include ps7_init_gpl.h not ps7_init.h which it will be including by default if we are using ones that were generated with Vivado.

Everything is pretty much ready to build, one added bonus is Zybo is now supported by u-boot and is included in the configs directory.  If we look at $(PATH_TO_UBOOT_SRC)/u-boot-xilinx/configs we can see all the supported boards.  We should see zynq_zybo_defconfig, if you don’t then do a git pull and make sure you have the latest source code.

make CROSS_COMPILE=arm-xilinx-linux-gnueabi- zynq_zybo_defconfig

This will configure our build properly and get it ready make our build files.

make CROSS_COMPILE=arm-xilinx-linux-gnueabi-

After this command our build will start and we should see all the files getting compiled and linked.  Once our build is finished we should see the following output:

MKIMAGE u-boot.img
./tools/zynq-boot-bin.py -o boot.bin -u spl/u-boot-spl.bin
Input file is: spl/u-boot-spl.bin
Output file is: boot.bin
Using /home/greg/src/emb_linux/u-boot-xlnx/spl/u-boot-spl.bin to get image length – it is 47632 (0xba10) bytes
After checksum waddr= 0x13 byte addr= 0x4c
Number of registers to initialize 0
Generating binary output /home/greg/src/emb_linux/u-boot-xlnx/boot.bin

We see our u-boot image file was created (u-boot.img) and we also see the spl being created, the interesting part of this output is the zynq-boot-bin.py script.  This script takes u-boot-spl.bin as an input file and creates the boot image, our case it’s boot.bin which is the file the Zybo needs to boot.  The last time I built this using mainline the python script wasn’t called automatically after the build.  I’m not sure if we need to do that manually in the mainline build but using the xilinx version of u-boot it’s done automatically for us which makes life easier.

Now that the build is done we need to copy the following files to the FAT32 partition of our sdcard.  Copy over boot.bin and u-boot.img, we can now put the sdcard back into the Zybo and boot it and we should see u-boot boot into the console.

Please leave any questions or comments and I’ll answer them as soon as I can.

 

4 thoughts on “U-Boot Secondary Program Loader On Zybo

  1. Hello!
    Your tutorials are the best out on the internet!
    I tried to boot Linux with FSBL and u-boot with xilinx and digilent repo, but after loading, it won’t log in to root:

    mount: mounting /dev/mmcblk0p2 on /newroot failed: Invalid argument
    Failed to switch_root, dropping to a shell
    sh: can’t access tty; job control turned off
    / #

    I can’t think of any way to solve this issue, not with uImage, boot.bin, devicetree.dtb, uRamDisc. I even checked my partitions of the SD card.

    Do you have any suggestions where to look?
    Thanks in advance,
    Aron.

    1. Hi, it looks like your initial file system is trying to do a switch root into the file system on the second partition on the sdcard. How is your sd card partitioned? Is there a root file system on the sd card? Basically the error says switch_root fails then drops back to using the ram file system. What steps are you using to make the root file system?

  2. Hello again.
    So I’ve managed to use the ZYBO board with Linux based on these amazing tutorials – with FSBL. When I tried to do the same with Secondary program loader, I’ve got the loading message posted, and everything halted, couldn’t even type into terminal. Do you have any ide what might happened?

    The message was:

    U-Boot SPL 2017.01-00015-g5290eb5 (Jun 18 2017 – 18:08:27)
    mmc boot
    Trying to boot from MMC1
    reading fpga.bin
    spl_load_image_fat: error reading image fpga.bin, err – -1
    spl: error reading image fpga.bin, err -1
    reading system.dtb
    reading uImage
    reading uImage

    On a side note. It would be really helpful if you could create a custom PL part and write a driver in kernel/user space for it after the real-time Linux is completed. I’ve searched on the Internet, and couldn’t find a really in-depth tutorial as these.

    Thanks in advance,
    Fehér Áron.

Leave a comment