From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (EUR04-HE1-obe.outbound.protection.outlook.com [40.107.7.79]) by mx.groups.io with SMTP id smtpd.web10.12798.1684400999667267758 for ; Thu, 18 May 2023 02:10:00 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=UuDjJjhT; spf=pass (domain: arm.com, ip: 40.107.7.79, 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=87dNbn7Tu+DDmq8qbw5npGWOcEK7Sxh5oy6/rbNCwY0=; b=UuDjJjhTZO/HSQa1/YhCn0e0lK8+oSRxNar3gWFgmNcFWxf8cFbTq6xEsuBvfT+qfPigJRX9mpiJfZvXslqCvG75cDvQfKqfDiNddHz4G5ez+9b+AC4am+KTvYxrwhW+zXO+sU00qlpCXxEdURp+E/zXNnqDs5dn1cYY1f37RBk= Received: from AS9PR07CA0059.eurprd07.prod.outlook.com (2603:10a6:20b:46b::34) by GV2PR08MB8702.eurprd08.prod.outlook.com (2603:10a6:150:b6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.19; Thu, 18 May 2023 09:09:55 +0000 Received: from AM7EUR03FT032.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:46b:cafe::6a) by AS9PR07CA0059.outlook.office365.com (2603:10a6:20b:46b::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.6 via Frontend Transport; Thu, 18 May 2023 09:09:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass 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; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM7EUR03FT032.mail.protection.outlook.com (100.127.140.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.18 via Frontend Transport; Thu, 18 May 2023 09:09:55 +0000 Received: ("Tessian outbound 3570909035da:v136"); Thu, 18 May 2023 09:09:54 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 3718bc4a4f61bcd8 X-CR-MTA-TID: 64aa7808 Received: from 31e92718b82b.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 613E0BFC-5637-43E9-942B-3106F60B4494.1; Thu, 18 May 2023 09:09:43 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 31e92718b82b.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 18 May 2023 09:09:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QLzB00665U/yXbRfEvHeRwfAoLhixph5flvx82esJqjCNIjjSFPfbe3UP/Fdco6kALbOzBJDojyuFiNm7IVB0Vhm8XZyPBX3nADyur2+vk4yDNIXhBCzduA/Pku4xwpqrJMrhMQ0OIITROfRhluF9dJcqC7Dop6C2EcZ2DbapxpEUc3DbJWLE60qAoRkHTs5F9Q9s5KMP8f/L36JFifiENaxcYVspqops+5Gh2aC81UWpgQl162W0Fq9bgOGqNDKsaqczX6k+Z/rS7QyZj+3rb37p7v9CQb0tK7ROYnuaVX7ajEL5/CW+CfOcgijZ3J2YI3TmucjAL2p1E3+0DI8gQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=87dNbn7Tu+DDmq8qbw5npGWOcEK7Sxh5oy6/rbNCwY0=; b=KRckMs/xAt6sp641Hr2pVOMNZxdcwc5wdLu1f0y1pWKhUKGVOPWgTA8pRP2/WNiAljDSN2KyJQxVaW8YxMH4a0DztUGfxBwDXaBXTVqUPd0z7H2bRhn7Sdal11THxWTH0syqAjFs5ZYaggd6Fr+l4JNTyB/laepOEYkAnEMWqdWu3HEm0B6s88WJ2//G+zfI9wSpWUBO2oOwYckDt/FbdtjTHEwTOFhPMx3AD4Lghdu7ZEDUUDxKbx85axPttlIx8Z9pzZ02Tx9rCIFcuDonIjB/2wEchUluMiOf3FJp6TW6mnCJF/8lixCyJrG5co2sS5uRpBRmXxfhNm+Upiqamw== 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=pass (p=none sp=none pct=100) 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=87dNbn7Tu+DDmq8qbw5npGWOcEK7Sxh5oy6/rbNCwY0=; b=UuDjJjhTZO/HSQa1/YhCn0e0lK8+oSRxNar3gWFgmNcFWxf8cFbTq6xEsuBvfT+qfPigJRX9mpiJfZvXslqCvG75cDvQfKqfDiNddHz4G5ez+9b+AC4am+KTvYxrwhW+zXO+sU00qlpCXxEdURp+E/zXNnqDs5dn1cYY1f37RBk= Received: from DU2PR04CA0028.eurprd04.prod.outlook.com (2603:10a6:10:3b::33) by PAWPR08MB9781.eurprd08.prod.outlook.com (2603:10a6:102:2e6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.19; Thu, 18 May 2023 09:09:40 +0000 Received: from DBAEUR03FT029.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:3b:cafe::22) by DU2PR04CA0028.outlook.office365.com (2603:10a6:10:3b::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.19 via Frontend Transport; Thu, 18 May 2023 09:09:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass 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; pr=C Received: from nebula.arm.com (40.67.248.234) by DBAEUR03FT029.mail.protection.outlook.com (100.127.142.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.19 via Frontend Transport; Thu, 18 May 2023 09:09:40 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 18 May 2023 09:09:37 +0000 Received: from E114225.Arm.com (10.1.196.36) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2507.23 via Frontend Transport; Thu, 18 May 2023 09:09:37 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , , , , , Subject: [PATCH v1 3/6] ArmVirtPkg: Fallback to variable emulation if no CFI is found Date: Thu, 18 May 2023 10:09:32 +0100 Message-ID: <20230518090935.10984-4-sami.mujawar@arm.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20230518090935.10984-1-sami.mujawar@arm.com> References: <20230518090935.10984-1-sami.mujawar@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DBAEUR03FT029:EE_|PAWPR08MB9781:EE_|AM7EUR03FT032:EE_|GV2PR08MB8702:EE_ X-MS-Office365-Filtering-Correlation-Id: dba77df2-4e02-4c2d-11a1-08db577fa56a x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: rRrHuNoNxvHHpDqYyTj8L+KK0RoquAfvhMlf0EIbOOCy6oabb2x+6+Hy4Lu3yB3J3omgZorgoutQXE8LVdlkfaRYlxLXR6hcplak1YNJfloLAtLsq3s8B6VcDlkMOstdGHAPHBGzskofjx5D0nfhxUcMwCsTxjlXSHbVpQcte5aOSgk/k0ytuQbiNh72ZuR1r0fmn4VSrpiOpvlQ/Mg1GY+sRDREfp7S2NFvvkmJzevp9ge2caokNA3WtHvceYGyLTY+SKe8dA2ZS4/KC+hcF9WLgT/VgkJ/Q/arn6kAi76ALc/j8yikNVo5dKhZ14h0wNyLAPSbABZbrNkbgvT7vJGMy9Kp71W2JsNxQhmKG0jnIEp4w5eBDfmHF74hKslfMh930mr/rLNFwCr7yGGKfylbsy/M5AfWQBDDaZniQkzHATCXYmCq38qvMi1lQa5WGFXrgP15K8Li3/om+iA4Msoy0iLPM7Jz2QBXRKT9tujusGonZxy23DEppbZVYBEF5lNVslVgEhjjHZSEgXHm5dNsZC7oJwtkC1DvmP980TAZ8SqrZ01swWdVuNWLtoyeV+jXh1TnIvL6pHsGo/mvCjYC6YyDWC2YVVMeqrmt/6CBgSIDl2I5F24TQu7lPmHRvohxEbtaOClNQTZd1mqtbKUDBsqtQGB6u+XCcaQLM1RYDLnpBqj/KYwJdE4F5Zre2WIeAt0u60Nf347PfsbWo30CFeWQqcuWUmYVsfjXK2w6S1jeki0UipwtXIO2tD3zphGgRCdvtj8hUJKYqUKGVA== 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;SFS:(13230028)(4636009)(39860400002)(136003)(346002)(396003)(376002)(451199021)(46966006)(40470700004)(36840700001)(40460700003)(6666004)(1076003)(26005)(7696005)(8676002)(426003)(336012)(478600001)(186003)(44832011)(316002)(36756003)(82310400005)(81166007)(86362001)(4326008)(356005)(2616005)(5660300002)(70586007)(70206006)(54906003)(82740400003)(6916009)(40480700001)(83380400001)(41300700001)(36860700001)(47076005)(2906002)(8936002)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR08MB9781 Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT032.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 4569b82c-bbda-4cbc-df89-08db577f9c83 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ypt4VKl3z+wwUZCVyOGISgO6o0jdSPXH8AXO5SdJMLoRofzXZ6ysu/84cQCp05CPMiopSc3r8oJqJsJot97MTQ0nBhIXOEfwhr4t9rpvyK655fsmQjzfkOTuEZIMHrYwTCI0HNiq6doBUqC56kzNjZ/OvLMnn84KPJj5ocaIAXBnHyS430+nzTPpDrkfOV4+dN1Bfrm02KJMekE/USXJPpGO6fQFMEk+EY2JWvSOmnVYOvjLNxN9CiLpNWJUV8kv7VDhOHpqMZtIaOMZdGCZDBN7s4/e0U5C+dsQ6sTxhdAXhsGSSVOh4ripqKEgWt6e2SIqNKB+ln0nDHJeGPhm1c/BIyEQGgmkBs049VZArbjXVQ/Bpd2sE8452MFNz0qVXJMJmdkKgtf6Wny5SxVatEmJ8Ttkdv1vka2lnDWCuR77Dy7n0TNV/7eRzy7ThLrt95nviBtIGU8tH015YpkVHLchhak6nEyRVfIlflR8epeCWbvJyhnz+6QUhTedYimHBhmDY1AqV6JJOICVUqgVgafIibncvXren+yjHJiYy9aEhoeea9LQFmfy2+TfD+ycpX4rHGQdv4/LuUd8b1nJLoDkFSeRUvD1FIGQjsmxalng6SVuAIJChRCLhVEYCYocWD9Wy/TdKS/t6KcwmbHUAfMc48uy3HASQdKZWtZGga61bUK6uUcEV8S/C0W54VRf3+dNDnDUiLiLxDEtY2rixjMUD5U2EThttxrEUFx4CUEVcnpHZHjzcq1ZDfqLPlWy 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;SFS:(13230028)(4636009)(39860400002)(376002)(396003)(136003)(346002)(451199021)(40470700004)(46966006)(36840700001)(54906003)(4326008)(5660300002)(316002)(41300700001)(6916009)(44832011)(478600001)(2906002)(70586007)(8936002)(70206006)(8676002)(7696005)(6666004)(1076003)(40460700003)(186003)(26005)(36756003)(426003)(2616005)(47076005)(336012)(40480700001)(83380400001)(36860700001)(82310400005)(81166007)(82740400003)(86362001);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2023 09:09:55.0087 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dba77df2-4e02-4c2d-11a1-08db577fa56a 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-AuthSource: AM7EUR03FT032.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR08MB8702 Content-Type: text/plain The kvmtool option '--flash ' is used to launch a guests VM with a CFI flash device that maps the flash file specified at the command line. However, kvmtool allows guest VMs to be launched without a CFI flash device. In such scenarios the firmware can utilize the emulated variable storage for UEFI variables. To support this the PCD gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable must be set to TRUE. Therefore, update the NorFlashKvmtoolLib to fallback to variable emulation if a CFI device is not detected. Also improve the error logging. Signed-off-by: Sami Mujawar --- ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtool.c | 38 +++++++++++++++++--- ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtoolLib.inf | 3 +- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtool.c b/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtool.c index 43f5858644b1f47ada17e00fba55a670ab5862bd..2beeefdd272d6f8841f7d0b972394739b745982e 100644 --- a/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtool.c +++ b/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtool.c @@ -1,7 +1,7 @@ /** @file An instance of the NorFlashPlatformLib for Kvmtool platform. - Copyright (c) 2020, ARM Ltd. All rights reserved.
+ Copyright (c) 2020 - 2023, Arm Ltd. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -228,7 +228,7 @@ NorFlashPlatformLibConstructor ( CONST CHAR8 *Label; UINT32 LabelLen; - if (mNorFlashDeviceCount != 0) { + if ((mNorFlashDeviceCount != 0) || PcdGetBool (PcdEmuVariableNvModeEnable)) { return EFI_SUCCESS; } @@ -337,9 +337,39 @@ NorFlashPlatformLibConstructor ( } if (mNorFlashDevices[UefiVarStoreIndex].DeviceBaseAddress != 0) { - return SetupVariableStore (&mNorFlashDevices[UefiVarStoreIndex]); + Status = SetupVariableStore (&mNorFlashDevices[UefiVarStoreIndex]); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to setup variable store, Status = %r\n", + Status + )); + ASSERT (0); + } + } else { + DEBUG (( + DEBUG_ERROR, + "ERROR: Invalid Flash device Base address\n" + )); + ASSERT (0); + Status = EFI_NOT_FOUND; + } + } else { + // No Flash device found fallback to Runtime Variable Emulation. + DEBUG (( + DEBUG_INFO, + "INFO: No Flash device found fallback to Runtime Variable Emulation.\n" + )); + Status = PcdSetBoolS (PcdEmuVariableNvModeEnable, TRUE); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to set PcdEmuVariableNvModeEnable, Status = %r\n", + Status + )); + ASSERT (0); } } - return EFI_NOT_FOUND; + return Status; } diff --git a/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtoolLib.inf b/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtoolLib.inf index b5f35d4782896761e7975a6e5c196ff0fab0d6db..fba1245e41ec4b146db79a821b8343247377af41 100644 --- a/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtoolLib.inf +++ b/ArmVirtPkg/Library/NorFlashKvmtoolLib/NorFlashKvmtoolLib.inf @@ -1,7 +1,7 @@ ## @file # Nor Flash library for Kvmtool. # -# Copyright (c) 2020, ARM Ltd. All rights reserved.
+# Copyright (c) 2020 - 2023, Arm Ltd. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -39,6 +39,7 @@ [Pcd] gArmTokenSpaceGuid.PcdFvBaseAddress gArmTokenSpaceGuid.PcdFvSize + gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'