mirror of
https://github.com/edk2-porting/edk2-rk3588.git
synced 2025-12-17 11:04:41 +08:00
Improve SD/eMMC var store detection robustness
The hardware boot order on all platforms is: FSPI->EMMC->SD->USB. U-Boot SPL (our chainloader), however, is told by its DTB to boot in this order: SD->EMMC->FSPI. It then populates `RkAtagTypeBootDev` with the device it decided to boot from. We use this information to determine the drive we belong to, in order to write the variable store there. While this behavior is useful for testing, it should generally be avoided because it bypasses the SPL version we intended to ship with UEFI, which could lead to all sorts of issues. One such issue is that some SPL builds (namely Orange Pi's) flashed to SPI will happily boot from SD card while setting the ATAG to EMMC instead. Obviously, this leads UEFI to use the wrong device (or none at all if EMMC is missing) for writing variables. Since SPL only reads the variable store into memory from the actual boot device (SD card), settings will not persist. To address this, we'll no longer rely on that ATAG unless it indicates FSPI boot, in which case it would most likely be correct due to FSPI having priority in hardware - well, assuming there no further broken SPLs in the wild that might set it to FSPI while booting from SD :P. Instead, we'll look through the SD->EMMC devices (same order as SPL) to find a FIT image matching our own, indicating that's likely the boot device. Signed-off-by: Mario Bălănică <mariobalanica02@gmail.com>
This commit is contained in:
1
build.sh
1
build.sh
@@ -151,6 +151,7 @@ function _build(){
|
||||
-p "${ROOTDIR}/${DSC_FILE}" \
|
||||
-b "${RELEASE_TYPE}" \
|
||||
-D FIRMWARE_VER="${GIT_COMMIT}" \
|
||||
--pcd gRockchipTokenSpaceGuid.PcdFitImageFlashAddress=0x100000 \
|
||||
${EDK2_FLAGS}
|
||||
|
||||
#
|
||||
|
||||
@@ -34,11 +34,18 @@
|
||||
#include <Guid/SystemNvDataGuid.h>
|
||||
#include <Guid/VariableFormat.h>
|
||||
#include <Guid/EventGroup.h>
|
||||
#include <libfdt.h>
|
||||
|
||||
#include "RkFvbDxe.h"
|
||||
|
||||
RKATAG_BOOTDEV_TYPE mBootDeviceType;
|
||||
VOID *mDiskIoRegistration;
|
||||
STATIC RKATAG_BOOTDEV_TYPE mBootDeviceType;
|
||||
|
||||
// This matches the expected SPL boot order.
|
||||
STATIC FVB_RK_BOOT_DEVICE mFvbSecondaryRkBootDevices[] = {
|
||||
{ RkAtagBootDevTypeSd0, FixedPcdGet32 (PcdRkSdmmcBaseAddress) },
|
||||
{ RkAtagBootDevTypeEmmc, FixedPcdGet32 (PcdDwcSdhciBaseAddress) },
|
||||
};
|
||||
|
||||
STATIC EFI_EVENT mFvbVirtualAddrChangeEvent;
|
||||
STATIC FVB_DEVICE *mFvbDevice;
|
||||
STATIC CONST FVB_DEVICE mRkFvbFlashInstanceTemplate = {
|
||||
@@ -1196,8 +1203,9 @@ FvbReadyToBootEventHandler (
|
||||
|
||||
STATIC
|
||||
BOOLEAN
|
||||
FvbCheckIsBootDevice (
|
||||
IN EFI_HANDLE Handle
|
||||
FvbCheckRkBootDeviceSupported (
|
||||
IN EFI_HANDLE Handle,
|
||||
IN FVB_RK_BOOT_DEVICE *BootDevice
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
@@ -1208,10 +1216,8 @@ FvbCheckIsBootDevice (
|
||||
|
||||
DevicePath = DevicePathFromHandle (Handle);
|
||||
|
||||
DEBUG ((DEBUG_INFO, "%a: DevPath type 0x%x subtype 0x%x\n",
|
||||
__FUNCTION__, DevicePath->Type, DevicePath->SubType));
|
||||
|
||||
if (DevicePath->Type != HARDWARE_DEVICE_PATH
|
||||
if (DevicePath == NULL
|
||||
|| DevicePath->Type != HARDWARE_DEVICE_PATH
|
||||
|| DevicePath->SubType != HW_VENDOR_DP) {
|
||||
return FALSE;
|
||||
}
|
||||
@@ -1235,105 +1241,226 @@ FvbCheckIsBootDevice (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (mBootDeviceType == RkAtagBootDevTypeEmmc) {
|
||||
return Descriptor->AddrRangeMin == PcdGet32 (PcdDwcSdhciBaseAddress);
|
||||
}
|
||||
if (mBootDeviceType == RkAtagBootDevTypeSd0) {
|
||||
return Descriptor->AddrRangeMin == PcdGet32 (PcdRkSdmmcBaseAddress);
|
||||
return Descriptor->AddrRangeMin == BootDevice->ControllerBaseAddress;
|
||||
}
|
||||
|
||||
STATIC
|
||||
BOOLEAN
|
||||
FvbCheckBootDiskDeviceHasFirmware (
|
||||
IN EFI_HANDLE Handle,
|
||||
IN UINT32 MediaId,
|
||||
IN CHAR16 *DevicePathText
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_DISK_IO_PROTOCOL *DiskIo;
|
||||
UINT64 Offset;
|
||||
UINTN Size;
|
||||
struct fdt_header FdtHeader;
|
||||
VOID *Fdt = NULL;
|
||||
INT32 Ret;
|
||||
INT32 Node;
|
||||
BOOLEAN Found = FALSE;
|
||||
|
||||
Status = gBS->HandleProtocol (Handle, &gEfiDiskIoProtocolGuid, (VOID **)&DiskIo);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
Offset = FixedPcdGet64 (PcdFitImageFlashAddress);
|
||||
|
||||
Size = sizeof (FdtHeader);
|
||||
Status = DiskIo->ReadDisk (DiskIo, MediaId, Offset, Size, &FdtHeader);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: [%s] Failed to read %u bytes at 0x%lx. Status=%r\n",
|
||||
__FUNCTION__, DevicePathText, Size, Offset, Status));
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
Ret = fdt_check_header (&FdtHeader);
|
||||
if (Ret) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: [%s] FIT has an invalid header! Ret=%a\n",
|
||||
__FUNCTION__, DevicePathText, fdt_strerror (Ret)));
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
Size = fdt_totalsize (&FdtHeader);
|
||||
Fdt = AllocatePool (Size);
|
||||
|
||||
Status = DiskIo->ReadDisk (DiskIo, MediaId, Offset, Size, Fdt);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: [%s] Failed to read %u bytes at 0x%lx. Status=%r\n",
|
||||
__FUNCTION__, DevicePathText, Size, Offset, Status));
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
Node = fdt_path_offset (Fdt, "/images/edk2");
|
||||
if (Node < 0) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: [%s] FIT: Couldn't locate '/images/edk2' node! Ret=%a\n",
|
||||
__FUNCTION__, DevicePathText, fdt_strerror (Node)));
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
Found = TRUE;
|
||||
|
||||
Exit:
|
||||
if (Fdt != NULL) {
|
||||
FreePool (Fdt);
|
||||
}
|
||||
|
||||
return Found;
|
||||
}
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
FvbProcessBootDiskDeviceHandle (
|
||||
IN EFI_HANDLE Handle,
|
||||
IN FVB_RK_BOOT_DEVICE *BootDevice
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_BLOCK_IO_PROTOCOL *BlkIo;
|
||||
EFI_DEVICE_PATH_PROTOCOL *Device = NULL;
|
||||
CHAR16 *DevicePathText = NULL;
|
||||
|
||||
if (!FvbCheckRkBootDeviceSupported (Handle, BootDevice)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **)&BlkIo);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Device = DuplicateDevicePath (DevicePathFromHandle (Handle));
|
||||
if (Device == NULL) {
|
||||
ASSERT (FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
DevicePathText = ConvertDevicePathToText (Device, FALSE, FALSE);
|
||||
|
||||
if (!BlkIo->Media->MediaPresent) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: [%s] Media not present!\n", __FUNCTION__, DevicePathText));
|
||||
goto Exit;
|
||||
}
|
||||
if (BlkIo->Media->ReadOnly) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: [%s] Media is read-only!\n", __FUNCTION__, DevicePathText));
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
Status = gBS->ConnectController (Handle, NULL, NULL, FALSE);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: [%s] ConnectController failed. Status=%r\n", __FUNCTION__, DevicePathText, Status));
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
if (!FvbCheckBootDiskDeviceHasFirmware (Handle, BlkIo->Media->MediaId, DevicePathText)) {
|
||||
DEBUG ((DEBUG_INFO, "%a: [%s] No compatible firmware found. Skipping.\n", __FUNCTION__, DevicePathText));
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
Status = FvbDiskDumpNvData (Device, BlkIo->Media->MediaId);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: [%s] Couldn't update NV data!\n", __FUNCTION__, DevicePathText));
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
DEBUG ((DEBUG_INFO, "%a: [%s] Found boot disk for NV storage!\n", __FUNCTION__, DevicePathText));
|
||||
|
||||
mFvbDevice->DiskDevice = Device;
|
||||
mFvbDevice->DiskMediaId = BlkIo->Media->MediaId;
|
||||
|
||||
Exit:
|
||||
if ((Device != NULL) && (mFvbDevice->DiskDevice != Device)) {
|
||||
FreePool (Device);
|
||||
}
|
||||
if (DevicePathText != NULL) {
|
||||
FreePool (DevicePathText);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
FvbFindBootDiskDevice (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_HANDLE *Handles = NULL;
|
||||
UINTN NoHandles;
|
||||
UINTN DevIndex;
|
||||
UINTN HandleIndex;
|
||||
EFI_HANDLE Handle;
|
||||
FVB_RK_BOOT_DEVICE *RkBootDevice;
|
||||
|
||||
Status = gBS->LocateHandleBuffer (
|
||||
ByProtocol,
|
||||
&gEfiBlockIoProtocolGuid,
|
||||
NULL,
|
||||
&NoHandles,
|
||||
&Handles
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR,"%a: Failed to locate block devices. Status=%r\n", __FUNCTION__, Status));
|
||||
goto Fail;
|
||||
}
|
||||
ASSERT (NoHandles > 0);
|
||||
|
||||
for (DevIndex = 0; DevIndex < ARRAY_SIZE (mFvbSecondaryRkBootDevices); DevIndex++) {
|
||||
RkBootDevice = &mFvbSecondaryRkBootDevices[DevIndex];
|
||||
|
||||
for (HandleIndex = 0; HandleIndex < NoHandles; HandleIndex++) {
|
||||
Handle = Handles[HandleIndex];
|
||||
|
||||
FvbProcessBootDiskDeviceHandle (Handle, RkBootDevice);
|
||||
|
||||
if (mFvbDevice->DiskDevice != NULL) {
|
||||
if ((mBootDeviceType != RkAtagBootDevTypeUnknown) &&
|
||||
(mBootDeviceType != RkBootDevice->AtagBootDevType))
|
||||
{
|
||||
DEBUG ((DEBUG_WARN, "%a: WARNING: Found boot device type (0x%x) does not match SPL (0x%x)!\n",
|
||||
__FUNCTION__, RkBootDevice->AtagBootDevType, mBootDeviceType));
|
||||
DEBUG ((DEBUG_WARN, "%a: WARNING: Variable store might be using the wrong device!\n", __FUNCTION__));
|
||||
DEBUG ((DEBUG_WARN, "%a: WARNING: Consider erasing any firmware present on other devices (SPI/EMMC/SD)!\n",
|
||||
__FUNCTION__));
|
||||
}
|
||||
|
||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||
&Handle,
|
||||
&gRockchipFirmwareBootDeviceProtocolGuid,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
goto Done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Fail:
|
||||
DEBUG ((DEBUG_WARN, "%a: WARNING: Boot disk device not found!\n", __FUNCTION__));
|
||||
DEBUG ((DEBUG_WARN, "%a: WARNING: Variable store changes will NOT persist!\n", __FUNCTION__));
|
||||
|
||||
Done:
|
||||
if (Handles != NULL) {
|
||||
gBS->FreePool (Handles);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
EFIAPI
|
||||
FvbDiskIoRegistrationHandler (
|
||||
IN EFI_EVENT Event,
|
||||
IN VOID *Context
|
||||
NotifyEndOfDxeEvent (
|
||||
IN EFI_EVENT Event,
|
||||
IN VOID *Context
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN HandleSize;
|
||||
EFI_HANDLE Handle;
|
||||
EFI_DEVICE_PATH_PROTOCOL *Device;
|
||||
EFI_BLOCK_IO_PROTOCOL *BlkIo;
|
||||
CHAR16 *DevicePathText = NULL;
|
||||
|
||||
if (mFvbDevice->DiskDevice != NULL) {
|
||||
//
|
||||
// We've already found the NV disk before,
|
||||
// and it is not removed from the system (hopefully).
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
while (TRUE) {
|
||||
HandleSize = sizeof (EFI_HANDLE);
|
||||
Status = gBS->LocateHandle (ByRegisterNotify,
|
||||
NULL,
|
||||
mDiskIoRegistration,
|
||||
&HandleSize,
|
||||
&Handle);
|
||||
if (Status == EFI_NOT_FOUND) {
|
||||
break;
|
||||
}
|
||||
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
if (!FvbCheckIsBootDevice (Handle)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Device = NULL;
|
||||
Status = gBS->HandleProtocol (Handle,
|
||||
&gEfiBlockIoProtocolGuid,
|
||||
(VOID*)&BlkIo);
|
||||
if (EFI_ERROR (Status)) {
|
||||
continue;
|
||||
}
|
||||
Device = DuplicateDevicePath (DevicePathFromHandle (Handle));
|
||||
ASSERT (Device != NULL);
|
||||
|
||||
if (DevicePathText != NULL) {
|
||||
gBS->FreePool (DevicePathText);
|
||||
}
|
||||
DevicePathText = ConvertDevicePathToText (Device, FALSE, FALSE);
|
||||
|
||||
if (!BlkIo->Media->MediaPresent) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: [%s] Media not present!\n",
|
||||
__FUNCTION__, DevicePathText));
|
||||
continue;
|
||||
}
|
||||
if (BlkIo->Media->ReadOnly) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: [%s] Media is read-only!\n",
|
||||
__FUNCTION__, DevicePathText));
|
||||
continue;
|
||||
}
|
||||
|
||||
Status = FvbDiskDumpNvData (Device, BlkIo->Media->MediaId);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: [%s] Couldn't update NV data!\n",
|
||||
__FUNCTION__, DevicePathText));
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mFvbDevice->DiskDevice != NULL) {
|
||||
gBS->FreePool (mFvbDevice->DiskDevice);
|
||||
}
|
||||
|
||||
DEBUG ((DEBUG_INFO, "%a: [%s] Found boot disk for NV storage!\n",
|
||||
__FUNCTION__, DevicePathText));
|
||||
|
||||
mFvbDevice->DiskDevice = Device;
|
||||
mFvbDevice->DiskMediaId = BlkIo->Media->MediaId;
|
||||
break;
|
||||
}
|
||||
|
||||
if (DevicePathText != NULL) {
|
||||
gBS->FreePool (DevicePathText);
|
||||
}
|
||||
FvbFindBootDiskDevice ();
|
||||
}
|
||||
|
||||
STATIC
|
||||
@@ -1375,19 +1502,17 @@ FvbInstallDiskNotifyHandler (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_EVENT Event;
|
||||
EFI_STATUS Status;
|
||||
EFI_EVENT Event;
|
||||
|
||||
Status = gBS->CreateEvent (EVT_NOTIFY_SIGNAL,
|
||||
TPL_CALLBACK,
|
||||
FvbDiskIoRegistrationHandler,
|
||||
NULL,
|
||||
&Event);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
Status = gBS->RegisterProtocolNotify (&gEfiDiskIoProtocolGuid,
|
||||
Event,
|
||||
&mDiskIoRegistration);
|
||||
Status = gBS->CreateEventEx (
|
||||
EVT_NOTIFY_SIGNAL, // Type
|
||||
TPL_CALLBACK, // NotifyTpl
|
||||
NotifyEndOfDxeEvent, // NotifyFunction
|
||||
NULL, // NotifyContext
|
||||
&gEfiEndOfDxeEventGroupGuid, // EventGroup
|
||||
&Event // Event
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.
|
||||
* Copyright (c) 2017 Marvell International Ltd.
|
||||
* Copyright (c) 2021-2022 Rockchip Electronics Co., Ltd.
|
||||
* Copyright (c) 2023, Mario Bălănică <mariobalanica02@gmail.com>
|
||||
* Copyright (c) 2023-2024, Mario Bălănică <mariobalanica02@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
*
|
||||
@@ -66,6 +66,11 @@ typedef struct {
|
||||
FVB_DEVICE_PATH DevicePath;
|
||||
} FVB_DEVICE;
|
||||
|
||||
typedef struct {
|
||||
UINT32 AtagBootDevType;
|
||||
UINT32 ControllerBaseAddress;
|
||||
} FVB_RK_BOOT_DEVICE;
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
FvbGetAttributes(
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
MemoryAllocationLib
|
||||
UefiRuntimeServicesTableLib
|
||||
RkAtagsLib
|
||||
FdtLib
|
||||
|
||||
[Guids]
|
||||
gEdkiiNvVarStoreFormattedGuid
|
||||
@@ -53,6 +54,7 @@
|
||||
gEfiSystemNvDataFvGuid
|
||||
gEfiVariableGuid
|
||||
gEfiEventReadyToBootGuid
|
||||
gEfiEndOfDxeEventGroupGuid
|
||||
|
||||
[Protocols]
|
||||
gEfiDevicePathProtocolGuid
|
||||
@@ -62,11 +64,13 @@
|
||||
gEfiBlockIoProtocolGuid
|
||||
gEdkiiNonDiscoverableDeviceProtocolGuid
|
||||
gEfiResetNotificationProtocolGuid
|
||||
gRockchipFirmwareBootDeviceProtocolGuid
|
||||
|
||||
[FixedPcd]
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
|
||||
gRockchipTokenSpaceGuid.PcdFitImageFlashAddress
|
||||
gRockchipTokenSpaceGuid.PcdNvStoragePreferSpiFlash
|
||||
gRockchipTokenSpaceGuid.PcdDwcSdhciBaseAddress
|
||||
gRockchipTokenSpaceGuid.PcdRkSdmmcBaseAddress
|
||||
|
||||
@@ -16,68 +16,25 @@
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/DevicePathLib.h>
|
||||
#include <Library/PrintLib.h>
|
||||
#include <Library/RkAtagsLib.h>
|
||||
#include <Protocol/NonDiscoverableDevice.h>
|
||||
|
||||
RKATAG_BOOTDEV_TYPE mBootDeviceType;
|
||||
|
||||
CHAR16 mBootDescFirmwareSuffix[] = L" [Fw]";
|
||||
|
||||
STATIC
|
||||
NON_DISCOVERABLE_DEVICE *
|
||||
GetNonDiscoverableDevice (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_HANDLE DeviceHandle;
|
||||
NON_DISCOVERABLE_DEVICE *Device;
|
||||
EFI_DEVICE_PATH_PROTOCOL *CurrentDevicePath;
|
||||
|
||||
CurrentDevicePath = DevicePath;
|
||||
|
||||
if (DevicePath->Type != HARDWARE_DEVICE_PATH
|
||||
|| DevicePath->SubType != HW_VENDOR_DP) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Status = gBS->LocateDevicePath (&gEdkiiNonDiscoverableDeviceProtocolGuid,
|
||||
&CurrentDevicePath, &DeviceHandle);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Status = gBS->HandleProtocol (DeviceHandle,
|
||||
&gEdkiiNonDiscoverableDeviceProtocolGuid, (VOID **) &Device);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Device;
|
||||
}
|
||||
|
||||
STATIC
|
||||
BOOLEAN
|
||||
CheckIsBootDevice (
|
||||
IN NON_DISCOVERABLE_DEVICE *Device
|
||||
IN EFI_HANDLE Handle
|
||||
)
|
||||
{
|
||||
EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor;
|
||||
Descriptor = &Device->Resources[0];
|
||||
EFI_STATUS Status;
|
||||
VOID *Instance;
|
||||
|
||||
if (Descriptor->Desc != ACPI_ADDRESS_SPACE_DESCRIPTOR ||
|
||||
Descriptor->ResType != ACPI_ADDRESS_SPACE_TYPE_MEM) {
|
||||
return FALSE;
|
||||
}
|
||||
Status = gBS->HandleProtocol (
|
||||
Handle,
|
||||
&gRockchipFirmwareBootDeviceProtocolGuid,
|
||||
&Instance
|
||||
);
|
||||
|
||||
if (mBootDeviceType == RkAtagBootDevTypeEmmc) {
|
||||
return Descriptor->AddrRangeMin == PcdGet32 (PcdDwcSdhciBaseAddress);
|
||||
}
|
||||
if (mBootDeviceType == RkAtagBootDevTypeSd0) {
|
||||
return Descriptor->AddrRangeMin == PcdGet32 (PcdRkSdmmcBaseAddress);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return !EFI_ERROR (Status);
|
||||
}
|
||||
|
||||
STATIC
|
||||
@@ -89,21 +46,14 @@ PlatformBootDescriptionHandler (
|
||||
)
|
||||
{
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||
NON_DISCOVERABLE_DEVICE *NonDiscoverableDevice;
|
||||
CHAR16 *Desc;
|
||||
UINTN DescSize;
|
||||
|
||||
if (!CheckIsBootDevice (Handle)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DevicePath = DevicePathFromHandle (Handle);
|
||||
|
||||
NonDiscoverableDevice = GetNonDiscoverableDevice (DevicePath);
|
||||
if (NonDiscoverableDevice == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!CheckIsBootDevice (NonDiscoverableDevice)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DevicePath = NextDevicePathNode (DevicePath);
|
||||
|
||||
if (DevicePath->SubType == MSG_EMMC_DP) {
|
||||
@@ -147,10 +97,5 @@ PlatformBootDescriptionLibConstructor (
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
RKATAG_BOOTDEV *BootDevice;
|
||||
|
||||
BootDevice = RkAtagsGetBootDev ();
|
||||
mBootDeviceType = BootDevice != NULL ? BootDevice->DevType : RkAtagBootDevTypeUnknown;
|
||||
|
||||
return EfiBootManagerRegisterBootDescriptionHandler (PlatformBootDescriptionHandler);
|
||||
}
|
||||
|
||||
@@ -31,10 +31,9 @@
|
||||
UefiBootManagerLib
|
||||
MemoryAllocationLib
|
||||
DevicePathLib
|
||||
RkAtagsLib
|
||||
|
||||
[Protocols]
|
||||
gEdkiiNonDiscoverableDeviceProtocolGuid ## SOMETIMES_CONSUMES
|
||||
gRockchipFirmwareBootDeviceProtocolGuid ## SOMETIMES_CONSUMES
|
||||
|
||||
[Pcd]
|
||||
gRockchipTokenSpaceGuid.PcdDwcSdhciBaseAddress
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include <Library/UefiBootManagerLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Library/UefiRuntimeServicesTableLib.h>
|
||||
#include <Library/RkAtagsLib.h>
|
||||
#include <Protocol/BootManagerPolicy.h>
|
||||
#include <Protocol/DevicePath.h>
|
||||
#include <Protocol/EsrtManagement.h>
|
||||
@@ -312,68 +311,6 @@ IsUsbHost (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
This FILTER_FUNCTION checks if the Block I/O protocol handle
|
||||
corresponds to that of the boot SD/eMMC device.
|
||||
|
||||
This code is almost identical to FvbCheckIsBootDevice from RkFvbDxe.
|
||||
**/
|
||||
STATIC
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
IsSdBootBlockIo (
|
||||
IN EFI_HANDLE Handle,
|
||||
IN CONST CHAR16 *ReportText
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||
EFI_HANDLE DeviceHandle;
|
||||
NON_DISCOVERABLE_DEVICE *Device;
|
||||
EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor;
|
||||
RKATAG_BOOTDEV *BootDevice;
|
||||
|
||||
BootDevice = RkAtagsGetBootDev ();
|
||||
if (BootDevice == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DevicePath = DevicePathFromHandle (Handle);
|
||||
|
||||
if (DevicePath->Type != HARDWARE_DEVICE_PATH
|
||||
|| DevicePath->SubType != HW_VENDOR_DP) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Status = gBS->LocateDevicePath (&gEdkiiNonDiscoverableDeviceProtocolGuid,
|
||||
&DevicePath, &DeviceHandle);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Status = gBS->HandleProtocol (DeviceHandle,
|
||||
&gEdkiiNonDiscoverableDeviceProtocolGuid, (VOID **) &Device);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Descriptor = &Device->Resources[0];
|
||||
|
||||
if (Descriptor->Desc != ACPI_ADDRESS_SPACE_DESCRIPTOR ||
|
||||
Descriptor->ResType != ACPI_ADDRESS_SPACE_TYPE_MEM) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (BootDevice->DevType == RkAtagBootDevTypeEmmc) {
|
||||
return Descriptor->AddrRangeMin == PcdGet32 (PcdDwcSdhciBaseAddress);
|
||||
}
|
||||
if (BootDevice->DevType == RkAtagBootDevTypeSd0) {
|
||||
return Descriptor->AddrRangeMin == PcdGet32 (PcdRkSdmmcBaseAddress);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
This CALLBACK_FUNCTION attempts to connect a handle non-recursively, asking
|
||||
the matching driver to produce all first-level child handles.
|
||||
@@ -928,14 +865,6 @@ PlatformBootManagerBeforeConsole (
|
||||
//
|
||||
FilterAndProcess (&gOhciDeviceProtocolGuid, NULL, Connect);
|
||||
|
||||
//
|
||||
// Connect the Block I/O device produced by the SD/eMMC device that
|
||||
// booted UEFI. We don't want BDS to ignore this device as it would
|
||||
// prevent RkFvbDxe from detecting it and dumping the NVRAM variables
|
||||
// in time.
|
||||
//
|
||||
FilterAndProcess (&gEfiBlockIoProtocolGuid, IsSdBootBlockIo, Connect);
|
||||
|
||||
//
|
||||
// Add the hardcoded serial console device path to ConIn, ConOut, ErrOut.
|
||||
//
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
## @file
|
||||
# Implementation for PlatformBootManagerLib library class interfaces.
|
||||
#
|
||||
# Copyright (c) 2023-2024, Mario Bălănică <mariobalanica02@gmail.com>
|
||||
# Copyright (C) 2015-2016, Red Hat, Inc.
|
||||
# Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>
|
||||
# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||
@@ -51,7 +52,6 @@
|
||||
UefiBootServicesTableLib
|
||||
UefiLib
|
||||
UefiRuntimeServicesTableLib
|
||||
RkAtagsLib
|
||||
|
||||
[FeaturePcd]
|
||||
gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport
|
||||
@@ -68,8 +68,6 @@
|
||||
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity
|
||||
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdBootDiscoveryPolicy
|
||||
gRockchipTokenSpaceGuid.PcdDwcSdhciBaseAddress
|
||||
gRockchipTokenSpaceGuid.PcdRkSdmmcBaseAddress
|
||||
|
||||
[Guids]
|
||||
gBootDiscoveryPolicyMgrFormsetGuid
|
||||
@@ -95,7 +93,6 @@
|
||||
gEfiLoadedImageProtocolGuid
|
||||
gEfiPciRootBridgeIoProtocolGuid
|
||||
gEfiSimpleFileSystemProtocolGuid
|
||||
gEfiBlockIoProtocolGuid
|
||||
gEsrtManagementProtocolGuid
|
||||
gPlatformBootManagerProtocolGuid
|
||||
gOhciDeviceProtocolGuid
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
gDpPhyProtocolGuid = { 0xb4bcf881, 0xc8b3, 0x46d7, { 0xaf, 0xbe, 0x5a, 0x2d, 0x94, 0x9d, 0x93, 0xc3 } }
|
||||
gPca95xxProtocolGuid = { 0x7e91391b, 0xa23c, 0x4a51, { 0x9d, 0xf7, 0xf6, 0x74, 0xef, 0x1d, 0x51, 0x1b } }
|
||||
gRockchipDsiPanelProtocolGuid = { 0x07a5d05c, 0x3216, 0x49fc, { 0xb4, 0x22, 0x28, 0x9d, 0x38, 0xd5, 0xdf, 0x7e } }
|
||||
gRockchipFirmwareBootDeviceProtocolGuid = { 0x8733765a, 0x3ce7, 0x47b5, { 0xb2, 0xc0, 0x39, 0x80, 0x68, 0xd5, 0x86, 0xb3 } }
|
||||
|
||||
[Guids]
|
||||
gRockchipTokenSpaceGuid = { 0xc620b83a, 0x3175, 0x11ec, { 0x95, 0xb4, 0xf4, 0x2a, 0x7d, 0xcb, 0x92, 0x5d } }
|
||||
@@ -49,6 +50,8 @@
|
||||
gRockchipTokenSpaceGuid.PcdFamilyName|"Unknown"|VOID*|0x00000008
|
||||
gRockchipTokenSpaceGuid.PcdDeviceTreeName|"Unknown"|VOID*|0x00000009
|
||||
|
||||
gRockchipTokenSpaceGuid.PcdFitImageFlashAddress|0|UINT64|0x01000000
|
||||
|
||||
gRockchipTokenSpaceGuid.PcdI2cSlaveAddresses|{ 0x0 }|VOID*|0x02000001
|
||||
gRockchipTokenSpaceGuid.PcdI2cSlaveBuses|{ 0x0 }|VOID*|0x02000002
|
||||
gRockchipTokenSpaceGuid.PcdI2cSlaveBusesRuntimeSupport|{ 0x0 }|VOID*|0x02000003
|
||||
|
||||
@@ -11,12 +11,12 @@
|
||||
#address-cells = <1>;
|
||||
|
||||
images {
|
||||
uboot {
|
||||
edk2 {
|
||||
description = "UEFI";
|
||||
data = /incbin/("./BL33_AP_UEFI.Fv");
|
||||
type = "standalone";
|
||||
arch = "arm64";
|
||||
os = "U-Boot";
|
||||
os = "EDK2";
|
||||
compression = "none";
|
||||
load = <0x00200000>;
|
||||
hash {
|
||||
@@ -98,7 +98,7 @@
|
||||
description = "@DEVICE@";
|
||||
rollback-index = <0x0>;
|
||||
firmware = "atf-1";
|
||||
loadables = "uboot", "atf-2", "atf-3", "optee", "nvdata";
|
||||
loadables = "edk2", "atf-2", "atf-3", "optee", "nvdata";
|
||||
fdt = "fdt";
|
||||
signature {
|
||||
algo = "sha256,rsa2048";
|
||||
|
||||
Reference in New Issue
Block a user