From patchwork Sun Mar 14 19:05:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 400111 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2861772jai; Sun, 14 Mar 2021 12:06:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6j8L88U4f/rx4xKxwIMO44OfQKcNfC/vg1JzXdJl3169uc7r53q74LE633pr1GvPBJSGD X-Received: by 2002:a17:906:c405:: with SMTP id u5mr19893280ejz.341.1615748766201; Sun, 14 Mar 2021 12:06:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615748766; cv=none; d=google.com; s=arc-20160816; b=XAFYIkuUreW+2Po4J0KrKfTY8CeDweA05waBcK8uo6XMy/uKbVNcYNZB/i/J3ALeJC cgRoWCmVw4jwZIeNbIFXcRr72bqSV2f9R2iZtIlWp5uZvcydBHp+nKr3p7vC4u97cn3R jMs60i/h0ZoaQ8SFs7vk0k2rK9cKTvcxxH8IR8+SFzdCfAn98CDcYgjHVO5KRQFslJv1 Y+ZHIXRLdU0V0KEGD1CBr5voxPIQ0Vm7engoPGvuihKoOtC+wOeRnmn+G4Cl+J+gGItC 3GQ6QemtUjjK2gwWoVgDsx2G45QxqbUJiJM0cJKOBjGmdOQYX9XMTWsVuck2XWWiawjX SQjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ocTK3X6ASpF320o4ymRG7C/8gkZtPsgEWtN76uAfrAg=; b=nY5+Fg2luSgmF57BYoTsLabDVaEH0eh98UmOSkdkXnQgtpkKC6a1/wTzjS9GLTuVyU +B0AzFBFgjTaHfMXLlnR90QWpKgPrdgup6YcMH7J+iB9a5awt+0rMNRjvME+cT3kGvMo URl8ceVcuiH2QzxNz+eRUGu57iUHZuU2T/x3wygPh2N9Gql+OcEyrezqw1oUFeJPzoev v0EMaIDsKxABYhn2RQodApFbjDT4xYf0oSimseMWjgrBWRiygAK4mExh924Bo4sy729O 3vu4ul89DFzW+Kexd4liSV5VYa7EsaDVJFB2rl2aIA4je02es7JxyUl7FDeaoP0uJTfG Kg8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PZaCy6z1; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id x21si9556894eju.471.2021.03.14.12.06.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 12:06:06 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PZaCy6z1; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5AC5082944; Sun, 14 Mar 2021 20:05:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="PZaCy6z1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 149CD82906; Sun, 14 Mar 2021 20:05:54 +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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B90F482935 for ; Sun, 14 Mar 2021 20:05:49 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wr1-x42a.google.com with SMTP id j7so4610038wrd.1 for ; Sun, 14 Mar 2021 12:05:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ocTK3X6ASpF320o4ymRG7C/8gkZtPsgEWtN76uAfrAg=; b=PZaCy6z1o7M7Ef3eDIIB06HyJdShF9iFXWUFjZ5A7qdj9Kh6crbN9IWDE446X9lSvm T/Li24SJYzK7JfjEa7ojPXbNxob3creZDOf0Vis5E9eR813RUDS28qXAFX/kJzu+8YKq UWdjp/O5EtP8MBUyIFmdIPRxMkdq/HsC3zwbADbCX5GvKCBGWK7kdFhTijYNSGNaewuF t+gTfWBn7nsQ0CPbXMvaEk9l0Yn+hOHl9cuNDJokIKFSAHGnNWh5EX1ptKfRxm4OZ0fL WQoOtyMH78CRRSYK6hEiwYimIMut6ZFfPIS2x8fqoYspRyPBBkn13/qNF+x+sN95hDK/ EYrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ocTK3X6ASpF320o4ymRG7C/8gkZtPsgEWtN76uAfrAg=; b=agdeTuy68WBME67b8IGRwt6tLr2W50mm+8w77G/3CL8j/JfPxol/LVGxGy0EwzWTQr jOtWl2MARC44JCCqswgaeDqMljmzEy7BjTf2WfWl+KFVwzZ8ek0c8dnJjnjcmkeTdOD1 gFsb640+MCdiQClDTFwzXkVOlLl3G3kUI0g0ch2CvqnRRzjbmpoSZ3FM/d0rs+76BcAi O3EkX13URi3KBDeB008iWX4LhGQx5yFNTpN2/oicbE0exefvMmFHk4E1uYcDN0QllNuJ DAl9TdDF/IEi9LXEcFFTTkzpUIfCB55PMVfGHKtS19WILzpraSdOQrd57sApe2F58HoX ky/w== X-Gm-Message-State: AOAM5313Jv43p59XeoO/3jCr6imdt74f3lYBZv0NqK/bCDcO0pmt7rzs GqfbAeRUhI938NpbgwBI8muSJQ== X-Received: by 2002:adf:f60b:: with SMTP id t11mr18909037wrp.269.1615748749265; Sun, 14 Mar 2021 12:05:49 -0700 (PDT) Received: from localhost.localdomain (ppp-94-64-113-158.home.otenet.gr. [94.64.113.158]) by smtp.gmail.com with ESMTPSA id 3sm18718029wry.72.2021.03.14.12.05.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 12:05:48 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, Ilias Apalodimas , Alexander Graf , Sughosh Ganu , u-boot@lists.denx.de Subject: [PATCH 1/6 v3] efi_selftest: Remove loadfile2 for initrd selftests Date: Sun, 14 Mar 2021 21:05:33 +0200 Message-Id: <20210314190541.129687-2-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314190541.129687-1-ilias.apalodimas@linaro.org> References: <20210314190541.129687-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean We are redefining how u-boot locates the initrd to load via the kernel LoadFile2 protocol. This selftest is not relevant any more, so remove it. A new one will be added later Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- lib/efi_selftest/Makefile | 1 - lib/efi_selftest/efi_selftest_load_initrd.c | 221 -------------------- 2 files changed, 222 deletions(-) delete mode 100644 lib/efi_selftest/efi_selftest_load_initrd.c -- 2.30.2 diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index b02fd56e0a79..50de581b7763 100644 --- a/lib/efi_selftest/Makefile +++ b/lib/efi_selftest/Makefile @@ -61,7 +61,6 @@ obj-$(CONFIG_CPU_V7) += efi_selftest_unaligned.o obj-$(CONFIG_EFI_LOADER_HII) += efi_selftest_hii.o obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_selftest_rng.o obj-$(CONFIG_EFI_GET_TIME) += efi_selftest_rtc.o -obj-$(CONFIG_EFI_LOAD_FILE2_INITRD) += efi_selftest_load_initrd.o obj-$(CONFIG_EFI_TCG2_PROTOCOL) += efi_selftest_tcg2.o ifeq ($(CONFIG_GENERATE_ACPI_TABLE),) diff --git a/lib/efi_selftest/efi_selftest_load_initrd.c b/lib/efi_selftest/efi_selftest_load_initrd.c deleted file mode 100644 index f591dcd2115e..000000000000 --- a/lib/efi_selftest/efi_selftest_load_initrd.c +++ /dev/null @@ -1,221 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * efi_selftest_load_initrd - * - * Copyright (c) 2020 Ilias Apalodimas - * - * This test checks the FileLoad2 protocol. - * A known file is read from the file system and verified. - * - * An example usage - given a file image with a file system in partition 1 - * holding file initrd - is: - * - * * Configure the sandbox with - * - * CONFIG_EFI_SELFTEST=y - * CONFIG_EFI_LOAD_FILE2_INITRD=y - * CONFIG_EFI_INITRD_FILESPEC="host 0:1 initrd" - * - * * Run ./u-boot and execute - * - * host bind 0 image - * setenv efi_selftest load initrd - * bootefi selftest - * - * This would provide a test output like: - * - * Testing EFI API implementation - * - * Selected test: 'load initrd' - * - * Setting up 'load initrd' - * Setting up 'load initrd' succeeded - * - * Executing 'load initrd' - * Loaded 12378613 bytes - * CRC32 2997478465 - * - * Now the size and CRC32 can be compared to the provided file. - */ - -#include -#include -#include - -static struct efi_boot_services *boottime; - -static struct efi_initrd_dp dp = { - .vendor = { - { - DEVICE_PATH_TYPE_MEDIA_DEVICE, - DEVICE_PATH_SUB_TYPE_VENDOR_PATH, - sizeof(dp.vendor), - }, - EFI_INITRD_MEDIA_GUID, - }, - .end = { - DEVICE_PATH_TYPE_END, - DEVICE_PATH_SUB_TYPE_END, - sizeof(dp.end), - } -}; - -static struct efi_initrd_dp dp_invalid = { - .vendor = { - { - DEVICE_PATH_TYPE_MEDIA_DEVICE, - DEVICE_PATH_SUB_TYPE_VENDOR_PATH, - sizeof(dp.vendor), - }, - EFI_INITRD_MEDIA_GUID, - }, - .end = { - 0x8f, /* invalid */ - 0xfe, /* invalid */ - sizeof(dp.end), - } -}; - -static int setup(const efi_handle_t handle, - const struct efi_system_table *systable) -{ - boottime = systable->boottime; - - return EFI_ST_SUCCESS; -} - -static int execute(void) -{ - struct efi_load_file_protocol *lf2; - struct efi_device_path *dp2, *dp2_invalid; - efi_status_t status; - efi_handle_t handle; - char buffer[64]; - efi_uintn_t buffer_size; - void *buf; - u32 crc32; - - memset(buffer, 0, sizeof(buffer)); - - dp2 = (struct efi_device_path *)&dp; - status = boottime->locate_device_path(&efi_guid_load_file2_protocol, - &dp2, &handle); - if (status != EFI_SUCCESS) { - efi_st_error("Unable to locate device path\n"); - return EFI_ST_FAILURE; - } - - status = boottime->handle_protocol(handle, - &efi_guid_load_file2_protocol, - (void **)&lf2); - if (status != EFI_SUCCESS) { - efi_st_error("Unable to locate protocol\n"); - return EFI_ST_FAILURE; - } - - /* Case 1: - * buffer_size can't be NULL - * protocol can't be NULL - */ - status = lf2->load_file(lf2, dp2, false, NULL, &buffer); - if (status != EFI_INVALID_PARAMETER) { - efi_st_error("Buffer size can't be NULL\n"); - return EFI_ST_FAILURE; - } - buffer_size = sizeof(buffer); - status = lf2->load_file(NULL, dp2, false, &buffer_size, &buffer); - if (status != EFI_INVALID_PARAMETER) { - efi_st_error("Protocol can't be NULL\n"); - return EFI_ST_FAILURE; - } - - /* - * Case 2: Match end node type/sub-type on device path - */ - dp2_invalid = (struct efi_device_path *)&dp_invalid; - buffer_size = sizeof(buffer); - status = lf2->load_file(lf2, dp2_invalid, false, &buffer_size, &buffer); - if (status != EFI_INVALID_PARAMETER) { - efi_st_error("Invalid device path type must return EFI_INVALID_PARAMETER\n"); - return EFI_ST_FAILURE; - } - - status = lf2->load_file(lf2, dp2_invalid, false, &buffer_size, &buffer); - if (status != EFI_INVALID_PARAMETER) { - efi_st_error("Invalid device path sub-type must return EFI_INVALID_PARAMETER\n"); - return EFI_ST_FAILURE; - } - - /* - * Case 3: - * BootPolicy 'true' must return EFI_UNSUPPORTED - */ - buffer_size = sizeof(buffer); - status = lf2->load_file(lf2, dp2, true, &buffer_size, &buffer); - if (status != EFI_UNSUPPORTED) { - efi_st_error("BootPolicy true must return EFI_UNSUPPORTED\n"); - return EFI_ST_FAILURE; - } - - /* - * Case: Pass buffer size as zero, firmware must return - * EFI_BUFFER_TOO_SMALL and an appropriate size - */ - buffer_size = 0; - status = lf2->load_file(lf2, dp2, false, &buffer_size, NULL); - if (status != EFI_BUFFER_TOO_SMALL || !buffer_size) { - efi_st_printf("buffer_size: %u\n", (unsigned int)buffer_size); - efi_st_printf("status: %x\n", (unsigned int)status); - efi_st_error("Buffer size not updated\n"); - return EFI_ST_FAILURE; - } - - /* - * Case: Pass buffer size as smaller than the file_size, - * firmware must return * EFI_BUFFER_TOO_SMALL and an appropriate size - */ - buffer_size = 1; - status = lf2->load_file(lf2, dp2, false, &buffer_size, &buffer); - if (status != EFI_BUFFER_TOO_SMALL || buffer_size <= 1) { - efi_st_error("Buffer size not updated\n"); - return EFI_ST_FAILURE; - } - - status = boottime->allocate_pool(EFI_BOOT_SERVICES_DATA, buffer_size, - &buf); - if (status != EFI_SUCCESS) { - efi_st_error("Cannot allocate buffer\n"); - return EFI_ST_FAILURE; - } - - /* Case: Pass correct buffer, load the file and verify checksum*/ - status = lf2->load_file(lf2, dp2, false, &buffer_size, buf); - if (status != EFI_SUCCESS) { - efi_st_error("Loading initrd failed\n"); - return EFI_ST_FAILURE; - } - - efi_st_printf("Loaded %u bytes\n", (unsigned int)buffer_size); - status = boottime->calculate_crc32(buf, buffer_size, &crc32); - if (status != EFI_SUCCESS) { - efi_st_error("Could not determine CRC32\n"); - return EFI_ST_FAILURE; - } - efi_st_printf("CRC32 %.8x\n", (unsigned int)crc32); - - status = boottime->free_pool(buf); - if (status != EFI_SUCCESS) { - efi_st_error("Cannot free buffer\n"); - return EFI_ST_FAILURE; - } - - return EFI_ST_SUCCESS; -} - -EFI_UNIT_TEST(load_initrd) = { - .name = "load initrd", - .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, - .setup = setup, - .execute = execute, - .on_request = true, -}; From patchwork Sun Mar 14 19:05:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 400112 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2861903jai; Sun, 14 Mar 2021 12:06:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyU8a4KhzuiLmiU24yBdiy2qzR2Rmhuw9vCKtHo73ZEUVavLw7OWm5WgtKA1ehw1mXxUoLu X-Received: by 2002:a05:6402:b2a:: with SMTP id bo10mr6198291edb.144.1615748777870; Sun, 14 Mar 2021 12:06:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615748777; cv=none; d=google.com; s=arc-20160816; b=r0BIbi218v515RvG141Gg7pe6YTrvmb3F++zWAAWGWuQX7pjCEJBaKxWnjHkF6z7Vl RwNe+dxHTLq3GVBqPFW74AHGMZRkn3H7qLrjK2p4vduKt2D5BxhlhRQK+6PEmtFrjSsc YDhR8VPnCSQuLiH1al7pIMdBwzUpZqoHLC+bxK+HDsfpI75Pl+XQxqeKAkpG13hL3Y7y LjFX7+t/5bmTz0pxmqQNel6nRzxAYQCagXlmNyfh9P66JyeFAxwhB5mw8e3L512vrkqC 5izsQdUu+mc605o57Mex2rgFPeefbsNB3cosjmh5qRf8UXMNfAWb1wr5kHIDBGdnnsNa V8QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uG4maLm+fRSlIZABVE5eBCkYjrC1YtWc1i+8/L5o+j8=; b=t9lzki3HE3yiBVNq7/fBZt7aN0KENTgHjuEmWTVmyHXoOSL1P+ZsUlKG7E20JquOCZ jcJNXIZq9q4+xNUvNDhcO6Abjz4Gv+Ok8uWYTdMjo8WKAkfKrbQodT5wm+dBaag1ocik x6W8HWlXHujVrSK6MKq6pFuXCj6HO0AXKiVZB4fmr4EGAbfdmRK5c6Zg/YjCKJXxAe1A 47xYlkgoXeqe+FlEKgxE2nmPWxAdJ3RbM4IZ9Xqq58+mJGBoUImMmDqt/NA2vO04IGow 1icZuCAj5CbiDzCCQWT9fal1Ra60lsSVGxD7KE2acMDPx22Hv8gTCPLWnSJK0MVf2qDg cfOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Au5XU5yN; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id cw1si9909615edb.412.2021.03.14.12.06.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 12:06:17 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Au5XU5yN; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1B47382970; Sun, 14 Mar 2021 20:06:01 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Au5XU5yN"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4968E82944; Sun, 14 Mar 2021 20:05:57 +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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3D7C88285A for ; Sun, 14 Mar 2021 20:05:54 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wr1-x432.google.com with SMTP id b9so4616374wrt.8 for ; Sun, 14 Mar 2021 12:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uG4maLm+fRSlIZABVE5eBCkYjrC1YtWc1i+8/L5o+j8=; b=Au5XU5yNx3/8+PXaZbCdzgM09+npt300TS29/+PhpD5XUqkmuv4YQ5c9FRQX3ZHBTJ LeGtlxFpA9Ix9pLaLNQPEsI7r/TkwLaRR0JKnGgeNB6tCkYn+sr0ZJOybFBYF2ApTTGd 2ABw5UyYvCVXLh4risT0vyr3tJ6RI1gH/5QGMVciV26/okUyjAwPsxiIM8nYKGgstuRK 6V1csO92os0r49vNZEPafZ/G0zWnJ7J0FShV3eRDm8mVxFbbAfeJ/02YHDOi29sATmMg newzT4J+18Iy0QVoSpeN/Nq2SA2t/+jhVQl0cuCJRUyIwxMVeSgw0ZH9zDFkOKKUelvm unxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uG4maLm+fRSlIZABVE5eBCkYjrC1YtWc1i+8/L5o+j8=; b=S6hn+f1qQv0rN5vWmBvTzDj9no6KU7e29B4qImPL2ydMDBDely8EAtOioq8nnd1ZHR qFhdA7IEvPTitmtF6NpFp+68gXPZ9InqYHiAQLT0+PxsQ8IslpAxBEBuwM5CW+p8GI3C opuCIMCYquXrUJmqkx1Cr9HPY/txJKWHzmknfghDd5QoaDugZTffz1OcD5c1r51t+fx+ NLqnFPygkT0UtW2dV2ZOmhfNic9RiMsBi+Csx/j1RUwqQKHeBDX0nmZS/Pu7H3ATnlz3 9m0qcbjevIXwtZsuPBG8cita1QyWvjvwuqObVt3a0+y1NMIDyR06+UylVc6L5rxrAdUZ R0WQ== X-Gm-Message-State: AOAM530XBtkGZ1O1v5B5h/D1NhTacp16ZK94Iv41tbDO2W5WYqm9nZet l7oS81/ALR8IsdS9Sfc2mTHICA== X-Received: by 2002:a5d:63d2:: with SMTP id c18mr23782071wrw.277.1615748753802; Sun, 14 Mar 2021 12:05:53 -0700 (PDT) Received: from localhost.localdomain (ppp-94-64-113-158.home.otenet.gr. [94.64.113.158]) by smtp.gmail.com with ESMTPSA id 3sm18718029wry.72.2021.03.14.12.05.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 12:05:53 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, Ilias Apalodimas , Alexander Graf , Sughosh Ganu , u-boot@lists.denx.de Subject: [PATCH 2/6 v3] efi_loader: Add device path related functions for initrd via Boot#### Date: Sun, 14 Mar 2021 21:05:34 +0200 Message-Id: <20210314190541.129687-3-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314190541.129687-1-ilias.apalodimas@linaro.org> References: <20210314190541.129687-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean On the following patches we allow for an initrd path to be stored in Boot#### variables. Specifically we encode in the FIlePathList[] of the EFI_LOAD_OPTIONS for each Boot#### variable. The FilePathList[] array looks like this: kernel - 0xff - VenMedia(initrd GUID) - initrd1 - 0x01 initrd2 - 0xff So let's add the relevant functions to concatenate and retrieve a device path based on a Vendor GUID. Signed-off-by: Ilias Apalodimas --- include/efi_loader.h | 4 ++ lib/efi_loader/efi_device_path.c | 106 +++++++++++++++++++++++++++++-- 2 files changed, 105 insertions(+), 5 deletions(-) -- 2.30.2 diff --git a/include/efi_loader.h b/include/efi_loader.h index f470bbd636f4..eb11a8c7d4b1 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -738,6 +738,10 @@ struct efi_load_option { const u8 *optional_data; }; +struct efi_device_path *efi_dp_from_lo(struct efi_load_option *lo, + efi_uintn_t *size, efi_guid_t guid); +struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1, + const struct efi_device_path *dp2); efi_status_t efi_deserialize_load_option(struct efi_load_option *lo, u8 *data, efi_uintn_t *size); unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data); diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index c9315dd45857..1491251e224b 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -282,11 +282,30 @@ struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp) return ndp; } -struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1, - const struct efi_device_path *dp2) +/** efi_dp_append_or_concatenate() - Append or concatenate two device paths. + * Concatenated device path will be separated + * by a sub-type 0xff end node + * + * @dp1: First device path + * @dp2: Second device path + * @concat: If true the two device paths will be concatenated and separated + * by an end of entrire device path sub-type 0xff end node. + * If true the second device path will be appended to the first and + * terminated by an end node + * + * Return: concatenated device path or NULL. Caller must free the returned + * value + */ +static struct +efi_device_path *efi_dp_append_or_concatenate(const struct efi_device_path *dp1, + const struct efi_device_path *dp2, + bool concat) { struct efi_device_path *ret; + size_t end_size = sizeof(END); + if (concat) + end_size = 2 * sizeof(END); if (!dp1 && !dp2) { /* return an end node */ ret = efi_dp_dup(&END); @@ -298,18 +317,56 @@ struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1, /* both dp1 and dp2 are non-null */ unsigned sz1 = efi_dp_size(dp1); unsigned sz2 = efi_dp_size(dp2); - void *p = dp_alloc(sz1 + sz2 + sizeof(END)); + void *p = dp_alloc(sz1 + sz2 + end_size); if (!p) return NULL; + ret = p; memcpy(p, dp1, sz1); + p += sz1; + + if (concat) { + memcpy(p, &END, sizeof(END)); + p += sizeof(END); + } + /* the end node of the second device path has to be retained */ - memcpy(p + sz1, dp2, sz2 + sizeof(END)); - ret = p; + memcpy(p, dp2, sz2); + p += sz2; + memcpy(p, &END, sizeof(END)); } return ret; } +/** efi_dp_append() - Append a device to an existing device path. + * + * @dp1: First device path + * @dp2: Second device path + * + * Return: concatenated device path or NULL. Caller must free the returned + * value + */ +struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1, + const struct efi_device_path *dp2) +{ + return efi_dp_append_or_concatenate(dp1, dp2, false); +} + +/** efi_dp_concat() - Concatenate 2 device paths. The final device path will + * contain two device paths separated by and end node (0xff). + * + * @dp1: First device path + * @dp2: Second device path + * + * Return: concatenated device path or NULL. Caller must free the returned + * value + */ +struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1, + const struct efi_device_path *dp2) +{ + return efi_dp_append_or_concatenate(dp1, dp2, true); +} + struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp, const struct efi_device_path *node) { @@ -1160,3 +1217,42 @@ ssize_t efi_dp_check_length(const struct efi_device_path *dp, dp = (const struct efi_device_path *)((const u8 *)dp + len); } } + +/** + * efi_dp_from_lo() - Get the instance of a VenMedia node in a + * multi-instance device path that matches + * a specific GUID. This kind of device paths + * is found in Boot#### options describing an + * initrd location + * + * @load_option: EFI_LOAD_OPTION containing a valid device path + * @size: size of the discovered device path + * @guid: guid to search for + * + * Return: device path including the VenMedia node or NULL. + * Caller must free the returned value + */ +struct +efi_device_path *efi_dp_from_lo(struct efi_load_option *lo, + efi_uintn_t *size, efi_guid_t guid) +{ + struct efi_device_path *fp = lo->file_path; + struct efi_device_path_vendor *vendor; + int lo_len = lo->file_path_length; + + for (; lo_len >= sizeof(struct efi_device_path); + lo_len -= fp->length, fp = (void *)fp + fp->length) { + if (lo_len < 0 || efi_dp_check_length(fp, lo_len) < 0) + break; + if (fp->type != DEVICE_PATH_TYPE_MEDIA_DEVICE || + fp->sub_type != DEVICE_PATH_SUB_TYPE_VENDOR_PATH) + continue; + + vendor = (struct efi_device_path_vendor *)fp; + if (!guidcmp(&vendor->guid, &guid)) + return efi_dp_dup(fp); + } + log_debug("VenMedia(%pUl) not found in %ls\n", &guid, lo->label); + + return NULL; +} From patchwork Sun Mar 14 19:05:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 400113 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2862027jai; Sun, 14 Mar 2021 12:06:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+8ZT582yJvMnXVz9q2+HRS6KIAoJ6ilv+bz98Ke4krWg6Y104vEqobMfxwn5+GPGZZ7Lm X-Received: by 2002:a17:906:b7d5:: with SMTP id fy21mr5071026ejb.153.1615748790415; Sun, 14 Mar 2021 12:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615748790; cv=none; d=google.com; s=arc-20160816; b=t2RZUTS90xjV4Ic1u3+woa6qZVfchuwLlp0/Q5JC/qFXZ0U37kIyZLhvDIazI6woTN phVh2E9bPH2iQLCclGgCUAyXK9RygykiDXfUzopANL9QUVc7h71sz1dZ0aQGspq4Hd2s 5AfTa8gqPF91JEayj6w5QI+q2uGptqY6bE3+3JREq5k00mah7j1RfeL9c6EfP8I92TrX pmCK7rqLF4SzRAgwBqQtgRg2jh+mQVrUkjRUelZmwGdYGVrfBI5xfZuAmxTgI4zvnumG 5wwxXaVrs93NyhTuYwwWXIa1yXFCFOG7WKhAcPiGiVhOY6HOdyPwJ1fY3mhDrzHQceIU IYqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=aucN0R1bTsCuusS52LQughd1Obv4V/vjNdPUbjUadNA=; b=vDnXuKFZs4BdFuTAwcTraqTtZkxKlPtw0i385Dgyua5OLXanm0WA1agl0RcoKMfXdb Vs4QBTbKUuTeTBEK62zthI+EjZKT37lNo9z/8JN1mcwOdg1KufjgFgNqC0cso+jTHEhP CF4K++3hNOv6Yw6hgE2suThJR/g7NzHmAK0mzZXf6W3XPeY4mY/J/wt/nftHueq4qEqK JreG8zrRlGe0Nsp3ggvFn/yuddp+W6pC2yPa/HzpwsnGCYnnL9Z3c3byCBdzm3SxVycY qNb3Z2o0UaBNJEz5strJvDWM5QDtouf1NjOxpePseIBuEk1/PmSq8E7UuuvED+Az95T2 EPdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZWRERxsl; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id yj20si10146556ejb.318.2021.03.14.12.06.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 12:06:30 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZWRERxsl; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D205B82976; Sun, 14 Mar 2021 20:06:06 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="ZWRERxsl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BEB998297D; Sun, 14 Mar 2021 20:06:03 +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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A6FD082946 for ; Sun, 14 Mar 2021 20:05:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wr1-x42d.google.com with SMTP id f12so7578822wrx.8 for ; Sun, 14 Mar 2021 12:05:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aucN0R1bTsCuusS52LQughd1Obv4V/vjNdPUbjUadNA=; b=ZWRERxsl8+ix/TqhWVNV88G2KzPvwwZazaZK6FvOO57ATDl17QGeQhESlhQoSsG3/V 9tIJTgKz8aHa3iE6xzvuJx99roMOektkWYWzk32AEpB/Or3skjSZjGTfK6b1n+7OLRJ+ yF38MJjXlTSL53MNJS+ReSQM/5n47jq3hfc+aFWCyFEmmkeXXVVS7k4gUz1LMOW9PFiD FU6d6XpOrG8eeLBWwzPIHjVZo2x98XbqZU71Lx1XpBJXHeJ+n8WjlgxW4ADCKhlkL1U4 1t34LyBPVSpmnfJlMFmL+0+fj0umbEu5p2dyb2af2PERMmZRjJNT3Tit03hncGM5EYk/ E+nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aucN0R1bTsCuusS52LQughd1Obv4V/vjNdPUbjUadNA=; b=CfLrsbX8m47BOxbSVpHhG3MeWfNJnwInPFPSk/eOL5OcxkkWrFk9/KLYjselpn+Tjb nNRMQrchuPcGbWF7fvbNKtWhJmPKey0XP8O+ZT/Y07IZ2tMrsfIKzElT+2VyqmOI6r28 GEczl/H2ydWq+pfuZBXVqaVBBkzNaYx2zRsUBYOkH7TI0/qxGeFSg38hKhwiUnyTmCUk 7ZnSQRyLKudo1C4X1XhI3Tte0rP45Hkonzk18sSSQooYJ5tKoig18Ct5PXqpZKrjfHtT ZutJgntexv0DRn50lTfPWquOTGJKJicjPSruCHj4NGbNiUBVrvyIlH5CEfSgABVA2sUm sbiw== X-Gm-Message-State: AOAM532mJ9ZIBEPJ6P2cLoo5N++gs5uT1+ESGYbrfEBr/Z5O3y8Ce9Fj tDaRn39ElF+XZUj5CDCglv6CjQ== X-Received: by 2002:a5d:404d:: with SMTP id w13mr24247390wrp.230.1615748758276; Sun, 14 Mar 2021 12:05:58 -0700 (PDT) Received: from localhost.localdomain (ppp-94-64-113-158.home.otenet.gr. [94.64.113.158]) by smtp.gmail.com with ESMTPSA id 3sm18718029wry.72.2021.03.14.12.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 12:05:57 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, Ilias Apalodimas , Alexander Graf , Sughosh Ganu , u-boot@lists.denx.de Subject: [PATCH 3/6 v3] efi_loader: Add helper functions for EFI Date: Sun, 14 Mar 2021 21:05:35 +0200 Message-Id: <20210314190541.129687-4-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314190541.129687-1-ilias.apalodimas@linaro.org> References: <20210314190541.129687-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean A following patch introduces a different logic for loading initrd's based on the EFI_LOAD_FILE2_PROTOCOL. Since similar logic can be applied in the future for other system files (i.e DTBs), let's add some helper functions which will retrieve and parse file paths stored in EFI variables. Signed-off-by: Ilias Apalodimas --- include/efi_loader.h | 7 +++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_file.c | 39 +++++++++++++ lib/efi_loader/efi_helper.c | 98 +++++++++++++++++++++++++++++++++ lib/efi_loader/efi_var_common.c | 33 +++++++++++ 5 files changed, 178 insertions(+) create mode 100644 lib/efi_loader/efi_helper.c -- 2.30.2 diff --git a/include/efi_loader.h b/include/efi_loader.h index eb11a8c7d4b1..25302628d8a8 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -552,6 +552,11 @@ struct efi_simple_file_system_protocol *efi_simple_file_system( /* open file from device-path: */ struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp); +efi_status_t efi_file_size(struct efi_file_handle *fh, efi_uintn_t *size); + +/* get a device path from a Boot#### option */ +struct efi_device_path *efi_get_dp_from_boot(const efi_guid_t guid); + /** * efi_size_in_pages() - convert size in bytes to size in pages * @@ -717,6 +722,8 @@ efi_status_t EFIAPI efi_query_variable_info( u64 *remaining_variable_storage_size, u64 *maximum_variable_size); +void *efi_get_var(u16 *name, const efi_guid_t *vendor, efi_uintn_t *size); + /* * See section 3.1.3 in the v2.7 UEFI spec for more details on * the layout of EFI_LOAD_OPTION. In short it is: diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index 10b42e8847bf..da2741adecfa 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -23,6 +23,7 @@ endif obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o obj-$(CONFIG_CMD_BOOTEFI_BOOTMGR) += efi_bootmgr.o obj-y += efi_boottime.o +obj-y += efi_helper.o obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += efi_capsule.o obj-$(CONFIG_EFI_CAPSULE_FIRMWARE) += efi_firmware.o obj-y += efi_console.o diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index 8ece8e71ee1c..bebcb520272a 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -409,6 +409,45 @@ static efi_status_t efi_get_file_size(struct file_handle *fh, return EFI_SUCCESS; } +/** + * efi_file_size() - Get the size of a file using an EFI file handle + * + * @handle: EFI file handle + * @size: buffer to fill in the discovered size + * + * Return: size of the file + */ +efi_status_t efi_file_size(struct efi_file_handle *fh, efi_uintn_t *size) +{ + struct efi_file_info *info = NULL; + efi_uintn_t bs = 0; + efi_status_t ret; + + *size = 0; + ret = EFI_CALL(fh->getinfo(fh, (efi_guid_t *)&efi_file_info_guid, &bs, + info)); + if (ret != EFI_BUFFER_TOO_SMALL) { + ret = EFI_DEVICE_ERROR; + goto out; + } + + info = malloc(bs); + if (!info) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + ret = EFI_CALL(fh->getinfo(fh, (efi_guid_t *)&efi_file_info_guid, &bs, + info)); + if (ret != EFI_SUCCESS) + goto out; + + *size = info->file_size; + +out: + free(info); + return ret; +} + static efi_status_t file_read(struct file_handle *fh, u64 *buffer_size, void *buffer) { diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c new file mode 100644 index 000000000000..d03a7364615e --- /dev/null +++ b/lib/efi_loader/efi_helper.c @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2020, Linaro Limited + */ + +#define LOG_CATEGORY LOGC_EFI +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * efi_create_current_boot_var() - Return Boot#### name were #### is replaced by + * the value of BootCurrent + * + * @var_name: variable name + * @var_name_size: size of var_name + * + * Return: Status code + */ +static efi_status_t efi_create_current_boot_var(u16 var_name[], + size_t var_name_size) +{ + efi_uintn_t boot_current_size; + efi_status_t ret; + u16 boot_current; + u16 *pos; + + boot_current_size = sizeof(boot_current); + ret = efi_get_variable_int(L"BootCurrent", + &efi_global_variable_guid, NULL, + &boot_current_size, &boot_current, NULL); + if (ret != EFI_SUCCESS) + goto out; + + pos = efi_create_indexed_name(var_name, var_name_size, "Boot", + boot_current); + if (!pos) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + +out: + return ret; +} + +/** + * efi_get_dp_from_boot() - Retrieve and return a device path from an EFI + * Boot### variable. + * A boot option may contain an array of device paths. + * We use a VenMedia() with a specific GUID to identify + * the usage of the array members. This function is + * used to extract a specific device path + * + * @guid: vendor GUID of the VenMedia() device path node identifying the + * device path + * + * Return: device path or NULL. Caller must free the returned value + */ +struct efi_device_path *efi_get_dp_from_boot(const efi_guid_t guid) +{ + struct efi_device_path *file_path = NULL; + struct efi_device_path *tmp = NULL; + struct efi_load_option lo; + void *var_value = NULL; + efi_uintn_t size; + efi_status_t ret; + u16 var_name[16]; + + ret = efi_create_current_boot_var(var_name, sizeof(var_name)); + if (ret != EFI_SUCCESS) + return NULL; + + var_value = efi_get_var(var_name, &efi_global_variable_guid, &size); + if (!var_value) + return NULL; + + ret = efi_deserialize_load_option(&lo, var_value, &size); + if (ret != EFI_SUCCESS) + goto out; + + tmp = efi_dp_from_lo(&lo, &size, guid); + if (!tmp) + goto out; + + /* efi_dp_dup will just return NULL if efi_dp_next is NULL */ + file_path = efi_dp_dup(efi_dp_next(tmp)); + +out: + efi_free_pool(tmp); + free(var_value); + + return file_path; +} diff --git a/lib/efi_loader/efi_var_common.c b/lib/efi_loader/efi_var_common.c index 1c7459266a38..b11ed91a74a4 100644 --- a/lib/efi_loader/efi_var_common.c +++ b/lib/efi_loader/efi_var_common.c @@ -9,6 +9,7 @@ #include #include #include +#include enum efi_secure_mode { EFI_MODE_SETUP, @@ -343,3 +344,35 @@ enum efi_auth_var_type efi_auth_var_get_type(u16 *name, const efi_guid_t *guid) } return EFI_AUTH_VAR_NONE; } + +/** + * efi_get_var() - read value of an EFI variable + * + * @name: variable name + * @start: vendor GUID + * @size: size of allocated buffer + * + * Return: buffer with variable data or NULL + */ +void *efi_get_var(u16 *name, const efi_guid_t *vendor, efi_uintn_t *size) +{ + efi_status_t ret; + void *buf = NULL; + + *size = 0; + ret = efi_get_variable_int(name, vendor, NULL, size, buf, NULL); + if (ret == EFI_BUFFER_TOO_SMALL) { + buf = malloc(*size); + if (!buf) + return NULL; + ret = efi_get_variable_int(name, vendor, NULL, size, buf, NULL); + } + + if (ret != EFI_SUCCESS) { + free(buf); + *size = 0; + return NULL; + } + + return buf; +} From patchwork Sun Mar 14 19:05:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 400114 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2862137jai; Sun, 14 Mar 2021 12:06:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyI28LGPfgt8nMHYgkdUr1ZKquQ7jS/cBqOy21fw1RfubZlvWuqV4pSPmtQnN419uM2X7NI X-Received: by 2002:a05:6402:b21:: with SMTP id bo1mr25779817edb.368.1615748804118; Sun, 14 Mar 2021 12:06:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615748804; cv=none; d=google.com; s=arc-20160816; b=ao0/4eXzFiGcHLpRNRP3nMO4xZguml3gfgbpwMPJXPJikBE7OO8ddNvkCVb7cey5cn 5HH/MNRBQvuaqdZemduXquFda4vOjSvaymovhafofXNrDDAYkCksAMMuYxgHSp1X+Cv1 gIa1PR0Aq0bmF9lNpEPvrPCdPR7HrmPLrwQQ/se5kwZUWJsdYGXdD+RDTiukVRb248IW +r+f+LZ+s2M8c/Nvif5J+ISw5OK/v7D6i2QPAgus1eGrZwfvZAtCSb8Hehtj012/H2+/ 4DXGY9PRugduDuNga9VyOYRcYiH/Gd1mvwTdgZS2r7SoNBpbCK8WHI/v0mBpSs0/eCrP NOww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=arrveHkitpLPgoMHt2k3a9qlI10zs4DmTVpcoTtkzp0=; b=0LFIk9RYoFF6x5SdLqCktDHnP5LqctFmnCWwru1dsmbsuRTKBOpIbtugivoICPpZjG A893oVNncGePQhgMlUqJae+Ko8XSflc4q+KzKcliKYb0C4T8iGjlQ2+n0I/JFCPcnorS Sk3XqkvtEkd9rqvWgBbu3Bv88ubBSdnE+j3SMUHff+/5Xj0cYUs0csrTCxHXxYob4Xos gOSr0wORT5wkR6g5b4gUwXo0ntCTwIr8FP+KCfunXbx8G8/8tNxOK7clxNCmGZKQIa7q u5JXZzth0TabCDEcIpHKOEJNXyT3dyB+4g2n9gcbTp5mwVxlF7nRoQYQ7SXCIMpOQsu5 1kZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PXnYCR3t; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id ss21si9128944ejb.338.2021.03.14.12.06.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 12:06:44 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PXnYCR3t; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1B37882985; Sun, 14 Mar 2021 20:06:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="PXnYCR3t"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B67718295C; Sun, 14 Mar 2021 20:06:08 +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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5A29F8297F for ; Sun, 14 Mar 2021 20:06:03 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wm1-x333.google.com with SMTP id b2-20020a7bc2420000b029010be1081172so18226825wmj.1 for ; Sun, 14 Mar 2021 12:06:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=arrveHkitpLPgoMHt2k3a9qlI10zs4DmTVpcoTtkzp0=; b=PXnYCR3txLit+BOCT107bsEuMJJ8H/gWLXrZRPzgPMuM2V7IfiBRwTvvVUSQRdNjhY RDHRQnZ0fQ/bBQeywvJikyPevt5u/b/rvWi8Hy9yaxfWU/RiEfWbO/IXFMgwdv5Vy6Jh BoPS54/eZdVDyreTKbA2FmR9pxs3X3KbNG+VGwXvvBsKhe3pxWUYfraxOViPamHMwNn1 bsK1HGCHa6GRQkiHHIvc3ukEdehVfbTdku+gjnJXdtZyssoU3EhLvZFcUHORXa9buIjo bo049xXMFLso0js0i7cHXOEpmc47OSwfbcJkdN6VeGkDEWwxPcYZGf0qv7ALu971ZHy7 6m+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=arrveHkitpLPgoMHt2k3a9qlI10zs4DmTVpcoTtkzp0=; b=sHPUoYNZxKNsZStv7djGrNrmjyvD0vuDLHNhTqBRIrCkknGCTskDjY6/G7eY35bzBV iJRBt6pc68ptfY3ccqOYWI7f1l1kQBNBpgzD/s7k60KSnYYR+hxhLVxj9TaKvpXHTciW v+8zHdnwN5snnpXljRn1OOOkXVhhR+zZHRzWUxHtJbOzTjdLVbkDKthmwB/KseZ6TMuM 3AWt1qOntg2BMoy7luzbQReCuUf/l1mqVfapoZ+VjELHpxHTA1cRISS2GUn221VE0PAQ dkKfPmN7QHpAzpxg4f4NNQKw/oa1TocgiE3MR9Hh+tMWDKFU3bfrbB2Wk9BVVvaFNuYA Q0EA== X-Gm-Message-State: AOAM531M1l/i5e9SB9BpbwirUX2VMjaQIV97NLHDJERRmE2I3WnrCsPC JOXiuY+rInnbK2j1mdmIFZWUoA== X-Received: by 2002:a1c:dc42:: with SMTP id t63mr22648950wmg.153.1615748762763; Sun, 14 Mar 2021 12:06:02 -0700 (PDT) Received: from localhost.localdomain (ppp-94-64-113-158.home.otenet.gr. [94.64.113.158]) by smtp.gmail.com with ESMTPSA id 3sm18718029wry.72.2021.03.14.12.06.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 12:06:02 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, Ilias Apalodimas , Alexander Graf , Sughosh Ganu , u-boot@lists.denx.de Subject: [PATCH 4/6 v3] efi_loader: Replace config option for initrd loading Date: Sun, 14 Mar 2021 21:05:36 +0200 Message-Id: <20210314190541.129687-5-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314190541.129687-1-ilias.apalodimas@linaro.org> References: <20210314190541.129687-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean Up to now we install EFI_LOAD_FILE2_PROTOCOL to load an initrd unconditionally. Although we correctly return various EFI exit codes depending on the file status (i.e EFI_NO_MEDIA, EFI_NOT_FOUND etc), the kernel loader, only falls back to the cmdline interpreted initrd if the protocol is not installed. This creates a problem for EFI installers, since they won't be able to load their own initrd and continue the installation. It also makes the feature hard to use, since we can either have a single initrd or we have to recompile u-boot if the filename changes. So let's introduce a different logic that will decouple the initrd path from the config option we currently have. When defining a UEFI BootXXXX we can use the filepathlist and store a file path pointing to our initrd. Specifically the EFI spec describes: "The first element of the array is a device path that describes the device and location of the Image for this load option. Other device paths may optionally exist in the FilePathList, but their usage is OSV specific" When the EFI application is launched through the bootmgr, we'll try to interpret the extra device path. If that points to a file that exists on our disk, we'll now install the load_file2 and the efi-stub will be able to use it. This opens up another path using U-Boot and defines a new boot flow. A user will be able to control the kernel/initrd pairs without explicit cmdline args or GRUB. Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- cmd/bootefi.c | 3 + include/efi_loader.h | 1 + lib/efi_loader/Kconfig | 17 +-- lib/efi_loader/efi_bootmgr.c | 19 ++- lib/efi_loader/efi_load_initrd.c | 202 ++++++++++++++++++------------- 5 files changed, 144 insertions(+), 98 deletions(-) -- 2.30.2 diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 271b385edea6..cba81ffe75e4 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -358,6 +358,9 @@ static efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options) free(load_options); + if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) + efi_initrd_deregister(); + return ret; } diff --git a/include/efi_loader.h b/include/efi_loader.h index 25302628d8a8..f17529695dd0 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -431,6 +431,7 @@ efi_status_t efi_net_register(void); /* Called by bootefi to make the watchdog available */ efi_status_t efi_watchdog_register(void); efi_status_t efi_initrd_register(void); +void efi_initrd_deregister(void); /* Called by bootefi to make SMBIOS tables available */ /** * efi_acpi_register() - write out ACPI tables diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index e729f727df11..380f86db60fc 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -315,18 +315,13 @@ config EFI_TCG2_PROTOCOL_EVENTLOG_SIZE config EFI_LOAD_FILE2_INITRD bool "EFI_FILE_LOAD2_PROTOCOL for Linux initial ramdisk" - default n - help - Expose a EFI_FILE_LOAD2_PROTOCOL that the Linux UEFI stub can - use to load the initial ramdisk. Once this is enabled using - initrd= will stop working. - -config EFI_INITRD_FILESPEC - string "initramfs path" - default "host 0:1 initrd" - depends on EFI_LOAD_FILE2_INITRD + default y help - Full path of the initramfs file, e.g. mmc 0:2 initramfs.cpio.gz. + Linux v5.7 and later can make use of this option. If the boot option + selected by the UEFI boot manager specifies an existing file to be used + as initial RAM disk, a Linux specific Load File2 protocol will be + installed and Linux 5.7+ will ignore any initrd= command line + argument. config EFI_SECURE_BOOT bool "Enable EFI secure boot support" diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 25f5cebfdb67..46c8011344b9 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -118,11 +118,13 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t *handle, ret = efi_set_variable_int(L"BootCurrent", &efi_global_variable_guid, attributes, sizeof(n), &n, false); - if (ret != EFI_SUCCESS) { - if (EFI_CALL(efi_unload_image(*handle)) - != EFI_SUCCESS) - log_err("Unloading image failed\n"); - goto error; + if (ret != EFI_SUCCESS) + goto unload; + /* try to register load file2 for initrd's */ + if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) { + ret = efi_initrd_register(); + if (ret != EFI_SUCCESS) + goto unload; } log_info("Booting: %ls\n", lo.label); @@ -146,6 +148,13 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t *handle, error: free(load_option); + return ret; + +unload: + if (EFI_CALL(efi_unload_image(*handle)) != EFI_SUCCESS) + log_err("Unloading image failed\n"); + free(load_option); + return ret; } diff --git a/lib/efi_loader/efi_load_initrd.c b/lib/efi_loader/efi_load_initrd.c index b9ee8839054f..e2a806302303 100644 --- a/lib/efi_loader/efi_load_initrd.c +++ b/lib/efi_loader/efi_load_initrd.c @@ -3,9 +3,11 @@ * Copyright (c) 2020, Linaro Limited */ +#define LOG_CATEGORY LOGC_EFI #include #include #include +#include #include #include #include @@ -23,57 +25,56 @@ static const struct efi_load_file_protocol efi_lf2_protocol = { * Device path defined by Linux to identify the handle providing the * EFI_LOAD_FILE2_PROTOCOL used for loading the initial ramdisk. */ -static const struct efi_initrd_dp dp = { +static const struct efi_initrd_dp dp_lf2_handle = { .vendor = { { DEVICE_PATH_TYPE_MEDIA_DEVICE, DEVICE_PATH_SUB_TYPE_VENDOR_PATH, - sizeof(dp.vendor), + sizeof(dp_lf2_handle.vendor), }, EFI_INITRD_MEDIA_GUID, }, .end = { DEVICE_PATH_TYPE_END, DEVICE_PATH_SUB_TYPE_END, - sizeof(dp.end), + sizeof(dp_lf2_handle.end), } }; +static efi_handle_t efi_initrd_handle; + /** - * get_file_size() - retrieve the size of initramfs, set efi status on error + * get_initrd_fp() - Get initrd device path from a FilePathList device path * - * @dev: device to read from, e.g. "mmc" - * @part: device partition, e.g. "0:1" - * @file: name of file - * @status: EFI exit code in case of failure + * @initrd_fp: the final initrd filepath * - * Return: size of file + * Return: status code. Caller must free initrd_fp */ -static loff_t get_file_size(const char *dev, const char *part, const char *file, - efi_status_t *status) +static efi_status_t get_initrd_fp(struct efi_device_path **initrd_fp) { - loff_t sz = 0; - int ret; - - ret = fs_set_blk_dev(dev, part, FS_TYPE_ANY); - if (ret) { - *status = EFI_NO_MEDIA; - goto out; - } + const efi_guid_t lf2_initrd_guid = EFI_INITRD_MEDIA_GUID; + struct efi_device_path *dp = NULL; - ret = fs_size(file, &sz); - if (ret) { - sz = 0; - *status = EFI_NOT_FOUND; - goto out; - } + /* + * if bootmgr is setup with and initrd, the device path will be + * in the FilePathList[] of our load options in Boot####. + * The first device path of the multi instance device path will + * start with a VenMedia and the initrds will follow. + * + * If the device path is not found return EFI_INVALID_PARAMETER. + * We can then use this specific return value and not install the + * protocol, while allowing the boot to continue + */ + dp = efi_get_dp_from_boot(lf2_initrd_guid); + if (!dp) + return EFI_INVALID_PARAMETER; -out: - return sz; + *initrd_fp = dp; + return EFI_SUCCESS; } /** - * efi_load_file2initrd() - load initial RAM disk + * efi_load_file2_initrd() - load initial RAM disk * * This function implements the LoadFile service of the EFI_LOAD_FILE2_PROTOCOL * in order to load an initial RAM disk requested by the Linux kernel stub. @@ -93,102 +94,125 @@ efi_load_file2_initrd(struct efi_load_file_protocol *this, struct efi_device_path *file_path, bool boot_policy, efi_uintn_t *buffer_size, void *buffer) { - char *filespec; - efi_status_t status = EFI_NOT_FOUND; - loff_t file_sz = 0, read_sz = 0; - char *dev, *part, *file; - char *pos; - int ret; + struct efi_device_path *initrd_fp = NULL; + efi_status_t ret = EFI_NOT_FOUND; + struct efi_file_handle *f = NULL; + efi_uintn_t bs; EFI_ENTRY("%p, %p, %d, %p, %p", this, file_path, boot_policy, buffer_size, buffer); - filespec = strdup(CONFIG_EFI_INITRD_FILESPEC); - if (!filespec) - goto out; - pos = filespec; - if (!this || this != &efi_lf2_protocol || !buffer_size) { - status = EFI_INVALID_PARAMETER; + ret = EFI_INVALID_PARAMETER; goto out; } - if (file_path->type != dp.end.type || - file_path->sub_type != dp.end.sub_type) { - status = EFI_INVALID_PARAMETER; + if (file_path->type != dp_lf2_handle.end.type || + file_path->sub_type != dp_lf2_handle.end.sub_type) { + ret = EFI_INVALID_PARAMETER; goto out; } if (boot_policy) { - status = EFI_UNSUPPORTED; + ret = EFI_UNSUPPORTED; goto out; } - /* - * expect a string with three space separated parts: - * - * * a block device type, e.g. "mmc" - * * a device and partition identifier, e.g. "0:1" - * * a file path on the block device, e.g. "/boot/initrd.cpio.gz" - */ - dev = strsep(&pos, " "); - if (!dev) + ret = get_initrd_fp(&initrd_fp); + if (ret != EFI_SUCCESS) goto out; - part = strsep(&pos, " "); - if (!part) - goto out; - file = strsep(&pos, " "); - if (!file) + + /* Open file */ + f = efi_file_from_path(initrd_fp); + if (!f) { + log_err("Can't find initrd specified in Boot####\n"); + ret = EFI_NOT_FOUND; goto out; + } - file_sz = get_file_size(dev, part, file, &status); - if (!file_sz) + /* Get file size */ + ret = efi_file_size(f, &bs); + if (ret != EFI_SUCCESS) goto out; - if (!buffer || *buffer_size < file_sz) { - status = EFI_BUFFER_TOO_SMALL; - *buffer_size = file_sz; + if (!buffer || *buffer_size < bs) { + ret = EFI_BUFFER_TOO_SMALL; + *buffer_size = bs; } else { - ret = fs_set_blk_dev(dev, part, FS_TYPE_ANY); - if (ret) { - status = EFI_NO_MEDIA; - goto out; - } - - ret = fs_read(file, map_to_sysmem(buffer), 0, *buffer_size, - &read_sz); - if (ret || read_sz != file_sz) - goto out; - *buffer_size = read_sz; - - status = EFI_SUCCESS; + ret = EFI_CALL(f->read(f, &bs, (void *)(uintptr_t)buffer)); + *buffer_size = bs; + } + +out: + efi_free_pool(initrd_fp); + if (f) + EFI_CALL(f->close(f)); + return EFI_EXIT(ret); +} + +/** + * check_initrd() - Determine if the file defined as an initrd in Boot#### + * load_options device path is present + * + * Return: status code + */ +static efi_status_t check_initrd(void) +{ + struct efi_device_path *initrd_fp = NULL; + struct efi_file_handle *f; + efi_status_t ret; + + ret = get_initrd_fp(&initrd_fp); + if (ret != EFI_SUCCESS) + goto out; + + /* + * If the file is not found, but the file path is set, return an error + * and trigger the bootmgr fallback + */ + f = efi_file_from_path(initrd_fp); + if (!f) { + log_err("Can't find initrd specified in Boot####\n"); + ret = EFI_NOT_FOUND; + goto out; } + EFI_CALL(f->close(f)); + out: - free(filespec); - return EFI_EXIT(status); + efi_free_pool(initrd_fp); + return ret; } /** * efi_initrd_register() - create handle for loading initial RAM disk * * This function creates a new handle and installs a Linux specific vendor - * device path and an EFI_LOAD_FILE_2_PROTOCOL. Linux uses the device path + * device path and an EFI_LOAD_FILE2_PROTOCOL. Linux uses the device path * to identify the handle and then calls the LoadFile service of the - * EFI_LOAD_FILE_2_PROTOCOL to read the initial RAM disk. + * EFI_LOAD_FILE2_PROTOCOL to read the initial RAM disk. * * Return: status code */ efi_status_t efi_initrd_register(void) { - efi_handle_t efi_initrd_handle = NULL; efi_status_t ret; + /* + * Allow the user to continue if Boot#### file path is not set for + * an initrd + */ + ret = check_initrd(); + if (ret == EFI_INVALID_PARAMETER) + return EFI_SUCCESS; + if (ret != EFI_SUCCESS) + return ret; + ret = EFI_CALL(efi_install_multiple_protocol_interfaces (&efi_initrd_handle, /* initramfs */ - &efi_guid_device_path, &dp, + &efi_guid_device_path, &dp_lf2_handle, /* LOAD_FILE2 */ &efi_guid_load_file2_protocol, (void *)&efi_lf2_protocol, @@ -196,3 +220,17 @@ efi_status_t efi_initrd_register(void) return ret; } + +/** + * efi_initrd_deregister() - delete the handle for loading initial RAM disk + * + * This will delete the handle containing the Linux specific vendor device + * path and EFI_LOAD_FILE2_PROTOCOL for loading an initrd + * + * Return: status code + */ +void efi_initrd_deregister(void) +{ + efi_delete_handle(efi_initrd_handle); + efi_initrd_handle = NULL; +} From patchwork Sun Mar 14 19:05:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 400115 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2862243jai; Sun, 14 Mar 2021 12:06:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXWx7zf11Flo8mYBs5GpX3vmBN4B7fUDaDrF7Oho1uuqSBqoAQH+S8KDYEyZYhxrMx5ZrU X-Received: by 2002:a17:906:688:: with SMTP id u8mr19468109ejb.38.1615748817536; Sun, 14 Mar 2021 12:06:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615748817; cv=none; d=google.com; s=arc-20160816; b=YYDmjSVMXbSr+zUrDdYf0cb2GgiACJH0kHpe4aaQg0ybp5Htj5I55KIfmlCh1TME0r scNj3wOciIlxsEZ4xy85Alq1tMHL92EnkO2e30G1wRQByYaGuaWHFsQOv+Da4SNkx8ph QFX5gkb8MwP0ASbTU3kXwEGs9AKKNYr40iECOlfBrAE2WLBHB+ZL+pGh7ZNEZ5pG/eMj RtGwtAhpimOMY4hIRJM/YhDpVFdQTpHcrOVrpB2qxYChkUfd50x4UL8lkiHfK0zZ+l3u SJjSlIzT0wCvlfM69uxEQwg2RipeL0eMpTY3zoDoS5Us4gTujJ8s55/8kZ63kFW4+fGU kYxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KGb1QECw2jtxlZ9meZqzSIPhk6+EElUS/FbJBAhktNQ=; b=CoZH6BYrOvH7SkR6evFwdF44YexXq35+10QWrXdmKKNoc10B76c34UxlQHSs587WsD LO8vL1JRznW1oY3QXoRvaGEhL2CAsQXrLcwa+ZSmkf4ASA9jzK+9zgkpVis4WSyen07g jDyZh3tTa/wsvI70v/tOhHf1GoRR3mvZpBvC14ibn3Tm6f/5JUj75/UZeFk/nFuHPpIA 4wd0JLAceYB3tVxCeuSXTnNqH7gwePibQG8Uhp4NsFLoMmqwlC5ejW3JOCgoVILmxCDf Kh/3/JMrrj+BvqDU7GJn3O/LnnY9eqJqrFjZIw7zLuv/oze47Fn9CxvmByGDXh2gi/OK g4jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pZ3LiJ20; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id h15si9037704edw.371.2021.03.14.12.06.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 12:06:57 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pZ3LiJ20; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 13B878295C; Sun, 14 Mar 2021 20:06:15 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="pZ3LiJ20"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8B6B5829A0; Sun, 14 Mar 2021 20:06:13 +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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id DD9AC8293C for ; Sun, 14 Mar 2021 20:06:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wr1-x436.google.com with SMTP id t9so4607672wrn.11 for ; Sun, 14 Mar 2021 12:06:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KGb1QECw2jtxlZ9meZqzSIPhk6+EElUS/FbJBAhktNQ=; b=pZ3LiJ20QmrF9LDhSYhVcZAjFJWwZGnv0OfBXGVP9Mo2nfB16QJGD223hA0mjfRJV9 iG/Amxbk/NOYGfLh/SVigfE9tLR4XI4xPs7MzAB1AQgB/wkng+WbKu7DrSmLaKcQ0tds SnLLcJKDDECutssnMun6pGlcAaDucwP59TBGMf/D7QxTYRakBGZlpZX4TK+Uf2YVxrDz qiA1uoniENbVouJPxryf1H9KHxk5AhedeobHRSONj3znt36+zw9Gb/dAo0E32jKt13px u6jG89Kh7tV5CPkFp6tqdLXvS54wmfeG1HDEAoDWf3d0GLgX7D7Ids8+Mr1vZyfOXHxJ rsEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KGb1QECw2jtxlZ9meZqzSIPhk6+EElUS/FbJBAhktNQ=; b=YkwA1UFb7N0cuwiUPX9x0LdgOpVv3A8p9tUu/G1eKCAKf5JolFSaQgiLvDOhiEXkLq 292LVXqpK2vx/CE+OcC2GgxBv6ny0iAn5QSJL/+hz3Vh4B+nLeuRymVyOJF/Xs6Oi4CA 9NgMia5Yo4mOnUNt/Oq+gtaFa1UQ7R2CBZSb/FvIyUEsM3KKdKZ3grVJZht5lLA8PiGf S2ADCUPqASP5upWm61odUModKfjrq1ssr/03Y7JHg1HbRXIelwTytOvWTUq19DfIoZ1N jvnlp2BKk+x+rEz+DbCoCjgoRMr9qzQUAPtaz8NQK+2mdktM/5HYzc9zH/uSCDHmDbuS Pozg== X-Gm-Message-State: AOAM533N+Sg+gqNTv21IxXBs+M3FJmzzlAVdnxnFBE+L+I3VUTVYy4Fw HTpLqLOHvBMyCA2wKAIfzagKRQ== X-Received: by 2002:a5d:5744:: with SMTP id q4mr24779465wrw.390.1615748767356; Sun, 14 Mar 2021 12:06:07 -0700 (PDT) Received: from localhost.localdomain (ppp-94-64-113-158.home.otenet.gr. [94.64.113.158]) by smtp.gmail.com with ESMTPSA id 3sm18718029wry.72.2021.03.14.12.06.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 12:06:07 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, Ilias Apalodimas , Alexander Graf , Sughosh Ganu , u-boot@lists.denx.de Subject: [PATCH 5/6 v3] efidebug: add multiple device path instances on Boot#### Date: Sun, 14 Mar 2021 21:05:37 +0200 Message-Id: <20210314190541.129687-6-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314190541.129687-1-ilias.apalodimas@linaro.org> References: <20210314190541.129687-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean The UEFI spec allows a packed array of UEFI device paths in the FilePathList[] of an EFI_LOAD_OPTION. The first file path must describe the loaded image but the rest are OS specific. Previous patches parse the device path and try to use the second member of the array as an initrd. So let's modify efidebug slightly and install the second file described in the command line as the initrd device path. Signed-off-by: Ilias Apalodimas --- cmd/efidebug.c | 193 ++++++++++++++---- doc/board/emulation/qemu_capsule_update.rst | 4 +- doc/uefi/uefi.rst | 2 +- .../test_efi_capsule/test_capsule_firmware.py | 6 +- test/py/tests/test_efi_secboot/test_signed.py | 16 +- .../test_efi_secboot/test_signed_intca.py | 8 +- .../tests/test_efi_secboot/test_unsigned.py | 8 +- 7 files changed, 178 insertions(+), 59 deletions(-) -- 2.30.2 diff --git a/cmd/efidebug.c b/cmd/efidebug.c index bbbcb0a54643..a96146748c61 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -19,6 +20,7 @@ #include #include #include +#include #define BS systab.boottime #define RT systab.runtime @@ -794,6 +796,64 @@ static int do_efi_show_tables(struct cmd_tbl *cmdtp, int flag, return CMD_RET_SUCCESS; } +/** + * add_initrd_instance() - Append a device path to load_options pointing to an + * inirtd + * + * @dev: Device + * @part: Partition of thge disk + * @file: Filename + * @fp: Device Path containing the existing load_options + * @fp_size: New size of the device path after the addition + * Return: Pointer to the device path or ERR_PTR + * + */ +static +struct efi_device_path *add_initrd_instance(const char *dev, const char *part, + const char *file, + const struct efi_device_path *fp, + efi_uintn_t *fp_size) +{ + struct efi_device_path *tmp_dp = NULL, *tmp_fp = NULL; + struct efi_device_path *final_fp = NULL, *initrd_dp = NULL; + efi_status_t ret; + const struct efi_initrd_dp id_dp = { + .vendor = { + { + DEVICE_PATH_TYPE_MEDIA_DEVICE, + DEVICE_PATH_SUB_TYPE_VENDOR_PATH, + sizeof(id_dp.vendor), + }, + EFI_INITRD_MEDIA_GUID, + }, + .end = { + DEVICE_PATH_TYPE_END, + DEVICE_PATH_SUB_TYPE_END, + sizeof(id_dp.end), + } + }; + + ret = efi_dp_from_name(dev, part, file, &tmp_dp, &tmp_fp); + if (ret != EFI_SUCCESS) { + printf("Cannot create device path for \"%s %s\"\n", part, file); + goto out; + } + + initrd_dp = efi_dp_append((const struct efi_device_path *)&id_dp, + tmp_fp); + if (!initrd_dp) + goto out; + final_fp = efi_dp_concat(fp, initrd_dp); + *fp_size = efi_dp_size(fp) + efi_dp_size(initrd_dp) + + (2 * sizeof(struct efi_device_path)); + +out: + efi_free_pool(initrd_dp); + efi_free_pool(tmp_dp); + efi_free_pool(tmp_fp); + return final_fp; +} + /** * do_efi_boot_add() - set UEFI load option * @@ -806,7 +866,9 @@ static int do_efi_show_tables(struct cmd_tbl *cmdtp, int flag, * * Implement efidebug "boot add" sub-command. Create or change UEFI load option. * - * efidebug boot add