From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: hpe.com, ip: 148.163.143.35, mailfrom: prvs=0143f30469=abner.chang@hpe.com) Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by groups.io with SMTP; Wed, 28 Aug 2019 01:43:14 -0700 Received: from pps.filterd (m0148664.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x7S8feXn013807; Wed, 28 Aug 2019 08:43:13 GMT Received: from g2t2353.austin.hpe.com (g2t2353.austin.hpe.com [15.233.44.26]) by mx0b-002e3701.pphosted.com with ESMTP id 2un4qhqc3f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Aug 2019 08:43:13 +0000 Received: from G1W8106.americas.hpqcorp.net (g1w8106.austin.hp.com [16.193.72.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by g2t2353.austin.hpe.com (Postfix) with ESMTPS id B216B82; Wed, 28 Aug 2019 08:43:12 +0000 (UTC) Received: from G9W8671.americas.hpqcorp.net (16.220.49.30) by G1W8106.americas.hpqcorp.net (16.193.72.61) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 28 Aug 2019 08:43:12 +0000 Received: from G2W6311.americas.hpqcorp.net (16.197.64.53) by G9W8671.americas.hpqcorp.net (16.220.49.30) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 28 Aug 2019 08:43:12 +0000 Received: from NAM03-BY2-obe.outbound.protection.outlook.com (15.241.52.11) by G2W6311.americas.hpqcorp.net (16.197.64.53) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Wed, 28 Aug 2019 08:43:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WnOZg/E0uRVx0ec3cl9vhyDt72/sAlKDr2kOVfWyoILh1e5a9d0seL0FLt4oJAeZkKwhAIz+ciIaBYCaYGta0VEMWumfpwf66LdHaxyKmDcS4czzLev7ghLerUwMYtG9kR+MfIsl/PDpWcOUjTPUEsLLegMNGEWAKUx4dspKdIpPt8dKCo11I/LcENT7tZFsugVpvBXjnQNY1/1SI5cRvdfaeO8Bua+KElBvv5ZGLVopXmWmusdNBzZ6f3lH2yMGyo8YqzZfQc0rkJt+ul2vtwFmn6K50xJBEMTHlTmYFrzthe625UotXunoqvDjF07KuIJR+2U2oHdjBwb30Ez0Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ppez2hYX2YxZx4Ev0DE/wkDqz6UY2g+SvGvq1YathSU=; b=CdJ73ZNkZoH6krT7EQt8d6wKnyhbQOcCTEKrxWWsaWAzD7onrZDxSr0U0bAbLllP0Gw8EMaQ6lT07nNIyMZUVnvaBbZ5EEYT3nH4ZSJ+O+JfQPonJMpwhaWurrjPgND0NlK3EercuLtVyPRfM0RMGri9fywvweLpjJUbPgEOD2eLPRY7Z4aP45b31GyZueUoBC3gGYsqF2Vlrlm8UsC8ZNNdKKtB7aHZ9ZEWXF7peXOXJeO7vPqeaL9Ws77p9OaZd/tKDB613wAtO6+s5+q5zXtOoZMWfbATgsF9m92xY6PlEcGcAE8GkD//j2CVHL9kBwJahHgP9ZaS5Gq73oR/Xw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hpe.com; dmarc=pass action=none header.from=hpe.com; dkim=pass header.d=hpe.com; arc=none Received: from CS1PR8401MB1192.NAMPRD84.PROD.OUTLOOK.COM (10.169.12.151) by CS1PR8401MB0373.NAMPRD84.PROD.OUTLOOK.COM (10.169.14.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Wed, 28 Aug 2019 08:43:10 +0000 Received: from CS1PR8401MB1192.NAMPRD84.PROD.OUTLOOK.COM ([fe80::9f7:2009:ab0f:983a]) by CS1PR8401MB1192.NAMPRD84.PROD.OUTLOOK.COM ([fe80::9f7:2009:ab0f:983a%11]) with mapi id 15.20.2220.013; Wed, 28 Aug 2019 08:43:10 +0000 From: "Abner Chang" To: Jonathan Cameron CC: "devel@edk2.groups.io" Subject: Re: [edk2-devel] [edk2-staging/RISC-V PATCH v1 1/14]: BaseTools: Update EDK2 build tool for RISC-V platform Thread-Topic: [edk2-devel] [edk2-staging/RISC-V PATCH v1 1/14]: BaseTools: Update EDK2 build tool for RISC-V platform Thread-Index: AQHVXXkt7kZEYNGgmkOz0OuAw5v0vKcQPfiw Date: Wed, 28 Aug 2019 08:43:10 +0000 Message-ID: References: <1566885632-5747-1-git-send-email-abner.chang@hpe.com> <20190828091756.00004ffc@huawei.com> In-Reply-To: <20190828091756.00004ffc@huawei.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [16.242.247.131] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 2485b1ec-3ba1-4e95-8326-08d72b93c19b x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020);SRVR:CS1PR8401MB0373; x-ms-traffictypediagnostic: CS1PR8401MB0373: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 014304E855 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(136003)(396003)(39860400002)(366004)(346002)(376002)(13464003)(189003)(199004)(102836004)(66476007)(66556008)(4326008)(256004)(53946003)(19627235002)(86362001)(76116006)(14444005)(25786009)(5660300002)(66446008)(64756008)(66946007)(52536014)(478600001)(9686003)(229853002)(53936002)(6246003)(316002)(71190400001)(66066001)(71200400001)(30864003)(8676002)(8936002)(33656002)(446003)(11346002)(6116002)(14454004)(7696005)(76176011)(2906002)(15650500001)(486006)(6916009)(55016002)(186003)(81166006)(99286004)(3846002)(7736002)(305945005)(6436002)(53546011)(6506007)(26005)(81156014)(476003)(74316002)(579004);DIR:OUT;SFP:1102;SCL:1;SRVR:CS1PR8401MB0373;H:CS1PR8401MB1192.NAMPRD84.PROD.OUTLOOK.COM;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: hpe.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: mHqyie2AtQ90gPJkKH9ii50tm2ZjcOi9s3TqwxhMXKpfh6Yum3hLQdOa4Dho2XHgrk1jONGTb5E6ZmaZHX1M0GJ6UOjZBpX8EgNPkmAonTgIyoUJil4aSIdBx/3h1EdW7ncgwtWv/QCOFZEt9F2XKtCqv8f7o413/grLZ+2f7qcSLHJhe/OCaKcApGV0YjwjuMb2to8nt984e9aQvOn0tPY+jEtJD0tZL4dueZJ27z9/csV7GtTJqcppRZGtaQShlkNywN/4pRDBCXM/kVyoukVjsB46Rsm8cWWopEXR8ojERTB8YJ8nwC0NWLX2xWyituQRI7HMbYs9fWWOUKNHfOCiMkXoN2V1fhJ93ooafrvO/PqrzAgj4RiqbXmpytWeBlXK+d7h4GbCegyaLI1TcQ6ssaOucLuisZqnijU/LHo= x-ms-exchange-transport-forked: True X-MS-Exchange-CrossTenant-Network-Message-Id: 2485b1ec-3ba1-4e95-8326-08d72b93c19b X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Aug 2019 08:43:10.3596 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: /Lkzsj5dA993bcK2levbkOC70gntXSu+KeS0RqzadvS82QMg8Bz6LajD8WuES8XBfra49WL4jEYgUBe9mYfv+g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CS1PR8401MB0373 X-OriginatorOrg: hpe.com X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:5.22.84,1.0.8 definitions=2019-08-28_03:2019-08-27,2019-08-28 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxlogscore=999 impostorscore=0 bulkscore=0 phishscore=0 priorityscore=1501 suspectscore=0 clxscore=1011 spamscore=0 mlxscore=0 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1906280000 definitions=main-1908280092 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thanks Jonathan, the cover letter and 3/14 patch were just sent. Abner > -----Original Message----- > From: Jonathan Cameron [mailto:jonathan.cameron@huawei.com] > Sent: Wednesday, August 28, 2019 4:18 PM > To: Chang, Abner (HPS SW/FW Technologist) > Cc: devel@edk2.groups.io > Subject: Re: [edk2-devel] [edk2-staging/RISC-V PATCH v1 1/14]: BaseTools: > Update EDK2 build tool for RISC-V platform >=20 > Hi Abner, >=20 > Just noticed in passing that this series doesn't seem to have a 3/14? >=20 > Speaking personally it would be useful to have a cover letter with a quick > summary of the series content. >=20 > Thanks, >=20 > Jonathan >=20 > On Tue, 27 Aug 2019 14:00:19 +0800 > Abner Chang wrote: >=20 > > Elf64Convert.c > > - Relocation process to hadnle below opcodes, > > * PCRELHI20 > > * PCRELLO12 > > * ADD32 > > * SUB32 > > > > GenFvInternalLib.c > > - This atches jump instrcution at the position of first instrcution fet= ched by > RISC-V processor after Zeroth Stage Boot Loader (ZSBL). > > > > Contributed-under: TianoCore Contribution Agreement 1.0 > > Signed-off-by: Abner Chang > > --- > > BaseTools/Source/C/GenFv/GenFvInternalLib.c | 311 ++++++++++++------ > ---------- > > BaseTools/Source/C/GenFw/Elf64Convert.c | 68 ++++++ > > 2 files changed, 197 insertions(+), 182 deletions(-) > > > > diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.c > > b/BaseTools/Source/C/GenFv/GenFvInternalLib.c > > index 01da00c..92abb7c 100644 > > --- a/BaseTools/Source/C/GenFv/GenFvInternalLib.c > > +++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.c > > @@ -1956,157 +1956,6 @@ Returns: > > return EFI_UNSUPPORTED; > > } > > > > -EFI_STATUS > > -UpdateRiscvResetVectorIfNeeded ( > > - MEMORY_FILE *FvImage, > > - FV_INFO *FvInfo, > > - EFI_FFS_FILE_HEADER *VtfFileImage > > - ) > > -/*++ > > - > > -Routine Description: > > - This parses the FV looking for SEC and patches that address into > > the > > - beginning of the FV header. > > - > > - For RISC-V ISA, the reset vector is at 0xfff~ff00h or 200h > > - > > -Arguments: > > - FvImage Memory file for the FV memory image/ > > - FvInfo Information read from INF file. > > - VtfFileImage Instance of VTF file. > > - > > -Returns: > > - > > - EFI_SUCCESS Function Completed successfully. > > - EFI_ABORTED Error encountered. > > - EFI_INVALID_PARAMETER A required parameter was NULL. > > - EFI_NOT_FOUND PEI Core file not found. > > - > > ---*/ > > -{ > > - EFI_FFS_FILE_HEADER *PeiCoreFile; > > - EFI_FFS_FILE_HEADER *SecCoreFile; > > - EFI_STATUS Status; > > - EFI_FILE_SECTION_POINTER Pe32Section; > > - UINT32 EntryPoint; > > - UINT32 BaseOfCode; > > - UINT16 MachineType; > > - EFI_PHYSICAL_ADDRESS PeiCorePhysicalAddress; > > - EFI_PHYSICAL_ADDRESS SecCorePhysicalAddress; > > - EFI_PHYSICAL_ADDRESS TrapAddress; > > - > > - // > > - // Verify input parameters > > - // > > - if (FvImage =3D=3D NULL || FvInfo =3D=3D NULL) { > > - Error (NULL, 0, 3000, "Invalid", "FvImage or FvInfo is NULL"); > > - return EFI_INVALID_PARAMETER; > > - } > > - // > > - // Initialize FV library > > - // > > - InitializeFvLib (FvImage->FileImage, FvInfo->Size); > > - > > - // > > - // Find the Sec Core > > - // > > - Status =3D GetFileByType (EFI_FV_FILETYPE_SECURITY_CORE, 1, > > &SecCoreFile); > > - if (EFI_ERROR (Status) || SecCoreFile =3D=3D NULL) { > > - // > > - // Maybe hardware does SEC job and we only have PEI Core? > > - // > > - > > - // > > - // Find the PEI Core. It may not exist if SEC loads DXE core direc= tly > > - // > > - PeiCorePhysicalAddress =3D 0; > > - Status =3D GetFileByType (EFI_FV_FILETYPE_PEI_CORE, 1, &PeiCoreFil= e); > > - if (!EFI_ERROR(Status) && PeiCoreFile !=3D NULL) { > > - // > > - // PEI Core found, now find PE32 or TE section > > - // > > - Status =3D GetSectionByType (PeiCoreFile, EFI_SECTION_PE32, 1, > &Pe32Section); > > - if (Status =3D=3D EFI_NOT_FOUND) { > > - Status =3D GetSectionByType (PeiCoreFile, EFI_SECTION_TE, 1, > &Pe32Section); > > - } > > - > > - if (EFI_ERROR (Status)) { > > - Error (NULL, 0, 3000, "Invalid", "could not find either a PE32= or a TE > section in PEI core file!"); > > - return EFI_ABORTED; > > - } > > - > > - Status =3D GetPe32Info ( > > - (VOID *) ((UINTN) Pe32Section.Pe32Section + > GetSectionHeaderLength(Pe32Section.CommonHeader)), > > - &EntryPoint, > > - &BaseOfCode, > > - &MachineType > > - ); > > - > > - if (EFI_ERROR (Status)) { > > - Error (NULL, 0, 3000, "Invalid", "could not get the PE32 entry= point for > the PEI core!"); > > - return EFI_ABORTED; > > - } > > - // > > - // Physical address is FV base + offset of PE32 + offset of the = entry > point > > - // > > - PeiCorePhysicalAddress =3D FvInfo->BaseAddress; > > - PeiCorePhysicalAddress +=3D (UINTN) Pe32Section.Pe32Section + > GetSectionHeaderLength(Pe32Section.CommonHeader) - (UINTN) FvImage- > >FileImage; > > - PeiCorePhysicalAddress +=3D EntryPoint; > > - DebugMsg (NULL, 0, 9, "PeiCore physical entry point address", > "Address =3D 0x%llX", (unsigned long long) PeiCorePhysicalAddress); > > - RiscvPatchVtf (VtfFileImage, (UINT32)PeiCorePhysicalAddress); > > - } > > - return EFI_SUCCESS; > > - } > > - > > - // > > - // Sec Core found, now find PE32 section > > - // > > - Status =3D GetSectionByType (SecCoreFile, EFI_SECTION_PE32, 1, > > &Pe32Section); > > - if (Status =3D=3D EFI_NOT_FOUND) { > > - Status =3D GetSectionByType (SecCoreFile, EFI_SECTION_TE, 1, > &Pe32Section); > > - } > > - > > - if (EFI_ERROR (Status)) { > > - Error (NULL, 0, 3000, "Invalid", "could not find a PE32 section in= the SEC > core file."); > > - return EFI_ABORTED; > > - } > > - > > - Status =3D GetPe32Info ( > > - (VOID *) ((UINTN) Pe32Section.Pe32Section + > GetSectionHeaderLength(Pe32Section.CommonHeader)), > > - &EntryPoint, > > - &BaseOfCode, > > - &MachineType > > - ); > > - if (EFI_ERROR (Status)) { > > - Error (NULL, 0, 3000, "Invalid", "could not get the PE32 entry poi= nt for > the SEC core."); > > - return EFI_ABORTED; > > - } > > - > > - if ((MachineType !=3D EFI_IMAGE_MACHINE_RISCV32) && > (MachineType !=3D EFI_IMAGE_MACHINE_RISCV64)) { > > - // > > - // If SEC is not RISC-V we have nothing to do > > - // > > - return EFI_SUCCESS; > > - } > > - > > - // > > - // Physical address is FV base + offset of PE32 + offset of the > > entry point > > - // > > - SecCorePhysicalAddress =3D FvInfo->BaseAddress; > > - SecCorePhysicalAddress +=3D (UINTN) Pe32Section.Pe32Section + > > GetSectionHeaderLength(Pe32Section.CommonHeader) - (UINTN) > > FvImage->FileImage; > > - SecCorePhysicalAddress +=3D EntryPoint; > > - DebugMsg (NULL, 0, 0x14, "SecCore physical entry point address", > > "Address =3D 0x%llX", (unsigned long long) SecCorePhysicalAddress); > > - RiscvPatchVtf (VtfFileImage, (UINT32)SecCorePhysicalAddress); > > - // > > - // Update RISC-V trap handler. > > - // > > - TrapAddress =3D (UINTN) Pe32Section.Pe32Section + > > GetSectionHeaderLength(Pe32Section.CommonHeader) + EntryPoint; > > - TrapAddress -=3D 40; > > - RiscvPatchVtfTrapHandler (VtfFileImage, TrapAddress); > > - > > - DebugMsg (NULL, 0, 9, "Update Reset vector in FV Header", NULL); > > - return EFI_SUCCESS; > > -} > > > > EFI_STATUS > > FindCorePeSection( > > @@ -2581,6 +2430,106 @@ Returns: > > } > > > > EFI_STATUS > > +UpdateRiscvResetVectorIfNeeded ( > > + MEMORY_FILE *FvImage, > > + FV_INFO *FvInfo > > + ) > > +/*++ > > + > > +Routine Description: > > + This parses the FV looking for SEC and patches that address into > > +the > > + beginning of the FV header. > > + > > + For RISC-V ISA, the reset vector is at 0xfff~ff00h or 200h > > + > > +Arguments: > > + FvImage Memory file for the FV memory image/ > > + FvInfo Information read from INF file. > > + > > +Returns: > > + > > + EFI_SUCCESS Function Completed successfully. > > + EFI_ABORTED Error encountered. > > + EFI_INVALID_PARAMETER A required parameter was NULL. > > + EFI_NOT_FOUND PEI Core file not found. > > + > > +--*/ > > +{ > > + EFI_STATUS Status; > > + UINT16 MachineType; > > + EFI_FILE_SECTION_POINTER SecPe32; > > + EFI_PHYSICAL_ADDRESS SecCoreEntryAddress; > > + > > + UINT32 bSecCore; > > + UINT32 tmp; > > + > > + > > + // > > + // Verify input parameters > > + // > > + if (FvImage =3D=3D NULL || FvInfo =3D=3D NULL) { > > + return EFI_INVALID_PARAMETER; > > + } > > + // > > + // Initialize FV library > > + // > > + InitializeFvLib (FvImage->FileImage, FvInfo->Size); > > + > > + // > > + // Find the Sec Core > > + // > > + Status =3D FindCorePeSection(FvImage->FileImage, FvInfo->Size, > > + EFI_FV_FILETYPE_SECURITY_CORE, &SecPe32); > > + if(EFI_ERROR(Status)) { > > + printf("skip because Secutiry Core not found\n"); > > + return EFI_SUCCESS; > > + } > > + > > + DebugMsg (NULL, 0, 9, "Update SEC core in FV Header", NULL); > > + > > + Status =3D GetCoreMachineType(SecPe32, &MachineType); > > + if(EFI_ERROR(Status)) { > > + Error(NULL, 0, 3000, "Invalid", "Could not get the PE32 machine ty= pe for > SEC core."); > > + return EFI_ABORTED; > > + } > > + > > + if ((MachineType !=3D EFI_IMAGE_MACHINE_RISCV32) && > (MachineType !=3D EFI_IMAGE_MACHINE_RISCV64)) { > > + Error(NULL, 0, 3000, "Invalid", "Could not update SEC core because > Machine type is not RiscV."); > > + return EFI_ABORTED; > > + } > > + > > + Status =3D GetCoreEntryPointAddress(FvImage->FileImage, FvInfo, > > + SecPe32, &SecCoreEntryAddress); > > + if(EFI_ERROR(Status)) { > > + Error(NULL, 0, 3000, "Invalid", "Could not get the PE32 entry point > address for SEC Core."); > > + return EFI_ABORTED; > > + } > > + > > + VerboseMsg("SecCore entry point Address =3D 0x%llX", (unsigned long > > + long) SecCoreEntryAddress); VerboseMsg("BaseAddress =3D 0x%llX", > > + (unsigned long long) FvInfo->BaseAddress); bSecCore =3D > > + (SecCoreEntryAddress - FvInfo->BaseAddress); VerboseMsg("offset =3D > > + 0x%llX", bSecCore); > > + > > + if(bSecCore > 0x0fffff) { > > + Error(NULL, 0, 3000, "Invalid", "SEC Entry point must be within 1M= B of > start of the FV"); > > + return EFI_ABORTED; > > + } > > + > > + tmp =3D bSecCore; > > + bSecCore =3D 0; > > + //J-type > > + bSecCore =3D (tmp&0x100000)<<11; //imm[20] at bit[31] > > + bSecCore |=3D (tmp&0x0007FE)<<20; //imm[10:1] at bit[30:21] > > + bSecCore |=3D (tmp&0x000800)<<9; //imm[11] at bit[20] > > + bSecCore |=3D (tmp&0x0FF000); //imm[19:12] at bit[19:12] > > + bSecCore |=3D 0x6F; //JAL opcode > > + > > + memcpy(FvImage->FileImage, &bSecCore, sizeof(bSecCore)); > > + > > + return EFI_SUCCESS; > > +} > > + > > + > > + > > +EFI_STATUS > > GetPe32Info ( > > IN UINT8 *Pe32, > > OUT UINT32 *EntryPoint, > > @@ -3037,7 +2986,6 @@ Returns: > > FvHeader->Checksum =3D 0; > > FvHeader->Checksum =3D CalculateChecksum16 ((UINT16 *) FvHead= er, > FvHeader->HeaderLength / sizeof (UINT16)); > > } > > - > > // > > // Add files to FV > > // > > @@ -3069,39 +3017,22 @@ Returns: > > goto Finish; > > } > > > > - if (mRiscV) { > > + if (!mArm && !mRiscV) { > > // > > - // Update RISCV reset vector. > > + // Update reset vector (SALE_ENTRY for IPF) > > + // Now for IA32 and IA64 platform, the fv which has bsf file mus= t have > the > > + // EndAddress of 0xFFFFFFFF. Thus, only this type fv needs to up= date > the > > + // reset vector. If the PEI Core is found, the VTF file will pro= bably get > > + // corrupted by updating the entry point. > > // > > - DebugMsg (NULL, 0, INFO_LOG_LEVEL, "Update RISCV reset vector", > NULL); > > - Status =3D UpdateRiscvResetVectorIfNeeded (&FvImageMemoryFile, > &mFvDataInfo, VtfFileImage); > > - if (EFI_ERROR (Status)) { > > - Error (NULL, 0, 3000, "Invalid", "Could not update the reset= vector for > RISC-V."); > > + if ((mFvDataInfo.BaseAddress + mFvDataInfo.Size) =3D=3D > FV_IMAGES_TOP_ADDRESS) { > > + Status =3D UpdateResetVector (&FvImageMemoryFile, &mFvDataInfo, > VtfFileImage); > > + if (EFI_ERROR(Status)) { > > + Error (NULL, 0, 3000, "Invalid", "Could not update the > > + reset vector."); > > goto Finish; > > - } > > - // > > - // Update Checksum for FvHeader > > - // > > - FvHeader->Checksum =3D 0; > > - FvHeader->Checksum =3D CalculateChecksum16 ((UINT16 *) FvHeader, > FvHeader->HeaderLength / sizeof (UINT16)); > > - } else { > > - if (!mArm) { > > - // > > - // Update reset vector (SALE_ENTRY for IPF) > > - // Now for IA32 and IA64 platform, the fv which has bsf file= must have > the > > - // EndAddress of 0xFFFFFFFF. Thus, only this type fv needs t= o update > the > > - // reset vector. If the PEI Core is found, the VTF file will= probably get > > - // corrupted by updating the entry point. > > - // > > - if ((mFvDataInfo.BaseAddress + mFvDataInfo.Size) =3D=3D > FV_IMAGES_TOP_ADDRESS) { > > - Status =3D UpdateResetVector (&FvImageMemoryFile, &mFvData= Info, > VtfFileImage); > > - if (EFI_ERROR(Status)) { > > - Error (NULL, 0, 3000, "Invalid", "Could not update the r= eset > vector."); > > - goto Finish; > > - } > > - DebugMsg (NULL, 0, 9, "Update Reset vector in VTF file", N= ULL); > > - } > > } > > + DebugMsg (NULL, 0, 9, "Update Reset vector in VTF file", NULL); > > + } > > } > > } > > > > @@ -3119,6 +3050,22 @@ Returns: > > FvHeader->Checksum =3D CalculateChecksum16 ((UINT16 *) FvHeader, > FvHeader->HeaderLength / sizeof (UINT16)); > > } > > > > + if (mRiscV) { > > + // > > + // Update RISCV reset vector. > > + // > > + Status =3D UpdateRiscvResetVectorIfNeeded (&FvImageMemoryFile, > &mFvDataInfo); > > + if (EFI_ERROR (Status)) { > > + Error (NULL, 0, 3000, "Invalid", "Could not update the reset ve= ctor for > RISC-V."); > > + goto Finish; > > + } > > + // > > + // Update Checksum for FvHeader > > + // > > + FvHeader->Checksum =3D 0; > > + FvHeader->Checksum =3D CalculateChecksum16 ((UINT16 *) FvHeader, > > + FvHeader->HeaderLength / sizeof (UINT16)); } > > + > > // > > // Update FV Alignment attribute to the largest alignment of all the= FFS > files in the FV > > // > > @@ -3853,7 +3800,7 @@ Returns: > > ImageContext.DestinationAddress =3D NewPe32BaseAddress; > > Status =3D PeCoffLoaderRelocateImage (&Im= ageContext); > > if (EFI_ERROR (Status)) { > > - Error (NULL, 0, 3000, "Invalid", "RelocateImage() call failed on= rebase of > %s", FileName); > > + Error (NULL, 0, 3000, "Invalid", "RelocateImage() call failed > > + on rebase of %s Status=3D%d", FileName, Status); > > free ((VOID *) MemoryImagePointer); > > return Status; > > } > > diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c > > b/BaseTools/Source/C/GenFw/Elf64Convert.c > > index 4857485..77b4d53 100644 > > --- a/BaseTools/Source/C/GenFw/Elf64Convert.c > > +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c > > @@ -946,8 +946,60 @@ WriteSections64 ( > > RiscvSymSecIndex =3D 0; > > break; > > > > + case R_RISCV_PCREL_HI20: > > + RiscvHi20Targ =3D Targ; > > + RiscvHi20Sym =3D SymShdr; > > + RiscvSymSecIndex =3D Sym->st_shndx; > > + > > + Value =3D (UINT32)(RV_X(*(UINT32 *)RiscvHi20Targ, 12, 20)); > > + printf("PCREL_HI20 Sym:[%s] value:0x%x SymShdr->sh_addr:0x= %lx > mCoffSectionOffset:%x \n", GetSymName(Sym), Value, SymShdr->sh_addr, > mCoffSectionsOffset[Sym->st_shndx]); > > + break; > > + case R_RISCV_PCREL_LO12_I: > > + if (RiscvHi20Targ !=3D NULL && RiscvHi20Sym !=3D NULL && > RiscvSymSecIndex !=3D 0) { > > + int i; > > + Value2 =3D (UINT32)(RV_X(*(UINT32 *)RiscvHi20Targ, 12, 2= 0)); > > + Value =3D (UINT32)(RV_X(*(UINT32 *)Targ, 20, 12)); > > + if(Value & (RISCV_IMM_REACH/2)) { > > + Value |=3D ~(RISCV_IMM_REACH-1); > > + } > > + printf("PCREL_LO12_I Sym:[%s] value:0x%x SymShdr- > >sh_addr:0x%lx mCoffSectionOffset:%x \n", GetSymName(Sym), Value, > SymShdr->sh_addr, mCoffSectionsOffset[Sym->st_shndx]); > > + Value =3D Value - RiscvHi20Sym->sh_addr + > mCoffSectionsOffset[RiscvSymSecIndex]; > > + if(-2048 > (INT32)Value) { > > + i =3D (-Value / 4096); > > + //Error (NULL, 0, 3000, "Invalid", "WriteSections64(): > PCREL_LO12_I relocation out of range. %d i=3D%d", Value, i); > > + printf("WriteSections64(): PCREL_LO12_I relocation out= of range. > Value:%d Value2:%d i=3D%d\n", Value, Value2, i); > > + Value2 -=3D i; > > + Value +=3D 4096 * i; > > + if(-2048 > (INT32)Value) { > > + Value2 -=3D 1; > > + Value +=3D 4096; > > + } > > + } > > + else if( 2047 < (INT32)Value) { > > + i =3D (Value / 4096); > > + //Error (NULL, 0, 3000, "Invalid", "WriteSections64(): > PCREL_LO12_I relocation out of range. %d i=3D%d", Value, i); > > + printf("WriteSections64(): PCREL_LO12_I relocation out= of range. > Value:%d Value2:%d i=3D%d\n", Value, Value2, i); > > + Value2 +=3D i; > > + Value -=3D 4096 * i; > > + if(2047 < (INT32)Value) { > > + Value2 +=3D 1; > > + Value -=3D 4096; > > + } > > + } > > + > > + *(UINT32 *)Targ =3D (RV_X(Value, 0, 12) << 20) | > (RV_X(*(UINT32*)Targ, 0, 20)); > > + *(UINT32 *)RiscvHi20Targ =3D (RV_X(Value2, 0, 20)<<12) | > (RV_X(*(UINT32 *)RiscvHi20Targ, 0, 12)); > > + printf("PCREL_LO12_I Sym:[%s] relocated value:0x%x(%d) > value2:0x%x(%d) SymShdr->sh_addr:0x%lx mCoffSectionOffset:%x \n", > GetSymName(Sym), Value, Value, Value2, Value2, SymShdr->sh_addr, > mCoffSectionsOffset[Sym->st_shndx]); > > + } > > + RiscvHi20Sym =3D NULL; > > + RiscvHi20Targ =3D NULL; > > + RiscvSymSecIndex =3D 0; > > + break; > > + > > case R_RISCV_ADD64: > > case R_RISCV_SUB64: > > + case R_RISCV_ADD32: > > + case R_RISCV_SUB32: > > case R_RISCV_BRANCH: > > case R_RISCV_JAL: > > case R_RISCV_GPREL_I: > > @@ -1120,6 +1172,20 @@ WriteRelocations64 ( > > EFI_IMAGE_REL_BASED_ABSOLUTE); > > break; > > > > + case R_RISCV_ADD32: > > + CoffAddFixup( > > + (UINT32) ((UINT64) mCoffSectionsOffset[RelShdr->sh_inf= o] > > + + (Rel->r_offset - SecShdr->sh_addr)), > > + EFI_IMAGE_REL_BASED_ABSOLUTE); > > + break; > > + > > + case R_RISCV_SUB32: > > + CoffAddFixup( > > + (UINT32) ((UINT64) mCoffSectionsOffset[RelShdr->sh_inf= o] > > + + (Rel->r_offset - SecShdr->sh_addr)), > > + EFI_IMAGE_REL_BASED_ABSOLUTE); > > + break; > > + > > case R_RISCV_BRANCH: > > CoffAddFixup( > > (UINT32) ((UINT64) > > mCoffSectionsOffset[RelShdr->sh_info] > > @@ -1145,6 +1211,8 @@ WriteRelocations64 ( > > case R_RISCV_SET8: > > case R_RISCV_SET16: > > case R_RISCV_SET32: > > + case R_RISCV_PCREL_HI20: > > + case R_RISCV_PCREL_LO12_I: > > break; > > > > default: >=20