From patchwork Mon Mar 8 11:29:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jose Marinho X-Patchwork-Id: 1448990 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=JP7vVui1; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=JP7vVui1; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DvGQz3Ynfz9sVv for ; Mon, 8 Mar 2021 22:32:27 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 93CC782A4E; Mon, 8 Mar 2021 12:32:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="JP7vVui1"; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="JP7vVui1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D8F2E82A60; Mon, 8 Mar 2021 12:32:17 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER,SPF_HELO_PASS, UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-ve1eur02on0620.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe06::620]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A651E82A4C for ; Mon, 8 Mar 2021 12:31:55 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=Jose.Marinho@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=JWlk/kt+t7fhdEsqwcqsFc3ICP+qWKoE5N9ucbo4rHM=; b=JP7vVui1fc4c5WZbEkuqp3KRsku+ICm5SvYiiLFYTDkUv2eUBQoRWxjBaHH7A/pfSDEceww0JRnHC2S1TEEwV/9hBmpIoDhY3u1HNYv7rnlo46fsmIsDx7Dx+xPl4XfYPTvbJQEkeakfKbyFfE0Df3QNU5aRYfCaIT7rFQ53A2Q= Received: from AS8PR04CA0230.eurprd04.prod.outlook.com (2603:10a6:20b:2f2::25) by PR3PR08MB5675.eurprd08.prod.outlook.com (2603:10a6:102:8a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17; Mon, 8 Mar 2021 11:31:54 +0000 Received: from AM5EUR03FT017.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:2f2:cafe::71) by AS8PR04CA0230.outlook.office365.com (2603:10a6:20b:2f2::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17 via Frontend Transport; Mon, 8 Mar 2021 11:31:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; lists.denx.de; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;lists.denx.de; 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT017.mail.protection.outlook.com (10.152.16.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17 via Frontend Transport; Mon, 8 Mar 2021 11:31:49 +0000 Received: ("Tessian outbound 72bd4bdd1f59:v71"); Mon, 08 Mar 2021 11:31:49 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: f797084adb832435 X-CR-MTA-TID: 64aa7808 Received: from 661eefa3a0de.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 732A4D4B-8115-47C0-BC4B-FFF98449A7DF.1; Mon, 08 Mar 2021 11:31:36 +0000 Received: from EUR03-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 661eefa3a0de.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 08 Mar 2021 11:31:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JGg7rSAr4bIwwMpzPixv6IAESra0cIhXjgw/VwAX2ffUXpLVZ0EuCtN8Rj8JbqlfHNfDsENAoedhm5PxuQ9sWHO83TvGVnUyQIJproNqIqF4DmphO+cmRdw4O/Pf5K+8C0u7NfXnh5w2GP57zbuoo/OUs5xz/7acFA6ylfccLYW60Znw4+8IIIPm+AAujQIfjCml/9Thn/rajjZDTKX8NGrJlkVxJz+Hr9QCBcM1yRkPco9jsrxBdH2himscj3EmMxxa7HeQqUQhxq6Vv3Z+4O8UpTixz3TXPWwgX18AT9uJxSKTMPLNObTypYSFju2cn1dGXJO80A2veZjMoefJFw== 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=JWlk/kt+t7fhdEsqwcqsFc3ICP+qWKoE5N9ucbo4rHM=; b=N38hI6VI6BqJCrNyk0eyU0XBk9jLxr83vto+Et3V9ZrZ6kZjqaIywcMHqc8dYjXSQ51ApvlOFwI/YIANsAWaaHFhwgFy7u4pBfyWFUDKuDWRUzhrD3uxdw8MAGRmEkOkcUYjfvBb/HQkFrkH6TQsUgXOCYf7Toc1C4oPg+enJ4PNjTsg67ieotZ/fOr/xhMYNKXR2jh/8EadurhuMHdt8mwReUMbCEINEE+mgFlQ9wh3P07Q6Txen1TGzgvZcCWv05RvyaUkrJ1Wcl7xaF+cm450bcMJsiDALqu7oqcxMEoGfhLl+KuDhEE6tdta5xkbYjY6quQm0YpH6Kyr3nDIQw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; 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=JWlk/kt+t7fhdEsqwcqsFc3ICP+qWKoE5N9ucbo4rHM=; b=JP7vVui1fc4c5WZbEkuqp3KRsku+ICm5SvYiiLFYTDkUv2eUBQoRWxjBaHH7A/pfSDEceww0JRnHC2S1TEEwV/9hBmpIoDhY3u1HNYv7rnlo46fsmIsDx7Dx+xPl4XfYPTvbJQEkeakfKbyFfE0Df3QNU5aRYfCaIT7rFQ53A2Q= Authentication-Results-Original: lists.denx.de; dkim=none (message not signed) header.d=none; lists.denx.de; dmarc=none action=none header.from=arm.com; Received: from DBBPR08MB6012.eurprd08.prod.outlook.com (2603:10a6:10:205::9) by DBAPR08MB5592.eurprd08.prod.outlook.com (2603:10a6:10:1a8::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.23; Mon, 8 Mar 2021 11:31:35 +0000 Received: from DBBPR08MB6012.eurprd08.prod.outlook.com ([fe80::5d51:f66c:7554:6920]) by DBBPR08MB6012.eurprd08.prod.outlook.com ([fe80::5d51:f66c:7554:6920%4]) with mapi id 15.20.3912.027; Mon, 8 Mar 2021 11:31:34 +0000 From: Jose Marinho To: u-boot@lists.denx.de Cc: Jose Marinho , Heinrich Schuchardt , Sughosh Ganu , AKASHI Takahiro , Ilias Apalodimas , Andre Przywara , Alexander Graf , nd@arm.com Subject: [PATCH 3/4 v6] efi: ESRT creation tests Date: Mon, 8 Mar 2021 11:29:34 +0000 Message-Id: <20210308112935.5782-4-jose.marinho@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210308112935.5782-1-jose.marinho@arm.com> References: <20210308112935.5782-1-jose.marinho@arm.com> X-Originating-IP: [217.140.106.50] X-ClientProxiedBy: LO2P265CA0158.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::26) To DBBPR08MB6012.eurprd08.prod.outlook.com (2603:10a6:10:205::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from josmar02Desktop.cambridge.arm.com (217.140.106.50) by LO2P265CA0158.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.26 via Frontend Transport; Mon, 8 Mar 2021 11:31:34 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 07c45286-f250-4ad2-3814-08d8e225c3d8 X-MS-TrafficTypeDiagnostic: DBAPR08MB5592:|PR3PR08MB5675: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:2582;OLM:2582; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: wUns5PT9aARUUJkd+AUB1AXfc7HaGT5Gl+x4x3uQUobNZyC5G82asgJgieZYYHX+QL4rwdKnViTYDsERNYz3dA/Eugv6GlmLwuV1WFio+BsTZ5tS3bsjTDfbov9s1fD0+nqYwSzdltBxYADfs/sbjFAhzj0q5cnkmCW1pxrgRGBjWdCG6A0ujv4DGRVDktzqVRoRnMKQRUqs7+4cFnv+F3vHe+Pc2jsdVx2fvYmDnsu2qZkdDQ2XFCDMdCR8HlxF84JOdh9t4Vc5ATWpZhavgHZIESG6SPwQ2i82XSwxlbo/lfzhQCdYDu5/U7MLoGxhSmf7VbfSbPOUINuLiXJpI1Bz6zzs4cHVQ0jMzoPPt0fZvnvG8YKwP6ChUt2J1w6Np1WIYoGrtfJlkord55kG8lomtVPPkinivHG8Tve8lqveVh+aeDh5cRAHU+1nNTaPVFUYcnseFhB4oC4tQFaqjfnpjyA57ZCUCFX9tVK4cTbSy3H+rydc1p3eOZGppB3tlpn/sKfG8IwcpRXtfOSexw== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DBBPR08MB6012.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(39850400004)(396003)(346002)(136003)(376002)(366004)(66476007)(7696005)(186003)(2906002)(66946007)(26005)(16526019)(316002)(54906003)(36756003)(2616005)(6916009)(66556008)(52116002)(956004)(8676002)(83380400001)(478600001)(1076003)(4326008)(44832011)(8936002)(5660300002)(6486002)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 1hCqzTXn79rAy4GsaqqutHe1EdfymYEMNWDIEbuyyJoqcgrPkXUMMC0T1F3nreREyycWbvsvUTEhW01ydttEX8ECXACc/mZVsEQCgybcy5PTUppzYX7vR1SnVQBSabag5/6ObaG09LxhSt+DJstqJDsW0j9qq0iIyE4JhiGhbqbAQgQZrnSukzaBPageo923tLgEgtADthWBJOr1CsHxg+au+D7/82iVznSpGcb3CbNKFtBKZNobksPqaREYq9RsevdTRXPCKTpBrOkDqU7+1KmiUrdSdq1ePaJgyVdSU112vJDxFWcvhoEaiEeiaXiN8DrbF1MyqwBaB+3O11Nd8Rc5nnNw9zpHMZBjFc50XYo0Fr0tV4x7nH8qmNN8sU7nP+Kojqz3QvmgEPeYi9CY2N4VmX6M9wh7o0db5Vr97S0pMwahXEfEeVjgU5l0t9mSTOJmgbO/qnDKDMSjvToF/t8ZjQ9RzW53e/11+Pbq9w9lzzmx1g0vDPlQ7b+s5UhSQOj6lvN2DIo03PJKXrwoTNdKAuVDKrcKCDkXL9rSk30lwKtciq4AfmgVh5Y17V+nVFkuq4dmyIlmEet7EICMH8szr3a97K+2Lwh+kF0s/NlSnfbLpXi2pfmPUaAqs8n6cI/L1jdnRTRRQ/DW0hhDPYMchaHQAE/43zEXYjcnKmfsoco+JsI+Zf3rkvX5+15LGBFbtiLCmIP5f6s/btD7Ki5QIpkopzAkLTZdHBsN811rBEohIkWOoQMdPyHKaD8xO5nX3V4aBqrxhG0CHjtC2FviHZr+p3BPpig74cPNFq4Qv5liAQYMSZjrS9M4o4ig5Y2Zv4vg0RZh9Iv2mPDaroQ6G5bJmj9L7SMt8ELklIOIdx2D1BN6sBH4fUyqTGULV7m1Cyf8oN6zLqOG7CcW40nTVxSbEQvBYkNIfwys4vqTpJofllvvGgFlOJrw2x9NKXRJ/BMdi3DDwAlWHCUr9jbF8Eu7H364LAXz9aXIM2MY/T7Z8/k2xP9da8imWzZg1j/ZaPISy7TVz4Ko4crGCQkir3ZRZnvmIA2YQfrTgvDnoRY38B6BAkvTx1Afg8m/SYGJVftzGuboHwI6w54Uq8G8t2/WCFesgtKd1vPCwOLLfuIo7AXONKI1QrHh8VrXf0VdyKj9k/q3Ah9CgTYmZd7mz8wIEKYuUGVGgjNlHNmHAGVA9h/XylT6Mx2mDs38ix0/stv5M4LCNIXddYhoEkOxfup9gIx3RkqOp1cNOH6AZ9uChy7IaoSPqg2GED8m81zC4Z07TPGOX1bmlV9iG1p7Etzh2hts6Dt797asrnKy4Nad+Dvc8ZxTOYDZ2gO6 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR08MB5592 Original-Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none; lists.denx.de; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT017.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 3962955a-583a-45db-259f-08d8e225ba75 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3Ur2VQfhNVaTDS7DvNDYsJH5LytXuuM766tFcXqy9Ja5yxk4txWoZPUUBM5cPKd+53zEij53jxj6uojZb1/7paTyxdjzeE6RTcDnRoFixdWyRGxv34ETrEAaksYIlJL0ZEW0tg/VGGoym2sXzjLNCSVFcMWMjiSz8hTHJ/WKLev+dKZoSp58/VJe5L33Y5cO5tGy3veTtjMo0B/QBRrEyrgT1polximwAJdI3qfDW2BBHRS85QSMbC/SJIJL0snrnRSTLrvw4Rac8ChQyNKespRu8Ea6CzRMBpLBrOWQg28q23DZUCzj1ajrpkIMVSK55/KSYVq6ydkofHZEu08FnJ6D+7LgOjlqur2SVn1SuQ7o64aA2vvq3pnJx1ujgTVeJacEGmPhQxhzkfP4wjyXgRWU4Hb4By+tXmnavpfZ5cCLhCPjUM/M3uhKPmQC02TpJvB2bky8tv/UP5iDrOUY9xvOYhv3OSuDFPUB3YAz3fopnna6qe6PPuDtUCNu/ZHlcTDHeGXwDDwk4hEZqgdNeLso3xRhvWJSSEWTT3crS3RzbKlBJmQCtGe8h7SMqxKIugNPKoA6VnQumdB8IFeNw/5MC2vA7hARfQmSvu/8TepquFn40TMRGDBtaxtVSNQp5J8Op8ttxaTxmOqQ6CQOhzcyFXE+Yu5/YGxnWmEPK30= 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:(4636009)(136003)(376002)(396003)(39850400004)(346002)(36840700001)(46966006)(336012)(44832011)(54906003)(356005)(26005)(47076005)(82740400003)(70586007)(81166007)(70206006)(82310400003)(36756003)(36860700001)(186003)(4326008)(2906002)(8936002)(83380400001)(956004)(5660300002)(6916009)(86362001)(7696005)(8676002)(6486002)(1076003)(316002)(2616005)(478600001)(16526019); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2021 11:31:49.9640 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 07c45286-f250-4ad2-3814-08d8e225c3d8 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: AM5EUR03FT017.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR08MB5675 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean This commmit exercises the ESRT creation in a EFI selftest. A fake FMP, with TEST_ESRT_NUM_ENTRIES FW images, is installed in the system leading to the corresponding ESRT entries being populated. The ESRT entries are checked against the datastructure used to initialize the FMP. Invocation from the sandbox platform: add to sandbox_defconfig: +CONFIG_CMD_BOOTEFI_SELFTEST=y make sandbox_capsule_defconfig all ./u-boot -d arch/sandbox/dts/test.dtb bootefi selftest CC: Heinrich Schuchardt CC: Sughosh Ganu CC: AKASHI Takahiro CC: Ilias Apalodimas CC: Andre Przywara CC: Alexander Graf CC: nd@arm.com Signed-off-by: Jose Marinho --- lib/efi_selftest/Makefile | 2 + lib/efi_selftest/efi_selftest_esrt.c | 264 +++++++++++++++++++++++++++ 2 files changed, 266 insertions(+) create mode 100644 lib/efi_selftest/efi_selftest_esrt.c diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index b02fd56e0a..58b27d6da3 100644 --- a/lib/efi_selftest/Makefile +++ b/lib/efi_selftest/Makefile @@ -72,6 +72,8 @@ ifeq ($(CONFIG_BLK)$(CONFIG_DOS_PARTITION),yy) obj-y += efi_selftest_block_device.o endif +obj-$(CONFIG_EFI_ESRT) += efi_selftest_esrt.o + targets += \ efi_miniapp_file_image_exception.h \ efi_miniapp_file_image_exit.h \ diff --git a/lib/efi_selftest/efi_selftest_esrt.c b/lib/efi_selftest/efi_selftest_esrt.c new file mode 100644 index 0000000000..d2b04b6a09 --- /dev/null +++ b/lib/efi_selftest/efi_selftest_esrt.c @@ -0,0 +1,264 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Test ESRT tables support + * + * Copyright (C) 2021 Arm Ltd. + */ +#include +#include +#include + +// This value must not exceed 255. +// An FMP cannot contain more than 255 FW images. +#define TEST_ESRT_NUM_ENTRIES 255 + +static +struct efi_firmware_image_descriptor static_img_info[TEST_ESRT_NUM_ENTRIES]; + +static const struct efi_system_table *local_systable; + +static void efi_test_esrt_init_info(void) +{ + for (int idx = 0; idx < TEST_ESRT_NUM_ENTRIES; idx++) { + static_img_info[idx].image_index = idx; + + // Note: the 16 byte value present in + // static_img_info[idx].image_type_id is not strictly a GUID. + // The value is used for the sake of code testing. + static_img_info[idx].image_type_id.b[0] = idx; + + static_img_info[idx].image_id = 0; + static_img_info[idx].image_id_name = NULL; + static_img_info[idx].version = 0; + static_img_info[idx].version_name = NULL; + static_img_info[idx].size = 0; + static_img_info[idx].lowest_supported_image_version = 1; + static_img_info[idx].last_attempt_version = 2; + static_img_info[idx].last_attempt_status = 3; + static_img_info[idx].hardware_instance = 1; + } +} + +static efi_status_t +EFIAPI efi_test_fmp_get_image_info(struct efi_firmware_management_protocol *this, + efi_uintn_t *image_info_size, + struct efi_firmware_image_descriptor *image_info, + u32 *descriptor_version, + u8 *descriptor_count, + efi_uintn_t *descriptor_size, + u32 *package_version, + u16 **package_version_name) +{ + efi_status_t ret = EFI_SUCCESS; + + if (!image_info_size) + return EFI_INVALID_PARAMETER; + + if (descriptor_version) + *descriptor_version = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION; + if (descriptor_count) + *descriptor_count = TEST_ESRT_NUM_ENTRIES; + if (descriptor_size) + *descriptor_size = sizeof(*image_info); + if (package_version) + *package_version = 0xffffffff; + if (package_version_name) + *package_version_name = NULL; + + if (*image_info_size < sizeof(*image_info)) { + *image_info_size = *descriptor_size * *descriptor_count; + return EFI_BUFFER_TOO_SMALL; + } + + for (int idx = 0; idx < TEST_ESRT_NUM_ENTRIES; idx++) + image_info[idx] = static_img_info[idx]; + + return ret; +} + +static struct efi_firmware_management_protocol efi_test_fmp = { + .get_image_info = efi_test_fmp_get_image_info, + .get_image = NULL, + .set_image = NULL, + .check_image = NULL, + .get_package_info = NULL, + .set_package_info = NULL, +}; + +static void *lib_test_get_esrt(void) +{ + if (!local_systable) { + efi_st_error("systable not found or uninitialized\n"); + return NULL; + } + + for (int idx = 0; idx < local_systable->nr_tables; idx++) + if (!guidcmp(&efi_esrt_guid, &local_systable->tables[idx].guid)) + return local_systable->tables[idx].table; + + return NULL; +} + +static bool lib_test_check_uuid_entry(struct efi_system_resource_table *esrt, + struct efi_firmware_image_descriptor + *img_info) +{ + const u32 filled_entries = esrt->fw_resource_count; + struct efi_system_resource_entry *entry = esrt->entries; + + for (u32 idx = 0; idx < filled_entries; idx++) { + if (!guidcmp(&entry[idx].fw_class, &img_info->image_type_id)) { + if (entry[idx].fw_version != img_info->version) + return false; + + if (entry[idx].lowest_supported_fw_version != + img_info->lowest_supported_image_version) + return false; + + if (entry[idx].last_attempt_version != + img_info->last_attempt_version) + return false; + + if (entry[idx].last_attempt_status != + img_info->last_attempt_status) + return false; + + /* + * The entry with fw_class = img_uuid matches with the + * remainder fmp input. + */ + return true; + } + } + + /* There exists no entry with fw_class equal to img_uuid in the ESRT. */ + return false; +} + +/* + * Setup unit test. + * + * Initialize the test FMP datastructure. + * Install the FMP in the system. + * + * @handle: handle of the loaded image + * @systable: system table + * @return: EFI_ST_SUCCESS for success + */ +static int setup(const efi_handle_t handle, + const struct efi_system_table *systable) +{ + local_systable = systable; + + if (!local_systable) { + efi_st_error("systable not found\n"); + return EFI_ST_FAILURE; + } + + efi_test_esrt_init_info(); + + return EFI_ST_SUCCESS; +} + +/* + * Tear down unit test. + * + * Uninstall the test FMP. + * + * @return: EFI_ST_SUCCESS for success + */ +static int teardown(void) +{ + efi_status_t ret = EFI_SUCCESS; + struct efi_boot_services *bt; + + if (!local_systable) { + efi_st_error("systable not found\n"); + return EFI_ST_FAILURE; + } + + bt = local_systable->boottime; + + if (!bt) { + efi_st_error("Cannot find boottime services structure\n"); + return EFI_ST_FAILURE; + } + + ret = bt->uninstall_multiple_protocol_interfaces + (efi_root, &efi_guid_firmware_management_protocol, + &efi_test_fmp, NULL); + + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to uninstall FMP\n"); + return EFI_ST_FAILURE; + } + + return EFI_ST_SUCCESS; +} + +static int execute(void) +{ + struct efi_system_resource_table *esrt; + efi_status_t ret = EFI_SUCCESS; + u32 base_entry_count; + u32 entry_delta; + struct efi_boot_services *bt; + + if (!local_systable) { + efi_st_error("systable not found\n"); + return EFI_ST_FAILURE; + } + + bt = local_systable->boottime; + + if (!bt) { + efi_st_error("Cannot find boottime services structure\n"); + return EFI_ST_FAILURE; + } + + esrt = lib_test_get_esrt(); + if (!esrt) { + efi_st_error("ESRT table not present\n"); + return EFI_ST_FAILURE; + } + base_entry_count = esrt->fw_resource_count; + + ret = bt->install_multiple_protocol_interfaces(&efi_root, + &efi_guid_firmware_management_protocol, + &efi_test_fmp, + NULL); + + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to install FMP\n"); + return EFI_ST_FAILURE; + } + + esrt = lib_test_get_esrt(); + if (!esrt) { + efi_st_error("ESRT table not present\n"); + return EFI_ST_FAILURE; + } + + entry_delta = esrt->fw_resource_count - base_entry_count; + if (entry_delta != TEST_ESRT_NUM_ENTRIES) { + efi_st_error("ESRT mismatch in new entry count (%d), expected (%d).\n", + entry_delta, TEST_ESRT_NUM_ENTRIES); + return EFI_ST_FAILURE; + } + + for (u32 idx = 0; idx < TEST_ESRT_NUM_ENTRIES; idx++) + if (!lib_test_check_uuid_entry(esrt, &static_img_info[idx])) { + efi_st_error("ESRT entry mistmatch\n"); + return EFI_ST_FAILURE; + } + + return EFI_ST_SUCCESS; +} + +EFI_UNIT_TEST(esrt) = { + .name = "esrt", + .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, + .setup = setup, + .execute = execute, + .teardown = teardown, +};