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 02:08:13 -0700 Received: from pps.filterd (m0134424.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x7S8qd1l006403; Wed, 28 Aug 2019 09:08:12 GMT Received: from g2t2353.austin.hpe.com (g2t2353.austin.hpe.com [15.233.44.26]) by mx0b-002e3701.pphosted.com with ESMTP id 2unj13j0dd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Aug 2019 09:08:12 +0000 Received: from G9W8455.americas.hpqcorp.net (exchangepmrr1.us.hpecorp.net [16.216.161.94]) (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 D538C6D; Wed, 28 Aug 2019 09:08:11 +0000 (UTC) Received: from G2W6309.americas.hpqcorp.net (2002:10c5:4033::10c5:4033) by G9W8455.americas.hpqcorp.net (2002:10d8:a15e::10d8:a15e) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 28 Aug 2019 09:08:11 +0000 Received: from NAM04-BN3-obe.outbound.protection.outlook.com (15.241.52.10) by G2W6309.americas.hpqcorp.net (16.197.64.51) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Wed, 28 Aug 2019 09:08:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NGFnM4iDrsZ2sfxMEqYfze5abUxIWAKFg2zdGNr+GAixLsdu91BPb1N6rvJkGEPxDz8tNXbgUbs3hdKOriOX8QbOdlQ4Cser0UfRS+bmL9XVUPLvi37yQ+p+O7WmU7G7kk2yqE2Etm22tUfnXT7u6mO06UslGLBT9ziY3kvpmr4dBMBIJS2WIVOZyCKxm1tsF/2koPhhXzQzjuxa0N3S82DdlGgwW5LR0b2hD7ku7JmnnE3/vSp78iNm/PI7dgLAexpEGu847J+n11RmTi/3gIIAQE39V287ex7aFk/InQ0mUKzh6+27MT3CyeXvq3dZIukd+/ULgQ1ZUfqbeh4xYQ== 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=ouyAecdPg04QXsGx9COSWUO54VU6GaiU/c2RvMsS8P8=; b=SEBeSdn4n8fUSIl+PU/bXv1iWXNSpo6nJmcAQlLCl4h6GxnphCw8N7tNJwp1Vc82H1BP5876zGlL8u7RrsPsW6klpf3IMHU55e+dbhPCGzo/yAzK3JLARvWAwhJJy/ERj/aH+GQYQBYHJoXsEsxFx9R8hmLNlV6loI/8tZd9o99ZcHjfMQIhsDsHier8AlRjrhj0A35oD6cNZeR4JzKC+7CHEiztzsfeVaAWfypOFeNB+gt6MnSpN7U68rQHV9XpsL04Ghwnbo4eDFTMvhhEP/IV/5zCVsS21VJCwes1zMJ/XSotAafGryPGWxwGPIDT0shiDO0QdsectOWw3dqYqA== 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 CS1PR8401MB0341.NAMPRD84.PROD.OUTLOOK.COM (10.169.13.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.19; Wed, 28 Aug 2019 09:08:09 +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 09:08:09 +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: AQHVXXkt7kZEYNGgmkOz0OuAw5v0vKcQPfiwgAAFAYCAAAEg4A== Date: Wed, 28 Aug 2019 09:08:09 +0000 Message-ID: References: <1566885632-5747-1-git-send-email-abner.chang@hpe.com> <20190828091756.00004ffc@huawei.com> <20190828095955.00002835@huawei.com> In-Reply-To: <20190828095955.00002835@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: c882bf20-0843-4c90-b33b-08d72b973f5c 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:CS1PR8401MB0341; x-ms-traffictypediagnostic: CS1PR8401MB0341: x-ms-exchange-purlcount: 1 x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7219; x-forefront-prvs: 014304E855 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39860400002)(396003)(376002)(346002)(136003)(366004)(189003)(199004)(13464003)(71200400001)(8936002)(25786009)(74316002)(86362001)(6436002)(71190400001)(2906002)(7696005)(966005)(76176011)(6246003)(99286004)(53546011)(5660300002)(102836004)(53946003)(52536014)(26005)(14454004)(6506007)(53936002)(15650500001)(186003)(478600001)(55016002)(30864003)(33656002)(6306002)(3846002)(6116002)(66446008)(64756008)(9686003)(66066001)(66556008)(66476007)(66946007)(76116006)(14444005)(8676002)(81156014)(81166006)(256004)(4326008)(7736002)(476003)(486006)(19627235002)(305945005)(446003)(229853002)(11346002)(316002)(6916009)(579004);DIR:OUT;SFP:1102;SCL:1;SRVR:CS1PR8401MB0341;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: JXZ4NmrDIOjB3zz6pqLBjRUF13DRMFOwI+wDP81DcFaGnD9/HfGHckPzG5JzuOX2MsX9loRlbRlqHKzQsJpHeJEIrBuWUjn5BsV5y0mN4fu75fYadTE4JlzsqrzrBjEi6LJ8Md7tf576gasxHaMPKZ/ju9b1mp9BB6Y0lolZOV+fPUs2eIWcR2EFbNLIkZsZenA7I5PlHmzgdPvDdTzD5SKHFQ4DmCFTOOfQHo3x4v42u5a/YLU2zX5qvUb7jcE/z/zRfxduYpDmmnJElW4xWOqrhIjLGmuhG/ol++T3LBEQMzVuUR82dQvHtVCV2fEHEhxPRxdPIw3Iwt8quHscMTguTXM+DwSkJKPcpWa+vBX3ttghNdQsau/2WfdqPslSpg81EcL4uaQAThv3biO69F711ptFQn4nnmNcaiPT3BY= x-ms-exchange-transport-forked: True X-MS-Exchange-CrossTenant-Network-Message-Id: c882bf20-0843-4c90-b33b-08d72b973f5c X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Aug 2019 09:08:09.7581 (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: gdCE/VOo1/iMjX10YSqwtEneulZOWTwGkjrYm2XxMHz88LvXU9Ht5Xn6KgL7PlXp2eL1BEkgzBZ1na+2c8m6Ow== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CS1PR8401MB0341 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_01:2019-08-27,2019-08-28 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxlogscore=999 adultscore=0 phishscore=0 lowpriorityscore=0 impostorscore=0 spamscore=0 suspectscore=0 mlxscore=0 bulkscore=0 clxscore=1015 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1906280000 definitions=main-1908280037 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: Jonathan Cameron [mailto:jonathan.cameron@huawei.com] > Sent: Wednesday, August 28, 2019 5:00 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 > On Wed, 28 Aug 2019 08:43:10 +0000 > "Chang, Abner (HPS SW/FW Technologist)" wrote: >=20 > > Thanks Jonathan, the cover letter and 3/14 patch were just sent. >=20 > Great. So am I right in thinking these apply to: > INVALID URI REMOVED > 3A__github.com_tianocore_edk2-2Dstaging_tree_RISC- > 2DV&d=3DDwICAg&c=3DC5b8zRQO1miGmBeVZ2LFWg&r=3D_SN6FZBN4Vgi4Ulkskz6 > qU3NYRO03nHp9P7Z5q59A3E&m=3D4xGwArhbyMMHxteOpv4UP8PJWPKah5H > fR_X2Dl0H8vE&s=3DsCxw_Qm3DjjrX9vULVZYYw6jqhmQWygJP-B0Dltr6kc&e=3D ? >=20 > Any plans to rebase that tree as it seems to be a few years old now? Yes. we have plan to rebase it as you said this one is too old, will do it = while edk2 devel review those patches ( includes edk2-platform/devel-rsicv = patches) Thanks >=20 > Thanks, >=20 > Jonathan >=20 > > > > 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 > > > > > > Hi Abner, > > > > > > Just noticed in passing that this series doesn't seem to have a 3/14? > > > > > > Speaking personally it would be useful to have a cover letter with a > > > quick summary of the series content. > > > > > > Thanks, > > > > > > Jonathan > > > > > > On Tue, 27 Aug 2019 14:00:19 +0800 > > > Abner Chang wrote: > > > > > > > Elf64Convert.c > > > > - Relocation process to hadnle below opcodes, > > > > * PCRELHI20 > > > > * PCRELLO12 > > > > * ADD32 > > > > * SUB32 > > > > > > > > GenFvInternalLib.c > > > > - This atches jump instrcution at the position of first > > > > instrcution fetched 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 d= irectly > > > > - // > > > > - PeiCorePhysicalAddress =3D 0; > > > > - Status =3D GetFileByType (EFI_FV_FILETYPE_PEI_CORE, 1, > &PeiCoreFile); > > > > - 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 e= ntry 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 sectio= n 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= point 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 type 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 1MB 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 *) > FvHeader, > > > 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 must have > > > the > > > > + // EndAddress of 0xFFFFFFFF. Thus, only this type fv needs > > > > + to update > > > the > > > > + // reset vector. If the PEI Core is found, the VTF file will= probably > get > > > > + // corrupted by updating the entry point. > > > > // > > > > - DebugMsg (NULL, 0, INFO_LOG_LEVEL, "Update RISCV reset > vector", > > > NULL); > > > > - Status =3D UpdateRiscvResetVectorIfNeeded (&FvImageMemoryFil= e, > > > &mFvDataInfo, VtfFileImage); > > > > - if (EFI_ERROR (Status)) { > > > > - Error (NULL, 0, 3000, "Invalid", "Could not update the r= eset 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 nee= ds to > 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, > &mFvDataInfo, > > > VtfFileImage); > > > > - if (EFI_ERROR(Status)) { > > > > - Error (NULL, 0, 3000, "Invalid", "Could not update t= he reset > > > vector."); > > > > - goto Finish; > > > > - } > > > > - DebugMsg (NULL, 0, 9, "Update Reset vector in VTF file= ", NULL); > > > > - } > > > > } > > > > + DebugMsg (NULL, 0, 9, "Update Reset vector in VTF file", N= ULL); > > > > + } > > > > } > > > > } > > > > > > > > @@ -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 vector 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 = (&ImageContext); > > > > if (EFI_ERROR (Status)) { > > > > - Error (NULL, 0, 3000, "Invalid", "RelocateImage() call faile= d 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, 1= 2, 20)); > > > > + 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", "WriteSections6= 4(): > > > 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", "WriteSections6= 4(): > > > 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= _info] > > > > + + (Rel->r_offset - SecShdr->sh_addr)), > > > > + EFI_IMAGE_REL_BASED_ABSOLUTE); > > > > + break; > > > > + > > > > + case R_RISCV_SUB32: > > > > + CoffAddFixup( > > > > + (UINT32) ((UINT64) mCoffSectionsOffset[RelShdr->sh= _info] > > > > + + (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