From patchwork Fri Mar 5 22:22:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 393591 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp811460jai; Fri, 5 Mar 2021 14:23:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJycvPm+t1qQ+y892CsT0B0BKyygpJTT3b6EprcdfBfBKtlpnDJ7i7c2hiw1WqcTVU8axxsb X-Received: by 2002:a17:906:3fc3:: with SMTP id k3mr4466001ejj.522.1614982994141; Fri, 05 Mar 2021 14:23:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614982994; cv=none; d=google.com; s=arc-20160816; b=ziSV1An6uSBbSyVGzsA+k7/3IiVC4jnHqLR8hx4q2crEDqjPFCbEE4zEcVJVHICw4K K83AHmI+gd5LX2EKb0opMlE8njClNRtNgQamhETW1kKhnX4pyijRWnrQHCX+759FwvaI U0LJYiYISt836/snOy5BZrMSslJb5ljE9BJbyjcw+uh4AyZMgDfYIlNafJmQawxRGIyd nd3Nm0U9u1bIEYmOOTx1yoYzhF1D6jQaJda+dgPpIpDlY8pPezsvnJ3xpkmp8itmuEeq MSqRBZUWBD4aPtBA3M9fscBI+Iu7bHvucZEzbF7+mg0s0MFfr0fujFeeNQt2b/xeEPt1 J/Lw== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=5OcCECrZzXBnzRqZO0dSAALpGrhofAEWzSenIxSDAGQ=; b=fpMf64i75guFiPm2TguPEofhIt83keeMsrivlrGmdmYa43erkhCzL8FhV86tkfwa2S eKTIKROgGIP8aO1z8PCtTAXcNsvk3b6vABBvFxegggnI0qfQrSFwaZeECPjgOqOYLo9x VFbJoQ7q5CvIY0YkLYYBLq4PX2Kxs8cKWXPmEiEyW5hZsNWwVq6BnU9TI7Ayj7MWbPCx NGCsb4YXvRilxpLV0Wg4DUAmNQQf61vH052LyF2g98oHzceF4xBkFCdgHhHl9EAF4RJ5 tPdqqbQt5dXb08LgSYAbEfkaQD9EavM3KN6LcWJwYkXQpc4OAwQf2JzJ1IrwfymgFwWO D9kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AnxHhUWs; 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 g23si1990489ejx.623.2021.03.05.14.23.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 14:23:14 -0800 (PST) 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=AnxHhUWs; 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 838578204B; Fri, 5 Mar 2021 23:23: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="AnxHhUWs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 516AA80F58; Fri, 5 Mar 2021 23:23:10 +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-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) (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 10BEE80F58 for ; Fri, 5 Mar 2021 23:23: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-x431.google.com with SMTP id b18so3733227wrn.6 for ; Fri, 05 Mar 2021 14:23:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5OcCECrZzXBnzRqZO0dSAALpGrhofAEWzSenIxSDAGQ=; b=AnxHhUWsZHPtIlgaxb6u4sQFDqNwg7PmUVf8rOOGVBBgKjSoRPnuHuZ6RSsWwnYqJq /A49n1jgbiTBiZishlSEcddDtDVgA8DDto1pq8iKrPGkeEmP1JLazb1UMBuwhBwuXfcg zwYzuPyJ7MH6gD8mJmIJx2pE14PL1KKGX99/dJknE9Q37BmRtouTOCE6QSPlgg1KmBo9 T5NTWfM2m8VXSrSrAfz9oNQetrQAEWzs5fqBK4xm8IO/USAoBndb2Ef/Ws5U4yzBwAev 7c1csIoWMiJ7paNMwRoHDBIreeghKPhj6VEtdzoi+YFXdPFSbUQ+wVEsy99deRQJgEpk Jy4A== 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:mime-version :content-transfer-encoding; bh=5OcCECrZzXBnzRqZO0dSAALpGrhofAEWzSenIxSDAGQ=; b=ojPmvU9SVxmvOj4X1TTt7pCjCVZEIYTYaBDcrilXfG06+yi9zB1xZcdYUa0Rxwg3RC IsoeWGm0yox50zFQ1dbomqU0mG0SmgbU6ndXvT5cShZhrxcTl/tsUhnGVm0jcplWqhyG Va7MYpiVpEAZwh+McYJm2p/akl7FkSh15rgImpSybbDclgY+s8sMwy8D/FY1J5rg/llW 23B3qm6MmNABGBzIeGzqam9BrrqDSltQKYvmrp/R6CwrlbAf4h7R49e+W9+psyso9mIi LGjZn+Dfo6i/5ngs7lV/zJCpWJKE9TITVftMdK8U1k0HrNdWJ0uHegZLjj+q7DhlVihm 8ZTg== X-Gm-Message-State: AOAM531vgS3Ppfh5dkQw8z4TMpiFe9QoZiloawGt8M4jXeRCGdcprRTk zXpe9wzMuJJAu8d+AZZ1W6sbUg== X-Received: by 2002:a05:6000:1819:: with SMTP id m25mr11303841wrh.169.1614982986486; Fri, 05 Mar 2021 14:23:06 -0800 (PST) Received: from apalos.home ([2a02:587:4647:e6c6:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id s11sm6493296wme.22.2021.03.05.14.23.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 14:23:06 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, takahiro.akashi@linaro.org Cc: Ilias Apalodimas , Alexander Graf , Sughosh Ganu , u-boot@lists.denx.de Subject: [PATCH 1/6] efi_selftest: Remove loadfile2 for initrd selftests Date: Sat, 6 Mar 2021 00:22:57 +0200 Message-Id: <20210305222303.2866284-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.1 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 --- 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.1 Reviewed-by: Heinrich Schuchardt 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 Fri Mar 5 22:22:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 393593 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp811622jai; Fri, 5 Mar 2021 14:23:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJwWfl0VZA4C0SB3+cYBmMnd2x4iT2PMfB2r3Sxh++KZVU8cWAe7kWTdIa0ypP/56RN5YPj8 X-Received: by 2002:a17:906:9888:: with SMTP id zc8mr4570274ejb.310.1614983013447; Fri, 05 Mar 2021 14:23:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614983013; cv=none; d=google.com; s=arc-20160816; b=rLuuF9opWapBYT1c4g3MOKRQ6ZN1rZKZNt7xr411yX+0wZ9vg3cX6ZEu9NvxPU54hU 88W4qDXnGoAihyYBIe57ANJ0z8NJkp/BiyRcVlz2B7XNKYoWTq2HTiycVHJTNkI1tzTG /Vi5zyVP18kKk9hLocAzW2pQWKCiG2MkCa+zXHFpYbIUgV+QZNLxXWZZ3gmyBT7Qr+hh i86O3xT7xDF5/ej8QmWvFMBDCWySv9bxwxwLf7JYJ5Kr6wk++JwmdIzr76YNuNAMS/ql XMKNPj4V+/UHwwRP9jqusdOvSf6XFWyRacfGP9ph4CyUpMqcWAqwmMFxhbVhurtKo65+ uePA== 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=dlRU6TIZxKlFX0m10EUF4T3JCjghXQQ1dR3PMOpdLhY=; b=aw3WYJctAQl8/qnkvAzTHoXstNDSrvsf7jvxKtqpf5Q7taqeOsW8sUauAEAsnvcTDN B52H8KGY+H5brhb2Vr/w2EM3v4qqbuMviAZ4wDsf3M0/M+xyoV0xUw23oox10SnH4YhB 2+yyP07ZX5pCX8lk/eqFKpklO45hQwyop7B1bWSLBs3krD7vZfKsON1s/aj39avYJFZE u9LexLAihwjKFrkyPARaqf8UCnPQlsM4QWqXmHjefec+WcwREiAxfMXM51VO30zv4ntr 48RZr+QKvWTbDtoTAE5fjMS1Uc+AMWSyg+QPky1edvxSxXBlvkVZpltFe/0kcnmykkj5 IxPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rpXsR7Fn; 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 bt16si2156365edb.440.2021.03.05.14.23.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 14:23:33 -0800 (PST) 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=rpXsR7Fn; 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 CEBA4826F3; Fri, 5 Mar 2021 23:23:19 +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="rpXsR7Fn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 09F9182748; Fri, 5 Mar 2021 23:23:18 +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-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) (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 3058782016 for ; Fri, 5 Mar 2021 23:23:09 +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-x332.google.com with SMTP id j4-20020a05600c4104b029010c62bc1e20so160476wmi.3 for ; Fri, 05 Mar 2021 14:23:09 -0800 (PST) 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=dlRU6TIZxKlFX0m10EUF4T3JCjghXQQ1dR3PMOpdLhY=; b=rpXsR7FnFjoR5F7Yv+L5creiLSZrJC/YPFcD8e4+UkOM1W8Id3E9EO76/BNv07juy8 2DfTDBHw0G5yS93iUmdufLetHPm3I6igi/q6X/O/pfRs6BIiYSSC1wNnC2WlGGNkPDnP BlMs0CpTTbLKojabtJ/mDUGgz62sA5NHZoI+AKlkyBC27EaqfD32pFMlF+M6peCf73cA I6+suXzoe+1h6TYNOJ0Lg+n7rcuQ+bp0nF6Xxptfk1vhd7sSTrNabcoEMh8/OjZSQWM+ b/OofaaUdUK2YreY1NJPr6MJz2d6YweavTTPqOSB6T+Fv+C7DGf9afO8aKY83M+w/CpX S1kg== 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=dlRU6TIZxKlFX0m10EUF4T3JCjghXQQ1dR3PMOpdLhY=; b=JiywIGGf05U8TSHJGoJpWNdtLELv1rkN2TamTK/xBHESxDOj+ULzvKJU8q58oBMBuH tHZkcS///tlM8OTKjZWx3MEkw4AxuxUkvl/q2xrOJODYGaePb1yOEmO8o1iQ5HPXeVsS mNPrAjrzvbXC7hfpmSWLHTSFa56vZ58xXsRjSiZpizURBW4fSi8wXLhmPbaLyKfK8n00 BF4ltLxyMAkfrRMTsF0+RZ74iVUIViDdX18lpB+faBDQwq+zPmdLwqKHYr5iwsP+WOpF bHXiO6E1I+Lc09OY/pRf5al0ZnaCkvXPbNvVd2TqqJfbSEr6uJS+gKc3AgHfksM3u3Fm 06yg== X-Gm-Message-State: AOAM530W/qNXrYm5tTVwJ0XQggh3Cx72zv0By3EUBBxgVhOy6I9O7aJY EJqJSBcimYVTtSOexWL2v03BHA== X-Received: by 2002:a7b:c050:: with SMTP id u16mr10844773wmc.90.1614982988749; Fri, 05 Mar 2021 14:23:08 -0800 (PST) Received: from apalos.home ([2a02:587:4647:e6c6:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id s11sm6493296wme.22.2021.03.05.14.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 14:23:08 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, takahiro.akashi@linaro.org Cc: Ilias Apalodimas , Alexander Graf , Sughosh Ganu , u-boot@lists.denx.de Subject: [PATCH 2/6] efi_loader: Add device path related functions for initrd via Boot#### Date: Sat, 6 Mar 2021 00:22:58 +0200 Message-Id: <20210305222303.2866284-2-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210305222303.2866284-1-ilias.apalodimas@linaro.org> References: <20210305222303.2866284-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) - 0x01 - 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 | 72 ++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) -- 2.30.1 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..cf1321828e87 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -310,6 +310,41 @@ struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1, return ret; } +/** 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 + * @size: 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) +{ + struct efi_device_path *ret; + efi_uintn_t sz1, sz2; + void *p; + + if (!dp1 || !dp2) + return NULL; + sz1 = efi_dp_size(dp1); + sz2 = efi_dp_size(dp2); + p = dp_alloc(sz1 + sz2 + (2 * sizeof(END))); + /* both dp1 and dp2 are non-null */ + if (!p) + return NULL; + ret = p; + memcpy(p, dp1, sz1); + p += sz1; + memcpy(p, &END, sizeof(END)); + p += sizeof(END); + memcpy(p, dp2, sz2); + p += sz2; + memcpy(p, &END, sizeof(END)); + + return ret; +} + struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp, const struct efi_device_path *node) { @@ -1160,3 +1195,40 @@ 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 Vendor Device Path + * in a multi-instance device path that matches + * a specific GUID + * + * @load_option: device paths to search + * @size: size of the discovered device path + * @guid: guid to search for + * + * Return: device path 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; + + while (lo_len) { + if (fp->type != DEVICE_PATH_TYPE_MEDIA_DEVICE || + fp->sub_type != DEVICE_PATH_SUB_TYPE_VENDOR_PATH) { + lo_len -= fp->length; + fp = (void *)fp + fp->length; + continue; + } + + vendor = (struct efi_device_path_vendor *)fp; + if (!guidcmp(&vendor->guid, &guid)) + return efi_dp_dup(fp); + lo_len -= fp->length; + fp = (void *)fp + fp->length; + } + + return NULL; +} From patchwork Fri Mar 5 22:22:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 393592 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp811542jai; Fri, 5 Mar 2021 14:23:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJzRxTQFEb7oEeWlf1a662Z7g9v5y/7Pn4sb9jmqpGA7ME2/YakKobInUnvvFnYJuIUkfpSC X-Received: by 2002:a17:906:85b:: with SMTP id f27mr4559980ejd.414.1614983003214; Fri, 05 Mar 2021 14:23:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614983003; cv=none; d=google.com; s=arc-20160816; b=rKUUkwznbGcVpIui3vbIiOd6n00ssJNRXnPazQVWCeSmN0s+FYVAQtO83TKBfRVyzr rRU+6PN23SFlMLioRjz7Ym2xznOrIaopO68aDqt9EZSavP8CsA6NAFhm5m6e3DvM/LCf Xet2XcbMlWAqNrvZ7yEAbCdPKJAKeT3vCVDI8gwRM7xOEGRxY+hxWoDBoMjidTSD46QE FDYr2WQQ4PFtmtF/gQK0MDs1MaGRNyCdFvPZFsTQZ5VZs5n6jEHkzCPHgluQ73rtFFG9 V7uJBYTYdIR2bs78B6cPfNBsem0DVJ5rUduYfMc6RYFWFlGMto2tqPGngp/GOfbRtvQ4 RgqQ== 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=RFQf9WM86z8M4nZY3lXy/h4OYj0BhG3f7ftR+C6YDzI=; b=eZkqlIZmTjNEvUdUs5jrUZJP6paHeWx+pQUkJJDswoZRKUxwDd4aZSUNHr9vbz958k FRwNujlqgKgdgfNR0L3w5krKxa/l51j944Oms5T6zu+84bMQCioLWDMmdyB23MYc8oaX kBSI5Nle+35u7bdQ2cp7G79Wd+KWF8u3PMz8pJD/BDT4NOkloMOtC+gwfEHJ6UZ6VP0k Y72a2YCvgPNdYYkztfFwWgVDWkmcAuep5yRflMePzbAdrVA8Xk6cDUQ+9kULe2JYs+38 AWox7aAJmzdRf2fsu8au5I4JfOZ/0RIFYEKHdZKnkxfcVaKqGr9s/52nWLXIuPek3WW3 E2Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Vy+f6/iO"; 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 k25si2284834ejq.186.2021.03.05.14.23.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 14:23:23 -0800 (PST) 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="Vy+f6/iO"; 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 68A88826A5; Fri, 5 Mar 2021 23:23:16 +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="Vy+f6/iO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A8D26826AC; Fri, 5 Mar 2021 23:23:14 +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-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (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 8E5F082462 for ; Fri, 5 Mar 2021 23:23: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=ilias.apalodimas@linaro.org Received: by mail-wr1-x42e.google.com with SMTP id v15so3735754wrx.4 for ; Fri, 05 Mar 2021 14:23:11 -0800 (PST) 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=RFQf9WM86z8M4nZY3lXy/h4OYj0BhG3f7ftR+C6YDzI=; b=Vy+f6/iOZ8VjkEoMcOhoMZ5zivPT+rYG4WCN65OvhgdvQaaQ5+nNrkp2BUa+XmWRi3 vgYddTZ27PZL471eXiFzkK/hjWm89+MV4XXS8vvcXY//iz/CwU5YwIfZsloqng/H4Ia7 vjuzAOBMXNbjZm5VSxjPmSVNPRyg/yE92G8zWM0HQbOHvXHRz/Bro42flfh1CBOYjfJc +tdmtf2dTEoQSMlIUBGIomaqggxP8ZyLKG/ynOkhiKDCf0YDYbxwaV241W9xbupr/lle CEhjlzqJipG3QpWPHp5qo93OfEIGbUV5VD8YKlXMu4gFRK78zKjoAb/nLiTpKK+X1/iA ZUjA== 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=RFQf9WM86z8M4nZY3lXy/h4OYj0BhG3f7ftR+C6YDzI=; b=F1kzS5Uopr3nW0lEFHnOIrxdPQ4WY4QEvd/DdJugXVd0Kh5JLdIUlt3tP+lFUeNOfy 8+ooFqNuXyathiV8EBehk7GV/W16dW5jzp1GcB+LP86vlVdrugR/l9OITevDTF3P3ZcY RBc0Hdv0o3ik7d5vPeqL7Or0jqdHA8IG9cjye6DR4MaDbRwytW+UN5pacMCxivQbc73A lcaDJ1nZDawBr4PMKyOkx237xjfBp277I7byjW5pMEsWE+nQvnatDqaNznk1C/101oFZ hfC91f7pWDHs1ej3BUQMpKsI7wj3RL33rxnCVwB7ryu7sbkWlTnwhO59vY+Bff7Cf2+J W3/g== X-Gm-Message-State: AOAM531SQ5iq4lWRWl6+i7Co/iwmj4bArdoVECDH4aRIbqSH2QpxO5c5 Cd/gTr4CyyOQJvy+Mec1cU/QYeqbcgSLLS4k X-Received: by 2002:a5d:67c8:: with SMTP id n8mr11356629wrw.351.1614982991089; Fri, 05 Mar 2021 14:23:11 -0800 (PST) Received: from apalos.home ([2a02:587:4647:e6c6:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id s11sm6493296wme.22.2021.03.05.14.23.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 14:23:10 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, takahiro.akashi@linaro.org Cc: Ilias Apalodimas , Alexander Graf , Sughosh Ganu , u-boot@lists.denx.de Subject: [PATCH 3/6] efi_loader: Introduce helper functions for EFI Date: Sat, 6 Mar 2021 00:22:59 +0200 Message-Id: <20210305222303.2866284-3-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210305222303.2866284-1-ilias.apalodimas@linaro.org> References: <20210305222303.2866284-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_helper.h | 15 +++++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_helper.c | 118 ++++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 include/efi_helper.h create mode 100644 lib/efi_loader/efi_helper.c -- 2.30.1 diff --git a/include/efi_helper.h b/include/efi_helper.h new file mode 100644 index 000000000000..4980a1bb35d7 --- /dev/null +++ b/include/efi_helper.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2020, Linaro Limited + */ + +#if !defined _EFI_HELPER_H_ +#define _EFI_HELPER_H + +#include +#include + +void *efi_get_var(u16 *name, const efi_guid_t *vendor, efi_uintn_t *size); +struct efi_device_path *efi_get_dp_from_boot(const efi_guid_t guid); + +#endif 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_helper.c b/lib/efi_loader/efi_helper.c new file mode 100644 index 000000000000..5437faa3ec49 --- /dev/null +++ b/lib/efi_loader/efi_helper.c @@ -0,0 +1,118 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2020, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * 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; +} + +/** + * create_boot_var_indexed() - 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 create_boot_var_indexed(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 + * + * @guid: Vendor guid of the VenMedia DP + * + * 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; + struct efi_load_option lo; + void *var_value = NULL; + efi_uintn_t size; + efi_status_t ret; + u16 var_name[16]; + + ret = create_boot_var_indexed(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) + return NULL; + + file_path = efi_dp_from_lo(&lo, &size, guid); + if (!file_path) { + log_debug("Missing file path in %ls", var_name); + return NULL; + } + + return file_path; +} From patchwork Fri Mar 5 22:23:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 393594 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp811706jai; Fri, 5 Mar 2021 14:23:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJxKcI74EmkA+z9OALgSUCQK9/X8hfTdqNj4vop6hVOHhThBCmRWosmnjSrw/P0u0W3eQdhJ X-Received: by 2002:a05:6402:d1:: with SMTP id i17mr11302854edu.85.1614983023363; Fri, 05 Mar 2021 14:23:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614983023; cv=none; d=google.com; s=arc-20160816; b=xHJMG3jkUEOw+iJETdi1zhjXgDoOVH6cIW+eUKDL/hZ36GMhe30G2fK/eqGDWy8d16 vwlgTJGX+M4EYh+LNom7+3K4fZVetXzPkJYRS651K6qXWTzqb5LSzeyN0W3iTkuDu0LB id2K7nsmaf9IoJqaXbYgZK1AxeVKgHJ2+xiv/aWhCVrE0fPIkwzhbzw2A42sAGZMQqJ0 qJJ8QkNsK3b2nR5eBNMcAfQFee6WQlhYigM56LV0f/ulvQipn/k6XGxeS8abPSnRbA+i B5Swm/S9GG447fQTn0yUWjni+LFtzBjf3X/4MPED598jCgP21nbW47EO82vz5J00yCdt nQlA== 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=ms7jMbeTl2lowQXYymgtE0yuZstw/D+B4x1Hc10hXRw=; b=eouamWVNXeCE57sVmtqrPFwC5GAA+Q92Op3sHfvA8qyS5YzFWYt5W3lWINnDR52CFd QN97RkS8NuibJ3Oz/QOaS1GtGZ09ecS4PNw+NeP/doEGRB3UqmzNQB9OgiH6SdtaTQQQ 8elXonFONUIi4sASsandxawz3RHpgp3DXIVTMDbwQiNEaNFENywcuakJ5lN3jpnVaRsw I63bJZmI76ARI2TY2NXWFLFYF6YnzrKLLIJp0zdAjrKYSUZx83EvV9sjZxPl5wszDeMn F3NwdSNQ3GvV9vHwL/hERTcRTegqT1t88Upjdw1UfHpkpv77E8KpMX5oIXLtNJcyudo6 1/3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MfZ8ka+v; 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 l25si2706966eds.122.2021.03.05.14.23.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 14:23:43 -0800 (PST) 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=MfZ8ka+v; 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 7AF8182700; Fri, 5 Mar 2021 23:23:22 +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="MfZ8ka+v"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1095982748; Fri, 5 Mar 2021 23:23:19 +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 0AB1C8269D for ; Fri, 5 Mar 2021 23:23:14 +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 e10so3693664wro.12 for ; Fri, 05 Mar 2021 14:23:14 -0800 (PST) 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=ms7jMbeTl2lowQXYymgtE0yuZstw/D+B4x1Hc10hXRw=; b=MfZ8ka+vaHvdWy7trQqXx6v8PUMk/ztzFCxqB7SyA5P3Nq5cTQdaDLJ05pIsOEXWXa dzSs8688XZNg4LWF9oIUTuiMfNVn65muFIv/OWyTIQh9f04pn7Kyr+QisGl/UhEjUhLQ Vk19m6fIEbW2mXHVS7ExYEPHpjp8uUffOceBM2AZLCPlh19XUVnBdHkhGLMT9gc3bGiF x2qypI3x7UD1fljCUXbr/1+sRrXDRn6mEd8gM0tzHJTohvrip9QnN0ePpSYPsLhvtU7P i5d1m7fkYclfQMEnfL7rK1BNCN+ahtKvwXXM96QZO5zpeKQz30knS+Nz/zAnZR6h2d7P nYaA== 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=ms7jMbeTl2lowQXYymgtE0yuZstw/D+B4x1Hc10hXRw=; b=AvPYluaPdoxGN7HkM1Vkaqu5DRMRpd7hASBSpREQgqkf0NWMjwtsZSP3pu7Tqe9Jbm CIb84jwgwBlxwBr1KWmWb49SeksxhFAIqXT2yWbwQ1yXtB7lWQIHXeawnw5jfoG6PCKD s07uEkR9JePrmlHucImJxt4t0JeSPhSO2ArDqzCQsjJjiqgBfVuuIzGSLqUHIcJMf6+i U+NFASLrUXk1WsETJ3peQdmkd8751WApt4KxTM1/40GT+M0cYkhfcyaLuMSg19SIn4D5 qrasHlqndEoAiQsFuLQGI7GiPNErTZopd4a23JGAj8S9SeaVqNp76QJp1FABMMyX5r0B Ux7A== X-Gm-Message-State: AOAM531MbzUPJABoA0n7p87WLleYuCbDi7Fx9gEzrttIqhXi+UHyLh7d XrkQTrkzdeHj5ypWDR6NV3FpmQ== X-Received: by 2002:adf:ab52:: with SMTP id r18mr11392035wrc.65.1614982993514; Fri, 05 Mar 2021 14:23:13 -0800 (PST) Received: from apalos.home ([2a02:587:4647:e6c6:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id s11sm6493296wme.22.2021.03.05.14.23.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 14:23:13 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, takahiro.akashi@linaro.org Cc: Ilias Apalodimas , Alexander Graf , Sughosh Ganu , u-boot@lists.denx.de Subject: [PATCH 4/6] efi_loader: Replace config option for initrd loading Date: Sat, 6 Mar 2021 00:23:00 +0200 Message-Id: <20210305222303.2866284-4-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210305222303.2866284-1-ilias.apalodimas@linaro.org> References: <20210305222303.2866284-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 --- cmd/bootefi.c | 3 + include/efi_loader.h | 1 + lib/efi_loader/Kconfig | 15 +-- lib/efi_loader/efi_bootmgr.c | 3 + lib/efi_loader/efi_load_initrd.c | 209 +++++++++++++++++++++---------- 5 files changed, 152 insertions(+), 79 deletions(-) -- 2.30.1 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 eb11a8c7d4b1..0d4f5d9acc9f 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..029f0e515f57 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -317,16 +317,11 @@ 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 - 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..d1baa8c71a4d 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -118,6 +118,9 @@ 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); + /* try to register load file2 for initrd's */ + if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) + ret |= efi_initrd_register(); if (ret != EFI_SUCCESS) { if (EFI_CALL(efi_unload_image(*handle)) != EFI_SUCCESS) diff --git a/lib/efi_loader/efi_load_initrd.c b/lib/efi_loader/efi_load_initrd.c index b9ee8839054f..b11c5ee293fe 100644 --- a/lib/efi_loader/efi_load_initrd.c +++ b/lib/efi_loader/efi_load_initrd.c @@ -5,7 +5,9 @@ #include #include +#include #include +#include #include #include #include @@ -39,41 +41,71 @@ static const struct efi_initrd_dp dp = { } }; +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 */ -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; + const efi_guid_t lf2_initrd_guid = EFI_INITRD_MEDIA_GUID; + struct efi_device_path *cur = NULL; + struct efi_device_path *dp = NULL; + struct efi_device_path *tmp_dp; + efi_uintn_t ret; + efi_uintn_t size; - ret = fs_set_blk_dev(dev, part, FS_TYPE_ANY); - if (ret) { - *status = EFI_NO_MEDIA; + /* + * 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) { + ret = EFI_INVALID_PARAMETER; goto out; } - ret = fs_size(file, &sz); - if (ret) { - sz = 0; - *status = EFI_NOT_FOUND; + tmp_dp = dp; + cur = efi_dp_get_next_instance(&tmp_dp, &size); + if (!cur) { + ret = EFI_OUT_OF_RESOURCES; goto out; } + /* + * We don't care if the file path is eventually NULL here. The + * callers will try to load a file from it and eventually fail + * but let's be explicit with our return values + */ + if (!tmp_dp) { + *initrd_fp = NULL; + ret = EFI_NOT_FOUND; + } else { + *initrd_fp = efi_dp_dup(tmp_dp); + if (*initrd_fp) + ret = EFI_SUCCESS; + else + ret = EFI_OUT_OF_RESOURCES; + } + out: - return sz; + efi_free_pool(cur); + efi_free_pool(dp); + return ret; } /** - * 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,98 +125,131 @@ 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; + struct efi_file_info *info = NULL; + efi_status_t ret = EFI_NOT_FOUND; + struct efi_file_handle *f; + 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; + 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) + + /* Open file */ + f = efi_file_from_path(initrd_fp); + if (!f) { + ret = EFI_NOT_FOUND; goto out; - file = strsep(&pos, " "); - if (!file) + } + + /* Get file size */ + bs = 0; + EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid, + &bs, info)); + if (ret != EFI_BUFFER_TOO_SMALL) { + ret = EFI_DEVICE_ERROR; goto out; + } - file_sz = get_file_size(dev, part, file, &status); - if (!file_sz) + info = malloc(bs); + EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid, &bs, + info)); + if (ret != EFI_SUCCESS) goto out; - if (!buffer || *buffer_size < file_sz) { - status = EFI_BUFFER_TOO_SMALL; - *buffer_size = file_sz; + bs = info->file_size; + 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; + EFI_CALL(ret = f->read(f, &bs, (void *)(uintptr_t)buffer)); + *buffer_size = bs; } out: - free(filespec); - return EFI_EXIT(status); + free(info); + efi_free_pool(initrd_fp); + 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) { + ret = EFI_NOT_FOUND; + goto out; + } + + EFI_CALL(f->close(f)); + +out: + 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 */ @@ -196,3 +261,9 @@ efi_status_t efi_initrd_register(void) return ret; } + +void efi_initrd_deregister(void) +{ + efi_delete_handle(efi_initrd_handle); + efi_initrd_handle = NULL; +} From patchwork Fri Mar 5 22:23:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 393595 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp811800jai; Fri, 5 Mar 2021 14:23:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJzfLgGnpFkBkhJ4ZDRqkRx9bm0nTaffAUhXWwt3QwlLoBtztwJGltYKYJWv2e/DCQhDd2Ja X-Received: by 2002:a17:906:5498:: with SMTP id r24mr4489118ejo.29.1614983033689; Fri, 05 Mar 2021 14:23:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614983033; cv=none; d=google.com; s=arc-20160816; b=kJOy2FJ5XL6sZfqOEwuJnGKM864V3XH+XUrB5rVFOeW0uxYKgdDPGVghxPAINOID1E 4mlQNqjESh9y6k4rtjGwnAcPRiLwWuddG39f9GKLR+lIeHYeGxJa+wRGLwPULKpT8c2j Oc1OXVXEZOrEijlUckzEJUQlw0Neu4rh36p9QGSSSCrNcOkfFUIwojwphPN451UY60qx zRp8ymBtSejd33rH2IDdTOyIZPFju2NsM6LBipMKHQTHhy+sHeA8Q9XNBZBjbcXFufe2 XdxTCjHSW66h92MR6bBRARFLwEOd3bXot0erHtxvGo4m/azS+MIKcmdkU39qC3tk9ctR 5sFA== 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=REadFhGeThBk1InjOfUot2CjqUZOtNk9JmR++lfR0eU=; b=RygE+QRCf7CJ8pufQqTglXls0Avd2Je/8OtyukBydKllKo+tr2+J0ipZavvpoe2dWh ScBfMtBd7YH0zGt2foUz1blCbYQuMl87nL2e54zJ0t1K7Z5Ul1SIFTKfby3TXcWQ495r KOKtxZGJ/WFIb0Hj1NWI6ZGcr6vv5lknlagnKaencxnqRJUo0MaUcCnhRu/Zomim6m5k X3eqbM+zdLDYEvya3BLXx+xPS8qj6L9SI0JyO7TlPB3qcRFdooniZsHY/DPOCEDY8XkL RwU/QIxt7bE1fWY0hHRNGc3v+V5JonerSTGzCd6ufxNjs8fpSXORwx9nqFu1GrzEFuck RpAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A2M00hGE; 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 ce20si2130191edb.34.2021.03.05.14.23.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 14:23:53 -0800 (PST) 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=A2M00hGE; 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 221E482774; Fri, 5 Mar 2021 23:23:25 +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="A2M00hGE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 93CD982700; Fri, 5 Mar 2021 23:23:21 +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-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) (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 6EA25826AC for ; Fri, 5 Mar 2021 23:23:16 +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-x429.google.com with SMTP id f12so3710882wrx.8 for ; Fri, 05 Mar 2021 14:23:16 -0800 (PST) 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=REadFhGeThBk1InjOfUot2CjqUZOtNk9JmR++lfR0eU=; b=A2M00hGEXVw11RXptPwPtZfsWRvGv7t0HVjMGXAXJw7EWaxEPpH71xdx8FC7SXZ+tX Km8ELZeUc+Gx0bOJWS+c82YXo+BjDjuIYCI9Xk6j5cRO2sqJxu4vvpzo0Sc9C4aRz15f Uf+b2CxDWm3B1+upxglXl21zS/AUYiWEZ4rQc5hUsezW8rS85Ec6xGdPKwH5swOKKgXQ JMXFUwmIlUrq0SLV7Y8mek85Nrn+IX3UU0w1aXazGFs4g/F0ps6LQ2XYjwHe9B8ce0Q/ IY4KSoiWBk0EBuSY4+kjXPVRIa3MD9kJ/5jj54zsE/GKKVv5jLbRtCM3Cjgi3F5pZsv4 KNRg== 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=REadFhGeThBk1InjOfUot2CjqUZOtNk9JmR++lfR0eU=; b=Of3wXj91b9DZbKnd0fw4yF1UzOUTO2zyGS4TBzGuXdpGmacxzTCa6HA30YOHesKVRv F3UwRmgvC4eLZ33HuXLoE4K0akJbamu25ZZFOSGzsFYDZUUE2495itM89pr0XN1D5yRM VLVRK/YHJicOLcKLtqUGrXy+RwTkrO11yiYZffsknbmzp5KkveF08Y5HmIOWXEVn/y/6 69PuXYmgJq40xSDCNPx96T7JhVJVu/xy6mWA2GmJ1AFeRIJxJhELkqaKXIQjRxVGVC4J +RxMjk+lyYFrc6wnP2XnfoMAneK+Y5uCuS5MgayaN1ybhryj6npi6N9f/je89H1ItIEk QMZg== X-Gm-Message-State: AOAM530hlUkodQtl6qMavUN28mV9/Mt7QXhVJE1QrnuuhXCaQBcKceAy UWkHlie4wz5nZhG3qv6anRwiMQ== X-Received: by 2002:adf:a703:: with SMTP id c3mr11155405wrd.379.1614982995936; Fri, 05 Mar 2021 14:23:15 -0800 (PST) Received: from apalos.home ([2a02:587:4647:e6c6:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id s11sm6493296wme.22.2021.03.05.14.23.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 14:23:15 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, takahiro.akashi@linaro.org Cc: Ilias Apalodimas , Alexander Graf , Sughosh Ganu , u-boot@lists.denx.de Subject: [PATCH 5/6] efidebug: add multiple device path instances on Boot#### Date: Sat, 6 Mar 2021 00:23:01 +0200 Message-Id: <20210305222303.2866284-5-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210305222303.2866284-1-ilias.apalodimas@linaro.org> References: <20210305222303.2866284-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 allow 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, 179 insertions(+), 58 deletions(-) -- 2.30.1 diff --git a/cmd/efidebug.c b/cmd/efidebug.c index bbbcb0a54643..9a1c471a3eaa 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include #include #include @@ -19,6 +21,7 @@ #include #include #include +#include #define BS systab.boottime #define RT systab.runtime @@ -794,6 +797,65 @@ 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 + * + * @argc: Number of arguments + * @argv: Argument array + * @file_path Existing device path, the new instance will be appended + * 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_instance((const struct efi_device_path *)&id_dp, + tmp_fp); + if (!initrd_dp) { + printf("Cannot append media vendor device path path\n"); + 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 ? final_fp : ERR_PTR(-EINVAL); +} + /** * do_efi_boot_add() - set UEFI load option * @@ -806,7 +868,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