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.147.86, mailfrom: prvs=0150651a61=abner.chang@hpe.com) Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by groups.io with SMTP; Wed, 04 Sep 2019 04:18:46 -0700 Received: from pps.filterd (m0148663.ppops.net [127.0.0.1]) by mx0a-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x84BGFtk007073; Wed, 4 Sep 2019 11:18:45 GMT Received: from g9t5008.houston.hpe.com (g9t5008.houston.hpe.com [15.241.48.72]) by mx0a-002e3701.pphosted.com with ESMTP id 2ut7enj6ne-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Sep 2019 11:18:45 +0000 Received: from G9W8453.americas.hpqcorp.net (exchangepmrr1.us.hpecorp.net [16.216.160.211]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by g9t5008.houston.hpe.com (Postfix) with ESMTPS id 4E3E956; Wed, 4 Sep 2019 11:18:44 +0000 (UTC) Received: from G1W8108.americas.hpqcorp.net (2002:10c1:483c::10c1:483c) by G9W8453.americas.hpqcorp.net (2002:10d8:a0d3::10d8:a0d3) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 4 Sep 2019 11:18:43 +0000 Received: from NAM04-BN3-obe.outbound.protection.outlook.com (15.241.52.11) by G1W8108.americas.hpqcorp.net (16.193.72.60) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Wed, 4 Sep 2019 11:18:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CIXbx92x/rzQTPLH/2MnT6oS3dx1ihnp85I7GN0oATOxIqZJ5X0+eM9Y+1Fy3O6F0UTGkmX1guHZTn0ZDgN2+lc0SDBW4tJ3H0ZtiyE6aGGv7hApd9E2UOjAjGq6ha6B579CcB2Fx1xulurnsYvw5whD3vBd+BKTG3+9JUB0JY8/Bk2LM0CQQrJwqxazP1ft3iOJbbF8qNGtK2QlE3Acagp6Nn5j15lOCenuv/kvkwcRz8sQxOFYFFCQoNJdIUoJhtUPdLoZ53LVK2eweykw4esx21+DPvQd3iswGMzNDsdyZ1Qsu2mbhW/pVyn4ekWEEq1Zzf4QPU3MgKQHz7MKmg== 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=PPVQYB/vTrLqeeeWjqYjQ1cM6Pg4NZlP7O0fulxLFDE=; b=QBj3YZqKXVm7J7UAcraR+P1YoYWQHGOeWWrRwCr+BNTHtBn9MzmxwCP26Gz5YWEG3aMvCkHP07BSsEk12Xg0iflscP1CEM20zaAsVdkN9N2VOqDBUa3qMAn5ohfJW2uE6UnafjnE0Uq6bLSZOorC3iWFoLp7UFcLN0HXvHws7PC3x2vLS3alj68xrqti8xtwsSSSrFCNuaFHzcFIlk5J2CwKZCbgA2TSos3ZpDY0WIo5XMAiyaUN091DhAnwyU4BiUzc7RRAHvMvuTK2Tyxd9KuMI0R7QWNQsBUBHUT25vxdMmw5CC+pqc4vvuEDtsX4ab7bz54jeHkqhx9q315oBA== 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 CS1PR8401MB0726.NAMPRD84.PROD.OUTLOOK.COM (10.169.15.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2241.13; Wed, 4 Sep 2019 11:18:41 +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.022; Wed, 4 Sep 2019 11:18:40 +0000 From: "Abner Chang" To: "devel@edk2.groups.io" , "Chang, Abner (HPS SW/FW Technologist)" , Jonathan Cameron 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: AQHVXXkt7kZEYNGgmkOz0OuAw5v0vKcQPfiwgAAFAYCAAAEg4IALJRFw Date: Wed, 4 Sep 2019 11:18:40 +0000 Message-ID: References: <1566885632-5747-1-git-send-email-abner.chang@hpe.com> <20190828091756.00004ffc@huawei.com> <20190828095955.00002835@huawei.com> <15BF0B00F4581767.2982@groups.io> In-Reply-To: <15BF0B00F4581767.2982@groups.io> 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: ea073cde-2e59-4da7-c2ce-08d73129a3e1 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:CS1PR8401MB0726; x-ms-traffictypediagnostic: CS1PR8401MB0726: x-ms-exchange-purlcount: 1 x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6790; x-forefront-prvs: 0150F3F97D x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39860400002)(366004)(376002)(396003)(136003)(189003)(199004)(13464003)(64756008)(9686003)(30864003)(55016002)(53546011)(66446008)(2501003)(102836004)(6306002)(66556008)(229853002)(19627235002)(74316002)(86362001)(3846002)(25786009)(256004)(6116002)(446003)(76116006)(53936002)(66066001)(476003)(52536014)(6436002)(66476007)(486006)(5660300002)(2906002)(6246003)(76176011)(33656002)(966005)(71200400001)(186003)(478600001)(71190400001)(7696005)(14454004)(11346002)(53946003)(66946007)(81156014)(110136005)(99286004)(14444005)(7736002)(26005)(305945005)(8676002)(316002)(81166006)(8936002)(15650500001)(6506007)(559001)(579004);DIR:OUT;SFP:1102;SCL:1;SRVR:CS1PR8401MB0726;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: mSBM3AG+0U87AF9wt6BXba17GUFgl1489SkzKJzd1gcYSGxw5LHc+BUmLPU/NP69Hcpn4WFjsbPvhWIogH+igjpNhfI85yvdXckCdmXEPaZ/JhCaoP+xZELA5Yp7Gcq2tPVepDITXfcMROYntguJL6OE2GEq25xYieF/xuqe9UdZ06YkjC0WcCi/mS1pi/sd/B3iT14dKwFkZGOASuiLclasYHsuEtsNYn5WEMi4rBz/iHRBX3W/5iGInSvIpN6MQH1RjoLTucMxhMKHO0oH2asrS3XpSeWCw01w8P7Qmx9YGQ/rBY6dacJA3m799Vj+HXRBCYtkLTTpnWbHRELSlaAbWNnX6v6xVoeIuoXU5c8c7P8VIlCKiOXB0RyZIj14kLu5d7MQSGXmvqznNp8lwlEk6ZgG8VxIPa5faz6cvd8= X-MS-Exchange-CrossTenant-Network-Message-Id: ea073cde-2e59-4da7-c2ce-08d73129a3e1 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Sep 2019 11:18:40.8506 (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: IoEwH9pGJomqS9XvBE1IcF9460GTcGyWe0g78hOw/Xx+EJzA814+1BNNYuqgXipiegAAJFNZdaXsd8SrNA9f3g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CS1PR8401MB0726 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:6.0.70,1.0.8 definitions=2019-09-04_03:2019-09-03,2019-09-04 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 bulkscore=0 clxscore=1015 mlxscore=0 phishscore=0 mlxlogscore=999 priorityscore=1501 malwarescore=0 spamscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1906280000 definitions=main-1909040114 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Jonathan, I created a new branch "RISC-V-V2" on edk2-staging which is ba= sed on most recent EDK2 master and sent the patches based on it. This is easier for reviewers to review the changes for RISC-V EDK2 port. T= he original "RISC-V" branch has some stale implementation and may confuse p= eople. This new branch on edk2-staging is much clear. Thanks Abner > -----Original Message----- > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of > Abner Chang > Sent: Wednesday, August 28, 2019 5:08 PM > 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 >=20 > > -----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]: BaseToo= ls: > > Update EDK2 build tool for RISC-V platform > > > > On Wed, 28 Aug 2019 08:43:10 +0000 > > "Chang, Abner (HPS SW/FW Technologist)" > wrote: > > > > > Thanks Jonathan, the cover letter and 3/14 patch were just sent. > > > > 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 ? > > > > 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) >=20 > Thanks >=20 > > > > Thanks, > > > > Jonathan > > > > > > > > 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 cor= e directly > > > > > - // > > > > > - 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_PE3= 2, 1, > > > > &Pe32Section); > > > > > - if (Status =3D=3D EFI_NOT_FOUND) { > > > > > - Status =3D GetSectionByType (PeiCoreFile, EFI_SECTION_T= E, 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 PE3= 2 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.Pe32Secti= on + > > > > GetSectionHeaderLength(Pe32Section.CommonHeader) - (UINTN) > > FvImage- > > > > >FileImage; > > > > > - PeiCorePhysicalAddress +=3D EntryPoint; > > > > > - DebugMsg (NULL, 0, 9, "PeiCore physical entry point addre= ss", > > > > "Address =3D 0x%llX", (unsigned long long) PeiCorePhysicalAddress)= ; > > > > > - RiscvPatchVtf (VtfFileImage, (UINT32)PeiCorePhysicalAddre= ss); > > > > > - } > > > > > - 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 sec= tion 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 en= try 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, FvInf= o, > > > > > + 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", (unsigne= d > > > > > + 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 > (&FvImageMemoryFile, > > > > &mFvDataInfo, VtfFileImage); > > > > > - if (EFI_ERROR (Status)) { > > > > > - Error (NULL, 0, 3000, "Invalid", "Could not update th= e 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 b= sf 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 fi= le 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 updat= e the reset > > > > vector."); > > > > > - goto Finish; > > > > > - } > > > > > - DebugMsg (NULL, 0, 9, "Update Reset vector in VTF f= ile", NULL); > > > > > - } > > > > > } > > > > > + 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 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 PeCoffLoaderRelocateIma= ge > (&ImageContext); > > > > > if (EFI_ERROR (Status)) { > > > > > - Error (NULL, 0, 3000, "Invalid", "RelocateImage() call fa= iled 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, 1= 2, 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 NU= LL > > > > > + && > > > > RiscvSymSecIndex !=3D 0) { > > > > > + int i; > > > > > + Value2 =3D (UINT32)(RV_X(*(UINT32 *)RiscvHi20Targ= , 12, 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", "WriteSectio= ns64(): > > > > 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", "WriteSectio= ns64(): > > > > 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 >=20 >=20