From patchwork Thu Nov 20 10:25:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 41227 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DF1E023588 for ; Thu, 20 Nov 2014 10:25:52 +0000 (UTC) Received: by mail-wg0-f71.google.com with SMTP id l18sf1510915wgh.2 for ; Thu, 20 Nov 2014 02:25:52 -0800 (PST) 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:cc:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list; bh=YiBWAYcuIUTYcxMXVZzBiX909gPe8k9zgwqR6ogkaB8=; b=R2Qip8X95e7j6mb07tvd5tNyW4GRyNw3XWmUcLGZG5UwmiYUuoQWtCBciSAePJKrBh /9uZqwVlcxiZ/JsPpeiwPlf8xHz/XUqQpoZEZSkV+c3aAOSoU2VLvIDgrP0FLRwZX+Kd rcq3RMKRvKjiZCza3Pyb6/dueAfDh4NQo2kM6lMh7VMYQkcC8Q7AjsorqWwt+mcvCVqA uzex2TqHAozNmIgx+dTabAjhsBjMImL3ngUpz+aGSyj8jRkhDtPjze5EHQK8Li/N55Hs 1QtnsPE3LY5goVyi+P/KoD/Uf+qS8uVZYKZvfy2YHldgwP0KqaBn3RCJ1ByNVyVCUybj 4CFQ== X-Gm-Message-State: ALoCoQnKQ0sB7EcPWEjvGIeXyrc45rxIsjt9tUKuzq7rpYEzQzyMEufQ+mO5tsFcRfKmCoq+5W3K X-Received: by 10.112.32.163 with SMTP id k3mr561917lbi.17.1416479152162; Thu, 20 Nov 2014 02:25:52 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.228.140 with SMTP id si12ls44376lac.25.gmail; Thu, 20 Nov 2014 02:25:52 -0800 (PST) X-Received: by 10.152.88.69 with SMTP id be5mr3773893lab.36.1416479152020; Thu, 20 Nov 2014 02:25:52 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id rs2si1763476lbb.91.2014.11.20.02.25.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Nov 2014 02:25:52 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id f15so544893lbj.41 for ; Thu, 20 Nov 2014 02:25:51 -0800 (PST) X-Received: by 10.112.52.37 with SMTP id q5mr10356095lbo.32.1416479151888; Thu, 20 Nov 2014 02:25:51 -0800 (PST) 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.184.201 with SMTP id ew9csp237042lbc; Thu, 20 Nov 2014 02:25:51 -0800 (PST) X-Received: by 10.194.81.38 with SMTP id w6mr66867115wjx.17.1416479151273; Thu, 20 Nov 2014 02:25:51 -0800 (PST) Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id c4si3620679wiz.99.2014.11.20.02.25.50 for ; Thu, 20 Nov 2014 02:25:51 -0800 (PST) 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 525614B6B3; Thu, 20 Nov 2014 11:25:50 +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 rrZCslBk-jmO; Thu, 20 Nov 2014 11:25:50 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B1D874B6BA; Thu, 20 Nov 2014 11:25:49 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3EEB44B69C for ; Thu, 20 Nov 2014 11:25: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 7ST-JBXTERi1 for ; Thu, 20 Nov 2014 11:25: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-wg0-f41.google.com (mail-wg0-f41.google.com [74.125.82.41]) by theia.denx.de (Postfix) with ESMTPS id 20ACC4B6BA for ; Thu, 20 Nov 2014 11:25:35 +0100 (CET) Received: by mail-wg0-f41.google.com with SMTP id y19so3263637wgg.28 for ; Thu, 20 Nov 2014 02:25:35 -0800 (PST) X-Received: by 10.180.8.34 with SMTP id o2mr13790092wia.23.1416479135027; Thu, 20 Nov 2014 02:25:35 -0800 (PST) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id da3sm2735137wjb.12.2014.11.20.02.25.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Nov 2014 02:25:33 -0800 (PST) From: Linus Walleij To: u-boot@lists.denx.de, Albert Aribaud Date: Thu, 20 Nov 2014 11:25:31 +0100 Message-Id: <1416479131-27853-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.9.3 Cc: u-boot-review@google.com, Mark Hambleton , Tom Rini , Darwin Rambo Subject: [U-Boot] [PATCH 3/3] arm: semihosting: get rid of forward declarations X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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.182 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 By rearranging the functions in the semihosting code we can avoid forward-declaration of the internal static functions. This puts the stuff in a logical order: read/open/close/len and then higher-order functions follow at the end. Cc: Darwin Rambo Cc: AKASHI Takahiro Cc: Mark Hambleton Cc: Tom Rini Signed-off-by: Linus Walleij --- arch/arm/lib/semihosting.c | 173 ++++++++++++++++++++++----------------------- 1 file changed, 84 insertions(+), 89 deletions(-) diff --git a/arch/arm/lib/semihosting.c b/arch/arm/lib/semihosting.c index 6e1b2d182eca..2eacbacfde0f 100644 --- a/arch/arm/lib/semihosting.c +++ b/arch/arm/lib/semihosting.c @@ -23,11 +23,6 @@ #define MODE_READ 0x0 #define MODE_READBIN 0x1 -static long smh_read(long fd, void *memp, size_t len); -static long smh_open(const char *fname, char *modestr); -static long smh_close(long fd); -static long smh_len_fd(long fd); - /* * Call the handler */ @@ -44,60 +39,43 @@ static long smh_trap(unsigned int sysnum, void *addr) } /* - * Open, load a file into memory, and close it. Check that the available space - * is sufficient to store the entire file. Return the bytes actually read from - * the file as seen by the read function. The verbose flag enables some extra - * printing of successful read status. + * Open a file on the host. Mode is "r" or "rb" currently. Returns a file + * descriptor or -1 on error. */ -int smh_load(const char *fname, void *memp, int avail, int verbose) +static long smh_open(const char *fname, char *modestr) { - long ret; long fd; - size_t len; - - ret = -1; - - debug("%s: fname \'%s\', avail %u, memp %p\n", __func__, fname, - avail, memp); - - /* Open the file */ - fd = smh_open(fname, "rb"); - if (fd == -1) - return -1; + unsigned long mode; + struct smh_open_s { + const char *fname; + unsigned long mode; + size_t len; + } open; - /* Get the file length */ - ret = smh_len_fd(fd); - if (ret == -1) { - smh_close(fd); - return -1; - } + debug("%s: file \'%s\', mode \'%s\'\n", __func__, fname, modestr); - /* Check that the file will fit in the supplied buffer */ - if (ret > avail) { - printf("%s: ERROR ret %ld, avail %u\n", __func__, ret, - avail); - smh_close(fd); + /* Check the file mode */ + if (!(strcmp(modestr, "r"))) { + mode = MODE_READ; + } else if (!(strcmp(modestr, "rb"))) { + mode = MODE_READBIN; + } else { + printf("%s: ERROR mode \'%s\' not supported\n", __func__, + modestr); return -1; } - len = ret; - - /* Read the file into the buffer */ - ret = smh_read(fd, memp, len); - if (ret == 0) { - /* Print successful load information if requested */ - if (verbose) { - printf("\n%s\n", fname); - printf(" 0x%8p dest\n", memp); - printf(" 0x%08lx size\n", len); - printf(" 0x%08x avail\n", avail); - } - } + open.fname = fname; + open.len = strlen(fname); + open.mode = mode; - /* Close the file */ - smh_close(fd); + /* Open the file on the host */ + fd = smh_trap(SYSOPEN, &open); + if (fd == -1) + printf("%s: ERROR fd %ld for file \'%s\'\n", __func__, fd, + fname); - return ret; + return fd; } /* @@ -135,46 +113,6 @@ static long smh_read(long fd, void *memp, size_t len) } /* - * Open a file on the host. Mode is "r" or "rb" currently. Returns a file - * descriptor or -1 on error. - */ -static long smh_open(const char *fname, char *modestr) -{ - long fd; - unsigned long mode; - struct smh_open_s { - const char *fname; - unsigned long mode; - size_t len; - } open; - - debug("%s: file \'%s\', mode \'%s\'\n", __func__, fname, modestr); - - /* Check the file mode */ - if (!(strcmp(modestr, "r"))) { - mode = MODE_READ; - } else if (!(strcmp(modestr, "rb"))) { - mode = MODE_READBIN; - } else { - printf("%s: ERROR mode \'%s\' not supported\n", __func__, - modestr); - return -1; - } - - open.fname = fname; - open.len = strlen(fname); - open.mode = mode; - - /* Open the file on the host */ - fd = smh_trap(SYSOPEN, &open); - if (fd == -1) - printf("%s: ERROR fd %ld for file \'%s\'\n", __func__, fd, - fname); - - return fd; -} - -/* * Close the file using the file descriptor */ static long smh_close(long fd) @@ -207,6 +145,63 @@ static long smh_len_fd(long fd) } /* + * Open, load a file into memory, and close it. Check that the available space + * is sufficient to store the entire file. Return the bytes actually read from + * the file as seen by the read function. The verbose flag enables some extra + * printing of successful read status. + */ +int smh_load(const char *fname, void *memp, int avail, int verbose) +{ + long ret; + long fd; + size_t len; + + ret = -1; + + debug("%s: fname \'%s\', avail %u, memp %p\n", __func__, fname, + avail, memp); + + /* Open the file */ + fd = smh_open(fname, "rb"); + if (fd == -1) + return -1; + + /* Get the file length */ + ret = smh_len_fd(fd); + if (ret == -1) { + smh_close(fd); + return -1; + } + + /* Check that the file will fit in the supplied buffer */ + if (ret > avail) { + printf("%s: ERROR ret %ld, avail %u\n", __func__, ret, + avail); + smh_close(fd); + return -1; + } + + len = ret; + + /* Read the file into the buffer */ + ret = smh_read(fd, memp, len); + if (ret == 0) { + /* Print successful load information if requested */ + if (verbose) { + printf("\n%s\n", fname); + printf(" 0x%8p dest\n", memp); + printf(" 0x%08lx size\n", len); + printf(" 0x%08x avail\n", avail); + } + } + + /* Close the file */ + smh_close(fd); + + return ret; +} + +/* * Get the file length from the filename */ long smh_len(const char *fname)