Zynq FPGA: U-boot creation by using Xilinx OSL (Open Source Linux)

Suppose Xilinx SDK is installed

1.Fetch resources u-boot and device tree generator

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

2. Compile device-tree-xlnx

make
export PATH={dtc dir}/dtc:$PATH

3. Create u-boot defconfig for custom Zynq board

cd u-boot-xlnx/configs
copy zynq_zc702_defconfig from
https://elixir.bootlin.com/u-boot/latest/source/configs/zynq_zc702_defconfig

Add lines:

CONFIG_DEFAULT_DEVICE_TREE="zynq-arty"
CONFIG_SYS_CONFIG_NAME="zynq-arty"
CONFIG_SUPPORT_SPL=n

save into directory u-boot-xlnx/configs

4. Generate DT file for u-boot by using Xilinx SDK

Files we have:
zynq@ubuntu:~/BuildZynq/build_dtb$ ls -l
total 68
-rwxrwxr-x 1 zynq zynq   150 Jun 24 00:11 build.sh
-rwxrw-rw- 1 zynq zynq   982 Jun 30 01:48 pcw.dtsi
-rwxrw-rw- 1 zynq zynq  1263 Jun 30 01:48 pl.dtsi
-rwxrw-rw- 1 zynq zynq   409 Jun 30 01:00 skeleton.dtsi
-rw-rw-r-- 1 zynq zynq 12566 Jul  1 04:14 system.dtb
-rwxrw-rw- 1 zynq zynq 15471 Jul  1 04:14 system.dts
-rwxrw-rw- 1 zynq zynq   495 Jun 30 01:49 system-top.dts
-rwxrw-rw- 1 zynq zynq 13631 May  6 19:00 zynq-7000.dtsi

File system.dts combines all dtsi files together. This file will be used for u-boot DT. 
Scripts for building system.dts and system.dtb is build.sh

#!/bin/bash
gcc -I my_dts -E -nostdinc -undef -D__DTS__ -x assembler-with-cpp -o system.dts system-top.dts
dtc -I dts -O dtb -o system.dtb system.dts
Rename system.dtc into zynq-arty.dts
5. Edit u-boot-xlnx/arch/arm/dts/Makefile

cd u-boot-xlnx/arch/arm/dts
vim  Makefile

Add system.dtb

dtb-$(CONFIG_ARCH_ZYNQ) += \
bitmain-antminer-s9.dtb \
zynq-arty.dtb \
cp zynq-arty.dts arch/arm/dts

6. Set Cross compiler or use from installed Xilinx SDK

export CROSS_COMPILE=arm-linux-gnueabihf-
export ARCH=arm
7. Add sys config file unclude/configs/zynq-arty.h

#ifndef __CONFIG_ZYNQ_COMMON_H
#define __CONFIG_ZYNQ_COMMON_H


#include <configs/zynq-common.h> 
/* processor - ps7_cortexa9_0 */
#define CONFIG_CPU_FREQ_HZ 650000000
#define CONFIG_CLOCKS
#define CONFIG_ARM_DCC
#define CONFIG_REMAKE_ELF
#define CONFIG_SYS_LDSCRIPT "arch/arm/mach-zynq/u-boot.lds"
#define ZYNQ_SCUTIMER_BASEADDR 0xF8F00600
#define CONFIG_SYS_TIMERBASE ZYNQ_SCUTIMER_BASEADDR
#define CONFIG_SYS_TIMER_COUNTS_DOWN
#define CONFIG_SYS_TIMER_COUNTER (CONFIG_SYS_TIMERBASE + 0x4)

#define CONFIG_SYS_MEMTEST_START 0x0
#define CONFIG_SYS_MEMTEST_END (0x0 + 0x1000)
#define CONFIG_SYS_LOAD_ADDR 0x0 /* default load address */
/* Physical Memory Map */
#define CONFIG_SYS_INIT_RAM_ADDR 0xFFFF0000
#define CONFIG_SYS_INIT_RAM_SIZE 0x2000
#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_INIT_RAM_ADDR + \
CONFIG_SYS_INIT_RAM_SIZE - \
GENERATED_GBL_DATA_SIZE)

/* Extra U-Boot Env settings */
#define CONFIG_EXTRA_ENV_SETTINGS \ 
"ethaddr=00:0a:35:00:01:22\0" \
    "kernel_size=0x140000\0" \
    "ramdisk_size=0x200000\0" \
"sdboot=echo Copying Linux from SD to RAM...;" \
"mmcinfo;" \
"fatload mmc 0 0x3000000 uImage;" \
"fatload mmc 0 0x2A00000 system.dtb;" \
"fatload mmc 0 0x2000000 uramdisk.image.gz;" \
"bootm 0x3000000 0x2000000 0x2A00000\0" \
""
#define CONFIG_BOOTCOMMAND "run sdboot"

#endif /* __CONFIG_ZYNQ_COMMON_H */

We set sdboot for loading uImage, system.dtb, uramdisk.image.gz from SD to RAM and boot

8. Set defconfig and make

make distclean
make ARCH=arm zynq_zc702_defconfig
make ARCH=arm

9. Create BOOT.BIN (fsbl.elf, system.bit, u-boot.elf)  by using Xilinx SDK and load into QSPI FLASH.

10. Load from QSPI
U-Boot 2020.01-00020-gd7a07b0-dirty (Jul 03 2020 - 14:21:21 -0700) Xilinx Zynq ZC702

CPU:   Zynq 7z020
Silicon: v3.1
DRAM:  ECC disabled 512 MiB
MMC:   mmc@e0100000: 0
Loading Environment from SPI Flash... SF: Detected n25q128a13 with page size 256 Bytes, erase size 4 KiB, total 16 MiB
*** Warning - bad CRC, using default environment

In:    serial@e0000000
Out:   serial@e0000000
Err:   serial@e0000000
Net:
ZYNQ GEM: e000b000, mdio bus e000b000, phyaddr -1, interface rgmii-id
eth0: ethernet@e000b000
Hit any key to stop autoboot:  0
Copying Linux from SD to RAM...
MMC: no card present
MMC: no card present
MMC: no card present
MMC: no card present
Wrong Image Format for bootm command
ERROR: can't get kernel image!
Zynq>

If we have microSD card with files inserted,  Linux OS would start from RAM memory.

Comments