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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2011-06-10 02:36:01 +00:00
|
|
|
#include <complete.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
|
|
|
|
2011-12-21 13:18:57 +00:00
|
|
|
static int do_go(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;
|
2010-03-30 08:35:11 +00:00
|
|
|
int (*func)(int argc, char *argv[]);
|
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
|
|
|
|
2010-12-20 23:02:02 +00:00
|
|
|
printf("## Starting application at 0x%p ...\n", addr);
|
2002-11-03 00:38:21 +00:00
|
|
|
|
2009-02-21 00:22:48 +00:00
|
|
|
console_flush();
|
|
|
|
|
2010-03-30 08:35:11 +00:00
|
|
|
func = addr;
|
2002-11-03 00:38:21 +00:00
|
|
|
|
2010-03-30 08:35:11 +00:00
|
|
|
shutdown_barebox();
|
2011-12-10 15:41:07 +00:00
|
|
|
|
|
|
|
if (do_execute)
|
|
|
|
do_execute(func, argc - 1, &argv[1]);
|
|
|
|
else
|
|
|
|
func(argc - 1, &argv[1]);
|
2010-03-30 08:35:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The application returned. Since we have shutdown barebox and
|
|
|
|
* we know nothing about the state of the cpu/memory we can't
|
|
|
|
* do anything here.
|
|
|
|
*/
|
|
|
|
while (1);
|
2008-08-14 08:26:23 +00:00
|
|
|
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
|
|
|
|
2009-12-15 08:11:09 +00:00
|
|
|
BAREBOX_CMD_START(go)
|
2007-07-05 16:01:52 +00:00
|
|
|
.cmd = do_go,
|
2008-08-14 08:26:23 +00:00
|
|
|
.usage = "start application at address or file",
|
2009-12-15 08:11:09 +00:00
|
|
|
BAREBOX_CMD_HELP(cmd_go_help)
|
2012-06-13 17:27:46 +00:00
|
|
|
BAREBOX_CMD_COMPLETE(command_var_complete)
|
2009-12-15 08:11:09 +00:00
|
|
|
BAREBOX_CMD_END
|