Thursday, August 15, 2019

How to add FPGA bin file in BOOT.bin, for FPGA configuration with Linux

This guide will explain how to recompile U-Boot, in order to add FPGA configuration bin file in BOOT.bin.

In order for FSBL to configure the FPGA at power up and before starting Linux, it must be added to the boot file immediately after FSBL, otherwise it will not find it. It is necessary to use the * .bit file. Because in the * .bin file there is no header and it does not start via FSBL. Boot.bin looks like this:


Fig. 1 boot image

But when you try to do this, the Xilinx SDK will throw an error:
[ERROR]  : Section uImage.0 offset of 0x100000 overlaps with prior section end address of 2A13C0

This means that the files added before uImage occupy a larger size than it's start address 0x100000, and it is not possible to add uImage to the desired location.

In order to analyze in more detail the size occupied by each file, you can create a boot file with the "-debug" option. To do this, copy the executable command from the console, which is located at the bottom of the screen:

Fig. 2 Copying a command from the console
In my case it’s:
cmd /C bootgen -image zybo.bif -arch zynq -o D:\study\maga2\V\BOOT.bin -w on
Next, open a terminal. This can be done through the Xilinx SDK by clicking Xilinx -> Launch Shell

Fig. 3 Terminal startup
In the window that appears, try to execute the saved command. Most likely it will not be executed, because it will not find the source file:

Fig. 4 The result of the command execution
You should specify the path to the file and add "-debug" to the end of the program, if everything is done correctly, information about files sizes should appear:

Fig. 5 Address space of the boot image
As you can see, U-Boot starts at 0x21A300, it takes up 0x870BC, therefore it ends at about 0x2A13BC, it is worth noting that some files on the disk take up more space than here and there may be a gap between the files in the boot image.

In Zybo there is a 128 Mb QSPI, the address of the last cell is 0x8000000, we still have enough space to move everything. The binary FPGA and FSBL should not change much in size, regardless of the complexity of the project.

Let's change file offsets to the following:
uImage 0x300000
devicetree.dtb 0x800000
uramdisk.image.gz 0x820000

Zybo.bif now has the following contents:
//arch = zynq; split = false; format = BIN
the_ROM_image:
{
    [bootloader]D:\study\maga2\V\Zybo-base-linux-aster\zybo_19\zybo_19.sdk\fsbl\Debug\fsbl.elf
    D:\study\maga2\V\Zybo-base-linux-aster\zybo_19\zybo_19.runs\impl_1\design_1_wrapper.bit
    D:\study\maga2\V\Linux_files\u-boot.elf
    [offset = 0x300000]D:\study\maga2\V\Linux_files\uImage
    [offset = 0x800000]D:\study\maga2\V\Linux_files\devicetree.dtb
    [offset = 0x820000]D:\study\maga2\V\Linux_files\uramdisk.image.gz
}
The boot file is successfully created, but when you try to run it on Zynq, an error appears, stating that U-Boot did not find the Linux image. In order to fix this, you need to change the sources of U-Boot, writing correct offset addresses and recompiling it.

U-Boot was taken from a Git server. We need to change the file
u-boot-xlnx/include/configs/zynq-common.h

Instead of this part:
"qspiboot=run xilinxcmd && " \
" echo Copying Linux from QSPI flash to RAM... && " \
"sf probe 0 0 0 && " \
"sf read ${kernel_load_address} 0x100000 ${kernel_size} && " \
"sf read ${devicetree_load_address} 0x600000 ${devicetree_size} && " \
"echo Copying ramdisk... && " \
"sf read ${ramdisk_load_address} 0x620000 ${ramdisk_size} && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
Write this:
"qspiboot=run xilinxcmd && " \
" echo Copying Linux from QSPI flash to RAM... && " \
"sf probe 0 0 0 && " \
"sf read ${kernel_load_address} 0x300000 ${kernel_size} && " \
"sf read ${devicetree_load_address} 0x800000 ${devicetree_size} && " \
"echo Copying ramdisk... && " \
"sf read ${ramdisk_load_address} 0x820000 ${ramdisk_size} && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
Next, you need to recompile U-Boot, as described in another article.

After completing all the steps, the FPGA is configured at power-up, then Linux is started as before.




No comments :

Post a Comment