Phant0mas’ Place

Coding, building, debugging

Setup a Linaro GNU/Linux Enviroment on the ZedBoard

| Comments

[Notice: This guide is outdated, but works. I will upload a guide for newer sources sometime in the future!]

Before we start

Disclaimers: I am sharing what works for me. It may not work for you or it may fail over time. You may suffer data loss or worse. I disclaim all warranties and representations. This guide is based on the one from digilent which you can find here, and the one from Jan Gray which you can find here.

For this guide I used an Arch GNU/Linux x86_64 box and the Xilinx ISE Design Suite, version 14.7 which you can get from here. This guide will probably work on any GNU/Linux box which can run the Xilinx tools, but I can’t guarantee anything. If you are using another os, it will probably work with some modifications, but I can’t guarantee that either.

In this post I will guide you through the process of getting a headless Linaro GNU/Linux system running on the ZedBoard. For those of you not familiar with the ZedBoard, which I highly doubt since you are here, read this.

So, why run Linaro on Zedboard?

Well, there are two main reasons for that:

  1. Linaro comes with a working gnu toolchain so you can actually build and debug directly on it, without the need of your main workstation.
  2. As it is based on Ubuntu, you can have access to the large collections of programs in its repos, making the customization of the system a lot easier.

What we’re going to build

  • An XPS design for ZedBoard, which we’ll export to the SDK.
  • A u-boot.elf (Linux boot loader).
  • An FSBL (first stage boot loader) using the SDK.
  • The linux kernel.
  • A devicetree blob named devicetree.dtb.
  • A FAT32 partition on our SD card that comprises these files BOOT.BIN, uImage, and devicetree.dtb.
  • An ext4 partition on our SD card with the pre-built Linaro Ubuntu userland .

Prerequisities

  • Just make sure ISE 14.7 w/ EDK is there and working.

Prepare the SD card

To boot the system on the ZedBoard you’ll need a SD memory card. The SD card should have at least 4 GB of storage and it is recommended to use a card with speed-grade 6 or higher to achieve optimal file transfer performance. The SD card needs to be partitioned with two partitions. I suggest to make the first one be about 256MB in size and the second one should take up the remaining space. For optimal performance make sure that the partitions are 4MB aligned. The first partition needs to be formatted with a FAT filesystem. It will hold the bootloader, devicetree and kernel images. Name it ZED_BOOT. The second partition needs to be formatted with a ext4 filesystem. Name it ROOT_FS. It will store the systems root filesystem. Use whatever tool you want to do it :-).

Building the programmable logic hardware

  • Download the reference design for ZedBoard from here.
  • Create a folder named tutorial.
  • 1
    
    $ mkdir tutorial
  • Change folder to tutorial.
  • 1
    
    $ cd tutorial
  • Unzip the file you download above, in here.
  • 1
    
    $ unzip ../ZedBoard_Linux_Design.zip .
  • Change folder to ZedBoard_Linux_Design.
  • 1
    
    $ cd ZedBoard_Linux_Design
  • Open system.xmp file in hw/xps_proj with xps.
  • 1
    
    $ xps hw/xps_proj/system.xmp &
  • Click yes when asked to upgrade cores to newer version.
  • Click Generate BitStream and start making fun of windows l-users play some ksp work-ahead on the u-boot and linux kernel steps below, while you check back on the progress on this step. When it’s finished, check if there are no errors and pretend you don’t see the warnings.
  • Click Export Design. Select Export and Launch SDK. (Continued below.)

Build u-boot, the Linux boot-loader

  • If you have properly installed the ISE suite in your box, you should already have the ARM cross compile toolchain installed, which will work just fine.
  • Fetch the source:
  • 1
    
    $ git clone https://github.com/Digilent/u-boot-digilent.git ../u-boot-digilent ; cd ../u-boot-digilent
  • Build u-boot with the cross-compile tools
  • 1
    2
    
    $ make  CROSS_COMPILE=arm-xilinx-linux-gnueabi- zynq_zed_config
    Configuring for zynq_zed board...
    1
    
    $ make  CROSS_COMPILE=arm-xilinx-linux-gnueabi-
  • After the compilation, the ELF (Executable and Linkable File) generated is named u-boot. We need to add the ‘.elf’ extension to the file name so that Xilinx SDK can read the file layout and generate BOOT.BIN. In this tutorial, we are going to move the u-boot.elf to boot_image folder and substitute the u-boot.elf that comes along with ZedBoard Embedded Linux Design Package.
  • 1
    
    $cp u-boot ../ZedBoard_Linux_Design/boot_image/u-boot.elf 

Generate the boot image BOOT.BIN

  • This consists of the FSBL (first stage boot loader), the system.bit configuration bitstream, and the U-boot Linux boot-loader u-boot.elf. Follow exactly the instructions.
  • By now xps should have finished generating the bitstream. So at xps, export the hardware design to Xilinx SDK by clicking on Project -> Export Hardware Design to SDK
  • Click Export & Launch SDK
  • Set Workspace to ZedBoard_Linux_Design/hw/xps_proj/SDK/SDK_Export and click ok
  • After SDK launches, the hardware platform project is already present in Project Explorer on the left of the SDK main window. We now need to create a First Stage Bootloader (FSBL). Click File->New->Project
  • In the New Project window, select Xilinx->Application Project, and then Click Next.
  • We will name the project FSBL. Select xps_proj_hw_platform for Target Hardware because it is the hardware project we just exported. Select standalone for OS Platform. Click Next.
  • Select Zynq FSBL as template, and click Finish
  • For the ZedBoard, we need to reset the USB PHY chip by toggling the USB-Reset pin in the FSBL. Add the following code to main.c of the FSBL project after the line 565
  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    
        /* Reset the USB */
    
        fsbl_printf(DEBUG_GENERAL, "Reset USB...\r\n");
    
        /* Set data dir */
        *(unsigned int *)0xe000a284 = 0x00000001;
    
        /* Set OEN */
        *(unsigned int *)0xe000a288 = 0x00000001;
        Xil_DCacheFlush();
    
        /* For REVB Set data value low for reset, then back high */
    #ifdef ZED_REV_A
        *(unsigned int *)0xe000a048 = 0x00000001;
        Xil_DCacheFlush();
        *(unsigned int *)0xe000a048 = 0x00000000;
        Xil_DCacheFlush();
    #else
        *(unsigned int *)0xe000a048 = 0x00000000;
        Xil_DCacheFlush();
        *(unsigned int *)0xe000a048 = 0x00000001;
        Xil_DCacheFlush();
    #endif
  • After you have saved the changes to main.c, the project will rebuild itself automatically. If it does not rebuild, Click Project->Clean to clean the project files, and Project->Build All to rebuild all the projects. The compiled ELF file is located in ZedBoard_Linux_Design/hw/xps_proj/SDK/SDK_Export/FSBL/Debug/FSBL.elf
  • Now, we have all the files ready to create BOOT.BIN. Click Xilinx Tools -> Create Zynq Boot Image.
  • In the Create Zynq Boot Image window, choose Create new Biff file and click Browse. Go to tutorial-zedboard/ZedBoard_Linux_Design/boot_image/ path and type BOOT.bif as the filename you want. It does not yet exist but it will get created.
  • Next in the Boot image partitions area click add, choose Partition type -> bootloader, add the FSBL.elf found at ZedBoard_Linux_Design/hw/xps_proj/SDK/SDK_Export/FSBL/Debug/ to the file path and click ok.
  • Click add again, Partition type -> datafile, add to the file path the system.bit found at ZedBoard_Linux_Design/hw/xps_proj/SDK/SDK_Export/xps_proj_hw_platform/ and click ok.
  • Repeat the above, but this time add u-boot.elf found at ZedBoard_Linux_Design/boot_image/.
  • Finally click Create Image and a file named output.bin is generated in the ZedBoard_Linux_Design/boot_image folder.
  • Change the name of output.bin to BOOT.BIN and you are done.
  • 1
    2
    
    $ cd ZedBoard_Linux_Design/boot_image
    $ mv output.bin BOOT.BIN

Build the Linux Kernel

  • Get the Linux kernel source code from Digilent git repository. Make sure you are in the tutorial root folder.
  • 1
    2
    3
    
    $ pwd
    /home/something/tutorial
    $ git clone https://github.com/Digilent/linux-digilent.git linux-digilent ; cd linux-digilent
  • We will start to configure the kernel with the default configuration for ZedBoard. The configuration is located at arch/arm/configs/digilent_zed_defconfig. To use the default configuration, you can use:
  • 1
    
    $ make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- digilent_zed_defconfig
  • We will keep the default kernel configuration, so use the command bellow and then just press exit.
  • 1
    
    $ make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- menuconfig
  • Build the Kernel
  • 1
    
    $ make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi-
  • After the compilation, the kernel image is located at arch/arm/boot/zImage. Copy it to the boot_image folder.
  • 1
    
    $ cp arch/arm/boot/zImage ../ZedBoard_Linux_Design/boot_image/

Build the device tree

  • Note your DTS file arch/arm/boot/dts/digilent-zed.dts if it includes these bootargs:
  • 1
    2
    
    bootargs = "console=ttyPS0,115200 root=/dev/mmcblk0p2 rw earlyprintk rootfstype=ext4 rootwait devtmpfs.mount=1";
    /* bootargs = "console=ttyPS0,115200 root=/dev/ram rw initrd=0x800000,8M init=/init earlyprintk rootwait devtmpfs.mount=1"; */
  • That’s good — Linux will mount your root file system from the second partition on your SD card.
  • Generate DTB file.
  • 1
    2
    
    $ ./scripts/dtc/dtc -I dts -O dtb -o ../ZedBoard_Linux_Design/boot_image/devicetree.dtb arch/arm/boot/dts/digilent-zed.dts 
    DTC: dts->dtb  on file "arch/arm/boot/dts/digilent-zed.dts"

Start copying to sd card

  • Copy to the ZED_BOOT partition of the sd card, that has the FAT filesystem, the files BOOT.BIN, devicetree.dtb, zImage that we created before, found in the ZedBoard_Linux_Design/boot_image folder.
  • Now it’s time to download the Linaro image, which you can find here.
  • Create a folder under /tmp named linaro, and copy the zipped Linaro image to it.
  • 1
    2
    3
    
    $ mkdir -p /tmp/linaro
    $ sudo cp linaro-saucy-developer-20140410-652.tar.gz /tmp/linaro/fs.tar.gz
    $ cd /tmp/linaro/
  • Unpack the disk image using the tar command.
  • 1
    2
    3
    
    $ sudo tar -xvf fs.tar.gz
    $ ls
    binary     fs.tar.gz
    
  • Unmount any automatically mounted partitions of the sd card.
  • Mount the SD Card to /tmp/sd_ext4. Make sure to replace the device node with the device node of the ext4 partition on your SD Card.
  • 1
    2
    
    $ mkdir -p /tmp/sd_ext4
    $ sudo mount /dev/sdX2 /tmp/sd_ext4
  • Use the command rsync to copy the root file system onto the SD card. This command will preserve those attributes that should remain unchanged.
  • 1
    2
    3
    4
    
    $ cd binary/
    $ pwd
    /tmp/linaro/binary
    $ sudo rsync –a ./ /tmp/sd_ext4
  • Unmount before removing the SD card to make sure all the files have been synchronized to it. Unmounting /tmp/sd_ext4 may take several minutes, but you must wait to see that umount returns before removing the SD card.
  • 1
    
    $ umount /tmp/sd_ext4
  • Everything is ready!!

Booting the SD Card

Once you complete these guide instructions, the SD card will have everything it needs to boot Linux on the ZedBoard. Complete the procedures in steps 1-7 to test your SD card with the ZedBoard.

  1. Insert the SD card into the ZedBoard.
  2. Set the jumpers on the ZedBoard as follows:
    • MIO 6: set to GND
    • MIO 5: set to 3V3
    • MIO 4: set to 3V3
    • MIO 3: set to GND
    • MIO 2: set to GND
    • VADJ Select: Set to 1V8
    • JP6: Shorted
    • JP2: Shorted
    • All other jumpers should be left unshorted
  3. Attach a computer running a terminal emulator to the UART port with a Micro-USB cable. Configure the terminal emulator with the following settings:
    • Baud: 115200
    • 8 data bits
    • 1 stop bit
    • no parity
  4. Attach a 12V power supply to the ZedBoard and power it on.
  5. Connect to the appropriate port in the terminal emulator. You should begin to see feedback from the boot process within a few seconds, depending on the speed of the SD card.
  6. Wait for the boot process to complete. If it gets stuck at the u-boot prompt just type reset and it will work.
  7. You now have a complete GNU/Linux system running on the ZedBoard.

Comments