OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [openrisc/] [arch/] [current/] [src/] [redboot_linux_exec.c] - Blame information for rev 811

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 811 skrzyp
//==========================================================================
2
//
3
//      redboot_linux_boot.c
4
//
5
//      RedBoot command to boot Linux on ARM platforms
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, 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
//####OTHERCOPYRIGHTBEGIN####
40
//
41
//  The structure definitions below are taken from include/asm-arm/setup.h in
42
//  the Linux kernel, Copyright (C) 1997-1999 Russell King. Their presence
43
//  here is for the express purpose of communication with the Linux kernel
44
//  being booted and is considered 'fair use' by the original author and
45
//  are included with his permission.
46
//
47
//####OTHERCOPYRIGHTEND####
48
//==========================================================================
49
//#####DESCRIPTIONBEGIN####
50
//
51
// Author(s):    Piotr Skrzypek
52
// Date:         2012-06-08
53
// Purpose:      
54
// Description:  Based on ARM code
55
//              
56
// This code is part of RedBoot (tm).
57
//
58
//####DESCRIPTIONEND####
59
//
60
//==========================================================================
61
 
62
#include <pkgconf/hal.h>
63
#include <redboot.h>
64
#include <cyg/hal/hal_intr.h>
65
#include <cyg/hal/hal_cache.h>
66
#include <cyg/hal/hal_io.h>
67
 
68
#ifdef CYGPKG_IO_ETH_DRIVERS
69
#include <cyg/io/eth/eth_drv.h>
70
#endif
71
 
72
// Exported CLI function(s)
73
static void do_exec(int argc, char *argv[]);
74
RedBoot_cmd("exec",
75
            "Execute an image",
76
            "[-w timeout] [-b <load addr> [-l <length>]]\n"
77
            "        [-t <target> ] [<entry_point>]",
78
            do_exec
79
    );
80
 
81
static void do_exec(int argc, char *argv[]) {
82
 
83
        cyg_uint32 wait_time;
84
        cyg_bool wait_time_set;
85
        cyg_uint32 base_addr;
86
        cyg_bool base_addr_set;
87
        cyg_uint32 length;
88
        cyg_bool length_set;
89
        cyg_uint32 target;
90
        cyg_bool target_set;
91
        cyg_uint32 entry;
92
 
93
        extern char __tramp_start__[], __tramp_end__[];
94
        cyg_uint32 oldints;
95
 
96
        // Parse parameters
97
        struct option_info opts[4];
98
        init_opts(&opts[0], 'w', true, OPTION_ARG_TYPE_NUM, (void **)&wait_time, (bool *)&wait_time_set, "wait timeout");
99
        init_opts(&opts[1], 'b', true, OPTION_ARG_TYPE_NUM, (void **)&base_addr, (bool *)&base_addr_set, "base address");
100
        init_opts(&opts[2], 'l', true, OPTION_ARG_TYPE_NUM, (void **)&length, (bool *)&length_set, "length");
101
        init_opts(&opts[3], 't', true, OPTION_ARG_TYPE_NUM, (void **)&target, (bool *)&target_set, "target address");
102
        int num_opts = 4;
103
 
104
        if(!scan_opts(argc, argv, 1, opts, num_opts, (void *)&entry, OPTION_ARG_TYPE_NUM, "starting address")) {
105
                return;
106
        }
107
 
108
        // Timeout is optional
109
        wait_time = wait_time_set ? wait_time : 0;
110
 
111
        // Base address is mandatory
112
        if(!base_addr_set) {
113
                diag_printf("Use -b option to provide base address\n");
114
                return;
115
        }
116
 
117
        // Length is mandatory
118
        if(!length_set) {
119
                diag_printf("Use -l option to provide size of the binary\n");
120
                return;
121
        }
122
        length = (length + 3) & ~0x03;
123
 
124
        // Target address is mandatory
125
        if(!target_set) {
126
                diag_printf("Use -t option to provide target address\n");
127
                return;
128
        }
129
 
130
        // Optionally wait
131
        if(wait_time_set) {
132
                int script_timeout_ms = wait_time * 1000;
133
#ifdef CYGFUN_REDBOOT_BOOT_SCRIPT
134
                unsigned char *hold_script = script;
135
                script = (unsigned char *) 0;
136
#endif
137
                diag_printf("About to start execution of image at %p, entry point %p - abort with ^C within %d seconds\n",
138
                                (void *)target, (void *)entry, wait_time);
139
                while(script_timeout_ms >= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT) {
140
                        char line[8];
141
                        int res = _rb_gets(line, sizeof(line), CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT);
142
                        if(res == _GETS_CTRLC) {
143
#ifdef CYGFUN_REDBOOT_BOOT_SCRIPT
144
                                script = hold_script;
145
#endif
146
                                return;
147
                        }
148
                        script_timeout_ms -= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT;
149
                }
150
        }
151
 
152
#ifdef CYGPKG_IO_ETH_DRIVERS
153
        eth_drv_stop();
154
#endif
155
 
156
        HAL_DISABLE_INTERRUPTS(oldints);
157
        HAL_DCACHE_SYNC();
158
        HAL_ICACHE_DISABLE();
159
        HAL_DCACHE_DISABLE();
160
        HAL_DCACHE_SYNC();
161
        HAL_ICACHE_INVALIDATE_ALL();
162
        HAL_DCACHE_INVALIDATE_ALL();
163
 
164
        // Copy the trampoline code below
165
        memcpy((char*)CYGPKG_REDBOOT_OPENRISC_TRAMPOLINE_ADDRESS, __tramp_start__, __tramp_end__ - __tramp_start__);
166
 
167
        // Jump to the trampoline. Pass arguments according to ABI
168
        void (*trampoline)(cyg_uint32 bin_start, cyg_uint32 bin_end, cyg_uint32 dest_base, cyg_uint32 entry);
169
        trampoline = CYGPKG_REDBOOT_OPENRISC_TRAMPOLINE_ADDRESS;
170
        trampoline(base_addr, base_addr + length, target, entry);
171
 
172
        // This code is executed from the trampoline address. Trampoline never returns.
173
        asm volatile (
174
                "__tramp_start__:\n"
175
                "1: l.sfeq  r3, r4\n"
176
                "   l.bf    2f\n"
177
                "   l.lwz   r13,0x00(r3)\n"
178
                "   l.sw    0x00(r5), r13\n"
179
                "   l.addi  r3, r3, 4\n"
180
                "   l.j     1b\n"
181
                "   l.addi  r5, r5, 4\n"
182
                "2: l.jr    r6\n"
183
                "   l.nop\n"
184
                "__tramp_end__:\n"
185
                : /* no output registers */
186
                : /* no input registers */
187
                : /* no clobbered registers */
188
        );
189
 
190
 
191
}
192
 
193
// EOF redboot_linux_exec.c

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.