From patchwork Tue Mar 2 12:13:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jose Marinho X-Patchwork-Id: 1445996 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=uXloRQQf; 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=uXloRQQf; 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 4Dqbfw4jnJz9sVt for ; Tue, 2 Mar 2021 23:15:04 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3F4428207F; Tue, 2 Mar 2021 13:14:46 +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="uXloRQQf"; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="uXloRQQf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CC4588236C; Tue, 2 Mar 2021 13:14:43 +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.9 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 EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on060f.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0c::60f]) (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 8BB308207F for ; Tue, 2 Mar 2021 13:14:36 +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=S6pvNyEvN0nzPKGLUNohKL/HKBJbFdGwRkAvzRTMZYc=; b=uXloRQQf+FUFwAO46eLCtx0o7TDeBT4/FECmF4yULxhCoB+AIbqOpq4LolPnafVbGZMNURkIs2CrIDWRQXaZp/mX2YIcvkcLbhHxP+JWA7JoxNmKtcbcgSvHsw1MzSIKoIriIS/DMhpPExkkFnYZk59mO+Gbg2pETLn/pyyNHIg= Received: from DB6PR0301CA0091.eurprd03.prod.outlook.com (2603:10a6:6:30::38) by AM4PR08MB2833.eurprd08.prod.outlook.com (2603:10a6:205:9::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.29; Tue, 2 Mar 2021 12:14:34 +0000 Received: from DB5EUR03FT003.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:30:cafe::3a) by DB6PR0301CA0091.outlook.office365.com (2603:10a6:6:30::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19 via Frontend Transport; Tue, 2 Mar 2021 12:14:34 +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 DB5EUR03FT003.mail.protection.outlook.com (10.152.20.157) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19 via Frontend Transport; Tue, 2 Mar 2021 12:14:33 +0000 Received: ("Tessian outbound 9eff4099a602:v71"); Tue, 02 Mar 2021 12:14:33 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: c6e6840bea41d49e X-CR-MTA-TID: 64aa7808 Received: from 73d821e1ef28.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 87045915-84D0-4083-9D62-0F0774CD65E4.1; Tue, 02 Mar 2021 12:14:27 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 73d821e1ef28.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 02 Mar 2021 12:14:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z7OCCAd4fB40WnqTPbjBWqt2hEavpxWsPCStQPVIqRW2JkagqJN/8tmQ4BaFFHYK7q7KjZtiIhzBNVn8UScSr4Djud9fiy7E6opAfQOd0Rwdbo2vC7MwvTt0kxlLnJZ+GDpXgFuVKysj5L4BVsL6lqS87XmKXHDjjMzzHADBtjZ5kwTWzmetCqxAUNIRJW4XkkfIzuO+5EUWdcUH8mREcS7yA2Zyzt5ROik2EwRuX1fW/dXC6es14xma0bxQbSdltuLGk6kDMLp9N4P9dpEbkb3kLITU6XGH+/VNwb2N6s3x39h7w5qc12r4jqKXv7A629xP0luxsJ8LGGg+BGlb/Q== 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=S6pvNyEvN0nzPKGLUNohKL/HKBJbFdGwRkAvzRTMZYc=; b=IXJ3x1oxVJfEQ2y6D1WQN1PqlMqkYVtRH1SlNjEScQ6wsGv5xV51KyJNlh8FQeTu3b0xrmOuvcPLCilXS3C7bWHWOFS46cn1YZm89//ChOZrM38+kndYShaZuAitMQ3XMqXBiw5Z/kzJuFPtrhYwtKx9IUBeFh+evrT0U0auJCL5L/vvOaNEhWEpBt/R2/lNB6fsMUJ5AhMZQuCpM+5tKgg1bV86t5E0oPeNH25EF3YJiU4/pB2YHKMrpCKC5RMDlqauX9T64MzO7ZoGU/KM63bVOTF+JHuaUB3JjqHzZr4GjIgjKYjg9vGOWr0emGJ2H+ldVxDuNMUciW40Jnf3RA== 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=S6pvNyEvN0nzPKGLUNohKL/HKBJbFdGwRkAvzRTMZYc=; b=uXloRQQf+FUFwAO46eLCtx0o7TDeBT4/FECmF4yULxhCoB+AIbqOpq4LolPnafVbGZMNURkIs2CrIDWRQXaZp/mX2YIcvkcLbhHxP+JWA7JoxNmKtcbcgSvHsw1MzSIKoIriIS/DMhpPExkkFnYZk59mO+Gbg2pETLn/pyyNHIg= 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 DB8PR08MB5484.eurprd08.prod.outlook.com (2603:10a6:10:111::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.36; Tue, 2 Mar 2021 12:14:25 +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.3890.029; Tue, 2 Mar 2021 12:14:25 +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/3 v5] efi: ESRT creation tests Date: Tue, 2 Mar 2021 12:13:54 +0000 Message-Id: <20210302121354.23009-4-jose.marinho@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210302121354.23009-1-jose.marinho@arm.com> References: <20210302121354.23009-1-jose.marinho@arm.com> X-Originating-IP: [217.140.106.54] X-ClientProxiedBy: LO2P265CA0117.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:c::33) 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.54) by LO2P265CA0117.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:c::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19 via Frontend Transport; Tue, 2 Mar 2021 12:14:25 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 02dd9d11-ee01-49bb-c799-08d8dd74bd2c X-MS-TrafficTypeDiagnostic: DB8PR08MB5484:|AM4PR08MB2833: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:68;OLM:68; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: ESRlkjO85Yxf/agtGNm7xAkP7sYnPsSn7Km+kp/AodNFTqCs7NRJrsX/IY69VfESXNA4+v9cFzSiN91cnx5VTTMV4hH7ExoN0nvmQmTcn1sfE/xEojVpjLlfOqjzSCilLzsPAjm6uFawaMuNHASCEzHjDtIsBpCjaoi5g40BGgyKmuVWRKK6BFy2Phb81o9NezdbbJ6gXYbXALPBA2nFww8/RZWIgMmfraPiXvrycfpAVvdYgS32mH7VfCicV+mp52/YNY0wBeEkzJE5AQhiHLB3XmBLRZ0/YMxzHIyPvmxJ/Yx7lfZ4UNaeDP6sEZQu0RdNRYGEl05FV3z/iGws/eXtqQAj5ms1yQzCWjVHcboiI8HK9NnN6/uL88ZThl0EtSnWFWtfnovd1HCtgwVI9/uV22Ei/qsq9w1prFgbLkX5I3KPEpvtnMUfFMg9xGfcyCjFG2UzNgGUHXLhu8Ujz1i94Vfne9NaZNJamvkjOtKyx4Nva0omPbHjxSyW9iQGWSvDcwC5758eX/2WD8ti1A== 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)(136003)(39860400002)(376002)(396003)(346002)(366004)(83380400001)(6486002)(26005)(54906003)(478600001)(7696005)(2616005)(4326008)(956004)(8676002)(66556008)(66476007)(6666004)(16526019)(1076003)(5660300002)(316002)(186003)(2906002)(86362001)(52116002)(66946007)(6916009)(8936002)(44832011)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Zir2cQSlACNiJOG6K2/yCe2x62rpbJxVHsuT49i9td2CxcnF99GcYAak8aK3nMSa4p9H6L2MajzN7w1T27TYiTBzeb5KG5reZxk6K0Hzw8J42YgIx+i6RP0o2Lrx328PKVQO4JjM3mOuIuVmQabPjfkOmJjYw/jNIwzFBeCgyU99HSV3aWLO9be06Rmn/y1SH9a4XwkfzxsFtf2ziMUo9QbJyOgHMOnsnwe1DCLPtxNNy6/72e2NRHm4GQoK/KtpMbIrpvJrBiWbiMkT9JWCaWWfszDJYl2OKpJ/040/rzCvnGYuvLUYVa6aHflUXyG3/pdjCPvMZmZTU5G/xsSZp59Bzcn5gQgP2QekL5gaueEGdvaEfKECJF8g/qvzi4blN1jmUtUQslYbN9SnLOVjGyoqSzfYhpzwO1NvTP1RZ3eJnI9bPO0d3hif+XSPWXorHgU9Roev9ivKkqL3k1Wr9BEoFPP4oeZWlj0v9gmfrCvZ5nAyunIeyN3O7IOGrdV9gcuNDf26FGxoEUbbQBd4jg2q4X/+LcdK7U8OcVsA8nFEK9oLBnMce6pyTUPafQ6xy6guUGgFnAhYYY8yVR6PWgB9k3tQI4GdG/akR22C3j6G9+Nz1o152iE4IbCe102linaVP1pp7Ankmstp4htSEQczXYMu0HCEfDX7nD3VpuuWx0nfMjqSNEBrrWafih7BiNH9kzXWsKaXcmeCMKYNJkE90WyXFxTgtuLWtnwWRLZC9Yjs+QbL5cxkBC2NsVgWXt2BnN7UVzoFD7Tpdin6T0mGDiEu4p5jYr2XgRGyuPNwNDRhPGBvn2zLChHN327COUCklYOsftp1Z9Nk1wAJ5jRjmgG1mmnNOLEMf7BquGL8764CwGUAZJyG49bDwsofVj4pPD/L2pPkHY+CpnhmzBO+C/fQV4Rn0gO4S8fNafC+y+c/RIsSgjzLAEydei22SPKdl0E+hLclp59XTMeGCI5BOW1NzpTCkoBIrKJttMUQJhwUGf9edUjXiMHoDJCo0RR6sEOEp+tzlx3vI5oRW5OjpgfCn0K0ytBSBy21XldrXy5r4/O96khyDh+m2p7TJdMRwxbbA/CQUsqvVwTR3rFeWPE+mzSb0Nl/7EKS4u4oh3ZDuNzGr5ZYkLk9nRbqrF17pEnrcogfxIUK+0PfbusGNYDBycwJHB668tbmwIlTya4TCUOdqKCimk7EDriTd8/vmau1h0+hHqJbJh3TbSWBQ2IbbIYAe29Wpk146wREZkqJwruYKz3eUH58n4UKKjcu1CMz55qyJrLcSp0C0sWW5+OuqmpGeC/sf8BSRuWuKFIo8AeEa2EsXZirJYVi X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5484 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: DB5EUR03FT003.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 53a910bf-1dc0-4dfb-94ab-08d8dd74b86c X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +mOI9zZ7u+6IJhtLLPukkXrMqd45noKVx97QYwOKmTJVba9KReGNqB3Dne6+Yy96g/OSO54zFJyOUIS1g/Y9RBSnsXXY2e67wdUpqMTNmLnCULDvQc9wr4IwFJoTHAz1uevyzzepWAIs6Qu0+EmZq3TlwZ82VSl6KrJMfotw/NbCwoBwAH6+QerzfWONRGHPXuK3AuluD0nCfXpQQi/BUHtiVA+nIOHxO44AzQ8xR6LFM98Dfh49Ty8LrnaFckLd79R2EmRRGp0VrFLXwc8ZNcRhYWKnlJ34NfJ+hDiT+EfqB9N1H70PNAhUN24sP4t/iMJIOTi9su770JDq82UfMEsPbVAQ9WgbJDFSnoAoTc8WCLHwvTlk4gjVh5iohkYpw49EZKMfTkSr1yan/tPQnEe1XK/8Si1AJ21ZoWGVYFr7cISNslHgmqMPlEYD8M0/YW/2cS26gFhf9HInzr1Ofy1Ws08clzpYmNROrtEpt+L0vdQYpT6Z2JUtUD+HiX3/r9z1jliMXapBz/Oextj7jCXwfO+xTIqb6vp0fT47g76bHqdV3U18bmRTiPTRd34VWk2DLqnCQVgO8iLdJhXFp1JJYs4VbjKVPpl7wL9+X3bk9BePnqnWB8sv4ZbrZ5cSCKfmFFkYE4vlEoZs9ts7AqtjeFZSh4Ltzgd2EGyxfas= 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)(346002)(136003)(39860400002)(376002)(396003)(36840700001)(46966006)(6916009)(44832011)(1076003)(70206006)(83380400001)(8676002)(336012)(7696005)(36860700001)(6666004)(26005)(47076005)(54906003)(82310400003)(70586007)(4326008)(2616005)(316002)(8936002)(16526019)(186003)(956004)(36756003)(6486002)(356005)(5660300002)(478600001)(86362001)(2906002)(82740400003)(81166007); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2021 12:14:33.2628 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 02dd9d11-ee01-49bb-c799-08d8dd74bd2c 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: DB5EUR03FT003.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR08MB2833 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 two tests. test 1: 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. test 1 invocation: add to sandbox_defconfig: +CONFIG_EFI_SELFTEST=y make sandbox_capsule_defconfig all ./u-boot -d arch/sandbox/dts/test.dtb bootefi selftest test 2: The test is part of test_efi_capsule_fw3. In order to run the test the following must be added to sandbox_defconfig: +CONFIG_CMD_SF=y +CONFIG_CMD_MEMORY=y +CONFIG_CMD_FAT=y +CONFIG_DFU=y The ESRT is printed in the u-boot shell by calling efidebug esrt. The test ensures that, after the capsule is installed, the ESRT contains entries with the GUIDs: - EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID; - EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID; test 2 invocation: sudo ./test/py/test.py --bd sandbox -k capsule_fw3 -l --build Signed-off-by: Jose Marinho CC: Heinrich Schuchardt CC: Sughosh Ganu CC: AKASHI Takahiro CC: Ilias Apalodimas CC: Andre Przywara CC: Alexander Graf CC: nd@arm.com --- lib/efi_selftest/Makefile | 2 + lib/efi_selftest/efi_selftest_esrt.c | 227 ++++++++++++++++++ .../test_efi_capsule/test_capsule_firmware.py | 4 + 3 files changed, 233 insertions(+) create mode 100644 lib/efi_selftest/efi_selftest_esrt.c diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index 7d6ea30102..017b191a46 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..b053b2e6c6 --- /dev/null +++ b/lib/efi_selftest/efi_selftest_esrt.c @@ -0,0 +1,227 @@ +// 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 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) +{ + for (int idx = 0; idx < systab.nr_tables; idx++) + if (!guidcmp(&efi_esrt_guid, &systab.tables[idx].guid)) + return systab.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) +{ + efi_status_t ret = EFI_SUCCESS; + struct efi_boot_services *bt = systab.boottime; + + if (!bt) + return EFI_ST_FAILURE; + + efi_test_esrt_init_info(); + + ret = EFI_CALL(bt->install_multiple_protocol_interfaces + (&efi_root, + &efi_guid_firmware_management_protocol, + &efi_test_fmp, + NULL)); + + if (ret != EFI_SUCCESS) + return EFI_ST_FAILURE; + + 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 = systab.boottime; + + if (!bt) + return EFI_ST_FAILURE; + + ret = EFI_CALL(bt->uninstall_multiple_protocol_interfaces + (efi_root, &efi_guid_firmware_management_protocol, + &efi_test_fmp, NULL)); + + if (ret != EFI_SUCCESS) + return EFI_ST_FAILURE; + + return EFI_ST_SUCCESS; +} + +static int execute(void) +{ + struct efi_system_resource_table *esrt; + efi_status_t ret = EFI_SUCCESS; + + esrt = lib_test_get_esrt(); + if (!esrt) + return EFI_ST_FAILURE; + + if (esrt->fw_resource_count != TEST_ESRT_NUM_ENTRIES) + return EFI_ST_FAILURE; + + /* Update the ESRT. */ + ret = efi_esrt_populate(); + if (ret != EFI_SUCCESS) + return EFI_ST_FAILURE; + + esrt = lib_test_get_esrt(); + if (!esrt) + return EFI_ST_FAILURE; + + /* Verify that the number of images remains the same. */ + if (esrt->fw_resource_count != 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])) + 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, +}; diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware.py b/test/py/tests/test_efi_capsule/test_capsule_firmware.py index f006fa95d6..3a7c2e1ac8 100644 --- a/test/py/tests/test_efi_capsule/test_capsule_firmware.py +++ b/test/py/tests/test_efi_capsule/test_capsule_firmware.py @@ -229,6 +229,10 @@ class TestEfiCapsuleFirmwareFit(object): output = u_boot_console.run_command( 'env print -e -all Capsule0000') + output = u_boot_console.run_command_list(['efidebug capsule esrt']) + assert 'AE13FF2D-9AD4-4E25-9AC8-6D80B3B22147' in ''.join(output) + assert 'E2BB9C06-70E9-4B14-97A3-5A7913176E3F' in ''.join(output) + output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])