Commit 1a9717fb30c5cbb70dcc5d53791670967dfe3487
Committed by
Tom Rini
1 parent
74e264b49f
Exists in
v2017.01-smarct4x
and in
30 other branches
common/armflash: add command to check if image exists
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>
Showing 1 changed file with 21 additions and 1 deletions Side-by-side Diff
common/cmd_armflash.c
... | ... | @@ -251,10 +251,28 @@ |
251 | 251 | } |
252 | 252 | } |
253 | 253 | |
254 | +static int exists(const char * const name) | |
255 | +{ | |
256 | + int i; | |
257 | + | |
258 | + parse_flash(); | |
259 | + for (i = 0; i < num_afs_images; i++) { | |
260 | + struct afs_image *afi = &afs_images[i]; | |
261 | + | |
262 | + if (strcmp(afi->name, name) == 0) | |
263 | + return CMD_RET_SUCCESS; | |
264 | + } | |
265 | + return CMD_RET_FAILURE; | |
266 | +} | |
267 | + | |
254 | 268 | static int do_afs(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
255 | 269 | { |
270 | + int ret = CMD_RET_SUCCESS; | |
271 | + | |
256 | 272 | if (argc == 1) { |
257 | 273 | print_images(); |
274 | + } else if (argc == 3 && !strcmp(argv[1], "exists")) { | |
275 | + ret = exists(argv[2]); | |
258 | 276 | } else if (argc == 3 && !strcmp(argv[1], "load")) { |
259 | 277 | load_image(argv[2], 0x0); |
260 | 278 | } else if (argc == 4 && !strcmp(argv[1], "load")) { |
261 | 279 | |
... | ... | @@ -266,12 +284,14 @@ |
266 | 284 | return CMD_RET_USAGE; |
267 | 285 | } |
268 | 286 | |
269 | - return 0; | |
287 | + return ret; | |
270 | 288 | } |
271 | 289 | |
272 | 290 | U_BOOT_CMD(afs, 4, 0, do_afs, "show AFS partitions", |
273 | 291 | "no arguments\n" |
274 | 292 | " - list images in flash\n" |
293 | + "exists <image>\n" | |
294 | + " - returns 1 if an image exists, else 0\n" | |
275 | 295 | "load <image>\n" |
276 | 296 | " - load an image to the location indicated in the header\n" |
277 | 297 | "load <image> 0x<address>\n" |