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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [ecos-2.0/] [packages/] [redboot/] [v2_0/] [include/] [redboot.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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