From patchwork Sat Mar 13 21:47: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: 399603 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2272696jai; Sat, 13 Mar 2021 13:49:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4vYH286EupOSWVcBi2TWcUffBxUepuUoY4/Yddr+/UKBL7+w92G/MSPo60xygOb3dL6I6 X-Received: by 2002:aa7:c7c3:: with SMTP id o3mr22197666eds.8.1615672145681; Sat, 13 Mar 2021 13:49:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615672145; cv=none; d=google.com; s=arc-20160816; b=O66SNLNhzvUiEbWPxRI4n/81z5PlCUbCsmOkRhsmVs1FWKIHkI+58mt2QLudj7BATj XokOFu8xQqDAfj0hidNZnaFSWcyx1jK4bI/i8+xxLVuC0eV8F2S1WWBguc9UzwQRIEk+ C0U8aXkLFQ4V9SCJDvHJQsMskSClrtKqL/gegz60g/hmu9HCBBR8eixB/4kqiY8u9Y7Q w+8OkU8TXZ9hkuuBYDUud/X6knyegfh7Lo0iLrwB67E6ypHz7BDeOWtEdNkwc2Cv/5/S QNJWzqaIegOLZEjVWO4AfuNIfcmyR9q5lxh/y8Vp4M0M5ATkSVjXvCYiDCJcklDe41Te 4IDQ== 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=wPYln86tgcXy3izEtVO0osSR27ceaNRV4De9E3sFEUE=; b=pvBn8w9OOpjNJXHGcmkA4EeRhoMbAIttYIj+jq641ikq1eVx4OtsSUxHPKmv0Z4mby goYebxCKNWOXKd1CamBpfTKWKnlo8qzqIHruWJdww2Ezw2WSUlKnbLM3W8xGAApa/nWR ymxClHXp8d7Cb1QbIOXZb3acOuhC33RGn1W9l+Hr9RoGc17iX+zb19dMfrIw+z82f/KQ YS8sgpHMJ5auzdJUXrgz+jjDr4wA1jNmw9spQVj7rzpIXrK4x+IVvGI9tvMApVa4/8Gr lxqgz4SOF9Vy+h4EOWnDEhMMSqti07icWRuWg8knIRDiMaDADj0SEDQJseOfgg1aY4Z3 qPzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wKM826dI; 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 5si7860882ejn.116.2021.03.13.13.49.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 13:49:05 -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=wKM826dI; 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 CAC4582897; Sat, 13 Mar 2021 22:48:08 +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="wKM826dI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D84408285E; Sat, 13 Mar 2021 22:48:00 +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-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) (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 8C4B282858 for ; Sat, 13 Mar 2021 22:47: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-ej1-x634.google.com with SMTP id r17so60032488ejy.13 for ; Sat, 13 Mar 2021 13:47:54 -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=wPYln86tgcXy3izEtVO0osSR27ceaNRV4De9E3sFEUE=; b=wKM826dIXzQ4d52NxU8+IXTmxUexPHueqF92x3azEGWQ5XMYK2PUN62D1I9xiqqTpz nQds5o+016XUG7VJLjKFtGjBd6Rc9py/dzQiPdRxU4HiLbzCaHbVY4uJ1+Wy4rkunpuh a64YR90PJYwAaIKcdCx73yptDmNvzpZMGCdqi7alDqB9an2HlCY0ImT3IdUFdDU7+TjH jaBMbjAN3dvSchZ1SwV2mv5UyhWR7HEXlsWVizXcZPjLtLOCdDYmU0+0q3JKan7j73Y3 pvEXxtR+cT0/LzIDCDH/Gkli33nnuYKEQhCbtbQZeaorEEWZlCGd3es9yk53g+BhjrGr G+lw== 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=wPYln86tgcXy3izEtVO0osSR27ceaNRV4De9E3sFEUE=; b=pW9mu7rUgLxg2rvioNmJ9sdQL9ZOofK4YrcUB+AHS59D91bVYrD6fWIK/iSTbo/bm6 NDJ9cfr54XgPOPCy3hTd14Me1sBt5uSHKBmrPePf192I3Xqi555P2+SfwVp8fmd3TgFI LT6XMbQwS/n69K2D9ArhSmhVCGcEk9BTF74t3S0KMPSafaGG8tBkaxD3PFkbSw/vU2Ie KoY5U8MzT+TZvzYs/o/A369UGigQHBdPXcREfsgARcqfUkPo5+PFN1U5goTgfnrwN74e C1leq4hDs4587Iw97+saXCEv7Nj7LIu2mABHSDGunb8dbWK+fYIQM/kpnmvwr7oyj2/Q NV5g== X-Gm-Message-State: AOAM531Lj+7ozCbn7owi0PSkIpF0PaAuPAmvMOLFE6Q3QOL1HLsmOEsf Pgf+Td/EsfA2wtsuJB+Va5CqtA== X-Received: by 2002:a17:906:f12:: with SMTP id z18mr15851976eji.132.1615672074134; Sat, 13 Mar 2021 13:47:54 -0800 (PST) Received: from apalos.home ([2a02:587:4647:e6c6:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id a9sm1571144eds.33.2021.03.13.13.47.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 13:47:53 -0800 (PST) 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 v2] efidebug: add multiple device path instances on Boot#### Date: Sat, 13 Mar 2021 23:47:36 +0200 Message-Id: <20210313214738.3257922-6-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210313214738.3257922-1-ilias.apalodimas@linaro.org> References: <20210313214738.3257922-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 | 194 ++++++++++++++---- 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, 180 insertions(+), 58 deletions(-) -- 2.30.1 diff --git a/cmd/efidebug.c b/cmd/efidebug.c index bbbcb0a54643..223cffa389fb 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,66 @@ 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) { + 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 +869,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