From patchwork Tue Mar 22 10:41:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rui Miguel Silva X-Patchwork-Id: 553477 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1248:0:0:0:0 with SMTP id z8csp2319355mag; Tue, 22 Mar 2022 04:24:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7iP0FjYjSu0rjIbDmkAF+/IheEvFhGnpZeyPxUN7GpokXCiKNMOORR2FD8Y7zOmXobK39 X-Received: by 2002:a05:6402:5186:b0:419:49af:428f with SMTP id q6-20020a056402518600b0041949af428fmr7773104edd.177.1647948276839; Tue, 22 Mar 2022 04:24:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647948276; cv=none; d=google.com; s=arc-20160816; b=tpi5tAIfok5tC5B85v8lckd8xFQxHxYkmwBQ4+x/Tf3COAk70m9M/Qns3m51Bzzr2J 7lWw+uiKO006SQ3xd8Hc0BS3qI4vyZa81pFBCt0GG5qkRsC9ZSQSPy6dkwriNnGyrE5H lH+hC93sLuEZy1wqjHDVbey5yPVutEdtnd0JRiOXhsVPpJuETmGcFvRZtq+SXoUljTKl twwcvukDhipkChP/WwGXIGehYlUuYGcubdD7vVd47Vff5bkkc8xgCH5P7T3LGHRRBiW5 t0MvDz2y57RuBmbM8Tu+AmOjjcs4Ejkt6ATmPHvMloTS+tdE3sfPxqI+BaXfJ9QeQoQ7 +6GQ== 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=NoM6EHi0XjCyQN28bkas2AtBgiZ28cEHh+DbqDTl1os=; b=fm6J3tPf44pFtujsOdlChqNYvr47aAMYVAXk+bHg2qj40gNF+GtYBpSL6ougpqEcm+ 3o8K+y9c0msIeHJZF6fCAx3kl8VgyEVrEsyH6dQPJ1n7cNL2Aw6fqiXpBC0p+GA8KWTx AmFszDDwBFtjYQkybSd0UFmOeKzGvinYtmX27daGt40nQRF2Ix3cUUv87Q3AVxI0HOQf LMfbbsq+hul2w8sO4hrxDUqKJIJ1xg1LZYzOsHHw+8QER9jGNUzLg3Ey9dqT4SIruefp fkiD8XvThTKTZKwwhKp6Q6091PMFOnnOcnl7m+EgwOQKwL6l5USsakNun54uJv1kKI6O tpXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pKrVqS2o; 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 k17-20020a50ce51000000b00418c2b5be28si12583814edj.266.2022.03.22.04.24.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 04:24:36 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pKrVqS2o; 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 6E94E83B48; Tue, 22 Mar 2022 12:23: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="pKrVqS2o"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9CEF3839D3; Tue, 22 Mar 2022 11:41: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-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) (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 B92D2838D5 for ; Tue, 22 Mar 2022 11:41:43 +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=rui.silva@linaro.org Received: by mail-ej1-x62d.google.com with SMTP id qa43so35148406ejc.12 for ; Tue, 22 Mar 2022 03:41:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NoM6EHi0XjCyQN28bkas2AtBgiZ28cEHh+DbqDTl1os=; b=pKrVqS2o+vLDZWQ4nZP5bzr7jPA0HcI0eK5EehwbQ/UHhn70Q7uqLRtcN48xnkMweR BOH+H3LTm9Bly58N2GpxExjAexbqRiwupy/0cTg6oVKa6sMo72lgHVpYnedjgKzIyw6Q ZWxG5Gr7NgJMsNmLveRNEi0Ik7AQXSGN6MZ4h0RtM6Ag5y4j2EQBdlrO28t46pHBw56q FAbnFUTUOsTE0tcxBzTWC3RhNIZNKpTXoQ49gMUeFwAiluzT/J5qi8jS7IPJvC2zWWXN glqwjfW52Xo0Dc6L1McxjpU10pnDQq7FhElT/WOXa64VBMyUu+ea1FS3U9qqJN7t4KIs 3J6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NoM6EHi0XjCyQN28bkas2AtBgiZ28cEHh+DbqDTl1os=; b=TVcXHWGJv7FVqyyK20xKTfs99dZzDM8g04WJ+F2VwZhqlwGZ2ULeQnUgjAxAMOAn7r Dofc/uVKHTNSgorwiLevx3iat6kO/dddElS84v/tTfIRQfY2f5lFXrJKdMo3JxNkC4vT 9PP4DG8stuAbAd+AVkgS2Qcov5G/XeHXJM20Jyah8L1nNRxknglbteYVJSoUX5wAxXOh 8iLVW09ApLhOTHbrc+Dql7u4BRVFQ6lhGzrgb+3LITi9NwN77g4ZeoqwFUTooO/PeKdJ vBJaH2FiGpc4uGF/UyvUeveXBU7B9i2uBwdISmDQD9fmaWjpc9pMosLYDy6oeMZLmVFT fkwQ== X-Gm-Message-State: AOAM533tKv6GQmteOR6oZweC7so5dHEj0uoo89jzZWTsR2411FExJQly 8fY/HNLec1mKXLCdPdgRCJeSIikE8dDNlQ== X-Received: by 2002:a17:907:2cc4:b0:6df:a036:a025 with SMTP id hg4-20020a1709072cc400b006dfa036a025mr23515207ejc.554.1647945703142; Tue, 22 Mar 2022 03:41:43 -0700 (PDT) Received: from arch-thunder.local (a109-49-33-111.cpe.netcabo.pt. [109.49.33.111]) by smtp.gmail.com with ESMTPSA id l2-20020aa7cac2000000b003f9b3ac68d6sm9359641edt.15.2022.03.22.03.41.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 03:41:42 -0700 (PDT) From: Rui Miguel Silva To: u-boot@lists.denx.de Cc: Rui Miguel Silva Subject: [PATCH 1/2] cmd: load: add load command for memory mapped Date: Tue, 22 Mar 2022 10:41:17 +0000 Message-Id: <20220322104118.573537-2-rui.silva@linaro.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220322104118.573537-1-rui.silva@linaro.org> References: <20220322104118.573537-1-rui.silva@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 22 Mar 2022 12:23:15 +0100 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 cp.b is used a lot as a way to load binaries to memory and execute them, however we may need to integrate this with the efi subsystem to set it up as a bootdev. So, introduce a loadm command that will be consistent with the other loadX commands and will call the efi API's. ex: loadm $kernel_addr $kernel_addr_r $kernel_size with this a kernel with CONFIG_EFI_STUB enabled will be loaded and then subsequently booted with bootefi command. Signed-off-by: Rui Miguel Silva --- README | 1 + cmd/Kconfig | 6 ++++ cmd/bootefi.c | 12 ++++++++ cmd/load.c | 48 ++++++++++++++++++++++++++++++++ include/efi_loader.h | 2 ++ lib/efi_loader/efi_device_path.c | 9 ++++++ 6 files changed, 78 insertions(+) diff --git a/README b/README index fe3ba01865e6..2932734b3edc 100644 --- a/README +++ b/README @@ -2693,6 +2693,7 @@ rarpboot- boot image via network using RARP/TFTP protocol diskboot- boot from IDE devicebootd - boot default, i.e., run 'bootcmd' loads - load S-Record file over serial line loadb - load binary file over serial line (kermit mode) +loadm - load binary blob from source address to destination address md - memory display mm - memory modify (auto-incrementing) nm - memory modify (constant address) diff --git a/cmd/Kconfig b/cmd/Kconfig index 564daa7bbc8d..d70e8398a558 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1076,6 +1076,12 @@ config CMD_LOADB help Load a binary file over serial line. +config CMD_LOADM + bool "loadm" + default y + help + Load a binary over memory mapped. + config CMD_LOADS bool "loads" default y diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 46eebd5ee225..64fe170bc3d6 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -34,6 +34,18 @@ 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 */ diff --git a/cmd/load.c b/cmd/load.c index 7e4a552d90ef..1224a7f85bb3 100644 --- a/cmd/load.c +++ b/cmd/load.c @@ -1063,6 +1063,44 @@ static ulong load_serial_ymodem(ulong offset, int mode) #endif +#if defined(CONFIG_CMD_LOADM) +static int do_load_memory_bin(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + ulong addr, dest, size; + void *src, *dst; + + if (argc != 4) + return CMD_RET_USAGE; + + addr = simple_strtoul(argv[1], NULL, 16); + + dest = simple_strtoul(argv[2], NULL, 16); + + size = simple_strtoul(argv[3], NULL, 16); + + if (!size) { + printf("loadm: can not load zero bytes\n"); + return 1; + } + + src = map_sysmem(addr, size); + dst = map_sysmem(dest, size); + + memcpy(dst, src, size); + + unmap_sysmem(src); + unmap_sysmem(dst); + + if (IS_ENABLED(CONFIG_CMD_BOOTEFI)) + efi_set_bootdev("Mem", "", "", map_sysmem(dest, 0), size); + + printf("loaded bin to memory: size: %lu\n", size); + + return 0; +} +#endif + /* -------------------------------------------------------------------- */ #if defined(CONFIG_CMD_LOADS) @@ -1137,3 +1175,13 @@ U_BOOT_CMD( ); #endif /* CONFIG_CMD_LOADB */ + +#if defined(CONFIG_CMD_LOADM) +U_BOOT_CMD( + loadm, 4, 0, do_load_memory_bin, + "load binary blob from source address to destination address", + "[src_addr] [dst_addr] [size]\n" + " - load a binary blob from one memory location to other" + " from src_addr to dst_addr by size bytes" +); +#endif /* CONFIG_CMD_LOADM */ diff --git a/include/efi_loader.h b/include/efi_loader.h index 110d8ae79cca..8d199db18ff2 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -585,6 +585,8 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, void efi_save_gd(void); /* Call this to relocate the runtime section to an address space */ void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map); +/* Call this to get image parameters */ +void efi_get_image_parameters(void **img_addr, size_t *img_size); /* Add a new object to the object list. */ void efi_add_handle(efi_handle_t obj); /* Create handle */ diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index dc787b4d3dde..707d5e043d3d 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -1112,6 +1112,8 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr, { struct blk_desc *desc = NULL; struct disk_partition fs_partition; + size_t image_size; + void *image_addr; int part = 0; char *filename; char *s; @@ -1127,6 +1129,13 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr, } else if (!strcmp(dev, "Uart")) { if (device) *device = efi_dp_from_uart(); + } else if (!strcmp(dev, "Mem")) { + efi_get_image_parameters(&image_addr, &image_size); + + if (device) + *device = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, + (uintptr_t)image_addr, + image_size); } else { part = blk_get_device_part_str(dev, devnr, &desc, &fs_partition, 1);