From patchwork Sat Feb 20 17:52:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jose Marinho X-Patchwork-Id: 1442657 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=85.214.62.61; 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=CR/5l7bk; 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=CR/5l7bk; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 4DjbfX4pV6z9sCD for ; Sun, 21 Feb 2021 04:53:56 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0433682755; Sat, 20 Feb 2021 18:53:48 +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="CR/5l7bk"; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="CR/5l7bk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3A53A8269F; Sat, 20 Feb 2021 18:53:45 +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 EUR03-DB5-obe.outbound.protection.outlook.com (mail-db5eur03on060d.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0a::60d]) (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 3962E82755 for ; Sat, 20 Feb 2021 18:53:39 +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=0OFusIGdAq7kGTZfPGK8s1jv4Yit4QJEyKEs/30SC4A=; b=CR/5l7bklv/iyjqxNALd0OL6D/xKtlLb15patyr+lLTC3xCathuB7QaAtM2deSpkwzE2wQbulc1K65WN3oc1iFYwX+oKFO7nXL5UcBq8hLfoIN+cFPVNGFx8JOh7BvITE91WQcgwRa/P7DIxH7uWNNCFKuLjG2b1wkLJ7KJ1SzY= Received: from AM5PR0502CA0017.eurprd05.prod.outlook.com (2603:10a6:203:91::27) by VI1PR08MB4333.eurprd08.prod.outlook.com (2603:10a6:803:101::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27; Sat, 20 Feb 2021 17:53:37 +0000 Received: from AM5EUR03FT023.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:91:cafe::2b) by AM5PR0502CA0017.outlook.office365.com (2603:10a6:203:91::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27 via Frontend Transport; Sat, 20 Feb 2021 17:53:37 +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 AM5EUR03FT023.mail.protection.outlook.com (10.152.16.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27 via Frontend Transport; Sat, 20 Feb 2021 17:53:36 +0000 Received: ("Tessian outbound fb307b4548b2:v71"); Sat, 20 Feb 2021 17:53:36 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 3765398f6f655de1 X-CR-MTA-TID: 64aa7808 Received: from bb211c913cf1.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 8FAD6AC3-B465-4A5E-986A-730274080907.1; Sat, 20 Feb 2021 17:53:25 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id bb211c913cf1.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Sat, 20 Feb 2021 17:53:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jQTn4V0WPiikNRLw2cvf2yyiQssaTR5L/RjcCKequa+LYcOPuVvoWL86cOs03D7Zo+kPeSZKg1pEnC8npTyvUz5Fn8I8o8PgkzMDUF7XTbFGCD2ehLRWvAAS7LSjZ23QYgdHo8mYInDU+xjspalqrv5aZW8zaevzm6Qm2Rbb9NjVqNyPjq7nWaU8ziTvHKOqODhZVhrMca6Y+OOrb2qs5SxZKlmrIRnpg1BVyR5JYba7WSTcMk1pFnxDlwS3Uwm7HwV+agb6KFyVQM2AI4eQQawjrCywiAYLu+VBH3IpxcnWhlZwvn3uGEEAzwczP+lyl+es2/0d3thuxAbiq3S6/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=0OFusIGdAq7kGTZfPGK8s1jv4Yit4QJEyKEs/30SC4A=; b=e/N0e700unaylQl10OGYHvajXgr+gQ8u88cGq17c0BwV9WNvpg7sMmc3AKdFcsVmAh+gC6QrbLJXqE2HwNMihZjjkkc+oPDdf70/2M0v0JR4H+HDQ0aMvpGvEFSK1u9yAPo5v9KD9foDk/uumTE+K24gczw0fuTmCVPKOwSElGELt4G5wQKQk1HluzQc0RSMORN6rcrpvGT9TOPH97tU7sCZ407qWaWpQ9u6hfBcEJTDFh3AYxrbLaJAvqrBWH2/xXM+gCtF9JOF9m2hG/1CvqjBQmV0hVWly9OW91pC7xZB/e3o8sUkEdU+kDZdm3FY629DH7cizLdEK2P8CAX0dQ== 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=0OFusIGdAq7kGTZfPGK8s1jv4Yit4QJEyKEs/30SC4A=; b=CR/5l7bklv/iyjqxNALd0OL6D/xKtlLb15patyr+lLTC3xCathuB7QaAtM2deSpkwzE2wQbulc1K65WN3oc1iFYwX+oKFO7nXL5UcBq8hLfoIN+cFPVNGFx8JOh7BvITE91WQcgwRa/P7DIxH7uWNNCFKuLjG2b1wkLJ7KJ1SzY= 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 DBBPR08MB6170.eurprd08.prod.outlook.com (2603:10a6:10:200::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27; Sat, 20 Feb 2021 17:53:23 +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.3846.044; Sat, 20 Feb 2021 17:53:23 +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 2/2 v3] efi: ESRT creation tests Date: Sat, 20 Feb 2021 17:52:52 +0000 Message-Id: <20210220175252.11619-3-jose.marinho@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210220175252.11619-1-jose.marinho@arm.com> References: <20210220175252.11619-1-jose.marinho@arm.com> X-Originating-IP: [217.140.106.50] X-ClientProxiedBy: LO4P123CA0264.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:194::17) 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 LO4P123CA0264.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:194::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.30 via Frontend Transport; Sat, 20 Feb 2021 17:53:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5b493be5-0da5-4b41-cc29-08d8d5c872be X-MS-TrafficTypeDiagnostic: DBBPR08MB6170:|VI1PR08MB4333: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:16;OLM:16; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: OaEP3rM1bNli+rw5xsGDQs8/hu5skl49MXf3VXI8T2/7iF6AzvBQPEALHCRBrYUS7d49rVyMrMnjj7xKkodxkSsNQOkIb8k2HDM7PvpXZwd5b1v24C6v47GnpQKiQ2lZBbQZRSffkCA/w8kohWVmT4kmwpVB+mhNMtV1VT6b9rPnl9G1QprNmsom1cbdWtxp2t1IhpjGKQGK4B0WkEWexGFd/OheWbksrpHoLFdASHtRa/rZ4KgZft64OUFSSbs5AtI+L4SVONDX25fpsk2tsI1ofHWZMjDGRdyXfzLWOYnOdZUbmekbFtwKcLuYsF8lQSikc7MUNB1gMtAOAQihCb5CR3NZPet8Q+q8m1Ft3C/r12+CvyrS3e7xArQz25Fn+1vzTZmjbEbto5zQKdup6+zapFOks5IXKqDA79UF9KcH2Mf+I54WFz8J36/OahUaCsgkO+H+n0hwXBH1Llw136T8/05/C8Bq2RpSn+HgByt7FK3zihWWWhjkCq7+CyajOwj1TS4hnVDReKRKAFS8Gg== 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)(39860400002)(366004)(346002)(136003)(396003)(376002)(16526019)(66946007)(1076003)(54906003)(5660300002)(186003)(26005)(66476007)(66556008)(6486002)(8676002)(52116002)(7696005)(30864003)(956004)(44832011)(36756003)(478600001)(2616005)(8936002)(6666004)(86362001)(83380400001)(4326008)(316002)(6916009)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: PPQYo1EGwd6rzps6ePQOCoAjKI6j/H95+7PhZ0tAYL0/r4X3Wg1um6EA96VVMLxalzo0++WEDvlsn/Lcm0lCY6B6HYySPtMFTmJYuYXOYqlFuDjcKxEIaFdNhDoE+fIdDXRjfznpVFZv1AxYKEHGwxvwMGiNkUA+pnZuaGsZdu0WRHTJD1XkKcP3HBT4jRVqNqUSj6copvSL91cPH9VVWqUj5a9aKuC7i/dHJs3s/eh464i7ZtgTT6H0BEvmnGjZmKxSEjpaiZPam0Lke9IlGV2SYwU1Vnv3afLVIpvBHzr/02RSiNH6Z13kAPWgiyeyLLbHi5KqEsXxzXylrRWnMzmRkj0ALZO7aAak4lL5BtnffdvTPLwS8MK7Y44CxIUEH+4k+5PalZr+NlKq5ftcaqYMKco4qcUx9DpUt0OssL7VVmZn3PSVr+uoUXWFEZRDP0tD0IN12ofJgyc9zvUmbcHYCg9sW/3WBMaJpxEsDO7qQ0OJrOBY7AygCl4m/7ITvGDZL3XSefOf8DKH8aoT6uNhQx8pO5BPVEKvfcTh4QERf9bT726G9jZQXKrKmdqto3tM5Es7IqDqN/UPKEOVEk49bsw2uJxoWHoM6brXiQfQIWyekirbyLGWTG6h+5iEEHQ38Elg0Hc5QKNwvXaWO0A+BbWUx2WRPDJ9j71m0yl8jfMocfS9MqnWXejf9aGZupbZtKwJwThiwMwCPS3ppYqX4RPLZKBnqVpBj2vKC0YDrf657zQprOx2Y+4KHTEfHk23KbCt2JKzrjZvzaXtdXsjnQVdGnVQI34ngR7Cfs2hylbyh2wefKzFzzCUfFYiqSbrV4Y29jKbkIWJew2GDBEbPTexU+Dm0Vumwo321DgOpOANaVXdcfJ+6aybiHJm/8RDbZuZImW+WbntCOSyh10BfzNXWOxkIkPvDutw5mNwCicWEevyv49iS2CuYwnKBHVTI9dAK6CRLVu2V2ESjFPB1Zq9C1wvlIAbJvEGJdk61ca3rW8vEt86m6mNHzbeQJ64gqBKcQ10joht/Qz2eiFUAGbCoqZRISYW+kv/kBSJvR+S8JApog2JWbZp/3m5iAMNjDZaqkBIAIpHNrfJDf38qOsDxoZ1FR7ZImc8SDwSDEPuh/dh9W37hTpnB8ZtCfi8mBEf45IqZLXLwUwSXKRKfrEnIg4ZS8H1A4zNvQ5RB1Be1NRMI8A5mqU0lszzysNf9P66CheG4VoddY30Kuw0lfVmf4AupDUrdhy6VNz/VZFilj+2vBt2aXvuASq9xTjdSC0wzlC3qXvu3T9/i4imv1KGsc872b/4KkXbLGbv7nQeQjU2upSFTqX8LTXZ X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB6170 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: AM5EUR03FT023.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: a18e617d-8afe-470d-2b65-08d8d5c8672e X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5Cou4nY1+5H1XBJvvZ3ZzSuEXcK3xdYDb5MIYl41JEpsZ+lLw+pQC1nrCriEVoezS9db2gTAd8zqDZTTZ2amQdS4vDhR23HhV1d6S0lzhxZ6LcKmBr2782N6huRARga9wXuYt+X62N53jmrjw1ydf3BQ+zUHDG6QHLvpH2L9jAwHJlP5LDykPFjXgaf/MNznFDLa9qmZRcx/yb4s5kuF16T08teHnX4ntLNPhnRJEt6jhsUyDkXPwB/wGh/Np4AJ8FTzSzzCEPkRKXAOyEg+sy2UsDg0+HkQWB/1RVmTH3RQmfPpISc/DncoemIzAI1Cq2PJewPDYaaiTgNQSijY7WoWsuDRBopvp7INzeuS/wxa41MXbjqnmDjJ3a7X5KEyAOBfPg1HuRz7a/fGR+ah9ZnY9R3SZNvwWdNDCAyreYPyi6EWVkzGEkMRZPn+qACd1v/yjMIv+PZsJCghtirFiSpiIImJShrZ8yoji5qkqlO+Xza91eWE9uLJlZ+xijYBTdxAiND/Bc1RMxwcaDwvuS0t+jTfRsq9utqIGGLBqyFwp2w7p/D5pt4PY/ZHSvIHK2CqDe64PXakITmhxRrP71oPKStmlETfbNkRSs8xGm648VbmFzDw54abnZikxoOx/PL+yrVdoTCBsANWP1nz21Z89W5JYZYj09cGJwNCxs4= 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)(396003)(376002)(39860400002)(136003)(46966006)(36840700001)(30864003)(186003)(82310400003)(36860700001)(82740400003)(316002)(81166007)(83380400001)(5660300002)(44832011)(478600001)(1076003)(86362001)(4326008)(54906003)(356005)(6916009)(6666004)(36756003)(2906002)(16526019)(6486002)(956004)(70586007)(47076005)(8676002)(8936002)(7696005)(26005)(2616005)(70206006)(336012); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Feb 2021 17:53:36.7507 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5b493be5-0da5-4b41-cc29-08d8d5c872be 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: AM5EUR03FT023.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB4333 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.3 at phobos.denx.de X-Virus-Status: Clean This commmit exercises the ESRT creation -- introduced in the previous commit -- 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: make sandbox_capsule_defconfig all ./u-boot -d arch/sandbox/dts/test.dtb ut lib 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 --- cmd/efidebug.c | 64 ++++++ test/lib/Makefile | 1 + test/lib/efi_esrt.c | 191 ++++++++++++++++++ .../test_efi_capsule/test_capsule_firmware.py | 4 + 4 files changed, 260 insertions(+) create mode 100644 test/lib/efi_esrt.c diff --git a/cmd/efidebug.c b/cmd/efidebug.c index a7dace2f80..5a9ff2bd9a 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -129,6 +129,61 @@ static int do_efi_capsule_show(struct cmd_tbl *cmdtp, int flag, return CMD_RET_SUCCESS; } +#ifdef CONFIG_EFI_ESRT +/** + * do_efi_capsule_esrt() - manage UEFI capsules + * + * @cmdtp: Command table + * @flag: Command flag + * @argc: Number of arguments + * @argv: Argument array + * Return: CMD_RET_SUCCESS on success, + * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure + * + * Implement efidebug "capsule esrt" sub-command. + * The prints the current ESRT table. + * + * efidebug capsule esrt + */ +static int do_efi_capsule_esrt(struct cmd_tbl *cmdtp, int flag, + int argc, char * const argv[]) +{ + struct efi_system_resource_table *esrt = NULL; + + if (argc != 1) + return CMD_RET_USAGE; + + for (int idx = 0; idx < systab.nr_tables; idx++) + if (!guidcmp(&efi_esrt_guid, &systab.tables[idx].guid)) + esrt = (struct efi_system_resource_table *)systab.tables[idx].table; + + if (!esrt) + return CMD_RET_FAILURE; + + printf("========================================\n"); + printf("ESRT: fw_resource_count=%d\n", esrt->fw_resource_count); + printf("ESRT: fw_resource_count_max=%d\n", esrt->fw_resource_count_max); + printf("ESRT: fw_resource_version=%lld\n", esrt->fw_resource_version); + + for (int idx = 0; idx < esrt->fw_resource_count; idx++) { + printf("[entry %d]==============================\n", idx); + printf("ESRT: fw_class=%pUL\n", &esrt->entries[idx].fw_class); + printf("ESRT: fw_type=%d\n", esrt->entries[idx].fw_type); + printf("ESRT: fw_version=%d\n", esrt->entries[idx].fw_version); + printf("ESRT: lowest_supported_fw_version=%d\n", + esrt->entries[idx].lowest_supported_fw_version); + printf("ESRT: capsule_flags=%d\n", + esrt->entries[idx].capsule_flags); + printf("ESRT: last_attempt_version=%d\n", + esrt->entries[idx].last_attempt_version); + printf("ESRT: last_attempt_status=%d\n", + esrt->entries[idx].last_attempt_status); + } + printf("========================================\n"); + + return CMD_RET_SUCCESS; +} +#endif /* CONFIG_EFI_ESRT */ /** * do_efi_capsule_res() - show a capsule update result * @@ -221,6 +276,10 @@ static struct cmd_tbl cmd_efidebug_capsule_sub[] = { "", ""), U_BOOT_CMD_MKENT(show, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_show, "", ""), +#ifdef CONFIG_EFI_ESRT + U_BOOT_CMD_MKENT(esrt, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_esrt, + "", ""), +#endif U_BOOT_CMD_MKENT(disk-update, 0, 0, do_efi_capsule_on_disk_update, "", ""), U_BOOT_CMD_MKENT(result, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_res, @@ -256,6 +315,7 @@ static int do_efi_capsule(struct cmd_tbl *cmdtp, int flag, return cp->cmd(cmdtp, flag, argc, argv); } + #endif /* CONFIG_EFI_HAVE_CAPSULE_SUPPORT */ /** @@ -1580,6 +1640,10 @@ static char efidebug_help_text[] = " - show capsule information\n" "efidebug capsule result []\n" " - show a capsule update result\n" +#ifdef CONFIG_EFI_ESRT + "efidebug capsule esrt\n" + " - print the ESRT\n" +#endif "\n" #endif "efidebug devices\n" diff --git a/test/lib/Makefile b/test/lib/Makefile index 97c11e35a8..aeb8c13eb0 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -15,3 +15,4 @@ obj-$(CONFIG_UT_LIB_ASN1) += asn1.o obj-$(CONFIG_UT_LIB_RSA) += rsa.o obj-$(CONFIG_AES) += test_aes.o obj-$(CONFIG_GETOPT) += getopt.o +obj-$(CONFIG_EFI_ESRT) += efi_esrt.o diff --git a/test/lib/efi_esrt.c b/test/lib/efi_esrt.c new file mode 100644 index 0000000000..e8cfe671e2 --- /dev/null +++ b/test/lib/efi_esrt.c @@ -0,0 +1,191 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Test ESRT tables support + * + * Copyright (C) 2021 Arm Ltd. + */ +#include +#include +#include +#include +#include +#include + +#define TEST_ESRT_NUM_ENTRIES 255 + +#if 0x100 < TEST_ESRT_NUM_ENTRIES +#error TEST_ESRT_NUM_ENTRIES must be lower or equal to 255. +#endif + +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 = 1; + + // 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; +} + +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; +} + +int lib_test_efi_esrt(struct unit_test_state *uts) +{ + struct efi_system_resource_table *esrt; + efi_status_t ret = EFI_SUCCESS; + struct efi_boot_services *bt; + + efi_test_esrt_init_info(); + + ret = efi_init_obj_list(); + + bt = systab.boottime; + ut_asserteq(ret, EFI_SUCCESS); + + assert(bt); + + ret = EFI_CALL(bt->install_multiple_protocol_interfaces + (&efi_root, + &efi_guid_firmware_management_protocol, + &efi_test_fmp, + NULL)); + + ut_asserteq(ret, EFI_SUCCESS); + + esrt = lib_test_get_esrt(); + ut_assert(esrt); + + ut_asserteq(esrt->fw_resource_count, TEST_ESRT_NUM_ENTRIES); + + /* Update the ESRT. */ + ut_asserteq(efi_esrt_populate(), EFI_SUCCESS); + esrt = lib_test_get_esrt(); + ut_assert(esrt); + + /* Verify that the number of images remains the same. */ + ut_asserteq(esrt->fw_resource_count, TEST_ESRT_NUM_ENTRIES); + + for (u32 idx = 0; idx < TEST_ESRT_NUM_ENTRIES; idx++) + ut_assert(lib_test_check_uuid_entry(esrt, &static_img_info[idx])); + + ret = EFI_CALL(bt->uninstall_multiple_protocol_interfaces + (efi_root, &efi_guid_firmware_management_protocol, + &efi_test_fmp, NULL)); + + ut_asserteq(ret, EFI_SUCCESS); + + /* Update the ESRT after FMP removal. */ + ut_asserteq(efi_esrt_populate(), EFI_SUCCESS); + esrt = lib_test_get_esrt(); + ut_assert(esrt); + + ut_asserteq(esrt->fw_resource_count, 0); + + return ret; +} + +LIB_TEST(lib_test_efi_esrt, 0); 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])