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