From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by mx.groups.io with SMTP id smtpd.web11.52972.1683789184098199111 for ; Thu, 11 May 2023 00:13:04 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=xJqt0hig; spf=pass (domain: rivosinc.com, ip: 209.85.214.180, mailfrom: dhaval@rivosinc.com) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1ab0c697c84so63183205ad.3 for ; Thu, 11 May 2023 00:13:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1683789183; x=1686381183; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BRA0tS+RHlcvw6Ja5K+isHoCUMi9ZabCdRuT+HBAURY=; b=xJqt0hig//Sntme5Y1cEwKZHW2dZMUUKxGPasHe2MLi1T27RxD1IXWT+x9OAO+GtvZ kalglgqiXvK61shlv+nttQ3mDRW+FwhUSGSwLfT54Ged73pmtAQ1EFeyyhGln4Rpv4mi fQmNwdlPGXiKLMlw4RGiet3cafwOvLo+l0YK1EI8w+x/5XcK2489X280otqdFgyV71Tr FNDjNhvFF5sYKR1INGfHP9MC4fd2vBUdIGWNAP3VrpJDImj95KsoGqLRtl0WI2Dod4SU bR6sSwKRtw8nwzkG69SNN6/B2IRv9BefMw2+04um2JXbJ63ByKrCMT10kGMD6CHS0CU2 mPCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683789183; x=1686381183; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BRA0tS+RHlcvw6Ja5K+isHoCUMi9ZabCdRuT+HBAURY=; b=WOFNbmm3p09ZzeoP8rrUZK6pYXjguBSLbRBU+vyIAIOa8gEW+Fk5gVxc/kdbFBrF4O 9+qjA1QaI+msDM9cd4y/LLPtJxW/2dONnKmhs/soZ9Tx/OTheyeicriYzAOLscvAYz89 QYPQyCqvZYJSgaOxoFDM24GOz/uZi3BA65cxJ4CuZe9JhVwbYyFZmmrdSGvHktGbM4KB vKHwPRdbYPfZ/ZR42B3su3WUtApp56kS+PXUm35wEwCnfeQrEN/y4RV3jmnwKKMdrm7e 0gu9h5Vph91W+Gx291WUpU/uaeOu2Sc6qiqQCDVH5SdXKl0ujf18+CN8Y1ZujaNWfHuP zcEw== X-Gm-Message-State: AC+VfDwx2v/NdIw/UBA2xuDTHCcnuhKoUOZKJpNRjf1cGGHDfskSYDVg oKYmOpeipPhuIHgVyegr98G9hTJmgO241rh5OUg= X-Google-Smtp-Source: ACHHUZ4FIBA2J4zJWiU/n51+21JxzJBQe6Fa0/5OCpV9yAhBHlvlueX+2CpX3CzV7vljAso7ISQhlQ== X-Received: by 2002:a17:902:e54b:b0:1ac:712d:2032 with SMTP id n11-20020a170902e54b00b001ac712d2032mr17964693plf.50.1683789183437; Thu, 11 May 2023 00:13:03 -0700 (PDT) Return-Path: Received: from dhaval.. ([42.106.13.180]) by smtp.gmail.com with ESMTPSA id w20-20020a1709029a9400b001a9884c02e3sm5111214plp.10.2023.05.11.00.13.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 May 2023 00:13:03 -0700 (PDT) From: "Dhaval Sharma" To: devel@edk2.groups.io Cc: Guo Dong , Ray Ni , Sean Rhodes , James Lu , Gua Guo , Sunil V Subject: [PATCH v1 7/8] UefiPayloadPkg: Find DxeFV and create required FV HOB Date: Thu, 11 May 2023 12:42:25 +0530 Message-Id: <20230511071226.19726-8-dhaval@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230511071226.19726-1-dhaval@rivosinc.com> References: <20230511071226.19726-1-dhaval@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable UPL expects to have Dxe info from gUniversalPayloadExtraDataGuid HOB. With new FDT proposal this requirement should go away. But for now satisfying this requirement through RV hook. Test: Able to enter DxeMain function after finding correct DxeFv. Cc: Guo Dong Cc: Ray Ni Cc: Sean Rhodes Cc: James Lu Cc: Gua Guo Cc: Sunil V Signed-off-by: Dhaval Sharma --- UefiPayloadPkg/UefiPayloadEntry/RiscV64/DxeLoadFunc.c | 46 ++++++ UefiPayloadPkg/UefiPayloadEntry/RiscV64/Rv64FdtParserLib.c | 149 +++++++++= ++++++++++- 2 files changed, 194 insertions(+), 1 deletion(-) diff --git a/UefiPayloadPkg/UefiPayloadEntry/RiscV64/DxeLoadFunc.c b/UefiPa= yloadPkg/UefiPayloadEntry/RiscV64/DxeLoadFunc.c index db44b38cc7c7..ecd249337151 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/RiscV64/DxeLoadFunc.c +++ b/UefiPayloadPkg/UefiPayloadEntry/RiscV64/DxeLoadFunc.c @@ -7,6 +7,16 @@ SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include "UefiPayloadEntry.h"=0D +=0D +#define STACK_SIZE 0x20000=0D =0D /**=0D Transfers control to DxeCore.=0D @@ -25,4 +35,40 @@ HandOffToDxeCore ( IN EFI_PEI_HOB_POINTERS HobList=0D )=0D {=0D + VOID *BaseOfStack;=0D + VOID *TopOfStack;=0D +=0D + //=0D + //=0D + // Allocate 128KB for the Stack=0D + //=0D + BaseOfStack =3D AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE));=0D + if (BaseOfStack =3D=3D NULL) {=0D + DEBUG ((DEBUG_ERROR, "%a: Can't allocate memory for stack.", __func__)= );=0D + ASSERT (FALSE);=0D + }=0D +=0D + //=0D + // Compute the top of the stack we were allocated. Pre-allocate a UINTN= =0D + // for safety.=0D + //=0D + TopOfStack =3D (VOID *)((UINTN)BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SI= ZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);=0D + TopOfStack =3D ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);=0D +=0D + //=0D + // Update the contents of BSP stack HOB to reflect the real stack info p= assed to DxeCore.=0D + //=0D + UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack, STACK_SIZE);=0D +=0D + DEBUG ((DEBUG_INFO, "DXE Core new stack at %x, stack pointer at %x\n", B= aseOfStack, TopOfStack));=0D +=0D + //=0D + // Transfer the control to the entry point of DxeCore.=0D + //=0D + SwitchStack (=0D + (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,=0D + HobList.Raw,=0D + NULL,=0D + TopOfStack=0D + );=0D }=0D diff --git a/UefiPayloadPkg/UefiPayloadEntry/RiscV64/Rv64FdtParserLib.c b/U= efiPayloadPkg/UefiPayloadEntry/RiscV64/Rv64FdtParserLib.c index 7be38bb742f6..b1251a83a236 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/RiscV64/Rv64FdtParserLib.c +++ b/UefiPayloadPkg/UefiPayloadEntry/RiscV64/Rv64FdtParserLib.c @@ -41,6 +41,8 @@ #define E820_DISABLED 6=0D #define E820_PMEM 7=0D #define E820_UNDEFINED 8=0D +#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \=0D + ((ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((= Alignment) - 1)))=0D =0D /**=0D Auto-generated function that calls the library constructors for all of t= he module's=0D @@ -341,6 +343,138 @@ BuildSerialHobFromFDT ( return TRUE;=0D }=0D =0D +/**=0D + This function searchs a given file type with a given Guid within a valid= FV.=0D + If input Guid is NULL, will locate the first section having the given fi= le type=0D +=0D + @param FvHeader A pointer to firmware volume header that contains= the set of files=0D + to be searched.=0D + @param FileType File type to be searched.=0D + @param Guid Will ignore if it is NULL.=0D + @param FileHeader A pointer to the discovered file, if successful.= =0D +=0D + @retval EFI_SUCCESS Successfully found FileType=0D + @retval EFI_NOT_FOUND File type can't be found.=0D +**/=0D +STATIC EFI_STATUS=0D +FvFindFileByTypeGuid (=0D + IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader,=0D + IN EFI_FV_FILETYPE FileType,=0D + IN EFI_GUID *Guid OPTIONAL,=0D + OUT EFI_FFS_FILE_HEADER **FileHeader=0D + )=0D +{=0D + EFI_PHYSICAL_ADDRESS CurrentAddress;=0D + EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume;=0D + EFI_FFS_FILE_HEADER *File;=0D + UINT32 Size;=0D + EFI_PHYSICAL_ADDRESS EndOfFile;=0D +=0D + CurrentAddress =3D (EFI_PHYSICAL_ADDRESS)(UINTN)FvHeader;=0D + EndOfFirmwareVolume =3D CurrentAddress + FvHeader->FvLength;=0D +=0D + //=0D + // Loop through the FFS files=0D + //=0D + for (EndOfFile =3D CurrentAddress + FvHeader->HeaderLength; ; ) {=0D + CurrentAddress =3D (EndOfFile + 7) & 0xfffffffffffffff8ULL;=0D + if (CurrentAddress > EndOfFirmwareVolume) {=0D + break;=0D + }=0D +=0D + File =3D (EFI_FFS_FILE_HEADER *)(UINTN)CurrentAddress;=0D + if (IS_FFS_FILE2 (File)) {=0D + Size =3D FFS_FILE2_SIZE (File);=0D + if (Size <=3D 0x00FFFFFF) {=0D + break;=0D + }=0D + } else {=0D + Size =3D FFS_FILE_SIZE (File);=0D + if (Size < sizeof (EFI_FFS_FILE_HEADER)) {=0D + break;=0D + }=0D + }=0D +=0D + EndOfFile =3D CurrentAddress + Size;=0D + if (EndOfFile > EndOfFirmwareVolume) {=0D + break;=0D + }=0D +=0D + //=0D + // Look for file type=0D + //=0D + if (File->Type =3D=3D FileType) {=0D + if ((Guid =3D=3D NULL) || CompareGuid (&File->Name, Guid)) {=0D + *FileHeader =3D File;=0D + return EFI_SUCCESS;=0D + }=0D + }=0D + }=0D +=0D + return EFI_NOT_FOUND;=0D +}=0D +=0D +/**=0D + This function searchs a given section type within a valid FFS file.=0D +=0D + @param FileHeader A pointer to the file header that contains= the set of sections to=0D + be searched.=0D + @param SectionType The value of the section type to search.= =0D + @param SectionData A pointer to the discovered section, if su= ccessful.=0D +=0D + @retval EFI_SUCCESS The section was found.=0D + @retval EFI_NOT_FOUND The section was not found.=0D +=0D +**/=0D +STATIC EFI_STATUS=0D +FileFindSection (=0D + IN EFI_FFS_FILE_HEADER *FileHeader,=0D + IN EFI_SECTION_TYPE SectionType,=0D + OUT VOID **SectionData=0D + )=0D +{=0D + UINT32 FileSize;=0D + EFI_COMMON_SECTION_HEADER *Section;=0D + UINT32 SectionSize;=0D + UINT32 Index;=0D +=0D + if (IS_FFS_FILE2 (FileHeader)) {=0D + FileSize =3D FFS_FILE2_SIZE (FileHeader);=0D + } else {=0D + FileSize =3D FFS_FILE_SIZE (FileHeader);=0D + }=0D +=0D + FileSize -=3D sizeof (EFI_FFS_FILE_HEADER);=0D +=0D + Section =3D (EFI_COMMON_SECTION_HEADER *)(FileHeader + 1);=0D + Index =3D 0;=0D + while (Index < FileSize) {=0D + if (Section->Type =3D=3D SectionType) {=0D + if (IS_SECTION2 (Section)) {=0D + *SectionData =3D (VOID *)((UINT8 *)Section + sizeof (EFI_COMMON_SE= CTION_HEADER2));=0D + } else {=0D + *SectionData =3D (VOID *)((UINT8 *)Section + sizeof (EFI_COMMON_SE= CTION_HEADER));=0D + }=0D +=0D + return EFI_SUCCESS;=0D + }=0D +=0D + if (IS_SECTION2 (Section)) {=0D + SectionSize =3D SECTION2_SIZE (Section);=0D + } else {=0D + SectionSize =3D SECTION_SIZE (Section);=0D + }=0D +=0D + SectionSize =3D GET_OCCUPIED_SIZE (SectionSize, 4);=0D + ASSERT (SectionSize !=3D 0);=0D + Index +=3D SectionSize;=0D +=0D + Section =3D (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + SectionSi= ze);=0D + }=0D +=0D + return EFI_NOT_FOUND;=0D +}=0D +=0D EFI_STATUS=0D BuildBlHobs (=0D IN UINTN Param1,=0D @@ -437,7 +571,20 @@ BuildBlHobs ( ASSERT (AcpiBoardInfo !=3D NULL);=0D }=0D =0D - *DxeFv =3D (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdPayloadFdMe= mBase);=0D + DxeCoreFv =3D (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdPayloadF= dMemBase);=0D +=0D + Status =3D FvFindFileByTypeGuid (DxeCoreFv, 0x0B, ((void *)0), &FileHead= er);=0D + if ((((INTN)(RETURN_STATUS)(Status)) < 0)) {=0D + return Status;=0D + }=0D +=0D + Status =3D FileFindSection (FileHeader, 0x17, (void **)DxeFv);=0D + if ((((INTN)(RETURN_STATUS)(Status)) < 0)) {=0D + return Status;=0D + }=0D +=0D + BuildFvHob ((EFI_PHYSICAL_ADDRESS)(UINTN)DxeCoreFv, DxeCoreFv->FvLength)= ;=0D +=0D return EFI_SUCCESS;=0D }=0D =0D --=20 2.34.1