Read SD card in edk2 using Realtek card reader

Hi! Since Jetson Orin NX doesn’t have internal eMMC, we use SD card.
We use a Realtek RTS5264 card reader, which is attached to Orin NX using PCIe.

Now I’m creating a UEFI driver to be able to read the SD card contents from UEFI, and eventually boot from this device. SD card contains Linux kernel, dtb and rootfs.

I was able to add a Rts5264 DXE driver to edk2-nvidia: GitHub - NVIDIA/edk2-nvidia: NVIDIA EDK2 platform support.
I’m able to build the driver, and run it when the PCIe device matching Vendor ID and Product ID of this chip is detected in UEFI. Then it performs register writes to the RTS5264 chip to enable power for SD card, etc.
See example log:

add-symbol-file /workspace/Build/Jetson/DEBUG_GCC5/AARCH64/Platform/NVIDIA/Jetson/Drivers/Rts5264/Rts5264/DEBUG/Rts5264Dxe.dll 0x46A9FF000
Loading driver at 0x0046A9FE000 EntryPoint=0x0046AA0756C Rts5264Dxe.efi

ListPciDevices: Segment: FF      Bus: 0x00       Device: 0x00    Function: 0x00 Vendor ID: 0xFFFF       Device ID:0x0000
ListPciDevices: Segment: 01      Bus: 0x00       Device: 0x00    Function: 0x00 Vendor ID: 0x10DE       Device ID:0x229E
ListPciDevices: Segment: 01      Bus: 0x01       Device: 0x00    Function: 0x00 Vendor ID: 0x10EC       Device ID:0x5264
ListPciDevices: Segment: 04      Bus: 0x00       Device: 0x00    Function: 0x00 Vendor ID: 0x10DE       Device ID:0x229C
ListPciDevices: Segment: 04      Bus: 0x01       Device: 0x00    Function: 0x00 Vendor ID: 0x8086       Device ID:0x2723
ListPciDevices: Segment: 07      Bus: 0x00       Device: 0x00    Function: 0x00 Vendor ID: 0x10DE       Device ID:0x229A
ListPciDevices: Segment: 08      Bus: 0x00       Device: 0x00    Function: 0x00 Vendor ID: 0x10DE       Device ID:0x229C
ListPciDevices: Segment: 08      Bus: 0x01       Device: 0x00    Function: 0x00 Vendor ID: 0x10EC       Device ID:0x8168
MnpSyncSendPacket: No network cable detected.
RTS5264_START: Querying protocols on incoming ControllerHandle 46792BE98
RTS5264_START: ControllerHandle 46792BE98 HAS DevicePath: VenHw(1E5A432C-0466-4D31-B009-D4D9239271D3)/MemoryMapped(0xB,0x14100000,0x1411FFFF)/PciRoot(0x0)/Pci(0x0,0x0)/Pci(0x0,0x0)
RTS5264_START: ControllerHandle 46792BE98 HAS PciIo Protocol (queried by HandleProtocol).
RTS5264_START: Raw BAR1 value: 0x40000000 (Type: MmYsNRts5264: IC Version: 0x1
RTS5264: Powering on card...
RTS5264: Setting initial clock...

However, I struggle with connecting this driver to the filesystem in edk2, to be able to read/write, and eventually boot from the SD card.

Can you please outline the steps that should be taken, which protocols should I implement to be able to read the SD card via this driver?

hello filip.kubicz,

I’m confused..
let me have confirmation, you’re going to boot from device (a Realtek card reader) which connected to PCIe?

Hi @JerryChang , yes I need to boot using SD card reader, Realtek RTS5264.

Jetson Orin <–PCIe–> Realtek card reader <–UHS–> SD card

So on Jetson, in edk2 we need to be able to read block from the SD card, and then boot kernel using L4TLauncher.

As I see it:

  • Jetson boots from QSPI
  • edk2 has a driver to read SD card contents
  • read kernel & rootfs from SD card
  • boot Linux kernel

Hi,

We don’t have experience for enabling that Realtek card reader driver in EDK2. Could you also reach out for the vendor to help enabling that first?

Hi @WayneWWW, there is a kernel driver from Realtek, which I ported to UEFI with some required tweaks. They said they only provide kernel driver and cannot help with UEFI/edk2.

So the hardware/register part is good.

I’m asking for general UEFI/edk2 advice, which protocol should I implement to be able to mount/map this device and read the blocks for SD card?

I tried to use EFI_SD_MMC_PASS_THRU_PROTOCOL but instead of getting PCI 1 1 0 0, for some reason I get DevicePath: VenHw(1E5A432C-0466-4D31-B009-D4D9239271D3)/MemoryMapped(0xB,0x14100000,0x1411FFFF)/PciRoot(0x0)/Pci(0x0,0x0)/Pci(0x0,0x0) as you can see in the log above.

This code succeeds:

    Pcr->SdMmcPassThru.IoAlign          = 1;
    Pcr->SdMmcPassThru.PassThru         = Rts5264PassThru;
    Pcr->SdMmcPassThru.GetNextSlot      = Rts5264GetNextSlot;
    Pcr->SdMmcPassThru.BuildDevicePath  = Rts5264BuildDevicePath;
    Pcr->SdMmcPassThru.GetSlotNumber    = Rts5264GetSlotNumber;
    Pcr->SdMmcPassThru.ResetDevice      = Rts5264ResetDevice;

    Status = gBS->InstallMultipleProtocolInterfaces(
                    &ControllerHandle,
                    &gEfiSdMmcPassThruProtocolGuid, &Pcr->SdMmcPassThru,
                    NULL
                    );
    if (EFI_ERROR(Status)) {
       DEBUG((DEBUG_ERROR, "Rts5264: Failed to install EFI_SD_MMC_PASS_THRU_PROTOCOL: %r\n", Status));
       goto ErrorRestoreAttributes;
    }

But my driver is getting a wrong PCIe device path: PciRoot(0x0)/Pci(0x0,0x0)/Pci(0x0,0x0)

RTS5264_START: ControllerHandle 46792BE98 HAS DevicePath: VenHw(1E5A432C-0466-4D31-B009-D4D9239271D3)/MemoryMapped(0xB,0x14100000,0x1411FFFF)/PciRoot(0x0)/Pci(0x0,0x0)/Pci(0x0,0x0)
RTS5264_START: ControllerHandle 46792BE98 HAS PciIo Protocol (queried by HandleProtocol).

My PCIe device is Vendor 10EC Device 5264 Prog Interface 0, Seq 1, Bus 1, Dev 0, Func 0.

Shell> pci
   Seg  Bus  Dev  Func
   ---  ---  ---  ----
    01   00   00    00 ==> Bridge Device - PCI/PCI bridge
             Vendor 10DE Device 229E Prog Interface 0
    01   01   00    00 ==> Device does not fit in any defined classes - 
             Vendor 10EC Device 5264 Prog Interface 0
    04   00   00    00 ==> Bridge Device - PCI/PCI bridge
             Vendor 10DE Device 229C Prog Interface 0
    04   01   00    00 ==> Network Controller - Other network controller
             Vendor 8086 Device 2723 Prog Interface 0
    07   00   00    00 ==> Bridge Device - PCI/PCI bridge
             Vendor 10DE Device 229A Prog Interface 0
    08   00   00    00 ==> Bridge Device - PCI/PCI bridge
             Vendor 10DE Device 229C Prog Interface 0
    08   01   00    00 ==> Network Controller - Ethernet controller
             Vendor 10EC Device 8168 Prog Interface 0

Any idea how to move forward?