From patchwork Tue Feb 23 16:50:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jose Marinho X-Patchwork-Id: 1443577 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=W0NDu6v4; 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=W0NDu6v4; 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 4DlQ6b3qsKz9s1l for ; Wed, 24 Feb 2021 03:51:03 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B203082A7E; Tue, 23 Feb 2021 17:50:55 +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="W0NDu6v4"; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="W0NDu6v4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9BEED82A70; Tue, 23 Feb 2021 17:50:41 +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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-ve1eur02on061b.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe06::61b]) (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 6C85281C73 for ; Tue, 23 Feb 2021 17:50:31 +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=+nFIH+SIu2MYUazrIQ7GT9ngA0Hi5pZEvH5wCkF38YM=; b=W0NDu6v46GBF+SobaH7hE2BySjTmjVDtSDoimQmrEv0ft/KT5L3iRg0zS2T/AvkVCgAfOC5KGP1R/0Jd9Z84+EV2+bj0ct0VgUXXOfge239Ae/7SlgymM7/rr+3npQTlMo8NabbivS01oEayuLSYbTiyTe3TGBGfop+1AqDRHr0= Received: from AM6PR02CA0035.eurprd02.prod.outlook.com (2603:10a6:20b:6e::48) by DB7PR08MB3035.eurprd08.prod.outlook.com (2603:10a6:5:1d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.30; Tue, 23 Feb 2021 16:50:29 +0000 Received: from VE1EUR03FT033.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:6e:cafe::6c) by AM6PR02CA0035.outlook.office365.com (2603:10a6:20b:6e::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27 via Frontend Transport; Tue, 23 Feb 2021 16:50:28 +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 VE1EUR03FT033.mail.protection.outlook.com (10.152.18.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27 via Frontend Transport; Tue, 23 Feb 2021 16:50:28 +0000 Received: ("Tessian outbound cae1e71cca86:v71"); Tue, 23 Feb 2021 16:50:28 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: b0ff0d3445bc3524 X-CR-MTA-TID: 64aa7808 Received: from 99a284dfca3e.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id D2A8CCE4-E855-40BE-92E9-19680299C798.1; Tue, 23 Feb 2021 16:50:22 +0000 Received: from EUR01-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 99a284dfca3e.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 23 Feb 2021 16:50:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Veipjlf7aBdnkLa5CwXsadXz93seynj/LTx9k274LWBFrIOtoy30Lyk9wcTsrD0a/zojreUmuZUmo8n6sB6SFZYCLUzO6bwBDK0Oy7ZsA+XmeCegDjUcjdN2xA+0NWVglBmYkI+6aQYeCcIUttoRSM/NMOGByx2oYD/v/ePDgZGwdBY3Awbz0YCizfEZewXy7VE6LWj+FnjeVrvm0lnfIgjp+QZV1c7sWi3dl7MZ5bM8cE6FcLu0BOxlwUAN1RoqFBrSLQNpW8IuZ1qthp33Rwy8EBZSFL4VgKwRL7jue2zAQKEyHZnuSyHd3VfPPRnlkKyGbNouGMyxUVL7Pp3+rA== 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=+nFIH+SIu2MYUazrIQ7GT9ngA0Hi5pZEvH5wCkF38YM=; b=d04+P4pGGKq84lXE5ZRqa4/qoWEXM/eYQ5M6a1AFUAZtQ7hjj3HJLIO3wOQUc7VLfVedc2wJmRVKTC7NUWpNQCVwGt5AQ6ttdW/bIzMttOFf7JYS6lHft2P9lS4PRpc+K44DKxO2UFexY6vXbz92XFTk1xSky487vaLz8Kskisv4QpwY0p8EupeW6mb1GNiz/bOI64FfP3n8J737wm+A25l4nNjTOG4UeKR4ZSG+gED1FE4v7Y1lvqcT7aHixfm8IA0PMlY5xQoDGod6HEES5ZOFWx7iH9vzF3USmb54P6y0SdERYdMdRkjRCwVMFqZN7P7zI8gJtDDGhJjZXczsIg== 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=+nFIH+SIu2MYUazrIQ7GT9ngA0Hi5pZEvH5wCkF38YM=; b=W0NDu6v46GBF+SobaH7hE2BySjTmjVDtSDoimQmrEv0ft/KT5L3iRg0zS2T/AvkVCgAfOC5KGP1R/0Jd9Z84+EV2+bj0ct0VgUXXOfge239Ae/7SlgymM7/rr+3npQTlMo8NabbivS01oEayuLSYbTiyTe3TGBGfop+1AqDRHr0= 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 DB8PR08MB4955.eurprd08.prod.outlook.com (2603:10a6:10:38::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.31; Tue, 23 Feb 2021 16:50:20 +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.046; Tue, 23 Feb 2021 16:50:20 +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 1/2 v4] efi: Add ESRT to the EFI system table Date: Tue, 23 Feb 2021 16:50:00 +0000 Message-Id: <20210223165001.17001-2-jose.marinho@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210223165001.17001-1-jose.marinho@arm.com> References: <20210223165001.17001-1-jose.marinho@arm.com> X-Originating-IP: [217.140.106.49] X-ClientProxiedBy: LO2P265CA0036.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:61::24) 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.49) by LO2P265CA0036.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:61::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.31 via Frontend Transport; Tue, 23 Feb 2021 16:50:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 48971463-1710-4b43-90ac-08d8d81b200f X-MS-TrafficTypeDiagnostic: DB8PR08MB4955:|DB7PR08MB3035: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: ScgsWmJAmw5M2hVulgQstidofcwWt3oAvSkM4PJvxDn6T1+O5ssTFnJKmZRyPLTD7z3EVEgc+OMbDJSZrGZOCnRY8yzMLJ/QrLigx063z1LpKhS1aRjg+X9+ptUkjovlIi3sZlBWKsJQyOGWXjHYVnj+NUKNJaP8odv8jBMVNAYlEnTrvyqTpaLCPO2otnkgPWV4wdVCqODU3avI2+9Nblc/xw5xoz6Z5vqQwgSjdwiGyuMsWHE8f4mx6043wR7vHtA9LYA6buELvxwPhtjtuLR7WZ2RF3btsHdC1FZCf8BiNhvKPD7mmvzQQYrMIri6gulvhSsuzKteMHddZtBuk6RmUa9E0VTL/YDDrrOdHsry+KZyYREW1hu+jeg6mUrB/+1ipkiFeV8dWDoU5CUpv+kgNoKdbIRXoYHOL4RwvhAjsJiCAkYtV3t+jW8gBdYEHejk9R6ZPIxBFA+aotHYpC7fl+HeYSTPf6IFdQdgcqAZG0YwCbWRu9mR+xD9KREuX0R31FN7NBvbs6/vXVqp8A== 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)(396003)(376002)(136003)(39850400004)(346002)(366004)(5660300002)(2616005)(86362001)(8936002)(44832011)(6666004)(6916009)(54906003)(4326008)(36756003)(316002)(478600001)(6486002)(8676002)(83380400001)(2906002)(1076003)(52116002)(16526019)(26005)(7696005)(186003)(66556008)(66476007)(66946007)(956004)(30864003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: O6VQPhP6xv0dgTsMiPylmRWaFtvc00ORJX+MfgGtV6Bl5deKrLlOQ23O+ixQEeyOqNCQbKVGUN1y0qheis8hl3fdzD1E4BRwXHvZ+g3Xevi0NgIVRXm+SaX5mXNzKJ0Tsu9GYaaDilqiR/MQ0/b5iYkDAdIgqLH7/6bB/LdgWi3L9cTrdCdYq3/Ob3/LrhRD1SdQRRym09O5t/rH1MlCyIZAl4K3a7mvLdTsYMX8qFK9x2Pcz1U8hrYBpZUBHl/I0ZzzX9mjbqAvD/+d6VSu3/NVmmHBMMQCV87h1vKoNZJuD1zF/vLOvzKe6Y8nPhQLRSID+mCuVA5VjkZKdHqDhnCY/KITYckGCnrtmJbWMTOIHRw8dvJgq1vkf40sHTEpQORVLayWJtvjaeRit8VOWKOSxJQw4VM1a5dbPdlvdKZkEpAq3Mh0kosUtHrqCO+wA2Ww4gnfL1cjARo+cZmJEb7vWcYJl9KhiL4Np0/RwkaNrxCnvLJqeYfDrVF7NIcimszWS/ZuBCp4gGH2hJCcm/SXDjcIKlIHfojW4AZ0o4orhMHIVBkXnhqiogdEbRCf9gth52SapzYSiJg1+vq3tAvNlVCZoWroDvJ6hM85r7/Vihb+AOMMKpLv4o76AcNoA1MERR/1j+zSrXJ+3M6L/Gt7oLKOWjSCGj6Smts5nmkC7by+A7WZ7zXbHyimaXbLsZnijJDNC30f0PxGXlaKOpTNTykp0eH3MprxRDux5+JN62ksR9mgmdQ8sHwoOL5SABv9xNKdvdxlCiaUTBrlevU6o8yl46RIyJUKzGFoQx0p5sefDL5QvKQI8O2RApktTb6SiykvJwgkFiiKNcFh1ZA1OYN1Z7h3R/pm0Q8av4PItNuqCxd6ZfmDebbOUA5dyaahmc3cOpHuaxXzA0qpO4+d/0RdWnJxFvhQCh6i8Im1l2eJO2EPRyKsUfSWGeA0kLNzLZmxB9CUVYMUPzGk8recGed1f1zGyCB9wQrUl8ZcdX3mVD+PswNlbjTZ4AcLOjgU4TOdFLY8AD5D7hjFdiRQqZPgM3V3Furdm/VM4470pNHkrwEbmDghqK52+Hw8s45H5R0w27kVnYdrRLFMWKC/9Qe/wS5t0DwXf56BDfVaobTZXgJMgWCcBcAq6KRAREPAFCCeaPNQCifpGt6ObceoOgG70dmsSK+lbpz7doTxnBw0U6UGmXJYq25kWb8bHC25gwfWLgY/glceUULQKgzdWUKUwzas6nRC/gbyATd5UgBYLal5jcQyfAyC6DiCW9ZPXalDswcDQh08kiCvytmpS+wcIUcKZIw5DOHCgTa4btBbk/ACCa9CxLFTb64N X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB4955 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: VE1EUR03FT033.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: cc815ac0-73fd-4334-1e4b-08d8d81b1ab7 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0KhHzHWWpWie4f0JYZhlxO5VIvTtwM9IyWLo9ox+HFasacWFdZrCgZF8F5eJyYvvf3rYB82qB9FFR4pzc3rhHaoRCKMQI7ofjm3d+KwZKbtIdnui2Y/p1fglyB87OrVBlp15AjkwkfAiz1VIe4VZ9c5FmoHM3Zyb0r6XUQCAoK0wTEuy322AqTcm/323DN93GgBzry24Ija5zEdprbgMTBfb81nZUZcpCKP+O77BHDdaxV4mXO9VNcGcUhkG//Swpy02L/D2Bv5b6dE5iAl/bhPvbvOI+vYKyadYHYZ7Q5wedTgvcYpkW1ZuWQ8UVvnYEq57oDMYIvskt4JdhonD/0GENegMslkf4QaurWkRukr94SnzSaS/S8cN8qqHI1lrmj43P471joTIbk1DdJn3ezCwhXd142BFZXJRz5MwF+9PU8glwq15n+NnoL0gFeQeGkcXE+KQjw6m5GW0D4mcIctXf5web9aPlQtKpsTwq5CpIBMAbDAlQMICFQGv5AkBOadUCZMa2v32b5r4l4NlNP9v7mxrNnRJqmQHf3VExATo66Woo6QuIhthMOtyjzqC7pCYiXxvctGMeagi693xlSX/q1Yc208iuONprHs1K/7XVq4OEVjd07Jbw8kgrcrYfINtua8GtSPuTHeUWHQgOPEHZ0dxnN1yukwBUShwEZI= 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)(396003)(346002)(136003)(39850400004)(376002)(46966006)(36840700001)(4326008)(16526019)(1076003)(2616005)(6666004)(956004)(186003)(82740400003)(82310400003)(356005)(30864003)(86362001)(478600001)(70586007)(36756003)(81166007)(47076005)(8676002)(6486002)(316002)(70206006)(8936002)(5660300002)(6916009)(26005)(336012)(83380400001)(2906002)(44832011)(54906003)(36860700001)(7696005); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Feb 2021 16:50:28.4843 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 48971463-1710-4b43-90ac-08d8d81b200f 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: VE1EUR03FT033.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR08MB3035 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 The ESRT is initialised during efi_init_objlist after efi_initialize_system_table(). The ESRT is recreated from scratch at the following events: - successful UpdateCapsule; - FMP instance install. The code ensures that every ESRT entry has a unique fw_class value. Limitations: - The ESRT is not updated when an FMP instance is uninstalled; - the fields image_type and flags are currently set to UNKNOWN and 0 respectively. The mapping between fw_class and the image_type/flags fields is platform specific. A mapping function is lacking from the current implementation but should be added in the future. 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 | 4 + include/efi_api.h | 21 ++ include/efi_loader.h | 20 ++ lib/efi_loader/Kconfig | 7 + lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_capsule.c | 8 + lib/efi_loader/efi_esrt.c | 518 +++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 6 + 8 files changed, 585 insertions(+) create mode 100644 lib/efi_loader/efi_esrt.c diff --git a/cmd/efidebug.c b/cmd/efidebug.c index bbbcb0a546..a7dace2f80 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -459,6 +459,10 @@ static const struct { "Block IO", EFI_BLOCK_IO_PROTOCOL_GUID, }, + { + "EFI System Resource Table", + EFI_SYSTEM_RESOURCE_TABLE_GUID, + }, { "Simple File System", EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, diff --git a/include/efi_api.h b/include/efi_api.h index 48e48a6263..fb53637419 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -1722,6 +1722,23 @@ struct efi_load_file_protocol { void *buffer); }; +struct efi_system_resource_entry { + efi_guid_t fw_class; + u32 fw_type; + u32 fw_version; + u32 lowest_supported_fw_version; + u32 capsule_flags; + u32 last_attempt_version; + u32 last_attempt_status; +} __packed; + +struct efi_system_resource_table { + u32 fw_resource_count; + u32 fw_resource_count_max; + u64 fw_resource_version; + struct efi_system_resource_entry entries[]; +} __packed; + /* Boot manager load options */ #define LOAD_OPTION_ACTIVE 0x00000001 #define LOAD_OPTION_FORCE_RECONNECT 0x00000002 @@ -1740,6 +1757,10 @@ struct efi_load_file_protocol { #define ESRT_FW_TYPE_DEVICEFIRMWARE 0x00000002 #define ESRT_FW_TYPE_UEFIDRIVER 0x00000003 +#define EFI_SYSTEM_RESOURCE_TABLE_GUID\ + EFI_GUID(0xb122a263, 0x3661, 0x4f68,\ + 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80) + /* Last Attempt Status Values */ #define LAST_ATTEMPT_STATUS_SUCCESS 0x00000000 #define LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL 0x00000001 diff --git a/include/efi_loader.h b/include/efi_loader.h index f470bbd636..c2720f2823 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -214,6 +214,8 @@ extern const efi_guid_t efi_guid_rng_protocol; extern const efi_guid_t efi_guid_capsule_report; /* GUID of firmware management protocol */ extern const efi_guid_t efi_guid_firmware_management_protocol; +/* GUID for the ESRT */ +extern const efi_guid_t efi_esrt_guid; extern unsigned int __efi_runtime_start, __efi_runtime_stop; extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop; @@ -884,4 +886,22 @@ static inline efi_status_t efi_launch_capsules(void) #endif /* CONFIG_IS_ENABLED(EFI_LOADER) */ +/** + * Install the ESRT system table. + * + * @return status code + */ +efi_status_t efi_esrt_register(void); + +/** + * efi_esrt_populate() - Populates the ESRT entries from the FMP instances + * present in the system. + * If an ESRT already exists, the old ESRT is replaced in the system table. + * The memory of the old ESRT is deallocated. + * + * Return: + * - EFI_SUCCESS if the ESRT is correctly created + * - error code otherwise. + */ +efi_status_t efi_esrt_populate(void); #endif /* _EFI_LOADER_H */ diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index e729f727df..a96014ce18 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -347,4 +347,11 @@ config EFI_SECURE_BOOT it is signed with a trusted key. To do that, you need to install, at least, PK, KEK and db. +config EFI_ESRT + bool "Enable the UEFI ESRT generation" + depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT + default y + help + Enabling this option creates the ESRT UEFI system table. + endif diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index 10b42e8847..9a8127846f 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -52,6 +52,7 @@ obj-y += efi_variable.o obj-$(CONFIG_EFI_VARIABLES_PRESEED) += efi_var_seed.o endif obj-y += efi_watchdog.o +obj-$(CONFIG_EFI_ESRT) += efi_esrt.o obj-$(CONFIG_LCD) += efi_gop.o obj-$(CONFIG_DM_VIDEO) += efi_gop.o obj-$(CONFIG_PARTITIONS) += efi_disk.o diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index b57f0302c5..a1a69e619d 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -482,6 +482,14 @@ efi_status_t EFIAPI efi_update_capsule( goto out; } out: + + if (IS_ENABLED(CONFIG_EFI_ESRT)) { + /* Rebuild the ESRT to reflect any updated FW images. */ + ret = EFI_CALL(efi_esrt_populate()); + if (ret != EFI_SUCCESS) + log_warning("EFI Capsule: failed to update ESRT\n"); + } + return EFI_EXIT(ret); } diff --git a/lib/efi_loader/efi_esrt.c b/lib/efi_loader/efi_esrt.c new file mode 100644 index 0000000000..d31963ad6e --- /dev/null +++ b/lib/efi_loader/efi_esrt.c @@ -0,0 +1,518 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * EFI application ESRT tables support + * + * Copyright (C) 2021 Arm Ltd. + */ + +#include +#include +#include +#include +#include + +const efi_guid_t efi_esrt_guid = EFI_SYSTEM_RESOURCE_TABLE_GUID; + +static struct efi_system_resource_table *esrt; + +#define EFI_ESRT_VERSION 1 + +/** + * efi_esrt_image_info_to_entry() - copy the information present in a fw image + * descriptor to a ESRT entry. + * The function ensures the ESRT entry matches the image_type_id in @img_info. + * In case of a mismatch we leave the entry unchanged. + * + * @img_info: the source image info descriptor + * @entry: pointer to the ESRT entry to be filled + * @desc_version: the version of the elements in img_info + * @image_type: the image type value to be set in the ESRT entry + * @flags: the capsule flags value to be set in the ESRT entry + * + * Return: + * - EFI_SUCCESS if the entry is correctly updated + * - EFI_INVALID_PARAMETER if entry does not match image_type_id in @img_info. + */ +static efi_status_t +efi_esrt_image_info_to_entry(struct efi_firmware_image_descriptor *img_info, + struct efi_system_resource_entry *entry, + u32 desc_version, u32 image_type, u32 flags) +{ + if (guidcmp(&entry->fw_class, &img_info->image_type_id)) { + EFI_PRINT("ESRT entry %pUL mismatches img_type_id %pUL\n", + &entry->fw_class, &img_info->image_type_id); + return EFI_INVALID_PARAMETER; + } + + entry->fw_version = img_info->version; + + entry->fw_type = image_type; + entry->capsule_flags = flags; + + /* + * The field lowest_supported_image_version is only present + * on image info structure of version 2 or greater. + * See the EFI_FIRMWARE_IMAGE_DESCRIPTOR definition in UEFI. + */ + if (desc_version >= 2) + entry->lowest_supported_fw_version = + img_info->lowest_supported_image_version; + else + entry->lowest_supported_fw_version = 0; + + /* + * The fields last_attempt_version and last_attempt_status + * are only present on image info structure of version 3 or + * greater. + * See the EFI_FIRMWARE_IMAGE_DESCRIPTOR definition in UEFI. + */ + if (desc_version >= 3) { + entry->last_attempt_version = + img_info->last_attempt_version; + + entry->last_attempt_status = + img_info->last_attempt_status; + } else { + entry->last_attempt_version = 0; + entry->last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS; + } + + return EFI_SUCCESS; +} + +/** + * efi_esrt_entries_to_size() - Obtain the bytes used by an ESRT + * datastructure with @num_entries. + * + * @num_entries: the number of entries in the ESRT. + * + * Return: the number of bytes an ESRT with @num_entries occupies in memory. + */ +static +inline u32 efi_esrt_entries_to_size(u32 num_entries) +{ + u32 esrt_size = sizeof(struct efi_system_resource_table) + + num_entries * sizeof(struct efi_system_resource_entry); + + return esrt_size; +} + +/** + * efi_esrt_allocate_install() - Allocates @num_entries for the ESRT and + * performs basic ESRT initialization. + * + * @bt: pointer to the boottime services structure. + * @num_entries: the number of entries that the ESRT will hold. + * + * Return: + * - pointer to the ESRT if successful. + * - NULL otherwise. + */ +static +efi_status_t efi_esrt_allocate_install(struct efi_boot_services *bt, + u32 num_entries) +{ + efi_status_t ret; + struct efi_system_resource_table *new_esrt; + u32 size = efi_esrt_entries_to_size(num_entries); + efi_guid_t esrt_guid = efi_esrt_guid; + + /* Reserve num_pages for ESRT */ + ret = bt->allocate_pool(EFI_BOOT_SERVICES_DATA, size, + (void **)&new_esrt); + + if (ret != EFI_SUCCESS) { + EFI_PRINT("ESRT cannot allocate memory for %d entries (%d bytes)\n", + num_entries, efi_esrt_entries_to_size(num_entries)); + + return ret; + } + + new_esrt->fw_resource_count_max = num_entries; + new_esrt->fw_resource_count = 0; + new_esrt->fw_resource_version = EFI_ESRT_VERSION; + + /* Install the ESRT in the system configuration table. */ + ret = bt->install_configuration_table(&esrt_guid, (void *)new_esrt); + if (ret != EFI_SUCCESS) { + EFI_PRINT("ESRT failed to install the ESRT in the system table\n"); + return ret; + } + + /* If there was a previous ESRT, deallocate its memory now. */ + if (esrt) + ret = bt->free_pool(esrt); + + esrt = new_esrt; + + return EFI_SUCCESS; +} + +/** + * esrt_find_entry() - Obtain the ESRT entry for the image with GUID + * @img_fw_class. + * + * If the img_fw_class is not yet present in the ESRT, this function + * reserves the tail element of the current ESRT as the entry for that fw_class. + * The number of elements in the ESRT is updated in that case. + * + * @img_fw_class: the GUID of the FW image which ESRT entry we want to obtain. + * + * Return: + * - A pointer to the ESRT entry for the image with GUID img_fw_class, + * - NULL if: + * - there is no more space in the ESRT, + * - ESRT is not initialized, + */ +static +struct efi_system_resource_entry *esrt_find_entry(efi_guid_t *img_fw_class) +{ + u32 filled_entries; + u32 max_entries; + struct efi_system_resource_entry *entry; + + if (!esrt) { + EFI_PRINT("ESRT access before initialized\n"); + return NULL; + } + + filled_entries = esrt->fw_resource_count; + entry = esrt->entries; + + /* Check if the image with img_fw_class is already in the ESRT. */ + for (u32 idx = 0; idx < filled_entries; idx++) { + if (!guidcmp(&entry[idx].fw_class, img_fw_class)) { + EFI_PRINT("ESRT found entry for image %pUl at index %d\n", + img_fw_class, idx); + return &entry[idx]; + } + } + + max_entries = esrt->fw_resource_count_max; + /* + * Since the image with img_fw_class is not present in the ESRT, check + * if ESRT is full before appending the new entry to it. + */ + if (filled_entries == max_entries) { + EFI_PRINT("ESRT full, this should not happen\n"); + return NULL; + } + + /* + * This is a new entry for a fw image, increment the element + * number in the table and set the fw_class field. + */ + esrt->fw_resource_count++; + entry[filled_entries].fw_class = *img_fw_class; + EFI_PRINT("ESRT allocated new entry for image %pUl at index %d\n", + img_fw_class, filled_entries); + + return &entry[filled_entries]; +} + +/** + * efi_esrt_add_from_fmp() - Populates a sequence of ESRT entries from the FW + * images in the FMP. + * + * @bt : pointer to the boottime services structure. + * @fmp: the FMP instance from which FW images are added to the ESRT + * + * Return: + * - EFI_SUCCESS if all the FW images in the FMP are added to the ESRT + * - Error status otherwise + */ +static +efi_status_t efi_esrt_add_from_fmp(struct efi_boot_services *bt, + struct efi_firmware_management_protocol *fmp) +{ + struct efi_system_resource_entry *entry = NULL; + size_t info_size = 0; + struct efi_firmware_image_descriptor *img_info = NULL; + u32 desc_version; + u8 desc_count; + size_t desc_size; + u32 package_version; + u16 *package_version_name; + efi_status_t ret = EFI_SUCCESS; + + /* + * TODO: set the field image_type depending on the FW image type + * defined in a platform basis. + */ + u32 image_type = ESRT_FW_TYPE_UNKNOWN; + + /* TODO: set the capsule flags as a function of the FW image type. */ + u32 flags = 0; + + ret = fmp->get_image_info(fmp, &info_size, img_info, + &desc_version, &desc_count, + &desc_size, NULL, NULL); + + if (ret != EFI_BUFFER_TOO_SMALL) { + /* + * An input of info_size=0 should always lead + * fmp->get_image_info to return BUFFER_TO_SMALL. + */ + EFI_PRINT("Erroneous FMP implementation\n"); + return EFI_INVALID_PARAMETER; + } + + ret = bt->allocate_pool(EFI_BOOT_SERVICES_DATA, info_size, + (void **)&img_info); + if (ret != EFI_SUCCESS) { + EFI_PRINT("ESRT failed to allocate memory for image info.\n"); + return ret; + } + + ret = fmp->get_image_info(fmp, &info_size, img_info, + &desc_version, &desc_count, + &desc_size, &package_version, &package_version_name); + if (ret != EFI_SUCCESS) { + EFI_PRINT("ESRT failed to obtain the FMP image info\n"); + goto out; + } + + /* + * Iterate over all the FW images in the FMP. + */ + for (u32 desc_idx = 0; desc_idx < desc_count; desc_idx++) { + struct efi_firmware_image_descriptor *cur_img_info = + (struct efi_firmware_image_descriptor *) + ((uintptr_t)img_info + desc_idx * desc_size); + + /* + * Obtain the ESRT entry for the FW image with fw_class + * equal to cur_img_info->image_type_id. + */ + entry = esrt_find_entry(&cur_img_info->image_type_id); + + if (entry) { + ret = efi_esrt_image_info_to_entry(cur_img_info, entry, + desc_version, + image_type, flags); + if (ret != EFI_SUCCESS) + EFI_PRINT("ESRT entry mismatches image_type\n"); + + } else { + EFI_PRINT("ESRT failed to add entry for %pUl\n", + &cur_img_info->image_type_id); + continue; + } + } + +out: + bt->free_pool(img_info); + return EFI_SUCCESS; +} + +/** + * efi_esrt_populate() - Populates the ESRT entries from the FMP instances + * present in the system. + * If an ESRT already exists, the old ESRT is replaced in the system table. + * The memory of the old ESRT is deallocated. + * + * Return: + * - EFI_SUCCESS if the ESRT is correctly created + * - error code otherwise. + */ +efi_status_t efi_esrt_populate(void) +{ + efi_handle_t *base_handle = NULL; + efi_handle_t *it_handle; + size_t no_handles = 0; + struct efi_firmware_management_protocol *fmp; + efi_status_t ret; + u32 num_entries = 0; + struct efi_boot_services *bt = systab.boottime; + + if (!bt) { + EFI_PRINT("ESRT cannot obtain pointer to BS\n"); + return EFI_NOT_READY; + } + + /* + * Obtain the number of registered FMP handles. + */ + ret = bt->locate_handle_buffer(BY_PROTOCOL, + &efi_guid_firmware_management_protocol, + NULL, &no_handles, + (efi_handle_t **)&base_handle); + + if (ret != EFI_SUCCESS) { + EFI_PRINT("ESRT There are no FMP instances\n"); + + ret = efi_esrt_allocate_install(bt, 0); + if (ret != EFI_SUCCESS) { + EFI_PRINT("ESRT failed to create table with 0 entries\n"); + return ret; + } + return EFI_SUCCESS; + } + + EFI_PRINT("ESRT populate esrt from (%ld) available FMP handles\n", + no_handles); + + /* + * Iterate over all FMPs to determine an upper bound on the number of + * ESRT entries. + */ + it_handle = base_handle; + for (u32 idx = 0; idx < no_handles; idx++, it_handle++) { + struct efi_firmware_image_descriptor *img_info = NULL; + size_t info_size = 0; + u32 desc_version = 0; + u8 desc_count = 0; + size_t desc_size = 0; + u32 package_version; + u16 *package_version_name; + + ret = bt->handle_protocol(*it_handle, + &efi_guid_firmware_management_protocol, + (void **)&fmp); + + if (ret != EFI_SUCCESS) { + EFI_PRINT("ESRT Unable to find FMP handle (%d)\n", + idx); + goto out; + } + + ret = fmp->get_image_info(fmp, &info_size, NULL, + &desc_version, &desc_count, + &desc_size, &package_version, &package_version_name); + + if (ret != EFI_BUFFER_TOO_SMALL) { + /* + * An input of info_size=0 should always lead + * fmp->get_image_info to return BUFFER_TO_SMALL. + */ + EFI_PRINT("ESRT erroneous FMP implementation\n"); + ret = EFI_INVALID_PARAMETER; + goto out; + } + + ret = bt->allocate_pool(EFI_BOOT_SERVICES_DATA, info_size, + (void **)&img_info); + if (ret != EFI_SUCCESS) { + EFI_PRINT("ESRT failed to allocate memory for image info\n"); + goto out; + } + + /* + * Calls to a FMP get_image_info method do not return the + * desc_count value if the return status differs from EFI_SUCCESS. + * We need to repeat the call to get_image_info with a properly + * sized buffer in order to obtain the real number of images + * handled by the FMP. + */ + ret = fmp->get_image_info(fmp, &info_size, img_info, + &desc_version, &desc_count, + &desc_size, &package_version, &package_version_name); + + if (ret != EFI_SUCCESS) { + EFI_PRINT("ESRT failed to obtain image info from FMP\n"); + bt->free_pool(img_info); + goto out; + } + + num_entries += desc_count; + + bt->free_pool(img_info); + } + + EFI_PRINT("ESRT create table with %d entries\n", num_entries); + /* + * Allocate an ESRT with the sufficient number of entries to accommodate + * all the FMPs in the system. + */ + ret = efi_esrt_allocate_install(bt, num_entries); + if (ret != EFI_SUCCESS) { + EFI_PRINT("ESRT failed to initialize table\n"); + goto out; + } + + /* + * Populate the ESRT entries with all existing FMP. + */ + it_handle = base_handle; + for (u32 idx = 0; idx < no_handles; idx++, it_handle++) { + ret = bt->handle_protocol(*it_handle, + &efi_guid_firmware_management_protocol, + (void **)&fmp); + + if (ret != EFI_SUCCESS) { + EFI_PRINT("ESRT unable to find FMP handle (%d)\n", + idx); + break; + } + + ret = efi_esrt_add_from_fmp(bt, fmp); + if (ret != EFI_SUCCESS) + EFI_PRINT("ESRT failed to add FMP to the table\n"); + } + +out: + + bt->free_pool(base_handle); + + return ret; +} + +/** + * efi_esrt_new_fmp_notify() - Callback for the EVT_NOTIFY_SIGNAL event raised + * when a new FMP protocol instance is registered in the system. + */ +static void EFIAPI efi_esrt_new_fmp_notify(struct efi_event *event, + void *context) +{ + efi_status_t ret; + + ret = efi_esrt_populate(); + if (ret != EFI_SUCCESS) { + EFI_PRINT("ESRT failed to populate ESRT entry\n"); + return; + } +} + +/** + * efi_esrt_register() - Install the ESRT system table. + * + * Return: status code + */ +efi_status_t efi_esrt_register(void) +{ + struct efi_boot_services *bt = systab.boottime; + struct efi_event *ev = NULL; + void *registration; + efi_status_t ret; + + if (!bt) { + EFI_PRINT("ESRT cannot obtain pointer to BS\n"); + return EFI_NOT_READY; + } + + EFI_PRINT("ESRT creation start\n"); + + ret = efi_esrt_populate(); + if (ret != EFI_SUCCESS) { + EFI_PRINT("ESRT failed to initiate the table\n"); + return ret; + } + + ret = bt->create_event(EVT_NOTIFY_SIGNAL, TPL_CALLBACK, + efi_esrt_new_fmp_notify, NULL, &ev); + if (ret != EFI_SUCCESS) { + EFI_PRINT("ESRT failed to create event\n"); + return ret; + } + + ret = bt->register_protocol_notify(&efi_guid_firmware_management_protocol, + ev, ®istration); + if (ret != EFI_SUCCESS) { + EFI_PRINT("ESRT failed to register FMP callback\n"); + return ret; + } + + EFI_PRINT("ESRT table created\n"); + + return ret; +} diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index b1c5125032..3c5cf9a435 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -227,6 +227,12 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; + if (IS_ENABLED(CONFIG_EFI_ESRT)) { + ret = efi_esrt_register(); + if (ret != EFI_SUCCESS) + goto out; + } + if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) { ret = efi_tcg2_register(); if (ret != EFI_SUCCESS) From patchwork Tue Feb 23 16:50:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jose Marinho X-Patchwork-Id: 1443576 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=3EYLMiFH; 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=3EYLMiFH; 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 4DlQ6M6MfKz9s1l for ; Wed, 24 Feb 2021 03:50:51 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CA7FC82A76; Tue, 23 Feb 2021 17:50:43 +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="3EYLMiFH"; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="3EYLMiFH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A5CD282A70; Tue, 23 Feb 2021 17:50:39 +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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on0614.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0e::614]) (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 A3E7282A4C for ; Tue, 23 Feb 2021 17:50:31 +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=3EYLMiFH9Uot6OPERtmTNluVOKvteqQ5pEjls11fhn2HuPL/67O4a7SkaniUiG3ivix09b55/GWWzHR5JrsdWIIEbStrJyIkPhm1XpELhcMDGamQt//v+TxGr5qLCl28GSvDllaTGazdSI5AQo3iq4iQ7LM3dN6BHCoVZstX14E= Received: from DU2PR04CA0273.eurprd04.prod.outlook.com (2603:10a6:10:28c::8) by AM6PR08MB3751.eurprd08.prod.outlook.com (2603:10a6:20b:84::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.32; Tue, 23 Feb 2021 16:50:30 +0000 Received: from DB5EUR03FT024.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:28c:cafe::b7) by DU2PR04CA0273.outlook.office365.com (2603:10a6:10:28c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27 via Frontend Transport; Tue, 23 Feb 2021 16:50:30 +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 DB5EUR03FT024.mail.protection.outlook.com (10.152.20.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27 via Frontend Transport; Tue, 23 Feb 2021 16:50:30 +0000 Received: ("Tessian outbound 46f6cf9da5e8:v71"); Tue, 23 Feb 2021 16:50:30 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 7472ad966d00d132 X-CR-MTA-TID: 64aa7808 Received: from d8109bd60a38.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 7E5EBB5B-BC05-4DB0-B89A-386AB079F10E.1; Tue, 23 Feb 2021 16:50:24 +0000 Received: from EUR01-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id d8109bd60a38.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 23 Feb 2021 16:50:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QafBJpDcbsFtVluFPmM/ZFJJYp2eHrrEW4x1+QuWJcbNdDNWGw2h8hhuBIyS6Ta7HskgR34u+EH3dOgpYMhgjqCQm/sBnSogo6aWKJ6/5Rs+dgmwzno7nsJfULIjkuNv/t2eCPBBLc4RnAniWmJsArijGyzQOMie/Tzx46fKdr2ewrj+7JKgeCPswnMpVbStFAPcqg8LW2t4RDfhOh0a3O5wKAcnHDGthxZqoYv6AYWg7LOE43K8VH5v/GyqmO8yLlfGVIT+y6HTVJfY6ZL1lAMLiFA6jgYolOqhV/Juql3JkKHikKPbdP4Z5a22/IJYO/itY3YrBt9DKVdjUZ6bPg== 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=jLrhL9+A83nF/vtiF2SdNfPbwZ4Ljsznsi7O9nfkM8s6M+3Zk97xtA86Q+OCrvAL2AKFwlHy+whPFLiS6i8cN5JYnH5DnzDygryE4KJMLwIEPbPvRV4oiaB5y4GJOiZYIy1lqamaT31UPheaQowgsaS0/9qxzcnHEQ1ezpQI8msUmTdJ7L3008XKWHababa8ST6MVt3PP/ClxboywW1l8K69ejQSRGeS7mKVKCwL0cyjd9+Jvx/e6DOUCDjufkF7gx0XtGB/XdoDZbcnsUq94TNNYOJCuFxpICj2plg3+TnNz2Pp4Y/8zdbKl4JO4XiaY3rjP0vDBNQ0tB4z+M+sGQ== 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=3EYLMiFH9Uot6OPERtmTNluVOKvteqQ5pEjls11fhn2HuPL/67O4a7SkaniUiG3ivix09b55/GWWzHR5JrsdWIIEbStrJyIkPhm1XpELhcMDGamQt//v+TxGr5qLCl28GSvDllaTGazdSI5AQo3iq4iQ7LM3dN6BHCoVZstX14E= 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 DB8PR08MB4955.eurprd08.prod.outlook.com (2603:10a6:10:38::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.31; Tue, 23 Feb 2021 16:50:22 +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.046; Tue, 23 Feb 2021 16:50:22 +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 v4] efi: ESRT creation tests Date: Tue, 23 Feb 2021 16:50:01 +0000 Message-Id: <20210223165001.17001-3-jose.marinho@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210223165001.17001-1-jose.marinho@arm.com> References: <20210223165001.17001-1-jose.marinho@arm.com> X-Originating-IP: [217.140.106.49] X-ClientProxiedBy: LO2P265CA0036.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:61::24) 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.49) by LO2P265CA0036.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:61::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.31 via Frontend Transport; Tue, 23 Feb 2021 16:50:21 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8f0da378-62d8-46a4-88eb-08d8d81b20eb X-MS-TrafficTypeDiagnostic: DB8PR08MB4955:|AM6PR08MB3751: 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: MGqlExZ/nVywPlY6L5/bRMfcygXtpGzK3J18nTU85TOvMnUTDmOR5fW7JUvkLZNopD5luslpEq7R+RFuBSF+JicFWceiGprPCQbEnS9esi8rqevurU+VAlQL29e6BD2MNMBb3xiBwy50Bvq5ckJ7CQtWcdlRzVjXwXIrmud60doLVOvJLdXzxMxR8e0rCr8w8NKJ8yxh+Pt4s8MFuyMbHUdC2rIkUGnGhn0+t17LxMJVYlI5pNTcGusuFo4FqV0gw0N3xfRj7cMF568p94nlyFSlk9p5HmxuqZwAB46k0j9SlH73D44cXBnmT+a+Kw/lgf56uuxlvzd/+RbKrs2cp5m1M8bJT3WKfTzsjo3xM5r/Ryeowe0P8bPZhzcY2ibcD3BdURk8zaZ9ulbzwF1IkmfIkmXV5jJCSzIY28HCCmn6dKFWDabohPHLg4DU9xQL0RUL81f1bvLJ1kIh2TlYu7uFmyf+w8SW0YeA8UN6YsMvO9jwyUuks44onS4N0vd9Mv+/gIEs75qjdep1Fq0r5Q== 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)(396003)(376002)(136003)(39850400004)(346002)(366004)(5660300002)(2616005)(86362001)(8936002)(44832011)(6666004)(6916009)(54906003)(4326008)(36756003)(316002)(478600001)(6486002)(8676002)(83380400001)(2906002)(1076003)(52116002)(16526019)(26005)(7696005)(186003)(66556008)(66476007)(66946007)(956004)(30864003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ssRjGNRzo9asttSPaOI8HXz3ltpRIafWU0E3RoE6zqqxS6AppsflPcRMdohu+1e85kHbht758vSlceAbpMIeDyVtwu+b8iJ5+M3uv6kcN7R0n1rLyeF7Seu/2ziFExASTEvDF+9oTKEt4q8MRV+0h3JwtF+nL4hXVSDXO5WeJcV2xN0A4U5e83R5XbYfaXfwpIenSHcd1nnsI2Vstz3QajTFN1BNwVpBnWomLfleLpfQOqKcH8863vAZD5OFiT/NyJMhZpO2tkBOHhvtjaPHiJKSsKfXYPLNd/uWSWLVG4iQNgDxeIyUTkr35FpFBQbvvcrBSuL4jXeOaOOQlMMxsTsW8XpIHYdu5AscaIr4wKRcL4KYex4PFCRCS8FmdCNVnJAPxiDAheIPjoLx9/aN8k084hYfCQA1YLCff/gvz17XK6XkD36R2vnOh1LnM2h67Ld26FDa1C4Y5p55quRnMWSswpXVhMn7q8usd7JyUDNuPqsCKkaqh/lBgymxH0ktjy76YVIQmJFX1qNLIgMVwAgROu7OhzzMNCRYGSWjXARFv8OQ7WnhvJA/ARM/3yqvc47hwarp8NEIzRiO8vCJua5RuCG5+5f251K7inGdec7BWlPeEVJOT0drSF9sJOM1yloW+TrqAElcWm87VioQJ6wTZ9YhdZllaa5PU2w4FX2HslvF/6Ov2Qp6357osxPGDfDerbzpaPz/bNTTnVs65Xx/dPIyGcp4sztUnEeTyizh4IyGzvRZxDvpxVdxrVRO+U4lfPRCin9gnH/sIbOf9UEKR9rs418wAcsoJhx8I77IVrtcqnbXbiq9T5oabb8scb3Ki+Y56xL1gza3jYbWRiCrK0utKb5naknD8YLt9/l0dxIbOBxZGbRY7bMSZxPQ33KMuY0rwW1hy4S5NhIL4UUfaIbh+8L1R2w7BFMmI6wRnRXt+5y6GqP59VaXQw8H8AATKkKosbxd+VjG0jt9NKuvTSviY2WxlptG6uP6eJ4dlZdcHq+hDWR5ApRMKxJgIBs9ZgSfVkkhhiKN2QmvTF8rmUjrlnI+PkTMJhrW26F1ONnPQjHoNOzWAYOecP6r7vKOHVI6Lmi/L0DHWu6g8d5BPl+NdyBOa9i3gNLvKW/IgTVCyIllWLOAjCNwlyzzwM0la+FFkzKxQaCGXbP/Tc2KDt7AI9KZ6000Tw+5p0PpYmj4ETME2c4wW5gqda/vwmQeBhBSenWODL7lTnurLJoxLKaA8+CzuIHWmuEgas1hr8fF/yuoYkURd9HDogrM4jc9Bj6db3J7qw7fNKxXU0u/zbZipSCQPztkwBwEblsUS2lzhwSSQyobSjG/mD8x X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB4955 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: DB5EUR03FT024.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: dc5c4574-117e-4ce9-1fcc-08d8d81b1bec X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BgZysUw8CKg20T4DepxRkf/ttEFv75FWvYZXG3tZvZKydC0W92LYCTS245MaJgeT/fxfthZ4okmI+dNz4BYCktNYq6ESuAYuWE3DBtqZrDYE+O7+vXCJuBgTMYs2mdRmXyV8M2rEC7kEgsdm8t9xFcjC2+E7ySztGhdhUj0bqG9BT6eXcb6gCRxuH99EEX9RmYrrMNKwgY3vKsFAk3oL8Q2iMPfewLwNDKoXLgYYJ77uLZLElbB5RcHe+mQJZO3Kk7BQnsJbLWYzIx7Ua5jHsKjFsX/Bjl2FrYzdp3UNxhR+3IxTzvMZq0rI10x1BF8R8wHcDppWf7OC82Q+KEXYMSgMo7k2nX/H234bfjxbg1lwAcRywcPArfoqZdIA/Tx2wDa9s5HckBNBa71mZWFGSjX/afhl7PWoTeweDcX8uzLN3ALIfjVYrDAWRF+7ckQl1v2RzW9IyS6jQPw3t9hAJ3Xk386hqbELPyo5YYZOYya+mZPGmXCHcw0G43mQmx15CAluC31H/7uQGzThO8BItI0QnLnLX8CRs2iE/q/5q3JTm2/ylDBXLKHmujqMOIYF0EtrHcX3l/rZoAHbdtDLeGdV5mkhrhWzR4sST6GPfcLhubWTlp5mloWFE4oxAmaX8ZlhOIUspJRbKzoBbJPWUcjM84q3Gxly/sPJ2QrQ+XM= 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)(396003)(376002)(346002)(136003)(39850400004)(46966006)(36840700001)(44832011)(4326008)(1076003)(82310400003)(6666004)(83380400001)(81166007)(7696005)(8936002)(86362001)(16526019)(70206006)(47076005)(6486002)(82740400003)(6916009)(36756003)(356005)(186003)(54906003)(2906002)(26005)(36860700001)(316002)(478600001)(2616005)(956004)(336012)(5660300002)(70586007)(8676002)(30864003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Feb 2021 16:50:30.0868 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8f0da378-62d8-46a4-88eb-08d8d81b20eb 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: DB5EUR03FT024.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3751 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])