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