From patchwork Mon Dec 28 12:24:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 352611 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp9705786jai; Mon, 28 Dec 2020 04:25:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJzmRm6RmBhYpq0aD89E/hBsrBxouvqnsWUBoiF3V+Xax8tHJCnuZUWCOrz3lzIey7Qqqb2s X-Received: by 2002:a17:906:b08f:: with SMTP id x15mr41428658ejy.36.1609158302814; Mon, 28 Dec 2020 04:25:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609158302; cv=none; d=google.com; s=arc-20160816; b=cpQgVsa/ZWbndxYM3GTFpzakw0cEGvLrpNdeBUY8itfm4PZ6ezNw5uuFAY8XL5WFe3 Fd5LUNWd9vrSPdeIqrEPHXp12Hl7onGawvXQqshdOEjHGl15lnyO6za62HcXoK9HAI48 mK67BaA+E59si0qcj25+X4Em+pm84EmF/ZSbC+JOp7X3iIlVjZtFj4rJTiCHDgK+5WH/ W/z8DWBRdrrUWG5jKrdXD+m9qqa72AvBIVpUnbTK+XOiL70YDogW05gHATZUfQeW52eI gHOOp45oPuFkOrFSpgut6w01gL/tCkIpbmYbBCRneTkq3cINnl0QfIjOtJ0dmSu0avPp 09Rg== 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=Do2zLEyevFIxalQhp34urDEKDXIhK1evlWJtbyM1ivE=; b=uLyYZlvVS5wa7Hxw6t0ATeMXMLyvKNw9wU0y/9HKc0KpVvJ/eeBIl3yrDgMSi2Hjz9 UKqSAm8h5+uWgQlgefUWL9BBXAKFqkjDNaRXhFHqZxK1pZdsauJkbJSNisWqvvw4YHvr wga77T1xGG0T8jv1ou/8BAcFj+jSGc3g/wpQP3CpS+maXmkjiS9QMLxeXWDoiWHe1vEY o3A0EYvxkZyEAWAB85lPo7lMbHdc6GpHfxjweTDoARluDp7asxnWKNGOf2A0ZMF16g3K qxsGNxJi3QYNSW/zbjDxUZRE5C+09N35/9WD3usyS5Zz5rgvdv8Q4jcZomTDOtujZ9lU xzjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X5Yafv8G; 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 d14si17585841ejt.356.2020.12.28.04.25.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 04:25:02 -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=X5Yafv8G; 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 E11508241C; Mon, 28 Dec 2020 13:24: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=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="X5Yafv8G"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5E4178241C; Mon, 28 Dec 2020 13:24:50 +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,RCVD_IN_DNSWL_NONE,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 23E178232D for ; Mon, 28 Dec 2020 13:24:46 +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 d26so11143362wrb.12 for ; Mon, 28 Dec 2020 04:24:46 -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=Do2zLEyevFIxalQhp34urDEKDXIhK1evlWJtbyM1ivE=; b=X5Yafv8Gx09nYsg8Ng38+2NlVjbmM4cfc/HRjgcYw22Gnl8PSSsrHOZPL6KIJtDKwa 188tfJ73fgYMzX/Wz/KUzNy00GUOhWTkLLEqvmfBeueoojKhO1JU591cABMPXwrTlDa5 cgXFSgpdh+UGSygtniFlF1reHayODDonS64mYktneDzl25wGPlqd3lYHqTlZyj93cZhh BinOLT2aufIliR/sSsjynm9t1lCXWU6wC46d1vaIY2adq2gTqs07ONpufi3qxkkkyKwr 6+8a8aHgHEFR0JHNYPTaaD6PHic6zJp51fBw8vSD7rd4GDedvqIe503Au/RH1UodS/CQ AnyA== 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=Do2zLEyevFIxalQhp34urDEKDXIhK1evlWJtbyM1ivE=; b=cfm79nAAD/GBtd2smzaoBqQIp4JLv1QaQBocDLxFx/nfCaaok8CW2/WcwvyeOwaH3k X37esmgkU/smOsuJZb8YQGa6B4pU5Apu657FShYGPw6hkJc8gyWmC+Sa+yvX0ot91Lt9 KvUvggGSka1eBVW4AtPPVstCW/eRXHVcUE+3i9Xtx0m1OFOyilW5BR3N2qeL8JcS+WGK hjO8f7Ao9D+EQTW2d+v7T3GDtAcrwnoQTeitV6ykWcblwlmTVfQlOOhIK5/REQInoNOo DkzLxOUSd9OIstglTOs0Fafe5ztyakK8tzaKgv/uyTwSDAEtI40jB1VbGLUmP3dXDgxe b6qQ== X-Gm-Message-State: AOAM530N7eHo4zFwyrVL81hCj2Jsgdjf6YFsDB2jB2KDAFnMtjCleLHT Vyy+STXQaKe1L8cWzIEG8yosKg== X-Received: by 2002:adf:c14d:: with SMTP id w13mr49985747wre.383.1609158285767; Mon, 28 Dec 2020 04:24:45 -0800 (PST) Received: from localhost.localdomain (athedsl-4484548.home.otenet.gr. [94.71.57.204]) by smtp.gmail.com with ESMTPSA id w21sm18710321wmi.45.2020.12.28.04.24.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 04:24:45 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, ard.biesheuvel@arm.com, Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH 1/6] efi_loader: remove unconditional initialization of file2 protocol for initrd Date: Mon, 28 Dec 2020 14:24:33 +0200 Message-Id: <20201228122440.316403-2-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0.rc2 In-Reply-To: <20201228122440.316403-1-ilias.apalodimas@linaro.org> References: <20201228122440.316403-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.3 at phobos.denx.de X-Virus-Status: Clean Up to now we register EFI_LOAD_FILE2_PROTOCOL to load an initrd unconditionally. Although we correctly return various EFI return 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 registered. This creates a problem for EFI installers, since they won't be able to load their own initrd and start the installation. A following patch introduces a different logic where we search for an initrd path defined in an EFI variable named 'Initrd####'. If the bootmgr is used to launch the EFI payload, we'll will try to match the BootCurrent value and find the corresponding initrd (i.e Boot0000 -> Initrd0000 etc). If the file is found, we'll register the required protocol which the kernel's efi-stub can use and load our initrd. Signed-off-by: Ilias Apalodimas --- lib/efi_loader/efi_setup.c | 5 ----- 1 file changed, 5 deletions(-) -- 2.30.0.rc2 diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index e206b60bb82c..d7f880921268 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -209,11 +209,6 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; #endif -#ifdef CONFIG_EFI_LOAD_FILE2_INITRD - ret = efi_initrd_register(); - if (ret != EFI_SUCCESS) - goto out; -#endif #ifdef CONFIG_NET ret = efi_net_register(); if (ret != EFI_SUCCESS) From patchwork Mon Dec 28 12:24:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 352612 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp9705901jai; Mon, 28 Dec 2020 04:25:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJyLKQY3+odllwEfJfRE8S4xzaWVN/zvIGvs+gz0pIWoSqMSZYaIBlg/p2Pb/vrogiwjlZp4 X-Received: by 2002:a05:6402:94c:: with SMTP id h12mr42058228edz.268.1609158312522; Mon, 28 Dec 2020 04:25:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609158312; cv=none; d=google.com; s=arc-20160816; b=eZL1Om44HSwkq6sTZJW0jYKL2LDOXPczFqLabsPVnDyriH8pJrZlhtLQeh5HX5GSRU D1qFl3zEUSL3f1h1EvlLb/pX0BNRekQzeTx1whJkJzpTIg4cOakq2gIRxtAmT/m7dcnT YUI321xhcZi4IQ4Zk1Of6Sz9wjfm5Fnu4xz4clvnxTvGTgWXy034qeqF5JY3U2V/CHk0 sXcpCo62yLQ2LPxb9iJ64PZWv1HCZLhogt+tImYhnu9ZYW/a5O41BhFaltzSOSiFrYAZ bJ+hA+lH4z01e2Kh++1dQxIH/8tv1OUhTrq6xKB6+Kx161kulxP+x6FfiWLO5oQBMYwo +GOQ== 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=Rvmf4NtYbsV4B+CR9AaY2V5Uo9GQ0IZzE+k4WrEsISI=; b=vw7wdJcRbSQVvDtZOq53idawsZg2vHl18b5x/6k/bbrPTkHwlD+/P1VGQkICxoCLNK nFNl/b4icBf5T2PT9Fh89BA+XWnzQ3TZ/qhW7IlIblPzZzcIROZnmnvZqIHA+Qvy89mO fc1R66abln6JFHYrWAzi8rFeIA3JTODY6KGRa8hGFeCQ3Ayx9tAweFJAO+g/Xfx9L1Mw htbDMxelGKNsK6YV/GdH6HZeBZdhMZcVHJEtxFdgIWyNc9yE2672v/rS4jUloXnS59uD JLJ0Iw7Aa9g2ZJEtU0ob5qSBXxv7mQx61m7N3eR0t6NW5fqLD/Xp8zX/j9aivDez+vJi lX5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZjDJ4CFC; 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 lz16si17623947ejb.373.2020.12.28.04.25.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 04:25:12 -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=ZjDJ4CFC; 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 E4C1F8244B; Mon, 28 Dec 2020 13:25: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=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="ZjDJ4CFC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2B67D8241C; Mon, 28 Dec 2020 13:24:53 +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,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) (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 05F3D82409 for ; Mon, 28 Dec 2020 13:24:48 +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-x335.google.com with SMTP id 3so9664921wmg.4 for ; Mon, 28 Dec 2020 04:24:48 -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=Rvmf4NtYbsV4B+CR9AaY2V5Uo9GQ0IZzE+k4WrEsISI=; b=ZjDJ4CFCUe1FknrozsTet9oXp2ZVejGc1XQZoxGeBkCI6PLbkcvEmTT0FGcVgpTFnb cAFH64ekE9qje+1fIwZ6orU5SJ6+7W/gmc2WF9pHlu+9Pw9JrPXzPr0Itnqck6yRYo1N R0KtnPm0NIK61VWkSutr9XVkaiWuhCDn21U+93KcMVCpBTIsOwu73+mrSmyNKIr3Q+ff Tvr0BkbxNEbkeMKnm9MNM7rr8QOzN4nFn581mu9OPmP9SxAUTqhsmyFOxzUzhrS6Fyoi vjtBAyuJYxJGqFYcLvjtTkvrMNC63SvuBXLZ2pdCOXT7f2LSHVHHVjhZwXUq5s99S44f U1fA== 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=Rvmf4NtYbsV4B+CR9AaY2V5Uo9GQ0IZzE+k4WrEsISI=; b=JkXeLdfPm/WT7LSvRCl7GZT/+bIcNGNDDkSfQh+4fbmMzHnQIM81DiqQKjNFHcR9t2 ySbdO4sBDq0sHBpVRKeEPZssAox4icT3rJ0IX4EPYuvHYiYxViiUDxSvYHWPvLd7/JfK YvIedEe3wuoXisnuVLREiQu7FoRcQM9cMY25k+qOZ7JmeE5sijBtmlDwaBEFGA8Xx5K9 e7bZifiGM9SX9Jwt4iSRE1dbOyVY5XE77Vj7AXlWbeBQ/TN1OYU4+tBLLHVVw+LfOIUJ ENuwiNUXTS5Qzd+ZZ2NGMTOuIyiB9zafwCmjrMZf6Ff4skQqMDI1M26S62L2d8+YkbIe oA7Q== X-Gm-Message-State: AOAM530xgTdW4aPkLBXB3s2WY4Z9P86ZzgxUbAQ3SUpEzPJV4DB0rzjT jyT6P666UaB7D1BylHeosMABhw== X-Received: by 2002:a7b:cc0f:: with SMTP id f15mr20375006wmh.29.1609158288539; Mon, 28 Dec 2020 04:24:48 -0800 (PST) Received: from localhost.localdomain (athedsl-4484548.home.otenet.gr. [94.71.57.204]) by smtp.gmail.com with ESMTPSA id w21sm18710321wmi.45.2020.12.28.04.24.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 04:24:48 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, ard.biesheuvel@arm.com, Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH 2/6] efi_loader: Introduce helper functions for EFI Date: Mon, 28 Dec 2020 14:24:34 +0200 Message-Id: <20201228122440.316403-3-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0.rc2 In-Reply-To: <20201228122440.316403-1-ilias.apalodimas@linaro.org> References: <20201228122440.316403-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.3 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 device paths via EFI variables. Signed-off-by: Ilias Apalodimas --- include/efi_helper.h | 29 ++++++ lib/efi_loader/efi_helper.c | 189 ++++++++++++++++++++++++++++++++++++ 2 files changed, 218 insertions(+) create mode 100644 include/efi_helper.h create mode 100644 lib/efi_loader/efi_helper.c -- 2.30.0.rc2 diff --git a/include/efi_helper.h b/include/efi_helper.h new file mode 100644 index 000000000000..d76e24e0f57d --- /dev/null +++ b/include/efi_helper.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2020, Linaro Limited + */ + +#if !defined _EFI_HELPER_H_ +#define _EFI_HELPER_H + +#include +#include + +/* + * @dev: device string i.e 'mmc' + * @part: partition string i.e '0:2' + * @filename: name of the file + */ +struct load_file_info { + char dev[32]; + char part[16]; + char filename[256]; +}; + +loff_t get_file_size(const struct load_file_info *file_loc, + efi_status_t *status); +efi_status_t efi_get_fp_from_var(const u16 *name, u16 start, + struct load_file_info *loc); +void *get_var(u16 *name, const efi_guid_t *vendor, efi_uintn_t *size); + +#endif diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c new file mode 100644 index 000000000000..4cf1f8abed30 --- /dev/null +++ b/lib/efi_loader/efi_helper.c @@ -0,0 +1,189 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2020, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * get_file_size() - retrieve the size of initramfs, set efi status on error + * + * @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 + * + * Return: size of file + */ +loff_t get_file_size(const struct load_file_info *info, efi_status_t *status) +{ + loff_t sz = 0; + int ret; + + ret = fs_set_blk_dev(info->dev, info->part, FS_TYPE_ANY); + if (ret) { + *status = EFI_NO_MEDIA; + goto out; + } + + ret = fs_size(info->filename, &sz); + if (ret) { + sz = 0; + *status = EFI_NOT_FOUND; + goto out; + } + +out: + return sz; +} + +/* + * string_to_load_args() - Fill in a struct load_file_info with the file info + * parsed from an EFI variable + * + * @args: value of the EFI variable i.e "mmc 0 initrd" + * @info: struct to fill in with file specific info + * + * Return: Status code + */ +static efi_status_t string_to_load_args(char *args, struct load_file_info *info) +{ + efi_status_t status = EFI_SUCCESS; + char *p; + + /* + * expect a string with three space separated parts: + * - block device type, e.g. "mmc" + * - device and partition identifier, e.g. "0:1" + * - file path on the block device, e.g. "/boot/initrd.cpio.gz" + */ + p = strsep(&args, " "); + if (!p) { + status = EFI_NO_MEDIA; + goto out; + } + strncpy(info->dev, p, sizeof(info->dev)); + + p = strsep(&args, " "); + if (!p) { + status = EFI_NO_MEDIA; + goto out; + } + strncpy(info->part, p, sizeof(info->part)); + + p = strsep(&args, " "); + if (!p) { + status = EFI_NOT_FOUND; + goto out; + } + strncpy(info->filename, p, sizeof(info->filename)); + +out: + return status; +} + +/** + * 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 *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); + ret = efi_get_variable_int(name, vendor, NULL, size, buf, NULL); + } + + if (ret != EFI_SUCCESS) { + free(buf); + *size = 0; + return NULL; + } + + return buf; +} + +/** + * efi_get_fp_from_var() - Retrieve a file path from an EFI variable + * + * @name: variable name + * @start: start replacing from + * @info: struct to fill in with file specific info + */ +efi_status_t efi_get_fp_from_var(const u16 *name, u16 start, + struct load_file_info *info) +{ + u16 hexmap[] = L"0123456789ABCDEF"; + efi_uintn_t boot_order_size; + void *var_value = NULL; + u16 *name_dup = NULL; + efi_uintn_t size; + efi_status_t ret; + u16 boot_order; + + memset(info, 0, sizeof(*info)); + + /* make sure we have enough space for replacements */ + if (u16_strsize(name) < sizeof(*name) * start + u16_strsize(L"####")) { + ret = EFI_INVALID_PARAMETER; + goto out; + } + boot_order_size = sizeof(boot_order); + ret = efi_get_variable_int(L"BootCurrent", + &efi_global_variable_guid, NULL, + &boot_order_size, &boot_order, NULL); + if (ret != EFI_SUCCESS) + goto out; + + name_dup = u16_strdup(name); + if (!name_dup) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + /* Match name variable to BootCurrent */ + name_dup[start] = hexmap[(boot_order & 0xf000) >> 12]; + name_dup[start + 1] = hexmap[(boot_order & 0x0f00) >> 8]; + name_dup[start + 2] = hexmap[(boot_order & 0x00f0) >> 4]; + name_dup[start + 3] = hexmap[(boot_order & 0x000f) >> 0]; + + var_value = get_var(name_dup, &efi_global_variable_guid, &size); + if (!var_value) { + ret = EFI_NOT_FOUND; + goto out; + } + + ret = string_to_load_args(var_value, info); + if (ret != EFI_SUCCESS) + goto out; + + if (fs_set_blk_dev(info->dev, info->part, FS_TYPE_ANY)) { + ret = EFI_NO_MEDIA; + goto out; + } + + if (!fs_exists(info->filename)) { + ret = EFI_NOT_FOUND; + goto out; + } + +out: + free(var_value); + free(name_dup); + return ret; +} From patchwork Mon Dec 28 12:24:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 352613 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp9706049jai; Mon, 28 Dec 2020 04:25:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJyYbjb+kBoZZB4MfpaGoWESHujHJDz6NAJVFf48ggdm8XOqGe4RINFsa8WODZLb5VJRcLN7 X-Received: by 2002:a17:906:f9da:: with SMTP id lj26mr40439127ejb.467.1609158325290; Mon, 28 Dec 2020 04:25:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609158325; cv=none; d=google.com; s=arc-20160816; b=eZkBOJ3uKgkZ5t9jd8rswpSfaCNgwJnuEok8YR11Gj/tZh3FyFIuvOEVIt3EyAAmKx jsZKHsU7KojEzbUNB/iWYO41B0E4VeED+odEkGpXIkeU//aUkeFwRB/r/xeRZpHzKuwN Pocmv8DtQxnx+L0pmihBOKDIMXYSXTtnPXF5wLwnumHpOOicIoJB0n6pT/QY2H5zFUzs Wz19Qh29pfb3OJ/9NmvkJSHRANoQVOIaSUp0wD0/v3lxAWZ/R2sfZol1qmkwlAELM/b9 9XhaDejKATCUgI8od3qhvXO2Jywka4AgjEBPvNeMVNTpjuBJae2jIn0AzzFZBFZTc1ps VIsw== 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=4a46bwnsrQkOkqJ3spx6VV0iU619VGKCfjwSSYJZe0k=; b=X9gOi+m/mdyedazi+Az0Cr0NV15F6Llb3J5MCVp3YP9JkpFxg846jwmiUopmYbRKT/ CnQGcow3sFyltPLpb3UsqXsutPcmiWjDpJK5LGqT1KvNjnjpj5FuMrkFLpReRY44FXaU c8XTF0nH+s6kfR7hLNLi7Cedmlen99UwQhc9q4ioeOsYgUgpZce4P3OqS6K+kl8Q0L1N RIKagcaVM+9NPsuz2aWjIdSatuBrPNihiBCAweg+pxS3+N8i+Z+Z6DUK+MsJbpNfB2tW Zo3LMGM/j230mkH01Ov7fX1hU3fznbjsI4bwcSfDIJp8uFlzuzhAtbFv2vvZifBVmns1 DoSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qEUmTnP0; 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 h14si18043752eji.737.2020.12.28.04.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 04:25:25 -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=qEUmTnP0; 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 E89C8823D3; Mon, 28 Dec 2020 13:25: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="qEUmTnP0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DE09D8253F; Mon, 28 Dec 2020 13:24:56 +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,RCVD_IN_DNSWL_NONE,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 A00AC8232D for ; Mon, 28 Dec 2020 13:24:51 +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 d13so11139643wrc.13 for ; Mon, 28 Dec 2020 04:24:51 -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=4a46bwnsrQkOkqJ3spx6VV0iU619VGKCfjwSSYJZe0k=; b=qEUmTnP0PoSoLvBJFtpwb/G3ZS2NxlYnZtjVXLLWEOhVZMCQ9MxI0YrAOzLRCVyVJp pAykqChmTErySXd4oyCqTUdw7Bw6V2ufyTC3P86m+NQrVR/2TDq91FxV6bXqJPagIMHx 892t3QT06L/jZBuhvpJrT4PLWkoItMEBe4dCUKyTP2LWR+//6Du+/2IAt4WD3qXrvgMp SfR5dg1Ip405x0/AiLuAmJiPDFloTVlwUJUlAEMBKX6OwPsrZ4aRBr2J+O4WMWd+HyjD t8RHirRkT2t/1FxQewgGnTKNprCNLwqqwMjr/jitPJtOlqMw+yk7kjF71KZjDbo/ogFk JM0g== 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=4a46bwnsrQkOkqJ3spx6VV0iU619VGKCfjwSSYJZe0k=; b=P6dAy67tcGyNcBCxE2ZD8zT0JNTLxZL6fSNRiVx/B1EHBBVMyiRHBfj3k3W2Kcpe2X 9mtkdkDpYuKbtA/oa+9EgRF8Mg0iRLoM7uEeIltrFZhzcVrKRIxAxeXyE9yimPS7FtBF ul9NEKn1OIyU+Wi/Cn5UrqMhE9eYqTGyiwXoCNcij8ECSufvjxs2ainNWGHG4gHT96nI hrdTOZ8i4frrNLNzP45BpXu472VClqn3cQWfThJbAKaLj/SmgUVh2NkKwlOiaccOwwkJ sERPBh0gkbemnoNRBJtg3C60mJUaE0axJ9KNWmHE33yJpKuxULVJwB17XCzyCq7J8AD9 CCuQ== X-Gm-Message-State: AOAM530prmnYFvJ6UWT+PwC7cb80PdAgpRGmkOF9XYfL+cj8dc55OYVl lTj7pmlDT92QPN9wXI26J5TAOw== X-Received: by 2002:a5d:6045:: with SMTP id j5mr49157752wrt.223.1609158291205; Mon, 28 Dec 2020 04:24:51 -0800 (PST) Received: from localhost.localdomain (athedsl-4484548.home.otenet.gr. [94.71.57.204]) by smtp.gmail.com with ESMTPSA id w21sm18710321wmi.45.2020.12.28.04.24.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 04:24:50 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, ard.biesheuvel@arm.com, Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH 3/6] efi_loader: Replace config option with EFI variable for initrd loading Date: Mon, 28 Dec 2020 14:24:35 +0200 Message-Id: <20201228122440.316403-4-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0.rc2 In-Reply-To: <20201228122440.316403-1-ilias.apalodimas@linaro.org> References: <20201228122440.316403-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.3 at phobos.denx.de X-Virus-Status: Clean Up to now we register EFI_LOAD_FILE2_PROTOCOL to load an initrd unconditionally. Although we correctly return various EFI return 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 registered. This creates a problem for EFI installers, since they won't be able to load their own initrd and continue the installation. So let's introduce a different logic that will decopouple the initrd path from the config option we currently support. When the EFI application is launched through the bootmgr, we'll try to match the BootCurrent value to an Initrd#### EFI variable. i.e Boot0000 -> Initrd0000, Boot0010 -> Initrd0010 etc. The Initrd#### EFI variable is expected to include the full file path, i.e 'mmc 0:1 initrd'. If the file is found, we'll register the appropriate protocol so the kernel's efi-stub load our initrd. If the file is not found the kernel will still try to load an initrd parsing the kernel cmdline, since the protocol won't be registered. 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. So we can base the whole boot flow on the Boot#### and Initrd#### paired values. Suggested-by: Heinrich Schuchardt Signed-off-by: Ilias Apalodimas --- lib/efi_loader/Kconfig | 12 ++--- lib/efi_loader/Makefile | 2 +- lib/efi_loader/efi_bootmgr.c | 6 ++- lib/efi_loader/efi_load_initrd.c | 86 +++++++++----------------------- 4 files changed, 33 insertions(+), 73 deletions(-) -- 2.30.0.rc2 diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index dd8b93bd3c5a..eca24e82b8b1 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -212,14 +212,10 @@ config EFI_LOAD_FILE2_INITRD 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. + initrd= will stop working. The protocol will only be + registered if bootmgr is used and the file is found on the defined + path. A boot entry of Boot0001 will try to match Initrd0001 and use + it. Initrd format 'mmc 0:1 ' config EFI_SECURE_BOOT bool "Enable EFI secure boot support" diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index cd4b252a417c..793e5b7f8730 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -54,7 +54,7 @@ obj-$(CONFIG_GENERATE_ACPI_TABLE) += efi_acpi.o obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_rng.o obj-$(CONFIG_EFI_TCG2_PROTOCOL) += efi_tcg2.o -obj-$(CONFIG_EFI_LOAD_FILE2_INITRD) += efi_load_initrd.o +obj-$(CONFIG_EFI_LOAD_FILE2_INITRD) += efi_helper.o efi_load_initrd.o obj-y += efi_signature.o EFI_VAR_SEED_FILE := $(subst $\",,$(CONFIG_EFI_VAR_SEED_FILE)) diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 61dc72a23da8..ceca5c5b1bf3 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -348,8 +349,11 @@ efi_status_t efi_bootmgr_load(efi_handle_t *handle, void **load_options) log_debug("%s trying to load Boot%04X\n", __func__, bootorder[i]); ret = try_load_entry(bootorder[i], handle, load_options); - if (ret == EFI_SUCCESS) + if (ret == EFI_SUCCESS) { + if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) + ret = efi_initrd_register(); break; + } } free(bootorder); diff --git a/lib/efi_loader/efi_load_initrd.c b/lib/efi_loader/efi_load_initrd.c index d517d686c330..984fea1bd679 100644 --- a/lib/efi_loader/efi_load_initrd.c +++ b/lib/efi_loader/efi_load_initrd.c @@ -10,7 +10,9 @@ #include #include #include +#include #include +#include static const efi_guid_t efi_guid_load_file2_protocol = EFI_LOAD_FILE2_PROTOCOL_GUID; @@ -45,40 +47,7 @@ static const struct efi_initrd_dp dp = { }; /** - * get_file_size() - retrieve the size of initramfs, set efi status on error - * - * @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 - * - * Return: size of file - */ -static loff_t get_file_size(const char *dev, const char *part, const char *file, - efi_status_t *status) -{ - loff_t sz = 0; - int ret; - - ret = fs_set_blk_dev(dev, part, FS_TYPE_ANY); - if (ret) { - *status = EFI_NO_MEDIA; - goto out; - } - - ret = fs_size(file, &sz); - if (ret) { - sz = 0; - *status = EFI_NOT_FOUND; - goto out; - } - -out: - return sz; -} - -/** - * 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. @@ -98,21 +67,14 @@ 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 load_file_info info; 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; @@ -130,24 +92,11 @@ efi_load_file2_initrd(struct efi_load_file_protocol *this, 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) - goto out; - part = strsep(&pos, " "); - if (!part) - goto out; - file = strsep(&pos, " "); - if (!file) + status = efi_get_fp_from_var(L"Initrd####", 6, &info); + if (status != EFI_SUCCESS) goto out; - file_sz = get_file_size(dev, part, file, &status); + file_sz = get_file_size(&info, &status); if (!file_sz) goto out; @@ -155,23 +104,25 @@ efi_load_file2_initrd(struct efi_load_file_protocol *this, status = EFI_BUFFER_TOO_SMALL; *buffer_size = file_sz; } else { - ret = fs_set_blk_dev(dev, part, FS_TYPE_ANY); + ret = fs_set_blk_dev(info.dev, info.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) + ret = fs_read(info.filename, map_to_sysmem(buffer), 0, + *buffer_size, &read_sz); + if (ret || read_sz != file_sz) { + status = EFI_DEVICE_ERROR; goto out; + } *buffer_size = read_sz; status = EFI_SUCCESS; } out: - free(filespec); return EFI_EXIT(status); } @@ -189,6 +140,15 @@ efi_status_t efi_initrd_register(void) { efi_handle_t efi_initrd_handle = NULL; efi_status_t ret; + struct load_file_info info; + + ret = efi_get_fp_from_var(L"Initrd####", 6, &info); + /* + * Don't fail here. If we don't register the protocol the efi-stub will + * try to load and initrd parsing the kernel cmdline + */ + if (ret != EFI_SUCCESS) + return EFI_SUCCESS; ret = EFI_CALL(efi_install_multiple_protocol_interfaces (&efi_initrd_handle, From patchwork Mon Dec 28 12:24:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 352614 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp9706156jai; Mon, 28 Dec 2020 04:25:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJwlrMgZHUXcP5mBsipk9c/HSg8LkrB/OizyQNvHuT1tIOQBYlIGtRJ3iBubhfSFOw10fxEB X-Received: by 2002:aa7:c253:: with SMTP id y19mr41470894edo.179.1609158337631; Mon, 28 Dec 2020 04:25:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609158337; cv=none; d=google.com; s=arc-20160816; b=VynnK7gPhV9dUIZquqBWnhWJW/jCGMZT3idUz5g3/Z5p4VdhfD//p6s9IpzVmRHgEV RvFiPly7iNgh76G8pSpMbXCmS5npLobPDv50Rjm/BWblFj/SVRrsgqNI3dc1dW01nGtQ t2K9Kc0v0GM9IMjE5qfdBkDSOqU0IQTWyuRwKJjqbsu0Pam8hkXlzpvLqSqZro/uGdxU gd0TRM8uJt1bshVgDINsCfGwie5zNOEg0mz15JK9QKYVVoBMfqaISe8OFYDOH5pFN6fH cCGt1kxns3uBydhNJVOldSZhzovDJSay3OyQt1SkpHoQA6i+IgI/0T7OQQJIadNOFLzJ wBwg== 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=o9AApdU48nlO5j2H22jA8ro8KOPJxly2NBQNkuXQdxg=; b=jDPJuAQpB9y8SVYwhxhxwns3YyQF4Rk3BPYKxy8lThwz9AFrfR5tSYebzYFh23ssyn CVYed2XEG0q0XwE6n56a9LfFl/bE+djHEViTghz1Rox01v8uPB/NzmNp50pLO0I1Harh VpGHaHe0xXayl3RzmrZxax89NBuGucMKqMLvQhoF/uu1xz3m2MxCku/hIeU4M+31ewEn jzSHiqq3dMT6/g82OKbuLgcnM0oSwqiW2ur2kHS/WR6B/Onb6YthlsQCJGvmZTPCmCwt LxUGvS4oVFG19ceQSfUe1eHP2bz657/S+wiZHY25q/ySvuIVDB22ldMK0gWDnzC+bBg4 MdSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nVW68o+k; 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 l18si18163560eje.178.2020.12.28.04.25.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 04:25:37 -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=nVW68o+k; 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 AACA382563; Mon, 28 Dec 2020 13:25:13 +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="nVW68o+k"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A2EC282540; Mon, 28 Dec 2020 13:24:58 +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,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) (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 3B059823D3 for ; Mon, 28 Dec 2020 13:24: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-wm1-x329.google.com with SMTP id r4so9659921wmh.5 for ; Mon, 28 Dec 2020 04:24: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=o9AApdU48nlO5j2H22jA8ro8KOPJxly2NBQNkuXQdxg=; b=nVW68o+kMUf1j1dNNKfBED0qv8HY3ouSQ9THYrugvhD1pFdEpcqY+trr6Q8KFpbE38 Jo2Sz2WIUPvMEV8TMu6t9z9FYjzilneqeBaXixF9mmeIZcymakRcbj8RrgSyN8GLzqjr t4oWAIAJB1X3soHIcdHvmbG5L+P+EW706nWsSvhSUDQdILPiSdnujEpRwdUtbXqpFoDQ f3X/7k2EEHKfKJYnyPDnj1OAlBYUgyQwniglpkbNzTQ+MVc9ghDxcZFOdiJfUm+oPZL9 zJC6+wOMKoaOP+bD1JblTSQrDJZ3zw9J588fawzkdllayIFXhkLJhtmMYF2dqM1aaJs5 fKmA== 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=o9AApdU48nlO5j2H22jA8ro8KOPJxly2NBQNkuXQdxg=; b=Q3lHDg4fM2W5T/eiAp/LDJtqcy/g4jH/dIZp6H3KrC+kvSiFiVdMIG6882L6Pt4lXh J5X80DrepEsJMKe60DZUrvv8rvc6bndlcoX8u5FbTKpLEWBv1GhAEERCytIUmllidIA/ Rc/J0TZtFanjo2N21uMNE0H92RqdE8D0kJlrCCjV5WaYnTxtVenVtJOynFNkk3Z/ivf4 p0s0z/XdupdX8l50NqXujaeIWnrXcH7ckyJqQpP4y7SGBFM7p/KKeIbu+0bvlpMoYnyx zEELAwb5w0XJe4FcIIMCm+8gKaN7w1gJztTM6Og3K+RnCwOYsQ0vC7TwJI/WPblSOLed 4bJA== X-Gm-Message-State: AOAM5332V0TTyK724qbczU4nDlsV8g7nW0UIcCDHHQCRIBXLaBr9fVX4 v1Vik96yTWnIchpEohiLftcrhQ== X-Received: by 2002:a1c:a9cc:: with SMTP id s195mr20342984wme.97.1609158293845; Mon, 28 Dec 2020 04:24:53 -0800 (PST) Received: from localhost.localdomain (athedsl-4484548.home.otenet.gr. [94.71.57.204]) by smtp.gmail.com with ESMTPSA id w21sm18710321wmi.45.2020.12.28.04.24.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 04:24:53 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, ard.biesheuvel@arm.com, Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH 4/6] efi_loader: Remove unused headers from efi_load_initrd.c Date: Mon, 28 Dec 2020 14:24:36 +0200 Message-Id: <20201228122440.316403-5-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0.rc2 In-Reply-To: <20201228122440.316403-1-ilias.apalodimas@linaro.org> References: <20201228122440.316403-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.3 at phobos.denx.de X-Virus-Status: Clean dm.h and env.h serve no purpose here. Remove them Signed-off-by: Ilias Apalodimas --- lib/efi_loader/efi_load_initrd.c | 2 -- 1 file changed, 2 deletions(-) -- 2.30.0.rc2 diff --git a/lib/efi_loader/efi_load_initrd.c b/lib/efi_loader/efi_load_initrd.c index 984fea1bd679..e0b4a82ce037 100644 --- a/lib/efi_loader/efi_load_initrd.c +++ b/lib/efi_loader/efi_load_initrd.c @@ -4,10 +4,8 @@ */ #include -#include #include #include -#include #include #include #include From patchwork Mon Dec 28 12:24:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 352615 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp9706245jai; Mon, 28 Dec 2020 04:25:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJz7iz2ZObU3weHWS1AaIH0p08b/CFdD5LaO4EY8yBexo/GtsKPtstwzxfPoqxeWn7PRjQHp X-Received: by 2002:a17:906:7687:: with SMTP id o7mr42195724ejm.209.1609158348718; Mon, 28 Dec 2020 04:25:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609158348; cv=none; d=google.com; s=arc-20160816; b=MjCDJshGANzB3RhJ3jlQt7hjTkp1wXoSU4SG6mLD/K9AueCpzXYnFHBjueC8ySdK9x QqltScidXUzAgVrRJFqZNDEG3KYHKPJaiwZpLTwabeKHOE+l9HZSTdwcJtU7h/XIoWJ+ HZ3JbrMvUWVkiiO+fXrXYkUR978QOduhgrnkb67vlQCHMcisjxnvsmO1lMUJ4fbPFq4v k+P4O2RNaAws6vPpeRUDK/ZmT0QoNDoRnMyzCJgc9Q7t7YZzhD7gbB8Idnd8xbbBuLu7 z4UDEtEqATq9SazUeXDyV1+Di6wrpg1r7PCKwixdQbQns7808zZ//0NBjD46gJtHqhL/ gz4Q== 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=3mRX3QJWmggl7OcQfkZb7kTWFb0Bs9EjftYpPbz50xA=; b=sfw/PhkBvx8oqo9lrlLOB32InV7JHiNsaKcqfZiJLlYh1oE8OnoZ33yyFwy/Hpj3Gy VE/WPS0LlEnf1PS6zN3HSl7bfiBNo2Ap8eS21XPeZ+GGTitXO0jmmOKaLdbi8vtYp6b9 qF6uLRUGwzuxcEI+5SlndzOknEuJOyywsu5I0/hck9ZQJtoU9WTW7E1HyJVnhbJSVNhR 4Oc2SBV3hoytgBpXy67tPNuClnnTDHp2Jei454opBdq05xY0ydvlbIQt88KP9pwTOEJc MvG42ecjIXLkX3c9FMTJraiCiOhYc33A+AMPYRUdLjGiFuNocjBdXPudP55+n1Czbu0N gZ0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NJa5RadH; 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 z21si21385695edr.365.2020.12.28.04.25.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 04:25:48 -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=NJa5RadH; 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 1F37B82540; Mon, 28 Dec 2020 13:25: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="NJa5RadH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 38CA58244B; Mon, 28 Dec 2020 13:25:04 +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,RCVD_IN_DNSWL_NONE,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 D9D30824C4 for ; Mon, 28 Dec 2020 13:24:56 +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 m5so11148252wrx.9 for ; Mon, 28 Dec 2020 04:24:56 -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=3mRX3QJWmggl7OcQfkZb7kTWFb0Bs9EjftYpPbz50xA=; b=NJa5RadHr4ifN7hgPtNslUxgjza/i982G3XtRNyR9vw4o98nFfaD+pOMo0CwPT27QG 6e+g+FuA8a3ttcHoJezEh5KcksjeVyPgEQaJm8Srm8B2cy4MOzVWos2PMHdiF7H9fy3e zw71aKWdaXPNYsemag6G1caFSIxxCZ178Ab/ShU8WfeymLNiQBDtNO3lVi/zoEvE8zsZ GR6aAStP4LV6hCHZWd927Yvx/kD92Sars5BZM6+pPufVJskYN6PgDXTbh6MKcRPiCp6E kQUdXdnyDFiaAC4fPgu2+AZT16YelsVQP/u7cfJDLm3KdRldVHHi2p8bBXedJCxDCF6U 297Q== 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=3mRX3QJWmggl7OcQfkZb7kTWFb0Bs9EjftYpPbz50xA=; b=c5PO+7Oz5g+d/GI/PLJS2r/8T2aGOE7BkqoXFmjcVfYoB5hZqyMm8Kib2xADULCXsr 4/yIPKk07YL3We7V/8cd8PQ894TJjWF+eQyE4ojP2y51EE2YgJ/5tfoLAtcNciM8THnt O9libsmP69TAXb8mg8V5YMfL22K+zceYSc0c3Q4BvYdMCIdXEtTCORPdBaxyyj34J4kg Dcjrf6sDLuvO+ZNcm3vKeZW6RHdzJx0dOBvCG9DO4j1YKAK33HdSWUxo627jgPUd8BBw vP6jzRZ4SmhmCMmtAT29dMS0aOyqNWlVzZiJcMVO9rrV0py5JhNiX1/prsF12JSKdSzR IP9A== X-Gm-Message-State: AOAM532VqZK5BVBoQTNVEqXrJF1F/pQh3V5wI4QOa2RML0i9vEPuStJm N6qVcKt2v+tsrzjEqwS8o8WoDg== X-Received: by 2002:adf:fd05:: with SMTP id e5mr51180211wrr.225.1609158296494; Mon, 28 Dec 2020 04:24:56 -0800 (PST) Received: from localhost.localdomain (athedsl-4484548.home.otenet.gr. [94.71.57.204]) by smtp.gmail.com with ESMTPSA id w21sm18710321wmi.45.2020.12.28.04.24.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 04:24:56 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, ard.biesheuvel@arm.com, Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH 5/6] efi_selftest: Modify self-tests for initrd loading Date: Mon, 28 Dec 2020 14:24:37 +0200 Message-Id: <20201228122440.316403-6-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0.rc2 In-Reply-To: <20201228122440.316403-1-ilias.apalodimas@linaro.org> References: <20201228122440.316403-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.3 at phobos.denx.de X-Virus-Status: Clean Previous patches change the logic of the initrd discovery and the registration of the protocol. Instead of a config now option it now resides in an EFI variable. Adjust the instructions of execution accordingly and add new self-tests which will cover the new functionality. Signed-off-by: Ilias Apalodimas --- lib/efi_selftest/efi_selftest_load_initrd.c | 90 ++++++++++++++++++++- 1 file changed, 88 insertions(+), 2 deletions(-) -- 2.30.0.rc2 diff --git a/lib/efi_selftest/efi_selftest_load_initrd.c b/lib/efi_selftest/efi_selftest_load_initrd.c index fe060a664402..85afed55425f 100644 --- a/lib/efi_selftest/efi_selftest_load_initrd.c +++ b/lib/efi_selftest/efi_selftest_load_initrd.c @@ -14,10 +14,12 @@ * * CONFIG_EFI_SELFTEST=y * CONFIG_EFI_LOAD_FILE2_INITRD=y - * CONFIG_EFI_INITRD_FILESPEC="host 0:1 initrd" * - * * Run ./u-boot and execute + * * Create files + * mkdir init_test && cp initrd init_test/ + * virt-make-fs -t ext4 init_test test.img * + * * Run ./u-boot and execute * host bind 0 image * setenv efi_selftest load initrd * bootefi selftest @@ -43,6 +45,7 @@ #include static struct efi_boot_services *boottime; +static struct efi_runtime_services *runtime; static struct efi_initrd_dp dp = { .vendor = { @@ -80,6 +83,7 @@ static int setup(const efi_handle_t handle, const struct efi_system_table *systable) { boottime = systable->boottime; + runtime = systable->runtime; return EFI_ST_SUCCESS; } @@ -87,6 +91,7 @@ static int setup(const efi_handle_t handle, static int execute(void) { efi_guid_t lf2_proto_guid = EFI_LOAD_FILE2_PROTOCOL_GUID; + efi_guid_t efi_global_variable_guid = EFI_GLOBAL_VARIABLE_GUID; struct efi_load_file_protocol *lf2; struct efi_device_path *dp2, *dp2_invalid; efi_status_t status; @@ -95,8 +100,89 @@ static int execute(void) efi_uintn_t buffer_size; void *buf; u32 crc32; + u16 boot_current = 0; + efi_uintn_t boot_current_size = sizeof(boot_current); + char path[] = "host 0 initrd"; + char invalid_path[] = "host 1 initrd"; + efi_uintn_t path_size = sizeof(path); + efi_uintn_t invalid_path_size = sizeof(invalid_path); + u32 attrs = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS; memset(buffer, 0, sizeof(buffer)); + /* Set variable BootCurrent and Initrd#### to a wrong value */ + status = runtime->set_variable(L"BootCurrent", &efi_global_variable_guid, + attrs, boot_current_size, &boot_current); + if (status != EFI_SUCCESS) { + efi_st_error("SetVariable for BootCurrent failed\n"); + return EFI_ST_FAILURE; + } + + /* + * We don't need NV for Initrd here. + * Set the file to an invalid file path + */ + status = runtime->set_variable(L"Initrd0010", &efi_global_variable_guid, + attrs, invalid_path_size, invalid_path); + if (status != EFI_SUCCESS) { + efi_st_error("SetVariable for Initrd failed\n"); + return EFI_ST_FAILURE; + } + + /* We only register the protocol during efibootmgr */ + status = efi_initrd_register(); + if (status != EFI_SUCCESS) { + efi_st_error("Failed to register initrd protocol\n"); + return EFI_ST_FAILURE; + } + + /* + * We should only register the protocol if the file's found + * Right now both BootCurrent and file path are invalid + */ + dp2 = (struct efi_device_path *)&dp; + status = boottime->locate_device_path(&lf2_proto_guid, &dp2, &handle); + if (status != EFI_NOT_FOUND) { + efi_st_error("Initrd protocol should't be registered\n"); + return EFI_ST_FAILURE; + } + + /* Update BootCurrent to the correct value */ + boot_current = 0x0010; + status = runtime->set_variable(L"BootCurrent", &efi_global_variable_guid, + attrs, boot_current_size, &boot_current); + if (status != EFI_SUCCESS) { + efi_st_error("SetVariable for BootCurrent failed\n"); + return EFI_ST_FAILURE; + } + + /* re-register with invalid file path */ + status = efi_initrd_register(); + if (status != EFI_SUCCESS) { + efi_st_error("Failed to register initrd protocol\n"); + return EFI_ST_FAILURE; + } + + /* file path is invalid */ + dp2 = (struct efi_device_path *)&dp; + status = boottime->locate_device_path(&lf2_proto_guid, &dp2, &handle); + if (status != EFI_NOT_FOUND) { + efi_st_error("Initrd protocol should't be registered\n"); + return EFI_ST_FAILURE; + } + + /* re-register with correct values now */ + status = runtime->set_variable(L"Initrd0010", &efi_global_variable_guid, + attrs, path_size, path); + if (status != EFI_SUCCESS) { + efi_st_error("SetVariable for Initrd failed\n"); + return EFI_ST_FAILURE; + } + + status = efi_initrd_register(); + if (status != EFI_SUCCESS) { + efi_st_error("Failed to register initrd protocol\n"); + return EFI_ST_FAILURE; + } dp2 = (struct efi_device_path *)&dp; status = boottime->locate_device_path(&lf2_proto_guid, &dp2, &handle); From patchwork Mon Dec 28 12:24:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 352616 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp9706330jai; Mon, 28 Dec 2020 04:25:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJyJVCD1tjZ2LHdMotaa0NNW44PE0SJsLWmOeajaJj82evHvJj4EssIjv6c6O5JbUj/Fd6e8 X-Received: by 2002:a17:906:add7:: with SMTP id lb23mr43510703ejb.352.1609158358656; Mon, 28 Dec 2020 04:25:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609158358; cv=none; d=google.com; s=arc-20160816; b=nt420MjMxh7f94B5A5Y8tor798IOX1zsKLzu7x7jPr7QPb0ATFMaD0Vm60YRewDrlc seWSWAZZG0baum8bInWoLZejTSjZgRagjABcUV3DugbuHb1ChLoCwWp5NHdSrLOKTx99 EfIs1r0w+1coWIk+FESCzttXE82k3O8e+vUrbD5KHF57gfCo3k4qrg4Y/8lhhHaHUDTt Fhjnj40+40Tu4LKb7mW2hkKOszcfwFIFF6XjUXmPBjmPomQqpJlco+ojEof+atzmn/SL KluZPJ1K3hu8WaG7d3RVxI8K8ggOIKSjFZVLiI8IaaEmELbVRYo/2FPlC5RxnEwpvdue VTGA== 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=yV7N0Ok1zSV8fDFf6PB/WUDGRTJRez5FG/AXMRuxEEc=; b=cKlWmx8vbpDvoZTMPZDvx4fLcc3Nyf4c8h9Inj5knIQG77QczHjj+xwyMYDG46cz7A EsNgLEgPXSBaVy2E06fObz7V1jNlZMoQmLSpGO/SBWt87JgEJHmVJNhJcDA1avxJo83i 1ikgKoCms0NlGWgKGTMYoPaULMYiLwmDb2tn3SLfm7EaYTGEIyBJb3Hf24lQcvIE6i4d sG16NTs8qQf5khKU87TfjkDFXzcXssMYPArW4dcCqm11QVNDPizRy8uwCvYy6fRId/ae vVk4lMo5hUZYr7i9z+Ikyd+MQkfpfgWobO3J6p8BK/n2DUpd2x7ZCKAd8BKsIdHodbXZ WtmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zvczVNbV; 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 cq3si20245382edb.72.2020.12.28.04.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 04:25:58 -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=zvczVNbV; 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 BB8FE8257F; Mon, 28 Dec 2020 13:25:24 +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="zvczVNbV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BF803824C4; Mon, 28 Dec 2020 13:25:05 +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,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) (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 9D356823D3 for ; Mon, 28 Dec 2020 13:24:59 +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-x32b.google.com with SMTP id c133so10236270wme.4 for ; Mon, 28 Dec 2020 04:24:59 -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=yV7N0Ok1zSV8fDFf6PB/WUDGRTJRez5FG/AXMRuxEEc=; b=zvczVNbVBskd5q9UG++mRUa68AkssOo6rSSZLdLXryeBY2kTjeX7aAIVMy1Eg80I+9 GcHUm1ci/NBDzWUzKhi8sSy6UNnWSJ5G+zGnfa5IvrO8avnzajbDre5oExPfCgzWwZL/ ouLBZrcMAfmtVXIKN9PiEoFoNqiKJTFG+fBL7YN2E2Anlzsdof1Rpe53W79DZXQU5psO bRLP3vTp3GCWcmW8HVQPtXKu5eq03s13hk3PQ5/QHRxtA2vl1ovHJF1Ja+AZODb9fpmN WZkqwJtBw5csBx8KGfkKD7teEQzavuIi99SdTFRIQYAebN6fwiVjI4qhbOuQHkxxL6NC j7lQ== 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=yV7N0Ok1zSV8fDFf6PB/WUDGRTJRez5FG/AXMRuxEEc=; b=lWDniSCxpJevHptUtc/+Ep5LQqgCbkzUFrYAXyBZz+gIiUeeAgXclf95KiWmK1pW3w /MX2P5Lne6XYmboSY/kCu6qhFfdDF7bIL0j2RJhxV3txf6U+KkNDHmjFBAaokI1B9uhe vihDpO4yf/KRGs1x3Bm92BRnPy2EgzU5rnE58wERNVZleIzGJvqnbnb0To3BoVO5oDD5 pvB3Kmb4BonK3o5tZ8KiB3N7eorloo7YpQFgZYuSJfWy+cSa5WXaupuwjcLpCju5/S+5 +hJDXr8wg/jBRlZyELkpE+dtgjcWoywKAPSNPaDm2DNTvaFxP/GnwxWNPT6Oa3P/GmH7 4TKQ== X-Gm-Message-State: AOAM530QfxKNOuIInEHdkiJ5d8o1sRazAKsFPzIYFis1UB78RnZIsQdF RFNGw/s5lnKJyO1pFfsb42Ol+lePXqZsmZXh X-Received: by 2002:a7b:c7d3:: with SMTP id z19mr20613781wmk.31.1609158299180; Mon, 28 Dec 2020 04:24:59 -0800 (PST) Received: from localhost.localdomain (athedsl-4484548.home.otenet.gr. [94.71.57.204]) by smtp.gmail.com with ESMTPSA id w21sm18710321wmi.45.2020.12.28.04.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 04:24:58 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, ard.biesheuvel@arm.com, Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH 6/6] efi_loader: bootmgr: use get_var from efi_helper file Date: Mon, 28 Dec 2020 14:24:38 +0200 Message-Id: <20201228122440.316403-7-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0.rc2 In-Reply-To: <20201228122440.316403-1-ilias.apalodimas@linaro.org> References: <20201228122440.316403-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.3 at phobos.denx.de X-Virus-Status: Clean A few patches before we introduced a file which includes the get_var() function defined in the efi bootmanager. So let's replace it here and use the common function as much as we can. Signed-off-by: Ilias Apalodimas --- lib/efi_loader/Makefile | 2 +- lib/efi_loader/efi_bootmgr.c | 33 +-------------------------------- 2 files changed, 2 insertions(+), 33 deletions(-) -- 2.30.0.rc2 diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index 793e5b7f8730..d21d57d5811e 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -21,7 +21,7 @@ targets += helloworld.o endif obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o -obj-y += efi_bootmgr.o +obj-y += efi_helper.o efi_bootmgr.o obj-y += efi_boottime.o obj-y += efi_console.o obj-y += efi_device_path.o diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index ceca5c5b1bf3..a175842ae053 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -166,38 +167,6 @@ unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data) return size; } -/** - * get_var() - get UEFI variable - * - * It is the caller's duty to free the returned buffer. - * - * @name: name of variable - * @vendor: vendor GUID of variable - * @size: size of allocated buffer - * Return: buffer with variable data or NULL - */ -static void *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); - ret = efi_get_variable_int(name, vendor, NULL, size, buf, NULL); - } - - if (ret != EFI_SUCCESS) { - free(buf); - *size = 0; - return NULL; - } - - return buf; -} - /** * try_load_entry() - try to load image for boot option *