2002-11-03 00:38:21 +00:00
|
|
|
/*
|
2007-10-16 17:07:21 +00:00
|
|
|
* go- execute some code anywhere (misc boot support)
|
|
|
|
*
|
2003-06-27 21:31:46 +00:00
|
|
|
* (C) Copyright 2000-2003
|
2002-11-03 00:38:21 +00:00
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2008-08-14 08:26:23 +00:00
|
|
|
#include <fs.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <errno.h>
|
2002-11-03 00:38:21 +00:00
|
|
|
|
2007-09-28 08:07:26 +00:00
|
|
|
static int do_go (cmd_tbl_t *cmdtp, int argc, char *argv[])
|
2002-11-03 00:38:21 +00:00
|
|
|
{
|
2008-08-14 08:26:23 +00:00
|
|
|
void *addr;
|
|
|
|
int rcode = 1;
|
|
|
|
int fd = -1;
|
2002-11-03 00:38:21 +00:00
|
|
|
|
2009-10-17 10:44:19 +00:00
|
|
|
if (argc < 2)
|
|
|
|
return COMMAND_ERROR_USAGE;
|
2002-11-03 00:38:21 +00:00
|
|
|
|
2008-08-14 08:26:23 +00:00
|
|
|
if (!isdigit(*argv[1])) {
|
|
|
|
fd = open(argv[1], O_RDONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
perror("open");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = memmap(fd, PROT_READ);
|
|
|
|
if (addr == (void *)-1) {
|
|
|
|
perror("memmap");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
addr = (void *)simple_strtoul(argv[1], NULL, 16);
|
2002-11-03 00:38:21 +00:00
|
|
|
|
2003-03-26 06:55:25 +00:00
|
|
|
printf ("## Starting application at 0x%08lX ...\n", addr);
|
2002-11-03 00:38:21 +00:00
|
|
|
|
2009-02-21 00:22:48 +00:00
|
|
|
console_flush();
|
|
|
|
|
2007-09-16 09:16:08 +00:00
|
|
|
#ifdef ARCH_HAS_EXECUTE
|
2008-08-14 08:26:23 +00:00
|
|
|
rcode = arch_execute(addr, argc, &argv[1]);
|
2003-10-08 23:26:14 +00:00
|
|
|
#else
|
2008-08-14 08:26:23 +00:00
|
|
|
rcode = ((ulong (*)(int, char *[]))addr) (--argc, &argv[1]);
|
2003-10-08 23:26:14 +00:00
|
|
|
#endif
|
2002-11-03 00:38:21 +00:00
|
|
|
|
2008-08-14 08:26:23 +00:00
|
|
|
printf ("## Application terminated, rcode = 0x%lX\n", rcode);
|
|
|
|
out:
|
|
|
|
if (fd > 0)
|
|
|
|
close(fd);
|
|
|
|
|
2002-11-03 00:38:21 +00:00
|
|
|
return rcode;
|
|
|
|
}
|
|
|
|
|
2008-04-04 09:46:55 +00:00
|
|
|
static const __maybe_unused char cmd_go_help[] =
|
2008-08-14 08:26:23 +00:00
|
|
|
"Usage: go addr [arg ...]\n"
|
|
|
|
"Start application at address 'addr' passing 'arg' as arguments.\n"
|
|
|
|
"If addr does not start with a digit it is interpreted as a filename\n"
|
|
|
|
"in which case the file is memmapped and executed\n";
|
2002-11-03 00:38:21 +00:00
|
|
|
|
2007-07-05 16:01:52 +00:00
|
|
|
U_BOOT_CMD_START(go)
|
|
|
|
.maxargs = CONFIG_MAXARGS,
|
|
|
|
.cmd = do_go,
|
2008-08-14 08:26:23 +00:00
|
|
|
.usage = "start application at address or file",
|
2008-04-04 09:46:55 +00:00
|
|
|
U_BOOT_CMD_HELP(cmd_go_help)
|
2007-07-05 16:01:52 +00:00
|
|
|
U_BOOT_CMD_END
|