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

Subversion Repositories or1k

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /or1k/trunk/ecos-2.0/packages/redboot/v2_0/include
    from Rev 1254 to Rev 1765
    Reverse comparison

Rev 1254 → Rev 1765

/sib.h
0,0 → 1,143
#ifndef _SIB_H_
#define _SIB_H_
//==========================================================================
//
// sib.h
//
// RedBoot - structure of ARM flash file format
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): Philippe Robin
// Contributors: Philippe Robin, jskov
// Date: 2001-10-31
// Purpose:
// Description:
//
// This code is part of RedBoot (tm).
//
//####DESCRIPTIONEND####
//
//==========================================================================
 
#include <cyg/hal/hal_io.h>
 
/* type information :-
* 0xffff ffff - deleted (usual flash erased value)
* 0x0000 xxxx - Reserved for ARM usage:
* Bit 0 - ARM Executable Image
* Bit 1 - System Information Block
* Bit 2 - File System Block
* 0xyyyy 0000 - Available for customers (y != 0)
*/
#define TYPE_DELETED 0xFFFFFFFF
#define TYPE_ARM_MASK 0x0000FFFF
#define TYPE_CUSTOM_MASK 0xFFFF0000
#define TYPE_ARM_EXEC 0x00000001
#define TYPE_ARM_SIB 0x00000002
#define TYPE_ARM_SYSBLOCK 0x00000004
 
/* This is the type we use for RedBoot blocks */
#define TYPE_REDHAT_REDBOOT 0x52420000
 
/* The ARM monitor may be using a different memory mapping than RedBoot */
#ifndef _ADDR_REDBOOT_TO_ARM
# define _ADDR_REDBOOT_TO_ARM(x)
#endif
 
/* Filetypes */
 
#define UNKNOWN_FILE 0x00000000
#define MOT_S_RECORD 0x00000001
#define INTEL_HEX 0x00000002
#define ELF 0x00000004
#define DWARF 0x00000008
#define ARM_AOF 0x00000010
#define ARM_AIF 0x00000020
#define PLAIN_BINARY 0x00000040
#define ARM_AIF_BIN 0x00000080
#define MCS_TYPE 0x00000100
 
#define CONVERT_TYPE (MOT_S_RECORD | INTEL_HEX | MCS_TYPE | ELF)
 
#define SIB_OWNER_STRING_SIZE 32
#define MAX_SIB_SIZE 512
#define MAX_SIB_INDEX 64
 
#define SIB_HEADER_SIGNATURE 0xA00FFF9F /* This is an invalid instruction - MULGE pc,pc,pc */
#define FLASH_FOOTER_SIGNATURE 0xA0FFFF9F /* This is an invalid instruction - SMULALGES pc,pc,pc */
 
 
typedef struct SIBType {
cyg_uint32 signature;
cyg_uint32 size;
char owner[SIB_OWNER_STRING_SIZE];
cyg_uint32 index;
cyg_uint32 revision;
cyg_uint32 checksum;
} tSIB;
 
typedef struct SIBInfoType {
cyg_uint32 SIB_number; /* Unique number of SIB Block */
cyg_uint32 SIB_Extension; /* Base of SIB Flash Block */
char Label[16]; /* String space for ownership string */
cyg_uint32 checksum; /* SIB Image checksum */
} tSIBInfo;
 
typedef struct FooterType {
void *infoBase; /* Address of first word of ImageFooter */
char *blockBase; /* Start of area reserved by this footer */
cyg_uint32 signature; /* 'Magic' number proves it's a footer */
cyg_uint32 type; /* Area type: ARM Image, SIB, customer */
cyg_uint32 checksum; /* Just this structure */
} tFooter ;
 
typedef struct ImageInfoType {
cyg_uint32 bootFlags; /* Boot flags, compression etc. */
cyg_uint32 imageNumber; /* Unique number, selects for boot etc. */
char *loadAddress; /* Address program should be loaded to */
cyg_uint32 length; /* Actual size of image */
char *address; /* Image is executed from here */
char name[16]; /* Null terminated */
char *headerBase; /* Flash Address of any stripped header */
cyg_uint32 header_length; /* Length of header in memory */
cyg_uint32 headerType; /* AIF, RLF, s-record etc. */
cyg_uint32 checksum; /* Image checksum (inc. this struct) */
} tImageInfo;
 
 
#endif // _SIB_H_
/redboot.h
0,0 → 1,469
//==========================================================================
//
// redboot.h
//
// Standard interfaces for RedBoot
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
// Copyright (C) 2002 Gary Thomas
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): gthomas
// Contributors: gthomas, tkoeller
// Date: 2000-07-14
// Purpose:
// Description:
//
// This code is part of RedBoot (tm).
//
//####DESCRIPTIONEND####
//
//==========================================================================
 
#ifndef _REDBOOT_H_
#define _REDBOOT_H_
 
#include <pkgconf/redboot.h>
#include <pkgconf/hal.h>
#include <cyg/hal/hal_if.h>
#include <cyg/hal/hal_tables.h>
#include <cyg/infra/diag.h>
#include <cyg/crc/crc.h>
#include <string.h>
 
#ifdef CYGPKG_REDBOOT_NETWORKING
#include <net/net.h>
#include <net/bootp.h>
// Determine an IP address for this node, using BOOTP
extern int __bootp_find_local_ip(bootp_header_t *info);
#endif
 
#ifdef DEFINE_VARS
#define EXTERN
#else
#define EXTERN extern
#endif
 
// Global variables
EXTERN int argc;
#define MAX_ARGV 16
EXTERN char *argv[MAX_ARGV];
EXTERN unsigned char *ram_start, *ram_end;
EXTERN unsigned char *user_ram_start, *user_ram_end;
EXTERN unsigned char *workspace_start, *workspace_end;
EXTERN unsigned long workspace_size;
 
// Data squirreled away after a load operation
EXTERN unsigned long entry_address;
EXTERN unsigned long load_address;
EXTERN unsigned long load_address_end;
 
 
#ifdef CYGPKG_REDBOOT_ANY_CONSOLE
EXTERN bool console_selected;
#endif
EXTERN bool console_echo;
EXTERN bool gdb_active;
#if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
EXTERN bool cmd_history;
#endif
 
#ifdef CYGPKG_REDBOOT_NETWORKING
EXTERN bool have_net, use_bootp;
EXTERN bootp_header_t my_bootp_info;
EXTERN int gdb_port;
EXTERN bool net_debug;
#endif
 
#ifdef CYGFUN_REDBOOT_BOOT_SCRIPT
EXTERN unsigned char *script;
EXTERN int script_timeout;
#ifdef CYGSEM_REDBOOT_VARIABLE_BAUD_RATE
EXTERN int console_baud_rate;
#endif
#endif
 
#ifdef CYGOPT_REDBOOT_FIS_ZLIB_COMMON_BUFFER
EXTERN unsigned char *fis_zlib_common_buffer;
#endif
 
// Prototypes
typedef int _printf_fun(const char *fmt, ...);
externC int strcasecmp(const char *s1, const char *s2);
externC int strncasecmp(const char *s1, const char *s2, size_t len);
 
externC void mon_write_char(char c);
externC bool verify_action(char *fmt, ...);
externC bool verify_action_with_timeout(int timeout, char *fmt, ...);
 
// Read a single line of input from the console, possibly with timeout
externC int _rb_gets(char *line, int len, int timeout);
// Just like _rb_gets(), except that the line buffer is assumed to contain
// valid input data. This provides an easy mechanism for edit-in-place.
externC int _rb_gets_preloaded(char *line, int len, int timeout);
// Result codes from 'gets()'
#define _GETS_TIMEOUT -1
#define _GETS_CTRLC -2
#define _GETS_GDB 0
#define _GETS_OK 1
 
// "console" selection
externC int start_console(void);
externC void end_console(int old_console);
 
// Alias functions
#ifdef CYGSEM_REDBOOT_FLASH_ALIASES
externC char *flash_lookup_alias(char *alias, char *alias_buf);
#endif
externC void expand_aliases(char *line, int len);
 
//
// Stream I/O support
//
 
typedef struct {
char *filename;
int mode;
int chan;
#ifdef CYGPKG_REDBOOT_NETWORKING
struct sockaddr_in *server;
#endif
} connection_info_t;
 
typedef struct {
int (*open)(connection_info_t *info, int *err);
void (*close)(int *err);
void (*terminate)(bool abort, int (*getc)(void));
int (*read)(char *buf, int size, int *err);
char *(*error)(int err);
} getc_io_funcs_t;
 
#define GETC_IO_FUNCS(_label_, _open_, _close_, _terminate_, _read_, _error_) \
getc_io_funcs_t _label_ = { \
_open_, _close_, _terminate_, _read_, _error_ \
};
 
struct load_io_entry {
char *name;
getc_io_funcs_t *funcs;
bool can_verbose;
bool need_filename;
int mode;
} CYG_HAL_TABLE_TYPE;
#define _RedBoot_load(_name_,_funcs_,_verbose_,_filename_,_mode_) \
struct load_io_entry _load_tab_##_funcs_##_name_ \
CYG_HAL_TABLE_QUALIFIED_ENTRY(RedBoot_load,_funcs_##_name) = \
{ #_name_, &_funcs_, _verbose_, _filename_, _mode_ };
#define RedBoot_load(_name_,_funcs_,_verbose_,_filename_, _mode_) \
_RedBoot_load(_name_,_funcs_,_verbose_,_filename_,_mode_)
#ifdef CYGPKG_COMPRESS_ZLIB
// Decompression support
typedef struct _pipe {
unsigned char* in_buf; // only changed by producer
int in_avail; // only changed by producer
unsigned char* out_buf; // only changed by consumer (init by producer)
int out_size; // only changed by consumer (init by producer)
int out_max; // set by producer
const char* msg; // message from consumer
void* priv; // handler's data
} _pipe_t;
 
typedef int _decompress_fun_init(_pipe_t*);
typedef int _decompress_fun_inflate(_pipe_t*);
typedef int _decompress_fun_close(_pipe_t*, int);
 
externC _decompress_fun_init* _dc_init;
externC _decompress_fun_inflate* _dc_inflate;
externC _decompress_fun_close* _dc_close;
#endif // CYGPKG_COMPRESS_ZLIB
 
// CLI support functions
externC bool parse_num(char *s, unsigned long *val, char **es, char *delim);
externC bool parse_bool(char *s, bool *val);
 
typedef void cmd_fun(int argc, char *argv[]);
struct cmd {
char *str;
char *help;
char *usage;
cmd_fun *fun;
struct cmd *sub_cmds, *sub_cmds_end;
} CYG_HAL_TABLE_TYPE;
externC struct cmd *cmd_search(struct cmd *tab, struct cmd *tabend, char *arg);
externC void cmd_usage(struct cmd *tab, struct cmd *tabend, char *prefix);
#define RedBoot_cmd(_s_,_h_,_u_,_f_) cmd_entry(_s_,_h_,_u_,_f_,0,0,RedBoot_commands)
#define RedBoot_nested_cmd(_s_,_h_,_u_,_f_,_subs_,_sube_) cmd_entry(_s_,_h_,_u_,_f_,_subs_,_sube_,RedBoot_commands)
#define _cmd_entry(_s_,_h_,_u_,_f_,_subs_,_sube_,_n_) \
cmd_fun _f_; \
struct cmd _cmd_tab_##_f_ CYG_HAL_TABLE_QUALIFIED_ENTRY(_n_,_f_) = {_s_, _h_, _u_, _f_, _subs_, _sube_};
#define cmd_entry(_s_,_h_,_u_,_f_,_subs_,_sube_,_n_) \
extern _cmd_entry(_s_,_h_,_u_,_f_,_subs_,_sube_,_n_)
#define local_cmd_entry(_s_,_h_,_u_,_f_,_n_) \
static _cmd_entry(_s_,_h_,_u_,_f_,0,0,_n_)
 
// Initialization functions
#define RedBoot_INIT_FIRST 0000
// Specify a 3 digit numeric value for proper prioritizing
#define RedBoot_INIT_PRIO(_n_) 1##_n_
#define RedBoot_INIT_LAST 9999
typedef void void_fun(void);
typedef void_fun *void_fun_ptr;
struct init_tab_entry {
void_fun_ptr fun;
} CYG_HAL_TABLE_TYPE;
#define _RedBoot_init(_f_,_p_) \
struct init_tab_entry _init_tab_##_p_##_f_ \
CYG_HAL_TABLE_QUALIFIED_ENTRY(RedBoot_inits,_p_##_f_) = { _f_ };
#define RedBoot_init(_f_,_p_) _RedBoot_init(_f_,_p_)
 
// Main loop [idle] call-back functions
#define RedBoot_IDLE_FIRST 0000
#define RedBoot_IDLE_BEFORE_NETIO 3000
#define RedBoot_IDLE_NETIO 5000
#define RedBoot_IDLE_AFTER_NETIO 7000
#define RedBoot_IDLE_LAST 9999
typedef void idle_fun(bool);
typedef idle_fun *idle_fun_ptr;
struct idle_tab_entry {
idle_fun_ptr fun;
} CYG_HAL_TABLE_TYPE;
#define _RedBoot_idle(_f_,_p_) \
struct idle_tab_entry _idle_tab_##_p_##_f_ \
CYG_HAL_TABLE_QUALIFIED_ENTRY(RedBoot_idle,_p_##_f_) = { _f_ };
#define RedBoot_idle(_f_,_p_) _RedBoot_idle(_f_,_p_)
 
// This function called when changing idle/not - mostly used by I/O
// to support idle when timeout, etc.
void do_idle(bool state);
 
// Option processing support
 
struct option_info {
char flag;
bool takes_arg;
int arg_type;
void **arg;
bool *arg_set;
char *name;
};
 
#define OPTION_ARG_TYPE_NUM 0 // Numeric data
#define OPTION_ARG_TYPE_STR 1 // Generic string
#define OPTION_ARG_TYPE_FLG 2 // Flag only
 
// Command line parsing
externC struct cmd *parse(char **line, int *argc, char **argv);
 
externC void init_opts(struct option_info *opts, char flag, bool takes_arg,
int arg_type, void **arg, bool *arg_set, char *name);
externC bool scan_opts(int argc, char *argv[], int first,
struct option_info *opts, int num_opts,
void **def_arg, int def_arg_type, char *def_descr);
 
#ifdef CYGNUM_HAL_VIRTUAL_VECTOR_AUX_CHANNELS
#define CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS \
(CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS+CYGNUM_HAL_VIRTUAL_VECTOR_AUX_CHANNELS)
#else
#define CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS \
CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS
#endif
 
#ifdef CYGPKG_REDBOOT_NETWORKING
//-----------------------------------------------------------------------------
// DNS wrapper
#ifdef CYGPKG_REDBOOT_NETWORKING_DNS
 
// I would really like if we could just pull in cyg/ns/dns/dns.h, but
// that would require adding dummy <network.h> and <netinet/in.h> files.
 
// Host name / IP mapping
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses */
};
#define h_addr h_addr_list[0] /* for backward compatibility */
 
externC int redboot_dns_res_init(void);
externC void set_dns(char* new_ip);
externC void show_dns(void);
externC struct hostent *gethostbyname(const char *host);
 
// Error reporting
externC int h_errno;
 
#define DNS_SUCCESS 0
#define HOST_NOT_FOUND 1
#define TRY_AGAIN 2
#define NO_RECOVERY 3
#define NO_DATA 4
 
static inline bool
_gethostbyname(const char* name, in_addr_t* host)
{
struct hostent* hent = gethostbyname(name);
if (hent) {
memcpy(host, hent->h_addr_list[0], sizeof(in_addr_t));
return true;
}
// Fall back to inet_aton - gethostbyname may already have tried
// it, but we can't know for sure (the DNS IP may not have been
// valid, preventing the inet_aton).
return inet_aton(name, host);
}
#else
static inline bool
_gethostbyname(const char* name, in_addr_t* host)
{
return inet_aton(name, host);
}
#endif // CYGPKG_REDBOOT_NETWORKING_DNS
#endif // CYGPKG_REDBOOT_NETWORKING
 
//-----------------------------------------------------------------------------
// String functions. Some of these are duplicates of the same functions in
// the I18N package.
 
// Validate a hex character
__inline__ static bool
_is_hex(char c)
{
return (((c >= '0') && (c <= '9')) ||
((c >= 'A') && (c <= 'F')) ||
((c >= 'a') && (c <= 'f')));
}
 
// Convert a single hex nibble
__inline__ static int
_from_hex(char c)
{
int ret = 0;
 
if ((c >= '0') && (c <= '9')) {
ret = (c - '0');
} else if ((c >= 'a') && (c <= 'f')) {
ret = (c - 'a' + 0x0a);
} else if ((c >= 'A') && (c <= 'F')) {
ret = (c - 'A' + 0x0A);
}
return ret;
}
 
// Convert a character to lower case
__inline__ static char
_tolower(char c)
{
if ((c >= 'A') && (c <= 'Z')) {
c = (c - 'A') + 'a';
}
return c;
}
 
// Validate alpha
__inline__ static bool
isalpha(int c)
{
return (((c >= 'a') && (c <= 'z')) ||
((c >= 'A') && (c <= 'Z')));
}
 
// Validate digit
__inline__ static bool
isdigit(int c)
{
return ((c >= '0') && (c <= '9'));
}
 
// Validate alphanum
__inline__ static bool
isalnum(int c)
{
return (isalpha(c) || isdigit(c));
}
 
//----------------------------------------------------------------------------
// syscall values
#if defined(CYGSEM_REDBOOT_BSP_SYSCALLS)
 
// These are required by the ANSI C part of newlib (excluding system() of
// course).
#define SYS_exit 1
#define SYS_open 2
#define SYS_close 3
#define SYS_read 4
#define SYS_write 5
#define SYS_lseek 6
#define SYS_unlink 7
#define SYS_getpid 8
#define SYS_kill 9
#define SYS_fstat 10
//#define SYS_sbrk 11 - not currently a system call, but reserved.
 
// ARGV support.
#define SYS_argvlen 12
#define SYS_argv 13
 
// These are extras added for one reason or another.
#define SYS_chdir 14
#define SYS_stat 15
#define SYS_chmod 16
#define SYS_utime 17
#define SYS_time 18
#define SYS_gettimeofday 19
#define SYS_times 20
 
#define SYS_interrupt 1000
#define SYS_meminfo 1001
 
#define __GET_SHARED 0xbaad // 47789 decimal
 
#ifdef CYGSEM_REDBOOT_BSP_SYSCALLS_GPROF
 
#define SYS_timer_call_back 2001
#define SYS_timer_frequency 2002
#define SYS_timer_reset 2003
 
#endif // CYGSEM_REDBOOT_BSP_SYSCALLS_GPROF
#define SYS_rename 3001
#define SYS_isatty 3002
#define SYS_system 3003
 
#endif // CYGSEM_REDBOOT_BSP_SYSCALLS
 
#endif // _REDBOOT_H_
/net/tftp_support.h
0,0 → 1,100
//==========================================================================
//
// net/tftp_support.h
//
// Stand-alone TFTP support for RedBoot
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
// Copyright (C) 2002 Gary Thomas
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): gthomas
// Contributors: gthomas
// Date: 2000-07-14
// Purpose:
// Description:
//
// This code is part of RedBoot (tm).
//
//####DESCRIPTIONEND####
//
//==========================================================================
 
#ifndef _TFTP_SUPPORT_H_
#define _TFTP_SUPPORT_H_
 
#include "net.h"
 
/*
* File transfer modes
*/
#define TFTP_NETASCII 0 // Text files
#define TFTP_OCTET 1 // Binary files
 
/*
* Errors
*/
#define TFTP_ENOTFOUND 1 /* file not found */
#define TFTP_EACCESS 2 /* access violation */
#define TFTP_ENOSPACE 3 /* disk full or allocation exceeded */
#define TFTP_EBADOP 4 /* illegal TFTP operation */
#define TFTP_EBADID 5 /* unknown transfer ID */
#define TFTP_EEXISTS 6 /* file already exists */
#define TFTP_ENOUSER 7 /* no such user */
#define TFTP_TIMEOUT 8 /* operation timed out */
#define TFTP_NETERR 9 /* some sort of network error */
#define TFTP_INVALID 10 /* invalid parameter */
#define TFTP_PROTOCOL 11 /* protocol violation */
#define TFTP_TOOLARGE 12 /* file is larger than buffer */
 
/*
* Client support
*/
 
extern int tftp_stream_open(connection_info_t *info, int *err);
extern int tftp_stream_read(char *buf, int len, int *err);
extern void tftp_stream_close(int *err);
extern char *tftp_error(int err);
 
#define TFTP_TIMEOUT_PERIOD 5
#define TFTP_TIMEOUT_MAX 15
#define TFTP_RETRIES_MAX 5
 
#define TFTP_PORT 69
 
extern getc_io_funcs_t tftp_io;
 
#endif // _TFTP_SUPPORT_H_
/net/tftp.h
0,0 → 1,146
//==========================================================================
//
// net/tftp.h
//
// Stand-alone TFTP support for RedBoot
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
// Copyright (C) 2002 Gary Thomas
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//####BSDCOPYRIGHTBEGIN####
//
// -------------------------------------------
//
// Portions of this software may have been derived from OpenBSD or other sources,
// and are covered by the appropriate copyright disclaimers included herein.
//
// -------------------------------------------
//
//####BSDCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): gthomas
// Contributors: gthomas
// Date: 2000-07-14
// Purpose:
// Description:
//
// This code is part of RedBoot (tm).
//
//####DESCRIPTIONEND####
//
//==========================================================================
 
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)tftp.h 5.4 (Berkeley) 4/3/91
*/
 
#ifndef _ARPA_TFTP_H_
#define _ARPA_TFTP_H_
 
/*
* Trivial File Transfer Protocol (IEN-133)
* Now, rev 2 - RFC 1350
*/
#define SEGSIZE 512 /* data segment size */
 
/*
* Packet types.
*/
#define RRQ 01 /* read request */
#define WRQ 02 /* write request */
#define DATA 03 /* data packet */
#define ACK 04 /* acknowledgement */
#define ERROR 05 /* error code */
 
struct tftphdr {
short th_opcode; /* packet type */
union {
unsigned short tu_block; /* block # */
short tu_code; /* error code */
char tu_stuff[1]; /* request packet stuff */
} __attribute__ ((packed)) th_u;
char th_data[0]; /* data or error string */
} __attribute__ ((packed));
 
#define th_block th_u.tu_block
#define th_code th_u.tu_code
#define th_stuff th_u.tu_stuff
#define th_msg th_data
 
/*
* Error codes.
*/
#define EUNDEF 0 /* not defined */
#define ENOTFOUND 1 /* file not found */
#define EACCESS 2 /* access violation */
#define ENOSPACE 3 /* disk full or allocation exceeded */
#define EBADOP 4 /* illegal TFTP operation */
#define EBADID 5 /* unknown transfer ID */
#define EEXISTS 6 /* file already exists */
#define ENOUSER 7 /* no such user */
 
#endif /* !_ARPA_TFTP_H_ */
/net/http.h
0,0 → 1,70
//==========================================================================
//
// net/http.h
//
// Stand-alone HTTP (client) support for RedBoot
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
// Copyright (C) 2002 Gary Thomas
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): gthomas
// Contributors: gthomas
// Date: 2002-05-22
// Purpose:
// Description:
//
// This code is part of RedBoot (tm).
//
//####DESCRIPTIONEND####
//
//==========================================================================
 
#ifndef _HTTP_H_
#define _HTTP_H_
 
extern int http_stream_open(connection_info_t *info, int *err);
extern int http_stream_read(char *buf, int len, int *err);
extern void http_stream_close(int *err);
extern char *http_error(int err);
 
#define HTTP_NOERR 0 // No error
#define HTTP_BADHDR 1 // Invalid HTTP header (response)
#define HTTP_OPEN 2 // Problems opening connection
#define HTTP_IO 3 // Misc I/O problems
 
extern getc_io_funcs_t http_io;
#endif // _HTTP_H_
/net/bootp.h
0,0 → 1,310
//==========================================================================
//
// net/bootp.h
//
// Stand-alone BOOTP support for RedBoot
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
// Copyright (C) 2002 Gary Thomas
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): gthomas
// Contributors: gthomas
// Date: 2000-07-14
// Purpose:
// Description:
//
// This code is part of RedBoot (tm).
//
//####DESCRIPTIONEND####
//
//==========================================================================
 
/************************************************************************
Copyright 1988, 1991 by Carnegie Mellon University
 
All Rights Reserved
 
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name of Carnegie Mellon University not be used
in advertising or publicity pertaining to distribution of the software
without specific, written prior permission.
 
CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
************************************************************************/
 
#ifndef _BOOTP_H_
#define _BOOTP_H_
 
/*
* Bootstrap Protocol (BOOTP). RFC951 and RFC1395.
*
* This file specifies the "implementation-independent" BOOTP protocol
* information which is common to both client and server.
*
*/
 
#define BP_CHADDR_LEN 16
#define BP_SNAME_LEN 64
#define BP_FILE_LEN 128
#define BP_VEND_LEN 312
#define BP_MINPKTSZ 300 /* to check sizeof(struct bootp) */
#define BP_MIN_VEND_SIZE 64 /* minimum actual vendor area */
 
typedef struct bootp {
unsigned char bp_op; /* packet opcode type */
unsigned char bp_htype; /* hardware addr type */
unsigned char bp_hlen; /* hardware addr length */
unsigned char bp_hops; /* gateway hops */
unsigned int bp_xid; /* transaction ID */
unsigned short bp_secs; /* seconds since boot began */
unsigned short bp_flags; /* RFC1532 broadcast, etc. */
struct in_addr bp_ciaddr; /* client IP address */
struct in_addr bp_yiaddr; /* 'your' IP address */
struct in_addr bp_siaddr; /* server IP address */
struct in_addr bp_giaddr; /* gateway IP address */
unsigned char bp_chaddr[BP_CHADDR_LEN]; /* client hardware address */
char bp_sname[BP_SNAME_LEN]; /* server host name */
char bp_file[BP_FILE_LEN]; /* boot file name */
unsigned char bp_vend[BP_VEND_LEN]; /* vendor-specific area */
/* note that bp_vend can be longer, extending to end of packet. */
} bootp_header_t;
 
/*
* UDP port numbers, server and client.
*/
#define IPPORT_BOOTPS 67
#define IPPORT_BOOTPC 68
 
#define BOOTREPLY 2
#define BOOTREQUEST 1
 
/*
* Hardware types from Assigned Numbers RFC.
*/
#define HTYPE_ETHERNET 1
#define HTYPE_EXP_ETHERNET 2
#define HTYPE_AX25 3
#define HTYPE_PRONET 4
#define HTYPE_CHAOS 5
#define HTYPE_IEEE802 6
#define HTYPE_ARCNET 7
 
/*
* Vendor magic cookie (v_magic) for CMU
*/
#define VM_CMU "CMU"
 
/*
* Vendor magic cookie (v_magic) for RFC1048
*/
#define VM_RFC1048 { 99, 130, 83, 99 }
 
 
/*
* Tag values used to specify what information is being supplied in
* the vendor (options) data area of the packet.
*/
/* RFC 1048 */
/* End of cookie */
#define TAG_END ((unsigned char) 255)
/* padding for alignment */
#define TAG_PAD ((unsigned char) 0)
/* Subnet mask */
#define TAG_SUBNET_MASK ((unsigned char) 1)
/* Time offset from UTC for this system */
#define TAG_TIME_OFFSET ((unsigned char) 2)
/* List of routers on this subnet */
#define TAG_GATEWAY ((unsigned char) 3)
/* List of rfc868 time servers available to client */
#define TAG_TIME_SERVER ((unsigned char) 4)
/* List of IEN 116 name servers */
#define TAG_NAME_SERVER ((unsigned char) 5)
/* List of DNS name servers */
#define TAG_DOMAIN_SERVER ((unsigned char) 6)
/* List of MIT-LCS UDL log servers */
#define TAG_LOG_SERVER ((unsigned char) 7)
/* List of rfc865 cookie servers */
#define TAG_COOKIE_SERVER ((unsigned char) 8)
/* List of rfc1179 printer servers (in order to try) */
#define TAG_LPR_SERVER ((unsigned char) 9)
/* List of Imagen Impress servers (in prefered order) */
#define TAG_IMPRESS_SERVER ((unsigned char) 10)
/* List of rfc887 Resourse Location servers */
#define TAG_RLP_SERVER ((unsigned char) 11)
/* Hostname of client */
#define TAG_HOST_NAME ((unsigned char) 12)
/* boot file size */
#define TAG_BOOT_SIZE ((unsigned char) 13)
/* RFC 1395 */
/* path to dump to in case of crash */
#define TAG_DUMP_FILE ((unsigned char) 14)
/* domain name for use with the DNS */
#define TAG_DOMAIN_NAME ((unsigned char) 15)
/* IP address of the swap server for this machine */
#define TAG_SWAP_SERVER ((unsigned char) 16)
/* The path name to the root filesystem for this machine */
#define TAG_ROOT_PATH ((unsigned char) 17)
/* RFC 1497 */
/* filename to tftp with more options in it */
#define TAG_EXTEN_FILE ((unsigned char) 18)
/* RFC 1533 */
/* The following are in rfc1533 and may be used by BOOTP/DHCP */
/* IP forwarding enable/disable */
#define TAG_IP_FORWARD ((unsigned char) 19)
/* Non-Local source routing enable/disable */
#define TAG_IP_NLSR ((unsigned char) 20)
/* List of pairs of addresses/masks to allow non-local source routing to */
#define TAG_IP_POLICY_FILTER ((unsigned char) 21)
/* Maximum size of datagrams client should be prepared to reassemble */
#define TAG_IP_MAX_DRS ((unsigned char) 22)
/* Default IP TTL */
#define TAG_IP_TTL ((unsigned char) 23)
/* Timeout in seconds to age path MTU values found with rfc1191 */
#define TAG_IP_MTU_AGE ((unsigned char) 24)
/* Table of MTU sizes to use when doing rfc1191 MTU discovery */
#define TAG_IP_MTU_PLAT ((unsigned char) 25)
/* MTU to use on this interface */
#define TAG_IP_MTU ((unsigned char) 26)
/* All subnets are local option */
#define TAG_IP_SNARL ((unsigned char) 27)
/* broadcast address */
#define TAG_IP_BROADCAST ((unsigned char) 28)
/* perform subnet mask discovery using ICMP */
#define TAG_IP_SMASKDISC ((unsigned char) 29)
/* act as a subnet mask server using ICMP */
#define TAG_IP_SMASKSUPP ((unsigned char) 30)
/* perform rfc1256 router discovery */
#define TAG_IP_ROUTERDISC ((unsigned char) 31)
/* address to send router solicitation requests */
#define TAG_IP_ROUTER_SOL_ADDR ((unsigned char) 32)
/* list of static routes to addresses (addr, router) pairs */
#define TAG_IP_STATIC_ROUTES ((unsigned char) 33)
/* use trailers (rfc893) when using ARP */
#define TAG_IP_TRAILER_ENC ((unsigned char) 34)
/* timeout in seconds for ARP cache entries */
#define TAG_ARP_TIMEOUT ((unsigned char) 35)
/* use either Ethernet version 2 (rfc894) or IEEE 802.3 (rfc1042) */
#define TAG_ETHER_IEEE ((unsigned char) 36)
/* default TCP TTL when sending TCP segments */
#define TAG_IP_TCP_TTL ((unsigned char) 37)
/* time for client to wait before sending a keepalive on a TCP connection */
#define TAG_IP_TCP_KA_INT ((unsigned char) 38)
/* don't send keepalive with an octet of garbage for compatability */
#define TAG_IP_TCP_KA_GARBAGE ((unsigned char) 39)
/* NIS domainname */
#define TAG_NIS_DOMAIN ((unsigned char) 40)
/* list of NIS servers */
#define TAG_NIS_SERVER ((unsigned char) 41)
/* list of NTP servers */
#define TAG_NTP_SERVER ((unsigned char) 42)
/* and stuff vendors may want to add */
#define TAG_VEND_SPECIFIC ((unsigned char) 43)
/* NetBios over TCP/IP name server */
#define TAG_NBNS_SERVER ((unsigned char) 44)
/* NetBios over TCP/IP NBDD servers (rfc1001/1002) */
#define TAG_NBDD_SERVER ((unsigned char) 45)
/* NetBios over TCP/IP node type option for use with above */
#define TAG_NBOTCP_OTPION ((unsigned char) 46)
/* NetBios over TCP/IP scopt option for use with above */
#define TAG_NB_SCOPE ((unsigned char) 47)
/* list of X Window system font servers */
#define TAG_XFONT_SERVER ((unsigned char) 48)
/* list of systems running X Display Manager (xdm) available to this client */
#define TAG_XDISPLAY_SERVER ((unsigned char) 49)
 
/* While the following are only allowed for DHCP */
/* DHCP requested IP address */
#define TAG_DHCP_REQ_IP ((unsigned char) 50)
/* DHCP time for lease of IP address */
#define TAG_DHCP_LEASE_TIME ((unsigned char) 51)
/* DHCP options overload */
#define TAG_DHCP_OPTOVER ((unsigned char) 52)
/* DHCP message type */
#define TAG_DHCP_MESS_TYPE ((unsigned char) 53)
/* DHCP server identification */
#define TAG_DHCP_SERVER_ID ((unsigned char) 54)
/* DHCP ordered list of requested parameters */
#define TAG_DHCP_PARM_REQ_LIST ((unsigned char) 55)
/* DHCP reply message */
#define TAG_DHCP_TEXT_MESSAGE ((unsigned char) 56)
/* DHCP maximum packet size willing to accept */
#define TAG_DHCP_MAX_MSGSZ ((unsigned char) 57)
/* DHCP time 'til client needs to renew */
#define TAG_DHCP_RENEWAL_TIME ((unsigned char) 58)
/* DHCP time 'til client needs to rebind */
#define TAG_DHCP_REBIND_TIME ((unsigned char) 59)
/* DHCP class identifier */
#define TAG_DHCP_CLASSID ((unsigned char) 60)
/* DHCP client unique identifier */
#define TAG_DHCP_CLIENTID ((unsigned char) 61)
 
/* XXX - Add new tags here */
 
 
/*
* "vendor" data permitted for CMU bootp clients.
*/
 
struct cmu_vend {
char v_magic[4]; /* magic number */
unsigned int v_flags; /* flags/opcodes, etc. */
struct in_addr v_smask; /* Subnet mask */
struct in_addr v_dgate; /* Default gateway */
struct in_addr v_dns1, v_dns2; /* Domain name servers */
struct in_addr v_ins1, v_ins2; /* IEN-116 name servers */
struct in_addr v_ts1, v_ts2; /* Time servers */
int v_unused[6]; /* currently unused */
};
 
 
/* v_flags values */
#define VF_SMASK 1 /* Subnet mask field contains valid data */
 
#define IPPORT_BOOTPS 67
#define IPPORT_BOOTPC 68
 
#endif // _BOOTP_H_
/net/net.h
0,0 → 1,633
//==========================================================================
//
// net/net.h
//
// Stand-alone networking support for RedBoot
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
// Copyright (C) 2002 Gary Thomas
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): gthomas
// Contributors: gthomas
// Date: 2000-07-14
// Purpose:
// Description:
//
// This code is part of RedBoot (tm).
//
//####DESCRIPTIONEND####
//
//==========================================================================
 
#ifndef _NET_H_
#define _NET_H_
 
#include <pkgconf/system.h>
#include <pkgconf/redboot.h>
#include <cyg/hal/hal_arch.h>
#include <cyg/hal/basetype.h>
#include <string.h>
 
extern bool net_debug;
#ifdef CYGPKG_IO_ETH_DRIVERS
# include <pkgconf/io_eth_drivers.h>
# ifdef CYGDBG_IO_ETH_DRIVERS_DEBUG
extern int cyg_io_eth_net_debug;
# endif
#endif
 
extern unsigned long do_ms_tick(void);
extern unsigned long get_ms_ticks(void);
#define MS_TICKS() get_ms_ticks()
#define MS_TICKS_DELAY() do_ms_tick()
 
/* #define NET_SUPPORT_RARP 1 */
#define NET_SUPPORT_ICMP 1
#define NET_SUPPORT_UDP 1
#define NET_SUPPORT_TCP 1
 
#if (CYG_BYTEORDER == CYG_LSBFIRST)
#ifndef __LITTLE_ENDIAN__
#define __LITTLE_ENDIAN__
#endif
extern unsigned long ntohl(unsigned long x);
extern unsigned long ntohs(unsigned short x);
#else
#define ntohl(x) (x)
#define ntohs(x) (x)
#endif
 
#define htonl(x) ntohl(x)
#define htons(x) ntohs(x)
 
/*
* Minimum ethernet packet length.
*/
#define ETH_MIN_PKTLEN 60
#define ETH_MAX_PKTLEN (1540-14)
#define ETH_HDR_SIZE 14
 
typedef unsigned char enet_addr_t[6];
typedef unsigned char ip_addr_t[4];
 
typedef unsigned char octet;
typedef unsigned short word;
typedef unsigned int dword;
 
#ifndef NULL
#define NULL 0
#endif
 
// IPv4 support
typedef struct in_addr {
unsigned long s_addr; // IPv4 address
} in_addr_t;
 
// Socket/connection information
struct sockaddr_in {
struct in_addr sin_addr;
unsigned short sin_port;
unsigned short sin_family;
short sin_len;
};
#define AF_INET 1
#define INADDR_ANY 0
 
struct timeval {
unsigned long tv_sec;
unsigned long tv_usec;
};
 
/*
* Simple timer support structure.
*/
typedef void (*tmr_handler_t)(void *user_data);
 
/*
* Timer structure.
* When expiration time is met or exceeded, the handler is
* called and the timer struct is removed from the list.
*/
typedef struct _timer {
struct _timer *next; /* next timer in list */
unsigned long delay; /* expiration time relative to start time */
unsigned long start; /* when the timer was set */
tmr_handler_t handler; /* user procedure to call when timer 'fires' */
void *user_data; /* user pointer passed to above procedure */
} timer_t;
 
 
/*
* Ethernet header.
*/
typedef struct {
enet_addr_t destination;
enet_addr_t source;
word type;
#define ETH_TYPE_IP 0x800
#define ETH_TYPE_ARP 0x806
#define ETH_TYPE_RARP 0x8053
} eth_header_t;
 
 
/*
* ARP/RARP header.
*/
typedef struct {
word hw_type;
#define ARP_HW_ETHER 1
#define ARP_HW_EXP_ETHER 2
word protocol;
octet hw_len;
octet proto_len;
word opcode;
#define ARP_REQUEST 1
#define ARP_REPLY 2
#define RARP_REQUEST 3
#define RARP_REPLY 4
enet_addr_t sender_enet;
ip_addr_t sender_ip;
enet_addr_t target_enet;
ip_addr_t target_ip;
} arp_header_t;
 
 
#define ARP_PKT_SIZE (sizeof(arp_header_t) + ETH_HDR_SIZE)
 
/*
* Internet Protocol header.
*/
typedef struct {
#ifdef __LITTLE_ENDIAN__
octet hdr_len:4,
version:4;
#else
octet version:4,
hdr_len:4;
#endif
octet tos;
word length;
word ident;
word fragment;
octet ttl;
octet protocol;
#define IP_PROTO_ICMP 1
#define IP_PROTO_TCP 6
#define IP_PROTO_UDP 17
word checksum;
ip_addr_t source;
ip_addr_t destination;
} ip_header_t;
 
 
#define IP_PKT_SIZE (60 + ETH_HDR_SIZE)
 
 
/*
* A IP<->ethernet address mapping.
*/
typedef struct {
ip_addr_t ip_addr;
enet_addr_t enet_addr;
} ip_route_t;
 
 
/*
* UDP header.
*/
typedef struct {
word src_port;
word dest_port;
word length;
word checksum;
} udp_header_t;
 
 
/*
* TCP header.
*/
typedef struct {
word src_port;
word dest_port;
dword seqnum;
dword acknum;
#ifdef __LITTLE_ENDIAN__
octet reserved:4,
hdr_len:4;
#else
octet hdr_len:4,
reserved:4;
#endif
octet flags;
#define TCP_FLAG_FIN 1
#define TCP_FLAG_SYN 2
#define TCP_FLAG_RST 4
#define TCP_FLAG_PSH 8
#define TCP_FLAG_ACK 16
#define TCP_FLAG_URG 32
word window;
word checksum;
word urgent;
} tcp_header_t;
 
 
/*
* ICMP header.
*/
typedef struct {
octet type;
#define ICMP_TYPE_ECHOREPLY 0
#define ICMP_TYPE_ECHOREQUEST 8
octet code;
word checksum;
word ident;
word seqnum;
} icmp_header_t;
 
typedef struct _pktbuf {
struct _pktbuf *next;
union {
ip_header_t *__iphdr; /* pointer to IP header */
arp_header_t *__arphdr; /* pointer to ARP header */
} u1;
#define ip_hdr u1.__iphdr
#define arp_hdr u1.__arphdr
union {
udp_header_t *__udphdr; /* pointer to UDP header */
tcp_header_t *__tcphdr; /* pointer to TCP header */
icmp_header_t *__icmphdr; /* pointer to ICMP header */
} u2;
#define udp_hdr u2.__udphdr
#define tcp_hdr u2.__tcphdr
#define icmp_hdr u2.__icmphdr
word pkt_bytes; /* number of data bytes in buf */
word bufsize; /* size of buf */
word *buf;
} pktbuf_t;
 
 
/* protocol handler */
typedef void (*pkt_handler_t)(pktbuf_t *pkt, eth_header_t *eth_hdr);
 
/* ICMP fielder */
typedef void (*icmp_handler_t)(pktbuf_t *pkt, ip_route_t *src_route);
 
typedef struct _udp_socket {
struct _udp_socket *next;
word our_port;
word pad;
void (*handler)(struct _udp_socket *skt, char *buf, int len,
ip_route_t *src_route, word src_port);
} udp_socket_t;
 
 
typedef void (*udp_handler_t)(udp_socket_t *skt, char *buf, int len,
ip_route_t *src_route, word src_port);
 
 
typedef struct _tcp_socket {
struct _tcp_socket *next;
int state; /* connection state */
#define _CLOSED 0
#define _LISTEN 1
#define _SYN_RCVD 2
#define _SYN_SENT 3
#define _ESTABLISHED 4
#define _CLOSE_WAIT 5
#define _LAST_ACK 6
#define _FIN_WAIT_1 7
#define _FIN_WAIT_2 8
#define _CLOSING 9
#define _TIME_WAIT 10
ip_route_t his_addr; /* address of other end of connection */
word our_port;
word his_port;
word data_bytes; /* number of data bytes in pkt */
char reuse; /* SO_REUSEADDR, no 2MSL */
timer_t timer;
pktbuf_t pkt; /* dedicated xmit packet */
pktbuf_t *rxlist; /* list of unread incoming data packets */
char *rxptr; /* pointer to next byte to read */
int rxcnt; /* bytes left in current read packet */
dword ack;
dword seq;
char pktbuf[ETH_MAX_PKTLEN];
} tcp_socket_t;
 
/*
* Our address.
*/
extern enet_addr_t __local_enet_addr;
extern ip_addr_t __local_ip_addr;
#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
extern ip_addr_t __local_ip_gate;
extern ip_addr_t __local_ip_mask;
#endif
 
/*
* Set a timer. Caller is responsible for providing the timer_t struct.
*/
extern void __timer_set(timer_t *t, unsigned long delay,
tmr_handler_t handler, void *user_data);
 
/*
* Cancel the given timer.
*/
extern void __timer_cancel(timer_t *t);
 
/*
* Poll timer list for timer expirations.
*/
extern void __timer_poll(void);
 
/*
* Initialize the free list.
*/
extern void __pktbuf_init(void);
 
/*
* simple pktbuf allocation.
* allocates at least nbytes for packet data including ethernet header.
*/
extern pktbuf_t *__pktbuf_alloc(int nbytes);
 
/*
* return a pktbuf for reuse.
*/
extern void __pktbuf_free(pktbuf_t *pkt);
 
/*
* Dump packet structures (debug, in case of running out)
*/
extern void __pktbuf_dump(void);
 
 
/*
* Install handlers for ethernet packets.
* Returns old handler.
*/
extern pkt_handler_t __eth_install_listener(int eth_type,
pkt_handler_t handler);
extern void __eth_remove_listener(int eth_type);
 
/*
* Non-blocking poll of ethernet link. Processes all pending
* input packets.
*/
extern void __enet_poll(void);
 
/*
* Send an ethernet packet.
*/
extern void __enet_send(pktbuf_t *pkt, enet_addr_t *dest, int eth_type);
 
#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
/*
* return true if addr is on local subnet
*/
extern int __ip_addr_local(ip_addr_t *addr);
#endif
 
/*
* Handle incoming ARP packets.
*/
extern void __arp_handler(pktbuf_t *pkt);
 
/*
* Find the ethernet address of the machine with the given
* ip address.
* Return true and fills in 'eth_addr' if successful, false
* if unsuccessful.
*/
extern int __arp_request(ip_addr_t *ip_addr, enet_addr_t *eth_addr);
 
/*
* Lookup an address from the local ARP cache. If not found,
* then call 'arp_request' to find it. [Basically just a cached
* version of 'arp_request']
*/
extern int __arp_lookup(ip_addr_t *host, ip_route_t *rt);
 
/*
* Do a one's complement checksum.
* The data being checksum'd is in network byte order.
* The returned checksum is in network byte order.
*/
extern unsigned short __sum(word *w, int len, int init_sum);
 
/*
* Compute a partial checksum for the UDP/TCP pseudo header.
*/
extern int __pseudo_sum(ip_header_t *ip);
 
/*
* Handle IP packets coming from the polled ethernet interface.
*/
extern void __ip_handler(pktbuf_t *pkt, enet_addr_t *src_enet_addr);
 
/*
* Send an IP packet.
*
* The IP data field should contain pkt->pkt_bytes of data.
* pkt->[udp|tcp|icmp]_hdr points to the IP data field. Any
* IP options are assumed to be already in place in the IP
* options field. Returns 0 for success.
*/
extern int __ip_send(pktbuf_t *pkt, int protocol, ip_route_t *dest);
 
/*
* Abort connection.
*/
extern void __tcp_abort(tcp_socket_t *s, unsigned long delay);
 
/*
* Handle incoming ICMP packets.
*/
extern void __icmp_handler(pktbuf_t *pkt, ip_route_t *r);
extern int __icmp_install_listener(icmp_handler_t handler);
extern void __icmp_remove_listener(void);
 
/*
* Handle incoming UDP packets.
*/
extern void __udp_handler(pktbuf_t *pkt, ip_route_t *r);
 
/*
* Install a handler for incoming udp packets.
* Caller provides the udp_socket_t structure.
* Returns zero if successful, -1 if socket is already used.
*/
extern int __udp_install_listener(udp_socket_t *s, word port,
udp_handler_t handler);
 
/*
* Remove the handler for the given socket.
*/
extern void __udp_remove_listener(word port);
 
/*
* Send a UDP packet.
*/
extern int __udp_send(char *buf, int len, ip_route_t *dest_ip,
word dest_port, word src_port);
 
// Send a UDP packet
extern int __udp_sendto(char *buf, int len,
struct sockaddr_in *server, struct sockaddr_in *local);
 
// Receive a UDP packet
extern int __udp_recvfrom(char *buf, int len,
struct sockaddr_in *from, struct sockaddr_in *local,
struct timeval *timeout);
 
/*
* TCP poll function. Should be called as often as possible.
*/
extern void __tcp_poll(void);
 
/*
* Initiate outgoing connection, waiting for at most timeout seconds.
*/
extern int __tcp_open(tcp_socket_t *s, struct sockaddr_in *host,
word port, int timeout, int *err);
 
/*
* Set up a listening socket on the given port.
* Does not block.
*/
extern int __tcp_listen(tcp_socket_t *s, word port);
 
/*
* SO_REUSEADDR, no 2MSL.
*/
extern void __tcp_so_reuseaddr(tcp_socket_t *s);
 
/*
* Block while waiting for all outstanding socket data to
* be transmitted.
*/
extern void __tcp_drain(tcp_socket_t *s);
 
/*
* Initiate connection close.
*/
extern void __tcp_close(tcp_socket_t *s);
 
/*
* Wait until connection has fully closed.
*/
extern void __tcp_close_wait(tcp_socket_t *s);
 
/*
* Read up to 'len' bytes without blocking.
* Returns number of bytes read.
* If connection is closed, returns -1.
*/
extern int __tcp_read(tcp_socket_t *s, char *buf, int len);
 
/*
* Write up to 'len' bytes without blocking.
* Returns number of bytes written.
* If connection is closed, returns -1.
*/
extern int __tcp_write(tcp_socket_t *s, char *buf, int len);
 
/*
* Write up to 'len' bytes, blocking until sent (not ACK'd).
* Returns number of bytes written.
* If connection is closed, returns -1.
*/
extern int __tcp_write_block(tcp_socket_t *s, char *buf, int len);
 
 
/*
* The following are a higher-level tcp socket interface.
*/
 
/*
* Initialize a socket for given port.
*/
extern void __skt_init(tcp_socket_t *s, unsigned short port);
 
/*
* Return true if socket connection is closed.
*/
#define __skt_is_closed(s) (((tcp_socket_t *)(s))->state == _CLOSED)
 
/*
* Block while listening for an incoming connection.
*/
extern void __skt_wait_for_connect(tcp_socket_t *s);
 
/*
* Read up to 'len' bytes from the given socket.
* Returns number of bytes read.
* Doesn't block.
*/
extern int __skt_read(tcp_socket_t *s, char *buf, int len);
 
/*
* Write 'len' bytes to the given socket.
* Returns number of bytes written.
* May not write all data if connection closes.
*/
extern int __skt_write(tcp_socket_t *s, char *buf, int len);
 
// Initialize the network stack - logical driver layer, etc.
extern void net_init(void);
 
// Test for new network I/O connections
extern void net_io_test(bool is_idle);
 
// Conversion between IP addresses and printable strings
extern bool inet_aton(const char *, in_addr_t *);
extern char *inet_ntoa(in_addr_t *);
 
// FIXME
/* #define NET_SUPPORT_RARP 1 */
#define NET_SUPPORT_ICMP 1
#define NET_SUPPORT_UDP 1
#define NET_SUPPORT_TCP 1
 
#ifdef BSP_LOG
#define BSPLOG(x) { int old_console = start_console(); x; end_console(old_console); }
#define bsp_log diag_printf
#else
#define BSPLOG(x)
#endif
 
#endif // _NET_H_
/fis.h
0,0 → 1,79
#ifndef _FIS_H_
#define _FIS_H_
//==========================================================================
//
// fis.h
//
// RedBoot - FLASH image directory layout
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): gthomas
// Contributors: gthomas, tkoeller
// Date: 2000-07-28
// Purpose:
// Description:
//
// This code is part of RedBoot (tm).
//
//####DESCRIPTIONEND####
//
//==========================================================================
 
#include <pkgconf/redboot.h>
#ifdef CYGOPT_REDBOOT_FIS
#include <cyg/infra/cyg_type.h>
 
#define FIS_IMAGE_DESC_SIZE_UNPADDED \
(16 + 4 * sizeof(unsigned long) + 3 * sizeof(CYG_ADDRESS))
 
struct fis_image_desc {
unsigned char name[16]; // Null terminated name
CYG_ADDRESS flash_base; // Address within FLASH of image
CYG_ADDRESS mem_base; // Address in memory where it executes
unsigned long size; // Length of image
CYG_ADDRESS entry_point; // Execution entry point
unsigned long data_length; // Length of actual data
unsigned char _pad[CYGNUM_REDBOOT_FIS_DIRECTORY_ENTRY_SIZE-FIS_IMAGE_DESC_SIZE_UNPADDED];
unsigned long desc_cksum; // Checksum over image descriptor
unsigned long file_cksum; // Checksum over image data
};
 
struct fis_image_desc *fis_lookup(char *name, int *num);
 
#endif // CYGOPT_REDBOOT_FIS
#endif // _FIS_H_
/flash_config.h
0,0 → 1,96
//==========================================================================
//
// flash_config.h
//
// Flash configuration data tables for RedBoot
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): gthomas
// Contributors: gthomas
// Date: 2000-08-21
// Purpose:
// Description:
//
// This code is part of RedBoot (tm).
//
//####DESCRIPTIONEND####
//
//==========================================================================
 
#ifndef _FLASH_CONFIG_H_
#define _FLASH_CONFIG_H_
 
#define MAX_SCRIPT_LENGTH CYGNUM_REDBOOT_FLASH_SCRIPT_SIZE
#define MAX_STRING_LENGTH CYGNUM_REDBOOT_FLASH_STRING_SIZE
#define MAX_CONFIG_DATA CYGNUM_REDBOOT_FLASH_CONFIG_SIZE
 
#define CONFIG_EMPTY 0
#define CONFIG_BOOL 1
#define CONFIG_INT 2
#define CONFIG_STRING 3
#define CONFIG_SCRIPT 4
#ifdef CYGPKG_REDBOOT_NETWORKING
#define CONFIG_IP 5
#define CONFIG_ESA 6
#endif
 
struct config_option {
char *key;
char *title;
char *enable;
bool enable_sense;
int type;
unsigned long dflt;
} CYG_HAL_TABLE_TYPE;
 
#define ALWAYS_ENABLED (char *)0
 
#define RedBoot_config_option(_t_,_n_,_e_,_ie_,_type_,_dflt_) \
struct config_option _config_option_##_n_ \
CYG_HAL_TABLE_QUALIFIED_ENTRY(RedBoot_config_options,_n_) = \
{#_n_,_t_,_e_,_ie_,_type_,(unsigned long)_dflt_};
 
// Cause the in-memory configuration data to be written to flash
void flash_write_config(void);
// Fetch a data item from flash storage, returns 'false' if not found
bool flash_get_config(char *key, void *val, int type);
// Add a new data item to configuration data base. Returns 'false'
// if no space is available.
bool flash_add_config(struct config_option *opt, bool update);
 
#endif // _FLASH_CONFIG_H_
/fs/disk.h
0,0 → 1,173
//==========================================================================
//
// disk.h
//
// Stand-alone disk support for RedBoot
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): msalter
// Contributors: msalter
// Date: 2001-07-02
// Purpose:
// Description:
//
// This code is part of RedBoot (tm).
//
//####DESCRIPTIONEND####
//
//==========================================================================
 
#ifndef CYGONCE_REDBOOT_DISK_H
#define CYGONCE_REDBOOT_DISK_H
 
#define SECTOR_SIZE 512
 
// Convenience macros to access disk/filesystem info which may
// be stored in a fixed endian format.
 
#define __SWAB16(x) \
((((x) & 0xFF) << 8) | (((x) >> 8) & 0xFF))
 
#define __SWAB32(x) \
((((x) & 0xff) << 24) | \
(((x) & 0xff00) << 8) | \
(((x) >> 8) & 0xff00) | \
(((x) >> 24) & 0xff))
 
#if (CYG_BYTEORDER == CYG_MSBFIRST)
#define SWAB_LE16(x) __SWAB16(x)
#define SWAB_LE32(x) __SWAB32(x)
#define SWAB_BE16(x) (x)
#define SWAB_BE32(x) (x)
#else
#define SWAB_LE16(x) (x)
#define SWAB_LE32(x) (x)
#define SWAB_BE16(x) __SWAB16(x)
#define SWAB_BE32(x) __SWAB32(x)
#endif
 
struct partition;
 
// filesystem interface
typedef struct fs_funs {
// Load a file into memory.
void * (*open)(struct partition *p, const char *path);
int (*read)(void *fp, char *buf, cyg_uint32 nbytes);
} fs_funs_t;
 
struct disk;
 
typedef struct partition {
struct disk *disk;
fs_funs_t *funs;
cyg_uint32 start_sector; // first sector in partition
cyg_uint32 nr_sectors; // number of sectors in partition
cyg_uint8 systype; // FAT12, FAT16, Linux, etc.
cyg_uint8 bootflag; // not really used...
} partition_t;
 
// System types
#define SYSTYPE_FAT12 0x01
#define SYSTYPE_FAT16_32M 0x04
#define SYSTYPE_EXTENDED 0x05
#define SYSTYPE_FAT16 0x06
#define SYSTYPE_LINUX_SWAP 0x82
#define SYSTYPE_LINUX 0x83
 
typedef struct disk_funs {
int (*read)(struct disk *d,
cyg_uint32 start_sector,
cyg_uint32 *buf,
cyg_uint8 nr_sectors);
} disk_funs_t;
 
 
typedef struct disk {
disk_funs_t *funs; // Disk driver functions
void *private; // Whatever is needed by disk functions
cyg_uint32 nr_sectors; // Total disk size in sectors
short kind; // IDE_HD, IDE_CDROM, SCSI_HD, etc
short index; // index within specific kind
partition_t partitions[CYGNUM_REDBOOT_MAX_PARTITIONS];
} disk_t;
 
#define DISK_READ(d,s,p,n) ((d)->funs->read)((d),(s),(p),(n))
#define PARTITION_READ(part,s,p,n) \
DISK_READ((part)->disk, (s) + (part)->start_sector, (p), (n))
 
// Kinds of disks
#define DISK_IDE_HD 1
#define DISK_IDE_CDROM 2
#define DISK_FLOPPY 3
 
// DOS partition table as laid out in the MBR
//
struct mbr_partition {
cyg_uint8 boot_ind; // 0x80 == active
cyg_uint8 head;
cyg_uint8 sector;
cyg_uint8 cyl;
cyg_uint8 sys_ind; // partition type
cyg_uint8 end_head;
cyg_uint8 end_sector;
cyg_uint8 end_cyl;
cyg_uint8 start_sect[4]; // starting sector counting from 0
cyg_uint8 nr_sects[4]; // number of sectors in partition
};
 
#define MBR_PTABLE_OFFSET 0x1be
#define MBR_MAGIC_OFFSET 0x1fe
#define MBR_MAGIC 0xaa55
 
// Add a disk to the disk table.
// Return zero if no more room in table.
//
externC int disk_register(disk_t *disk);
 
 
#define diskerr_badname -1
#define diskerr_partition -2
#define diskerr_open -3
#define diskerr_read -4
 
externC int disk_stream_open(connection_info_t *info, int *err);
externC void disk_stream_close(int *err);
externC int disk_stream_read(char *buf, int size, int *err);
externC char *disk_error(int err);
 
#endif // CYGONCE_REDBOOT_DISK_H
/fs/e2fs.h
0,0 → 1,199
//==========================================================================
//
// e2fs.h
//
// Second extended filesystem defines.
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): msalter
// Contributors: msalter
// Date: 2001-06-25
// Purpose:
// Description:
//
// This code is part of RedBoot (tm).
//
//####DESCRIPTIONEND####
//
//==========================================================================
 
#ifndef CYGONCE_REDBOOT_E2FS_H
#define CYGONCE_REDBOOT_E2FS_H
 
//
// Structure of the super block
//
struct e2fs_super_block {
cyg_uint32 inodes_count;
cyg_uint32 blocks_count;
cyg_uint32 r_blocks_count;
cyg_uint32 free_blocks_count;
cyg_uint32 free_inodes_count;
cyg_uint32 first_data_block;
cyg_uint32 log_block_size;
cyg_int32 log_frag_size;
cyg_uint32 blocks_per_group;
cyg_uint32 frags_per_group;
cyg_uint32 inodes_per_group;
cyg_uint32 mtime;
cyg_uint32 wtime;
cyg_uint16 mnt_count;
cyg_int16 max_mnt_count;
cyg_uint16 magic;
cyg_uint16 state;
cyg_uint16 errors;
cyg_uint16 minor_rev_level;
cyg_uint32 lastcheck;
cyg_uint32 checkinterval;
cyg_uint32 creator_os;
cyg_uint32 rev_level;
cyg_uint16 def_resuid;
cyg_uint16 def_resgid;
};
 
#define E2FS_PRE_02B_MAGIC 0xEF51
#define E2FS_SUPER_MAGIC 0xEF53
 
#define E2FS_PTRS_PER_BLOCK(e) ((e)->blocksize / sizeof(cyg_uint32))
 
#define E2FS_BLOCK_SIZE(s) (E2FS_MIN_BLOCK_SIZE << SWAB_LE32((s)->log_block_size))
#define E2FS_ADDR_PER_BLOCK(s) (E2FS_BLOCK_SIZE(s) / sizeof(unsigned int))
#define E2FS_BLOCK_SIZE_BITS(s) (SWAB_LE32((s)->log_block_size) + 10)
 
#define E2FS_NR_DIR_BLOCKS 12
 
#define E2FS_IND_BLOCK E2FS_NR_DIR_BLOCKS
#define E2FS_DIND_BLOCK (E2FS_IND_BLOCK + 1)
#define E2FS_TIND_BLOCK (E2FS_DIND_BLOCK + 1)
 
#define E2FS_N_BLOCKS (E2FS_TIND_BLOCK + 1)
 
 
// Structure of an inode on the disk
//
typedef struct e2fs_inode {
cyg_uint16 mode;
cyg_uint16 uid;
cyg_uint32 size;
cyg_uint32 atime;
cyg_uint32 ctime;
cyg_uint32 mtime;
cyg_uint32 dtime;
cyg_uint16 gid;
cyg_uint16 links_count;
cyg_uint32 blocks;
cyg_uint32 flags;
cyg_uint32 reserved1;
cyg_uint32 block[E2FS_N_BLOCKS];
cyg_uint32 version;
cyg_uint32 file_acl;
cyg_uint32 dir_acl;
cyg_uint32 faddr;
cyg_uint8 frag;
cyg_uint8 fsize;
cyg_uint16 pad1;
cyg_uint32 reserved2[2];
} e2fs_inode_t;
 
 
#define E2FS_INODES_PER_BLOCK(e) ((e)->blocksize / sizeof (struct e2fs_inode))
 
#define E2FS_MIN_BLOCK_SIZE 1024
#define E2FS_MAX_BLOCK_SIZE 4096
 
// Special inode numbers
//
#define E2FS_BAD_INO 1
#define E2FS_ROOT_INO 2
 
typedef struct e2fs_dir_entry {
cyg_uint32 inode;
cyg_uint16 reclen;
cyg_uint8 namelen;
cyg_uint8 filetype;
char name[2];
} e2fs_dir_entry_t;
 
#define E2FS_FTYPE_UNKNOWN 0
#define E2FS_FTYPE_REG_FILE 1
#define E2FS_FTYPE_DIR 2
#define E2FS_FTYPE_CHRDEV 3
#define E2FS_FTYPE_BLKDEV 4
#define E2FS_FTYPE_FIFO 5
#define E2FS_FTYPE_SOCK 6
#define E2FS_FTYPE_SYMLINK 7
 
typedef struct e2fs_group
{
cyg_uint32 block_bitmap; // blocks bitmap block
cyg_uint32 inode_bitmap; // inodes bitmap block
cyg_uint32 inode_table; // inodes table block
cyg_uint16 free_blocks_count;
cyg_uint16 free_inodes_count;
cyg_uint16 used_dirs_count;
cyg_uint16 pad;
cyg_uint32 reserved[3];
} e2fs_group_t;
 
#define E2FS_BLOCKS_PER_GROUP(s) (SWAB_LE32((s)->blocks_per_group))
#define E2FS_INODES_PER_GROUP(s) (SWAB_LE32((s)->inodes_per_group))
 
#define E2FS_GDESC_PER_BLOCK(e) ((e)->blocksize / sizeof (struct e2fs_e2fs_group_desc))
#define E2FS_GDESC_PER_SECTOR (SECTOR_SIZE/sizeof(e2fs_group_t))
#define E2FS_GDESC_CACHE_SIZE (E2FS_GDESC_PER_SECTOR * 1)
#define E2FS_GDESC_PER_SECTOR (SECTOR_SIZE/sizeof(e2fs_group_t))
 
typedef struct e2fs_desc {
partition_t *part; // partition holding this filesystem
cyg_uint32 blocksize; // fs blocksize
cyg_uint32 ngroups; // number of groups in fs
cyg_uint32 blocks_per_group;
cyg_uint32 inodes_per_group;
cyg_uint32 gdesc_block; // block nr of group descriptors
cyg_int32 gdesc_first; // which gdesc is first in cache
e2fs_group_t gdesc_cache[E2FS_GDESC_CACHE_SIZE];
cyg_uint32 nr_ind_blocks;
cyg_uint32 nr_dind_blocks;
cyg_uint32 nr_tind_blocks;
} e2fs_desc_t;
 
#define E2FS_BLOCK_TO_SECTOR(e,b) ((b) * ((e)->blocksize / SECTOR_SIZE))
 
extern fs_funs_t redboot_e2fs_funs;
 
#endif // CYGONCE_REDBOOT_E2FS_H
/fs/ide.h
0,0 → 1,104
//==========================================================================
//
// ide.h
//
// IDE Interface Driver Tables for RedBoot
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): msalter
// Contributors: msalter
// Date: 2001-07-06
// Purpose:
// Description:
//
// This code is part of RedBoot (tm).
//
//####DESCRIPTIONEND####
//
//==========================================================================
 
#ifndef CYGONCE_REDBOOT_IDE_H
#define CYGONCE_REDBOOT_IDE_H
 
// IDE Register Indices
#define IDE_REG_DATA 0
#define IDE_REG_ERROR 1
#define IDE_REG_FEATURES 1
#define IDE_REG_COUNT 2
#define IDE_REG_REASON 2 // ATAPI
#define IDE_REG_LBALOW 3
#define IDE_REG_LBAMID 4
#define IDE_REG_LBAHI 5
#define IDE_REG_DEVICE 6
#define IDE_REG_STATUS 7
#define IDE_REG_COMMAND 7
 
#define IDE_STAT_BSY 0x80
#define IDE_STAT_DRDY 0x40
#define IDE_STAT_SERVICE 0x10
#define IDE_STAT_DRQ 0x08
#define IDE_STAT_CORR 0x04
#define IDE_STAT_ERR 0x01
 
#define IDE_REASON_REL 0x04
#define IDE_REASON_IO 0x02
#define IDE_REASON_COD 0x01
 
//
// Drive ID offsets of interest
//
#define IDE_DEVID_GENCONFIG 0
#define IDE_DEVID_SERNO 20
#define IDE_DEVID_MODEL 54
#define IDE_DEVID_LBA_CAPACITY 120
 
struct ide_priv {
cyg_uint8 controller;
cyg_uint8 drive;
cyg_uint16 flags;
};
 
/* flag values */
#define IDE_DEV_PRESENT 1 // Device is present
#define IDE_DEV_PACKET 2 // Supports packet interface
#define IDE_DEV_ADDR48 3 // Supports 48bit addressing
 
#define CDROM_SECTOR_SIZE 2048
#define SECTORS_PER_CDROM_SECTOR (CDROM_SECTOR_SIZE/SECTOR_SIZE)
 
#endif // CYGONCE_REDBOOT_IDE_H
/elf.h
0,0 → 1,704
#ifndef CYGONCE_REDBOOT_ELF_H
#define CYGONCE_REDBOOT_ELF_H
 
//==========================================================================
//
// elf.h
//
// ELF file format definitions
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): nickg
// Contributors: nickg
// Date: 2000-11-15
// Purpose: Define ELF file format
// Description: The types defined here describe the ELF file format.
//
// Usage: #include <cyg/loader/elf.h>
//
//####DESCRIPTIONEND####
//
//==========================================================================
//
// Quite a lot of this file was taken from the BSD exec_elf.h header file.
// Hence we should show you this...
//
/* $OpenBSD: exec_elf.h,v 1.20 1999/09/19 16:16:49 kstailey Exp $ */
/*
* Copyright (c) 1995, 1996 Erik Theisen. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
//==========================================================================
 
#include <cyg/infra/cyg_type.h>
 
// -------------------------------------------------------------------------
// Basic types:
 
typedef cyg_uint32 Elf32_Addr;
typedef cyg_uint32 Elf32_Off;
typedef cyg_uint16 Elf32_Half;
typedef cyg_uint32 Elf32_Word;
typedef cyg_int32 Elf32_Sword;
 
typedef cyg_uint64 Elf64_Addr;
typedef cyg_uint64 Elf64_Off;
typedef cyg_uint16 Elf64_Half;
typedef cyg_uint32 Elf64_Word;
typedef cyg_int32 Elf64_Sword;
typedef cyg_uint64 Elf64_Xword;
typedef cyg_int64 Elf64_Sxword;
 
// -------------------------------------------------------------------------
// ELF header
 
#define EI_NIDENT 16
 
typedef struct {
unsigned char e_ident[EI_NIDENT];
Elf32_Half e_type;
Elf32_Half e_machine;
Elf32_Word e_version;
Elf32_Addr e_entry;
Elf32_Off e_phoff;
Elf32_Off e_shoff;
Elf32_Word e_flags;
Elf32_Half e_ehsize;
Elf32_Half e_phentsize;
Elf32_Half e_phnum;
Elf32_Half e_shentsize;
Elf32_Half e_shnum;
Elf32_Half e_shtrndx;
} Elf32_Ehdr;
 
typedef struct {
unsigned char e_ident[EI_NIDENT];
Elf64_Half e_type;
Elf64_Half e_machine;
Elf64_Word e_version;
Elf64_Addr e_entry;
Elf64_Off e_phoff;
Elf64_Off e_shoff;
Elf64_Word e_flags;
Elf64_Half e_ehsize;
Elf64_Half e_phentsize;
Elf64_Half e_phnum;
Elf64_Half e_shentsize;
Elf64_Half e_shnum;
Elf64_Half e_shtrndx;
} Elf64_Ehdr;
 
// -------------------------------------------------------------------------
/* e_ident[] identification indexes */
 
#define EI_MAG0 0 /* file ID */
#define EI_MAG1 1 /* file ID */
#define EI_MAG2 2 /* file ID */
#define EI_MAG3 3 /* file ID */
#define EI_CLASS 4 /* file class */
#define EI_DATA 5 /* data encoding */
#define EI_VERSION 6 /* ELF header version */
#define EI_OSABI 7 /* Operating system/ABI identification */
#define EI_ABIVERSION 8 /* ABI version */
#define EI_PAD 9 /* start of pad bytes */
 
// -------------------------------------------------------------------------
/* e_ident[] magic number */
 
#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
#define ELFMAG1 'E' /* e_ident[EI_MAG1] */
#define ELFMAG2 'L' /* e_ident[EI_MAG2] */
#define ELFMAG3 'F' /* e_ident[EI_MAG3] */
#define ELFMAG "\177ELF" /* magic */
#define SELFMAG 4 /* size of magic */
 
// -------------------------------------------------------------------------
/* e_ident[] file class */
 
#define ELFCLASSNONE 0 /* invalid */
#define ELFCLASS32 1 /* 32-bit objs */
#define ELFCLASS64 2 /* 64-bit objs */
#define ELFCLASSNUM 3 /* number of classes */
 
// -------------------------------------------------------------------------
/* e_ident[] data encoding */
 
#define ELFDATANONE 0 /* invalid */
#define ELFDATA2LSB 1 /* Little-Endian */
#define ELFDATA2MSB 2 /* Big-Endian */
#define ELFDATANUM 3 /* number of data encode defines */
 
// -------------------------------------------------------------------------
/* e_ident */
 
#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
(ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
(ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
(ehdr).e_ident[EI_MAG3] == ELFMAG3)
 
// -------------------------------------------------------------------------
/* e_type */
 
#define ET_NONE 0 /* No file type */
#define ET_REL 1 /* relocatable file */
#define ET_EXEC 2 /* executable file */
#define ET_DYN 3 /* shared object file */
#define ET_CORE 4 /* core file */
#define ET_NUM 5 /* number of types */
#define ET_LOOS 0xfe00 /* Operating system-specific */
#define ET_HIOS 0xfeff /* Operating system-specific */
#define ET_LOPROC 0xff00 /* reserved range for processor */
#define ET_HIPROC 0xffff /* specific e_type */
 
// -------------------------------------------------------------------------
/* e_machine */
// The following values taken from 22 June 2000 SysV ABI spec, updated with
// extra values from binutils elf/common.h.
 
#define EM_NONE 0 // No machine
#define EM_M32 1 // AT&T WE 32100
#define EM_SPARC 2 // SPARC
#define EM_386 3 // Intel 80386
#define EM_68K 4 // Motorola 68000
#define EM_88K 5 // Motorola 88000
#define EM_860 7 // Intel 80860
#define EM_MIPS 8 // MIPS I Architecture
#define EM_S370 9 // IBM System/370 Processor
#define EM_MIPS_RS3_LE 10 // MIPS RS3000 Little-endian
#define EM_PARISC 15 // Hewlett-Packard PA-RISC
#define EM_VPP500 17 // Fujitsu VPP500
#define EM_SPARC32PLUS 18 // Enhanced instruction set SPARC
#define EM_960 19 // Intel 80960
#define EM_PPC 20 // PowerPC
#define EM_PPC64 21 // 64-bit PowerPC
#define EM_V800 36 // NEC V800
#define EM_FR20 37 // Fujitsu FR20
#define EM_RH32 38 // TRW RH-32
#define EM_RCE 39 // Motorola RCE
#define EM_ARM 40 // Advanced RISC Machines ARM
#define EM_ALPHA 41 // Digital Alpha
#define EM_SH 42 // Hitachi SH
#define EM_SPARCV9 43 // SPARC Version 9
#define EM_TRICORE 44 // Siemens Tricore embedded processor
#define EM_ARC 45 // Argonaut RISC Core, Argonaut Technologies Inc.
#define EM_H8_300 46 // Hitachi H8/300
#define EM_H8_300H 47 // Hitachi H8/300H
#define EM_H8S 48 // Hitachi H8S
#define EM_H8_500 49 // Hitachi H8/500
#define EM_IA_64 50 // Intel IA-64 processor architecture
#define EM_MIPS_X 51 // Stanford MIPS-X
#define EM_COLDFIRE 52 // Motorola ColdFire
#define EM_68HC12 53 // Motorola M68HC12
#define EM_MMA 54 // Fujitsu MMA Multimedia Accelerator
#define EM_PCP 55 // Siemens PCP
#define EM_NCPU 56 // Sony nCPU embedded RISC processor
#define EM_NDR1 57 // Denso NDR1 microprocessor
#define EM_STARCORE 58 // Motorola Star*Core processor
#define EM_ME16 59 // Toyota ME16 processor
#define EM_ST100 60 // STMicroelectronics ST100 processor
#define EM_TINYJ 61 // Advanced Logic Corp. TinyJ embedded processor family
#define EM_FX66 66 // Siemens FX66 microcontroller
#define EM_ST9PLUS 67 // STMicroelectronics ST9+ 8/16 bit microcontroller
#define EM_ST7 68 // STMicroelectronics ST7 8-bit microcontroller
#define EM_68HC16 69 // Motorola MC68HC16 Microcontroller
#define EM_68HC11 70 // Motorola MC68HC11 Microcontroller
#define EM_68HC08 71 // Motorola MC68HC08 Microcontroller
#define EM_68HC05 72 // Motorola MC68HC05 Microcontroller
#define EM_SVX 73 // Silicon Graphics SVx
#define EM_ST19 74 // STMicroelectronics ST19 8-bit microcontroller
#define EM_VAX 75 // Digital VAX
#define EM_CRIS 76 // Axis Communications 32-bit embedded processor
#define EM_JAVELIN 77 // Infineon Technologies 32-bit embedded processor
#define EM_FIREPATH 78 // Element 14 64-bit DSP Processor
#define EM_ZSP 79 // LSI Logic 16-bit DSP Processor
#define EM_MMIX 80 // Donald Knuth's educational 64-bit processor
#define EM_HUANY 81 // Harvard University machine-independent object files
#define EM_PRISM 82 // SiTera Prism
 
/* Cygnus PowerPC ELF backend. Written in the absence of an ABI. */
#define EM_CYGNUS_POWERPC 0x9025
 
/* Old version of Sparc v9, from before the ABI; this should be
removed shortly. */
#define EM_OLD_SPARCV9 11
 
/* Old version of PowerPC, this should be removed shortly. */
#define EM_PPC_OLD 17
 
/* Cygnus ARC ELF backend. Written in the absence of an ABI. */
#define EM_CYGNUS_ARC 0x9040
 
/* Cygnus M32R ELF backend. Written in the absence of an ABI. */
#define EM_CYGNUS_M32R 0x9041
 
/* Alpha backend magic number. Written in the absence of an ABI. */
//#define EM_ALPHA 0x9026
 
/* D10V backend magic number. Written in the absence of an ABI. */
#define EM_CYGNUS_D10V 0x7650
 
/* D30V backend magic number. Written in the absence of an ABI. */
#define EM_CYGNUS_D30V 0x7676
 
/* V850 backend magic number. Written in the absense of an ABI. */
#define EM_CYGNUS_V850 0x9080
 
/* mn10200 and mn10300 backend magic numbers.
Written in the absense of an ABI. */
#define EM_CYGNUS_MN10200 0xdead
#define EM_CYGNUS_MN10300 0xbeef
 
/* FR30 magic number - no EABI available. */
#define EM_CYGNUS_FR30 0x3330
 
/* AVR magic number
Written in the absense of an ABI. */
#define EM_AVR 0x1057
 
// -------------------------------------------------------------------------
/* Version */
 
#define EV_NONE 0 /* Invalid */
#define EV_CURRENT 1 /* Current */
#define EV_NUM 2 /* number of versions */
 
// -------------------------------------------------------------------------
/* Section Header */
 
typedef struct {
Elf32_Word sh_name; /* name - index into section header
string table section */
Elf32_Word sh_type; /* type */
Elf32_Word sh_flags; /* flags */
Elf32_Addr sh_addr; /* address */
Elf32_Off sh_offset; /* file offset */
Elf32_Word sh_size; /* section size */
Elf32_Word sh_link; /* section header table index link */
Elf32_Word sh_info; /* extra information */
Elf32_Word sh_addralign; /* address alignment */
Elf32_Word sh_entsize; /* section entry size */
} Elf32_Shdr;
 
typedef struct {
Elf64_Word sh_name; /* section name */
Elf64_Word sh_type; /* section type */
Elf64_Xword sh_flags; /* section flags */
Elf64_Addr sh_addr; /* virtual address */
Elf64_Off sh_offset; /* file offset */
Elf64_Xword sh_size; /* section size */
Elf64_Word sh_link; /* link to another */
Elf64_Word sh_info; /* misc info */
Elf64_Xword sh_addralign; /* memory alignment */
Elf64_Xword sh_entsize; /* table entry size */
} Elf64_Shdr;
 
// -------------------------------------------------------------------------
/* Special Section Indexes */
 
#define SHN_UNDEF 0 /* undefined */
#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */
#define SHN_LOPROC 0xff00 /* reserved range for processor */
#define SHN_HIPROC 0xff1f /* specific section indexes */
#define SHN_LOOS 0xff20 /* reserved range for operating */
#define SHN_HIOS 0xff3f /* system specific section indexes */
#define SHN_ABS 0xfff1 /* absolute value */
#define SHN_COMMON 0xfff2 /* common symbol */
#define SHN_XINDEX 0xffff /* escape value for oversize index */
#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */
 
// -------------------------------------------------------------------------
/* sh_type */
 
#define SHT_NULL 0 /* inactive */
#define SHT_PROGBITS 1 /* program defined information */
#define SHT_SYMTAB 2 /* symbol table section */
#define SHT_STRTAB 3 /* string table section */
#define SHT_RELA 4 /* relocation section with addends*/
#define SHT_HASH 5 /* symbol hash table section */
#define SHT_DYNAMIC 6 /* dynamic section */
#define SHT_NOTE 7 /* note section */
#define SHT_NOBITS 8 /* no space section */
#define SHT_REL 9 /* relation section without addends */
#define SHT_SHLIB 10 /* reserved - purpose unknown */
#define SHT_DYNSYM 11 /* dynamic symbol table section */
#define SHT_INIT_ARRAY 14 /* init procedure array */
#define SHT_FINI_ARRAY 15 /* fini procedure array */
#define SHT_PREINIT_ARRAY 16 /* preinit procedure array */
#define SHT_GROUP 17 /* section group */
#define SHT_SYMTAB_SHNDX 18 /* oversize index table */
#define SHT_NUM 19 /* number of section types */
#define SHT_LOOS 0x60000000 /* reserved range for O/S */
#define SHT_HIOS 0x6fffffff /* specific section header types */
#define SHT_LOPROC 0x70000000 /* reserved range for processor */
#define SHT_HIPROC 0x7fffffff /* specific section header types */
#define SHT_LOUSER 0x80000000 /* reserved range for application */
#define SHT_HIUSER 0xffffffff /* specific indexes */
 
// -------------------------------------------------------------------------
/* Section names */
 
#define ELF_BSS ".bss" /* uninitialized data */
#define ELF_DATA ".data" /* initialized data */
#define ELF_DEBUG ".debug" /* debug */
#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */
#define ELF_DYNSTR ".dynstr" /* dynamic string table */
#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */
#define ELF_FINI ".fini" /* termination code */
#define ELF_GOT ".got" /* global offset table */
#define ELF_HASH ".hash" /* symbol hash table */
#define ELF_INIT ".init" /* initialization code */
#define ELF_REL_DATA ".rel.data" /* relocation data */
#define ELF_REL_FINI ".rel.fini" /* relocation termination code */
#define ELF_REL_INIT ".rel.init" /* relocation initialization code */
#define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */
#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */
#define ELF_REL_TEXT ".rel.text" /* relocation code */
#define ELF_RODATA ".rodata" /* read-only data */
#define ELF_SHSTRTAB ".shstrtab" /* section header string table */
#define ELF_STRTAB ".strtab" /* string table */
#define ELF_SYMTAB ".symtab" /* symbol table */
#define ELF_TEXT ".text" /* code */
 
// -------------------------------------------------------------------------
/* Section Attribute Flags - sh_flags */
 
#define SHF_WRITE 0x001 /* Writable */
#define SHF_ALLOC 0x002 /* occupies memory */
#define SHF_EXECINSTR 0x004 /* executable */
#define SHF_MERGE 0x010 /* merge data */
#define SHF_STRINGS 0x020 /* contains strings */
#define SHF_INFO_LINK 0x040 /* link in sh_info field */
#define SHF_LINK_ORDER 0x080 /* preserve link order */
#define SHF_OS_NONCONFORMING 0x100 /* special OS-specific */
/* processing needed */
#define SHF_GROUP 0x200 /* member of group */
#define SHF_MASKOS 0x0ff00000 /* reserved bits for OS */
/* specific section attributes */
#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */
/* specific section attributes */
 
// -------------------------------------------------------------------------
/* Symbol Table Entry */
 
typedef struct {
Elf32_Word st_name; /* name - index into string table */
Elf32_Addr st_value; /* symbol value */
Elf32_Word st_size; /* symbol size */
unsigned char st_info; /* type and binding */
unsigned char st_other; /* visibility */
Elf32_Half st_shndx; /* section header index */
} Elf32_Sym;
 
typedef struct {
Elf64_Word st_name; /* Symbol name index in str table */
unsigned char st_info; /* type / binding attrs */
unsigned char st_other; /* visibility */
Elf64_Half st_shndx; /* section index of symbol */
Elf64_Addr st_value; /* value of symbol */
Elf64_Xword st_size; /* size of symbol */
} Elf64_Sym;
 
// -------------------------------------------------------------------------
/* Symbol table index */
 
#define STN_UNDEF 0 /* undefined */
 
/* Extract symbol info - st_info */
#define ELF32_ST_BIND(x) ((x) >> 4)
#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
#define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
 
#define ELF64_ST_BIND(x) ((x) >> 4)
#define ELF64_ST_TYPE(x) (((unsigned int) x) & 0xf)
#define ELF64_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
 
#define ELF32_ST_VISIBILITY(o) ((o)&0x3)
#define ELF64_ST_VISIBILITY(o) ((o)&0x3)
 
// -------------------------------------------------------------------------
/* Symbol Binding - ELF32_ST_BIND - st_info */
 
#define STB_LOCAL 0 /* Local symbol */
#define STB_GLOBAL 1 /* Global symbol */
#define STB_WEAK 2 /* like global - lower precedence */
#define STB_NUM 3 /* number of symbol bindings */
#define STB_LOOS 10 /* reserved range for OS */
#define STB_HIOS 12 /* specific symbol bindings */
#define STB_LOPROC 13 /* reserved range for processor */
#define STB_HIPROC 15 /* specific symbol bindings */
 
// -------------------------------------------------------------------------
/* Symbol type - ELF32_ST_TYPE - st_info */
 
#define STT_NOTYPE 0 /* not specified */
#define STT_OBJECT 1 /* data object */
#define STT_FUNC 2 /* function */
#define STT_SECTION 3 /* section */
#define STT_FILE 4 /* file */
#define STT_COMMON 5 /* common block */
#define STT_NUM 6 /* number of symbol types */
#define STT_LOOS 10 /* reserved range for OS */
#define STT_HIOS 12 /* specific symbol types */
#define STT_LOPROC 13 /* reserved range for processor */
#define STT_HIPROC 15 /* specific symbol types */
 
// -------------------------------------------------------------------------
// symbol visibility in st_other
 
#define STV_DEFAULT 0 /* default to binding type */
#define STV_INTERNAL 1 /* processor specific */
#define STV_HIDDEN 2 /* invisible */
#define STV_PROTECTED 3 /* non-premptable */
 
// -------------------------------------------------------------------------
// 32 bit relocation records
 
/* Relocation entry with implicit addend */
typedef struct
{
Elf32_Addr r_offset; /* offset of relocation */
Elf32_Word r_info; /* symbol table index and type */
} Elf32_Rel;
 
/* Relocation entry with explicit addend */
typedef struct
{
Elf32_Addr r_offset; /* offset of relocation */
Elf32_Word r_info; /* symbol table index and type */
Elf32_Sword r_addend;
} Elf32_Rela;
 
/* Extract relocation info - r_info */
#define ELF32_R_SYM(i) ((i) >> 8)
#define ELF32_R_TYPE(i) ((unsigned char) (i))
#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))
 
// -------------------------------------------------------------------------
// 64 bit equivalents of above structures and macros.
 
typedef struct {
Elf64_Addr r_offset; /* where to do it */
Elf64_Xword r_info; /* index & type of relocation */
} Elf64_Rel;
 
typedef struct {
Elf64_Addr r_offset; /* where to do it */
Elf64_Xword r_info; /* index & type of relocation */
Elf64_Sxword r_addend; /* adjustment value */
} Elf64_RelA;
 
#define ELF64_R_SYM(info) ((info) >> 32)
#define ELF64_R_TYPE(info) ((info) & 0xFFFFFFFF)
#define ELF64_R_INFO(s,t) (((s) << 32) + (u_int32_t)(t))
 
// -------------------------------------------------------------------------
/* Program Header */
 
typedef struct {
Elf32_Word p_type; /* segment type */
Elf32_Off p_offset; /* segment offset */
Elf32_Addr p_vaddr; /* virtual address of segment */
Elf32_Addr p_paddr; /* physical address - ignored? */
Elf32_Word p_filesz; /* number of bytes in file for seg. */
Elf32_Word p_memsz; /* number of bytes in mem. for seg. */
Elf32_Word p_flags; /* flags */
Elf32_Word p_align; /* memory alignment */
} Elf32_Phdr;
 
typedef struct {
Elf64_Word p_type; /* entry type */
Elf64_Word p_flags; /* flags */
Elf64_Off p_offset; /* offset */
Elf64_Addr p_vaddr; /* virtual address */
Elf64_Addr p_paddr; /* physical address */
Elf64_Xword p_filesz; /* file size */
Elf64_Xword p_memsz; /* memory size */
Elf64_Xword p_align; /* memory & file alignment */
} Elf64_Phdr;
 
// -------------------------------------------------------------------------
/* Segment types - p_type */
 
#define PT_NULL 0 /* unused */
#define PT_LOAD 1 /* loadable segment */
#define PT_DYNAMIC 2 /* dynamic linking section */
#define PT_INTERP 3 /* the RTLD */
#define PT_NOTE 4 /* auxiliary information */
#define PT_SHLIB 5 /* reserved - purpose undefined */
#define PT_PHDR 6 /* program header */
#define PT_NUM 7 /* Number of segment types */
#define PT_LOOS 0x60000000 /* reserved range for OS */
#define PT_HIOS 0x6fffffff /* specific segment types */
#define PT_LOPROC 0x70000000 /* reserved range for processor */
#define PT_HIPROC 0x7fffffff /* specific segment types */
 
// -------------------------------------------------------------------------
/* Segment flags - p_flags */
 
#define PF_X 0x1 /* Executable */
#define PF_W 0x2 /* Writable */
#define PF_R 0x4 /* Readable */
#define PF_MASKOS 0x0ff00000 /* reserved bits for OS */
/* specific segment flags */
#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */
/* specific segment flags */
 
// -------------------------------------------------------------------------
/* Dynamic structure */
 
typedef struct {
Elf32_Sword d_tag; /* controls meaning of d_val */
union {
Elf32_Word d_val; /* Multiple meanings - see d_tag */
Elf32_Addr d_ptr; /* program virtual address */
} d_un;
} Elf32_Dyn;
 
extern Elf32_Dyn _DYNAMIC[]; /* XXX not 64-bit clean */
 
typedef struct {
Elf64_Sxword d_tag; /* controls meaning of d_val */
union {
Elf64_Xword d_val;
Elf64_Addr d_ptr;
} d_un;
} Elf64_Dyn;
 
// -------------------------------------------------------------------------
/* Dynamic Array Tags - d_tag */
 
#define DT_NULL 0 /* marks end of _DYNAMIC array */
#define DT_NEEDED 1 /* string table offset of needed lib */
#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */
#define DT_PLTGOT 3 /* address PLT/GOT */
#define DT_HASH 4 /* address of symbol hash table */
#define DT_STRTAB 5 /* address of string table */
#define DT_SYMTAB 6 /* address of symbol table */
#define DT_RELA 7 /* address of relocation table */
#define DT_RELASZ 8 /* size of relocation table */
#define DT_RELAENT 9 /* size of relocation entry */
#define DT_STRSZ 10 /* size of string table */
#define DT_SYMENT 11 /* size of symbol table entry */
#define DT_INIT 12 /* address of initialization func. */
#define DT_FINI 13 /* address of termination function */
#define DT_SONAME 14 /* string table offset of shared obj */
#define DT_RPATH 15 /* string table offset of library
search path */
#define DT_SYMBOLIC 16 /* start sym search in shared obj. */
#define DT_REL 17 /* address of rel. tbl. w addends */
#define DT_RELSZ 18 /* size of DT_REL relocation table */
#define DT_RELENT 19 /* size of DT_REL relocation entry */
#define DT_PLTREL 20 /* PLT referenced relocation entry */
#define DT_DEBUG 21 /* bugger */
#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */
#define DT_JMPREL 23 /* add. of PLT's relocation entries */
#define DT_BIND_NOW 24 /* Bind now regardless of env setting */
#define DT_INIT_ARRAY 25 /* init array address */
#define DT_FINI_ARRAY 26 /* fini array address */
#define DT_INIT_ARRAYSZ 27 /* init array size */
#define DT_FINI_ARRAYSZ 28 /* fini array size */
#define DT_RUNPATH 29 /* library search path */
#define DT_FLAGS 30 /* flags */
#define DT_ENCODING 32 /* encoding rules start here */
#define DT_PREINIT_ARRAY 32 /* preinit array address */
#define DT_PREINIT_ARRAYSZ 33 /* preinit array size */
#define DT_NUM 26 /* Number used. */
#define DT_LOOS 0x60000000 /* reserved range for OS */
#define DT_HIOS 0x6fffffff /* specific dynamic array tags */
#define DT_LOPROC 0x70000000 /* reserved range for processor */
#define DT_HIPROC 0x7fffffff /* specific dynamic array tags */
 
// -------------------------------------------------------------------------
// Values for DT_FLAGS entry
 
#define DF_ORIGIN 0x1 /* Uses $ORIGIN substitution string */
#define DF_SYMBOLIC 0x2 /* search for symbols here first */
#define DF_TEXTREL 0x4 /* text may be relocatable */
#define DF_BIND_NOW 0x8 /* bind references now, dammit */
 
// -------------------------------------------------------------------------
/* Note Definitions */
 
typedef struct {
Elf32_Word namesz;
Elf32_Word descsz;
Elf32_Word type;
} Elf32_Note;
 
typedef struct {
Elf64_Word namesz;
Elf64_Word descsz;
Elf64_Word type;
} Elf64_Note;
 
// -------------------------------------------------------------------------
// Hash table structure
// The same structure is used by both 32 and 64 bit formats
 
typedef struct {
Elf32_Word nbucket; /* number of buckets */
Elf32_Word nchain; /* number of chains */
 
/* The buckets follow this structure in memory and the chains
follow those. */
} Elf_Hash;
 
// -------------------------------------------------------------------------
#endif // ifndef CYGONCE_REDBOOT_ELF_H
// EOF elf.h

powered by: WebSVN 2.1.0

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