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