Skip to content

Commit

Permalink
fix(launcher): improve backwards compatibility
Browse files Browse the repository at this point in the history
re-add functions that were removed when l4t launcher support
protocol was added to allow for backwards compatibility.

Signed-off-by: Ashish Singhal <ashishsingha@nvidia.com>
Reviewed-by: Jeff Brasen <jbrasen@nvidia.com>
Tested-by: Jake Garver <jake@nvidia.com>
Reviewed-by: Jake Garver <jake@nvidia.com>
  • Loading branch information
ashishsingha authored and jgarver committed Jan 22, 2025
1 parent f49f566 commit 85becaf
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 22 deletions.
71 changes: 55 additions & 16 deletions Silicon/NVIDIA/Application/L4TLauncher/L4TLauncher.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
**/

#include <PiPei.h>

#include <Library/BaseMemoryLib.h>
#include <Library/UefiLib.h>
#include <Library/HobLib.h>
#include <Library/PcdLib.h>
#include <Library/ShellLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
Expand Down Expand Up @@ -40,6 +44,8 @@

#include <NVIDIAConfiguration.h>
#include <libfdt.h>
#include <Library/PlatformBootOrderLib.h>
#include <Library/TegraDeviceTreeOverlayLib.h>
#include "L4TLauncher.h"
#include "L4TRootfsValidation.h"

Expand Down Expand Up @@ -1566,7 +1572,12 @@ ExtLinuxBoot (
goto Exit;
}

Status = gL4TSupportProtocol->ApplyTegraDeviceTreeOverlay (ExpandedFdtBase, OverlayBuffer, SWModule);
if (gL4TSupportProtocol != NULL) {
Status = gL4TSupportProtocol->ApplyTegraDeviceTreeOverlay (ExpandedFdtBase, OverlayBuffer, SWModule);
} else {
Status = ApplyTegraDeviceTreeOverlay (ExpandedFdtBase, OverlayBuffer, SWModule);
}

if (EFI_ERROR (Status)) {
goto Exit;
}
Expand Down Expand Up @@ -2462,7 +2473,12 @@ GetDeviceHandleForFvBoot (
continue;
}

Status = gL4TSupportProtocol->GetBootDeviceClass (DevicePath, &DeviceClass);
if (gL4TSupportProtocol != NULL) {
Status = gL4TSupportProtocol->GetBootDeviceClass (DevicePath, &DeviceClass);
} else {
Status = GetBootDeviceClass (DevicePath, &DeviceClass);
}

if (EFI_ERROR (Status)) {
continue;
}
Expand Down Expand Up @@ -2514,28 +2530,31 @@ L4TLauncher (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_DEVICE_PATH *FullDevicePath;
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
EFI_STATUS Status;
TEGRA_BOOT_MODE_METADATA BootModeMetaData;
EFI_HANDLE LoadedImageHandle = 0;
EFI_HANDLE RootFsDeviceHandle = 0;
EFI_HANDLE DeviceHandle = 0;
L4T_BOOT_PARAMS BootParams;
EXTLINUX_BOOT_CONFIG ExtLinuxConfig;
UINTN ExtLinuxBootOption;
UINTN Index;
EFI_DEVICE_PATH *FullDevicePath;
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
EFI_STATUS Status;
TEGRA_BOOT_MODE_METADATA BootModeMetaData;
EFI_HANDLE LoadedImageHandle = 0;
EFI_HANDLE RootFsDeviceHandle = 0;
EFI_HANDLE DeviceHandle = 0;
L4T_BOOT_PARAMS BootParams;
EXTLINUX_BOOT_CONFIG ExtLinuxConfig;
UINTN ExtLinuxBootOption;
UINTN Index;
VOID *Hob;
TEGRA_PLATFORM_RESOURCE_INFO *PlatformResourceInfo;

Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&LoadedImage);
if (EFI_ERROR (Status)) {
ErrorPrint (L"%a: Unable to locate loaded image: %r\r\n", __FUNCTION__, Status);
return Status;
}

Status = gBS->LocateProtocol (&gNVIDIAL4TLauncherSupportProtocol, NULL, (VOID **)&gL4TSupportProtocol);
gL4TSupportProtocol = NULL;
Status = gBS->LocateProtocol (&gNVIDIAL4TLauncherSupportProtocol, NULL, (VOID **)&gL4TSupportProtocol);
if (EFI_ERROR (Status)) {
ErrorPrint (L"%a: Unable to locate L4T Support protocol: %r\r\n", __FUNCTION__, Status);
return Status;
ErrorPrint (L"%a: Using legacy interface. Support would be deprecated soon!!!\r\n", __FUNCTION__);
}

Status = ProcessBootParams (LoadedImage, &BootParams);
Expand All @@ -2553,7 +2572,27 @@ L4TLauncher (
}
}

Status = gL4TSupportProtocol->GetBootModeInfo (&BootModeMetaData);
if (gL4TSupportProtocol != NULL) {
Status = gL4TSupportProtocol->GetBootModeInfo (&BootModeMetaData);
} else {
Hob = GetFirstGuidHob (&gNVIDIAPlatformResourceDataGuid);
if ((Hob != NULL) &&
(GET_GUID_HOB_DATA_SIZE (Hob) == sizeof (TEGRA_PLATFORM_RESOURCE_INFO)))
{
PlatformResourceInfo = (TEGRA_PLATFORM_RESOURCE_INFO *)GET_GUID_HOB_DATA (Hob);
BootModeMetaData.BootType = PlatformResourceInfo->BootType;
if (BootModeMetaData.BootType == TegrablBootRcm) {
BootModeMetaData.RcmBootOsInfo.Base = PcdGet64 (PcdRcmKernelBase);
BootModeMetaData.RcmBootOsInfo.Size = PcdGet64 (PcdRcmKernelSize);
}

Status = EFI_SUCCESS;
} else {
ErrorPrint (L"%a: Failed to get PlatformResourceInfo\r\n", __FUNCTION__);
Status = EFI_NOT_FOUND;
}
}

if (EFI_ERROR (Status)) {
return Status;
}
Expand Down
9 changes: 9 additions & 0 deletions Silicon/NVIDIA/Application/L4TLauncher/L4TLauncher.inf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
UefiBootServicesTableLib
UefiApplicationEntryPoint
BaseMemoryLib
HobLib
PcdLib
DebugLib
DevicePathLib
UefiLib
Expand All @@ -43,14 +45,21 @@
UefiRuntimeServicesTableLib
AndroidBootImgLib
SecureBootVariableLib
TegraDeviceTreeKernelOverlayLib
OpteeNvLib
PlatformBootOrderLib

[Guids]
gNVIDIAPublicVariableGuid
gFdtTableGuid
gEfiSecureBootEnableDisableGuid
gNVIDIAPlatformResourceDataGuid
gNVIDIATokenSpaceGuid

[Pcd]
gNVIDIATokenSpaceGuid.PcdRcmKernelBase
gNVIDIATokenSpaceGuid.PcdRcmKernelSize

[Protocols]
gEfiLoadedImageProtocolGuid
gEfiDevicePathProtocolGuid
Expand Down
16 changes: 15 additions & 1 deletion Silicon/NVIDIA/Application/L4TLauncher/L4TOpteeDecrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <Library/MemoryAllocationLib.h>
#include <Library/HandleParsingLib.h>
#include <Library/PrintLib.h>
#include <Library/TegraPlatformInfoLib.h>
#include <Library/OpteeNvLib.h>
#include <Library/FileHandleLib.h>
#include <libfdt_env.h>
Expand Down Expand Up @@ -114,6 +115,7 @@ GetImageEncryptionInfo (
EFI_GUID CPD_TA_UUID = TA_CPUBL_PAYLOAD_DECRYPTION_UUID;
OPTEE_SESSION *OpteeSession = NULL;
UINTN HeaderSize;
UINTN ChipID;

if (!IsOpteePresent ()) {
ErrorPrint (L"%a: optee is not present\r\n", __FUNCTION__);
Expand Down Expand Up @@ -189,7 +191,19 @@ GetImageEncryptionInfo (
if (MessageArg->Params[1].Union.Value.A == 1) {
Info->ImageEncrypted = TRUE;

Status = gL4TSupportProtocol->GetBootComponentHeaderSize (&HeaderSize);
if (gL4TSupportProtocol != NULL) {
Status = gL4TSupportProtocol->GetBootComponentHeaderSize (&HeaderSize);
} else {
ChipID = TegraGetChipID ();
if (ChipID == T194_CHIP_ID) {
HeaderSize = SIZE_4KB;
} else {
HeaderSize = SIZE_8KB;
}

Status = EFI_SUCCESS;
}

if (EFI_ERROR (Status)) {
ErrorPrint (L"%a: Failed to get boot component header size %r\r\n", __FUNCTION__, Status);
goto CloseSession;
Expand Down
35 changes: 30 additions & 5 deletions Silicon/NVIDIA/Application/L4TLauncher/L4TRootfsValidation.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,12 @@ InitializeRootfsStatusReg (
UINT32 MaxRetryCount;
UINT32 RootfsStatus;

Status = gL4TSupportProtocol->GetRootfsStatusReg (&RegisterValue);
if (gL4TSupportProtocol != NULL) {
Status = gL4TSupportProtocol->GetRootfsStatusReg (&RegisterValue);
} else {
Status = GetRootfsStatusReg (&RegisterValue);
}

if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
Expand Down Expand Up @@ -287,7 +292,12 @@ InitializeRootfsStatusReg (
RegisterValue = SR_RF_RETRY_COUNT_B_SET (RetryCount, RegisterValue);

// Write Rootfs Status register
Status = gL4TSupportProtocol->SetRootfsStatusReg (RegisterValue);
if (gL4TSupportProtocol != NULL) {
Status = gL4TSupportProtocol->SetRootfsStatusReg (RegisterValue);
} else {
Status = SetRootfsStatusReg (RegisterValue);
}

if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
Expand Down Expand Up @@ -692,7 +702,12 @@ ValidateRootfsStatus (
// Clear the SR_RF when boot to recovery kernel.
// Slot status can be set to normal via UEFI menu in next boot
// or via OTA.
Status = gL4TSupportProtocol->SetRootfsStatusReg (0x0);
if (gL4TSupportProtocol != NULL) {
Status = gL4TSupportProtocol->SetRootfsStatusReg (0x0);
} else {
Status = SetRootfsStatusReg (0x0);
}

if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
Expand Down Expand Up @@ -846,7 +861,12 @@ ValidateRootfsStatus (
return Status;
}

Status = gL4TSupportProtocol->SetRootfsStatusReg (RegisterValueRf);
if (gL4TSupportProtocol != NULL) {
Status = gL4TSupportProtocol->SetRootfsStatusReg (RegisterValueRf);
} else {
Status = SetRootfsStatusReg (RegisterValueRf);
}

if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
Expand Down Expand Up @@ -875,7 +895,12 @@ ValidateRootfsStatus (
// Trigger a reset to switch the BootChain if the UpdateFlag of BootChainFwNext is 1
if (mRootfsInfo.RootfsVar[RF_FW_NEXT].UpdateFlag) {
// Clear the rootfs status register before issuing a reset
Status = gL4TSupportProtocol->SetRootfsStatusReg (0x0);
if (gL4TSupportProtocol != NULL) {
Status = gL4TSupportProtocol->SetRootfsStatusReg (0x0);
} else {
Status = SetRootfsStatusReg (0x0);
}

if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
Expand Down

0 comments on commit 85becaf

Please sign in to comment.