From patchwork Wed Nov 23 17:50:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Barker X-Patchwork-Id: 1708432 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NHTF12RV5z23lT for ; Thu, 24 Nov 2022 04:50:43 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5889F8559A; Wed, 23 Nov 2022 18:50:35 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sancloud.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 05A7B8559A; Wed, 23 Nov 2022 18:50:34 +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=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on20619.outbound.protection.outlook.com [IPv6:2a01:111:f403:704b::619]) (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 0B56D85584 for ; Wed, 23 Nov 2022 18:50:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sancloud.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=paul.barker@sancloud.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P3Bt5nyC9ILg2vokphbjm9hznxlvL1f66gI6DQehzMx9bcKPoIkpIz1wDmYfYBGWLdIsKvFXrFv2NVEtFW3Z4Q/E+AS+HbCxSUgbvSHIxaY8qE7c+9F+P8bAOQjuDfT7RUmX+BVRIBaXe43+sa3AdKqXBUnZrH+ZdzGJJUrbopaGgCmU37LWuz4qLTNq/Gl2O74W3NiVPnoJGs3kAqh5tfxcDrnyfQ37ZImScevXnWpQELl3qjXTbGUBRoV70MEiKgQlX+J2abVKPRPfD1FEbwRBHmra3fWq68sSjeZjHD5pythpwSU7r5DOyQ8cFJ5ea4ImC/nfC/TGlTm/VNadnA== 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=lfkn74wuMl/yYKeNQhMb41nGMwShC87cwH80v4+33UU=; b=RBE8T6a2cq0ujRvs6Q7JSx8KfYHcBBbN9DP1NbGWNBg9fdwtps2Sng54QofGftWtdzwL6ZhxygjdU/+MTBxNdNvVc4DGCuOIYV/NMW7eXVM/dWUhuUmEFnqq1ezYJQ75XFSA6VHRAAJiFH8VBlXMCA16qh0xQNq4ak0rBnqLAYrput5v0YsPJJhpNTk6Gh1voiJ4IOOmcCNBZdc2y8mS/Z1nLcnPt5tcEODTGviUuWiqtYd312IB7e5fpSBDNZ5Qd1e1ZpJEAK+xSpa9ADD1DOPmVnn3JPOWScDb3j9OC/146G0RbUQU8ye/UEzV3fh2Ehl7nko9ddYnIWevFPpugw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=sancloud.com; dmarc=pass action=none header.from=sancloud.com; dkim=pass header.d=sancloud.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=sancloud.com; Received: from SEYPR06MB5064.apcprd06.prod.outlook.com (2603:1096:101:55::13) by TYZPR06MB4320.apcprd06.prod.outlook.com (2603:1096:400:65::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.15; Wed, 23 Nov 2022 17:50:26 +0000 Received: from SEYPR06MB5064.apcprd06.prod.outlook.com ([fe80::3343:e4e0:2fbb:3c9c]) by SEYPR06MB5064.apcprd06.prod.outlook.com ([fe80::3343:e4e0:2fbb:3c9c%5]) with mapi id 15.20.5834.015; Wed, 23 Nov 2022 17:50:26 +0000 From: Paul Barker To: u-boot@lists.denx.de, Simon Glass , Tom Rini , Heinrich Schuchardt , Ilias Apalodimas , Jagan Teki Cc: Paul Barker Subject: [PATCH v5 0/3] Support UEFI SPI I/O protocol Date: Wed, 23 Nov 2022 17:50:03 +0000 Message-Id: <20221123175006.4080122-1-paul.barker@sancloud.com> X-Mailer: git-send-email 2.25.1 X-ClientProxiedBy: LO4P123CA0101.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:191::16) To SEYPR06MB5064.apcprd06.prod.outlook.com (2603:1096:101:55::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR06MB5064:EE_|TYZPR06MB4320:EE_ X-MS-Office365-Filtering-Correlation-Id: c64a76f5-ea7a-4a1d-527b-08dacd7b3406 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: s2nxJ0akohnU46SfQBtasr1jkBbwIC85XNRXiTXu9Tu/488pGl4O+pi0Mn6Ss0gfugw6NlgqFmoU1M1aSYVYM8pVrzqJhVDtXvuhZOgd6evfSLnLnT3BeTSRhywlW7QSkGWvzbcmE321LWFJ3nPNvmHe20t/QGQAMu+8NpeAg+1qsNlp8RJ6nMyEL4TD8VckWswF8hznk4gwkz7Cb8ZihEhENJKsUn3a3jK97+12vB3JqjFrBYsz24iBT6rF1+WjE7o/LmLUj0/Lqws0U+bE0JwuH8hMFnmqnq6Po8gspB+wKyx4acLbau43jCELZ4/+m8BRwm+QYP7o/CuQ6dcvSBOEHLZhVr0z87ggSDROe15BvfO6SAfGa9KhYsktDsqsSpYmV7+/5awklkW1kVodEQ5zGHpWLl/zSrL9fBT9dOvEYY9ICIveEXDVgM8MOAv1XUyhd6ueeVP/0gAqhQwXgziYK0d2xpvwE+ugmZb5eKnHAXhVBSyONVFV6qR9aRLxX80QXcKfyDEQ68r2fhiK+qmy2aI8gJJvLhIEkuM1RhF30w2Z2YRvQ7dHV18Y4/KKnr0ZkNIUMXI+WRnA8N7wU8GLpi9SoGmhSGQ/Uy0p28zGfs3RevvO6EIhOinztkdZfAvqjh/BDRMfTzl7jG/1zQNiTjEDjHQZj2n0SJAlSewYeYPii5+Ymt2KNzG0M4xYf9nR2WDVOYccmm5CiIJxW3uw6HsAn+uJXhVb/XHwNik= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEYPR06MB5064.apcprd06.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(346002)(396003)(39830400003)(376002)(366004)(136003)(451199015)(66476007)(83380400001)(86362001)(38350700002)(41300700001)(2906002)(38100700002)(44832011)(478600001)(8936002)(41320700001)(6512007)(5660300002)(6506007)(1076003)(6666004)(107886003)(52116002)(2616005)(4326008)(186003)(8676002)(66556008)(316002)(66946007)(26005)(6486002)(966005)(110136005)(786003)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: v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XbECBjvPyEjTIj34v8NAkH83hDn6mjSddBfdrXo1GjajIctNt+CZimjcTsB6fHMnpoiNbh26pwCVmQL+VxYpQ1O2w0lorRdQIQbnbRAtRzzxb5VdWscsDE+49VN2/wAu/ZUvgo5USewJRGfubTh/VX6XRrkmsPNHo8Etxszzszr9Ubosn+bxGsl8zClrovvr3qDw+DDC8NA6ShZzmuImZlQyBSiLt3k/ZJQRrXbdTiIwLuHjAqGAkTXIAcCPvmwSWABM7o3Rwg9bVYvDUL1bucEWNTXrGSBW1nYRE5Hc7c5z8ZusS31u3fbSkazOy1GQYjSxTdVXoPYEO32lqxtkZBH0LLOiZi9RdyhfMWP5fUrbzu7X32hgW2Rdn2DeekOXHj3UNtSsJYOzNdEP0BXUGuAcqGR2UYHnfeCtFB4/Skh6E1+MjWs/vO8JaqJLxEoyd0pLOZF6yFKp8R8DI60WHUNmdK/AK4ateE7dDn7AHmZw+2V5mNaZj04+C2X2JFEF5hB4aVGtA1O2gGIjfQo6ChVnECqsd+Pw== X-OriginatorOrg: sancloud.com X-MS-Exchange-CrossTenant-Network-Message-Id: c64a76f5-ea7a-4a1d-527b-08dacd7b3406 X-MS-Exchange-CrossTenant-AuthSource: SEYPR06MB5064.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Nov 2022 17:50:26.5409 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3e0f949f-6a74-4378-baf2-0abfca8d5e06 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: I+/6jnSers3flaIG/cb7uzODpWacokYe533BdILmKhH9E6d4aLrwyrU85VjjEc6PwJa7VcGMoHKQ9Bddz4sFNbPrPPlvr24J4cXiuw6rg0k= X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB4320 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.6 at phobos.denx.de X-Virus-Status: Clean These patches add support for the UEFI SPI I/O protocol defined in the UEFI Platform Initialization (PI) Specification, Version 1.7 Errata A (April 2020). This allows a UEFI application to interact with devices on the SPI bus. This support is initially intended to be used to communicate with SPI devices from "pre-boot" UEFI applications which perform setup before the main OS is loaded. Other use cases may also be supported, however this is not intended to be a replacement for UEFI capsule updates. The "pre-boot" UEFI application which we are currently developing will interact with a Micron Authenta[1] flash device, sending vendor-specific commands over the SPI bus to make use of Authenta security features, to verify flash integrity and to generate ephemeral keys based on the flash contents. The code here is self-contained and easy to enable/disable at compile time. Compilation testing with am335x_evm_defconfig shows that the size of u-boot.img increases by less than 2kB when CONFIG_EFI_SPI_PROTOCOL is enabled. [1]: https://www.micron.com/-/media/client/global/documents/products/product-flyer/authenta_technology_solutions_brief.pdf Changes since v4: * Dropped patches which have already been merged. * Re-based on top of my other patch series [2] to avoid conflicts in am335x-sancloud-bbe-lite-u-boot.dtsi. * Dropped `am335x_evm_defconfig: Enable Micron SPI flash support` as this was moved to my other patch series [3]. * Reformat code to fit in 80 chars per line where possible. * Use efi_install_multiple_protocol_interfaces() instead of efi_create_handle() & efi_add_protocol(). * Rename dtb properties to start with 'u-boot,'. * Move SanCloud BBE Lite dtb changes to am335x-sancloud-bbe-lite-u-boot.dtsi. * Convert remaining printf() calls to debug() calls. [2]: https://lore.kernel.org/u-boot/20221114124243.3719037-1-paul.barker@sancloud.com/ [3]: https://lore.kernel.org/u-boot/20221114124243.3719037-7-paul.barker@sancloud.com/ Changes since v3: * Add implementation of spi_set_speed() so we can use this in efi_spi_io_transaction(). * Rename convert_efi_string() to efi_convert_string() and move to efi_string.c as a common helper function. * Call spi_set_speed() instead of manually de-referencing the function pointer in struct dm_spi_ops. * Don't call efi_delete_handle() in destroy_efi_spi_peripheral(). * Use '%pUl' to print guid string. * Split efi_selftest changes into a separate patch. Changes since v2: * Added description to efi_spi_protocol.h. * Moved definition of EFI_SPI_CONFIGURATION_GUID to efi_api.h and added it to the list in lib/uuid.c. * Fixed UEFI GUID byte order in test.dts and in debug output. * Use log_debug() instead of printf() for debug output. * Add test cases to confirm that efi_legacy_spi_controller_protocol functions return EFI_UNSUPPORTED (as they are not currently implemented) Changes since v1: * Skip emulated SPI peripherals. These appear as duplicates within the list of devices on the bus when using the sandbox SPI drivers. * Make most printf statements debug only. * Add efi_seltest unit test. * Do not enable config EFI_SPI_PROTOCOL by default. * Mark functions with EFIAPI where necessary. * Handle debug_transaction argument to efi_spi_io_transaction(). * Handle a value of zero for target->max_read_size & target->max_write_size. * Probe inactive SPI devices when initializing the EFI SPI protocol to ensure that dev_get_parent_priv() returns valid data and the exported devices are ready to use. Paul Barker (3): efi_loader: Add SPI I/O protocol support efi_selftest: Add tests for SPI protocol support arm: dts: am335x-sancloud-bbe-lite: UEFI SPI export MAINTAINERS | 7 + .../dts/am335x-sancloud-bbe-lite-u-boot.dtsi | 13 +- arch/arm/dts/am335x-sancloud-bbe-lite.dts | 2 +- arch/sandbox/dts/test.dts | 13 + configs/am335x_evm_defconfig | 1 + include/efi_api.h | 4 + include/efi_loader.h | 4 + include/efi_spi_protocol.h | 166 +++++ lib/efi_loader/Kconfig | 8 + lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_setup.c | 6 + lib/efi_loader/efi_spi_protocol.c | 576 ++++++++++++++++++ lib/efi_selftest/Makefile | 1 + lib/efi_selftest/efi_selftest_spi_protocol.c | 284 +++++++++ lib/uuid.c | 4 + 15 files changed, 1086 insertions(+), 4 deletions(-) create mode 100644 include/efi_spi_protocol.h create mode 100644 lib/efi_loader/efi_spi_protocol.c create mode 100644 lib/efi_selftest/efi_selftest_spi_protocol.c