From patchwork Tue Nov 21 01:29:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 745669 Delivered-To: patch@linaro.org Received: by 2002:a5d:5052:0:b0:32d:baff:b0ca with SMTP id h18csp1627948wrt; Mon, 20 Nov 2023 17:31:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IHuUKgNvpLY4MW5Hx4NfgGgchhmCpxV1gCHTGtP7pWwj9KKq7KasIC8CUzWSHcYHMUvdhsH X-Received: by 2002:a17:906:d54b:b0:9fa:d1df:c2c4 with SMTP id cr11-20020a170906d54b00b009fad1dfc2c4mr1268137ejc.36.1700530307657; Mon, 20 Nov 2023 17:31:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700530307; cv=none; d=google.com; s=arc-20160816; b=oRJWJc7xZAoUfoFNMytZJK+2q4KBsf41QRGs/mmWHLeaoszNfIc8MpPVEilDVk5X9G w6onRS9FvnywzIDcBdq7RjvtZrIqN6eh/OFhTFzJktOVMOe0xT+/1cOSRQvt0ZoN3zVk 7aJh+PDXluGPq4poCtEwh0w1ItSO+8XBbxxdwYBq+YjjsrduCWvSeugJw9Iu3gSUrnwI FSpTtclsNE4jEc+Kg01bN+BbFtw4NdEBQgTIyNovGdykd029kqTta7QuUGFqNOMtht8g KJcFh8kXI3IVAg2eJ0EJI/OgMXe5k+C751up5XaUQraRLwAdGdFGgBXX/RkrccjKaL1C O9FA== 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=J0WEP5AXjHAZm/oKDWY7reBF0PdcawUlf+/Ln7Vx3Gk=; fh=p8OTi/tJSbfUA0ykVxDxRCnpqUhQqJazFYHXT9edm5U=; b=pFjmWaX55K+QvnRhe82POTg2GGr+QaWVue32VspAvF+of3fXL+eFQkklpM0erTGUqJ YUXPF0EoIasgMb+1qRenlK5b6a6aVJSuEF7QP7JIOgae7oVuLpVCacqWpW3y22Ur0pQU ezwKX/nvnT1RFyWHuURWlliCsCrBqQZHmOnbXExIkvrCXQ7WIjh3WX9DuLaQcaVMU09P kssPTUENjgY9Lhepphxgat6G8Eg05MED73sFi9JlcBG7IqBX6qdtGRweQQ9aJFHl31ke ndc/UwgNYFR1XSJbLlmdiHvIEHvKQS6j52V404zVuV/RLrxn34d3C2E2SbjjJGaYzbgh sB5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tdSWpJjR; 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 jg4-20020a170907970400b009b953b4b961si5347635ejc.189.2023.11.20.17.31.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:31:47 -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=tdSWpJjR; 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 436458759F; Tue, 21 Nov 2023 02:30:45 +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="tdSWpJjR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0D70187594; Tue, 21 Nov 2023 02:30:42 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0: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 58F9687574 for ; Tue, 21 Nov 2023 02:30:35 +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=takahiro.akashi@linaro.org Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1ca85ff26afso8802145ad.1 for ; Mon, 20 Nov 2023 17:30:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700530234; x=1701135034; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=J0WEP5AXjHAZm/oKDWY7reBF0PdcawUlf+/Ln7Vx3Gk=; b=tdSWpJjRI5jbe3xbYk9NXBQiiDoyvfF8Tjb+eec8xrvTy1GgqnMZtuyTjzdSonzHHg A/rHy5hn3X9hMdf++t3cnIZiI967xrmXzhA1aOJA2RcLEqmry7at+zt6ta8cGTbKs05x YW+u5wTFYGTpQx/ggk0ntAEGxNSSiIX1r9EVQg8tIM0gRqT1bZKVlJn/amneygHd8Bhj V/rUbydj27HUXhy6pPdFo+N0Z+tHJni07VuOl1Kn3oDM7pKs5eakHJov9jlOKp+YezEh 94k1v/xAtT59ryH2UM/50blqpTmdHjQn1lRIlfILnsNtwutVRCa0Qpg40I7VIwJ1u2aa +Mpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700530234; x=1701135034; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J0WEP5AXjHAZm/oKDWY7reBF0PdcawUlf+/Ln7Vx3Gk=; b=ZnIrLq7+3vR80+YoS4875cqHmzKaDxvasLpBGA63jdt4zPFn64xPjrmAdE3XOlaWVo agNLvyh2i/vx/OvejFDwSiQF0vyiR9ZyITq2GL5D0Y875jz4OxQ469BqKlowPpxFRBeR zcBgsm3xV3kCjsxLJwDATmwoI8yxgaX5mjaQq0r7HPuVguumqQgnQS/O62RQAdxFqYYA qsCEJKaBS8LggaACeBZHDpFDrMFfAjaO5gvJrvdSY3zKmCgxkoKQ4ygcIyosPKjisIZF 7OIK5sXKFqc3xm2ZBoVH5Rp0PGdQX3BdRWYVuw/846QrveSv4ecAcLhOAgCfldCOxpXF Ilag== X-Gm-Message-State: AOJu0Yw9AdlvCDkmDlzeZNtTXdMnemXhQPOZbqujc5JcmoNNgQdL19VF vWlBJya2ALfyBQ6KIOoGeBQfOw== X-Received: by 2002:a17:902:e749:b0:1ce:63bf:e4c9 with SMTP id p9-20020a170902e74900b001ce63bfe4c9mr11604986plf.0.1700530233602; Mon, 20 Nov 2023 17:30:33 -0800 (PST) Received: from octopus.. ([2400:4050:c3e1:100:f6af:a59c:7ca:897f]) by smtp.gmail.com with ESMTPSA id e9-20020a170902d38900b001c8a0879805sm3612508pld.206.2023.11.20.17.30.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:30:33 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org, xypron.glpk@gmx.de, ilias.apalodimas@linaro.org Cc: u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v2 01/12] cmd: bootefi: unfold do_bootefi_image() Date: Tue, 21 Nov 2023 10:29:39 +0900 Message-Id: <20231121012950.156539-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121012950.156539-1-takahiro.akashi@linaro.org> References: <20231121012950.156539-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean Unfold do_bootefi_image() into do_bootefi() in order to make it easier to re-organize do_bootefi() in the next commit. Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 101 ++++++++++++++++++-------------------------------- 1 file changed, 37 insertions(+), 64 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 4d74969ad621..190ccba260e0 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -437,58 +437,6 @@ static int do_efibootmgr(void) return CMD_RET_SUCCESS; } -/** - * do_bootefi_image() - execute EFI binary - * - * Set up memory image for the binary to be loaded, prepare device path, and - * then call do_bootefi_exec() to execute it. - * - * @image_opt: string with image start address - * @size_opt: string with image size or NULL - * Return: status code - */ -static int do_bootefi_image(const char *image_opt, const char *size_opt) -{ - void *image_buf; - unsigned long addr, size; - efi_status_t ret; - -#ifdef CONFIG_CMD_BOOTEFI_HELLO - if (!strcmp(image_opt, "hello")) { - image_buf = __efi_helloworld_begin; - size = __efi_helloworld_end - __efi_helloworld_begin; - efi_clear_bootdev(); - } else -#endif - { - addr = strtoul(image_opt, NULL, 16); - /* Check that a numeric value was passed */ - if (!addr) - return CMD_RET_USAGE; - image_buf = map_sysmem(addr, 0); - - if (size_opt) { - size = strtoul(size_opt, NULL, 16); - if (!size) - return CMD_RET_USAGE; - efi_clear_bootdev(); - } else { - if (image_buf != image_addr) { - log_err("No UEFI binary known at %s\n", - image_opt); - return CMD_RET_FAILURE; - } - size = image_size; - } - } - ret = efi_run_image(image_buf, size); - - if (ret != EFI_SUCCESS) - return CMD_RET_FAILURE; - - return CMD_RET_SUCCESS; -} - /** * efi_run_image() - run loaded UEFI image * @@ -660,8 +608,9 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { efi_status_t ret; - char *img_addr, *img_size, *str_copy, *pos; - void *fdt; + char *p; + void *fdt, *image_buf; + unsigned long addr, size; if (argc < 2) return CMD_RET_USAGE; @@ -696,18 +645,42 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc, if (!strcmp(argv[1], "selftest")) return do_efi_selftest(); #endif - str_copy = strdup(argv[1]); - if (!str_copy) { - log_err("Out of memory\n"); - return CMD_RET_FAILURE; + +#ifdef CONFIG_CMD_BOOTEFI_HELLO + if (!strcmp(argv[1], "hello")) { + image_buf = __efi_helloworld_begin; + size = __efi_helloworld_end - __efi_helloworld_begin; + efi_clear_bootdev(); + } else +#endif + { + addr = strtoul(argv[1], NULL, 16); + /* Check that a numeric value was passed */ + if (!addr) + return CMD_RET_USAGE; + image_buf = map_sysmem(addr, 0); + + p = strchr(argv[1], ':'); + if (p) { + size = strtoul(++p, NULL, 16); + if (!size) + return CMD_RET_USAGE; + efi_clear_bootdev(); + } else { + if (image_buf != image_addr) { + log_err("No UEFI binary known at %s\n", + argv[1]); + return CMD_RET_FAILURE; + } + size = image_size; + } } - pos = str_copy; - img_addr = strsep(&pos, ":"); - img_size = strsep(&pos, ":"); - ret = do_bootefi_image(img_addr, img_size); - free(str_copy); + ret = efi_run_image(image_buf, size); - return ret; + if (ret != EFI_SUCCESS) + return CMD_RET_FAILURE; + + return CMD_RET_SUCCESS; } U_BOOT_LONGHELP(bootefi, From patchwork Tue Nov 21 01:29:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 745670 Delivered-To: patch@linaro.org Received: by 2002:a5d:5052:0:b0:32d:baff:b0ca with SMTP id h18csp1628075wrt; Mon, 20 Nov 2023 17:32:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEgu1fmGN5UBSHm51qAcDDghuq5u5jDgbUhEEhUdG4G+5JMtoMDJGgQiQYcr7+G7n2hWTIt X-Received: by 2002:a05:6402:12d6:b0:541:29c8:9575 with SMTP id k22-20020a05640212d600b0054129c89575mr728995edx.28.1700530334393; Mon, 20 Nov 2023 17:32:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700530334; cv=none; d=google.com; s=arc-20160816; b=R7mm5FnPRP6ymzx5oGef/PHKMmTuuY1zU3ScBM3lmAE6DTRLt6WXUVYgayhtClAFmB JyN6FP6mm15CjcwCGt79KWkMizi5wHUt+FtEeG3emifFq0ruVfststEsCr4znH6SJecW FiK58SVVeC7YfZOEd6pUy+EX/aYbojaUPu2SJDiXOE3IPOMuNIfu5n3JJ8Lv9wYl5DNT 7DkX+nGc3So6GNo6Qi6xZ4tG0H9u5vZcPKv8oH/hfPCYdpeykJ+flfL6c7hELMEyqlVR A9WIiD/jcpXb6tIqBuBvCVy8nwUUvXinbBSJwvAtjDELkfFxT+twfX7DrpX1y7YVlyTl Oejw== 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=qlJe6g/MGmxeo7thBlyeM3f/K57ZCfoKPQB8Mjgnljw=; fh=p8OTi/tJSbfUA0ykVxDxRCnpqUhQqJazFYHXT9edm5U=; b=ENhjf6GC8ntYMcPwVEq+WDTg1DwRfjq+fib0VFI5ZdfpPfwkwj9uhAOnTw53QqQ+iO 1Jcz77UiM8su9y2vJaF8BT87sxhPM2C2sGDCHhhvmD8EGeNHAl+uC66SKsyNpvU+wqGu gHaePhs8C06GrkJm+Lj6OLCng7Aw9HbquhAPbrXztfMfpKwmg/qG8L6+skT168cnHzRz mw6koKBvrmarPMMOL67GMjVlb3ubIpgJghbA37HzKXxZN1yfFcZilBWkzXF/dCHcjRIN FFH+hyWjqx2GqnaYMyhChzSkTZuVMitYPV5GVjdwl7QkO1kIjHVjyavE1x17jCDuIPCG haww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zjeFWMf1; 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 h11-20020a05640250cb00b005487d701432si3380688edb.492.2023.11.20.17.32.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:32:14 -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=zjeFWMf1; 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 A913D87587; Tue, 21 Nov 2023 02:30:47 +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="zjeFWMf1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E883D87584; Tue, 21 Nov 2023 02:30:45 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) (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 9F4C6863FD for ; Tue, 21 Nov 2023 02:30:37 +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=takahiro.akashi@linaro.org Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1ca85ff26afso8802195ad.1 for ; Mon, 20 Nov 2023 17:30:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700530236; x=1701135036; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qlJe6g/MGmxeo7thBlyeM3f/K57ZCfoKPQB8Mjgnljw=; b=zjeFWMf1r0iWvd9/3/J1j51PADZGHFXZ73yO5I2tTPFzRJPkI8Zx/Sy9iXEeHwdKtX 4uA46QuS0Kd2OyFmsBBAntqi7hRgH2awsdlblUiLDrojI5p47BEnu4ra1zjV2xmTF9nh atZKvHO/1N/xpmVJrXpbdvsh5Eqqu+BSm0keVArygAchHIXwJZk/ZhsbUxmfBs0Wq94e 44zoHS8xbwLBXJwiE7nS4ds0ZBbeJIKjjs4qYuej6R+U7cgpmeQYFLo3xGx7p2ClP7XT sEk8bHC/Cewnge3k7qNJNQgx3jj6WkwsW1dB266FiCvP0A1wV+tgt268tPXeCoyoz2HD QgMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700530236; x=1701135036; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qlJe6g/MGmxeo7thBlyeM3f/K57ZCfoKPQB8Mjgnljw=; b=h8/HlvjdU9GuRWkDYyLYIj1kd7XAUVjeaCGQOBI1Hf8LFf7pSR7VuylxjaLKcDAipL 02rbswBx6DxJ8Loe1ayCse0bgr4kiWs7n2GAZFMrBwKoW45aqdWZY/C+/TGcBvYThb14 e7wHZ85O1hYBvOWUgLFqrIbsb7HXUae05pKQzI+mHKIxCYZVH/lQRUIAhEfdie/tUzla gma1qGII+zErsxuaNHLMtoWPzZrSrzIsr1JxpZqC28mc0bKg3uq4S4KC0Propi8KVK7S KlhA6mAWxlEJTpAseJ3pqoKBqugy5T2BZV8vgFexc7ILCedDnYtHSVxRp9aWX5AZ4u4x olkg== X-Gm-Message-State: AOJu0YywMhKZ0spID0jglvDV3AlWJfZStbj1MJOE3mKs828gk20lpN08 NptYV0inYHFS2BjKTmA6UoKDDg== X-Received: by 2002:a17:902:f691:b0:1cf:55c7:94e9 with SMTP id l17-20020a170902f69100b001cf55c794e9mr8842691plg.2.1700530235763; Mon, 20 Nov 2023 17:30:35 -0800 (PST) Received: from octopus.. ([2400:4050:c3e1:100:f6af:a59c:7ca:897f]) by smtp.gmail.com with ESMTPSA id e9-20020a170902d38900b001c8a0879805sm3612508pld.206.2023.11.20.17.30.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:30:35 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org, xypron.glpk@gmx.de, ilias.apalodimas@linaro.org Cc: u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v2 02/12] cmd: bootefi: re-organize do_bootefi() Date: Tue, 21 Nov 2023 10:29:40 +0900 Message-Id: <20231121012950.156539-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121012950.156539-1-takahiro.akashi@linaro.org> References: <20231121012950.156539-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean Replicate some code and re-organize do_bootefi() into three cases, which will be carved out as independent functions in the next two commits. Signed-off-by: AKASHI Takahiro --- cmd/Kconfig | 15 ++++++-- cmd/bootefi.c | 82 ++++++++++++++++++++++++++++++-------------- include/efi_loader.h | 2 -- 3 files changed, 69 insertions(+), 30 deletions(-) diff --git a/cmd/Kconfig b/cmd/Kconfig index 6f636155e5b6..4cf9a210c4a1 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -362,9 +362,19 @@ config CMD_BOOTEFI help Boot an EFI image from memory. +if CMD_BOOTEFI +config CMD_BOOTEFI_BINARY + bool "Allow booting an EFI binary directly" + depends on BOOTEFI_BOOTMGR + default y + help + Select this option to enable direct execution of binary at 'bootefi'. + This subcommand will allow you to load the UEFI binary using + other U-Boot commands or external methods and then run it. + config CMD_BOOTEFI_BOOTMGR bool "UEFI Boot Manager command" - depends on BOOTEFI_BOOTMGR && CMD_BOOTEFI + depends on BOOTEFI_BOOTMGR default y help Select this option to enable the 'bootmgr' subcommand of 'bootefi'. @@ -373,7 +383,7 @@ config CMD_BOOTEFI_BOOTMGR config CMD_BOOTEFI_HELLO_COMPILE bool "Compile a standard EFI hello world binary for testing" - depends on CMD_BOOTEFI && !CPU_V7M + depends on !CPU_V7M default y help This compiles a standard EFI hello world application with U-Boot so @@ -395,6 +405,7 @@ config CMD_BOOTEFI_HELLO up EFI support on a new architecture. source lib/efi_selftest/Kconfig +endif config CMD_BOOTMENU bool "bootmenu" diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 190ccba260e0..e9e5ab67a1f5 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -503,7 +503,6 @@ out: return (ret != EFI_SUCCESS) ? ret : ret2; } -#ifdef CONFIG_CMD_BOOTEFI_SELFTEST static efi_status_t bootefi_run_prepare(const char *load_options_path, struct efi_device_path *device_path, struct efi_device_path *image_path, @@ -593,7 +592,6 @@ static int do_efi_selftest(void) return ret != EFI_SUCCESS; } -#endif /* CONFIG_CMD_BOOTEFI_SELFTEST */ /** * do_bootefi() - execute `bootefi` command @@ -615,14 +613,6 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc, if (argc < 2) return CMD_RET_USAGE; - /* Initialize EFI drivers */ - ret = efi_init_obj_list(); - if (ret != EFI_SUCCESS) { - log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n", - ret & ~EFI_ERROR_MASK); - return CMD_RET_FAILURE; - } - if (argc > 2) { uintptr_t fdt_addr; @@ -631,29 +621,54 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc, } else { fdt = EFI_FDT_USE_INTERNAL; } - ret = efi_install_fdt(fdt); - if (ret == EFI_INVALID_PARAMETER) - return CMD_RET_USAGE; - else if (ret != EFI_SUCCESS) - return CMD_RET_FAILURE; - if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) { - if (!strcmp(argv[1], "bootmgr")) - return do_efibootmgr(); + if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR) && + !strcmp(argv[1], "bootmgr")) { + /* Initialize EFI drivers */ + ret = efi_init_obj_list(); + if (ret != EFI_SUCCESS) { + log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n", + ret & ~EFI_ERROR_MASK); + return CMD_RET_FAILURE; + } + + ret = efi_install_fdt(fdt); + if (ret == EFI_INVALID_PARAMETER) + return CMD_RET_USAGE; + else if (ret != EFI_SUCCESS) + return CMD_RET_FAILURE; + + return do_efibootmgr(); } -#ifdef CONFIG_CMD_BOOTEFI_SELFTEST - if (!strcmp(argv[1], "selftest")) + + if (IS_ENABLED(CONFIG_CMD_BOOTEFI_SELFTEST) && + !strcmp(argv[1], "selftest")) { + /* Initialize EFI drivers */ + ret = efi_init_obj_list(); + if (ret != EFI_SUCCESS) { + log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n", + ret & ~EFI_ERROR_MASK); + return CMD_RET_FAILURE; + } + + ret = efi_install_fdt(fdt); + if (ret == EFI_INVALID_PARAMETER) + return CMD_RET_USAGE; + else if (ret != EFI_SUCCESS) + return CMD_RET_FAILURE; + return do_efi_selftest(); -#endif + } -#ifdef CONFIG_CMD_BOOTEFI_HELLO - if (!strcmp(argv[1], "hello")) { + if (!IS_ENABLED(CONFIG_CMD_BOOTEFI_BINARY)) + return CMD_RET_SUCCESS; + + if (IS_ENABLED(CONFIG_CMD_BOOTEFI_HELLO) && + !strcmp(argv[1], "hello")) { image_buf = __efi_helloworld_begin; size = __efi_helloworld_end - __efi_helloworld_begin; efi_clear_bootdev(); - } else -#endif - { + } else { addr = strtoul(argv[1], NULL, 16); /* Check that a numeric value was passed */ if (!addr) @@ -675,6 +690,21 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc, size = image_size; } } + + /* Initialize EFI drivers */ + ret = efi_init_obj_list(); + if (ret != EFI_SUCCESS) { + log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n", + ret & ~EFI_ERROR_MASK); + return CMD_RET_FAILURE; + } + + ret = efi_install_fdt(fdt); + if (ret == EFI_INVALID_PARAMETER) + return CMD_RET_USAGE; + else if (ret != EFI_SUCCESS) + return CMD_RET_FAILURE; + ret = efi_run_image(image_buf, size); if (ret != EFI_SUCCESS) diff --git a/include/efi_loader.h b/include/efi_loader.h index 664dae28f882..44436d346286 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -879,14 +879,12 @@ efi_status_t __efi_runtime EFIAPI efi_get_time( efi_status_t __efi_runtime EFIAPI efi_set_time(struct efi_time *time); -#ifdef CONFIG_CMD_BOOTEFI_SELFTEST /* * Entry point for the tests of the EFI API. * It is called by 'bootefi selftest' */ efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle, struct efi_system_table *systab); -#endif efi_status_t EFIAPI efi_get_variable(u16 *variable_name, const efi_guid_t *vendor, u32 *attributes, From patchwork Tue Nov 21 01:29:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 745671 Delivered-To: patch@linaro.org Received: by 2002:a5d:5052:0:b0:32d:baff:b0ca with SMTP id h18csp1628196wrt; Mon, 20 Nov 2023 17:32:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJbaVyPMFxKHE/PBKtWnv6gXRF3dI7KPedB5tvUp8ILmEprqfCrF5JGmtCB265OV+B5upY X-Received: by 2002:a19:c511:0:b0:50a:a31e:55eb with SMTP id w17-20020a19c511000000b0050aa31e55ebmr6061429lfe.37.1700530359680; Mon, 20 Nov 2023 17:32:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700530359; cv=none; d=google.com; s=arc-20160816; b=oAWvEhUqDQNWwPYcduAiCjauxfb1IqUvnwIcRWTXBZ2qLhVb23GQdfw4SznRQx4TPF gk4VZj1/PCihTcVzM6jMHresyvhFpJsdB8aWMf9I1PsLAlcXh9QQNwv6rSndpUFzx74g bdNUKuDhbMpHklQD1q8EsueY3D+Z83/JuNdQuXp1vXH9PS6raIem1T6OBxYr6OsnPYCU 74Nse1bi3hXNjIdV6srm5MDaSjYKnRNvG/41Kx5bkS6H5cNtYp/o3JmPqg6+0JzYkuYu QBvohNEZD1xlSXN9cnC1Axjl9Zcd8Ns5mlE0bKPZPFWwA7OFxylDjgQ3x88a1he1bccv 42yA== 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=Azv2jiokxdDjjZVQpsj4tHdv10eu4UK1JN/knIvXPu4=; fh=p8OTi/tJSbfUA0ykVxDxRCnpqUhQqJazFYHXT9edm5U=; b=Xzg2xdnoa9oIw/uXxo3z63ctXHHD5MG2o1WYblSnDFnlC9gS5n3q3eF9rzbkhWxGB8 3BeM/DytMrCR7LricwqfZvPJvK117IjkT4vkTDock8YvvxhCvzdfj0JC6LlvkD3gadRA 086Do2pYZECSg0i8u7yPJ3rTwTfi0aTfdB1GFxNpnHOilOK7uNLqLM2gDzJWHeytN1rf ervWydrExOkWJkHMHsfz8yPx7F7I0V1EHRSqJgUBj9DFbRLIzL9HoydutfPr2lcb/p7y zdMeyHrGEGgu4Rw12UqhagikJ0teip2Y6hqmDcVpeQ2jnALcdHgRSlZZXqwKCwQhKmaS XOWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=to8s09Rl; 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 by26-20020a0564021b1a00b00548bc81607fsi1668499edb.6.2023.11.20.17.32.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:32:39 -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=to8s09Rl; 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 580C7875A7; Tue, 21 Nov 2023 02:30: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=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="to8s09Rl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0887A87582; Tue, 21 Nov 2023 02:30:47 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) (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 39EDD875A7 for ; Tue, 21 Nov 2023 02:30:40 +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=takahiro.akashi@linaro.org Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1cc703d2633so10670275ad.0 for ; Mon, 20 Nov 2023 17:30:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700530238; x=1701135038; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Azv2jiokxdDjjZVQpsj4tHdv10eu4UK1JN/knIvXPu4=; b=to8s09RlkP4KblHZ4l5HzIY2Kgl33PqP7HPOiHo2NPH54FVlNoShcsinFElqF2729w YzgfDmJCO2+OL957r33LMGSVL7lifcluUL+/K4SGiFXUTILnvLhYlLtBQFQoIBOplLrF FbQcpuOVODErPp/BM1G8b01bQsLr9bibMZ7/zo1R0rtEe0RbQ7WoPfVN+vhXwsvnxxSF fq2dYm1lk1QMz3D16LmoRfaU8p+dHF9KRjKkBrnuyvaFPIAYZf/op41Y73pmKs5g3qDF m9oNLsiNXGB1O7mki1yifJ4iqshqRPA7uIoNzz8FF87lXzhqP+8cup2Nh9gJGwRWZk5J fSFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700530238; x=1701135038; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Azv2jiokxdDjjZVQpsj4tHdv10eu4UK1JN/knIvXPu4=; b=elAG2+qQlHDIGakrFSNDjcfE3EZZc7frGmD4+NEBzLAyMDVORKSAMnc6HrMOThCgBt qvpgoylLFqsb+A4SI4/vxOYoSiQcDQwnzZ4UbTL1u92ZXcmeOhqXnfqxJfcXRfwJ3nPQ iJkeFdb/iO7mdjzcKzF8fjgAygcBPNyDgJGJvF8/T4zMHEXiZv813JOKzOpwGNUh50uE pCJA52hZmxZRvYFX6twdOZ56ZJz4nuKCNkMZWYM4TZnLiWBwjs791eXfRUv6KAdiRN91 rLNcbxYCa0EIgUTEkKFyzLTYO8oHBMOvAF1eRl1IhYdKYRqAm62/62RMA6zP7/b/iIXg aw6Q== X-Gm-Message-State: AOJu0YyDZvjjGbxjJOzrpH63OU7XQ3+bTBjechxYfZZkiDK6a6aI0dng px+PgQGyYQ+yMAl5L9N2o601dg== X-Received: by 2002:a17:902:e74b:b0:1cc:32c6:e5fa with SMTP id p11-20020a170902e74b00b001cc32c6e5famr11564552plf.6.1700530238103; Mon, 20 Nov 2023 17:30:38 -0800 (PST) Received: from octopus.. ([2400:4050:c3e1:100:f6af:a59c:7ca:897f]) by smtp.gmail.com with ESMTPSA id e9-20020a170902d38900b001c8a0879805sm3612508pld.206.2023.11.20.17.30.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:30:37 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org, xypron.glpk@gmx.de, ilias.apalodimas@linaro.org Cc: u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v2 03/12] cmd: bootefi: carve out EFI boot manager interface Date: Tue, 21 Nov 2023 10:29:41 +0900 Message-Id: <20231121012950.156539-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121012950.156539-1-takahiro.akashi@linaro.org> References: <20231121012950.156539-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean Carve EFI boot manager related code out of do_bootefi_image() in order to move boot manager specific code into library directory in the later commit. Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index e9e5ab67a1f5..87910c42333a 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -413,28 +413,40 @@ out: } /** - * do_efibootmgr() - execute EFI boot manager + * efi_bootmgr_run() - execute EFI boot manager + * fdt: Flat device tree + * + * Invoke EFI boot manager and execute a binary depending on + * boot options. If @fdt is not NULL, it will be passed to + * the executed binary. * * Return: status code */ -static int do_efibootmgr(void) +static efi_status_t efi_bootmgr_run(void *fdt) { efi_handle_t handle; - efi_status_t ret; void *load_options; + efi_status_t ret; - ret = efi_bootmgr_load(&handle, &load_options); + /* Initialize EFI drivers */ + ret = efi_init_obj_list(); if (ret != EFI_SUCCESS) { - log_notice("EFI boot manager: Cannot load any image\n"); + log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n", + ret & ~EFI_ERROR_MASK); return CMD_RET_FAILURE; } - ret = do_bootefi_exec(handle, load_options); - + ret = efi_install_fdt(fdt); if (ret != EFI_SUCCESS) - return CMD_RET_FAILURE; + return ret; - return CMD_RET_SUCCESS; + ret = efi_bootmgr_load(&handle, &load_options); + if (ret != EFI_SUCCESS) { + log_notice("EFI boot manager: Cannot load any image\n"); + return ret; + } + + return do_bootefi_exec(handle, load_options); } /** @@ -624,21 +636,14 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc, if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR) && !strcmp(argv[1], "bootmgr")) { - /* Initialize EFI drivers */ - ret = efi_init_obj_list(); - if (ret != EFI_SUCCESS) { - log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n", - ret & ~EFI_ERROR_MASK); - return CMD_RET_FAILURE; - } + ret = efi_bootmgr_run(fdt); - ret = efi_install_fdt(fdt); if (ret == EFI_INVALID_PARAMETER) return CMD_RET_USAGE; - else if (ret != EFI_SUCCESS) + else if (ret) return CMD_RET_FAILURE; - return do_efibootmgr(); + return CMD_RET_SUCCESS; } if (IS_ENABLED(CONFIG_CMD_BOOTEFI_SELFTEST) && From patchwork Tue Nov 21 01:29:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 745675 Delivered-To: patch@linaro.org Received: by 2002:a5d:5052:0:b0:32d:baff:b0ca with SMTP id h18csp1628564wrt; Mon, 20 Nov 2023 17:33:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IHfxK/cbrFLpiR66MgukuO1gzWwGr1+35enztosK476w/QmCms1hm7mlVY+ohaY62m/3aNg X-Received: by 2002:a17:906:14c:b0:a00:1c10:f94e with SMTP id 12-20020a170906014c00b00a001c10f94emr883494ejh.3.1700530428753; Mon, 20 Nov 2023 17:33:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700530428; cv=none; d=google.com; s=arc-20160816; b=lwVZzNewfeEN5W0B0ErD22oQkpOxK67tC197ynzaSXzxVyE2rCOQzM4k+ci/EcK0l1 TbvKE9xHQCbEE8oHL2MPp03Ki9+YSvb/YOiR3sfAzps51rryY1r8y1Zdj0fj9NaWSreu TokWt8breOV5+ZX3KhVcRFx5R1qNbYyoXPF3elOFuvC88uxjoMOAHLsZ0vc1OgqPVM2u Hjxq1yOhajy+VhAXIUzrpQm4Nxhnjn3BgFBsGBrrSFSSV9AOXJr+QiLuZAIbiI22fzUz xwW4bpi9zPKo0IRx4MK7yv4LjmtzyZt67lAZFqlWbygca2C/gmfE2mM/Z+7RO5dWBS/B bEow== 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=jV5l8YImZIXIFIXxc6opG4nNMwJSYg+WrFO678oFI8I=; fh=p8OTi/tJSbfUA0ykVxDxRCnpqUhQqJazFYHXT9edm5U=; b=xEiRAB1PhBZmSjpczrDYx4L2cNTev1/FQ72ug0wlO0NkFelj1PyBWS5GKRUjQUafcZ GyTnytoM5Gjer7N5LUQ3Zadscgep6xHNFvNMsTWotzacXCzLrqSn+HKYBlKJPbypJ7VV 2JMzyjwSg/COw0f9+axu89NLocfvkhr62FjV2iHp2F5oX9s209mroCBwuvqDyMti3goS ugYloXU8U0gYQFTQF+rcfhFCMzwbIsFIrlBYuSkaZs1XBt2toRTjTnbbAEIo79DnL4fn iBj9NG00w58QCiPhZoH198kYhKshRRsGhvExHl73tmbMTG7JW7ZQ6Jibq4DyQ+C6DAwo MTLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cQADARlp; 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 y8-20020a170906558800b009f6d405abffsi4814605ejp.348.2023.11.20.17.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:33: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=cQADARlp; 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 C59ED87574; Tue, 21 Nov 2023 02:31:38 +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="cQADARlp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C3FD287574; Tue, 21 Nov 2023 02:31: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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) (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 B630C875B5 for ; Tue, 21 Nov 2023 02:30: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=takahiro.akashi@linaro.org Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1ca85ff26afso8802255ad.1 for ; Mon, 20 Nov 2023 17:30:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700530240; x=1701135040; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jV5l8YImZIXIFIXxc6opG4nNMwJSYg+WrFO678oFI8I=; b=cQADARlpUZOGpJp3Z9gdtnr8dMRTunOLtO/j+mbdeJXG3U6o9OFtfb9NZ9ZAF2yg5d C/t9/mttCbOFQQNj3T5a1Lnd5KzTUqhMHsQqVxGY0Yc036gFJjB5A1JKXXJ/ZbW0uVk6 +gS300EYkHlPmseKBiHBrmrGKI3hMSZukAPEUmLc1G5SuQLwv90P0wA2mTtV7IUNMIa1 bYdSna+S2EP3AIPNXwXast5Hm6B6zY/3eAKAG2lbfjJ6m8u0Qx1kaTWwL0gIeL/OHESJ sYOnMXvSN2CKEErSOCDBk3GEMrq0rCJ9c2WhqZObxJgX/NsI0viqKcyVNxSAVzBYUBEb I/3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700530240; x=1701135040; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jV5l8YImZIXIFIXxc6opG4nNMwJSYg+WrFO678oFI8I=; b=nKLMjMp7fNoXojicH6+4eTGcTjNhdeiWHxSvrYhVU2+/yOqUXDq9K+O/fYyuK14y3b pV8INO8RNGjvtZF4LRDKhwCIjjGopDhybKTkBsS3/Ckb6UQXKxY5V3dN8+vLGbybRdd7 +F+1U0QSABHMuWG+579ZoedJg6N5YJsvmdjmQ7Jd9RzACakcz2tUC+M+HoSLhCJA9ZW/ bt1BaMcEnGeKYGKm/3W1OPo/vty3h3pN5K1D/aoMTnYm5vSxx7WofaX+eBLjXwRiWor+ m9q0NEcOmAq1Rp88z0lqVhtztRzRl2aZj6XxspqWiiBQcZxibFf4jlOuud+AzcxNqf3K 4AGQ== X-Gm-Message-State: AOJu0Yz7uU3mt93ZT9sD5HiMLAVROud3coODXfZ5Vcv2LJOHPlLPvzfK 3JgapDMtW+Zf7ifI6C8LVT949A== X-Received: by 2002:a17:902:e749:b0:1ce:63bf:e4c9 with SMTP id p9-20020a170902e74900b001ce63bfe4c9mr11605260plf.0.1700530240157; Mon, 20 Nov 2023 17:30:40 -0800 (PST) Received: from octopus.. ([2400:4050:c3e1:100:f6af:a59c:7ca:897f]) by smtp.gmail.com with ESMTPSA id e9-20020a170902d38900b001c8a0879805sm3612508pld.206.2023.11.20.17.30.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:30:39 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org, xypron.glpk@gmx.de, ilias.apalodimas@linaro.org Cc: u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v2 04/12] cmd: bootefi: carve out binary execution interface Date: Tue, 21 Nov 2023 10:29:42 +0900 Message-Id: <20231121012950.156539-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121012950.156539-1-takahiro.akashi@linaro.org> References: <20231121012950.156539-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean Carve binary execution code out of do_bootefi_image() in order to move binary-execution specific code into library directory in the later commit. Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 87910c42333a..957e2618aca2 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -515,6 +515,36 @@ out: return (ret != EFI_SUCCESS) ? ret : ret2; } +/** + * efi_binary_run() - run loaded UEFI image + * + * @image: memory address of the UEFI image + * @size: size of the UEFI image + * + * Execute an EFI binary image loaded at @image. + * @size may be zero if the binary is loaded with U-Boot load command. + * + * Return: status code + */ +static efi_status_t efi_binary_run(void *image, size_t size, void *fdt) +{ + efi_status_t ret; + + /* Initialize EFI drivers */ + ret = efi_init_obj_list(); + if (ret != EFI_SUCCESS) { + log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n", + ret & ~EFI_ERROR_MASK); + return ret; + } + + ret = efi_install_fdt(fdt); + if (ret != EFI_SUCCESS) + return ret; + + return efi_run_image(image, size); +} + static efi_status_t bootefi_run_prepare(const char *load_options_path, struct efi_device_path *device_path, struct efi_device_path *image_path, @@ -696,23 +726,11 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc, } } - /* Initialize EFI drivers */ - ret = efi_init_obj_list(); - if (ret != EFI_SUCCESS) { - log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n", - ret & ~EFI_ERROR_MASK); - return CMD_RET_FAILURE; - } + ret = efi_binary_run(image_buf, size, fdt); - ret = efi_install_fdt(fdt); if (ret == EFI_INVALID_PARAMETER) return CMD_RET_USAGE; - else if (ret != EFI_SUCCESS) - return CMD_RET_FAILURE; - - ret = efi_run_image(image_buf, size); - - if (ret != EFI_SUCCESS) + else if (ret) return CMD_RET_FAILURE; return CMD_RET_SUCCESS; From patchwork Tue Nov 21 01:29:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 745672 Delivered-To: patch@linaro.org Received: by 2002:a5d:5052:0:b0:32d:baff:b0ca with SMTP id h18csp1628256wrt; Mon, 20 Nov 2023 17:32:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNYvM9eDapcl6h5SrDrOmacyrJz7X4sJMjLS6mEHHf2kVEER6UJnPeANq4y0hOGFA181Zw X-Received: by 2002:a17:906:74d3:b0:a01:aafc:5884 with SMTP id z19-20020a17090674d300b00a01aafc5884mr357744ejl.7.1700530372016; Mon, 20 Nov 2023 17:32:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700530372; cv=none; d=google.com; s=arc-20160816; b=bCn8jY8dUN3NyEMFt94uRTewzsgqa0V+IFT6XqJSdZMA/YdwiFZ9Q34tu83cSPSJs4 3C70CEfJVyPFe3l/Bld5SFz68oT1lQNgZRNUzimnHRcQZ0lbgPkoYfjNt7IRDVmH1ROk t2xIuGVBQayvnBwY+V/DG0JXzSF0hRoCf9dtLAh5+CL7XV0DmRHoCvzpoEk+3rPRuQhn 3wIPAshJElIbD0ZMQoOTd2gCMAvJsG3n3RoqMVFiEtQ2uhKKsO6vJTpRXN/3JKSm4F1O D2BhyzUIWLn4cVUdwzKDtF+YI6KOQdp5dZRERrY561DngVaESz1d7ja7i9K/mH6IPamJ VZng== 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=KtBO7KJX8Q9+7Q4jJOUKHuAVfeIuAYXNAI/om3PTs+Y=; fh=p8OTi/tJSbfUA0ykVxDxRCnpqUhQqJazFYHXT9edm5U=; b=wNzlS5bLs/ObNjtgqPv+OokkFQtvvXyQTENcVCAuWiEde3FeVAk58ab8WIlq55rULo yJBufb5lHSmtZou0+wAk16qiNksTXt9JyL/Nr4aJDFGKcdbduS4l/TtsAY1xfAk1ZRI8 wijj25OgrtWo1o1MiEDrRlxp+hIb2s+Vm10vuP+PMT3o9+5BjLij4NRhIu26QlhO6v+c iRuBTtaZfROS25iTquEKwbfel6sC1HvoqIKFu00y54oZpknmNZU4+Sk3Fcrv8uO9bO5P 4RkkEVHJHEIeJjPu+QlHUA1w3OQDaX7YvgTGY2cJ90ad++UAL0L/xOUwfrnTyAiRHcWs tXUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M8chPif7; 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 gn28-20020a1709070d1c00b009fbc6f0e80asi2906116ejc.497.2023.11.20.17.32.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:32:51 -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=M8chPif7; 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 778B087593; Tue, 21 Nov 2023 02:31: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="M8chPif7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 51C0C875AB; Tue, 21 Nov 2023 02:30:52 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (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 E428986BFA for ; Tue, 21 Nov 2023 02:30: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=takahiro.akashi@linaro.org Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1cc28719cb0so8856985ad.0 for ; Mon, 20 Nov 2023 17:30:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700530242; x=1701135042; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KtBO7KJX8Q9+7Q4jJOUKHuAVfeIuAYXNAI/om3PTs+Y=; b=M8chPif7z/fdqAwoYaHwRJ5hCMKapX3rim0DUsxqFGLNiHJRIJbNbwY80ZZ5DTj3ai XS/MwF3KOV6Ivwpc15kpsvl5S2fxObyD/lAgvmTnU+Y6RMeRprFJBhUTktMimmOf33uE LYfr8Abbmr1wgJ36uElyiCatqNBwHGYhhw2A9ooTfFg5+tnpbtekS7b10B5WtOpbauNh axk0n8wt7ZbjM/pfkMluqaDLFkh5yQNqtGHnzEcM0p8P69pUzoXb7ghYQL99BjQ+IbhY X+ZjAvaSAopMSLFY8xXCmPoKEEBfNlgcWNkWrrJKk1Kxv1TzfMJ7owvFEEPzPqi94KIH v4Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700530242; x=1701135042; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KtBO7KJX8Q9+7Q4jJOUKHuAVfeIuAYXNAI/om3PTs+Y=; b=kx8s4g0/FvOXI4DD7wNHVg76JKkWxtd1QMXllCaWTriezkHeb+3pviHyevZrQ0V8o9 wNmLwb4odm5N2Q3YK91WRGv7XL+eE+lqAYizMmWYpSHk8mJj90txKPzD0+3f8PdfrB/0 Z8uFmIdaEyE4EZ3Ha8EvxnUdDsXzmjVH209zZD1AYP6pipDjej+dsK6cHfCn4tYPc6j5 jN6vIyvjHow+RV+1LkmoEsNvm84TgV8/6C/qDsxjm5ulZPDPugiQW0rX/YB/nkVcBRbp IpxW3SvhGBEp9h/nFGYIHXPcC/uPPrOZyr3Hn8mTGwE81iW4zCv7oc024/FDxpwvgUba Yvtg== X-Gm-Message-State: AOJu0YyoAplc5qX4FNhXb+PL6X6uMkxXbf/b07yBxtPKh+cvdUnospwF PN3gdJf5xsziNHqpsYpJ7MN6KA== X-Received: by 2002:a17:902:eccd:b0:1cf:6a75:e989 with SMTP id a13-20020a170902eccd00b001cf6a75e989mr2294288plh.6.1700530242416; Mon, 20 Nov 2023 17:30:42 -0800 (PST) Received: from octopus.. ([2400:4050:c3e1:100:f6af:a59c:7ca:897f]) by smtp.gmail.com with ESMTPSA id e9-20020a170902d38900b001c8a0879805sm3612508pld.206.2023.11.20.17.30.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:30:42 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org, xypron.glpk@gmx.de, ilias.apalodimas@linaro.org Cc: u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v2 05/12] cmd: bootefi: localize global device paths for efi_selftest Date: Tue, 21 Nov 2023 10:29:43 +0900 Message-Id: <20231121012950.156539-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121012950.156539-1-takahiro.akashi@linaro.org> References: <20231121012950.156539-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean Device paths allocated in bootefi_test_prepare() will be immediately consumed by do_efi_selftest() and there is no need to keep them for later use. Introduce test-specific varialbles to make it easier to move other bootmgr functions into library directory in the next commit. Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 957e2618aca2..7930c99def44 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -29,6 +29,8 @@ DECLARE_GLOBAL_DATA_PTR; +static struct efi_device_path *test_image_path; +static struct efi_device_path *test_device_path; static struct efi_device_path *bootefi_image_path; static struct efi_device_path *bootefi_device_path; static void *image_addr; @@ -586,23 +588,26 @@ static efi_status_t bootefi_test_prepare efi_status_t ret; /* Construct a dummy device path */ - bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, 0, 0); - if (!bootefi_device_path) + test_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, 0, 0); + if (!test_device_path) return EFI_OUT_OF_RESOURCES; - bootefi_image_path = efi_dp_from_file(NULL, path); - if (!bootefi_image_path) { + test_image_path = efi_dp_from_file(NULL, path); + if (!test_image_path) { ret = EFI_OUT_OF_RESOURCES; goto failure; } - ret = bootefi_run_prepare(load_options_path, bootefi_device_path, - bootefi_image_path, image_objp, + ret = bootefi_run_prepare(load_options_path, test_device_path, + test_image_path, image_objp, loaded_image_infop); if (ret == EFI_SUCCESS) return ret; failure: + efi_free_pool(test_device_path); + efi_free_pool(test_image_path); + /* TODO: not sure calling clear function is necessary */ efi_clear_bootdev(); return ret; } @@ -627,6 +632,8 @@ static int do_efi_selftest(void) ret = EFI_CALL(efi_selftest(&image_obj->header, &systab)); efi_restore_gd(); free(loaded_image_info->load_options); + efi_free_pool(test_device_path); + efi_free_pool(test_image_path); if (ret != EFI_SUCCESS) efi_delete_handle(&image_obj->header); else From patchwork Tue Nov 21 01:29:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 745673 Delivered-To: patch@linaro.org Received: by 2002:a5d:5052:0:b0:32d:baff:b0ca with SMTP id h18csp1628377wrt; Mon, 20 Nov 2023 17:33:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IExEXW7c9GhEDAMKpA3son9R1hKrmc6zS3S6a3EdFZ7WTdz5lfR9Td9D8DOSKlhumjsS1+S X-Received: by 2002:a17:906:4153:b0:9cd:5223:e5fa with SMTP id l19-20020a170906415300b009cd5223e5famr6756351ejk.42.1700530394407; Mon, 20 Nov 2023 17:33:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700530394; cv=none; d=google.com; s=arc-20160816; b=bp1yMsnzNHW8t4N/Qc0bhhcLOmGx7H0TcC1UIQfq+GxpfMz7yzhRGzQhMrEphNtVIT 4meLCJSD+jp/iVapgbYDvKL0hmz1K99ylPMQRAu55Z1MtpJZhVuCfyOdo+2bHceX1NkS dMwTprRcFlk/DDQIfvPxHtRqcEbvnjFNCJDYzW/Yd6JNr79siu92vtsrUoZqucMk3M9V y2xFjemwICmlfc7Kd3sEKudNawABd8tB2QHFObuPifPjxsT23P96/xGpzv4Ifuouj4dU JMBgFjwbFvTx58+QOfNfIQMpmtlyW+3Ly1YLJl4bgEZbxeA8hZ5EmQ29UKcz9GoaCaUd jGZA== 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=P9MLLKtcjwc04FJmiopPsNAWSNVAbA4vr9K4vFjWhQM=; fh=p8OTi/tJSbfUA0ykVxDxRCnpqUhQqJazFYHXT9edm5U=; b=RQfcZ9BWtGKsP1VbExZAPA2XOOL6JI8m4K8hfVjK4w4OaUU+i3wHHiUXOndytpj0q6 wCzrOJF6E4gloTjM+Wt+16jZ1nks5ubgwYfglrlwrpiJV+6mO1BR9/l7u9EmBEiImGQH VV9m72d5b5ovJcZ7BlRcBUbbgs8rGtDh5s0LHF+GFQBBLxx/rWm/lOR6HYBekA4B+mu4 6u958/qME4Zj+FDsJIOyyeh+TvXkgwb5hgRo2PC7jTgsaIqyQqDb4aDQQTfnAk33RY+L WfqHMhIyMJBRfvcDd+3b0prtyXp6Nml7xjMNuXCNaYjNVqEsnTMPdpVfehsC9+3Sw8oI FYHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cPAFVmN4; 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 gt40-20020a1709072da800b00a01c33eba20si209131ejc.75.2023.11.20.17.33.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:33:14 -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=cPAFVmN4; 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 72B71875AB; Tue, 21 Nov 2023 02:31: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="cPAFVmN4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 63943875AB; Tue, 21 Nov 2023 02:31: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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) (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 E372C863FD for ; Tue, 21 Nov 2023 02:30: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=takahiro.akashi@linaro.org Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1cc703d2633so10670365ad.0 for ; Mon, 20 Nov 2023 17:30:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700530245; x=1701135045; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=P9MLLKtcjwc04FJmiopPsNAWSNVAbA4vr9K4vFjWhQM=; b=cPAFVmN4cZWbGnqiLjPUc0Q5+SeAOlmWg9H+/lrp/mMbfqAuv28KhWpfSWO8jb2dPH mZhl591u738L0xghn25BdyoIIU7TujnyTTGEuNXkhiQc/L9Id7AM68egehL6mhQ+xlnT 02ujvk0wPrJM2B8rbz2TrUsRrGj0rNN0jeFfnlE2thyjBxv5+bAkcBZuEXl6VJCtZXKI yq/jQArj/uPJjSzVVuvgH1eaaMirymuz2bP+CxwKkGnRpAwpvGwPKHntlZPUjhnB0bXQ qHLQj/NcEBqfzPq9GPekZqLvUOHrnVmjjb254f39RixFKXzp4nbBH96B20vGcd59HSXl qnlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700530245; x=1701135045; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P9MLLKtcjwc04FJmiopPsNAWSNVAbA4vr9K4vFjWhQM=; b=QNpGcFFP231cfkvgVMGkqUJsg95N8YpcJrH+64AX77Ot90qoIHo6pHTtj+Sb0WosZK 4TRhODNhQxMo2UqI1TcF7d/CaAqBFZgmauSkqOGTeBailuXnT3lLWBISudWoQ05jP+lR MYO25DOgzlsi6lBWqS31RYAjK3YFKKFqfxLG8Zsop9o3+eRWQgT/1Krw1dkQlYQD5o8o 8j5e61hED4nxHVYpCuYGNaVfw4mTac/MnvjeaGdk/Dpvu7AC7cHxQk7aNsR6f+yQeW9B aFaS2i/3sbcmdVyy6EiM7CUD3BjVmU1+q5JTSsWR1f83vmUQJkHwxo2X0xomHi8CZTqZ pedw== X-Gm-Message-State: AOJu0Yxb/gsHdYiYXej7vg9ho5YLeu1iPPnGiWVv1kQAsyXnOAy6MBdz vYkm74amAt1ocwhUBoVRUU2t4Q== X-Received: by 2002:a17:903:2312:b0:1cf:5854:41fa with SMTP id d18-20020a170903231200b001cf585441famr8574408plh.1.1700530244695; Mon, 20 Nov 2023 17:30:44 -0800 (PST) Received: from octopus.. ([2400:4050:c3e1:100:f6af:a59c:7ca:897f]) by smtp.gmail.com with ESMTPSA id e9-20020a170902d38900b001c8a0879805sm3612508pld.206.2023.11.20.17.30.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:30:44 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org, xypron.glpk@gmx.de, ilias.apalodimas@linaro.org Cc: u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v2 06/12] cmd: bootefi: move library interfaces under lib/efi_loader Date: Tue, 21 Nov 2023 10:29:44 +0900 Message-Id: <20231121012950.156539-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121012950.156539-1-takahiro.akashi@linaro.org> References: <20231121012950.156539-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean In the prior commits, interfaces for executing EFI binary and boot manager were carved out. Move them under efi_loader directory so that they can be called from other places without depending on bootefi command. Only efi_selftest-related code will be left in bootefi.c. Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 539 +---------------------------------- include/efi_loader.h | 10 + lib/efi_loader/efi_bootmgr.c | 529 ++++++++++++++++++++++++++++++++++ 3 files changed, 550 insertions(+), 528 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 7930c99def44..9cf9027bf409 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -7,545 +7,22 @@ #define LOG_CATEGORY LOGC_EFI -#include -#include -#include #include -#include +#include #include -#include -#include -#include -#include +#include #include #include -#include -#include -#include #include -#include +#include #include -#include +#include +#include DECLARE_GLOBAL_DATA_PTR; static struct efi_device_path *test_image_path; static struct efi_device_path *test_device_path; -static struct efi_device_path *bootefi_image_path; -static struct efi_device_path *bootefi_device_path; -static void *image_addr; -static size_t image_size; - -/** - * efi_get_image_parameters() - return image parameters - * - * @img_addr: address of loaded image in memory - * @img_size: size of loaded image - */ -void efi_get_image_parameters(void **img_addr, size_t *img_size) -{ - *img_addr = image_addr; - *img_size = image_size; -} - -/** - * efi_clear_bootdev() - clear boot device - */ -static void efi_clear_bootdev(void) -{ - efi_free_pool(bootefi_device_path); - efi_free_pool(bootefi_image_path); - bootefi_device_path = NULL; - bootefi_image_path = NULL; - image_addr = NULL; - image_size = 0; -} - -/** - * efi_set_bootdev() - set boot device - * - * This function is called when a file is loaded, e.g. via the 'load' command. - * We use the path to this file to inform the UEFI binary about the boot device. - * - * @dev: device, e.g. "MMC" - * @devnr: number of the device, e.g. "1:2" - * @path: path to file loaded - * @buffer: buffer with file loaded - * @buffer_size: size of file loaded - */ -void efi_set_bootdev(const char *dev, const char *devnr, const char *path, - void *buffer, size_t buffer_size) -{ - struct efi_device_path *device, *image; - efi_status_t ret; - - log_debug("dev=%s, devnr=%s, path=%s, buffer=%p, size=%zx\n", dev, - devnr, path, buffer, buffer_size); - - /* Forget overwritten image */ - if (buffer + buffer_size >= image_addr && - image_addr + image_size >= buffer) - efi_clear_bootdev(); - - /* Remember only PE-COFF and FIT images */ - if (efi_check_pe(buffer, buffer_size, NULL) != EFI_SUCCESS) { - if (IS_ENABLED(CONFIG_FIT) && - !fit_check_format(buffer, IMAGE_SIZE_INVAL)) { - /* - * FIT images of type EFI_OS are started via command - * bootm. We should not use their boot device with the - * bootefi command. - */ - buffer = 0; - buffer_size = 0; - } else { - log_debug("- not remembering image\n"); - return; - } - } - - /* efi_set_bootdev() is typically called repeatedly, recover memory */ - efi_clear_bootdev(); - - image_addr = buffer; - image_size = buffer_size; - - ret = efi_dp_from_name(dev, devnr, path, &device, &image); - if (ret == EFI_SUCCESS) { - bootefi_device_path = device; - if (image) { - /* FIXME: image should not contain device */ - struct efi_device_path *image_tmp = image; - - efi_dp_split_file_path(image, &device, &image); - efi_free_pool(image_tmp); - } - bootefi_image_path = image; - log_debug("- boot device %pD\n", device); - if (image) - log_debug("- image %pD\n", image); - } else { - log_debug("- efi_dp_from_name() failed, err=%lx\n", ret); - efi_clear_bootdev(); - } -} - -/** - * efi_env_set_load_options() - set load options from environment variable - * - * @handle: the image handle - * @env_var: name of the environment variable - * @load_options: pointer to load options (output) - * Return: status code - */ -static efi_status_t efi_env_set_load_options(efi_handle_t handle, - const char *env_var, - u16 **load_options) -{ - const char *env = env_get(env_var); - size_t size; - u16 *pos; - efi_status_t ret; - - *load_options = NULL; - if (!env) - return EFI_SUCCESS; - size = sizeof(u16) * (utf8_utf16_strlen(env) + 1); - pos = calloc(size, 1); - if (!pos) - return EFI_OUT_OF_RESOURCES; - *load_options = pos; - utf8_utf16_strcpy(&pos, env); - ret = efi_set_load_options(handle, size, *load_options); - if (ret != EFI_SUCCESS) { - free(*load_options); - *load_options = NULL; - } - return ret; -} - -#if !CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) - -/** - * copy_fdt() - Copy the device tree to a new location available to EFI - * - * The FDT is copied to a suitable location within the EFI memory map. - * Additional 12 KiB are added to the space in case the device tree needs to be - * expanded later with fdt_open_into(). - * - * @fdtp: On entry a pointer to the flattened device tree. - * On exit a pointer to the copy of the flattened device tree. - * FDT start - * Return: status code - */ -static efi_status_t copy_fdt(void **fdtp) -{ - unsigned long fdt_ram_start = -1L, fdt_pages; - efi_status_t ret = 0; - void *fdt, *new_fdt; - u64 new_fdt_addr; - uint fdt_size; - int i; - - for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { - u64 ram_start = gd->bd->bi_dram[i].start; - u64 ram_size = gd->bd->bi_dram[i].size; - - if (!ram_size) - continue; - - if (ram_start < fdt_ram_start) - fdt_ram_start = ram_start; - } - - /* - * Give us at least 12 KiB of breathing room in case the device tree - * needs to be expanded later. - */ - fdt = *fdtp; - fdt_pages = efi_size_in_pages(fdt_totalsize(fdt) + 0x3000); - fdt_size = fdt_pages << EFI_PAGE_SHIFT; - - ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, - EFI_ACPI_RECLAIM_MEMORY, fdt_pages, - &new_fdt_addr); - if (ret != EFI_SUCCESS) { - log_err("ERROR: Failed to reserve space for FDT\n"); - goto done; - } - new_fdt = (void *)(uintptr_t)new_fdt_addr; - memcpy(new_fdt, fdt, fdt_totalsize(fdt)); - fdt_set_totalsize(new_fdt, fdt_size); - - *fdtp = (void *)(uintptr_t)new_fdt_addr; -done: - return ret; -} - -/** - * get_config_table() - get configuration table - * - * @guid: GUID of the configuration table - * Return: pointer to configuration table or NULL - */ -static void *get_config_table(const efi_guid_t *guid) -{ - size_t i; - - for (i = 0; i < systab.nr_tables; i++) { - if (!guidcmp(guid, &systab.tables[i].guid)) - return systab.tables[i].table; - } - return NULL; -} - -#endif /* !CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) */ - -/** - * efi_install_fdt() - install device tree - * - * If fdt is not EFI_FDT_USE_INTERNAL, the device tree located at that memory - * address will will be installed as configuration table, otherwise the device - * tree located at the address indicated by environment variable fdt_addr or as - * fallback fdtcontroladdr will be used. - * - * On architectures using ACPI tables device trees shall not be installed as - * configuration table. - * - * @fdt: address of device tree or EFI_FDT_USE_INTERNAL to use the - * the hardware device tree as indicated by environment variable - * fdt_addr or as fallback the internal device tree as indicated by - * the environment variable fdtcontroladdr - * Return: status code - */ -efi_status_t efi_install_fdt(void *fdt) -{ - /* - * The EBBR spec requires that we have either an FDT or an ACPI table - * but not both. - */ -#if CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) - if (fdt) { - log_warning("WARNING: Can't have ACPI table and device tree - ignoring DT.\n"); - return EFI_SUCCESS; - } -#else - struct bootm_headers img = { 0 }; - efi_status_t ret; - - if (fdt == EFI_FDT_USE_INTERNAL) { - const char *fdt_opt; - uintptr_t fdt_addr; - - /* Look for device tree that is already installed */ - if (get_config_table(&efi_guid_fdt)) - return EFI_SUCCESS; - /* Check if there is a hardware device tree */ - fdt_opt = env_get("fdt_addr"); - /* Use our own device tree as fallback */ - if (!fdt_opt) { - fdt_opt = env_get("fdtcontroladdr"); - if (!fdt_opt) { - log_err("ERROR: need device tree\n"); - return EFI_NOT_FOUND; - } - } - fdt_addr = hextoul(fdt_opt, NULL); - if (!fdt_addr) { - log_err("ERROR: invalid $fdt_addr or $fdtcontroladdr\n"); - return EFI_LOAD_ERROR; - } - fdt = map_sysmem(fdt_addr, 0); - } - - /* Install device tree */ - if (fdt_check_header(fdt)) { - log_err("ERROR: invalid device tree\n"); - return EFI_LOAD_ERROR; - } - - /* Prepare device tree for payload */ - ret = copy_fdt(&fdt); - if (ret) { - log_err("ERROR: out of memory\n"); - return EFI_OUT_OF_RESOURCES; - } - - if (image_setup_libfdt(&img, fdt, 0, NULL)) { - log_err("ERROR: failed to process device tree\n"); - return EFI_LOAD_ERROR; - } - - /* Create memory reservations as indicated by the device tree */ - efi_carve_out_dt_rsv(fdt); - - efi_try_purge_kaslr_seed(fdt); - - if (CONFIG_IS_ENABLED(EFI_TCG2_PROTOCOL_MEASURE_DTB)) { - ret = efi_tcg2_measure_dtb(fdt); - if (ret == EFI_SECURITY_VIOLATION) { - log_err("ERROR: failed to measure DTB\n"); - return ret; - } - } - - /* Install device tree as UEFI table */ - ret = efi_install_configuration_table(&efi_guid_fdt, fdt); - if (ret != EFI_SUCCESS) { - log_err("ERROR: failed to install device tree\n"); - return ret; - } -#endif /* GENERATE_ACPI_TABLE */ - - return EFI_SUCCESS; -} - -/** - * do_bootefi_exec() - execute EFI binary - * - * The image indicated by @handle is started. When it returns the allocated - * memory for the @load_options is freed. - * - * @handle: handle of loaded image - * @load_options: load options - * Return: status code - * - * Load the EFI binary into a newly assigned memory unwinding the relocation - * information, install the loaded image protocol, and call the binary. - */ -static efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options) -{ - efi_status_t ret; - efi_uintn_t exit_data_size = 0; - u16 *exit_data = NULL; - struct efi_event *evt; - - /* On ARM switch from EL3 or secure mode to EL2 or non-secure mode */ - switch_to_non_secure_mode(); - - /* - * The UEFI standard requires that the watchdog timer is set to five - * minutes when invoking an EFI boot option. - * - * Unified Extensible Firmware Interface (UEFI), version 2.7 Errata A - * 7.5. Miscellaneous Boot Services - EFI_BOOT_SERVICES.SetWatchdogTimer - */ - ret = efi_set_watchdog(300); - if (ret != EFI_SUCCESS) { - log_err("ERROR: Failed to set watchdog timer\n"); - goto out; - } - - /* Call our payload! */ - ret = EFI_CALL(efi_start_image(handle, &exit_data_size, &exit_data)); - if (ret != EFI_SUCCESS) { - log_err("## Application failed, r = %lu\n", - ret & ~EFI_ERROR_MASK); - if (exit_data) { - log_err("## %ls\n", exit_data); - efi_free_pool(exit_data); - } - } - - efi_restore_gd(); - -out: - free(load_options); - - if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) { - if (efi_initrd_deregister() != EFI_SUCCESS) - log_err("Failed to remove loadfile2 for initrd\n"); - } - - /* Notify EFI_EVENT_GROUP_RETURN_TO_EFIBOOTMGR event group. */ - list_for_each_entry(evt, &efi_events, link) { - if (evt->group && - !guidcmp(evt->group, - &efi_guid_event_group_return_to_efibootmgr)) { - efi_signal_event(evt); - EFI_CALL(systab.boottime->close_event(evt)); - break; - } - } - - /* Control is returned to U-Boot, disable EFI watchdog */ - efi_set_watchdog(0); - - return ret; -} - -/** - * efi_bootmgr_run() - execute EFI boot manager - * fdt: Flat device tree - * - * Invoke EFI boot manager and execute a binary depending on - * boot options. If @fdt is not NULL, it will be passed to - * the executed binary. - * - * Return: status code - */ -static efi_status_t efi_bootmgr_run(void *fdt) -{ - efi_handle_t handle; - void *load_options; - efi_status_t ret; - - /* Initialize EFI drivers */ - ret = efi_init_obj_list(); - if (ret != EFI_SUCCESS) { - log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n", - ret & ~EFI_ERROR_MASK); - return CMD_RET_FAILURE; - } - - ret = efi_install_fdt(fdt); - if (ret != EFI_SUCCESS) - return ret; - - ret = efi_bootmgr_load(&handle, &load_options); - if (ret != EFI_SUCCESS) { - log_notice("EFI boot manager: Cannot load any image\n"); - return ret; - } - - return do_bootefi_exec(handle, load_options); -} - -/** - * efi_run_image() - run loaded UEFI image - * - * @source_buffer: memory address of the UEFI image - * @source_size: size of the UEFI image - * Return: status code - */ -efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size) -{ - efi_handle_t mem_handle = NULL, handle; - struct efi_device_path *file_path = NULL; - struct efi_device_path *msg_path; - efi_status_t ret, ret2; - u16 *load_options; - - if (!bootefi_device_path || !bootefi_image_path) { - log_debug("Not loaded from disk\n"); - /* - * Special case for efi payload not loaded from disk, - * such as 'bootefi hello' or for example payload - * loaded directly into memory via JTAG, etc: - */ - file_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, - (uintptr_t)source_buffer, - source_size); - /* - * Make sure that device for device_path exist - * in load_image(). Otherwise, shell and grub will fail. - */ - ret = efi_install_multiple_protocol_interfaces(&mem_handle, - &efi_guid_device_path, - file_path, NULL); - if (ret != EFI_SUCCESS) - goto out; - msg_path = file_path; - } else { - file_path = efi_dp_append(bootefi_device_path, - bootefi_image_path); - msg_path = bootefi_image_path; - log_debug("Loaded from disk\n"); - } - - log_info("Booting %pD\n", msg_path); - - ret = EFI_CALL(efi_load_image(false, efi_root, file_path, source_buffer, - source_size, &handle)); - if (ret != EFI_SUCCESS) { - log_err("Loading image failed\n"); - goto out; - } - - /* Transfer environment variable as load options */ - ret = efi_env_set_load_options(handle, "bootargs", &load_options); - if (ret != EFI_SUCCESS) - goto out; - - ret = do_bootefi_exec(handle, load_options); - -out: - ret2 = efi_uninstall_multiple_protocol_interfaces(mem_handle, - &efi_guid_device_path, - file_path, NULL); - efi_free_pool(file_path); - return (ret != EFI_SUCCESS) ? ret : ret2; -} - -/** - * efi_binary_run() - run loaded UEFI image - * - * @image: memory address of the UEFI image - * @size: size of the UEFI image - * - * Execute an EFI binary image loaded at @image. - * @size may be zero if the binary is loaded with U-Boot load command. - * - * Return: status code - */ -static efi_status_t efi_binary_run(void *image, size_t size, void *fdt) -{ - efi_status_t ret; - - /* Initialize EFI drivers */ - ret = efi_init_obj_list(); - if (ret != EFI_SUCCESS) { - log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n", - ret & ~EFI_ERROR_MASK); - return ret; - } - - ret = efi_install_fdt(fdt); - if (ret != EFI_SUCCESS) - return ret; - - return efi_run_image(image, size); -} static efi_status_t bootefi_run_prepare(const char *load_options_path, struct efi_device_path *device_path, @@ -658,6 +135,8 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc, char *p; void *fdt, *image_buf; unsigned long addr, size; + void *image_addr; + size_t image_size; if (argc < 2) return CMD_RET_USAGE; @@ -709,6 +188,7 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc, !strcmp(argv[1], "hello")) { image_buf = __efi_helloworld_begin; size = __efi_helloworld_end - __efi_helloworld_begin; + /* TODO: not sure calling clear function is necessary */ efi_clear_bootdev(); } else { addr = strtoul(argv[1], NULL, 16); @@ -724,6 +204,9 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_USAGE; efi_clear_bootdev(); } else { + /* Image should be already loaded */ + efi_get_image_parameters(&image_addr, &image_size); + if (image_buf != image_addr) { log_err("No UEFI binary known at %s\n", argv[1]); diff --git a/include/efi_loader.h b/include/efi_loader.h index 44436d346286..34e7fbbf1840 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -90,6 +90,8 @@ efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len); * back to u-boot world */ void efi_restore_gd(void); +/* Call this to unset the current device name */ +void efi_clear_bootdev(void); /* Call this to set the current device name */ void efi_set_bootdev(const char *dev, const char *devnr, const char *path, void *buffer, size_t buffer_size); @@ -114,6 +116,7 @@ static inline efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len) /* No loader configured, stub out EFI_ENTRY */ static inline void efi_restore_gd(void) { } +static inline void efi_clear_bootdev(void) { } static inline void efi_set_bootdev(const char *dev, const char *devnr, const char *path, void *buffer, size_t buffer_size) { } @@ -527,14 +530,21 @@ efi_status_t efi_bootmgr_get_unused_bootoption(u16 *buf, efi_status_t efi_bootmgr_update_media_device_boot_option(void); /* Delete selected boot option */ efi_status_t efi_bootmgr_delete_boot_option(u16 boot_index); +/* Invoke EFI boot manager */ +efi_status_t efi_bootmgr_run(void *fdt); /* search the boot option index in BootOrder */ bool efi_search_bootorder(u16 *bootorder, efi_uintn_t num, u32 target, u32 *index); /* Set up console modes */ void efi_setup_console_size(void); +/* Set up load options from environment variable */ +efi_status_t efi_env_set_load_options(efi_handle_t handle, const char *env_var, + u16 **load_options); /* Install device tree */ efi_status_t efi_install_fdt(void *fdt); /* Run loaded UEFI image */ efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size); +/* Run loaded UEFI image with given fdt */ +efi_status_t efi_binary_run(void *image, size_t size, void *fdt); /* Initialize variable services */ efi_status_t efi_init_variables(void); /* Notify ExitBootServices() is called */ diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 48153bd5ffbb..e910f1bb2a23 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -3,6 +3,8 @@ * EFI boot manager * * Copyright (c) 2017 Rob Clark + * For the code moved from cmd/bootefi.c + * Copyright (c) 2016 Alexander Graf */ #define LOG_CATEGORY LOGC_EFI @@ -20,6 +22,17 @@ #include #include +/* TODO: temporarily added here; clean up later */ +#include +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + static const struct efi_boot_services *bs; static const struct efi_runtime_services *rs; @@ -1115,3 +1128,519 @@ out: return EFI_SUCCESS; return ret; } + +static struct efi_device_path *bootefi_image_path; +static struct efi_device_path *bootefi_device_path; +static void *image_addr; +static size_t image_size; + +/** + * efi_get_image_parameters() - return image parameters + * + * @img_addr: address of loaded image in memory + * @img_size: size of loaded image + */ +void efi_get_image_parameters(void **img_addr, size_t *img_size) +{ + *img_addr = image_addr; + *img_size = image_size; +} + +/** + * efi_clear_bootdev() - clear boot device + */ +void efi_clear_bootdev(void) +{ + efi_free_pool(bootefi_device_path); + efi_free_pool(bootefi_image_path); + bootefi_device_path = NULL; + bootefi_image_path = NULL; + image_addr = NULL; + image_size = 0; +} + +/** + * efi_set_bootdev() - set boot device + * + * This function is called when a file is loaded, e.g. via the 'load' command. + * We use the path to this file to inform the UEFI binary about the boot device. + * + * @dev: device, e.g. "MMC" + * @devnr: number of the device, e.g. "1:2" + * @path: path to file loaded + * @buffer: buffer with file loaded + * @buffer_size: size of file loaded + */ +void efi_set_bootdev(const char *dev, const char *devnr, const char *path, + void *buffer, size_t buffer_size) +{ + struct efi_device_path *device, *image; + efi_status_t ret; + + log_debug("dev=%s, devnr=%s, path=%s, buffer=%p, size=%zx\n", dev, + devnr, path, buffer, buffer_size); + + /* Forget overwritten image */ + if (buffer + buffer_size >= image_addr && + image_addr + image_size >= buffer) + efi_clear_bootdev(); + + /* Remember only PE-COFF and FIT images */ + if (efi_check_pe(buffer, buffer_size, NULL) != EFI_SUCCESS) { + if (IS_ENABLED(CONFIG_FIT) && + !fit_check_format(buffer, IMAGE_SIZE_INVAL)) { + /* + * FIT images of type EFI_OS are started via command + * bootm. We should not use their boot device with the + * bootefi command. + */ + buffer = 0; + buffer_size = 0; + } else { + log_debug("- not remembering image\n"); + return; + } + } + + /* efi_set_bootdev() is typically called repeatedly, recover memory */ + efi_clear_bootdev(); + + image_addr = buffer; + image_size = buffer_size; + + ret = efi_dp_from_name(dev, devnr, path, &device, &image); + if (ret == EFI_SUCCESS) { + bootefi_device_path = device; + if (image) { + /* FIXME: image should not contain device */ + struct efi_device_path *image_tmp = image; + + efi_dp_split_file_path(image, &device, &image); + efi_free_pool(image_tmp); + } + bootefi_image_path = image; + log_debug("- boot device %pD\n", device); + if (image) + log_debug("- image %pD\n", image); + } else { + log_debug("- efi_dp_from_name() failed, err=%lx\n", ret); + efi_clear_bootdev(); + } +} + +/** + * efi_env_set_load_options() - set load options from environment variable + * + * @handle: the image handle + * @env_var: name of the environment variable + * @load_options: pointer to load options (output) + * Return: status code + */ +efi_status_t efi_env_set_load_options(efi_handle_t handle, + const char *env_var, + u16 **load_options) +{ + const char *env = env_get(env_var); + size_t size; + u16 *pos; + efi_status_t ret; + + *load_options = NULL; + if (!env) + return EFI_SUCCESS; + size = sizeof(u16) * (utf8_utf16_strlen(env) + 1); + pos = calloc(size, 1); + if (!pos) + return EFI_OUT_OF_RESOURCES; + *load_options = pos; + utf8_utf16_strcpy(&pos, env); + ret = efi_set_load_options(handle, size, *load_options); + if (ret != EFI_SUCCESS) { + free(*load_options); + *load_options = NULL; + } + return ret; +} + +#if !CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) + +/** + * copy_fdt() - Copy the device tree to a new location available to EFI + * + * The FDT is copied to a suitable location within the EFI memory map. + * Additional 12 KiB are added to the space in case the device tree needs to be + * expanded later with fdt_open_into(). + * + * @fdtp: On entry a pointer to the flattened device tree. + * On exit a pointer to the copy of the flattened device tree. + * FDT start + * Return: status code + */ +static efi_status_t copy_fdt(void **fdtp) +{ + unsigned long fdt_ram_start = -1L, fdt_pages; + efi_status_t ret = 0; + void *fdt, *new_fdt; + u64 new_fdt_addr; + uint fdt_size; + int i; + + for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { + u64 ram_start = gd->bd->bi_dram[i].start; + u64 ram_size = gd->bd->bi_dram[i].size; + + if (!ram_size) + continue; + + if (ram_start < fdt_ram_start) + fdt_ram_start = ram_start; + } + + /* + * Give us at least 12 KiB of breathing room in case the device tree + * needs to be expanded later. + */ + fdt = *fdtp; + fdt_pages = efi_size_in_pages(fdt_totalsize(fdt) + 0x3000); + fdt_size = fdt_pages << EFI_PAGE_SHIFT; + + ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, + EFI_ACPI_RECLAIM_MEMORY, fdt_pages, + &new_fdt_addr); + if (ret != EFI_SUCCESS) { + log_err("ERROR: Failed to reserve space for FDT\n"); + goto done; + } + new_fdt = (void *)(uintptr_t)new_fdt_addr; + memcpy(new_fdt, fdt, fdt_totalsize(fdt)); + fdt_set_totalsize(new_fdt, fdt_size); + + *fdtp = (void *)(uintptr_t)new_fdt_addr; +done: + return ret; +} + +/** + * get_config_table() - get configuration table + * + * @guid: GUID of the configuration table + * Return: pointer to configuration table or NULL + */ +static void *get_config_table(const efi_guid_t *guid) +{ + size_t i; + + for (i = 0; i < systab.nr_tables; i++) { + if (!guidcmp(guid, &systab.tables[i].guid)) + return systab.tables[i].table; + } + return NULL; +} + +#endif /* !CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) */ + +/** + * efi_install_fdt() - install device tree + * + * If fdt is not EFI_FDT_USE_INTERNAL, the device tree located at that memory + * address will be installed as configuration table, otherwise the device + * tree located at the address indicated by environment variable fdt_addr or as + * fallback fdtcontroladdr will be used. + * + * On architectures using ACPI tables device trees shall not be installed as + * configuration table. + * + * @fdt: address of device tree or EFI_FDT_USE_INTERNAL to use + * the hardware device tree as indicated by environment variable + * fdt_addr or as fallback the internal device tree as indicated by + * the environment variable fdtcontroladdr + * Return: status code + */ +efi_status_t efi_install_fdt(void *fdt) +{ + /* + * The EBBR spec requires that we have either an FDT or an ACPI table + * but not both. + */ +#if CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) + if (fdt) { + log_warning("WARNING: Can't have ACPI table and device tree - ignoring DT.\n"); + return EFI_SUCCESS; + } +#else + struct bootm_headers img = { 0 }; + efi_status_t ret; + + if (fdt == EFI_FDT_USE_INTERNAL) { + const char *fdt_opt; + uintptr_t fdt_addr; + + /* Look for device tree that is already installed */ + if (get_config_table(&efi_guid_fdt)) + return EFI_SUCCESS; + /* Check if there is a hardware device tree */ + fdt_opt = env_get("fdt_addr"); + /* Use our own device tree as fallback */ + if (!fdt_opt) { + fdt_opt = env_get("fdtcontroladdr"); + if (!fdt_opt) { + log_err("ERROR: need device tree\n"); + return EFI_NOT_FOUND; + } + } + fdt_addr = hextoul(fdt_opt, NULL); + if (!fdt_addr) { + log_err("ERROR: invalid $fdt_addr or $fdtcontroladdr\n"); + return EFI_LOAD_ERROR; + } + fdt = map_sysmem(fdt_addr, 0); + } + + /* Install device tree */ + if (fdt_check_header(fdt)) { + log_err("ERROR: invalid device tree\n"); + return EFI_LOAD_ERROR; + } + + /* Prepare device tree for payload */ + ret = copy_fdt(&fdt); + if (ret) { + log_err("ERROR: out of memory\n"); + return EFI_OUT_OF_RESOURCES; + } + + if (image_setup_libfdt(&img, fdt, 0, NULL)) { + log_err("ERROR: failed to process device tree\n"); + return EFI_LOAD_ERROR; + } + + /* Create memory reservations as indicated by the device tree */ + efi_carve_out_dt_rsv(fdt); + + efi_try_purge_kaslr_seed(fdt); + + if (CONFIG_IS_ENABLED(EFI_TCG2_PROTOCOL_MEASURE_DTB)) { + ret = efi_tcg2_measure_dtb(fdt); + if (ret == EFI_SECURITY_VIOLATION) { + log_err("ERROR: failed to measure DTB\n"); + return ret; + } + } + + /* Install device tree as UEFI table */ + ret = efi_install_configuration_table(&efi_guid_fdt, fdt); + if (ret != EFI_SUCCESS) { + log_err("ERROR: failed to install device tree\n"); + return ret; + } +#endif /* GENERATE_ACPI_TABLE */ + + return EFI_SUCCESS; +} + +/** + * do_bootefi_exec() - execute EFI binary + * + * The image indicated by @handle is started. When it returns the allocated + * memory for the @load_options is freed. + * + * @handle: handle of loaded image + * @load_options: load options + * Return: status code + * + * Load the EFI binary into a newly assigned memory unwinding the relocation + * information, install the loaded image protocol, and call the binary. + */ +static efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options) +{ + efi_status_t ret; + efi_uintn_t exit_data_size = 0; + u16 *exit_data = NULL; + struct efi_event *evt; + + /* On ARM switch from EL3 or secure mode to EL2 or non-secure mode */ + switch_to_non_secure_mode(); + + /* + * The UEFI standard requires that the watchdog timer is set to five + * minutes when invoking an EFI boot option. + * + * Unified Extensible Firmware Interface (UEFI), version 2.7 Errata A + * 7.5. Miscellaneous Boot Services - EFI_BOOT_SERVICES.SetWatchdogTimer + */ + ret = efi_set_watchdog(300); + if (ret != EFI_SUCCESS) { + log_err("ERROR: Failed to set watchdog timer\n"); + goto out; + } + + /* Call our payload! */ + ret = EFI_CALL(efi_start_image(handle, &exit_data_size, &exit_data)); + if (ret != EFI_SUCCESS) { + log_err("## Application failed, r = %lu\n", + ret & ~EFI_ERROR_MASK); + if (exit_data) { + log_err("## %ls\n", exit_data); + efi_free_pool(exit_data); + } + } + + efi_restore_gd(); + +out: + free(load_options); + + if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) { + if (efi_initrd_deregister() != EFI_SUCCESS) + log_err("Failed to remove loadfile2 for initrd\n"); + } + + /* Notify EFI_EVENT_GROUP_RETURN_TO_EFIBOOTMGR event group. */ + list_for_each_entry(evt, &efi_events, link) { + if (evt->group && + !guidcmp(evt->group, + &efi_guid_event_group_return_to_efibootmgr)) { + efi_signal_event(evt); + EFI_CALL(systab.boottime->close_event(evt)); + break; + } + } + + /* Control is returned to U-Boot, disable EFI watchdog */ + efi_set_watchdog(0); + + return ret; +} + +/** + * efi_bootmgr_run() - execute EFI boot manager + * fdt: Flat device tree + * + * Invoke EFI boot manager and execute a binary depending on + * boot options. If @fdt is not NULL, it will be passed to + * the executed binary. + * + * Return: status code + */ +efi_status_t efi_bootmgr_run(void *fdt) +{ + efi_handle_t handle; + void *load_options; + efi_status_t ret; + + /* Initialize EFI drivers */ + ret = efi_init_obj_list(); + if (ret != EFI_SUCCESS) { + log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n", + ret & ~EFI_ERROR_MASK); + return CMD_RET_FAILURE; + } + + ret = efi_install_fdt(fdt); + if (ret != EFI_SUCCESS) + return ret; + + ret = efi_bootmgr_load(&handle, &load_options); + if (ret != EFI_SUCCESS) { + log_notice("EFI boot manager: Cannot load any image\n"); + return ret; + } + + return do_bootefi_exec(handle, load_options); +} + +/** + * efi_run_image() - run loaded UEFI image + * + * @source_buffer: memory address of the UEFI image + * @source_size: size of the UEFI image + * Return: status code + */ +efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size) +{ + efi_handle_t mem_handle = NULL, handle; + struct efi_device_path *file_path = NULL; + struct efi_device_path *msg_path; + efi_status_t ret, ret2; + u16 *load_options; + + if (!bootefi_device_path || !bootefi_image_path) { + log_debug("Not loaded from disk\n"); + /* + * Special case for efi payload not loaded from disk, + * such as 'bootefi hello' or for example payload + * loaded directly into memory via JTAG, etc: + */ + file_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, + (uintptr_t)source_buffer, + source_size); + /* + * Make sure that device for device_path exist + * in load_image(). Otherwise, shell and grub will fail. + */ + ret = efi_install_multiple_protocol_interfaces(&mem_handle, + &efi_guid_device_path, + file_path, NULL); + if (ret != EFI_SUCCESS) + goto out; + msg_path = file_path; + } else { + file_path = efi_dp_append(bootefi_device_path, + bootefi_image_path); + msg_path = bootefi_image_path; + log_debug("Loaded from disk\n"); + } + + log_info("Booting %pD\n", msg_path); + + ret = EFI_CALL(efi_load_image(false, efi_root, file_path, source_buffer, + source_size, &handle)); + if (ret != EFI_SUCCESS) { + log_err("Loading image failed\n"); + goto out; + } + + /* Transfer environment variable as load options */ + ret = efi_env_set_load_options(handle, "bootargs", &load_options); + if (ret != EFI_SUCCESS) + goto out; + + ret = do_bootefi_exec(handle, load_options); + +out: + ret2 = efi_uninstall_multiple_protocol_interfaces(mem_handle, + &efi_guid_device_path, + file_path, NULL); + efi_free_pool(file_path); + return (ret != EFI_SUCCESS) ? ret : ret2; +} + +/** + * efi_binary_run() - run loaded UEFI image + * + * @image: memory address of the UEFI image + * @size: size of the UEFI image + * + * Execute an EFI binary image loaded at @image. + * @size may be zero if the binary is loaded with U-Boot load command. + * + * Return: status code + */ +efi_status_t efi_binary_run(void *image, size_t size, void *fdt) +{ + efi_status_t ret; + + /* Initialize EFI drivers */ + ret = efi_init_obj_list(); + if (ret != EFI_SUCCESS) { + log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n", + ret & ~EFI_ERROR_MASK); + return -1; + } + + ret = efi_install_fdt(fdt); + if (ret != EFI_SUCCESS) + return ret; + + return efi_run_image(image, size); +} From patchwork Tue Nov 21 01:29:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 745674 Delivered-To: patch@linaro.org Received: by 2002:a5d:5052:0:b0:32d:baff:b0ca with SMTP id h18csp1628462wrt; Mon, 20 Nov 2023 17:33:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IERoiSeIXEGujxxnNQIlAq9QUGpTT84SoV389WHUu49+7mJ0+NWc7XzzDTRXuIM6B+1vUN3 X-Received: by 2002:a2e:9612:0:b0:2c6:ee90:5e6c with SMTP id v18-20020a2e9612000000b002c6ee905e6cmr6266506ljh.21.1700530408313; Mon, 20 Nov 2023 17:33:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700530408; cv=none; d=google.com; s=arc-20160816; b=eFsKNF9UXtmtOgN7bepkH/QnUb27tj/YweN4Y8tSl0hCST51oSvSx0NSZYVHImCNcS qJbR3P/U0MLuKI/uRNAtvJkFVb4wZ5Pb2C85YNHLH8cwPAxfNkjL9NPNfTL7NFLkT+c9 mz6XTeJ28kbG++qB2XaI51+bIixfBlPxhH6v4iz5z7oIUIIftmyM1csTtXeF0yp4V83k r+EBvz2E2Mq24fP5tWL1BTNWuC8lAgEMPWo4UwQXK/pFlNatSZx7+x3czrBL6jMdaoiX fa1yjK539ccvUnKTErxvmGat5W/JFWb1LzQRkWGTa2VNk0NdMcIFsJHXCDj1a9iLb4iy hkDw== 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=i0pOwWKtyCvU6lfQQoNXU/mUJNM6UWiWzauvvCP1A+4=; fh=p8OTi/tJSbfUA0ykVxDxRCnpqUhQqJazFYHXT9edm5U=; b=FEGtstM6mBJw1OafDUX52UvRQSr3Xu/U8SN0CuZBnIL322QJZrUsBF9hsdjEUFzrtg SWyEHBMBu/469KCcZMA9S9C0k3yOfsDrJ5Tc3uWfqW44hkubKxW1+3KroBfkX7wYN99p AI+MXWsCqoZQ38iBZYmqLDPQXTuuRlTBC9C5G62E+oFOuk81jf7/CXBRPl0l5STQX8HQ SWjaWVMjj+lslAag8wxtVPTcMWgn6tinKaRLxatvhv5Mv+B6FeWfLcJRiT5U2TIeWyoM 3ApjVoc3O04P+Nt9W1+7AeLDu/fV3/okQDbkYMcNpbZlcsmU+6yUe032ohMuD0sfOTm4 9AOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BXL6HbPT; 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 ji14-20020a170907980e00b009ffcd59375dsi1148555ejc.309.2023.11.20.17.33.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:33:28 -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=BXL6HbPT; 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 E4591875B8; Tue, 21 Nov 2023 02:31:21 +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="BXL6HbPT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CA0CB875A4; Tue, 21 Nov 2023 02:31:16 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) (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 A1A4C875AA for ; Tue, 21 Nov 2023 02:30: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=takahiro.akashi@linaro.org Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1cc4d306fe9so11476555ad.0 for ; Mon, 20 Nov 2023 17:30:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700530247; x=1701135047; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i0pOwWKtyCvU6lfQQoNXU/mUJNM6UWiWzauvvCP1A+4=; b=BXL6HbPTEUuTKZc/3A3kDXzI/X+K+dwqtL3xIzu6fd/MAOO6xbVLOmIfvrZjIiNjsE yzWghdEGMfPhBkAab/Sj3IIDfN02db+y5eM1MAHLIiSfvxlTPUrRkPPGhY9Nzsc/ei4h YyeFJxVFglOs+Xbk5VrKJZtkBUL1htoKKk/pnu8g/Qu/drfhnPOqHYWBKFaCYJOOb91U YU3q1iYxmE9DFbjCBDMrnu3oS5U2sWY7m4SmYdSrJ7oB+YSJZnsOUaRW9xMQX2ukSL++ pUp3vpODnuy/MEDYc6pojS3xbG/Iwx6Rbt5DQcE/1HlR01axihuO+OWvjCQUJmhn4qmv FE5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700530247; x=1701135047; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i0pOwWKtyCvU6lfQQoNXU/mUJNM6UWiWzauvvCP1A+4=; b=VzokBusaGAJgQdyovDLtXK3jTElA7pXHmCgPkiwgLAMQ619wBny0P8ddL4QVL2L5IS Pk4hsE4N0u0smMCa9qk3M/i4mWxO3Gcvyin8jrkfd+na4o0MKwCNHdVy6zPlwkoZ9s4d R9eXolREfxVpcpPblkk+Tdytg87qrlzGk1UJslQ0q6r2iCoaRih2auo4gKxtxdL2At/v +kSL7tsNgVMdGfUVln6G2uE3u74Sa3lQ8w04n6s5o1N2h9JBAivVxT1rlBeRSZQNq7aF Wc7rL7hWP0NwK+ENVZ0l6YW0GXMBZN+rnm9aqaxt3JhDtx+oopvA4jlJYoaynD5zX0Cz 08Ew== X-Gm-Message-State: AOJu0YwhhtfQxd+E8RcNZHNwjngI3fxWLCu4eRu2Lu2mYZFXjpvbxY2c VUt58ChfCbLgxKpnrSz3wktrEg== X-Received: by 2002:a17:902:d48c:b0:1ce:5b6e:bae1 with SMTP id c12-20020a170902d48c00b001ce5b6ebae1mr11892980plg.3.1700530246913; Mon, 20 Nov 2023 17:30:46 -0800 (PST) Received: from octopus.. ([2400:4050:c3e1:100:f6af:a59c:7ca:897f]) by smtp.gmail.com with ESMTPSA id e9-20020a170902d38900b001c8a0879805sm3612508pld.206.2023.11.20.17.30.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:30:46 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org, xypron.glpk@gmx.de, ilias.apalodimas@linaro.org Cc: u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v2 07/12] cmd: efidebug: ease efi configuration dependency Date: Tue, 21 Nov 2023 10:29:45 +0900 Message-Id: <20231121012950.156539-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121012950.156539-1-takahiro.akashi@linaro.org> References: <20231121012950.156539-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean Now it is clear that the command actually depends on interfaces, not "bootefi bootmgr" command. Signed-off-by: AKASHI Takahiro --- cmd/efidebug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 78ef16f4cb5c..e10fbf891a42 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -1410,7 +1410,7 @@ static __maybe_unused int do_efi_test_bootmgr(struct cmd_tbl *cmdtp, int flag, } static struct cmd_tbl cmd_efidebug_test_sub[] = { -#ifdef CONFIG_CMD_BOOTEFI_BOOTMGR +#ifdef CONFIG_BOOTEFI_BOOTMGR U_BOOT_CMD_MKENT(bootmgr, CONFIG_SYS_MAXARGS, 1, do_efi_test_bootmgr, "", ""), #endif @@ -1604,7 +1604,7 @@ U_BOOT_LONGHELP(efidebug, " - show UEFI memory map\n" "efidebug tables\n" " - show UEFI configuration tables\n" -#ifdef CONFIG_CMD_BOOTEFI_BOOTMGR +#ifdef CONFIG_BOOTEFI_BOOTMGR "efidebug test bootmgr\n" " - run simple bootmgr for test\n" #endif From patchwork Tue Nov 21 01:29:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 745676 Delivered-To: patch@linaro.org Received: by 2002:a5d:5052:0:b0:32d:baff:b0ca with SMTP id h18csp1628637wrt; Mon, 20 Nov 2023 17:34:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFUbSBs2JJ11g91SgsDMaTMm0GOAMxb8Bqie0hofumT8+s3j/+NpVnfBbmsNc4mK9jfZuDm X-Received: by 2002:a05:6402:33a:b0:548:7a6f:b51e with SMTP id q26-20020a056402033a00b005487a6fb51emr677675edw.14.1700530440562; Mon, 20 Nov 2023 17:34:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700530440; cv=none; d=google.com; s=arc-20160816; b=I9QfmaPBNr1gz9VdlwXJ8BM8+zt3/i2zeefLqniCedbOC63hVr8Jqw5YzXDtHH8UE0 +qiSDxDNKhe7XLpjt/g24R5KoHKOXtouqd/EA7aCR9J7xsI9aJs4pbna+A+VVHfSJyPH h2Y1I9ftVkbqt3AMGcj2DpdrLRz/cjwO2AyEhp+do3PlMRHJMYj9a1pBNFlZqFgapsIe KEtfjnCbtzYY38EoMNZE5hgKrazci1/zREJjbJdCqMpABlxk4U/L0QBxtbiaDuhyiI0d yXTz6V3x3jJXbQRdIRX9Vvc8ZZsoitBgAJMdA1Vy7Azjewj+fVV/6mm9UlD1Z8jLhoBm +BAA== 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=cjbRHjiZr+w34RNHzCx/XM1Riu2LAgDdjh0G8y9lKfI=; fh=p8OTi/tJSbfUA0ykVxDxRCnpqUhQqJazFYHXT9edm5U=; b=sF43CjkiJg6eqbn7mHcZTo574WKFWjb6iTDVOsixGKbR5MwTMa0g5ErG8b6VQvpg46 5Vu9dwEUQewQlOcE7bBPSmzCUP9+IrWP5BNL44mko6a2Nj9C54XcevvOeYKmJ6Ii9QE5 NJdXotfnsaEOoA78leVBRjIV+FYyixaocRM9IDIwxXHpGrhGw03ZTlEbhTeIUJKDRhMi 2SDSh71PWaPcMgU15k9XuGCtYY/y6p0blB5J1Km5yw/cpP+JhQVINAS4w8oaCgTR+pWl qyt/v71K3okSKHtgO3h2VkikIQEsq1K1yL/q7Udgg9SOsbLhAJImFm/MAYJaL0TF89BR o7HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rk3jxiZJ; 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 m13-20020aa7c2cd000000b00548e56c33f4si697461edp.515.2023.11.20.17.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:34:00 -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=Rk3jxiZJ; 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 9384C875BE; Tue, 21 Nov 2023 02:31:39 +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="Rk3jxiZJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CDD4B875B9; Tue, 21 Nov 2023 02:31:36 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) (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 64ACE864F3 for ; Tue, 21 Nov 2023 02:31:21 +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=takahiro.akashi@linaro.org Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1cc2b8deb23so10682195ad.1 for ; Mon, 20 Nov 2023 17:31:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700530249; x=1701135049; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cjbRHjiZr+w34RNHzCx/XM1Riu2LAgDdjh0G8y9lKfI=; b=Rk3jxiZJcUvVkfiVnmqJXFAHVLezt2guSk0uaeiAGCKvTzPTRCcyh1NGOx25lRxB4C 2jK6pfl1y21zZlNtWhEY+nd3H4kznQ1HruMPWJ+p+ZS6VAp9dlppcrnKJKJncwIxBKym 8L8LTyt/6JuSKMvuVvuMgzdomJJ2pZzw/BAlZ0i5fHs8NYzYpVkMr9MPVdpqPLCV/sby ziSo1ZUWgxqBOI5xcXK4derqYRgQ/zDRkK3sf/qJjL6CDXMkzVxxiwuaSMA74T9TjX63 SzVwhrt+udWDbiYojYBw11EaEgLp5ui9H4xOlbngGCK3CwT62Yb/E5PPOEBmVTB+rrVn 9oYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700530249; x=1701135049; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cjbRHjiZr+w34RNHzCx/XM1Riu2LAgDdjh0G8y9lKfI=; b=O+IYLp8mL0PTo7U4aqAJFjzonbwrA3SF61yrHRBhq75veBSEPle8jLMksAOkrS1LaF RXVIathyq2RQyUS74cTbRdEjJqAAq5VVGuoUBoWu5BXQHmy5j+AxhE4PluH51t4h+OHZ Dn2yzM9WQUaxO/Aedt2SdYScUrm+ucyrXcb8r258Xz7oJBBEoyQ3LFJZ58CPuje8ckQz onrVdwDZjlOwfJQyFx/tW0UYl+LeBUOMcCl+lQealj+3o+qzQY9dfyVC5kPSu7PhXLZC w4NfriV4I+h84Buhv9ktq099CKKtr5c+8JuvoUhAMZrp/dfyCiNrQQmD2H3KCK7RfSRn 13Wg== X-Gm-Message-State: AOJu0Yz9szaolgL7U7KQgYUd4xiGsFkRJDc/BesZ5ojesFjxj3qpdBYe VrVH7dbgtDs4Mbiv7cTGpiKP+A== X-Received: by 2002:a17:902:e74b:b0:1cc:32c6:e5fa with SMTP id p11-20020a170902e74b00b001cc32c6e5famr11565064plf.6.1700530249078; Mon, 20 Nov 2023 17:30:49 -0800 (PST) Received: from octopus.. ([2400:4050:c3e1:100:f6af:a59c:7ca:897f]) by smtp.gmail.com with ESMTPSA id e9-20020a170902d38900b001c8a0879805sm3612508pld.206.2023.11.20.17.30.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:30:48 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org, xypron.glpk@gmx.de, ilias.apalodimas@linaro.org Cc: u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v2 08/12] bootmeth: use efi_loader interfaces instead of bootefi command Date: Tue, 21 Nov 2023 10:29:46 +0900 Message-Id: <20231121012950.156539-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121012950.156539-1-takahiro.akashi@linaro.org> References: <20231121012950.156539-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean Now that efi_loader subsystem provides interfaces that are equivalent with bootefi command, we can replace command invocations with APIs. Signed-off-by: AKASHI Takahiro --- boot/Kconfig | 4 ++-- boot/Makefile | 2 +- boot/bootm_os.c | 31 +++++++------------------------ boot/bootmeth_efi.c | 8 +------- boot/bootmeth_efi_mgr.c | 2 +- cmd/Kconfig | 2 +- test/boot/bootflow.c | 2 +- 7 files changed, 14 insertions(+), 37 deletions(-) diff --git a/boot/Kconfig b/boot/Kconfig index ef71883a5026..e879c63b84e3 100644 --- a/boot/Kconfig +++ b/boot/Kconfig @@ -511,7 +511,7 @@ config BOOTMETH_EXTLINUX_PXE config BOOTMETH_EFILOADER bool "Bootdev support for EFI boot" - depends on CMD_BOOTEFI + depends on BOOTEFI_BOOTMGR default y help Enables support for EFI boot using bootdevs. This makes the @@ -546,7 +546,7 @@ config BOOTMETH_DISTRO select BOOTMETH_SCRIPT if CMDLINE # E.g. Armbian uses scripts select BOOTMETH_EXTLINUX # E.g. Debian uses these select BOOTMETH_EXTLINUX_PXE if CMD_PXE && CMD_NET && DM_ETH - select BOOTMETH_EFILOADER if CMD_BOOTEFI # E.g. Ubuntu uses this + select BOOTMETH_EFILOADER if BOOTEFI_BOOTMGR # E.g. Ubuntu uses this config SPL_BOOTMETH_VBE bool "Bootdev support for Verified Boot for Embedded (SPL)" diff --git a/boot/Makefile b/boot/Makefile index 3fd048bb41ab..4eaa5eab4b77 100644 --- a/boot/Makefile +++ b/boot/Makefile @@ -32,7 +32,7 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_CROS) += bootm.o bootm_os.o bootmeth_cros.o obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_SANDBOX) += bootmeth_sandbox.o obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_SCRIPT) += bootmeth_script.o ifdef CONFIG_$(SPL_TPL_)BOOTSTD_FULL -obj-$(CONFIG_CMD_BOOTEFI_BOOTMGR) += bootmeth_efi_mgr.o +obj-$(CONFIG_BOOTEFI_BOOTMGR) += bootmeth_efi_mgr.o obj-$(CONFIG_$(SPL_TPL_)EXPO) += bootflow_menu.o obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootflow_menu.o obj-$(CONFIG_$(SPL_TPL_)CEDIT) += cedit.o diff --git a/boot/bootm_os.c b/boot/bootm_os.c index 30296eb27d7d..c2f39cdf3f36 100644 --- a/boot/bootm_os.c +++ b/boot/bootm_os.c @@ -487,7 +487,6 @@ static int do_bootm_efi(int flag, int argc, char *const argv[], struct bootm_headers *images) { int ret; - efi_status_t efi_ret; void *image_buf; if (flag != BOOTM_STATE_OS_GO) @@ -498,37 +497,21 @@ static int do_bootm_efi(int flag, int argc, char *const argv[], if (ret) return ret; - /* Initialize EFI drivers */ - efi_ret = efi_init_obj_list(); - if (efi_ret != EFI_SUCCESS) { - printf("## Failed to initialize UEFI sub-system: r = %lu\n", - efi_ret & ~EFI_ERROR_MASK); - return 1; - } + /* We expect to return */ + images->os.type = IH_TYPE_STANDALONE; - /* Install device tree */ - efi_ret = efi_install_fdt(images->ft_len - ? images->ft_addr : EFI_FDT_USE_INTERNAL); - if (efi_ret != EFI_SUCCESS) { - printf("## Failed to install device tree: r = %lu\n", - efi_ret & ~EFI_ERROR_MASK); - return 1; - } + image_buf = map_sysmem(images->ep, images->os.image_len); /* Run EFI image */ printf("## Transferring control to EFI (at address %08lx) ...\n", images->ep); bootstage_mark(BOOTSTAGE_ID_RUN_OS); - /* We expect to return */ - images->os.type = IH_TYPE_STANDALONE; - - image_buf = map_sysmem(images->ep, images->os.image_len); + ret = efi_binary_run(image_buf, images->os.image_len, + images->ft_len + ? images->ft_addr : EFI_FDT_USE_INTERNAL); - efi_ret = efi_run_image(image_buf, images->os.image_len); - if (efi_ret != EFI_SUCCESS) - return 1; - return 0; + return ret; } #endif diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c index ae936c8daa18..2a9f29f9db5a 100644 --- a/boot/bootmeth_efi.c +++ b/boot/bootmeth_efi.c @@ -412,7 +412,6 @@ static int distro_efi_read_bootflow(struct udevice *dev, struct bootflow *bflow) static int distro_efi_boot(struct udevice *dev, struct bootflow *bflow) { ulong kernel, fdt; - char cmd[50]; int ret; kernel = env_get_hex("kernel_addr_r", 0); @@ -441,12 +440,7 @@ static int distro_efi_boot(struct udevice *dev, struct bootflow *bflow) fdt = env_get_hex("fdt_addr_r", 0); } - /* - * At some point we can add a real interface to bootefi so we can call - * this directly. For now, go through the CLI, like distro boot. - */ - snprintf(cmd, sizeof(cmd), "bootefi %lx %lx", kernel, fdt); - if (run_command(cmd, 0)) + if (efi_binary_run(map_sysmem(kernel, 0), 0, map_sysmem(fdt, 0))) return log_msg_ret("run", -EINVAL); return 0; diff --git a/boot/bootmeth_efi_mgr.c b/boot/bootmeth_efi_mgr.c index e6c42d41fb80..5f6f68e423e6 100644 --- a/boot/bootmeth_efi_mgr.c +++ b/boot/bootmeth_efi_mgr.c @@ -85,7 +85,7 @@ static int efi_mgr_boot(struct udevice *dev, struct bootflow *bflow) int ret; /* Booting is handled by the 'bootefi bootmgr' command */ - ret = run_command("bootefi bootmgr", 0); + ret = efi_bootmgr_run(EFI_FDT_USE_INTERNAL); return 0; } diff --git a/cmd/Kconfig b/cmd/Kconfig index 4cf9a210c4a1..dc4ea48f78bc 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -273,7 +273,7 @@ config CMD_BOOTMETH config BOOTM_EFI bool "Support booting UEFI FIT images" - depends on CMD_BOOTEFI && CMD_BOOTM && FIT + depends on BOOTEFI_BOOTMGR && CMD_BOOTM && FIT default y help Support booting UEFI FIT images via the bootm command. diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index f640db8a2418..fa1bebdd02da 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -374,7 +374,7 @@ static int bootflow_system(struct unit_test_state *uts) { struct udevice *bootstd, *dev; - if (!IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) + if (!IS_ENABLED(CONFIG_BOOTEFI_BOOTMGR)) return -EAGAIN; ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); ut_assertok(device_bind(bootstd, DM_DRIVER_GET(bootmeth_efi_mgr), From patchwork Tue Nov 21 01:29:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 745680 Delivered-To: patch@linaro.org Received: by 2002:a5d:5052:0:b0:32d:baff:b0ca with SMTP id h18csp1629046wrt; Mon, 20 Nov 2023 17:35:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IFXrVr9ESEkmHNDrwxXyMoCpaud+oc0x/u3KDdeK9nRyxtJ0dIf7jmAxh2/O+WfxGhMTJ+r X-Received: by 2002:a05:6402:2692:b0:549:37e:8b2f with SMTP id w18-20020a056402269200b00549037e8b2fmr111028edd.0.1700530526221; Mon, 20 Nov 2023 17:35:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700530526; cv=none; d=google.com; s=arc-20160816; b=csCNqnMrPPvzGFOf8/P+9iNI6BkeM0VPg8LhR7hu2nhBWvx7+CK99udNWF8sT7e8vT tfJvn2rCpMnX5G92j5++gpHuVH9UKG0h2w6fYgOAfCtG/W7yjT6ZupTTrqNJN9IqQyga EWxCLFb6Izv+VrKLmCAMCOq79QKpwYfWsQ6xxQMPm+XKYkeJ3BYt1fVoKsZ0IPsTI7Uw fQ7bgzXWgL3VDf78tfE4A2h2hJWXKCcTgg5O9o+N+cEKU7cTUvXCdIWefMh5ftC8CG4e X9gnGAQiI+SjSB2MklsyZ+Z3hZ5gMOW2Oab3kLf5WtoAfAa32V6q+eHcv7f8RmZhbMev wemg== 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=hj7xGbXh/3x3XPgzbdBZv9iipG0M3VTUpOWSlqb9nnY=; fh=p8OTi/tJSbfUA0ykVxDxRCnpqUhQqJazFYHXT9edm5U=; b=mJ0kgGBaNuVtIpOKV9PmjHdfdDl+bkruuXRgMM5VhZl33kTlpTUD5DU+JEusXJ0Bd8 NScbdayqoaE9Cg01ataIAn3jzPeqyBRU6iEBgwZ+oYtLJBc5k8p+4D5bK0L9K/S/IJH+ GRAS461Sx4+RtNaNADISCv5Dy386mGcG4fWw+/+4tDRQBcEkf32uoK6MYcN+8imbW5pm yG5TWAG1mnAf2Zw8qYUzIYDm1K3dTRQiuEwMVVrAFHWk7DqtZDOHZXh8Rm8qbc2qgtz8 Sg2l12muynJwBplKsRzSXoVfzPEusUz9GpLeNQepL9rTOAKcIec+rjg6OQhEYJA//8Rt KGjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="G/vRbId6"; 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 a15-20020a50e70f000000b00537fdb2a284si5468777edn.550.2023.11.20.17.35.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:35:26 -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="G/vRbId6"; 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 46A35875E0; Tue, 21 Nov 2023 02:32: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="G/vRbId6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9E826875C3; Tue, 21 Nov 2023 02:31:46 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) (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 A13FB875B5 for ; Tue, 21 Nov 2023 02:31:21 +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=takahiro.akashi@linaro.org Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1cf61775439so2875845ad.0 for ; Mon, 20 Nov 2023 17:31:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700530251; x=1701135051; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hj7xGbXh/3x3XPgzbdBZv9iipG0M3VTUpOWSlqb9nnY=; b=G/vRbId6uGyxOIkd3qxR1Q4o3h2gR4eqeF7/f3Smeejo5gqSfDU8kM78VcP5k6KVRH wUj9GyVOtD9t0qiEJqQVklcboYYsLTyvdXLlS4bSr1Kz7VJ+NFgrSaQtbDpP4cEyNjfb C/oSxqzUNOTR8VPmyM62fWat+CP6oz0pLnWO3QK5YkCUghM/Tvi0fAHP65ntPjKgf3cV +WHo3M2stHhn2I/gBnDZTU0YYsMSTz6YwSegUOx8vxilpBAbb1p3vaGl7m/EXUM4eKQo nGz2cd4UI6rmVRu5eFXWjFR+KAlcmKdLy2WUeMe7CxULdX4kcO6LOlSBBj4oWJr5bcsr remw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700530251; x=1701135051; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hj7xGbXh/3x3XPgzbdBZv9iipG0M3VTUpOWSlqb9nnY=; b=WKRDLv9F9q9kCfvibtd8xzLHdMmtI9qzK5AUwZesNfL4Np0ZtxfTGUm7BCo8+fQT2Q j8ZRO6Z51XUiuNKfWX3Pn4iORC9jIpVf57FhVWFpL5CTCy7BAvpi4tkVGEg4b/uB6Nlt Tp7JoKARKndQ/WYIcXwf3rAHRR8IWOVQuBNUuP7PIws0nv+wiGeFJcH9FhGIubIf1k1p NYfvEcyw4DZmG8fiQ6ygqQcwBA0Y4UdqpTF1smtueiFXm1UVeSf0jTZgfDdIBlT2sR4S CI/PIOMrErPh+h2SOuTTfsHdB8m/9F0MLMMRiESOCht48yDXjh9CLcBERhoMJGZV8dLd CxvQ== X-Gm-Message-State: AOJu0YxTlueW3+GFluADeovZHjrXLp11B49Z0LZzjRxSrtGf2cHC58Et VQAky3cEZ3LzNLkuEvyPsvXhDw== X-Received: by 2002:a17:902:d4cc:b0:1cf:636f:1bbc with SMTP id o12-20020a170902d4cc00b001cf636f1bbcmr4209346plg.4.1700530251188; Mon, 20 Nov 2023 17:30:51 -0800 (PST) Received: from octopus.. ([2400:4050:c3e1:100:f6af:a59c:7ca:897f]) by smtp.gmail.com with ESMTPSA id e9-20020a170902d38900b001c8a0879805sm3612508pld.206.2023.11.20.17.30.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:30:50 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org, xypron.glpk@gmx.de, ilias.apalodimas@linaro.org Cc: u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v2 09/12] efi_loader: split unrelated code from efi_bootmgr.c Date: Tue, 21 Nov 2023 10:29:47 +0900 Message-Id: <20231121012950.156539-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121012950.156539-1-takahiro.akashi@linaro.org> References: <20231121012950.156539-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean Some code moved from cmd/bootefi.c is actually necessary only for "bootefi " command (starting an image manually loaded by a user using U-Boot load commands or other methods (like JTAG debugger). The code will never been opted out as unused code by a compiler which doesn't know how EFI boot manager is implemented. So introduce a new configuration, CONFIG_EFI_BINARY_EXEC, to enforce theem opted out explicitly. Signed-off-by: AKASHI Takahiro --- boot/Kconfig | 4 +- cmd/Kconfig | 6 +- include/efi_loader.h | 28 +- lib/efi_loader/Kconfig | 9 + lib/efi_loader/efi_bootmgr.c | 492 ------------------------------ lib/efi_loader/efi_device_path.c | 3 +- lib/efi_loader/efi_helper.c | 498 ++++++++++++++++++++++++++++++- 7 files changed, 528 insertions(+), 512 deletions(-) diff --git a/boot/Kconfig b/boot/Kconfig index e879c63b84e3..dddc53766bb9 100644 --- a/boot/Kconfig +++ b/boot/Kconfig @@ -511,7 +511,7 @@ config BOOTMETH_EXTLINUX_PXE config BOOTMETH_EFILOADER bool "Bootdev support for EFI boot" - depends on BOOTEFI_BOOTMGR + depends on EFI_BINARY_EXEC default y help Enables support for EFI boot using bootdevs. This makes the @@ -546,7 +546,7 @@ config BOOTMETH_DISTRO select BOOTMETH_SCRIPT if CMDLINE # E.g. Armbian uses scripts select BOOTMETH_EXTLINUX # E.g. Debian uses these select BOOTMETH_EXTLINUX_PXE if CMD_PXE && CMD_NET && DM_ETH - select BOOTMETH_EFILOADER if BOOTEFI_BOOTMGR # E.g. Ubuntu uses this + select BOOTMETH_EFILOADER if EFI_BINARY_EXEC # E.g. Ubuntu uses this config SPL_BOOTMETH_VBE bool "Bootdev support for Verified Boot for Embedded (SPL)" diff --git a/cmd/Kconfig b/cmd/Kconfig index dc4ea48f78bc..189ea6003293 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -273,7 +273,7 @@ config CMD_BOOTMETH config BOOTM_EFI bool "Support booting UEFI FIT images" - depends on BOOTEFI_BOOTMGR && CMD_BOOTM && FIT + depends on EFI_BINARY_EXEC && CMD_BOOTM && FIT default y help Support booting UEFI FIT images via the bootm command. @@ -365,7 +365,7 @@ config CMD_BOOTEFI if CMD_BOOTEFI config CMD_BOOTEFI_BINARY bool "Allow booting an EFI binary directly" - depends on BOOTEFI_BOOTMGR + depends on EFI_BINARY_EXEC default y help Select this option to enable direct execution of binary at 'bootefi'. @@ -396,7 +396,7 @@ config CMD_BOOTEFI_HELLO_COMPILE config CMD_BOOTEFI_HELLO bool "Allow booting a standard EFI hello world for testing" - depends on CMD_BOOTEFI_HELLO_COMPILE + depends on CMD_BOOTEFI_BINARY && CMD_BOOTEFI_HELLO_COMPILE default y if CMD_BOOTEFI_SELFTEST help This adds a standard EFI hello world application to U-Boot so that diff --git a/include/efi_loader.h b/include/efi_loader.h index 34e7fbbf1840..484c9fad239f 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -90,11 +90,7 @@ efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len); * back to u-boot world */ void efi_restore_gd(void); -/* Call this to unset the current device name */ -void efi_clear_bootdev(void); -/* Call this to set the current device name */ -void efi_set_bootdev(const char *dev, const char *devnr, const char *path, - void *buffer, size_t buffer_size); + /* Called by networking code to memorize the dhcp ack package */ void efi_net_set_dhcp_ack(void *pkt, int len); /* Print information about all loaded images */ @@ -116,10 +112,6 @@ static inline efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len) /* No loader configured, stub out EFI_ENTRY */ static inline void efi_restore_gd(void) { } -static inline void efi_clear_bootdev(void) { } -static inline void efi_set_bootdev(const char *dev, const char *devnr, - const char *path, void *buffer, - size_t buffer_size) { } static inline void efi_net_set_dhcp_ack(void *pkt, int len) { } static inline void efi_print_image_infos(void *pc) { } static inline efi_status_t efi_launch_capsules(void) @@ -129,6 +121,20 @@ static inline efi_status_t efi_launch_capsules(void) #endif /* CONFIG_IS_ENABLED(EFI_LOADER) */ +#if CONFIG_IS_ENABLED(EFI_BINARY_EXEC) +/* Call this to unset the current device name */ +void efi_clear_bootdev(void); +/* Call this to set the current device name */ +void efi_set_bootdev(const char *dev, const char *devnr, const char *path, + void *buffer, size_t buffer_size); +#else +static inline void efi_clear_bootdev(void) { } + +static inline void efi_set_bootdev(const char *dev, const char *devnr, + const char *path, void *buffer, + size_t buffer_size) { } +#endif + /* Maximum number of configuration tables */ #define EFI_MAX_CONFIGURATION_TABLES 16 @@ -541,8 +547,8 @@ efi_status_t efi_env_set_load_options(efi_handle_t handle, const char *env_var, u16 **load_options); /* Install device tree */ efi_status_t efi_install_fdt(void *fdt); -/* Run loaded UEFI image */ -efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size); +/* Execute loaded UEFI image */ +efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options); /* Run loaded UEFI image with given fdt */ efi_status_t efi_binary_run(void *image, size_t size, void *fdt); /* Initialize variable services */ diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 2913d1c9dfe7..ddb1a012a761 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -32,6 +32,15 @@ config EFI_LOADER if EFI_LOADER +config EFI_BINARY_EXEC + bool "Execute UEFI binary" + default y + help + Select this option if you want to execute the UEFI binary after + loading it with U-Boot load commands or other methods. + You may enable CMD_BOOTEFI_BINARY so that you can use bootefi + command to do that. + config BOOTEFI_BOOTMGR bool "UEFI Boot Manager" default y diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index e910f1bb2a23..3d70c643f895 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -3,8 +3,6 @@ * EFI boot manager * * Copyright (c) 2017 Rob Clark - * For the code moved from cmd/bootefi.c - * Copyright (c) 2016 Alexander Graf */ #define LOG_CATEGORY LOGC_EFI @@ -22,17 +20,6 @@ #include #include -/* TODO: temporarily added here; clean up later */ -#include -#include -#include -#include -#include -#include -#include - -DECLARE_GLOBAL_DATA_PTR; - static const struct efi_boot_services *bs; static const struct efi_runtime_services *rs; @@ -1129,389 +1116,6 @@ out: return ret; } -static struct efi_device_path *bootefi_image_path; -static struct efi_device_path *bootefi_device_path; -static void *image_addr; -static size_t image_size; - -/** - * efi_get_image_parameters() - return image parameters - * - * @img_addr: address of loaded image in memory - * @img_size: size of loaded image - */ -void efi_get_image_parameters(void **img_addr, size_t *img_size) -{ - *img_addr = image_addr; - *img_size = image_size; -} - -/** - * efi_clear_bootdev() - clear boot device - */ -void efi_clear_bootdev(void) -{ - efi_free_pool(bootefi_device_path); - efi_free_pool(bootefi_image_path); - bootefi_device_path = NULL; - bootefi_image_path = NULL; - image_addr = NULL; - image_size = 0; -} - -/** - * efi_set_bootdev() - set boot device - * - * This function is called when a file is loaded, e.g. via the 'load' command. - * We use the path to this file to inform the UEFI binary about the boot device. - * - * @dev: device, e.g. "MMC" - * @devnr: number of the device, e.g. "1:2" - * @path: path to file loaded - * @buffer: buffer with file loaded - * @buffer_size: size of file loaded - */ -void efi_set_bootdev(const char *dev, const char *devnr, const char *path, - void *buffer, size_t buffer_size) -{ - struct efi_device_path *device, *image; - efi_status_t ret; - - log_debug("dev=%s, devnr=%s, path=%s, buffer=%p, size=%zx\n", dev, - devnr, path, buffer, buffer_size); - - /* Forget overwritten image */ - if (buffer + buffer_size >= image_addr && - image_addr + image_size >= buffer) - efi_clear_bootdev(); - - /* Remember only PE-COFF and FIT images */ - if (efi_check_pe(buffer, buffer_size, NULL) != EFI_SUCCESS) { - if (IS_ENABLED(CONFIG_FIT) && - !fit_check_format(buffer, IMAGE_SIZE_INVAL)) { - /* - * FIT images of type EFI_OS are started via command - * bootm. We should not use their boot device with the - * bootefi command. - */ - buffer = 0; - buffer_size = 0; - } else { - log_debug("- not remembering image\n"); - return; - } - } - - /* efi_set_bootdev() is typically called repeatedly, recover memory */ - efi_clear_bootdev(); - - image_addr = buffer; - image_size = buffer_size; - - ret = efi_dp_from_name(dev, devnr, path, &device, &image); - if (ret == EFI_SUCCESS) { - bootefi_device_path = device; - if (image) { - /* FIXME: image should not contain device */ - struct efi_device_path *image_tmp = image; - - efi_dp_split_file_path(image, &device, &image); - efi_free_pool(image_tmp); - } - bootefi_image_path = image; - log_debug("- boot device %pD\n", device); - if (image) - log_debug("- image %pD\n", image); - } else { - log_debug("- efi_dp_from_name() failed, err=%lx\n", ret); - efi_clear_bootdev(); - } -} - -/** - * efi_env_set_load_options() - set load options from environment variable - * - * @handle: the image handle - * @env_var: name of the environment variable - * @load_options: pointer to load options (output) - * Return: status code - */ -efi_status_t efi_env_set_load_options(efi_handle_t handle, - const char *env_var, - u16 **load_options) -{ - const char *env = env_get(env_var); - size_t size; - u16 *pos; - efi_status_t ret; - - *load_options = NULL; - if (!env) - return EFI_SUCCESS; - size = sizeof(u16) * (utf8_utf16_strlen(env) + 1); - pos = calloc(size, 1); - if (!pos) - return EFI_OUT_OF_RESOURCES; - *load_options = pos; - utf8_utf16_strcpy(&pos, env); - ret = efi_set_load_options(handle, size, *load_options); - if (ret != EFI_SUCCESS) { - free(*load_options); - *load_options = NULL; - } - return ret; -} - -#if !CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) - -/** - * copy_fdt() - Copy the device tree to a new location available to EFI - * - * The FDT is copied to a suitable location within the EFI memory map. - * Additional 12 KiB are added to the space in case the device tree needs to be - * expanded later with fdt_open_into(). - * - * @fdtp: On entry a pointer to the flattened device tree. - * On exit a pointer to the copy of the flattened device tree. - * FDT start - * Return: status code - */ -static efi_status_t copy_fdt(void **fdtp) -{ - unsigned long fdt_ram_start = -1L, fdt_pages; - efi_status_t ret = 0; - void *fdt, *new_fdt; - u64 new_fdt_addr; - uint fdt_size; - int i; - - for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { - u64 ram_start = gd->bd->bi_dram[i].start; - u64 ram_size = gd->bd->bi_dram[i].size; - - if (!ram_size) - continue; - - if (ram_start < fdt_ram_start) - fdt_ram_start = ram_start; - } - - /* - * Give us at least 12 KiB of breathing room in case the device tree - * needs to be expanded later. - */ - fdt = *fdtp; - fdt_pages = efi_size_in_pages(fdt_totalsize(fdt) + 0x3000); - fdt_size = fdt_pages << EFI_PAGE_SHIFT; - - ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, - EFI_ACPI_RECLAIM_MEMORY, fdt_pages, - &new_fdt_addr); - if (ret != EFI_SUCCESS) { - log_err("ERROR: Failed to reserve space for FDT\n"); - goto done; - } - new_fdt = (void *)(uintptr_t)new_fdt_addr; - memcpy(new_fdt, fdt, fdt_totalsize(fdt)); - fdt_set_totalsize(new_fdt, fdt_size); - - *fdtp = (void *)(uintptr_t)new_fdt_addr; -done: - return ret; -} - -/** - * get_config_table() - get configuration table - * - * @guid: GUID of the configuration table - * Return: pointer to configuration table or NULL - */ -static void *get_config_table(const efi_guid_t *guid) -{ - size_t i; - - for (i = 0; i < systab.nr_tables; i++) { - if (!guidcmp(guid, &systab.tables[i].guid)) - return systab.tables[i].table; - } - return NULL; -} - -#endif /* !CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) */ - -/** - * efi_install_fdt() - install device tree - * - * If fdt is not EFI_FDT_USE_INTERNAL, the device tree located at that memory - * address will be installed as configuration table, otherwise the device - * tree located at the address indicated by environment variable fdt_addr or as - * fallback fdtcontroladdr will be used. - * - * On architectures using ACPI tables device trees shall not be installed as - * configuration table. - * - * @fdt: address of device tree or EFI_FDT_USE_INTERNAL to use - * the hardware device tree as indicated by environment variable - * fdt_addr or as fallback the internal device tree as indicated by - * the environment variable fdtcontroladdr - * Return: status code - */ -efi_status_t efi_install_fdt(void *fdt) -{ - /* - * The EBBR spec requires that we have either an FDT or an ACPI table - * but not both. - */ -#if CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) - if (fdt) { - log_warning("WARNING: Can't have ACPI table and device tree - ignoring DT.\n"); - return EFI_SUCCESS; - } -#else - struct bootm_headers img = { 0 }; - efi_status_t ret; - - if (fdt == EFI_FDT_USE_INTERNAL) { - const char *fdt_opt; - uintptr_t fdt_addr; - - /* Look for device tree that is already installed */ - if (get_config_table(&efi_guid_fdt)) - return EFI_SUCCESS; - /* Check if there is a hardware device tree */ - fdt_opt = env_get("fdt_addr"); - /* Use our own device tree as fallback */ - if (!fdt_opt) { - fdt_opt = env_get("fdtcontroladdr"); - if (!fdt_opt) { - log_err("ERROR: need device tree\n"); - return EFI_NOT_FOUND; - } - } - fdt_addr = hextoul(fdt_opt, NULL); - if (!fdt_addr) { - log_err("ERROR: invalid $fdt_addr or $fdtcontroladdr\n"); - return EFI_LOAD_ERROR; - } - fdt = map_sysmem(fdt_addr, 0); - } - - /* Install device tree */ - if (fdt_check_header(fdt)) { - log_err("ERROR: invalid device tree\n"); - return EFI_LOAD_ERROR; - } - - /* Prepare device tree for payload */ - ret = copy_fdt(&fdt); - if (ret) { - log_err("ERROR: out of memory\n"); - return EFI_OUT_OF_RESOURCES; - } - - if (image_setup_libfdt(&img, fdt, 0, NULL)) { - log_err("ERROR: failed to process device tree\n"); - return EFI_LOAD_ERROR; - } - - /* Create memory reservations as indicated by the device tree */ - efi_carve_out_dt_rsv(fdt); - - efi_try_purge_kaslr_seed(fdt); - - if (CONFIG_IS_ENABLED(EFI_TCG2_PROTOCOL_MEASURE_DTB)) { - ret = efi_tcg2_measure_dtb(fdt); - if (ret == EFI_SECURITY_VIOLATION) { - log_err("ERROR: failed to measure DTB\n"); - return ret; - } - } - - /* Install device tree as UEFI table */ - ret = efi_install_configuration_table(&efi_guid_fdt, fdt); - if (ret != EFI_SUCCESS) { - log_err("ERROR: failed to install device tree\n"); - return ret; - } -#endif /* GENERATE_ACPI_TABLE */ - - return EFI_SUCCESS; -} - -/** - * do_bootefi_exec() - execute EFI binary - * - * The image indicated by @handle is started. When it returns the allocated - * memory for the @load_options is freed. - * - * @handle: handle of loaded image - * @load_options: load options - * Return: status code - * - * Load the EFI binary into a newly assigned memory unwinding the relocation - * information, install the loaded image protocol, and call the binary. - */ -static efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options) -{ - efi_status_t ret; - efi_uintn_t exit_data_size = 0; - u16 *exit_data = NULL; - struct efi_event *evt; - - /* On ARM switch from EL3 or secure mode to EL2 or non-secure mode */ - switch_to_non_secure_mode(); - - /* - * The UEFI standard requires that the watchdog timer is set to five - * minutes when invoking an EFI boot option. - * - * Unified Extensible Firmware Interface (UEFI), version 2.7 Errata A - * 7.5. Miscellaneous Boot Services - EFI_BOOT_SERVICES.SetWatchdogTimer - */ - ret = efi_set_watchdog(300); - if (ret != EFI_SUCCESS) { - log_err("ERROR: Failed to set watchdog timer\n"); - goto out; - } - - /* Call our payload! */ - ret = EFI_CALL(efi_start_image(handle, &exit_data_size, &exit_data)); - if (ret != EFI_SUCCESS) { - log_err("## Application failed, r = %lu\n", - ret & ~EFI_ERROR_MASK); - if (exit_data) { - log_err("## %ls\n", exit_data); - efi_free_pool(exit_data); - } - } - - efi_restore_gd(); - -out: - free(load_options); - - if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) { - if (efi_initrd_deregister() != EFI_SUCCESS) - log_err("Failed to remove loadfile2 for initrd\n"); - } - - /* Notify EFI_EVENT_GROUP_RETURN_TO_EFIBOOTMGR event group. */ - list_for_each_entry(evt, &efi_events, link) { - if (evt->group && - !guidcmp(evt->group, - &efi_guid_event_group_return_to_efibootmgr)) { - efi_signal_event(evt); - EFI_CALL(systab.boottime->close_event(evt)); - break; - } - } - - /* Control is returned to U-Boot, disable EFI watchdog */ - efi_set_watchdog(0); - - return ret; -} - /** * efi_bootmgr_run() - execute EFI boot manager * fdt: Flat device tree @@ -1548,99 +1152,3 @@ efi_status_t efi_bootmgr_run(void *fdt) return do_bootefi_exec(handle, load_options); } - -/** - * efi_run_image() - run loaded UEFI image - * - * @source_buffer: memory address of the UEFI image - * @source_size: size of the UEFI image - * Return: status code - */ -efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size) -{ - efi_handle_t mem_handle = NULL, handle; - struct efi_device_path *file_path = NULL; - struct efi_device_path *msg_path; - efi_status_t ret, ret2; - u16 *load_options; - - if (!bootefi_device_path || !bootefi_image_path) { - log_debug("Not loaded from disk\n"); - /* - * Special case for efi payload not loaded from disk, - * such as 'bootefi hello' or for example payload - * loaded directly into memory via JTAG, etc: - */ - file_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, - (uintptr_t)source_buffer, - source_size); - /* - * Make sure that device for device_path exist - * in load_image(). Otherwise, shell and grub will fail. - */ - ret = efi_install_multiple_protocol_interfaces(&mem_handle, - &efi_guid_device_path, - file_path, NULL); - if (ret != EFI_SUCCESS) - goto out; - msg_path = file_path; - } else { - file_path = efi_dp_append(bootefi_device_path, - bootefi_image_path); - msg_path = bootefi_image_path; - log_debug("Loaded from disk\n"); - } - - log_info("Booting %pD\n", msg_path); - - ret = EFI_CALL(efi_load_image(false, efi_root, file_path, source_buffer, - source_size, &handle)); - if (ret != EFI_SUCCESS) { - log_err("Loading image failed\n"); - goto out; - } - - /* Transfer environment variable as load options */ - ret = efi_env_set_load_options(handle, "bootargs", &load_options); - if (ret != EFI_SUCCESS) - goto out; - - ret = do_bootefi_exec(handle, load_options); - -out: - ret2 = efi_uninstall_multiple_protocol_interfaces(mem_handle, - &efi_guid_device_path, - file_path, NULL); - efi_free_pool(file_path); - return (ret != EFI_SUCCESS) ? ret : ret2; -} - -/** - * efi_binary_run() - run loaded UEFI image - * - * @image: memory address of the UEFI image - * @size: size of the UEFI image - * - * Execute an EFI binary image loaded at @image. - * @size may be zero if the binary is loaded with U-Boot load command. - * - * Return: status code - */ -efi_status_t efi_binary_run(void *image, size_t size, void *fdt) -{ - efi_status_t ret; - - /* Initialize EFI drivers */ - ret = efi_init_obj_list(); - if (ret != EFI_SUCCESS) { - log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n", - ret & ~EFI_ERROR_MASK); - return -1; - } - - ret = efi_install_fdt(fdt); - if (ret != EFI_SUCCESS) - return ret; - - return efi_run_image(image, size); -} diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index ed7214f3a347..786d8a70e2ad 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -1090,7 +1090,8 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr, if (path && !file) return EFI_INVALID_PARAMETER; - if (!strcmp(dev, "Mem") || !strcmp(dev, "hostfs")) { + if (IS_ENABLED(CONFIG_EFI_BINARY_EXEC) && + (!strcmp(dev, "Mem") || !strcmp(dev, "hostfs"))) { /* loadm command and semihosting */ efi_get_image_parameters(&image_addr, &image_size); diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index cdfd16ea7742..74d2c54f57b2 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -1,17 +1,28 @@ // SPDX-License-Identifier: GPL-2.0+ /* * Copyright (c) 2020, Linaro Limited + * For the code moved from cmd/bootefi.c + * Copyright (c) 2016 Alexander Graf */ #define LOG_CATEGORY LOGC_EFI +#include #include -#include -#include #include -#include #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; #if defined(CONFIG_CMD_EFIDEBUG) || defined(CONFIG_EFI_LOAD_FILE2_INITRD) /* GUID used by Linux to identify the LoadFile2 protocol with the initrd */ @@ -282,3 +293,484 @@ bool efi_search_bootorder(u16 *bootorder, efi_uintn_t num, u32 target, u32 *inde return false; } + +#if !CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) + +/** + * copy_fdt() - Copy the device tree to a new location available to EFI + * + * The FDT is copied to a suitable location within the EFI memory map. + * Additional 12 KiB are added to the space in case the device tree needs to be + * expanded later with fdt_open_into(). + * + * @fdtp: On entry a pointer to the flattened device tree. + * On exit a pointer to the copy of the flattened device tree. + * FDT start + * Return: status code + */ +static efi_status_t copy_fdt(void **fdtp) +{ + unsigned long fdt_ram_start = -1L, fdt_pages; + efi_status_t ret = 0; + void *fdt, *new_fdt; + u64 new_fdt_addr; + uint fdt_size; + int i; + + for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { + u64 ram_start = gd->bd->bi_dram[i].start; + u64 ram_size = gd->bd->bi_dram[i].size; + + if (!ram_size) + continue; + + if (ram_start < fdt_ram_start) + fdt_ram_start = ram_start; + } + + /* + * Give us at least 12 KiB of breathing room in case the device tree + * needs to be expanded later. + */ + fdt = *fdtp; + fdt_pages = efi_size_in_pages(fdt_totalsize(fdt) + 0x3000); + fdt_size = fdt_pages << EFI_PAGE_SHIFT; + + ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, + EFI_ACPI_RECLAIM_MEMORY, fdt_pages, + &new_fdt_addr); + if (ret != EFI_SUCCESS) { + log_err("ERROR: Failed to reserve space for FDT\n"); + goto done; + } + new_fdt = (void *)(uintptr_t)new_fdt_addr; + memcpy(new_fdt, fdt, fdt_totalsize(fdt)); + fdt_set_totalsize(new_fdt, fdt_size); + + *fdtp = (void *)(uintptr_t)new_fdt_addr; +done: + return ret; +} + +/** + * get_config_table() - get configuration table + * + * @guid: GUID of the configuration table + * Return: pointer to configuration table or NULL + */ +static void *get_config_table(const efi_guid_t *guid) +{ + size_t i; + + for (i = 0; i < systab.nr_tables; i++) { + if (!guidcmp(guid, &systab.tables[i].guid)) + return systab.tables[i].table; + } + return NULL; +} + +#endif /* !CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) */ + +/** + * efi_install_fdt() - install device tree + * + * If fdt is not EFI_FDT_USE_INTERNAL, the device tree located at that memory + * address will be installed as configuration table, otherwise the device + * tree located at the address indicated by environment variable fdt_addr or as + * fallback fdtcontroladdr will be used. + * + * On architectures using ACPI tables device trees shall not be installed as + * configuration table. + * + * @fdt: address of device tree or EFI_FDT_USE_INTERNAL to use + * the hardware device tree as indicated by environment variable + * fdt_addr or as fallback the internal device tree as indicated by + * the environment variable fdtcontroladdr + * Return: status code + */ +efi_status_t efi_install_fdt(void *fdt) +{ + /* + * The EBBR spec requires that we have either an FDT or an ACPI table + * but not both. + */ +#if CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) + if (fdt) { + log_warning("WARNING: Can't have ACPI table and device tree - ignoring DT.\n"); + return EFI_SUCCESS; + } +#else + struct bootm_headers img = { 0 }; + efi_status_t ret; + + if (fdt == EFI_FDT_USE_INTERNAL) { + const char *fdt_opt; + uintptr_t fdt_addr; + + /* Look for device tree that is already installed */ + if (get_config_table(&efi_guid_fdt)) + return EFI_SUCCESS; + /* Check if there is a hardware device tree */ + fdt_opt = env_get("fdt_addr"); + /* Use our own device tree as fallback */ + if (!fdt_opt) { + fdt_opt = env_get("fdtcontroladdr"); + if (!fdt_opt) { + log_err("ERROR: need device tree\n"); + return EFI_NOT_FOUND; + } + } + fdt_addr = hextoul(fdt_opt, NULL); + if (!fdt_addr) { + log_err("ERROR: invalid $fdt_addr or $fdtcontroladdr\n"); + return EFI_LOAD_ERROR; + } + fdt = map_sysmem(fdt_addr, 0); + } + + /* Install device tree */ + if (fdt_check_header(fdt)) { + log_err("ERROR: invalid device tree\n"); + return EFI_LOAD_ERROR; + } + + /* Prepare device tree for payload */ + ret = copy_fdt(&fdt); + if (ret) { + log_err("ERROR: out of memory\n"); + return EFI_OUT_OF_RESOURCES; + } + + if (image_setup_libfdt(&img, fdt, 0, NULL)) { + log_err("ERROR: failed to process device tree\n"); + return EFI_LOAD_ERROR; + } + + /* Create memory reservations as indicated by the device tree */ + efi_carve_out_dt_rsv(fdt); + + efi_try_purge_kaslr_seed(fdt); + + if (CONFIG_IS_ENABLED(EFI_TCG2_PROTOCOL_MEASURE_DTB)) { + ret = efi_tcg2_measure_dtb(fdt); + if (ret == EFI_SECURITY_VIOLATION) { + log_err("ERROR: failed to measure DTB\n"); + return ret; + } + } + + /* Install device tree as UEFI table */ + ret = efi_install_configuration_table(&efi_guid_fdt, fdt); + if (ret != EFI_SUCCESS) { + log_err("ERROR: failed to install device tree\n"); + return ret; + } +#endif /* GENERATE_ACPI_TABLE */ + + return EFI_SUCCESS; +} + +/** + * do_bootefi_exec() - execute EFI binary + * + * The image indicated by @handle is started. When it returns the allocated + * memory for the @load_options is freed. + * + * @handle: handle of loaded image + * @load_options: load options + * Return: status code + * + * Load the EFI binary into a newly assigned memory unwinding the relocation + * information, install the loaded image protocol, and call the binary. + */ +efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options) +{ + efi_status_t ret; + efi_uintn_t exit_data_size = 0; + u16 *exit_data = NULL; + struct efi_event *evt; + + /* On ARM switch from EL3 or secure mode to EL2 or non-secure mode */ + switch_to_non_secure_mode(); + + /* + * The UEFI standard requires that the watchdog timer is set to five + * minutes when invoking an EFI boot option. + * + * Unified Extensible Firmware Interface (UEFI), version 2.7 Errata A + * 7.5. Miscellaneous Boot Services - EFI_BOOT_SERVICES.SetWatchdogTimer + */ + ret = efi_set_watchdog(300); + if (ret != EFI_SUCCESS) { + log_err("ERROR: Failed to set watchdog timer\n"); + goto out; + } + + /* Call our payload! */ + ret = EFI_CALL(efi_start_image(handle, &exit_data_size, &exit_data)); + if (ret != EFI_SUCCESS) { + log_err("## Application failed, r = %lu\n", + ret & ~EFI_ERROR_MASK); + if (exit_data) { + log_err("## %ls\n", exit_data); + efi_free_pool(exit_data); + } + } + + efi_restore_gd(); + +out: + free(load_options); + + if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) { + if (efi_initrd_deregister() != EFI_SUCCESS) + log_err("Failed to remove loadfile2 for initrd\n"); + } + + /* Notify EFI_EVENT_GROUP_RETURN_TO_EFIBOOTMGR event group. */ + list_for_each_entry(evt, &efi_events, link) { + if (evt->group && + !guidcmp(evt->group, + &efi_guid_event_group_return_to_efibootmgr)) { + efi_signal_event(evt); + EFI_CALL(systab.boottime->close_event(evt)); + break; + } + } + + /* Control is returned to U-Boot, disable EFI watchdog */ + efi_set_watchdog(0); + + return ret; +} + +#if CONFIG_IS_ENABLED(EFI_BINARY_EXEC) +static struct efi_device_path *bootefi_image_path; +static struct efi_device_path *bootefi_device_path; +static void *image_addr; +static size_t image_size; + +/** + * efi_get_image_parameters() - return image parameters + * + * @img_addr: address of loaded image in memory + * @img_size: size of loaded image + */ +void efi_get_image_parameters(void **img_addr, size_t *img_size) +{ + *img_addr = image_addr; + *img_size = image_size; +} + +/** + * efi_clear_bootdev() - clear boot device + */ +void efi_clear_bootdev(void) +{ + efi_free_pool(bootefi_device_path); + efi_free_pool(bootefi_image_path); + bootefi_device_path = NULL; + bootefi_image_path = NULL; + image_addr = NULL; + image_size = 0; +} + +/** + * efi_set_bootdev() - set boot device + * + * This function is called when a file is loaded, e.g. via the 'load' command. + * We use the path to this file to inform the UEFI binary about the boot device. + * + * @dev: device, e.g. "MMC" + * @devnr: number of the device, e.g. "1:2" + * @path: path to file loaded + * @buffer: buffer with file loaded + * @buffer_size: size of file loaded + */ +void efi_set_bootdev(const char *dev, const char *devnr, const char *path, + void *buffer, size_t buffer_size) +{ + struct efi_device_path *device, *image; + efi_status_t ret; + + log_debug("dev=%s, devnr=%s, path=%s, buffer=%p, size=%zx\n", dev, + devnr, path, buffer, buffer_size); + + /* Forget overwritten image */ + if (buffer + buffer_size >= image_addr && + image_addr + image_size >= buffer) + efi_clear_bootdev(); + + /* Remember only PE-COFF and FIT images */ + if (efi_check_pe(buffer, buffer_size, NULL) != EFI_SUCCESS) { + if (IS_ENABLED(CONFIG_FIT) && + !fit_check_format(buffer, IMAGE_SIZE_INVAL)) { + /* + * FIT images of type EFI_OS are started via command + * bootm. We should not use their boot device with the + * bootefi command. + */ + buffer = 0; + buffer_size = 0; + } else { + log_debug("- not remembering image\n"); + return; + } + } + + /* efi_set_bootdev() is typically called repeatedly, recover memory */ + efi_clear_bootdev(); + + image_addr = buffer; + image_size = buffer_size; + + ret = efi_dp_from_name(dev, devnr, path, &device, &image); + if (ret == EFI_SUCCESS) { + bootefi_device_path = device; + if (image) { + /* FIXME: image should not contain device */ + struct efi_device_path *image_tmp = image; + + efi_dp_split_file_path(image, &device, &image); + efi_free_pool(image_tmp); + } + bootefi_image_path = image; + log_debug("- boot device %pD\n", device); + if (image) + log_debug("- image %pD\n", image); + } else { + log_debug("- efi_dp_from_name() failed, err=%lx\n", ret); + efi_clear_bootdev(); + } +} + +/** + * efi_env_set_load_options() - set load options from environment variable + * + * @handle: the image handle + * @env_var: name of the environment variable + * @load_options: pointer to load options (output) + * Return: status code + */ +efi_status_t efi_env_set_load_options(efi_handle_t handle, + const char *env_var, + u16 **load_options) +{ + const char *env = env_get(env_var); + size_t size; + u16 *pos; + efi_status_t ret; + + *load_options = NULL; + if (!env) + return EFI_SUCCESS; + size = sizeof(u16) * (utf8_utf16_strlen(env) + 1); + pos = calloc(size, 1); + if (!pos) + return EFI_OUT_OF_RESOURCES; + *load_options = pos; + utf8_utf16_strcpy(&pos, env); + ret = efi_set_load_options(handle, size, *load_options); + if (ret != EFI_SUCCESS) { + free(*load_options); + *load_options = NULL; + } + return ret; +} + +/** + * efi_run_image() - run loaded UEFI image + * + * @source_buffer: memory address of the UEFI image + * @source_size: size of the UEFI image + * Return: status code + */ +static efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size) +{ + efi_handle_t mem_handle = NULL, handle; + struct efi_device_path *file_path = NULL; + struct efi_device_path *msg_path; + efi_status_t ret, ret2; + u16 *load_options; + + if (!bootefi_device_path || !bootefi_image_path) { + log_debug("Not loaded from disk\n"); + /* + * Special case for efi payload not loaded from disk, + * such as 'bootefi hello' or for example payload + * loaded directly into memory via JTAG, etc: + */ + file_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, + (uintptr_t)source_buffer, + source_size); + /* + * Make sure that device for device_path exist + * in load_image(). Otherwise, shell and grub will fail. + */ + ret = efi_install_multiple_protocol_interfaces(&mem_handle, + &efi_guid_device_path, + file_path, NULL); + if (ret != EFI_SUCCESS) + goto out; + msg_path = file_path; + } else { + file_path = efi_dp_append(bootefi_device_path, + bootefi_image_path); + msg_path = bootefi_image_path; + log_debug("Loaded from disk\n"); + } + + log_info("Booting %pD\n", msg_path); + + ret = EFI_CALL(efi_load_image(false, efi_root, file_path, source_buffer, + source_size, &handle)); + if (ret != EFI_SUCCESS) { + log_err("Loading image failed\n"); + goto out; + } + + /* Transfer environment variable as load options */ + ret = efi_env_set_load_options(handle, "bootargs", &load_options); + if (ret != EFI_SUCCESS) + goto out; + + ret = do_bootefi_exec(handle, load_options); + +out: + ret2 = efi_uninstall_multiple_protocol_interfaces(mem_handle, + &efi_guid_device_path, + file_path, NULL); + efi_free_pool(file_path); + return (ret != EFI_SUCCESS) ? ret : ret2; +} + +/** + * efi_binary_run() - run loaded UEFI image + * + * @image: memory address of the UEFI image + * @size: size of the UEFI image + * + * Execute an EFI binary image loaded at @image. + * @size may be zero if the binary is loaded with U-Boot load command. + * + * Return: status code + */ +efi_status_t efi_binary_run(void *image, size_t size, void *fdt) +{ + efi_status_t ret; + + /* Initialize EFI drivers */ + ret = efi_init_obj_list(); + if (ret != EFI_SUCCESS) { + log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n", + ret & ~EFI_ERROR_MASK); + return ret; + } + + ret = efi_install_fdt(fdt); + if (ret != EFI_SUCCESS) + return ret; + + return efi_run_image(image, size); +} +#endif /* CONFIG_EFI_BINARY_EXEC */ From patchwork Tue Nov 21 01:29:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 745678 Delivered-To: patch@linaro.org Received: by 2002:a5d:5052:0:b0:32d:baff:b0ca with SMTP id h18csp1628828wrt; Mon, 20 Nov 2023 17:34:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEyWPUaYxeOQUTcU4GBoWaGcg6j1CiwGWh2cCaDzX13D4jWHoYOjiUnT4DduQU6Ml0aOJqo X-Received: by 2002:aa7:ca50:0:b0:548:986e:255 with SMTP id j16-20020aa7ca50000000b00548986e0255mr889278edt.21.1700530484889; Mon, 20 Nov 2023 17:34:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700530484; cv=none; d=google.com; s=arc-20160816; b=yj3puTFvfl+o1AlOLAqa4m2d/GH+MdQRhTSE6lyFAwpE5Ctsh13QOGhB3PmPNswCeo CL/Q3rjxacrJgLNMoJDH3k+cWyz0ccH8j+Sywz56ZMBuYFQBAydVcF5rUUSri5K97yy/ 0LgYynXdjxUnkBcayagVOy++jUtrLor5cpT54VYrdX3r7BMpukQpLxXjuu0F4lIgd/y9 fWyGSinxVrQlJ0OASxUUyUsToAp4oLFHiRcQuhs0ZPcuq1LQdYDfPr6sQc6gt8aOHWSN 0pbHxdMoeHCIxfN1N6B26602ln7FNNAQkHrQtzqafLR8Y+JT5gM04CI9JHcmlAoQ0yIb f7SQ== 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=otqnZHrndwWLn4WmIHD98CEzafN5CRxFeZ2ufbMbKkw=; fh=p8OTi/tJSbfUA0ykVxDxRCnpqUhQqJazFYHXT9edm5U=; b=yn10/5RcnCARSKxyRG3YFIQ+QTqo8f3T/29yX6GKC20vjrhMVTmbCtIasDyT2YMgYt 8ldr8HxkFiCHaiRbpU3ITP5rhcc58xVFUDfHuj9Ux2b3yC86zmHCf2jg2EYV3rsJ5bWQ 29B+LwpgAa7LpBfSnMcGF8fubFgiZznOHiV/9eyyCHKJN+GmNsGkFi2d4sJckUadL8s1 ML+pghaNqEtqJ12JJu3JklSQc3EidPeX6AXk0UynoVKDfV4NAt0IV7bxSRzqchY/R88B k0XBph82EbjrVmv0tGiZ2x3tff/JsKMjuI+5Wd9iDdszAZQl8mTlawoRWZl2t+jCU8N6 ED8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ojppAoBP; 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 w20-20020a50fa94000000b00548e6517054si696964edr.277.2023.11.20.17.34.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:34:44 -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=ojppAoBP; 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 097B587584; Tue, 21 Nov 2023 02:31:50 +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="ojppAoBP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0FD77875BC; Tue, 21 Nov 2023 02:31:39 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) (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 3EFBD875A4 for ; Tue, 21 Nov 2023 02:31:21 +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=takahiro.akashi@linaro.org Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1cc2b8deb23so10682255ad.1 for ; Mon, 20 Nov 2023 17:31:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700530253; x=1701135053; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=otqnZHrndwWLn4WmIHD98CEzafN5CRxFeZ2ufbMbKkw=; b=ojppAoBPfo5fcDNbh4wvVKPDusenix+feA3uRb2KX+RN7YXlHpKuRwfiOlJOyxb1DH A6f/FCqh9BMyYWwlsgnGZz7EbicdhelHA+HBTKUFTDn3YJjUz0MGHJ9hwqRVUPToVPCZ Uzd16zHdqwbkZek4Z8Urj/0URLwFloxXjXeV7/JSim7gbYYIjzHpuAUGhgScoluF6fMd v/+nME2yR9A1JnvtEsPirgLnSnhzcb+dcXVB4cUxUMgESX9L8gOz1L4xzqBJKafo0uCk yYM001Rg4dgLuYCHgaW7gml7Pv35zwtkOQGXGZuOaCGX0N2asxVChapcAivj8/t2Q99/ 0yVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700530253; x=1701135053; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=otqnZHrndwWLn4WmIHD98CEzafN5CRxFeZ2ufbMbKkw=; b=BxCgYLNb8m0RQhDHrb8PKrwrUUpzZj9uFzm0NCxDLoIy5DoM4LBH4B/RpMYnbYdXPf ibPKIfNohF52gVCJtO/FQyEInjVdVqHYFePNGPcoc8UwKVchWfHUJPiXlVDOF8n4pQCW gh0aZ/n/P75TKTglWfxiQm+jwntJXrn4bRbthEnro1UbNmQW8IAChQ65IBKXjVQJGx6g c8VgOcCkoa9LNul4xK1YSeOwRmATeWSrGL9AonMSHi57uPpTaRoDRAXrvbXcGcNoQ/B9 dYUqCSVChKfHEB4/YLUJMUv848GEfz5e52wI2cw1PEFbCNinaq53N0Bk8MrZXLQRfWDv Najg== X-Gm-Message-State: AOJu0YyEqG/mB+i2P0z5rxAikYCS61Iu4/r4mo2Cf4YtCtpk+CdFKuHu Lm+u0XzNQ10wqVHfYBU7dK7cVg== X-Received: by 2002:a17:903:32c4:b0:1ce:2fc1:60ef with SMTP id i4-20020a17090332c400b001ce2fc160efmr12252807plr.0.1700530253373; Mon, 20 Nov 2023 17:30:53 -0800 (PST) Received: from octopus.. ([2400:4050:c3e1:100:f6af:a59c:7ca:897f]) by smtp.gmail.com with ESMTPSA id e9-20020a170902d38900b001c8a0879805sm3612508pld.206.2023.11.20.17.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:30:53 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org, xypron.glpk@gmx.de, ilias.apalodimas@linaro.org Cc: u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v2 10/12] efi_loader: rename BOOTEFI_BOOTMGR to EFI_BOOTMGR Date: Tue, 21 Nov 2023 10:29:48 +0900 Message-Id: <20231121012950.156539-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121012950.156539-1-takahiro.akashi@linaro.org> References: <20231121012950.156539-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean At this point, EFI boot manager interfaces is fully independent from bootefi command. So just rename the configuration parameter. Signed-off-by: AKASHI Takahiro --- boot/Makefile | 2 +- cmd/Kconfig | 4 ++-- cmd/efidebug.c | 4 ++-- lib/efi_loader/Kconfig | 2 +- lib/efi_loader/Makefile | 2 +- test/boot/bootflow.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/boot/Makefile b/boot/Makefile index 4eaa5eab4b77..48d74c67d680 100644 --- a/boot/Makefile +++ b/boot/Makefile @@ -32,7 +32,7 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_CROS) += bootm.o bootm_os.o bootmeth_cros.o obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_SANDBOX) += bootmeth_sandbox.o obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_SCRIPT) += bootmeth_script.o ifdef CONFIG_$(SPL_TPL_)BOOTSTD_FULL -obj-$(CONFIG_BOOTEFI_BOOTMGR) += bootmeth_efi_mgr.o +obj-$(CONFIG_EFI_BOOTMGR) += bootmeth_efi_mgr.o obj-$(CONFIG_$(SPL_TPL_)EXPO) += bootflow_menu.o obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootflow_menu.o obj-$(CONFIG_$(SPL_TPL_)CEDIT) += cedit.o diff --git a/cmd/Kconfig b/cmd/Kconfig index 189ea6003293..897e99ae68de 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -374,7 +374,7 @@ config CMD_BOOTEFI_BINARY config CMD_BOOTEFI_BOOTMGR bool "UEFI Boot Manager command" - depends on BOOTEFI_BOOTMGR + depends on EFI_BOOTMGR default y help Select this option to enable the 'bootmgr' subcommand of 'bootefi'. @@ -2124,7 +2124,7 @@ config CMD_EFIDEBUG config CMD_EFICONFIG bool "eficonfig - provide menu-driven uefi variables maintenance interface" default y if !HAS_BOARD_SIZE_LIMIT - depends on BOOTEFI_BOOTMGR + depends on EFI_BOOTMGR select MENU help Enable the 'eficonfig' command which provides the menu-driven UEFI diff --git a/cmd/efidebug.c b/cmd/efidebug.c index e10fbf891a42..b4954258eeba 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -1410,7 +1410,7 @@ static __maybe_unused int do_efi_test_bootmgr(struct cmd_tbl *cmdtp, int flag, } static struct cmd_tbl cmd_efidebug_test_sub[] = { -#ifdef CONFIG_BOOTEFI_BOOTMGR +#ifdef CONFIG_EFI_BOOTMGR U_BOOT_CMD_MKENT(bootmgr, CONFIG_SYS_MAXARGS, 1, do_efi_test_bootmgr, "", ""), #endif @@ -1604,7 +1604,7 @@ U_BOOT_LONGHELP(efidebug, " - show UEFI memory map\n" "efidebug tables\n" " - show UEFI configuration tables\n" -#ifdef CONFIG_BOOTEFI_BOOTMGR +#ifdef CONFIG_EFI_BOOTMGR "efidebug test bootmgr\n" " - run simple bootmgr for test\n" #endif diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index ddb1a012a761..61e056dedb5b 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -41,7 +41,7 @@ config EFI_BINARY_EXEC You may enable CMD_BOOTEFI_BINARY so that you can use bootefi command to do that. -config BOOTEFI_BOOTMGR +config EFI_BOOTMGR bool "UEFI Boot Manager" default y select BOOTMETH_GLOBAL if BOOTSTD diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index 0a2cb6e3c476..f882474bba6f 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -42,7 +42,7 @@ targets += initrddump.o endif obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o -obj-$(CONFIG_BOOTEFI_BOOTMGR) += efi_bootmgr.o +obj-$(CONFIG_EFI_BOOTMGR) += efi_bootmgr.o obj-y += efi_boottime.o obj-y += efi_helper.o obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += efi_capsule.o diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index fa1bebdd02da..b670dfd5e5b5 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -374,7 +374,7 @@ static int bootflow_system(struct unit_test_state *uts) { struct udevice *bootstd, *dev; - if (!IS_ENABLED(CONFIG_BOOTEFI_BOOTMGR)) + if (!IS_ENABLED(CONFIG_EFI_BOOTMGR)) return -EAGAIN; ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); ut_assertok(device_bind(bootstd, DM_DRIVER_GET(bootmeth_efi_mgr), From patchwork Tue Nov 21 01:29:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 745679 Delivered-To: patch@linaro.org Received: by 2002:a5d:5052:0:b0:32d:baff:b0ca with SMTP id h18csp1628901wrt; Mon, 20 Nov 2023 17:34:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IERCpAfm03cBWyEmtWSVUt02bZf3/c//czYdDpy8JjhoilENtvXDpc7S/S8yfSX/kp0EIqb X-Received: by 2002:a05:6402:1612:b0:541:2476:d23e with SMTP id f18-20020a056402161200b005412476d23emr798998edv.28.1700530499000; Mon, 20 Nov 2023 17:34:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700530498; cv=none; d=google.com; s=arc-20160816; b=ZpN5ADzHf5UjrHBKI1sq5yjkdSb0u88zZd49SIuRwTFNUiYnw/Sd8h1koOlgRd9DXt 2CZ+lx46bi+4KPHluO/4pPcR6f2KBONycOiyQTeCJzME0wKHQ3s7rOV/opIh15LCTe83 b0evvDCYbdZMwUZ1iGaVXf6DvlEqSzrU7Kpc4HSlH7KAQtILjXVql2klz7mXocGuq5xM qMV/VZo25Jr8z51CpIXHy1S/N6ViLq7gIeoD5nAZuIu4wLL4cnIBzsOjIZWPne9Ye2sh b+dbEnEQCaT5MRGOzVxZWYc5ABxMRsKYhlJRXZ7XM9RfgNtcZ4ynxYzpr8CxPFwDFVDe XwzQ== 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=f1xnsDhYxoGq8Q7UUWBB8Cvz7zbisEXPmyyhu/S5S0E=; fh=p8OTi/tJSbfUA0ykVxDxRCnpqUhQqJazFYHXT9edm5U=; b=qweuUfL32vz5fXOBhnzQXyogJBSTZZwLNkHwYWWwNCP5bA6A0uqs8lZI6g38U8AbnM 7++bmH6cSXBoe/WQ2tN72j8n3P0XzRMgbVLK5alnqDsb0Lgew+mpkgGZyQd6fr/MUvwW zRkT84DzTpprSh0UuAz6YDK+pY5LaK9/fWOo4w4P2b9k1/WReWDTanEtYgb3dR9ri+xY qmt/0CI/bqnFvf8cHQ9B1LbWWT/0saYLUS7/xB9g06ilcRfqYrbeLJQ+MXXsj3GA8Qpq tpKgFCmWTpi56gFkJYHIuaIvOk2UDn812BMiZQPa2lKeacTEszIaC898pQUuEeMJDxJT SOKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oNAkHz+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 y15-20020a056402270f00b00548c748de9esi1368238edd.278.2023.11.20.17.34.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:34: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=oNAkHz+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 C4281875D6; Tue, 21 Nov 2023 02:32:12 +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="oNAkHz+V"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 52379875A4; Tue, 21 Nov 2023 02:31:39 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) (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 3ECDC87596 for ; Tue, 21 Nov 2023 02:31:21 +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=takahiro.akashi@linaro.org Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-28399608b7aso837568a91.0 for ; Mon, 20 Nov 2023 17:31:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700530255; x=1701135055; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=f1xnsDhYxoGq8Q7UUWBB8Cvz7zbisEXPmyyhu/S5S0E=; b=oNAkHz+VXft4CccPHHhAlmOkmi5SXPPg5tL+CekyRQEiV7QvAp85UQjUdMzDKSyb2B aqwB/eh70FLgQtbMA/kdlcJFyBuGlqqImHyagU7ANw8YmBESLZh8qtW9MjwVOcqlLV4z woK2IAlBpxVGt/npWlbgQmygKYiQVmbcYczE9ayFl+qgPUDz+z3knxHFQSW6h5ODe3+9 Q6Ou8DefuAloGkFbzoxep9P7AYo6Cx7BCtEEaaoZnRBs01d+dR4kPoL6g2r3SKLuJnHh 0ibnN/N9A3EKQOUIHugcwj3UAj9+LX8kUH2rcmOmsTKTjV2PlN9LjFcfS0ahSL/XomRa uGsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700530255; x=1701135055; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f1xnsDhYxoGq8Q7UUWBB8Cvz7zbisEXPmyyhu/S5S0E=; b=truX3/WEcgsqYz/03LuLUpdi68LYmRwz7jEER46ssQoG0JX03ras5dLsdJXsj7tLtX 97kumDH3iQw0JBqbQepSv3GDhDDg31xYLvbqtcLk8elgwbqUX5990lfp2IJ3HNbPfJmG vCNAt512Io0cMVpi7wIZEkQsIm16q5i9MM+nT+l2i1arhl/q/tiNxAk9g0PzY1CAwcZE xgtdHe26rYM8b/5izGlOsbbO3z1UKoRBzbGIKMsKM3EuiJH3pyAJ5mQEZXA6Oc1YE3xJ y0+MYmmbcKT3YGCHf9ZfIUw26TgtxNkMEOVDQ+64QbIbZe/zhoBmo9V8OYy/+VzAqvSP hQZg== X-Gm-Message-State: AOJu0YyMzf822tkDoN60uMFkIqwt4NV79CUTuO9O8JcIpTG5Sp/EkyFL q7CcCMwbdGybQBErlxu8tXHnKw== X-Received: by 2002:a17:90b:370b:b0:283:27b6:f33f with SMTP id mg11-20020a17090b370b00b0028327b6f33fmr9339851pjb.4.1700530255623; Mon, 20 Nov 2023 17:30:55 -0800 (PST) Received: from octopus.. ([2400:4050:c3e1:100:f6af:a59c:7ca:897f]) by smtp.gmail.com with ESMTPSA id e9-20020a170902d38900b001c8a0879805sm3612508pld.206.2023.11.20.17.30.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:30:55 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org, xypron.glpk@gmx.de, ilias.apalodimas@linaro.org Cc: u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v2 11/12] net: tftp: remove explicit efi configuration dependency Date: Tue, 21 Nov 2023 10:29:49 +0900 Message-Id: <20231121012950.156539-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121012950.156539-1-takahiro.akashi@linaro.org> References: <20231121012950.156539-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean Now it is clear that the feature actually depends on efi interfaces, not "bootefi" command. efi_set_bootdev() will automatically be nullified if necessary efi component is disabled. Signed-off-by: AKASHI Takahiro --- net/tftp.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/net/tftp.c b/net/tftp.c index 88e71e67de35..2e335413492b 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -302,12 +302,10 @@ static void tftp_complete(void) time_start * 1000, "/s"); } puts("\ndone\n"); - if (IS_ENABLED(CONFIG_CMD_BOOTEFI)) { - if (!tftp_put_active) - efi_set_bootdev("Net", "", tftp_filename, - map_sysmem(tftp_load_addr, 0), - net_boot_file_size); - } + if (!tftp_put_active) + efi_set_bootdev("Net", "", tftp_filename, + map_sysmem(tftp_load_addr, 0), + net_boot_file_size); net_set_state(NETLOOP_SUCCESS); } From patchwork Tue Nov 21 01:29:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 745677 Delivered-To: patch@linaro.org Received: by 2002:a5d:5052:0:b0:32d:baff:b0ca with SMTP id h18csp1628760wrt; Mon, 20 Nov 2023 17:34:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IGcYQ0vdZXfEWwX65oJfF6zoxnEUVrNK8khpQLo6k650sp9OEA07ULfhXYuUq0hKS2UMvGy X-Received: by 2002:a05:6512:3e20:b0:50a:af72:538 with SMTP id i32-20020a0565123e2000b0050aaf720538mr3546982lfv.55.1700530468042; Mon, 20 Nov 2023 17:34:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700530468; cv=none; d=google.com; s=arc-20160816; b=gCoxNwNlIxqTKq9v5VrV/i8al8CHHZulzAdVc8mYnaVBayXVVxgP59uEnDGnnrBwmQ M4/W/DcX+chEsPS6KLwjeVgWdJouLZk4/qgaucNhQZk+FgsnDQZga5PubRi7EDOKM1fm FP4oZ3gw2Fm+g4FqtQJUveoAWbeNpXL5co26ac5DopCpR/JmgitzO0Gyny1L0m0dooQo THV8a+nHq89c3rnsYW33QKS9KqUtd5J0mwbLMPqm5YjIgoYQ0+OGz/vN350LweAtyb7q sLkcnxhyTTw1up5APfSGeguPrJeioegXMro54OWPhmssdoZKJVYpGPTVm6jI5vXxbFIE 7Y1g== 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=OCUBljU3l7bLi+2Mof6yKcdAJGAgEsp6V13IE4RoUsg=; fh=p8OTi/tJSbfUA0ykVxDxRCnpqUhQqJazFYHXT9edm5U=; b=RkJqFxsfzjMLzWkmzi9cDqE9IPofM9hLe4xmeRhbIJOzVSNWGX++viEPTowhi3qbpO y1SmypFDjh4zS7g+K0VTjrZPvK8qo5J9df1FOJqGBLxq3aIILZvVZ8eCFKmOVTW18Dd8 pKRbmV/EQQ+5ZECQS9NCZ0k4SW7aOIzpcA/5eVmaJ6mjBkvOPm3riUhXQm0mYE3ViC6+ UotdXuWnwFQJSDENKaVswbT72hbEEe2qOFqwHGUlvK1CJNovLNKamC5tlVUWmq3iaPyK ODJSOEUorCCV0A+xY7aQjvJH9gkglyMrRnKG3CR0BrP+SafAfS/yCR6hiTwYlMoSEJBl JT+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y9SNJgPC; 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 k4-20020aa7d8c4000000b005489dd01008si2556713eds.559.2023.11.20.17.34.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:34:28 -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=y9SNJgPC; 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 55E2A864F3; Tue, 21 Nov 2023 02:31:40 +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="y9SNJgPC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3D23787574; Tue, 21 Nov 2023 02:31:38 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) (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 3E17C87584 for ; Tue, 21 Nov 2023 02:31:21 +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=takahiro.akashi@linaro.org Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1cc4d306fe9so11476775ad.0 for ; Mon, 20 Nov 2023 17:31:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700530258; x=1701135058; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OCUBljU3l7bLi+2Mof6yKcdAJGAgEsp6V13IE4RoUsg=; b=y9SNJgPC+M9K6B2UYWY5lHfmp20BaZM3ZvbgimLVi9qiPmHK0+vJIUR4cL0pf54iiI t4wlWoXq/dpIqsGh5Hy40e/gaF9naTePUms9RMeRKaik7xymarbeOJgOM76ualylZoaz nhZpxOroPfx8EHIBzkqS2zgB8Qj0sudacIGWlJLaAy3ZDahFbuz6qNpo1FyvZdbMRqm+ 1K7P+2jLHhJ5Lku2gA3izG0nlhASE5o1dAtcqNqg4MdcNDhTf6Z0QgfsfeQDhkCP8NFY sL2jXx5Wu8ouYqR6zQ/GLYOe8wk77cuplgPC+nwRtAT2mFPBzW7CWoptH9UjaS3jd1EB J4VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700530258; x=1701135058; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OCUBljU3l7bLi+2Mof6yKcdAJGAgEsp6V13IE4RoUsg=; b=Lcpb/FBTeujP6yPbjHY+WdBel2lys08SPflMJD74AuySeo6KoeHA4mTKsfVd8RXPez 4WP7Y+1qx6DHt0XtbQI1LY7/rFv9OUS7U4Qgkv47eAJmDAZ6nrbfl1e9uwW/NF404Ryd rqCfElN9yvVhsiQf334yjRKMfDp7x0EFNywj764vsTNjMvi/aYHqbeXiibAuU8BwKnfU gH61495dp5EbWSaOAtmO+HOutUnJLPNT1358NoJkaIHVES+bFyukhedF1Akj3LvZYXHB 3JPWXuXy5NqBTyNPkwJ5YwydXKx96dhHdhQVw30W7oVm5n2zFSxEfqRt9TQ5f/GEe8Ho WVNQ== X-Gm-Message-State: AOJu0YwtUfP6BYjgzC8K2T6Iafy5ndqLMwoYvnfinUMIk4wqJOkX4utg hXbx1iNs+jxPP6mpNqSXs7M3xA== X-Received: by 2002:a17:903:2448:b0:1ce:ca8:74d5 with SMTP id l8-20020a170903244800b001ce0ca874d5mr11947114pls.1.1700530257769; Mon, 20 Nov 2023 17:30:57 -0800 (PST) Received: from octopus.. ([2400:4050:c3e1:100:f6af:a59c:7ca:897f]) by smtp.gmail.com with ESMTPSA id e9-20020a170902d38900b001c8a0879805sm3612508pld.206.2023.11.20.17.30.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:30:57 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org, xypron.glpk@gmx.de, ilias.apalodimas@linaro.org Cc: u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v2 12/12] fs: remove explicit efi configuration dependency Date: Tue, 21 Nov 2023 10:29:50 +0900 Message-Id: <20231121012950.156539-13-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121012950.156539-1-takahiro.akashi@linaro.org> References: <20231121012950.156539-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean Now it is clear that the feature actually depends on efi interfaces, not "bootefi" command. efi_set_bootdev() will automatically be nullified if necessary efi component is disabled. Signed-off-by: AKASHI Takahiro --- fs/fs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/fs.c b/fs/fs.c index 4cb4310c9cc2..70cdb594c4c8 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -791,10 +791,9 @@ int do_load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], return 1; } - if (IS_ENABLED(CONFIG_CMD_BOOTEFI)) - efi_set_bootdev(argv[1], (argc > 2) ? argv[2] : "", - (argc > 4) ? argv[4] : "", map_sysmem(addr, 0), - len_read); + efi_set_bootdev(argv[1], (argc > 2) ? argv[2] : "", + (argc > 4) ? argv[4] : "", map_sysmem(addr, 0), + len_read); printf("%llu bytes read in %lu ms", len_read, time); if (time > 0) {