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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [redboot/] [current/] [include/] [redboot.h] - Blame information for rev 856

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      redboot.h
4
//
5
//      Standard interfaces for RedBoot
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, 2005 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
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    gthomas
43
// Contributors: gthomas, tkoeller
44
// Date:         2000-07-14
45
// Purpose:      
46
// Description:  
47
//              
48
// This code is part of RedBoot (tm).
49
//
50
//####DESCRIPTIONEND####
51
//
52
//==========================================================================
53
 
54
#ifndef _REDBOOT_H_
55
#define _REDBOOT_H_
56
 
57
#include <pkgconf/redboot.h>
58
#include <pkgconf/hal.h>
59
#include <cyg/hal/hal_if.h>
60
#include <cyg/hal/hal_tables.h>
61
#include <cyg/hal/hal_endian.h>
62
#include <cyg/infra/diag.h>
63
#include <cyg/crc/crc.h>
64
#include <string.h>
65
 
66
#ifdef CYGPKG_REDBOOT_NETWORKING
67
#include <net/net.h>
68
#include <net/bootp.h>
69
// Determine an IP address for this node, using BOOTP
70
#ifdef CYGPKG_REDBOOT_NETWORKING_BOOTP
71
extern int __bootp_find_local_ip(bootp_header_t *info);
72
#endif
73
#endif
74
 
75
#ifdef DEFINE_VARS
76
#define EXTERN
77
#else
78
#define EXTERN extern
79
#endif
80
 
81
// Global variables
82
EXTERN int argc;
83
#define MAX_ARGV 16
84
EXTERN char *argv[MAX_ARGV];
85
EXTERN unsigned char *ram_start, *ram_end;
86
EXTERN struct _mem_segment {
87
    unsigned char *start, *end;
88
} mem_segments[CYGBLD_REDBOOT_MAX_MEM_SEGMENTS];
89
#define NO_MEMORY (unsigned char *)0xFFFFFFFF
90
EXTERN bool valid_address(unsigned char *addr);
91
EXTERN void cyg_plf_memory_segment(int seg, unsigned char **start, unsigned char **end);
92
EXTERN unsigned char *workspace_start, *workspace_end, *workspace_end_init;
93
 
94
// Data squirreled away after a load operation
95
EXTERN unsigned long entry_address;
96
EXTERN unsigned long load_address;
97
EXTERN unsigned long load_address_end;
98
 
99
 
100
#ifdef CYGPKG_REDBOOT_ANY_CONSOLE
101
EXTERN bool console_selected;
102
#endif
103
EXTERN bool console_echo;
104
EXTERN bool gdb_active;
105
#if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
106
EXTERN bool cmd_history;
107
#endif
108
 
109
#ifdef CYGPKG_REDBOOT_NETWORKING
110
EXTERN bool have_net, use_bootp;
111
EXTERN bootp_header_t my_bootp_info;
112
EXTERN int gdb_port;
113
EXTERN bool net_debug;
114
#endif
115
 
116
#ifdef CYGFUN_REDBOOT_BOOT_SCRIPT
117
EXTERN char *script;
118
EXTERN int script_timeout;
119
#ifdef CYGSEM_REDBOOT_VARIABLE_BAUD_RATE
120
EXTERN int console_baud_rate;
121
#endif
122
#endif
123
 
124
#ifdef CYGOPT_REDBOOT_FIS_ZLIB_COMMON_BUFFER
125
EXTERN unsigned char *fis_zlib_common_buffer;
126
#endif
127
 
128
#ifdef CYGSEM_REDBOOT_PLF_STARTUP
129
EXTERN void cyg_plf_redboot_startup(void);
130
#endif
131
 
132
// Prototypes
133
typedef int _printf_fun(const char *fmt, ...);
134
externC int  strcasecmp(const char *s1, const char *s2);
135
externC int  strncasecmp(const char *s1, const char *s2, size_t len);
136
 
137
externC void mon_write_char(unsigned char c);
138
externC bool mon_read_char_with_timeout(unsigned char *c);
139
externC void mon_set_read_char_timeout(int ms);
140
externC bool verify_action(char *fmt, ...);
141
externC bool verify_action_with_timeout(int timeout, char *fmt, ...);
142
 
143
// Read a single line of input from the console, possibly with timeout
144
externC int  _rb_gets(char *line, int len, int timeout);
145
// Just like _rb_gets(), except that the line buffer is assumed to contain
146
// valid input data.  This provides an easy mechanism for edit-in-place.
147
externC int  _rb_gets_preloaded(char *line, int len, int timeout);
148
// Result codes from 'gets()'
149
#define _GETS_TIMEOUT -1
150
#define _GETS_CTRLC   -2
151
#define _GETS_GDB      0
152
#define _GETS_OK       1
153
// Test for ^C on the console.  This function should only be used if any
154
// other console input can be discarded, e.g. while performing some long
155
// computation, waiting for the network, etc.  Returns 'true' if ^C typed.
156
externC bool _rb_break(int timeout);
157
 
158
// "console" selection
159
externC int  start_console(void);
160
externC void end_console(int old_console);
161
 
162
// Tick functions
163
__externC unsigned long do_ms_tick(void);
164
__externC unsigned long get_ms_ticks(void);
165
__externC void ms_ticks_add_us(long);
166
 
167
#define MS_TICKS() get_ms_ticks()
168
#define MS_TICKS_DELAY() do_ms_tick()
169
 
170
// Alias functions
171
#ifdef CYGSEM_REDBOOT_FLASH_ALIASES
172
externC char *flash_lookup_alias(char *alias, char *alias_buf);
173
#endif
174
externC void expand_aliases(char *line, int len);
175
 
176
//
177
// Stream I/O support
178
//
179
 
180
typedef struct {
181
    char *filename;
182
    int   mode;
183
    int   chan;
184
#ifdef CYGPKG_REDBOOT_NETWORKING
185
    struct sockaddr_in *server;
186
#endif
187
} connection_info_t;
188
 
189
typedef struct {
190
    int   (*open)(connection_info_t *info, int *err);
191
    void  (*close)(int *err);
192
    void  (*terminate)(bool abort, int (*getc)(void));
193
    int   (*read)(char *buf, int size, int *err);
194
    char *(*error)(int err);
195
} getc_io_funcs_t;
196
 
197
#define GETC_IO_FUNCS(_label_, _open_, _close_, _terminate_, _read_, _error_)   \
198
getc_io_funcs_t _label_ = {                                                     \
199
    _open_, _close_, _terminate_, _read_, _error_                               \
200
};
201
 
202
struct load_io_entry {
203
    char            *name;
204
    getc_io_funcs_t *funcs;
205
    bool             can_verbose;
206
    bool             need_filename;
207
    int              mode;
208
} CYG_HAL_TABLE_TYPE;
209
#define _RedBoot_load(_name_,_funcs_,_verbose_,_filename_,_mode_)       \
210
struct load_io_entry _load_tab_##_funcs_##_name_                        \
211
   CYG_HAL_TABLE_QUALIFIED_ENTRY(RedBoot_load,_funcs_##_name) =         \
212
     { #_name_, &_funcs_, _verbose_, _filename_, _mode_ }; 
213
#define RedBoot_load(_name_,_funcs_,_verbose_,_filename_, _mode_)       \
214
   _RedBoot_load(_name_,_funcs_,_verbose_,_filename_,_mode_)
215
 
216
#ifdef CYGPKG_COMPRESS_ZLIB
217
// Decompression support
218
typedef struct _pipe {
219
    unsigned char* in_buf;              // only changed by producer
220
    int in_avail;                       // only changed by producer
221
    unsigned char* out_buf;             // only changed by consumer (init by producer)
222
    int out_size;                       // only changed by consumer (init by producer)
223
    int out_max;                        // set by producer
224
    const char* msg;                    // message from consumer
225
    void* priv;                         // handler's data
226
} _pipe_t;
227
 
228
typedef int _decompress_fun_init(_pipe_t*);
229
typedef int _decompress_fun_inflate(_pipe_t*);
230
typedef int _decompress_fun_close(_pipe_t*, int);
231
 
232
externC _decompress_fun_init* _dc_init;
233
externC _decompress_fun_inflate* _dc_inflate;
234
externC _decompress_fun_close* _dc_close;
235
#endif // CYGPKG_COMPRESS_ZLIB
236
 
237
// CLI support functions
238
externC bool parse_num(char *s, unsigned long *val, char **es, char *delim);
239
externC bool parse_bool(char *s, bool *val);
240
 
241
typedef void cmd_fun(int argc, char *argv[]);
242
struct cmd {
243
    char    *str;
244
    char    *help;
245
    char    *usage;
246
    cmd_fun *fun;
247
    struct cmd *sub_cmds, *sub_cmds_end;
248
} CYG_HAL_TABLE_TYPE;
249
externC struct cmd *cmd_search(struct cmd *tab, struct cmd *tabend, char *arg);
250
externC void        cmd_usage(struct cmd *tab, struct cmd *tabend, char *prefix);
251
#define RedBoot_cmd(_s_,_h_,_u_,_f_) cmd_entry(_s_,_h_,_u_,_f_,0,0,RedBoot_commands)
252
#define RedBoot_nested_cmd(_s_,_h_,_u_,_f_,_subs_,_sube_) cmd_entry(_s_,_h_,_u_,_f_,_subs_,_sube_,RedBoot_commands)
253
#define _cmd_entry(_s_,_h_,_u_,_f_,_subs_,_sube_,_n_)                                   \
254
cmd_fun _f_;                                                      \
255
struct cmd _cmd_tab_##_f_ CYG_HAL_TABLE_QUALIFIED_ENTRY(_n_,_f_) = {_s_, _h_, _u_, _f_, _subs_, _sube_};
256
#define cmd_entry(_s_,_h_,_u_,_f_,_subs_,_sube_,_n_)                                   \
257
extern _cmd_entry(_s_,_h_,_u_,_f_,_subs_,_sube_,_n_)
258
#define local_cmd_entry(_s_,_h_,_u_,_f_,_n_)                             \
259
static _cmd_entry(_s_,_h_,_u_,_f_,0,0,_n_)
260
 
261
// Initialization functions
262
#define RedBoot_INIT_FIRST              0000
263
#define RedBoot_INIT_SECOND             0100
264
// Specify a 3 digit numeric value for proper prioritizing
265
#define RedBoot_INIT_PRIO(_n_) 1##_n_
266
#define RedBoot_INIT_BEFORE_NET         6900
267
#define RedBoot_INIT_NET                7000
268
#define RedBoot_INIT_AFTER_NET          7100
269
#define RedBoot_INIT_LAST               9999
270
typedef void void_fun(void);
271
typedef void_fun *void_fun_ptr;
272
struct init_tab_entry {
273
    void_fun_ptr fun;
274
} CYG_HAL_TABLE_TYPE;
275
#define _RedBoot_init(_f_,_p_)                                          \
276
struct init_tab_entry _init_tab_##_p_##_f_                              \
277
  CYG_HAL_TABLE_QUALIFIED_ENTRY(RedBoot_inits,_p_##_f_) = { _f_ }; 
278
#define RedBoot_init(_f_,_p_) _RedBoot_init(_f_,_p_)
279
 
280
// Main loop [idle] call-back functions
281
#define RedBoot_IDLE_FIRST          0000
282
#define RedBoot_IDLE_BEFORE_NETIO   3000
283
#define RedBoot_IDLE_NETIO          5000
284
#define RedBoot_IDLE_AFTER_NETIO    7000
285
#define RedBoot_IDLE_LAST           9999
286
typedef void idle_fun(bool);
287
typedef idle_fun *idle_fun_ptr;
288
struct idle_tab_entry {
289
    idle_fun_ptr fun;
290
} CYG_HAL_TABLE_TYPE;
291
#define _RedBoot_idle(_f_,_p_)                                          \
292
struct idle_tab_entry _idle_tab_##_p_##_f_                              \
293
   CYG_HAL_TABLE_QUALIFIED_ENTRY(RedBoot_idle,_p_##_f_) = { _f_ }; 
294
#define RedBoot_idle(_f_,_p_) _RedBoot_idle(_f_,_p_)
295
 
296
// This function called when changing idle/not - mostly used by I/O
297
// to support idle when timeout, etc.
298
void do_idle(bool state);
299
 
300
// Option processing support
301
 
302
struct option_info {
303
    char flag;
304
    bool takes_arg;
305
    int  arg_type;
306
    void *arg;
307
    bool *arg_set;
308
    char *name;
309
};
310
 
311
#define NUM_ELEMS(s) (sizeof(s)/sizeof(s[0]))
312
 
313
#define OPTION_ARG_TYPE_NUM 0    // Numeric data
314
#define OPTION_ARG_TYPE_STR 1    // Generic string
315
#define OPTION_ARG_TYPE_FLG 2    // Flag only
316
 
317
// Command line parsing
318
externC struct cmd *parse(char **line, int *argc, char **argv);
319
 
320
externC void init_opts(struct option_info *opts, char flag, bool takes_arg,
321
                       int arg_type, void *arg, bool *arg_set, char *name);
322
externC bool scan_opts(int argc, char *argv[], int first,
323
                       struct option_info *opts, int num_opts,
324
                       void *def_arg, int def_arg_type, char *def_descr);
325
 
326
externC int redboot_exec( char *command, ... );
327
 
328
externC void err_printf( const char *fmt, ... );
329
 
330
#ifdef CYGNUM_HAL_VIRTUAL_VECTOR_AUX_CHANNELS
331
#define CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS \
332
  (CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS+CYGNUM_HAL_VIRTUAL_VECTOR_AUX_CHANNELS)
333
#else
334
#define CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS \
335
  CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS
336
#endif
337
 
338
#ifdef CYGPKG_REDBOOT_NETWORKING
339
//-----------------------------------------------------------------------------
340
// DNS wrapper
341
#ifdef CYGPKG_REDBOOT_NETWORKING_DNS
342
 
343
// I would really like if we could just pull in cyg/ns/dns/dns.h, but
344
// that would require adding dummy <network.h> and <netinet/in.h> files.
345
 
346
// Host name / IP mapping
347
struct hostent {
348
    char    *h_name;        /* official name of host */
349
    char    **h_aliases;    /* alias list */
350
    int     h_addrtype;     /* host address type */
351
    int     h_length;       /* length of address */
352
    char    **h_addr_list;  /* list of addresses */
353
};
354
#define h_addr  h_addr_list[0]  /* for backward compatibility */
355
 
356
externC int redboot_dns_res_init(void);
357
externC void set_dns(char* new_ip);
358
externC void show_dns(void);
359
externC struct hostent *gethostbyname(const char *host);
360
externC int setdomainname(const char *, size_t);
361
 
362
// Error reporting
363
externC int h_errno;
364
 
365
#define DNS_SUCCESS  0
366
#define HOST_NOT_FOUND 1
367
#define TRY_AGAIN      2
368
#define NO_RECOVERY    3
369
#define NO_DATA        4
370
 
371
static inline bool
372
_gethostbyname(const char* name, in_addr_t* host)
373
{
374
    struct hostent* hent = gethostbyname(name);
375
    if (hent) {
376
        memcpy(host, hent->h_addr_list[0], sizeof(in_addr_t));
377
        return true;
378
    }
379
    // Fall back to inet_aton - gethostbyname may already have tried
380
    // it, but we can't know for sure (the DNS IP may not have been
381
    // valid, preventing the inet_aton).
382
    return inet_aton(name, host);
383
}
384
#else
385
static inline bool
386
_gethostbyname(const char* name, in_addr_t* host)
387
{
388
    return inet_aton(name, host);
389
}
390
#endif // CYGPKG_REDBOOT_NETWORKING_DNS
391
#endif // CYGPKG_REDBOOT_NETWORKING
392
 
393
//-----------------------------------------------------------------------------
394
// String functions. Some of these are duplicates of the same functions in
395
// the I18N package.
396
 
397
// Validate a hex character
398
__inline__ static bool
399
_is_hex(char c)
400
{
401
    return (((c >= '0') && (c <= '9')) ||
402
            ((c >= 'A') && (c <= 'F')) ||
403
            ((c >= 'a') && (c <= 'f')));
404
}
405
 
406
// Convert a single hex nibble
407
__inline__ static int
408
_from_hex(char c)
409
{
410
    int ret = 0;
411
 
412
    if ((c >= '0') && (c <= '9')) {
413
        ret = (c - '0');
414
    } else if ((c >= 'a') && (c <= 'f')) {
415
        ret = (c - 'a' + 0x0a);
416
    } else if ((c >= 'A') && (c <= 'F')) {
417
        ret = (c - 'A' + 0x0A);
418
    }
419
    return ret;
420
}
421
 
422
// Convert a character to lower case
423
__inline__ static char
424
_tolower(char c)
425
{
426
    if ((c >= 'A') && (c <= 'Z')) {
427
        c = (c - 'A') + 'a';
428
    }
429
    return c;
430
}
431
 
432
// Validate alpha
433
__inline__ static bool
434
isalpha(int c)
435
{
436
    return (((c >= 'a') && (c <= 'z')) ||
437
            ((c >= 'A') && (c <= 'Z')));
438
}
439
 
440
// Validate digit
441
__inline__ static bool
442
isdigit(int c)
443
{
444
    return ((c >= '0') && (c <= '9'));
445
}
446
 
447
// Validate alphanum
448
__inline__ static bool
449
isalnum(int c)
450
{
451
    return (isalpha(c) || isdigit(c));
452
}
453
 
454
//----------------------------------------------------------------------------
455
// syscall values
456
#if defined(CYGSEM_REDBOOT_BSP_SYSCALLS)
457
 
458
// These are required by the ANSI C part of newlib (excluding system() of
459
// course).
460
#define SYS_exit         1
461
#define SYS_open         2
462
#define SYS_close        3
463
#define SYS_read         4
464
#define SYS_write        5
465
#define SYS_lseek        6
466
#define SYS_unlink       7
467
#define SYS_getpid       8
468
#define SYS_kill         9
469
#define SYS_fstat        10
470
//#define SYS_sbrk       11 - not currently a system call, but reserved.
471
 
472
// ARGV support.
473
#define SYS_argvlen      12
474
#define SYS_argv         13
475
 
476
// These are extras added for one reason or another.
477
#define SYS_chdir        14
478
#define SYS_stat         15
479
#define SYS_chmod        16
480
#define SYS_utime        17
481
#define SYS_time         18
482
#define SYS_gettimeofday 19
483
#define SYS_times        20
484
 
485
#define SYS_interrupt   1000
486
#define SYS_meminfo     1001
487
 
488
#define __GET_SHARED  0xbaad // 47789 decimal
489
 
490
#ifdef CYGSEM_REDBOOT_BSP_SYSCALLS_GPROF
491
 
492
#define SYS_timer_call_back 2001
493
#define SYS_timer_frequency 2002
494
#define SYS_timer_reset     2003
495
 
496
#endif // CYGSEM_REDBOOT_BSP_SYSCALLS_GPROF
497
#define SYS_rename          3001
498
#define SYS_isatty          3002
499
#define SYS_system          3003
500
 
501
#endif // CYGSEM_REDBOOT_BSP_SYSCALLS
502
 
503
 
504
//----------------------------------------------------------------------------
505
// Allow HAL to override RedBoot flash read/program operations.
506
#ifdef HAL_FLASH_READ
507
#define FLASH_READ(f, r, l, e) HAL_FLASH_READ((f),(r),(l),(e))
508
#else
509
#define FLASH_READ(f, r, l, e) flash_read((f), (r), (l), (e))
510
#endif
511
 
512
#ifdef HAL_FLASH_PROGRAM
513
#define FLASH_PROGRAM(f, r, l, e) HAL_FLASH_PROGRAM((f),(r),(l),(e))
514
#else
515
#define FLASH_PROGRAM(f, r, l, e) flash_program((f), (r), (l), (e))
516
#endif
517
 
518
 
519
// Define REDBOOT_FLASH_REVERSE_BYTEORDER if config and fis info is stored in flash
520
// with byte ordering opposite from CYG_BYTEORDER. 
521
#if (defined(CYGOPT_REDBOOT_FLASH_BYTEORDER_MSBFIRST) && (CYG_BYTEORDER != CYG_MSBFIRST)) || \
522
    (defined(CYGOPT_REDBOOT_FLASH_BYTEORDER_LSBFIRST) && (CYG_BYTEORDER != CYG_LSBFIRST))
523
#define REDBOOT_FLASH_REVERSE_BYTEORDER
524
#endif
525
 
526
#endif // _REDBOOT_H_

powered by: WebSVN 2.1.0

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