From patchwork Mon Mar 23 10:06:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 46175 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C405320D10 for ; Mon, 23 Mar 2015 10:06:46 +0000 (UTC) Received: by lamq1 with SMTP id q1sf26314224lam.3 for ; Mon, 23 Mar 2015 03:06:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list; bh=Avq0oA7WSvhdfyadWtf66S4js/fQiDUnlWXAWn+tUBw=; b=dgzaqDGDeIqrJ68SvNeS1Hve4u4Am3EJFWUPl07Yv/p7D/oTlUQqXeQneVOJ0aSVwq uBkSEafit+vOwLifH108lliPmP8Ac+IHkdwN8NvkTlJkmRIxYlarr1EMYfh9oCMJSseU 6J38FaXWISSzLRihUFJMCKZcXOQUHToHb6DTSp3ZoHKwVk2CmakNamrOzPL2jfbpSuZS n0hmcy06P5KK6tX6kVsHW6A+2ZEPXdcy//8VN5X48Jb/3XSyHHGfeMbp7yr/+RCDovDR JtkOAvAyvznCqx3WxvZ9/TaOhG4pCT/YigA842YmgOjlyqBoP8RfzATvU+i84MPZnk2b xKVA== X-Gm-Message-State: ALoCoQkFWGiiAcLkQ15JeXrtrpizgtw2NkSLWimwCE0q8Y1GpfJ0nKQa3+lxCespW4um1OvsHty6 X-Received: by 10.112.118.203 with SMTP id ko11mr1971698lbb.15.1427105205729; Mon, 23 Mar 2015 03:06:45 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.169 with SMTP id x9ls679374lal.92.gmail; Mon, 23 Mar 2015 03:06:45 -0700 (PDT) X-Received: by 10.112.219.135 with SMTP id po7mr82108643lbc.111.1427105205446; Mon, 23 Mar 2015 03:06:45 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id yt20si248086lbb.89.2015.03.23.03.06.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Mar 2015 03:06:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbbsy1 with SMTP id sy1so114649987lbb.1 for ; Mon, 23 Mar 2015 03:06:45 -0700 (PDT) X-Received: by 10.112.46.74 with SMTP id t10mr6241684lbm.73.1427105205233; Mon, 23 Mar 2015 03:06:45 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.57.201 with SMTP id k9csp724806lbq; Mon, 23 Mar 2015 03:06:44 -0700 (PDT) X-Received: by 10.194.122.196 with SMTP id lu4mr185322293wjb.154.1427105204532; Mon, 23 Mar 2015 03:06:44 -0700 (PDT) Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id qa2si11041478wic.10.2015.03.23.03.06.43; Mon, 23 Mar 2015 03:06:44 -0700 (PDT) Received-SPF: none (google.com: u-boot-bounces@lists.denx.de does not designate permitted sender hosts) client-ip=85.214.87.163; Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5EB9FA7460; Mon, 23 Mar 2015 11:06:43 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Qe6PtKupNAYF; Mon, 23 Mar 2015 11:06:43 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D39F7A743B; Mon, 23 Mar 2015 11:06:42 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CF0DBA7462 for ; Mon, 23 Mar 2015 11:06:39 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cZfQnzAqEKB8 for ; Mon, 23 Mar 2015 11:06:39 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com [209.85.215.50]) by theia.denx.de (Postfix) with ESMTPS id 246FBA745A for ; Mon, 23 Mar 2015 11:06:32 +0100 (CET) Received: by labe2 with SMTP id e2so54495684lab.3 for ; Mon, 23 Mar 2015 03:06:31 -0700 (PDT) X-Received: by 10.112.161.66 with SMTP id xq2mr83485960lbb.103.1427105191730; Mon, 23 Mar 2015 03:06:31 -0700 (PDT) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id x7sm87147lag.3.2015.03.23.03.06.29 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Mar 2015 03:06:30 -0700 (PDT) From: Linus Walleij To: u-boot@lists.denx.de, Albert Aribaud , Tom Rini Date: Mon, 23 Mar 2015 11:06:11 +0100 Message-Id: <1427105174-20072-2-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1427105174-20072-1-git-send-email-linus.walleij@linaro.org> References: <1427105174-20072-1-git-send-email-linus.walleij@linaro.org> Cc: Steve Rae , u-boot-review@google.com Subject: [U-Boot] [PATCH 2/5] armv8: semihosting: add a command to load semihosted images X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linus.walleij@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Instead of sprinkling custom code and calls over the Vexpress64 boardfile, create a command that loads images using semihosting just like we would load from flash memory of over the network, using a special command: smhload
This will make it possible to remove some custom calls and code and make the boot easier. Signed-off-by: Linus Walleij --- arch/arm/lib/semihosting.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ doc/README.semihosting | 25 ++++------------- 2 files changed, 75 insertions(+), 20 deletions(-) diff --git a/arch/arm/lib/semihosting.c b/arch/arm/lib/semihosting.c index d3f724b726e1..edacb1187731 100644 --- a/arch/arm/lib/semihosting.c +++ b/arch/arm/lib/semihosting.c @@ -13,6 +13,7 @@ * for them. */ #include +#include #include #define SYSOPEN 0x01 @@ -234,3 +235,72 @@ long smh_len(const char *fname) /* Return the file length (or -1 error indication) */ return len; } + +static int smh_load_file(const char * const name, ulong load_addr, + ulong *end_addr) +{ + long fd; + long len; + long ret; + + fd = smh_open(name, "rb"); + if (fd == -1) + return -1; + + len = smh_len_fd(fd); + if (len < 0) { + smh_close(fd); + return -1; + } + + ret = smh_read(fd, (void *)load_addr, len); + smh_close(fd); + + if (ret == 0) { + *end_addr = load_addr + len - 1; + printf("loaded file %s from %08lX to %08lX, %08lX bytes\n", + name, + load_addr, + *end_addr, + len); + } else { + printf("read failed\n"); + return 0; + } + + return 0; +} + +static int do_smhload(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + if (argc == 3 || argc == 4) { + ulong load_addr; + ulong end_addr = 0; + ulong ret; + char end_str[64]; + + load_addr = simple_strtoul(argv[2], NULL, 16); + if (!load_addr) + return -1; + + ret = smh_load_file(argv[1], load_addr, &end_addr); + if (ret < 0) + return 1; + + /* Optionally save returned end to the environment */ + if (argc == 4) { + sprintf(end_str, "0x%08lx", end_addr); + setenv(argv[3], end_str); + } + } else { + return CMD_RET_USAGE; + } + return 0; +} + +U_BOOT_CMD(smhload, 4, 0, do_smhload, "load a file using semihosting", + " 0x
[end var]\n" + " - load a semihosted file to the address specified\n" + " if the optional [end var] is specified, the end\n" + " address of the file will be stored in this environment\n" + " variable.\n"); diff --git a/doc/README.semihosting b/doc/README.semihosting index 724856078069..c016a4f8406d 100644 --- a/doc/README.semihosting +++ b/doc/README.semihosting @@ -30,25 +30,10 @@ vexpress_aemv8a.h but differentiate the two models by the presence or absence of CONFIG_BASE_FVP. This change is tested and works on both the Foundation and Base fastmodel simulators. -The level of semihosting support is minimal, restricted to just what it -takes to load images to memory. If more semihosting functionality is -required, such as file seek, outputting strings, reading characters, etc, -then it can be easily added later. +The semihosting code adds a command: -We require that the board include file define these env variables: -- kernel_name e.g. "uImage" -- kernel_addr_r e.g. "0x80000000" -- initrd_name e.g. "ramdisk.img" -- initrd_addr_r e.g. "0x88000000" -- fdt_name e.g. "devtree.dtb" -- fdt_addr_r e.g. "0x83000000" + smhload
[env var] -Optionally, "fdt_high" and "initrd_high" can be specified as per -their rules for allowing or preventing copying of these images. - -For the "fdt chosen" startup macro, this code will then define: -- initrd_end (based on retrieving initrd_addr_r plus actual initrd_size) - -We will then load the kernel, initrd, and fdt into the specified -locations in memory in a similar way that the ATF fastmodel code -uses semihosting calls to load other boot stages and u-boot itself. +That will load an image from the host filesystem into RAM at the specified +address and optionally store the load end address in the specified +environment variable.