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