Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 942B3C433EF for ; Wed, 6 Apr 2022 05:05:02 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7465783B38; Wed, 6 Apr 2022 07:04:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=FreeBSD.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; secure) header.d=freebsd.org header.i=@freebsd.org header.b="pe7ZU5W1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3F06D83B42; Wed, 6 Apr 2022 07:04:58 +0200 (CEST) Received: from mx2.freebsd.org (mx2.freebsd.org [96.47.72.81]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id DC558807DF for ; Wed, 6 Apr 2022 07:04:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kevans@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits)) (Client CN "mx1.freebsd.org", Issuer "R3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id DAD2175423; Wed, 6 Apr 2022 05:04:42 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KYC9k3zMhz4gv0; Wed, 6 Apr 2022 05:04:42 +0000 (UTC) (envelope-from kevans@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649221482; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=TMKhU4cFFQojTwYP7E+J/HD+FTKyuxzuISHJl5W6Nb8=; b=pe7ZU5W12fgniRFh8nA1z6S9xaVB8R9cTVs5LxKlruSpGo5FEmPM7aoubyLVTSIC28kl2u e7VHwvf472H5jjfBigZIItdjYARsLXZxYkd3m8f2ULpldTbF5JvcRyWr9Cqfi7n5JcRDlP /+r6RGJobzPWhsaEOIc2YqB6s5OTGHd2XpcC4uCSFsZzuCYgr9dlH7yNqhSJsHj7f7kZry KwwFTunlcoHIl6Xm9NLUu9PWqsOty55u402dDUovZjY0G45/g+D2V+WOPnBICKC44Ey8rQ /+Ms7lX+NYetAPy08F8Kp5rZ6Z1PSpbZZn92mso1LBtnj8B1Px+UOUxfxOnEjA== Received: from localhost.localdomain (unknown [209.182.121.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: kevans) by smtp.freebsd.org (Postfix) with ESMTPSA id 19CF42BB3F; Wed, 6 Apr 2022 05:04:42 +0000 (UTC) (envelope-from kevans@FreeBSD.org) From: kevans@FreeBSD.org To: u-boot@lists.denx.de Cc: Kyle Evans , Heinrich Schuchardt Subject: [PATCH] cmd: bootefi: restore ability to boot arbitrary blob Date: Wed, 6 Apr 2022 00:04:23 -0500 Message-Id: <20220406050423.79897-1-kevans@FreeBSD.org> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649221482; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=TMKhU4cFFQojTwYP7E+J/HD+FTKyuxzuISHJl5W6Nb8=; b=t5eeysamrBj+PZMhylIRLFgrSGxrWAv2LvGidMwcSozHzkLs2LX3in6ugp2R4m/gCg7UQc kpxicBusP8HS1vuUhMzCR/192oDb6UVxe3M0sZLnC61jbRWNEzeE/ycf38wlPa0QeJBzEe G39xpsR4STTHx/oxOjM1meEe7a3gE1WW8JhPl/wCe/d0wGBKgfq+kzJtGDGjfAYmR2YQ5w VaYU+Duu9NIOn6rwxbwpYg+bc/lSTsW46LKmiC0SVBYsA60iI3oCoJ3t8D0U7ySzyClv7Z 8y5Ko9/zD1cP+b+rvPDncZyn2EWLoneVNyuwUoev4BH2rD2FVqr87Ei9gsqBbQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649221482; a=rsa-sha256; cv=none; b=oLqVj9HUGh6aWcs9yI7RXLVcl3wUKpZi7ddHof6qgyOaoEjJ0PU4sUxTXjLhFPRnEjDCUC ohC2hp/mWbUGGodQ6z0IlwTTIZprxFVVD7k47Bv0OBQvn6g3V4leDRzPAgrwifXvuVByq+ NI/n/sEvSE5R4Ittjzw1j/DXlAsEvy3mYqa0uMEGnTz/MKXVE2SmejrlRLCt9ZC7KczG1L g9rhClGPcx19rjZFNVdCHAeApT8VyMLFiTGJafwEOfVW26pnBWy99/kX8nBpwzKcV6od2X apvNup+vyNFEy/qZ41sITJk2ofScrEPgsHMkXB8MZEGZ+e6ylcnQdzL0qn0Jwg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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.5 at phobos.denx.de X-Virus-Status: Clean From: Kyle Evans Up until commit 5f59518a7b1ae ("efi_loader: setting boot device"), we could boot an arbitrary blob with bootefi. Indeed, efi_run_image() even has a special case for missing device paths indicating a payload that was directly loaded via JTAG, for example. Restore the ability to inject a UEFI payload into memory and `bootefi` it. If the address passed isn't the last PE-COFF loaded, then we'll wipe out the pre-existing DP/Image information and let efi_run_image() synthesize a memory device path. An image size is required if we're booting an arbitrary payload, and the FDT argument has been changed to accept `-`. The size could be deduced from the image header, but it's required anyways as an explicit acknowledgment that one's trying to boot an arbitrary payload rather than accidentally using the wrong address in the single-addr form. Signed-off-by: Kyle Evans --- cmd/bootefi.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 53d9f0e0dc..1dac74781e 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -425,7 +425,7 @@ static int do_efibootmgr(void) * @image_opt: string of image start address * Return: status code */ -static int do_bootefi_image(const char *image_opt) +static int do_bootefi_image(const char *image_opt, const char *size_opt) { void *image_buf; unsigned long addr, size; @@ -444,13 +444,29 @@ static int do_bootefi_image(const char *image_opt) if (!addr) return CMD_RET_USAGE; + size = 0; + if (size_opt) { + size = strtoul(size_opt, NULL, 16); + /* Check that a numeric value was passed */ + if (!size) + return CMD_RET_USAGE; + } + image_buf = map_sysmem(addr, 0); if (image_buf != image_addr) { - log_err("No UEFI binary known at %s\n", image_opt); - return CMD_RET_FAILURE; + /* Fake device path -- we must have a size. */ + + if (image_addr) + efi_clear_bootdev(); + + if (size == 0) + return CMD_RET_USAGE; + } else { + if (size != 0) + return CMD_RET_USAGE; + size = image_size; } - size = image_size; } ret = efi_run_image(image_buf, size); @@ -654,7 +670,7 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_FAILURE; } - if (argc > 2) { + if (argc > 2 && strcmp(argv[2], "-") != 0) { uintptr_t fdt_addr; fdt_addr = hextoul(argv[2], NULL); @@ -677,15 +693,19 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc, return do_efi_selftest(); #endif - return do_bootefi_image(argv[1]); + return do_bootefi_image(argv[1], argc > 3 ? argv[3] : NULL); } #ifdef CONFIG_SYS_LONGHELP static char bootefi_help_text[] = - " [fdt address]\n" + " [fdt address [image size]]\n" " - boot EFI payload stored at address .\n" " If specified, the device tree located at gets\n" " exposed as EFI configuration table.\n" + " The image size is required if this is not a preloaded image, but\n" + " it must be omitted if the image was preloaded.\n" + " The parameter accepts '-' to indicate FDT already\n" + " installed or pre-specified in fdt_addr or fdtcontroladdr.\n" #ifdef CONFIG_CMD_BOOTEFI_HELLO "bootefi hello\n" " - boot a sample Hello World application stored within U-Boot\n" @@ -707,7 +727,7 @@ static char bootefi_help_text[] = #endif U_BOOT_CMD( - bootefi, 3, 0, do_bootefi, + bootefi, 4, 0, do_bootefi, "Boots an EFI payload from memory", bootefi_help_text ); -- 2.33.0