From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (EUR05-VI1-obe.outbound.protection.outlook.com [40.107.21.58]) by mx.groups.io with SMTP id smtpd.web11.28441.1684508159183533315 for ; Fri, 19 May 2023 07:55:59 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=OK9KruIo; spf=pass (domain: arm.com, ip: 40.107.21.58, 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=OK9KruIoZM7/FQLQs3v+Z1VA8vhZyrn6J/3xSQGGSSGuc/Lk8+hRYRmkuDaWhjjtALY7zgzeTd21APFDSqhjAZWaM97K4mX/q2/PHluUd3S2s6Rn0HxIHFSXEUDtfZQzIhZxb3SZmi1SyXoI6FgvfGpBYNw7f9YKStG6gsKcGEw= Received: from DU2P251CA0027.EURP251.PROD.OUTLOOK.COM (2603:10a6:10:230::33) by DU0PR08MB9226.eurprd08.prod.outlook.com (2603:10a6:10:419::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.21; Fri, 19 May 2023 14:55:53 +0000 Received: from DBAEUR03FT043.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:230:cafe::b0) by DU2P251CA0027.outlook.office365.com (2603:10a6:10:230::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.21 via Frontend Transport; Fri, 19 May 2023 14:55:53 +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 DBAEUR03FT043.mail.protection.outlook.com (100.127.143.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.7 via Frontend Transport; Fri, 19 May 2023 14:55:53 +0000 Received: ("Tessian outbound 99a3040377ca:v136"); Fri, 19 May 2023 14:55:52 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: fe9ca0d7265a8522 X-CR-MTA-TID: 64aa7808 Received: from b57b2aa596ad.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 9B57A631-FBBF-40E5-8DF2-4AF14ACB63C6.1; Fri, 19 May 2023 14:55:45 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id b57b2aa596ad.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 19 May 2023 14:55:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e6/ze9UuNP4xeteXwMbLopyw36n4QI0Bj14KEGs32eCxPMSdui19uw485Ajb1LeB0GVI8iHQVLilfyVbzGJQDPRPG1rOqgM16b4hiY6aB6cRmQn8AOvcwrAf2XH0SXBPH4bH6ckQqdZq0fngyCNExRCRuBNMchr2jgmtuwFxIJFglGnMtwO+ZB0BRZ5YTtUdn3EXkGwcrwis8aPj9B6Fztuc1i+ZtvuiQewfdT28hGBcJPbUJJSiunxaEnl/vSerPOOvN2ccDzpe/4vBnRj4oaAM8MIAZN90EMpu+Ai2lKUIE6UmjK2q0ec/m54iPiMCMLQF67nBaxO9GiiIjgmLUA== 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=Ptybjwc5cneYYtV8/v/DCtI3svjmxSl+X92Lzt6ww+B/ABa3+m8opk6mi0LatoKlM4GZYXXhNsDK4yz89XbePmb693wHcVPUZf0SOxi8nWkq/sHPpt2JsFLrGPXUaARfs/Km5RtmHfx5iUj/jJT9azk/3z1yAKvL5AqRkng8/TlDjJTmkkE3g1BISyrlJSKvZ6xzFxWCozaG+vHItKJ+lEgidrtmY6XJWhQHiQ9CJM0YTtFhu3UGH84naOIBH7Is+j9g7D0B5dscOagjv4422yUw5kHwB2/CjLhIYIBTMZm86Y+o6/CKW4YkQZlU2hSlXPYBgHDimr9WzrkwtNJZTA== 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=OK9KruIoZM7/FQLQs3v+Z1VA8vhZyrn6J/3xSQGGSSGuc/Lk8+hRYRmkuDaWhjjtALY7zgzeTd21APFDSqhjAZWaM97K4mX/q2/PHluUd3S2s6Rn0HxIHFSXEUDtfZQzIhZxb3SZmi1SyXoI6FgvfGpBYNw7f9YKStG6gsKcGEw= Received: from DUZP191CA0028.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:4f8::24) by DB8PR08MB5354.eurprd08.prod.outlook.com (2603:10a6:10:114::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.21; Fri, 19 May 2023 14:55:43 +0000 Received: from DBAEUR03FT018.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:4f8:cafe::4f) by DUZP191CA0028.outlook.office365.com (2603:10a6:10:4f8::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.21 via Frontend Transport; Fri, 19 May 2023 14:55:43 +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 DBAEUR03FT018.mail.protection.outlook.com (100.127.142.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6433.7 via Frontend Transport; Fri, 19 May 2023 14:55:43 +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; Fri, 19 May 2023 14:55:43 +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; Fri, 19 May 2023 14:55:42 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , , , , , Subject: [PATCH v2 3/5] ArmVirtPkg: Fallback to variable emulation if no CFI is found Date: Fri, 19 May 2023 15:55:38 +0100 Message-ID: <20230519145540.46700-4-sami.mujawar@arm.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20230519145540.46700-1-sami.mujawar@arm.com> References: <20230519145540.46700-1-sami.mujawar@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DBAEUR03FT018:EE_|DB8PR08MB5354:EE_|DBAEUR03FT043:EE_|DU0PR08MB9226:EE_ X-MS-Office365-Filtering-Correlation-Id: 7afbd10d-5b33-4e26-0a17-08db5879249e 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: MLkyXNQcw8xNWQPV78hpUn4vpZwsN/Yv2B+w6tSdqC5WMlXra60nHTJYRwcPzgjNbAWq56tIkF9S8APOl+5wnlaDIL0fIrCU92GQMTqWb94r3GwiCaypOpPwo843wrwm6tGhMZNrBgi0FWeUnYFQqeycyCkYdu3NvzdkB78D7CR+bmoemWgbF8b6J65NPB/VplHEAG3Pz2a2w2hVtr/olV0PNiEyV19hzKG8jPYnMvn2PtZ7T3a4nkrcTD8e2bst7OXx49If+D9VxpUzLN0sa8cAFPgunWmFqYjqfr9xesxpnPVkqX1hjeuG3eFq28A+TAlJdDVsbw0ztKLfEEGgnXt6lCpHFw9lInESR1XzejaZkRRZwkGFISH70wMNgyZ2eOk1IriKj44kXtlRL5pzehWnXK/rhs9H9zOrEt6/oh5emL8GZkVxkag2YtpLEcBn6Oe+m828OFwHHPf4PR47YvcSJ6eImOJgE6FMD0c28ua5pqDEnY+u0qBgDAyqkP6VmuPmODVSRkQbPVb0TvCBrkQiqTtpl7J0wcBn0sptiy8egZvZcNZq00DYBBooWigh8FxO3VpYCLzUiBMp1ye9Ys4CfmDpMXGSh5wOeie73D2DZhZPFQE0gKRpsQ+BxUKCiILS/k4/NPxBemZKkXTIL7jyy15Yl5HnY5aguQLKHbHNMiZ3qzN1XLRPkd3xKlYDzkOvcE5VeImci/Td6hEnfniptFrA0waUiukoydKxrOAeDHl5Hu6dFEGnSJeiU47zdys7PnugMYlKhkhPix0yyw== 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)(40470700004)(36840700001)(46966006)(70206006)(70586007)(2906002)(8936002)(8676002)(5660300002)(44832011)(6916009)(316002)(4326008)(41300700001)(86362001)(2616005)(426003)(54906003)(47076005)(40460700003)(478600001)(36756003)(6666004)(40480700001)(7696005)(26005)(186003)(336012)(1076003)(36860700001)(83380400001)(82310400005)(82740400003)(81166007)(356005)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5354 Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT043.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 74fe1bbc-57c5-4871-1681-08db58791efe X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RresOGG0gcTEPP0SOsPkKnEb5LH39BtImCnbJz3uurtLsnwxUf5kd9pIMfwVZFO0ANjQK6ilngcf7HPSxsYTp9LvdH5DIWmlnTrULjATCNGBoSJ6IhTfGdYN8itkQCC7sdJaiG9Hc+yu6BdcsstPM8441NyljUOCzQTKEoVoMb/Yp71mojtH02X6aZar7Y2wTLT0JmuGlfwI7Pgkf8KJuVtHZ/akYTFkuhHN1FbVXye4nTSLmtSWcT5YnXro+UVgiRmD5dyHGmklUqS2FBACSE8YTUj+pSMKsCwLG8+xhQPFexBrgtta1T3EX5218nWZXlYoJd9r0/6TYaSEGXDOOTVg9zrNUn1PgeW+eZaE04XsWKtx/n/zutcJbCMGkIst9yki0A/j7lSGxcd33OCqeQFQc6tgpAH0tK7QMDy14Lxh48dtZXI7p6sBzT+PtNNjAGhoLNwG/00icOIcjxdRcj08/FH5sU9llJ6ExDgMP26YxehcrcfIaR8GLPl0C6K9kVLCVI0/eWkrSzx1KJhvpe8C7iyRM55dnepxtOpYzIspPeW0tlWzOmQBqhijfRS034I3fX+4ztQDoLQwwpv7M5hcWl4Ws6eIfbD4DGmIUOynzhFn6WqsTc9UEdwjs62BBOai5XrhrGvXDmZdRHAcMR1cXkaqM48UOWULNQ2+SANJmSFSQhcCKAfPRB5nBOwxTfPCPlEXvODZe1yoWaXu2iKucQKgo/muJfZ0nO7meApwJ65gz1TC+g9MJC5FobCJ 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)(376002)(346002)(39860400002)(396003)(136003)(451199021)(46966006)(40470700004)(36840700001)(86362001)(36756003)(54906003)(316002)(70586007)(6916009)(4326008)(478600001)(70206006)(40480700001)(6666004)(82310400005)(8936002)(8676002)(5660300002)(41300700001)(2906002)(44832011)(81166007)(82740400003)(7696005)(186003)(336012)(2616005)(426003)(26005)(1076003)(36860700001)(47076005)(83380400001)(40460700003);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2023 14:55:53.0428 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7afbd10d-5b33-4e26-0a17-08db5879249e 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: DBAEUR03FT043.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9226 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)'