X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=common%2Fcmd_source.c;h=6881bc9ddd3382c02c4c6130f313e5efca0066f3;hb=f13606b77d32344d35f6430eb45cffd47302e244;hp=43e131592933346b0a36f53c014583b2ea526862;hpb=ca41ef301b21b3ac25af71750624e0b3d5ddbb3e;p=people%2Fms%2Fu-boot.git diff --git a/common/cmd_source.c b/common/cmd_source.c index 43e1315929..6881bc9ddd 100644 --- a/common/cmd_source.c +++ b/common/cmd_source.c @@ -2,23 +2,7 @@ * (C) Copyright 2001 * Kyle Harris, kharris@nexus-tech.net * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA + * SPDX-License-Identifier: GPL-2.0+ */ /* @@ -36,22 +20,21 @@ #include #include #include +#include #if defined(CONFIG_8xx) #include #endif -#ifdef CONFIG_SYS_HUSH_PARSER -#include -#endif int source (ulong addr, const char *fit_uname) { ulong len; - image_header_t *hdr; +#if defined(CONFIG_IMAGE_FORMAT_LEGACY) + const image_header_t *hdr; +#endif ulong *data; - char *cmd; - int rcode = 0; int verify; + void *buf; #if defined(CONFIG_FIT) const void* fit_hdr; int noffset; @@ -61,9 +44,11 @@ source (ulong addr, const char *fit_uname) verify = getenv_yesno ("verify"); - switch (genimg_get_format ((void *)addr)) { + buf = map_sysmem(addr, 0); + switch (genimg_get_format(buf)) { +#if defined(CONFIG_IMAGE_FORMAT_LEGACY) case IMAGE_FORMAT_LEGACY: - hdr = (image_header_t *)addr; + hdr = buf; if (!image_check_magic (hdr)) { puts ("Bad magic number\n"); @@ -102,6 +87,7 @@ source (ulong addr, const char *fit_uname) */ while (*data++); break; +#endif #if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: if (fit_uname == NULL) { @@ -109,7 +95,7 @@ source (ulong addr, const char *fit_uname) return 1; } - fit_hdr = (const void *)addr; + fit_hdr = buf; if (!fit_check_format (fit_hdr)) { puts ("Bad FIT image format\n"); return 1; @@ -129,7 +115,7 @@ source (ulong addr, const char *fit_uname) /* verify integrity */ if (verify) { - if (!fit_image_check_hashes (fit_hdr, noffset)) { + if (!fit_image_verify(fit_hdr, noffset)) { puts ("Bad Data Hash\n"); return 1; } @@ -151,55 +137,12 @@ source (ulong addr, const char *fit_uname) } debug ("** Script length: %ld\n", len); - - if ((cmd = malloc (len + 1)) == NULL) { - return 1; - } - - /* make sure cmd is null terminated */ - memmove (cmd, (char *)data, len); - *(cmd + len) = 0; - -#ifdef CONFIG_SYS_HUSH_PARSER /*?? */ - rcode = parse_string_outer (cmd, FLAG_PARSE_SEMICOLON); -#else - { - char *line = cmd; - char *next = cmd; - - /* - * break into individual lines, - * and execute each line; - * terminate on error. - */ - while (*next) { - if (*next == '\n') { - *next = '\0'; - /* run only non-empty commands */ - if (*line) { - debug ("** exec: \"%s\"\n", - line); - if (run_command (line, 0) < 0) { - rcode = 1; - break; - } - } - line = next + 1; - } - ++next; - } - if (rcode == 0 && *line) - rcode = (run_command(line, 0) >= 0); - } -#endif - free (cmd); - return rcode; + return run_command_list((char *)data, len, 0); } /**************************************************/ #if defined(CONFIG_CMD_SOURCE) -int -do_source (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +static int do_source(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { ulong addr; int rcode; @@ -224,33 +167,21 @@ do_source (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return rcode; } -U_BOOT_CMD( - source, 2, 0, do_source, - "run script from memory", +#ifdef CONFIG_SYS_LONGHELP +static char source_help_text[] = "[addr]\n" "\t- run script starting at addr\n" - "\t- A valid image header must be present\n" + "\t- A valid image header must be present" #if defined(CONFIG_FIT) + "\n" "For FIT format uImage addr must include subimage\n" - "unit name in the form of addr:\n" + "unit name in the form of addr:" +#endif + ""; #endif -); - -/* - * Keep for now for backward compatibility; - * remove later when support for "autoscr" goes away. - */ -static int -do_autoscr (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - printf ("\n### WARNING ### " - "\"autoscr\" is deprecated, use \"source\" instead ###\n\n"); - return do_source (cmdtp, flag, argc, argv); -} U_BOOT_CMD( - autoscr, 2, 0, do_autoscr, - "DEPRECATED - use \"source\" command instead", - "DEPRECATED - use \"source\" command instead\n" + source, 2, 0, do_source, + "run script from memory", source_help_text ); #endif