June 16, 2024

the Zynq FSBL - where is the NAND driver

Two of my Zynq boards (the Antminer S9 and EBAZ-4205) boot from NAND chips. So I naturally expected to find the NAND driver included in my fsbl build. It is not.

We see the file fsbl/nand.c -- but on close inspection we see that pretty much the entire contents of the file are conditional on:

#if defined(XPAR_PS7_NAND_0_BASEADDR) || defined(XPAR_XNANDPS_0_FLASHBASE)
Indeed, neither of these variables are defined. It they were defined, it would be done in include/xparameters.h -- we can look in that file and fine definitions like:
#define XPAR_PS7_SD_0_BASEADDR 0xE0100000
#define XPAR_PS7_QSPI_LINEAR_0_S_AXI_BASEADDR 0xFC000000
So this explains why we get support for the SD card and Qspi devices. Why not NAND? What could we do to pull in NAND support?

A criticism

I think there ought to be a general file with base addresses for every possible peripheral. I search the entire "embeddedsw" distribution and I don't find the NAND base address anwhere. What ought to be done is to put the specific driver selections in some other file. Maybe fsbl.h or bspconfig.h in a form like U-Boot uses, i.e.
#define	CONFIG_NAND_DRIVER
#define	CONFIG_QSPI_DRIVER
Apart from making things clearer, this would make the base address definitions easily available for any configuration. As it is, they are not to be found anywhere for the NAND driver.

Finding a NAND driver

The file fsbl/nand.c would make calls to:
XNandPs_Read()
A search through the "embeddedsw" distribution finds that this is provided by the file:
XilinxProcessorIPLib/drivers/nandps/src/xnandps.h
The directory "XilinxProcessorIPLib/driver" has quite a collection of drivers, including "sdps/src" for the SD card and so forth.

Note though that the SD driver (as an example) used in the FSBL build was found in:

zynq_fsbl/misc/ps7_cortexa9_0/libsrc/sdps/src
But wait! That entire ps7_cortexa9_0 directory was build "on the fly" by the distributed FSBL build process. I ran that first, then pulled files from it. Where did that build process get the SD driver from? This is handled by the file:
misc/copy_bsp.sh
And this reminds us of an important decision I made when I did the original build. I specified the Zedboard as my board target. This means that the file xparameters.h was obtained from the "zed" directory. In that file we see:
# selection of drivers is based on the board selected
DRIVERS_LIST="$BOARD_DIR/drivers.txt"
So, this is really the answer to the question. A Zedboard has Qspi flash, not NAND, so a NAND driver is not required. The copy_bsp.sh script does in fact copy drivers from "XilinxProcessorIPLib/drivers".

Conclusion

The answer is clear. I build an FSBL for a Zedboard and that does not include NAND memory support (nor should it).

I have to remind myself that I am not trying to build the FSBL in order to use and run it. For that, I might go to the U-Boot distribution, which does work on my NAND based boards and presumably has everything set up to build it.

I know where the NAND driver is, should I want to study it, and I can for the purposes on studying the FSBL, just look at the SD driver (or for an even more simple case, the NOR driver).


Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org