1 #ifndef SYS_DEP_H
2 #define SYS_DEP_H
3 
4 #include <common.h>
5 #include <command.h>
6 #include <net.h>
7 #include <bzlib.h>
8 #include <part.h>
9 
10 typedef long            LONG;
11 typedef unsigned long   ULONG;
12 typedef short           WORD;
13 typedef unsigned short  UWORD;
14 typedef signed char		BYTE;
15 typedef unsigned char   UBYTE;
16 typedef char *          STRPTR;
17 typedef long			BSTR;
18 typedef short           BOOL;
19 typedef void *          APTR;
20 typedef ULONG           CPTR; //For Joerg.
21 #ifndef _SIZE_T
22 #define _SIZE_T
23 typedef unsigned int    size_t;
24 #endif
25 
26 #ifndef TRUE
27 #define TRUE 1
28 #endif
29 
30 #ifndef FALSE
31 #define FALSE 0
32 #endif
33 
34 #define NULL ((void *)0)
35 
36 //The whole bunch of <devices/hardblocks.h>
37 struct RigidDiskBlock {
38     ULONG   rdb_ID;		/* 4 character identifier */
39     ULONG   rdb_SummedLongs;	/* size of this checksummed structure */
40     LONG    rdb_ChkSum;		/* block checksum (longword sum to zero) */
41     ULONG   rdb_HostID;		/* SCSI Target ID of host */
42     ULONG   rdb_BlockBytes;	/* size of disk blocks */
43     ULONG   rdb_Flags;		/* see below for defines */
44     /* block list heads */
45     ULONG   rdb_Obsolete1;	/* No longer used, was optional bad block list */
46     ULONG   rdb_PartitionList;	/* optional first partition block */
47     ULONG   rdb_FileSysHeaderList; /* optional file system header block */
48     ULONG   rdb_DriveInit;	/* optional drive-specific init code */
49 				/* DriveInit(lun,rdb,ior): "C" stk & d0/a0/a1 */
50     ULONG   rdb_BootStrapCode;  /* Secondary bootstrap code. Uses sector type BOOT */
51     ULONG   rdb_Reserved1[5];	/* set to $ffffffff */
52     /* physical drive characteristics */
53     ULONG   rdb_Cylinders;	/* number of drive cylinders */
54     ULONG   rdb_Sectors;	/* sectors per track */
55     ULONG   rdb_Heads;		/* number of drive heads */
56     ULONG   rdb_Interleave;	/* interleave */
57     ULONG   rdb_Park;		/* landing zone cylinder */
58     ULONG   rdb_Reserved2[3];
59     ULONG   rdb_WritePreComp;	/* starting cylinder: write precompensation */
60     ULONG   rdb_ReducedWrite;	/* starting cylinder: reduced write current */
61     ULONG   rdb_StepRate;	/* drive step rate */
62     ULONG   rdb_Reserved3[5];
63     /* logical drive characteristics */
64     ULONG   rdb_RDBBlocksLo;	/* low block of range reserved for hardblocks */
65     ULONG   rdb_RDBBlocksHi;	/* high block of range for these hardblocks */
66     ULONG   rdb_LoCylinder;	/* low cylinder of partitionable disk area */
67     ULONG   rdb_HiCylinder;	/* high cylinder of partitionable data area */
68     ULONG   rdb_CylBlocks;	/* number of blocks available per cylinder */
69     ULONG   rdb_AutoParkSeconds; /* zero for no auto park */
70     ULONG   rdb_HighRDSKBlock;	/* highest block used by RDSK */
71 				/* (not including replacement bad blocks) */
72     ULONG   rdb_Reserved4;
73     /* drive identification */
74     char    rdb_DiskVendor[8];
75     char    rdb_DiskProduct[16];
76     char    rdb_DiskRevision[4];
77     char    rdb_ControllerVendor[8];
78     char    rdb_ControllerProduct[16];
79     char    rdb_ControllerRevision[4];
80     char    rdb_DriveInitName[40]; // jdow: Filename for driveinit source
81 				   // jdow: as a terminated string.
82     char    rdb_BootStrapName[108];// avallino: Filename for bootstrapper source
83 				   // avallino: as a terminated string.
84     ULONG   rdb_Reserved5[37];
85 };
86 
87 #define	IDNAME_RIGIDDISK	0x5244534B	/* 'RDSK' */
88 
89 #define	RDB_LOCATION_LIMIT	16
90 
91 struct PartitionBlock {
92     ULONG   pb_ID;		/* 4 character identifier */
93     ULONG   pb_SummedLongs;	/* size of this checksummed structure */
94     LONG    pb_ChkSum;		/* block checksum (longword sum to zero) */
95     ULONG   pb_HostID;		/* SCSI Target ID of host */
96     ULONG   pb_Next;		/* block number of the next PartitionBlock */
97     ULONG   pb_Flags;		/* see below for defines */
98     ULONG   pb_Reserved1[2];
99     ULONG   pb_DevFlags;	/* preferred flags for OpenDevice */
100     UBYTE   pb_DriveName[32];	/* preferred DOS device name: BSTR form */
101 				/* (not used if this name is in use) */
102     ULONG   pb_Reserved2[15];	/* filler to 32 longwords */
103     ULONG   pb_Environment[20];	/* environment vector for this partition */
104     ULONG   pb_EReserved[12];	/* reserved for future environment vector */
105 };
106 
107 #define	IDNAME_PARTITION	0x50415254	/* 'PART' */
108 
109 #define	PBFB_BOOTABLE	0	/* this partition is intended to be bootable */
110 #define	PBFF_BOOTABLE	1L	/*   (expected directories and files exist) */
111 #define	PBFB_NOMOUNT	1	/* do not mount this partition (e.g. manually */
112 #define	PBFF_NOMOUNT	2L	/*   mounted, but space reserved here) */
113 
114 struct BootstrapCodeBlock {
115     ULONG   bcb_ID;		/* 4 character identifier */
116     ULONG   bcb_SummedLongs;	/* size of this checksummed structure */
117     LONG    bcb_ChkSum;		/* block checksum (longword sum to zero) */
118     ULONG   bcb_HostID;		/* SCSI Target ID of host */
119     ULONG   bcb_Next;		/* block number of the next BootstrapCodeBlock */
120     ULONG   bcb_LoadData[123];	/* binary data of the bootstrapper */
121     /* note [123] assumes 512 byte blocks */
122 };
123 #define	IDNAME_BOOTSTRAPCODE	0x424f4f54 /* 'BOOT' */
124 
125 #define DE_TABLESIZE	0	/* minimum value is 11 (includes NumBuffers) */
126 #define DE_SIZEBLOCK	1	/* in longwords: standard value is 128 */
127 #define DE_SECORG	2	/* not used; must be 0 */
128 #define DE_NUMHEADS	3	/* # of heads (surfaces). drive specific */
129 #define DE_SECSPERBLK	4	/* not used; must be 1 */
130 #define DE_BLKSPERTRACK 5	/* blocks per track. drive specific */
131 #define DE_RESERVEDBLKS 6	/* unavailable blocks at start.	 usually 2 */
132 #define DE_PREFAC	7	/* not used; must be 0 */
133 #define DE_INTERLEAVE	8	/* usually 0 */
134 #define DE_LOWCYL	9	/* starting cylinder. typically 0 */
135 #define DE_UPPERCYL	10	/* max cylinder.  drive specific */
136 #define DE_NUMBUFFERS	11	/* starting # of buffers.  typically 5 */
137 #define DE_MEMBUFTYPE	12	/* type of mem to allocate for buffers. */
138 #define DE_BUFMEMTYPE	12	/* same as above, better name
139 				 * 1 is public, 3 is chip, 5 is fast */
140 #define DE_MAXTRANSFER	13	/* Max number bytes to transfer at a time */
141 #define DE_MASK		14	/* Address Mask to block out certain memory */
142 #define DE_BOOTPRI	15	/* Boot priority for autoboot */
143 #define DE_DOSTYPE	16	/* ASCII (HEX) string showing filesystem type;
144 				 * 0X444F5300 is old filesystem,
145 				 * 0X444F5301 is fast file system */
146 #define DE_BAUD		17	/* Baud rate for serial handler */
147 #define DE_CONTROL	18	/* Control word for handler/filesystem */
148 #define DE_BOOTBLOCKS	19	/* Number of blocks containing boot code */
149 
150 /* Note well: when the second level bootloader is called, no "system calls" are allowed.
151 All system interaction is routed through the sbl_callback_context.
152 */
153 
154 //WARNING: the definition below doesn't work under AOS! So if you need to simulate
155 // an uboot environment, you need to change it radically.
156 
157 #include "slb/our_lists.h"
158 #define MinNode mynode
159 
160 typedef struct uboot_scan_handle
161 {
162   struct MinNode     ush_link;
163   UWORD              ush_bustype;
164   UWORD              ush_already_scanned;
165   block_dev_desc_t   ush_device;
166 } * SCAN_HANDLE;
167 
168 typedef struct old_block_dev_desc {
169 	int           if_type;    /* type of the interface */
170 	int           dev;        /* device number */
171 	unsigned char part_type;  /* partition type */
172 	unsigned char target;			/* target SCSI ID */
173 	unsigned char lun;				/* target LUN */
174 	unsigned char type;				/* device type */
175 	unsigned long lba;        /* number of blocks */
176 	unsigned long blksz;			/* block size */
177 	unsigned char vendor[40]; /* IDE model, SCSI Vendor */
178 	unsigned char product[20];/* IDE Serial no, SCSI product */
179 	unsigned char revision[4];/* firmware revision */
180 	SCAN_HANDLE backpointer;
181 	unsigned char removable;	/* removable device */
182 	unsigned long (*block_read)(int dev,
183 				    unsigned long start,
184 				    unsigned long blkcnt,
185 				    unsigned long *buffer);
186 } old_block_dev_desc_t;
187 
188 typedef struct uboot_old_scan_handle
189 {
190   struct MinNode	ush_link;
191   UWORD			ush_bustype;
192   UWORD			ush_already_scanned;
193   old_block_dev_desc_t	ush_device;
194 } * OLD_SCAN_HANDLE;
195 
196 enum bustype
197   {
198     BUSTYPE_VIA_ATA,
199     BUSTYPE_SCSI,
200     BUSTYPE_USB,
201     BUSTYPE_NET,
202     BUSTYPE_FLOPPY,
203     BUSTYPE_SIL_PARALLEL,
204     BUSTYPE_SIL_SERIAL,
205     BUSTYPE_SIL_4_SERIAL,
206 #ifdef CONFIG_SAM460EX
207     BUSTYPE_SATA2_460,
208 #endif
209     BUSTYPE_NONE
210   };
211 
212 typedef void *			uboot_dev_impl;
213 typedef block_dev_desc_t *	internal_uboot_dev_impl;
214 
215 #define get_lowlevel_handler(scan_handle) (&((scan_handle)->ush_device))
216 
217 struct dev_access_entry
218 {
219   char * dae_identifier;
220   block_dev_desc_t * (*dae_get_dev)(int index);
221   UBYTE dae_request_type;
222   UBYTE dae_max_unitnum;
223   UBYTE dae_bustype;
224   UBYTE dae_padding_1;
225   ULONG dae_padding_2;
226 };
227 
228 //extern dev_access_entry * devices_access_table;
229 extern struct dev_access_entry * find_dae(const char * s);
230 
231 //These two below are used in dae_request_type and 'type', along with the others
232 //defined in the uboot includes.
233 
234 #define DEV_TYPE_NETBOOT   0x81 //Almost a random choice.
235 #define DEV_TYPE_DUMMY_END 0xff
236 
237 #ifndef SECOND_LEVEL_BOOTLOADER
238 extern SCAN_HANDLE start_unit_scan(const void * scan_list, ULONG * const blocksize);
239 extern SCAN_HANDLE next_unit_scan(SCAN_HANDLE h, ULONG * const blocksize);
240 extern BOOL open_specific_unit(const SCAN_HANDLE h);
241 extern void end_unit_scan(SCAN_HANDLE h);
242 extern void end_global_scan(void);
243 extern BOOL loadsector(const ULONG sectn, const ULONG sect_size,
244 	const ULONG numb_sects, void * const dest_buf);
245 
246 extern void * alloc_mem_for_iobuffers(const unsigned long size);
247 extern void * alloc_mem_for_kickmodule(const unsigned long size);
248 extern void * alloc_mem_for_execNG(const unsigned long size);
249 extern void * alloc_mem_for_anythingelse(const unsigned long size);
250 extern void * alloc_mem_for_bootloader(const unsigned long size);
251 //extern void * alloc_mem_for_bootloader_ABS(const unsigned long size, void * addr);
252 // The above function is no longer used.
253 
254 extern void free_mem(void * const loc);
255 extern struct sbl_callback_context * build_callback_context(void *context);
256 extern void degrade_to_old_frigging_interface(struct sbl_callback_context * c);
257 extern int my_NetLoop(char * fn, void * buff);
258 #endif //SECOND_LEVEL_BOOTLOADER
259 
260 //extern void mycopymem(const char * src, char * dest, unsigned long size);
261 
262 //#define printf_to_user printf
263 //#define scanf_from_user scanf
264 
265 #define CALLBACK_VERSION 4
266 
267 struct sbl_callback_context	//This is the context structure passed to the
268 				//second-level bootloader.
269 				//It's essentially a bunch of callbacks and
270 				//some data structures.
271 	{
272 	  ULONG	ssc_version;	//Version of the callback protocol context.
273 	  void (* ssc_printf_like)(const char * fmtstring, ...); //printf() like stuff;
274 	  int (* ssc_getc_like)(void);
275 
276 	  void * ssc_scan_list; //This is the parameter passed to the functions below as 'scan_list'
277 	  struct MinList * ssc_devices_list;
278 	  SCAN_HANDLE ssc_curr_device;
279 
280 	  SCAN_HANDLE (* ssc_start_unit_scan)(const void * scan_list, ULONG * const blocksize);
281 	  SCAN_HANDLE (* ssc_next_unit_scan)(SCAN_HANDLE h, ULONG * const blocksize);
282 	  BOOL (* ssc_open_specific_unit)(const SCAN_HANDLE h);
283 	  void (* ssc_end_unit_scan)(SCAN_HANDLE h);
284 	  void (* ssc_end_global_scan)(void);
285 	  BOOL (* ssc_loadsector)(const ULONG sectn, const ULONG sect_size,
286 				  const ULONG numb_sects, void * const dest_buf);
287 
288 	  int (* ssc_my_netloop)(char * filename, void * dump_here);
289 
290 	  char * (* ssc_getenv)(uchar *);
291 	  void (* ssc_setenv)(char *, char *);
292 
293 	  void * (* ssc_alloc_mem_for_iobuffers)(const size_t size);
294 	  void * (* ssc_alloc_mem_for_kickmodule)(const size_t size);
295 	  void * (* ssc_alloc_mem_for_execNG)(const size_t size);
296 	  void * (* ssc_alloc_mem_for_anythingelse)(const size_t size);
297 	  void * (* ssc_alloc_mem_for_bootloader)(const size_t size);
298 	  void (* ssc_free_mem)(void * const loc);
299 
300 	  void * (* ssc_get_board_info)(void);
301 
302 	int (* ssc_BZ2_bzBuffToBuffDecompress) (
303 		char*         dest,
304 		unsigned int* destLen,
305 		char*         source,
306 		unsigned int  sourceLen,
307 		int           small,
308 		int           verbosity
309 		);
310 
311 	//Video functions (silly EGA style character menus and things.)
312 	void (* ssc_video_clear)(void);
313 	void (* ssc_video_draw_box)(int style, int attr, char *title, int separate, int x, int y, int w, int h);
314 
315 	void (* ssc_video_draw_text)(int x, int y, int attr, char *text, int field);
316 
317 	void (* ssc_video_repeat_char)(int x, int y, int repcnt, int repchar, int attr);
318 
319 	unsigned short (* ssc_set_partial_scroll_limits)(const short start, const short end);
320 	void (* ssc_get_partial_scroll_limits)(short * const start, short * const end);
321 	int (* ssc_video_get_key)(void);
322 
323 	int (* ssc_do_bootm)(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
324 	void * (* ssc_memmove)(void * dest,const void *src,size_t count);
325 	void (* ssc_set_load_addr)(void * const la);
326 
327 	int (* ssc_tstc)(void);
328 	void (* ssc_udelay)(unsigned long);
329 	int (* ssc_sprintf)(char * buf, const char *fmt, ...);
330 
331 	//New to version 4.1 (should be 5....): ext2fs support in uboot.
332 	int (* ssc_ext2fs_set_blk_dev_full)(block_dev_desc_t * const rbdd, disk_partition_t * const p);
333 	int (* ssc_ext2fs_open)(char *filename);
334 	int (* ssc_ext2fs_read)(char *buf, unsigned len);
335 	int (* ssc_ext2fs_mount)(unsigned part_length);
336 	int (* ssc_ext2fs_close)(void);
337 	};
338 
339 
340 #endif
341 
342