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