Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D7CB5C433F5 for ; Thu, 23 Dec 2021 14:52:28 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E5062834DE; Thu, 23 Dec 2021 15:52:13 +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="YDEAPXWw"; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="YDEAPXWw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B70ED83433; Thu, 23 Dec 2021 15:52:03 +0100 (CET) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on062b.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0e::62b]) (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 02F9F831D7 for ; Thu, 23 Dec 2021 15:51:58 +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=S+73zxu0VW9i+tVAQvsGIHLNSh7dVO0uXKW97OZuTb0=; b=YDEAPXWwKB4Zc+zt1ux8AHtPfmTxE+7UUX/10AcqhY1SK2SYKPD8O1PR8I3TlmmUBkysURTL5JCEm9g18PgRRPvXuM1YMXKQIPbw6NV+gXSyJtCGvWy/paqz3Cu4nrg5xIo7dRfNgONeAMSkBAeZoLGKWLyLjMszRRRCNDoZDLk= Received: from AS8PR07CA0032.eurprd07.prod.outlook.com (2603:10a6:20b:459::6) by AM5PR0801MB1921.eurprd08.prod.outlook.com (2603:10a6:203:44::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4823.19; Thu, 23 Dec 2021 14:51:55 +0000 Received: from VE1EUR03FT032.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:459:cafe::a5) by AS8PR07CA0032.outlook.office365.com (2603:10a6:20b:459::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4844.7 via Frontend Transport; Thu, 23 Dec 2021 14:51:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT032.mail.protection.outlook.com (10.152.18.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4823.18 via Frontend Transport; Thu, 23 Dec 2021 14:51:55 +0000 Received: ("Tessian outbound c61f076cbd30:v110"); Thu, 23 Dec 2021 14:51:55 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: f6eab035ead19215 X-CR-MTA-TID: 64aa7808 Received: from e32ad01ab733.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 944999ED-A11E-406A-A066-03459D2EF45F.1; Thu, 23 Dec 2021 14:51:47 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id e32ad01ab733.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 23 Dec 2021 14:51:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G0rgSRJJtXmTg9WTRwsJ9p9GYtVGYDRhi4riWCz/9zT8VaIjH9UePbqnxGL7m61qEW1ceDhhoo8vv6n/F7w8C/zgL9hwy6S63TathQuGrAJ2CfM6nsNmEaIc/CiykZPPcVsXs2TUu8OtuXOym35pHzJDjJd6hAfDkiSzcIMBHGohVUPxEJKUjCINPgepg+3Dlw9+wYhBfwCg2edwfRJsRd6U9JEmx8JxRyxyxGHA3A6hn1TBihAua9hkLGFQq8Do44NgJX07Sli01GdkgI84l+Q+59qI13EDY6aLxQVmYPSRsbzueKo4jVhnEpd388PYaTQ6zW50UoAzQSwGVIscrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=S+73zxu0VW9i+tVAQvsGIHLNSh7dVO0uXKW97OZuTb0=; b=CYHaSyOdZnLGFjg8sFmkemPnEdfO7Fjzi9vpwrYFUO6xK92e7elYzUdlCnfBle/hYjvMv68YWQmNz9EwH5TSJexXM0c+CNAbQLPhY8/eVlvhAojUzPIIhY9O6KaiXTQy+U2/POO3GuILVahI8C9p/qP3UVA0BEOeFOjjefCDmOCeNwjRrZO/oNUKKJIWDdWiiRQ23E6LgfuUjcvkkSqeMybcCKVD5IKF9teFTehVsQmKjrsR8YLTjarzRmoEpN/RVmro8bmYDeyx4ryPB5K5il4fH8VQeKTvSD97Or1RdWxJuH/lCNVUFbR3ESccamJwtnTEZDA1Cv90H21w9IGTIw== 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=S+73zxu0VW9i+tVAQvsGIHLNSh7dVO0uXKW97OZuTb0=; b=YDEAPXWwKB4Zc+zt1ux8AHtPfmTxE+7UUX/10AcqhY1SK2SYKPD8O1PR8I3TlmmUBkysURTL5JCEm9g18PgRRPvXuM1YMXKQIPbw6NV+gXSyJtCGvWy/paqz3Cu4nrg5xIo7dRfNgONeAMSkBAeZoLGKWLyLjMszRRRCNDoZDLk= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from DBBPR08MB6012.eurprd08.prod.outlook.com (2603:10a6:10:205::9) by DB8PR08MB5387.eurprd08.prod.outlook.com (2603:10a6:10:115::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.20; Thu, 23 Dec 2021 14:51:42 +0000 Received: from DBBPR08MB6012.eurprd08.prod.outlook.com ([fe80::5d1b:4877:774f:275e]) by DBBPR08MB6012.eurprd08.prod.outlook.com ([fe80::5d1b:4877:774f:275e%9]) with mapi id 15.20.4823.019; Thu, 23 Dec 2021 14:51:42 +0000 From: Jose Marinho To: u-boot@lists.denx.de Cc: Jose Marinho , ilias.apalodimas@linaro.org, sughosh.ganu@linaro.org, xypron.glpk@gmx.de, takahiro.akashi@linaro.org, agraf@csgraf.de, nd@arm.com Subject: [PATCH v2 3/3] efi: ECPT EFI selftest Date: Thu, 23 Dec 2021 14:51:09 +0000 Message-Id: <20211223145109.198312-4-jose.marinho@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211223145109.198312-1-jose.marinho@arm.com> References: <20211223145109.198312-1-jose.marinho@arm.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: LO4P265CA0011.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2ad::19) To DBBPR08MB6012.eurprd08.prod.outlook.com (2603:10a6:10:205::9) MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 4b6154cf-9c65-4f11-f2b8-08d9c623c37e X-MS-TrafficTypeDiagnostic: DB8PR08MB5387:EE_|VE1EUR03FT032:EE_|AM5PR0801MB1921:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:5516;OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: hZR1BAUT9j8kPw3peiQ/khdG5dykTWCYDGvVTGX9JrET1jePTd80gEKu7FvuQkcw16nhQOLBt8qbpwerLeP4P/YBZG7q+3ClCbhvbn9wjIxlRL3Kb5rTU9ZrbrJO8spEmJ9ZL45pvzodPkrcNQKgQm56GMgsV1ZjeFzbN1H4aq7/N83cwW8dwR7yF8rntuOGSdJUmlGTJKFCr0BDgBfzVSByOK0b5oGkteM++NKJeycL55G244kseYDCFPGqgFuFhgKHSWN32+RSDkGdv/rAyrl562SW8M+EF8TTwfxzjPSTvl1gxbiGlPEiScytluzVbp6w6NyNIvcZjvciyW1+KUJ3I/oTSoE/5UiDzMpLwdSmmPwt9osHvfI3zaQH1bS2nzXKERXpeQekk2QFneggpBA7VIyV5JYcCpg+AznpPEJeDbrjOosy2XzmxBhEXx45YN5qJ1hNXUC7fXxmA7ibj1mnvhbG7wokFK+2itOD/s/eaYKat7PLqREpB0jgKmiAa34a5t+12BX7W+qElBhrqnYmZ1Xi8RDdO6AKsR3rbx+mpKgW2/AbnoaPXvZiHd+EpAZvnJ21bGWNnAssnGx358XHf7FNtu3DovcZ+cL30leBhRIkn7dr81+sS5BtTVbwGVxPbQVq/bvT4X4+HYI0ok2AUV6XYCCmLVg9vMMtXCNcgqsASsXFn33K1jhb6sSYWnJwL5hKPSKLgueGdfHITw== 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)(366004)(1076003)(5660300002)(6486002)(86362001)(52116002)(66946007)(44832011)(6916009)(66556008)(36756003)(6506007)(66476007)(38100700002)(38350700002)(316002)(508600001)(6512007)(2616005)(4326008)(186003)(83380400001)(8936002)(6666004)(2906002)(26005)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5387 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT032.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 03902987-cf07-4622-cf07-08d9c623bbb1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sEm/xE2j4YNKgHVcnmv9lN+rY1exTpuzlm4+TCzYaopkORtbiWWsAVE/E5mtvyjVpvo1fU3+L745XEcwTgLfoBbouXm1CrnN0aVUS3rFIITVlhozoiuXGc9lo74WkwjYpKninI4ZJ3EtGC2SdcCbgWI57DVezuxQCv9kncWMfxudp9ociCDcy5Zuy4xM25MK22O+RfapEXzLzF1QJftHWjq9FVJOh0dJTeIaQbDGHiA6YD2L2wE8mkOtDxFmMnqD9bUr2WL9fRnwgBNhyB3P5LzgnvvmQ5YZCVUiRoFjTehH3GiSa+1It7FFqZ8+yMK9ZaBiMdeuaWNNbX9X6MeTF/Xdp1o0SLK7PazJ5lFHBn7cUcE9w7bhBR1KvtrRjMwKYUQNKFP4sP1pEKMkXoXS4s7ms3nID3XI0mbCBVIKx7tneg6ThfbT+tbObnhTRzgsOT3WmEA0z2xoI1xsdMp6F8/I61jxbA4tvijrsklhjqb+/2s5S0zj284AuMcEqYJaHmDm4KiVjXPFUENoqq8MoTuDZPbK+6xLkcmQRBgCWG8sB1QQubKxmfLZ1KA81RX7WeFVOhfGflYUmJqsdIAmzLLcMQMxliUtoQYaR7JxHp1Shofu8dtYjI5qGWJp0H2cXc+93SHQigFZZ899+hUOtqOxy1beBHfBdE4XkjWQAgk8tLLU0vonxzFZUW8Suw9GHgypUdXmktusG1udhTjxkQ== 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)(46966006)(36840700001)(2616005)(4326008)(47076005)(44832011)(316002)(70206006)(5660300002)(70586007)(1076003)(36756003)(6916009)(2906002)(508600001)(36860700001)(356005)(83380400001)(26005)(186003)(336012)(8676002)(6666004)(8936002)(6512007)(81166007)(82310400004)(86362001)(6506007)(6486002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Dec 2021 14:51:55.4730 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4b6154cf-9c65-4f11-f2b8-08d9c623c37e 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: VE1EUR03FT032.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1921 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 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.103.2 at phobos.denx.de X-Virus-Status: Clean This test ensures the ECPT table is present and is consistent. Invocation from the sandbox platform: add to sandbox_defconfig: +CONFIG_CMD_BOOTEFI_SELFTEST=y make sandbox_capsule_defconfig all ./u-boot -d arch/sandbox/dts/test.dtb bootefi selftest Signed-off-by: Jose Marinho --- lib/efi_selftest/Makefile | 2 + lib/efi_selftest/efi_selftest_ecpt.c | 105 +++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 lib/efi_selftest/efi_selftest_ecpt.c diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index 9ff6e1760c..6cf548653f 100644 --- a/lib/efi_selftest/Makefile +++ b/lib/efi_selftest/Makefile @@ -112,3 +112,5 @@ $(obj)/efi_selftest_loadimage.o: $(obj)/efi_miniapp_file_image_exit.h $(obj)/efi_selftest_startimage_exit.o: $(obj)/efi_miniapp_file_image_exit.h $(obj)/efi_selftest_startimage_return.o: $(obj)/efi_miniapp_file_image_return.h + +obj-$(CONFIG_EFI_ECPT) += efi_selftest_ecpt.o diff --git a/lib/efi_selftest/efi_selftest_ecpt.c b/lib/efi_selftest/efi_selftest_ecpt.c new file mode 100644 index 0000000000..555b59bc90 --- /dev/null +++ b/lib/efi_selftest/efi_selftest_ecpt.c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Test ECPT tables support + * + * Copyright (C) 2022 Arm Ltd. + */ +#include +#include +#include + +static const struct efi_system_table *local_systable; + +/* + * Setup unit test. + * + * @handle: handle of the loaded image + * @systable: system table + * @return: EFI_ST_SUCCESS for success + */ +static int setup(const efi_handle_t handle, + const struct efi_system_table *systable) +{ + local_systable = systable; + + return EFI_ST_SUCCESS; +} + +/* + * Traverse the ECPT table looking for a particular profile. + * + * @profile_guid: the guid of the conformance profile to find + * @ecpt: a pointer to the ECPT table + * @return: true if profile_guid is an entry in ECPT, false otherwise + */ +static bool find_profile(efi_guid_t *profile_guid, + struct efi_conformance_profiles_table *ecpt) +{ + for (int idx = 0; idx < local_systable->nr_tables; idx++) + if (!guidcmp(profile_guid, &ecpt->conformance_profiles[idx])) + return true; + return false; +} + +/* + * Perform the test + * + * The test consists of the following steps: + * + * 1) Obtain the ECPT + * 2) Quantify the number of expected profiles + * 3) Verify that each expected profile is in the ECPT + * 4) Ensure that the number of ECPT entries is the expected + * + * The failure of any of the above steps results in a test failure. + * + */ +static int execute(void) +{ + struct efi_conformance_profiles_table *ecpt; + efi_status_t ret = EFI_SUCCESS; + struct efi_boot_services *bt; + int expected_num_entries; + + bt = local_systable->boottime; + + if (!bt) { + efi_st_error("Cannot find boottime services structure\n"); + return EFI_ST_FAILURE; + } + + for (int idx = 0; idx < local_systable->nr_tables; idx++) + if (!guidcmp(&efi_ecpt_guid, &local_systable->tables[idx].guid)) + ecpt = (struct efi_conformance_profiles_table *) + local_systable->tables[idx].table; + + if (!ecpt) { + efi_st_error("ECPT table not present\n"); + return EFI_ST_FAILURE; + } + + /* + * Check for presence of each expected profile. + */ + if (IS_ENABLED(CONFIG_EFI_EBBR_2_0_CONFORMANCE)) { + expected_num_entries++; + if (!find_profile(&efi_ecpt_guid, ecpt)) { + efi_st_error("failed to find profile %pUL\n", &efi_ecpt_guid); + return EFI_ST_FAILURE; + } + } + + if (ecpt->number_of_profiles != expected_num_entries) { + efi_st_error("Mismatch in number of ECPT entries\n"); + return EFI_ST_FAILURE; + } + + return EFI_ST_SUCCESS; +} + +EFI_UNIT_TEST(ecpt) = { + .name = "ecpt", + .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, + .setup = setup, + .execute = execute, +}; -- 2.25.1