How to use the spi interface for commuciating in uefi?

Platform: Jetpack 5.1.1 for the AGXI
Hello, I am trying to using the spi interface (spi1: pin-19, pin-21,pin-23,pin-24) to commuciate with FPGA in UEFI.
image

I have download the UEFI source code, but I only find the QSPI controller diver library. There are only 4 lines for spi1 , so I think spi1 should only work for standard mode rather that QSPI mode.
edk2-nvidia/Silicon/NVIDIA/Drivers/QspiControllerDxe/QspiControllerDxe.c at main · NVIDIA/edk2-nvidia · GitHub

edk2-nvidia/Silicon/NVIDIA/Library/QspiControllerLib/QspiControllerLib.c at main · NVIDIA/edk2-nvidia · GitHub

Where I can find the SPI controller driver for spi1? Or is there any reference?

Thanks.

Hi Bryan_Zhong,

Are you using the devkit or custom board for AGX Xavier?

Could you try to refer to SpiDxe in UEFI source?

Hi,KevinFFF

For testing spi interface,I am using the devkit for AGX Xavier.

But I don 't find ‘SpiDxe’ in edk2-nvidia source.
GitHub - NVIDIA/edk2-nvidia: NVIDIA EDK2 platform support

Do you means from other UEFI source? Could you please provide a link for SpiDxe?

when you used edkrepo to download UEFI source, there should be other sources downloaded at the same time.

SpiDxe would be included in edk2-platforms.

After checkout edk2-platforms . I only find SpiDxe for platform FT2000-4Pkg , not for nvidia. Do you mean that driver? I think the driver for FT2000-4Pkg maybe not suit for Nvidia. Because there must be some difference between these two platforms. They should be have some different configurations. for example, configuration for SpiController.
edk2-platforms/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c at master · tianocore/edk2-platforms · GitHub

Please let me know if I don’t find the right driver.

Hi Bryan_Zhong,

Qspi controller driver supports spi controller as well.
It depends on the compatibility string(as following) in dtb.
edk2-nvidia/Silicon/NVIDIA/Drivers/QspiControllerDxe/QspiControllerDxe.c at main · NVIDIA/edk2-nvidia · GitHub

Please configure the nvidia,tegra194-spi in your UEFI dtb, and use this controller for your SPI device.

1 Like

HI,KevinFFF,

Thanks,that’s good. I will try it.

Hi KevinFFF,

After configuring the nvidia,tegra194-spi in your UEFI dtb, I tried use some protocols to find handler, but I can’t find any handler about spi.
the protocols that I have tried are as follows (add in **.inf file):
[Guids.common]
gNVIDIANonDiscoverableSpiDeviceGuid #spi
gNVIDIANonDiscoverableQspiDeviceGuid

[Protocols]
gNVIDIAQspiControllerProtocolGuid #spi
gEfiSpiConfigurationProtocolGuid
gEfiLegacySpiControllerProtocolGuid

I use gBS->LocateHandleBuffer() to find device. And I replace Guid with gNVIDIANonDiscoverableSpiDeviceGuid ,gNVIDIANonDiscoverableQspiDeviceGuid , gNVIDIAQspiControllerProtocolGuid,gEfiSpiConfigurationProtocolGuid and gEfiLegacySpiControllerProtocolGuid.
for example:
image
The return value of HandleCount always 0.

Do you have any suggestion to find spi handle?

Thanks.

gNVIDIAQspiControllerProtocolGuid is installed for spi as well as qspi.
You need to locate this protocol only and then talk to the client on the bus.

If you want to install a new guid, you can create that and change the guid in edk2-nvidia/Silicon/NVIDIA/Drivers/QspiControllerDxe/QspiControllerDxe.c at a03bece4373a150a4a179ab92fb00c2764df237f · NVIDIA/edk2-nvidia · GitHub based on edk2-nvidia/Silicon/NVIDIA/Drivers/QspiControllerDxe/QspiControllerDxe.c at a03bece4373a150a4a179ab92fb00c2764df237f · NVIDIA/edk2-nvidia · GitHub true or not.

Hi KevinFFF,

I use LocateHandleBuffer() to locate gNVIDIAQspiControllerProtocolGuid protocol like this:

.
The result that I expected is that HandleCount is bigger than 0 . but now the 'HandleCount ’ equals 0. That means I don’t get any client ( or handle).
There should be at least two controller (QspiController and spiController ) .so I think HandleCount should be bigger than 2 or equals 2. (The desired result is HandleCount >=2)

I don’t want to add a new gui d. I just want to use a protocol to find the spl controller.

Do I use the wrong function to locate the protocol? if yes, what is the right method?

Thanks.

If protocol installed successfully it should be found.
Could you add logs after install protocol to check if it is installed correctly?

Hi KevinFFF:

I have added logs in QspiControllerDxe.c as follows:

.

Then I compiled uefi source and replaced uefi_jetson.bin with uefi_Jetson_DEBUG.bin.
I reflashed the devkit with sudo ./flash.sh -r jetson-agx-xavier-industrial mmcblk0p1. But I didn’t find the logs that I add. That means it didn’t install gNVIDIAQspiControllerProtocolGuid successfully.
agxi_boot_log-20240315.log (85.9 KB)

Do you have any suggestions to install the protocol?
Thanks.

Can you add more logs and confirm if QspiControllerDxe.c is loaded during boot up?

In the boot log agxi_boot_log-20240315.log , I could find that QspiControllerDxe.efi was loaded.
https://forums.developer.nvidia.com/uploads/short-url/tDoy3i9UBWA3fMTiYFAa5RdAEvE.log


And I am sure that I have added nvidia,tegra194-spi in the tegra194-p2888-0008-p2822-0000.dtb.

I also notice that tegra194-p2888-0008-p2822-0000.dtb contains nvidia,tegra186-spinvidia,tegra186-qspi in the original SDK.
And there is no nvidia,tegra194-spi and nvidia,tegra194-qspi in the dtb. So I change nvidia,tegra186-spi to nvidia,tegra194-spi .

So I am sure that QspiControllerDxe.c* is loaded .

Can you add more logs in DeviceDiscoveryNotify() to check if it break out somewhere so that the protocol is not installed correctly?
You can also add log to check ControllerType currently.

Have you confirmed the node with nvidia-tegra186-spi is enabled (status="okay") in device tree?

Hi KevinFFF:

After add more logs in DeviceDiscoveryNotify() .Everytime when it enter DeviceDiscoveryNotify() . I find that it break out from this branch. Do you have any suggestions to fix this?
image

Yes. I have. The node with nvidia-tegra186-spi is enabled (status=“okay”).

Qspi flash is protected from non secure access by mm.

Can you add log in case DeviceDiscoveryDriverBindingStart:?

Hi KevinFFF:

I have added log in case DeviceDiscoveryDriverBindingStart:. but I could not find any log that indicates it enter DeviceDiscoveryDriverBindingStart.


I change QspiControllerDxe.c to QspiControllerDxe.txt for uploading. You can find all changes in QspiControllerDxe.txt.
QspiControllerDxe.txt (23.1 KB)

By the way. the boot log about QspiControllerDxe is as follows:


I guess if it fails in case DeviceDiscoveryDriverBindingSupported. it won’t enter case DeviceDiscoveryDriverBindingStart. In the logs. I found that it enter case DeviceDiscoveryDriverBindingSupported a few times. Maybe it indicates find more than one *spi device,including QspiController device and SpiController device. If so, maybe SpiController device couldn’t be supported in case DeviceDiscoveryDriverBindingSupported .

I am looking forward to your reply.
Thanks.

Please share your tegra194-p2888-0008-p2822-0000.dtb for further check.

Hi KevinFFF:

Here is the dtb file.
tegra194-p2888-0008-p2822-0000.zip (59.6 KB)

Thanks.