1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// redboot_linux_exec.c
|
4 |
|
|
//
|
5 |
|
|
// RedBoot exec command for Linux booting
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//==========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): t@keshi.org
|
43 |
|
|
// Contributors: t@keshi.org, jskov, dwmw2
|
44 |
|
|
// Date: 2001-07-09
|
45 |
|
|
// Purpose: RedBoot exec command for Linux booting
|
46 |
|
|
//
|
47 |
|
|
//####DESCRIPTIONEND####
|
48 |
|
|
//
|
49 |
|
|
//===========================================================================
|
50 |
|
|
|
51 |
|
|
#include <redboot.h>
|
52 |
|
|
|
53 |
|
|
#include <cyg/infra/cyg_type.h>
|
54 |
|
|
#include <cyg/hal/hal_intr.h>
|
55 |
|
|
#include <cyg/hal/hal_cache.h>
|
56 |
|
|
#include <cyg/hal/hal_if.h>
|
57 |
|
|
|
58 |
|
|
#ifdef CYGPKG_IO_ETH_DRIVERS
|
59 |
|
|
#include <cyg/io/eth/eth_drv.h> // Logical driver interfaces
|
60 |
|
|
#endif
|
61 |
|
|
|
62 |
|
|
#define xstr(s) str(s)
|
63 |
|
|
#define str(s...) #s
|
64 |
|
|
|
65 |
|
|
typedef struct
|
66 |
|
|
{
|
67 |
|
|
char *name;
|
68 |
|
|
char *val;
|
69 |
|
|
} t_env_var;
|
70 |
|
|
|
71 |
|
|
struct parmblock {
|
72 |
|
|
t_env_var memsize;
|
73 |
|
|
t_env_var modetty0;
|
74 |
|
|
t_env_var ethaddr;
|
75 |
|
|
t_env_var env_end;
|
76 |
|
|
char *argv[2];
|
77 |
|
|
char text[0];
|
78 |
|
|
};
|
79 |
|
|
|
80 |
|
|
static void do_exec(int argc, char *argv[]);
|
81 |
|
|
RedBoot_cmd("exec",
|
82 |
|
|
"Execute an image",
|
83 |
|
|
"[-b <argv addr>] [-c \"kernel command line\"] [-w <timeout>]\n"
|
84 |
|
|
" [<entry point>]",
|
85 |
|
|
do_exec
|
86 |
|
|
);
|
87 |
|
|
|
88 |
|
|
static void
|
89 |
|
|
do_exec(int argc, char *argv[])
|
90 |
|
|
{
|
91 |
|
|
cyg_uint32 entry = (cyg_uint32)entry_address?:CYGDAT_REDBOOT_MIPS_LINUX_BOOT_ENTRY;
|
92 |
|
|
cyg_uint32 base_addr = CYGDAT_REDBOOT_MIPS_LINUX_BOOT_ARGV_ADDR;
|
93 |
|
|
char *cmd_line = xstr(CYGDAT_REDBOOT_MIPS_LINUX_BOOT_COMMAND_LINE);
|
94 |
|
|
bool base_addr_set, cmd_line_set, wait_time_set;
|
95 |
|
|
int wait_time, res;
|
96 |
|
|
char line[8];
|
97 |
|
|
|
98 |
|
|
struct option_info opts[3];
|
99 |
|
|
char *pcmd;
|
100 |
|
|
struct parmblock *pb;
|
101 |
|
|
void (*linux)(int, char **, void *);
|
102 |
|
|
int oldints;
|
103 |
|
|
hal_virtual_comm_table_t *__chan;
|
104 |
|
|
int baud;
|
105 |
|
|
|
106 |
|
|
init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
|
107 |
|
|
(void **)&base_addr, &base_addr_set, "base address");
|
108 |
|
|
init_opts(&opts[1], 'w', true, OPTION_ARG_TYPE_NUM,
|
109 |
|
|
(void **)&wait_time, (bool *)&wait_time_set, "wait timeout");
|
110 |
|
|
init_opts(&opts[2], 'c', true, OPTION_ARG_TYPE_STR,
|
111 |
|
|
(void **)&cmd_line, &cmd_line_set, "kernel command line");
|
112 |
|
|
|
113 |
|
|
if (!scan_opts(argc, argv, 1, opts, 3, (void *)&entry,
|
114 |
|
|
OPTION_ARG_TYPE_NUM, "entry address"))
|
115 |
|
|
return;
|
116 |
|
|
if (entry == (unsigned long)NO_MEMORY) {
|
117 |
|
|
diag_printf("Can't execute Linux - invalid entry address\n");
|
118 |
|
|
return;
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
linux = (void *)entry;
|
122 |
|
|
|
123 |
|
|
__chan = CYGACC_CALL_IF_CONSOLE_PROCS();
|
124 |
|
|
baud = CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_GETBAUD);
|
125 |
|
|
|
126 |
|
|
diag_printf("Now booting linux kernel:\n");
|
127 |
|
|
diag_printf(" Base address 0x%08x Entry 0x%08x\n", base_addr, entry);
|
128 |
|
|
diag_printf(" Cmdline : %s\n", cmd_line);
|
129 |
|
|
|
130 |
|
|
if (wait_time_set) {
|
131 |
|
|
diag_printf("About to start execution at %p - abort with ^C within %d seconds\n",
|
132 |
|
|
(void *)entry, wait_time);
|
133 |
|
|
res = _rb_gets(line, sizeof(line), wait_time*1000);
|
134 |
|
|
if (res == _GETS_CTRLC) {
|
135 |
|
|
return;
|
136 |
|
|
}
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
HAL_DISABLE_INTERRUPTS(oldints);
|
140 |
|
|
|
141 |
|
|
#ifdef CYGPKG_IO_ETH_DRIVERS
|
142 |
|
|
eth_drv_stop();
|
143 |
|
|
#endif
|
144 |
|
|
|
145 |
|
|
pb = (struct parmblock *)base_addr;
|
146 |
|
|
pcmd = pb->text;
|
147 |
|
|
|
148 |
|
|
pb->memsize.name = pcmd;
|
149 |
|
|
pcmd += diag_sprintf(pcmd, "memsize");
|
150 |
|
|
pb->memsize.val = ++pcmd;
|
151 |
|
|
pcmd += diag_sprintf(pcmd, "0x%08x", (ram_end - ram_start + 0xFFFFF) & ~0xFFFFF);
|
152 |
|
|
|
153 |
|
|
pb->modetty0.name = ++pcmd;
|
154 |
|
|
pcmd += diag_sprintf(pcmd, "modetty0");
|
155 |
|
|
pb->modetty0.val = ++pcmd;
|
156 |
|
|
pcmd += diag_sprintf(pcmd, "%d,n,8,1,hw", baud);
|
157 |
|
|
|
158 |
|
|
#ifdef CYGPKG_REDBOOT_NETWORKING
|
159 |
|
|
pb->ethaddr.name = ++pcmd;
|
160 |
|
|
pcmd += diag_sprintf(pcmd, "ethaddr");
|
161 |
|
|
pb->ethaddr.val = ++pcmd;
|
162 |
|
|
pcmd += diag_sprintf(pcmd, "%02x.%02x.%02x.%02x.%02x.%02x",
|
163 |
|
|
__local_enet_addr[0], __local_enet_addr[1],
|
164 |
|
|
__local_enet_addr[2], __local_enet_addr[3],
|
165 |
|
|
__local_enet_addr[4], __local_enet_addr[5]);
|
166 |
|
|
pb->env_end.name = NULL;
|
167 |
|
|
pb->env_end.val = NULL;
|
168 |
|
|
#else
|
169 |
|
|
pb->ethaddr.name = NULL;
|
170 |
|
|
pb->ethaddr.val = NULL;
|
171 |
|
|
#endif
|
172 |
|
|
|
173 |
|
|
/* Point argv[0] at a handy `\0` */
|
174 |
|
|
pb->argv[0] = pcmd;
|
175 |
|
|
pb->argv[1] = ++pcmd;
|
176 |
|
|
|
177 |
|
|
strcpy(pcmd, cmd_line);
|
178 |
|
|
|
179 |
|
|
HAL_DCACHE_SYNC();
|
180 |
|
|
HAL_ICACHE_DISABLE();
|
181 |
|
|
HAL_DCACHE_DISABLE();
|
182 |
|
|
HAL_DCACHE_SYNC();
|
183 |
|
|
HAL_ICACHE_INVALIDATE_ALL();
|
184 |
|
|
HAL_DCACHE_INVALIDATE_ALL();
|
185 |
|
|
|
186 |
|
|
linux(2, pb->argv, pb);
|
187 |
|
|
}
|