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, 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): yoshinori sato
|
43 |
|
|
// Contributors: yoshinori sato
|
44 |
|
|
// Date: 2002-05-28
|
45 |
|
|
// Purpose: RedBoot exec command for uClinux 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 |
|
|
|
57 |
|
|
#define xstr(s) str(s)
|
58 |
|
|
#define str(s...) #s
|
59 |
|
|
|
60 |
|
|
#if defined(CYGDAT_REDBOOT_H8300_LINUX_COMMAND_START)
|
61 |
|
|
static void
|
62 |
|
|
do_exec(int argc, char *argv[])
|
63 |
|
|
{
|
64 |
|
|
cyg_uint32 entry = CYGDAT_REDBOOT_H8300_LINUX_BOOT_ENTRY;
|
65 |
|
|
cyg_uint32 command_addr = CYGDAT_REDBOOT_H8300_LINUX_COMMAND_START;
|
66 |
|
|
char *cmd_line = xstr( CYGDAT_REDBOOT_H8300_LINUX_BOOT_COMMAND_LINE );
|
67 |
|
|
|
68 |
|
|
bool command_addr_set,command_line_set;
|
69 |
|
|
|
70 |
|
|
struct option_info opts[2];
|
71 |
|
|
char *pcmd;
|
72 |
|
|
int oldints;
|
73 |
|
|
|
74 |
|
|
init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
|
75 |
|
|
&command_addr, &command_addr_set, "command line address");
|
76 |
|
|
init_opts(&opts[1], 'c', true, OPTION_ARG_TYPE_STR,
|
77 |
|
|
&cmd_line, &command_line_set, "kernel command line");
|
78 |
|
|
|
79 |
|
|
if (!scan_opts(argc, argv, 1, opts, 2, (void *)&entry,
|
80 |
|
|
OPTION_ARG_TYPE_NUM, "entry address"))
|
81 |
|
|
return ;
|
82 |
|
|
if (entry == (unsigned long)NO_MEMORY) {
|
83 |
|
|
diag_printf("Can't execute Linux - invalid entry address\n");
|
84 |
|
|
return;
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
diag_printf("Now booting linux kernel:\n");
|
88 |
|
|
diag_printf(" Entry Address 0x%08x\n", entry);
|
89 |
|
|
diag_printf(" Cmdline : %s\n", cmd_line);
|
90 |
|
|
|
91 |
|
|
HAL_DISABLE_INTERRUPTS(oldints);
|
92 |
|
|
HAL_DCACHE_SYNC();
|
93 |
|
|
HAL_ICACHE_DISABLE();
|
94 |
|
|
HAL_DCACHE_DISABLE();
|
95 |
|
|
HAL_DCACHE_SYNC();
|
96 |
|
|
HAL_ICACHE_INVALIDATE_ALL();
|
97 |
|
|
HAL_DCACHE_INVALIDATE_ALL();
|
98 |
|
|
|
99 |
|
|
pcmd = (char *)command_addr;
|
100 |
|
|
while ((*pcmd++ = *cmd_line++));
|
101 |
|
|
|
102 |
|
|
asm ("jmp @%0" : : "r" (entry));
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
RedBoot_cmd("exec",
|
106 |
|
|
"Execute an image",
|
107 |
|
|
"[-b <command line addr>] [-c \"kernel command line\"]\n"
|
108 |
|
|
" [<entry point>]",
|
109 |
|
|
do_exec
|
110 |
|
|
);
|
111 |
|
|
#endif
|
112 |
|
|
|
113 |
|
|
static void
|
114 |
|
|
do_set_mem(int argc, char *argv[])
|
115 |
|
|
{
|
116 |
|
|
struct option_info opts[5];
|
117 |
|
|
unsigned long base, data;
|
118 |
|
|
bool base_set, data_set,len_set = 0;
|
119 |
|
|
static char _size = 1;
|
120 |
|
|
bool set_32bit, set_16bit, set_8bit;
|
121 |
|
|
|
122 |
|
|
init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
|
123 |
|
|
&base, (bool *)&base_set, "base address");
|
124 |
|
|
init_opts(&opts[1], 'd', true, OPTION_ARG_TYPE_NUM,
|
125 |
|
|
&data, (bool *)&data_set, "write_data");
|
126 |
|
|
init_opts(&opts[2], '4', false, OPTION_ARG_TYPE_FLG,
|
127 |
|
|
&set_32bit, (bool *)0, "dump 32 bit units");
|
128 |
|
|
init_opts(&opts[3], '2', false, OPTION_ARG_TYPE_FLG,
|
129 |
|
|
&set_16bit, (bool *)0, "dump 16 bit units");
|
130 |
|
|
init_opts(&opts[4], '1', false, OPTION_ARG_TYPE_FLG,
|
131 |
|
|
&set_8bit, (bool *)0, "dump 8 bit units");
|
132 |
|
|
if (!scan_opts(argc, argv, 1, opts, 5, 0, 0, "")) {
|
133 |
|
|
return;
|
134 |
|
|
}
|
135 |
|
|
if (!base_set) {
|
136 |
|
|
diag_printf("illigal base\n");
|
137 |
|
|
return ;
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
if (!data_set) {
|
141 |
|
|
diag_printf("illigal data\n");
|
142 |
|
|
return ;
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
if (set_32bit) {
|
146 |
|
|
_size = 4;
|
147 |
|
|
} else if (set_16bit) {
|
148 |
|
|
_size = 2;
|
149 |
|
|
} else if (set_8bit) {
|
150 |
|
|
_size = 1;
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
if (!len_set) {
|
154 |
|
|
_size = 4;
|
155 |
|
|
}
|
156 |
|
|
diag_printf("%d %x = %x\n",_size,base,data);
|
157 |
|
|
switch( _size ) {
|
158 |
|
|
case 1:
|
159 |
|
|
*(unsigned char *)base=data;
|
160 |
|
|
break;
|
161 |
|
|
case 2:
|
162 |
|
|
*(unsigned short *)base=data;
|
163 |
|
|
break;
|
164 |
|
|
case 4:
|
165 |
|
|
*(unsigned long *)base=data;
|
166 |
|
|
break;
|
167 |
|
|
}
|
168 |
|
|
}
|
169 |
|
|
|
170 |
|
|
RedBoot_cmd("set",
|
171 |
|
|
"Set Memory",
|
172 |
|
|
"-b address -[1|2|4] -d data",
|
173 |
|
|
do_set_mem
|
174 |
|
|
);
|
175 |
|
|
|