From patchwork Fri Oct 9 16:18:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Harkin X-Patchwork-Id: 528300 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 969AF140549 for ; Sat, 10 Oct 2015 03:19:59 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0F2774B8DB; Fri, 9 Oct 2015 18:19:58 +0200 (CEST) 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 fA9FnNWdWilt; Fri, 9 Oct 2015 18:19:57 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 695034B88E; Fri, 9 Oct 2015 18:19:09 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0B1894B893 for ; Fri, 9 Oct 2015 18:18:34 +0200 (CEST) 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 syXELqHpWuAZ for ; Fri, 9 Oct 2015 18:18:33 +0200 (CEST) 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-f182.google.com (mail-wi0-f182.google.com [209.85.212.182]) by theia.denx.de (Postfix) with ESMTPS id 305104B892 for ; Fri, 9 Oct 2015 18:18:25 +0200 (CEST) Received: by wicfx3 with SMTP id fx3so73668990wic.0 for ; Fri, 09 Oct 2015 09:18:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=eDPdobh8Tut7zNRg8re4jzmzD3wCMyga6ogWMajDrcw=; b=i/BZZ9PV19biBouqg3WwjhwPCxfzJ1YxNh5He+qYnJkYzLJuWU+T9NKp8nTtYaWjqm JIc5AiQL3JYVofHsl4pG3w3D4NkRQf6j1PRf7dP/IONtwjAiuf66uMdfYCPjSS1/R9ex oGSrjJSEbKs8pN1HMacS6K92GPNKqVP8Jd3Eh/1OzkHnBQiIHn8kEO1BgKbThNqg45ea BKGucu9b5yrbYpj+xBNPz1AOubQ7MQVxSr5xnudtFiNp0OedkjEoPfxPfsVCTW1KKKUs tUVSahpTR5sKJqiJKsdfBEZNeSKwTME/uKfbtmUEwjNJ0ov/WbnschY8lG6uWle/25T8 dfmw== X-Gm-Message-State: ALoCoQlJUI8wd6Atr1W4/uCRAveq1xqQXM6kU7F7rPXAqAVR7hr8G2aNqedqbYmgM2RMbFtwZZOE X-Received: by 10.194.238.228 with SMTP id vn4mr15511636wjc.13.1444407505688; Fri, 09 Oct 2015 09:18:25 -0700 (PDT) Received: from localhost.localdomain (82-69-54-187.dsl.in-addr.zen.co.uk. [82.69.54.187]) by smtp.gmail.com with ESMTPSA id bf8sm2942173wjc.22.2015.10.09.09.18.24 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Oct 2015 09:18:25 -0700 (PDT) From: Ryan Harkin To: ryan.harkin@linaro.org, u-boot@lists.denx.de, Albert Aribaud , Tom Rini Date: Fri, 9 Oct 2015 17:18:04 +0100 Message-Id: <1444407488-32646-7-git-send-email-ryan.harkin@linaro.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1444407488-32646-1-git-send-email-ryan.harkin@linaro.org> References: <1444407488-32646-1-git-send-email-ryan.harkin@linaro.org> Cc: Steve Rae Subject: [U-Boot] [PATCH v4 06/10] common/armflash: add command to check if image exists X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion 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" Add a command to the ARM flash support to check if an image exists or not. If the image is found, it will return CMD_RET_SUCCESS, else CMD_RET_FAILURE. This allows hush scripts to conditionally load images. A simple example: if afs exists ${kernel_name}; then echo found; else echo \ not found; fi Signed-off-by: Ryan Harkin Reviewed-by: Linus Walleij --- common/cmd_armflash.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/common/cmd_armflash.c b/common/cmd_armflash.c index 1db92b0..a37f5c4 100644 --- a/common/cmd_armflash.c +++ b/common/cmd_armflash.c @@ -251,10 +251,28 @@ static void print_images(void) } } +static int exists(const char * const name) +{ + int i; + + parse_flash(); + for (i = 0; i < num_afs_images; i++) { + struct afs_image *afi = &afs_images[i]; + + if (strcmp(afi->name, name) == 0) + return CMD_RET_SUCCESS; + } + return CMD_RET_FAILURE; +} + static int do_afs(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { + int ret = CMD_RET_SUCCESS; + if (argc == 1) { print_images(); + } else if (argc == 3 && !strcmp(argv[1], "exists")) { + ret = exists(argv[2]); } else if (argc == 3 && !strcmp(argv[1], "load")) { load_image(argv[2], 0x0); } else if (argc == 4 && !strcmp(argv[1], "load")) { @@ -266,12 +284,14 @@ static int do_afs(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return CMD_RET_USAGE; } - return 0; + return ret; } U_BOOT_CMD(afs, 4, 0, do_afs, "show AFS partitions", "no arguments\n" " - list images in flash\n" + "exists \n" + " - returns 1 if an image exists, else 0\n" "load \n" " - load an image to the location indicated in the header\n" "load 0x
\n"