diff mbox

[v4,06/10] common/armflash: add command to check if image exists

Message ID 1444407488-32646-7-git-send-email-ryan.harkin@linaro.org
State Accepted
Commit 1a9717fb30c5cbb70dcc5d53791670967dfe3487
Headers show

Commit Message

Ryan Harkin Oct. 9, 2015, 4:18 p.m. UTC
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 <ryan.harkin@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
---
 common/cmd_armflash.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

Comments

Tom Rini Oct. 12, 2015, 3:17 p.m. UTC | #1
On Fri, Oct 09, 2015 at 05:18:04PM +0100, Ryan Harkin wrote:

> 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 <ryan.harkin@linaro.org>
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Applied to u-boot/master, thanks!
diff mbox

Patch

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 <image>\n"
+	   "    - returns 1 if an image exists, else 0\n"
 	   "load <image>\n"
 	   "    - load an image to the location indicated in the header\n"
 	   "load <image> 0x<address>\n"