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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      disk.h
4
//
5
//      Stand-alone disk support for RedBoot
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    msalter
43
// Contributors: msalter
44
// Date:         2001-07-02
45
// Purpose:      
46
// Description:  
47
//              
48
// This code is part of RedBoot (tm).
49
//
50
//####DESCRIPTIONEND####
51
//
52
//==========================================================================
53
 
54
#ifndef CYGONCE_REDBOOT_DISK_H
55
#define CYGONCE_REDBOOT_DISK_H
56
 
57
#define SECTOR_SIZE 512
58
 
59
// Convenience macros to access disk/filesystem info which may
60
// be stored in a fixed endian format.
61
 
62
#define __SWAB16(x) \
63
    ((((x) & 0xFF) << 8) | (((x) >> 8) & 0xFF))
64
 
65
#define __SWAB32(x)         \
66
   ((((x) & 0xff) << 24)   |  \
67
    (((x) & 0xff00) <<  8) |  \
68
    (((x) >> 8) & 0xff00)  |  \
69
    (((x) >> 24) & 0xff))
70
 
71
#if (CYG_BYTEORDER == CYG_MSBFIRST)
72
#define SWAB_LE16(x) __SWAB16(x)
73
#define SWAB_LE32(x) __SWAB32(x)
74
#define SWAB_BE16(x) (x)
75
#define SWAB_BE32(x) (x)
76
#else
77
#define SWAB_LE16(x) (x)
78
#define SWAB_LE32(x) (x)
79
#define SWAB_BE16(x) __SWAB16(x)
80
#define SWAB_BE32(x) __SWAB32(x)
81
#endif
82
 
83
struct partition;
84
 
85
// filesystem interface
86
typedef struct fs_funs {
87
    // Load a file into memory.
88
    void * (*open)(struct partition *p, const char *path);
89
    int    (*read)(void *fp, char *buf, cyg_uint32 nbytes);
90
} fs_funs_t;
91
 
92
struct disk;
93
 
94
typedef struct partition {
95
    struct disk *disk;
96
    fs_funs_t   *funs;
97
    cyg_uint32  start_sector;   // first sector in partition
98
    cyg_uint32  nr_sectors;     // number of sectors in partition
99
    cyg_uint8   systype;        // FAT12, FAT16, Linux, etc.
100
    cyg_uint8   bootflag;       // not really used...
101
} partition_t;
102
 
103
// System types
104
#define SYSTYPE_FAT12        0x01
105
#define SYSTYPE_FAT16_32M    0x04
106
#define SYSTYPE_EXTENDED     0x05
107
#define SYSTYPE_FAT16        0x06
108
#define SYSTYPE_LINUX_SWAP   0x82
109
#define SYSTYPE_LINUX        0x83
110
 
111
typedef struct disk_funs {
112
    int  (*read)(struct disk *d,
113
                 cyg_uint32  start_sector,
114
                 cyg_uint32  *buf,
115
                 cyg_uint8   nr_sectors);
116
} disk_funs_t;
117
 
118
 
119
typedef struct disk {
120
    disk_funs_t *funs;          // Disk driver functions
121
    void        *private;       // Whatever is needed by disk functions
122
    cyg_uint32  nr_sectors;     // Total disk size in sectors
123
    short       kind;           // IDE_HD, IDE_CDROM, SCSI_HD, etc
124
    short       index;          // index within specific kind
125
    partition_t partitions[CYGNUM_REDBOOT_MAX_PARTITIONS];
126
} disk_t;
127
 
128
#define DISK_READ(d,s,p,n) ((d)->funs->read)((d),(s),(p),(n))
129
#define PARTITION_READ(part,s,p,n) \
130
    DISK_READ((part)->disk, (s) + (part)->start_sector, (p), (n))
131
 
132
// Kinds of disks
133
#define DISK_IDE_HD     1
134
#define DISK_IDE_CDROM  2
135
#define DISK_FLOPPY     3
136
 
137
// DOS partition table as laid out in the MBR
138
//
139
struct mbr_partition {
140
    cyg_uint8  boot_ind;        // 0x80 == active
141
    cyg_uint8  head;
142
    cyg_uint8  sector;
143
    cyg_uint8  cyl;
144
    cyg_uint8  sys_ind;         // partition type
145
    cyg_uint8  end_head;
146
    cyg_uint8  end_sector;
147
    cyg_uint8  end_cyl;
148
    cyg_uint8  start_sect[4];   // starting sector counting from 0
149
    cyg_uint8  nr_sects[4];     // number of sectors in partition
150
};
151
 
152
#define MBR_PTABLE_OFFSET 0x1be
153
#define MBR_MAGIC_OFFSET  0x1fe
154
#define MBR_MAGIC         0xaa55
155
 
156
// Add a disk to the disk table.
157
// Return zero if no more room in table.
158
//
159
externC int disk_register(disk_t *disk);
160
 
161
 
162
#define diskerr_badname   -1
163
#define diskerr_partition -2
164
#define diskerr_open      -3
165
#define diskerr_read      -4
166
 
167
externC int   disk_stream_open(connection_info_t *info, int *err);
168
externC void  disk_stream_close(int *err);
169
externC int   disk_stream_read(char *buf, int size, int *err);
170
externC char *disk_error(int err);
171
 
172
#endif // CYGONCE_REDBOOT_DISK_H

powered by: WebSVN 2.1.0

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