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