arm start.c: Make runtime function address calculation tolerant for more compilers
[barebox-mini2440.git] / commands / go.c
blob02629402ade6f33b993b885d13437a2cbdeb50d6
1 /*
2 * go- execute some code anywhere (misc boot support)
4 * (C) Copyright 2000-2003
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 * See file CREDITS for list of people who contributed to this
8 * project.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
26 #include <common.h>
27 #include <command.h>
28 #include <fs.h>
29 #include <fcntl.h>
30 #include <linux/ctype.h>
31 #include <errno.h>
33 static int do_go(struct command *cmdtp, int argc, char *argv[])
35 void *addr;
36 int rcode = 1;
37 int fd = -1;
38 int (*func)(int argc, char *argv[]);
40 if (argc < 2)
41 return COMMAND_ERROR_USAGE;
43 if (!isdigit(*argv[1])) {
44 fd = open(argv[1], O_RDONLY);
45 if (fd < 0) {
46 perror("open");
47 goto out;
50 addr = memmap(fd, PROT_READ);
51 if (addr == (void *)-1) {
52 perror("memmap");
53 goto out;
55 } else
56 addr = (void *)simple_strtoul(argv[1], NULL, 16);
58 printf("## Starting application at 0x%08lX ...\n", addr);
60 console_flush();
62 func = addr;
64 shutdown_barebox();
65 func(argc - 1, &argv[1]);
68 * The application returned. Since we have shutdown barebox and
69 * we know nothing about the state of the cpu/memory we can't
70 * do anything here.
72 while (1);
73 out:
74 if (fd > 0)
75 close(fd);
77 return rcode;
80 static const __maybe_unused char cmd_go_help[] =
81 "Usage: go addr [arg ...]\n"
82 "Start application at address 'addr' passing 'arg' as arguments.\n"
83 "If addr does not start with a digit it is interpreted as a filename\n"
84 "in which case the file is memmapped and executed\n";
86 BAREBOX_CMD_START(go)
87 .cmd = do_go,
88 .usage = "start application at address or file",
89 BAREBOX_CMD_HELP(cmd_go_help)
90 BAREBOX_CMD_END