1 //==========================================================================
3 // redboot_linux_exec.c
5 // RedBoot exec command for Linux booting
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
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.
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
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.
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.
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.
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####
44 // Author(s): t@keshi.org
45 // Contributors: t@keshi.org, jskov, dwmw2
47 // Purpose: RedBoot exec command for Linux booting
49 //####DESCRIPTIONEND####
51 //===========================================================================
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>
60 #ifdef CYGPKG_IO_ETH_DRIVERS
61 #include <cyg/io/eth/eth_drv.h> // Logical driver interfaces
64 #define xstr(s) str(s)
82 static void do_exec(int argc, char *argv[]);
85 "[-b <argv addr>] [-c \"kernel command line\"] [-w <timeout>]\n"
91 do_exec(int argc, char *argv[])
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;
100 struct option_info opts[3];
102 struct parmblock *pb;
103 void (*linux)(int, char **, void *);
105 hal_virtual_comm_table_t *__chan;
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");
115 if (!scan_opts(argc, argv, 1, opts, 3, (void *)&entry,
116 OPTION_ARG_TYPE_NUM, "entry address"))
118 if (entry == (unsigned long)NO_MEMORY) {
119 diag_printf("Can't execute Linux - invalid entry address\n");
123 linux = (void *)entry;
125 __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
126 baud = CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_GETBAUD);
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);
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) {
141 HAL_DISABLE_INTERRUPTS(oldints);
143 #ifdef CYGPKG_IO_ETH_DRIVERS
147 pb = (struct parmblock *)base_addr;
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);
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);
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;
171 pb->ethaddr.name = NULL;
172 pb->ethaddr.val = NULL;
175 /* Point argv[0] at a handy `\0` */
177 pb->argv[1] = ++pcmd;
179 strcpy(pcmd, cmd_line);
182 HAL_ICACHE_DISABLE();
183 HAL_DCACHE_DISABLE();
185 HAL_ICACHE_INVALIDATE_ALL();
186 HAL_DCACHE_INVALIDATE_ALL();
188 linux(2, pb->argv, pb);