From patchwork Mon Dec 15 10:06:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 42222 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A47FA2456A for ; Mon, 15 Dec 2014 10:06:27 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id w7sf3423381lbi.8 for ; Mon, 15 Dec 2014 02:06:26 -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=+VBiYY5eUQGpuyiNas28obHTuWa1MwLl2vM//DDdMxA=; b=EcrEulgDGDayD3SYnxwhT2W9jce7t5gG6r1tTBEQP42SOgs0nhirpMh0iGD1i7nyYC RQd02jf4d061+D21U1OCzJ8ThqaXUfnreIkzrWTP5BMwuscn6ugPD7x6w0oTwGOOHu/5 5IqRORihQH4QXq2PmP6gJ8RFcBmkP4iCIj9xvS0UZP5INURPKaRaCGxWgSc6aNK4iCFQ ro8RKM+cnWIfGth+F2I85egDxxvODoocuq2KhjV34xjeSuvogsQfElFHKcTG7KaEZFel KHTnqjjO/iLBUlXRRohAoaymKQK6nN1EaPGlG0RPdPQzqMGZ/egSv2VmD3iemqjUnmQQ o/jQ== X-Gm-Message-State: ALoCoQmp/HJKRZvQ99Ys2znKF6UC33KJCTNWV1UlTp6qx6rtiu0nNnfObW/5AkgEUtuvYb3w5Me4 X-Received: by 10.112.142.36 with SMTP id rt4mr4539434lbb.3.1418637986662; Mon, 15 Dec 2014 02:06:26 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.20.132 with SMTP id n4ls456392lae.57.gmail; Mon, 15 Dec 2014 02:06:26 -0800 (PST) X-Received: by 10.112.8.69 with SMTP id p5mr29254490lba.97.1418637986287; Mon, 15 Dec 2014 02:06:26 -0800 (PST) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id tn9si9979251lbb.72.2014.12.15.02.06.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 15 Dec 2014 02:06:26 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by mail-la0-f52.google.com with SMTP id hs14so9215901lab.11 for ; Mon, 15 Dec 2014 02:06:26 -0800 (PST) X-Received: by 10.152.2.74 with SMTP id 10mr28822715las.38.1418637986168; Mon, 15 Dec 2014 02:06:26 -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.142.69 with SMTP id ru5csp665818lbb; Mon, 15 Dec 2014 02:06:25 -0800 (PST) X-Received: by 10.180.221.72 with SMTP id qc8mr30252274wic.19.1418637984438; Mon, 15 Dec 2014 02:06:24 -0800 (PST) Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id n1si15886868wix.100.2014.12.15.02.06.21; Mon, 15 Dec 2014 02:06:24 -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 B73234B97A; Mon, 15 Dec 2014 11:06:21 +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 ygxzWbjUCkSu; Mon, 15 Dec 2014 11:06:21 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 43B994B9A0; Mon, 15 Dec 2014 11:06:21 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3DC984B9C3 for ; Mon, 15 Dec 2014 11:06:17 +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 McLaGSDWRwKx for ; Mon, 15 Dec 2014 11:06:17 +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-wi0-f174.google.com (mail-wi0-f174.google.com [209.85.212.174]) by theia.denx.de (Postfix) with ESMTPS id 2841C4B9E2 for ; Mon, 15 Dec 2014 11:06:09 +0100 (CET) Received: by mail-wi0-f174.google.com with SMTP id h11so8306410wiw.1 for ; Mon, 15 Dec 2014 02:06:09 -0800 (PST) X-Received: by 10.180.97.195 with SMTP id ec3mr30495631wib.79.1418637969208; Mon, 15 Dec 2014 02:06:09 -0800 (PST) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id ep6sm12642915wib.0.2014.12.15.02.06.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Dec 2014 02:06:08 -0800 (PST) From: Linus Walleij To: u-boot@lists.denx.de, Albert Aribaud , Steve Rae Date: Mon, 15 Dec 2014 11:06:05 +0100 Message-Id: <1418637965-23554-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 v2] 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.215.52 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 Acked-by: Steve Rae Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebased on 2/3 v2. - Added Steve's ACK. --- 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 e9d524e18aca..fd6d8573f560 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)