]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/hal/frv/arch/v2_0/src/redboot_linux_exec.c
Initial revision
[karo-tx-redboot.git] / packages / hal / frv / 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 //
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:         2003-11-13
46 // Purpose:      RedBoot exec command for Linux booting, from MIPS arch
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 #ifdef CYGPKG_IO_ETH_DRIVERS
60 #include <cyg/io/eth/eth_drv.h>            // Logical driver interfaces
61 #endif
62
63 #define xstr(s) str(s)
64 #define str(s...) #s
65
66 static void do_exec(int argc, char *argv[]);
67 RedBoot_cmd("exec", 
68             "Execute an image", 
69             "[-c \"kernel command line\"] [-w <timeout>]\n"
70             "        [<entry point>]",
71             do_exec
72     );
73
74 static void 
75 do_exec(int argc, char *argv[])
76 {
77     cyg_uint32 entry = (cyg_uint32)entry_address?:CYGDAT_REDBOOT_FRV_LINUX_BOOT_ENTRY;
78     char *cmd_line = xstr(CYGDAT_REDBOOT_FRV_LINUX_BOOT_COMMAND_LINE);
79     bool cmd_line_set, wait_time_set;
80     int wait_time, res;
81     char line[8];
82     
83     struct option_info opts[3];
84     void (*linux_boot)(unsigned long, char *);
85     int oldints;
86     hal_virtual_comm_table_t *__chan;
87     int baud;
88
89     init_opts(&opts[0], 'w', true, OPTION_ARG_TYPE_NUM, 
90               (void **)&wait_time, (bool *)&wait_time_set, "wait timeout");
91     init_opts(&opts[1], 'c', true, OPTION_ARG_TYPE_STR, 
92               (void **)&cmd_line, &cmd_line_set, "kernel command line");
93     
94     if (!scan_opts(argc, argv, 1, opts, 2, (void *)&entry, 
95                    OPTION_ARG_TYPE_NUM, "entry address"))
96         return;
97
98     linux_boot = (void *)entry;
99
100     __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
101     baud = CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_GETBAUD);
102
103     diag_printf("Now booting linux kernel:\n");
104     diag_printf(" Entry 0x%08x\n", entry);
105     diag_printf(" Cmdline : %s\n", cmd_line);
106
107     if (wait_time_set) {
108         diag_printf("About to start execution at %p - abort with ^C within %d seconds\n",
109                     (void *)entry, wait_time);
110         res = _rb_gets(line, sizeof(line), wait_time*1000);
111         if (res == _GETS_CTRLC) {
112             return;
113         }
114     }
115     
116     HAL_DISABLE_INTERRUPTS(oldints);
117
118 #ifdef CYGPKG_IO_ETH_DRIVERS
119     eth_drv_stop();
120 #endif
121    
122     HAL_DCACHE_SYNC();
123     HAL_ICACHE_DISABLE();
124     HAL_DCACHE_DISABLE();
125     HAL_DCACHE_SYNC();
126     HAL_ICACHE_INVALIDATE_ALL();
127     HAL_DCACHE_INVALIDATE_ALL();
128
129     linux_boot(0xdead1eaf, cmd_line);
130 }