From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR03-AM5-obe.outbound.protection.outlook.com (EUR03-AM5-obe.outbound.protection.outlook.com [40.107.3.44]) by mx.groups.io with SMTP id smtpd.web11.8369.1589445889421649120 for ; Thu, 14 May 2020 01:44:49 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=rTt+twmd; spf=pass (domain: arm.com, ip: 40.107.3.44, mailfrom: sami.mujawar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=U3JROEys4lAJOIFdSWr3gw4bvHvEgm6Rvf29k4uSrG4=; b=rTt+twmd+kCk3E8DD8Yw9cXjtcrnU1HDVe98C1qmJ1AeSBXJ1FNUJG8dq4EPLn/peJA7jQenUH1wiNYQxqz160NuKLfJy8gZBTcTy4esFL3Dj2/D0UzaiHIIgjYZtuJhfGN530Iu36WeH8ahRk7N3tpRKRkyVtvQhgrgBtxHl1w= Received: from DB6PR07CA0007.eurprd07.prod.outlook.com (2603:10a6:6:2d::17) by AM4PR08MB2657.eurprd08.prod.outlook.com (2603:10a6:205:b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.26; Thu, 14 May 2020 08:44:46 +0000 Received: from DB5EUR03FT036.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:2d:cafe::4c) by DB6PR07CA0007.outlook.office365.com (2603:10a6:6:2d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.12 via Frontend Transport; Thu, 14 May 2020 08:44:46 +0000 Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT036.mail.protection.outlook.com (10.152.20.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.19 via Frontend Transport; Thu, 14 May 2020 08:44:46 +0000 Received: ("Tessian outbound 567b75aed2b9:v54"); Thu, 14 May 2020 08:44:45 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 415b487d8a8da3ad X-CR-MTA-TID: 64aa7808 Received: from eaa5f226e0b2.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 29E2A850-49C6-4EEE-A2BE-87524FACC852.1; Thu, 14 May 2020 08:44:40 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id eaa5f226e0b2.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 14 May 2020 08:44:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WngwPdbQgvPhSTNrdfMiLQc0ulhxn6cX8IU2pjCpUuXL57NVNumO7nR7B/GtIQ6P2T30Ngl7aVWb7OVIfk7OmPefXtp7tEuIyVH3ezuheCNZz1yvZgemQ1tgwb0tDOP5zn7enPecoMfna9IpmRx6/CJRvJWqgCY/y02tnrcAFAxmjeStlyR4RHQAlVI1pPv5+ROnjIa8Q9dlWFL2Uevj61/jYuZWS0r2gLNVn4ntOygKOX1w3lj1oT2OMoQlMQGNLx0tf7Qyrz2DEfbtl6r9rOb9A9h34bMDzBhPiH9Aj9xwEw35Ba96Eye/uBIPNbPHi2XxSBiyc4RDCsbpX7I46Q== 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=U3JROEys4lAJOIFdSWr3gw4bvHvEgm6Rvf29k4uSrG4=; b=fNJ+m43HHlAmPDY0fBtd0WsiIa7CMA5GGI2j3E+tCxKXCxXehvIRY4tw7aI4HHrRy4r+MNSFoa1ookI/s8vFkQFmqulKY+c12dTNIlO4s6Oxozg9YwhhSzL+NkvuqFcXwcyxoaB8qJha8pW5XIfojrJc6g3nCDyLiddVktcMbP0jt1WhhrMypnneWGKHTbL8cOCl0RLKAZbaeXPpkyCwJm58NaPhOCCMiUgr7BJ66zmQZhj69vJ2qAX4umvrRvXbEaRRr8ggPms2rToGEiGeXBeTTMyBuLrV7lPCqlqEVVn1TL2jo7XdNl1tcFBSfwofk2eamupUZRVS41m6WVqaVQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com; dmarc=bestguesspass action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=U3JROEys4lAJOIFdSWr3gw4bvHvEgm6Rvf29k4uSrG4=; b=rTt+twmd+kCk3E8DD8Yw9cXjtcrnU1HDVe98C1qmJ1AeSBXJ1FNUJG8dq4EPLn/peJA7jQenUH1wiNYQxqz160NuKLfJy8gZBTcTy4esFL3Dj2/D0UzaiHIIgjYZtuJhfGN530Iu36WeH8ahRk7N3tpRKRkyVtvQhgrgBtxHl1w= Received: from DB6PR0301CA0061.eurprd03.prod.outlook.com (2603:10a6:4:54::29) by AM0PR08MB4099.eurprd08.prod.outlook.com (2603:10a6:208:12a::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.34; Thu, 14 May 2020 08:44:39 +0000 Received: from DB5EUR03FT021.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:54:cafe::ca) by DB6PR0301CA0061.outlook.office365.com (2603:10a6:4:54::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Thu, 14 May 2020 08:44:39 +0000 Authentication-Results-Original: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT021.mail.protection.outlook.com (10.152.20.238) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.3000.19 via Frontend Transport; Thu, 14 May 2020 08:44:39 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Thu, 14 May 2020 08:40:29 +0000 Received: from E107187.Arm.com (10.57.42.179) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Thu, 14 May 2020 08:40:29 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , , , Subject: [PATCH v1 08/11] ArmVirtPkg: Add Kvmtool NOR flash lib Date: Thu, 14 May 2020 09:40:16 +0100 Message-ID: <20200514084019.71368-9-sami.mujawar@arm.com> X-Mailer: git-send-email 2.11.0.windows.3 In-Reply-To: <20200514084019.71368-1-sami.mujawar@arm.com> References: <20200514084019.71368-1-sami.mujawar@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFTY:;SFS:(4636009)(136003)(396003)(39860400002)(346002)(376002)(46966005)(82310400002)(8676002)(47076004)(54906003)(44832011)(70586007)(86362001)(8936002)(6916009)(82740400003)(4326008)(26005)(356005)(36756003)(2616005)(6666004)(7696005)(5660300002)(336012)(81166007)(2906002)(186003)(70206006)(1076003)(478600001)(426003)(316002);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fac8e4fb-aaf6-454c-3491-08d7f7e30df6 X-MS-TrafficTypeDiagnostic: AM0PR08MB4099:|AM4PR08MB2657: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8882;OLM:8882; X-Forefront-PRVS: 040359335D X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: lmKLV3DgEza86H5/EXC/mgyHIW4b1kvjX299yCMD04us8GdAGeEzO6C1nUGmxhNHFBpsD1haFnmo6Ew/diE9l88ePV3UitZD6mC9/JLGA+7SIzniyyrNCF82rk9fQKLuCUF4pypmpuznaiz3xqaPADsCj+qAZVOZ1hgR5ccmu5/RSIkYrN+4K/OhyW8AQbzKB3jKpieW/W3APrgF+zUTUIMwc5SIIxp0vlLcetueRHdq9p0MMKuALJ8cI1ug3fFhEj81qf3hq+7jmoE2+osytvn00lazOyDCV6Uok4AlNo13086SpU6256oaDCdc71qR1kKhYfy/sHyt3CJC7pUCXtpX/Cybd9iYd5cquc8Al6A6vO7YUJdevUTtpv39XAH/fvak1FidtkNbMunzQNC9E5dKrpbg+ArwT7GpdvQdsNSK6tNR1Ly6wOgYZgZQeLtcYqmeL4YJhC2+54XFs6C1K9a+2Pu4UzxKERP4CGAzIMJP/fG2CcCwdSwQLGJb19Z7W/wHhU4mwUflMjQzdlnkXg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB4099 Original-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT036.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFTY:;SFS:(4636009)(396003)(39860400002)(346002)(136003)(376002)(46966005)(7696005)(426003)(54906003)(2616005)(186003)(1076003)(8936002)(5660300002)(336012)(316002)(36756003)(44832011)(478600001)(82740400003)(8676002)(47076004)(70586007)(6916009)(4326008)(26005)(6666004)(86362001)(82310400002)(70206006)(2906002)(81166007);DIR:OUT;SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: b581e055-b189-44f4-d345-08d7f7e30a21 X-Forefront-PRVS: 040359335D X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: P5t1jb9FfcH6pV+U3lYdr5mfSx+zbI/lyvUZqqs79hI/Imi5+20zNKZ9YKlEjGKPb+nm9JuZRXEQncG4rTr/Ym17lRgRECPYlOnrNHFcjPc9yRDdckFMIw5Bo8WxlCpaXdgrqPmtWH5sPq79gohLxSQoKz5e3t84bOzsFWEz7s/4Md7vdVaiiI59XL7eKu+pskZheppShtOq9UgRUZEyA2fwmXfxIscl8IelT6IvenVGSKihrFCEDiU9TfC05+KvbEWzUjjoBjJethpTNt43YFXaAG3wbwU5X2R1rWZB8BX194ajMjcCjihVoBZtpAVsaEEcfwFafXkIWv5xFrQYb4tx5HilTDj+LkgIp6fod5RWwfOlcjGpN8I1WtzapDiEDCUp2DZ3UPlZ0LD4hzh3R1b2YyODeG1MESKt8ovO/cHeOFizH8LGYBNIQGqdfZKy3ZEg+i5J0B2Cs2Yw/iNebE+DYtQqBahgrw51dvjuflRC0EY4qRyrCSmWUoxMxEQka2+4nFPzKZNtCGakBlyfaQ== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2020 08:44:46.0000 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fac8e4fb-aaf6-454c-3491-08d7f7e30df6 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR08MB2657 Content-Type: text/plain Kvmtool places the base address of the CFI flash in the device tree it passes to UEFI. This library parses the kvmtool device tree to read the CFI base address and initialise the PCDs use by the NOR flash driver and the variable storage. Signed-off-by: Sami Mujawar --- ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtool.c | 265 ++++++++++++++++++++ ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtoolLib.inf | 50 ++++ 2 files changed, 315 insertions(+) diff --git a/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtool.c b/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtool.c new file mode 100644 index 0000000000000000000000000000000000000000..2e43c2e21bc9ef7dd1dd198eebbd70c3b0b96d1c --- /dev/null +++ b/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtool.c @@ -0,0 +1,265 @@ +/** @file + An instance of the NorFlashPlatformLib for Kvmtool platform. + + Copyright (c) 2020, ARM Ltd. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + **/ + +#include +#include +#include +#include +#include + +/** Macro defining the maximum number of Flash Banks. + */ +#define MAX_FLASH_BANKS 4 + +STATIC NOR_FLASH_DESCRIPTION mNorFlashDevices[MAX_FLASH_BANKS]; +STATIC UINTN mNorFlashDeviceCount = 0; + +/** This function performs platform specific actions to initialise + the NOR flash, if required. + + @retval EFI_SUCCESS Success. +**/ +EFI_STATUS +NorFlashPlatformInitialization ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "NorFlashPlatformInitialization\n")); + // Nothing to do here + return EFI_SUCCESS; +} + +/** Initialise Non volatile Flash storage variables. + + @param [in] FlashDevice Pointer to the NOR Flash device. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_OUT_OF_RESOURCES Insufficient flash storage space. +**/ +EFI_STATUS +SetupVariableStore ( + IN NOR_FLASH_DESCRIPTION * FlashDevice + ) +{ + UINTN FlashRegion; + UINTN FlashNvStorageVariableBase; + UINTN FlashNvStorageFtwWorkingBase; + UINTN FlashNvStorageFtwSpareBase; + UINTN FlashNvStorageVariableSize; + UINTN FlashNvStorageFtwWorkingSize; + UINTN FlashNvStorageFtwSpareSize; + + FlashNvStorageVariableSize = PcdGet32 (PcdFlashNvStorageVariableSize); + FlashNvStorageFtwWorkingSize = PcdGet32 (PcdFlashNvStorageFtwWorkingSize); + FlashNvStorageFtwSpareSize = PcdGet32 (PcdFlashNvStorageFtwSpareSize); + + if ((FlashNvStorageVariableSize == 0) || + (FlashNvStorageFtwWorkingSize == 0) || + (FlashNvStorageFtwSpareSize == 0)) { + DEBUG ((DEBUG_ERROR, "FlashNvStorage size not defined\n")); + return EFI_INVALID_PARAMETER; + } + + // Setup the variable store + FlashRegion = FlashDevice->DeviceBaseAddress; + + FlashNvStorageVariableBase = FlashRegion; + FlashRegion += PcdGet32 (PcdFlashNvStorageVariableSize); + + FlashNvStorageFtwWorkingBase = FlashRegion; + FlashRegion += PcdGet32 (PcdFlashNvStorageFtwWorkingSize); + + FlashNvStorageFtwSpareBase = FlashRegion; + FlashRegion += PcdGet32 (PcdFlashNvStorageFtwSpareSize); + + if (FlashRegion > (FlashDevice->DeviceBaseAddress + FlashDevice->Size)) { + DEBUG ((DEBUG_ERROR, "Insufficient flash storage size\n")); + return EFI_OUT_OF_RESOURCES; + } + + PcdSet32S ( + PcdFlashNvStorageVariableBase, + FlashNvStorageVariableBase + ); + + PcdSet32S ( + PcdFlashNvStorageFtwWorkingBase, + FlashNvStorageFtwWorkingBase + ); + + PcdSet32S ( + PcdFlashNvStorageFtwSpareBase, + FlashNvStorageFtwSpareBase + ); + + DEBUG (( + DEBUG_INFO, + "PcdFlashNvStorageVariableBase = 0x%x\n", + FlashNvStorageVariableBase + )); + DEBUG (( + DEBUG_INFO, + "PcdFlashNvStorageVariableSize = 0x%x\n", + FlashNvStorageVariableSize + )); + DEBUG (( + DEBUG_INFO, + "PcdFlashNvStorageFtwWorkingBase = 0x%x\n", + FlashNvStorageFtwWorkingBase + )); + DEBUG (( + DEBUG_INFO, + "PcdFlashNvStorageFtwWorkingSize = 0x%x\n", + FlashNvStorageFtwWorkingSize + )); + DEBUG (( + DEBUG_INFO, + "PcdFlashNvStorageFtwSpareBase = 0x%x\n", + FlashNvStorageFtwSpareBase + )); + DEBUG (( + DEBUG_INFO, + "PcdFlashNvStorageFtwSpareSize = 0x%x\n", + FlashNvStorageFtwSpareSize + )); + + return EFI_SUCCESS; +} + +/** Return the Flash devices on the platform. + + @param [out] NorFlashDescriptions Pointer to the Flash device description. + @param [out] Count Number of Flash devices. + + @retval EFI_SUCCESS Success. + @retval EFI_NOT_FOUND Flash device not found. +**/ +EFI_STATUS +NorFlashPlatformGetDevices ( + OUT NOR_FLASH_DESCRIPTION **NorFlashDescriptions, + OUT UINT32 *Count + ) +{ + if (mNorFlashDeviceCount > 0) { + *NorFlashDescriptions = mNorFlashDevices; + *Count = mNorFlashDeviceCount; + return EFI_SUCCESS; + } + return EFI_NOT_FOUND; +} + +/** Entrypoint for NorFlashPlatformLib. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Flash device not found. +**/ +EFI_STATUS +EFIAPI +NorFlashPlatformLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE * SystemTable + ) +{ + FDT_CLIENT_PROTOCOL *FdtClient; + INT32 Node; + EFI_STATUS Status; + EFI_STATUS FindNodeStatus; + CONST UINT32 *Reg; + UINT32 PropSize; + UINT64 Base; + UINT64 Size; + + if (mNorFlashDeviceCount != 0) { + return EFI_SUCCESS; + } + + Status = gBS->LocateProtocol ( + &gFdtClientProtocolGuid, + NULL, + (VOID **)&FdtClient + ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + for (FindNodeStatus = FdtClient->FindCompatibleNode ( + FdtClient, + "cfi-flash", + &Node + ); + !EFI_ERROR (FindNodeStatus) && (mNorFlashDeviceCount < MAX_FLASH_BANKS); + FindNodeStatus = FdtClient->FindNextCompatibleNode ( + FdtClient, + "cfi-flash", + Node, + &Node + )) { + Status = FdtClient->GetNodeProperty ( + FdtClient, + Node, + "reg", + (CONST VOID **)&Reg, + &PropSize + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: GetNodeProperty () failed (Status == %r)\n", + __FUNCTION__, Status)); + continue; + } + + ASSERT ((PropSize % (4 * sizeof (UINT32))) == 0); + + while ((PropSize >= (4 * sizeof (UINT32))) && + (mNorFlashDeviceCount < MAX_FLASH_BANKS)) { + Base = SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[0])); + Size = SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[2])); + Reg += 4; + + PropSize -= 4 * sizeof (UINT32); + + // + // Disregard any flash devices that overlap with the primary FV. + // The firmware is not updatable from inside the guest anyway. + // + if ((PcdGet64 (PcdFvBaseAddress) + PcdGet32 (PcdFvSize) > Base) && + (Base + Size) > PcdGet64 (PcdFvBaseAddress)) { + continue; + } + + DEBUG (( + DEBUG_INFO, + "NOR%d : Base = 0x%lx, Size = 0x%lx\n", + mNorFlashDeviceCount, + Base, + Size + )); + + mNorFlashDevices[mNorFlashDeviceCount].DeviceBaseAddress = (UINTN)Base; + mNorFlashDevices[mNorFlashDeviceCount].RegionBaseAddress = (UINTN)Base; + mNorFlashDevices[mNorFlashDeviceCount].Size = (UINTN)Size; + mNorFlashDevices[mNorFlashDeviceCount].BlockSize = SIZE_256KB; + mNorFlashDeviceCount++; + } + } + + // Setup the variable store in the last bank + if ((mNorFlashDeviceCount > 0) && + (mNorFlashDevices[mNorFlashDeviceCount - 1].DeviceBaseAddress != 0)) { + return SetupVariableStore (&mNorFlashDevices[mNorFlashDeviceCount - 1]); + } + + return EFI_NOT_FOUND; +} + diff --git a/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtoolLib.inf b/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtoolLib.inf new file mode 100644 index 0000000000000000000000000000000000000000..8bd6f730dcb52e597b418e59766c1566a9519789 --- /dev/null +++ b/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtoolLib.inf @@ -0,0 +1,50 @@ +#/** @file +# +# Copyright (c) 2020, ARM Ltd. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#**/ + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = NorFlashKvmtoolLib + FILE_GUID = E75F07A1-B160-4893-BDD4-09E32FF847DC + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = NorFlashPlatformLib + CONSTRUCTOR = NorFlashPlatformLibConstructor + +[Sources.common] + NorFlashKvmtool.c + +[Packages] + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + ArmVirtPkg/ArmVirtPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + BaseLib + DebugLib + PcdLib + UefiBootServicesTableLib + +[Protocols] + gFdtClientProtocolGuid ## CONSUMES + +[Pcd] + gArmTokenSpaceGuid.PcdFvBaseAddress + gArmTokenSpaceGuid.PcdFvSize + + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize + + +[Depex] + gFdtClientProtocolGuid + -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'