]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - include/wince.h
Merge branch 'master' of ../denx-uboot into tx28
[karo-tx-uboot.git] / include / wince.h
1 #ifndef __WINCE_H__
2 #define __WINCE_H__
3
4 #define CE_DOFFSET              (net->align_offset + ETHER_HDR_SIZE + IP_HDR_SIZE)
5
6 /* Bin image parse results */
7
8 #define CE_PR_EOF                               0
9 #define CE_PR_MORE                              1
10 #define CE_PR_ERROR                             2
11
12
13
14
15 #pragma pack(1)
16
17 /* Edbg BOOTME packet structures */
18
19 typedef struct 
20 {
21     unsigned int        id;                     /* Protocol identifier ("EDBG" on the wire)                                             */
22     unsigned char       service;        /* Service identifier                                                                                   */
23     unsigned char       flags;          /* Flags (see defs below)                                                                               */
24     unsigned char       seqNum;         /* For detection of dropped packets                                                             */
25     unsigned char       cmd;            /* For administrative messages                                                                  */
26     unsigned char       data[1];        /* Cmd specific data starts here (format is determined by               */ 
27                                                                 /* Cmd, len is determined by UDP packet size)                                   */
28
29 eth_dbg_hdr;
30
31 #define OFFSETOF(s,m)                                   ((unsigned int)&(((s*)0)->m))
32 #define EDBG_DATA_OFFSET                                (OFFSETOF(eth_dbg_hdr, data))
33
34 typedef struct 
35 {
36     unsigned char       versionMajor;   // Bootloader version
37     unsigned char       versionMinor;   // Bootloader version
38     unsigned char       macAddr[6];             // Ether address of device (net byte order)
39     unsigned int        ipAddr;                 // IP address of device (net byte order)
40     char                        platformId[17]; // Platform Id string (NULL terminated)
41     char                        deviceName[17]; // Device name string (NULL terminated). Should include
42                                                                         // platform and number based on Ether address (e.g. Odo42, CEPCLS2346, etc)
43     unsigned char       cpuId;          // CPU identifier (upper nibble = type)
44                                                                         // The following fields were added in CE 3.0 Platform Builder release
45     unsigned char       bootmeVer;     // BOOTME Version.  Must be in the range 2 -> EDBG_CURRENT_BOOTME_VERSION, or
46                                                                         // remaining fields will be ignored by Eshell and defaults will be used.
47     unsigned int        bootFlags;              // Boot Flags
48     unsigned short      downloadPort;   // Download Port (net byte order) (0 -> EDBG_DOWNLOAD_PORT) 
49     unsigned short      svcPort;                // Service Port (net byte order) (0 -> EDBG_SVC_PORT)
50
51 } edbg_bootme_data;
52
53 // Packet size
54
55 #define BOOTME_PKT_SIZE                                 (EDBG_DATA_OFFSET + sizeof(edbg_bootme_data))
56
57 // WinCE .BIN file format signature
58
59 #define CE_BIN_SIGN                             "B000FF\x0A"
60 #define CE_BIN_SIGN_LEN                 7
61
62
63 typedef struct
64 {
65         unsigned char sign[ CE_BIN_SIGN_LEN ];
66         unsigned int rtiPhysAddr;
67         unsigned int rtiPhysLen;
68 }
69 ce_bin_hdr;
70
71 typedef struct
72 {
73         unsigned int physAddr;
74         unsigned int physLen;
75         unsigned int chkSum;
76         unsigned char data[ 1 ];
77 }
78 ce_bin_entry;
79
80 // CE ROM image structures
81
82 #define ROM_SIGNATURE_OFFSET                    0x40         // Offset from the image's physfirst address to the ROM signature.
83 #define ROM_SIGNATURE                                   0x43454345       // Signature
84 #define ROM_TOC_POINTER_OFFSET                  0x44         // Offset from the image's physfirst address to the TOC pointer.
85 #define ROM_TOC_OFFSET_OFFSET                   0x48         // Offset from the image's physfirst address to the TOC offset (from physfirst).
86
87 typedef struct
88 {
89     unsigned int        dllfirst;               // first DLL address
90     unsigned int        dlllast;                // last DLL address
91     unsigned int        physfirst;              // first physical address
92     unsigned int        physlast;               // highest physical address
93     unsigned int        nummods;                // number of TOCentry's
94     unsigned int        ramStart;                               // start of RAM
95     unsigned int        ramFree;                                // start of RAM free space
96     unsigned int        ramEnd;                                 // end of RAM
97     unsigned int        copyEntries;                    // number of copy section entries
98     unsigned int        copyOffset;                             // offset to copy section
99     unsigned int        profileLen;                             // length of PROFentries RAM 
100     unsigned int        profileOffset;                  // offset to PROFentries
101     unsigned int        numfiles;               // number of FILES
102     unsigned int        kernelFlags;                    // optional kernel flags from ROMFLAGS .bib config option
103     unsigned int        fsRamPercent;                   // Percentage of RAM used for filesystem 
104                                                                                         // from FSRAMPERCENT .bib config option
105                                                                                         // byte 0 = #4K chunks/Mbyte of RAM for filesystem 0-2Mbytes 0-255
106                                                                                         // byte 1 = #4K chunks/Mbyte of RAM for filesystem 2-4Mbytes 0-255
107                                                                                         // byte 2 = #4K chunks/Mbyte of RAM for filesystem 4-6Mbytes 0-255
108                                                                                         // byte 3 = #4K chunks/Mbyte of RAM for filesystem > 6Mbytes 0-255
109
110     unsigned int        drivglobStart;                  // device driver global starting address
111     unsigned int        drivglobLen;                    // device driver global length
112     unsigned short      cpuType;                                // CPU (machine) Type
113     unsigned short      miscFlags;                              // Miscellaneous flags
114     void*                       extensions;                             // pointer to ROM Header extensions
115     unsigned int        trackingStart;                  // tracking memory starting address
116     unsigned int        trackingLen;                    // tracking memory ending address
117
118 ce_rom_hdr;
119
120 // Win32 FILETIME strcuture
121
122 typedef struct
123 {
124     unsigned int        loDateTime;
125     unsigned int        hiDateTime;
126
127 ce_file_time;
128
129 // Table Of Contents entry structure
130
131 typedef struct
132 {   
133     unsigned int        fileAttributes;
134     ce_file_time        fileTime;
135     unsigned int        fileSize;
136     char*                       fileName;
137     unsigned int        e32Offset;            // Offset to E32 structure
138     unsigned int        o32Offset;            // Offset to O32 structure
139     unsigned int        loadOffset;           // MODULE load buffer offset
140
141 ce_toc_entry;
142
143 typedef struct  
144 {                                                                       /* Extra information header block      */
145     unsigned int        rva;            /* Virtual relative address of info    */
146     unsigned int        size;           /* Size of information block           */
147 }
148 e32_info;
149
150 #define ROM_EXTRA       9
151
152 typedef struct
153 {
154     unsigned short  e32_objcnt;     /* Number of memory objects            */
155     unsigned short  e32_imageflags; /* Image flags                         */
156     unsigned int        e32_entryrva;   /* Relative virt. addr. of entry point */
157     unsigned int        e32_vbase;      /* Virtual base address of module      */
158     unsigned short  e32_subsysmajor;/* The subsystem major version number  */
159     unsigned short  e32_subsysminor;/* The subsystem minor version number  */
160     unsigned int        e32_stackmax;   /* Maximum stack size                  */
161     unsigned int        e32_vsize;      /* Virtual size of the entire image    */
162     unsigned int        e32_sect14rva;  /* section 14 rva */
163     unsigned int        e32_sect14size; /* section 14 size */
164     unsigned int        e32_timestamp;  /* Time EXE/DLL was created/modified   */
165     e32_info            e32_unit[ ROM_EXTRA ]; /* Array of extra info units      */
166     unsigned short  e32_subsys;     /* The subsystem type                  */
167
168 e32_rom;
169
170
171
172 // OS config msg 
173
174 #define EDBG_FL_DBGMSG    0x01  // Debug messages
175 #define EDBG_FL_PPSH      0x02  // Text shell
176 #define EDBG_FL_KDBG      0x04  // Kernel debugger
177 #define EDBG_FL_CLEANBOOT 0x08  // Force a clean boot
178
179 typedef struct
180 {
181     unsigned char       flags;           // Flags that will be used to determine what features are
182                                                                    // enabled over ethernet (saved in driver globals by bootloader)
183     unsigned char       kitlTransport;   // Tells KITL which transport to start
184
185     // The following specify addressing info, only valid if the corresponding
186     // flag is set in the Flags field.
187     
188         unsigned int    dbgMsgIPAddr;
189     unsigned short      dbgMsgPort;
190     unsigned int        ppshIPAddr;
191     unsigned short      ppshPort;
192     unsigned int        kdbgIPAddr;
193     unsigned short      kdbgPort;
194     
195 } edbg_os_config_data;
196
197
198
199 // Driver globals structure
200 // Used to pass driver globals info from RedBoot to WinCE core
201
202 #define DRV_GLB_SIGNATURE                               0x424C4744 // "DGLB"
203
204 typedef struct
205 {
206         unsigned int            signature;              // Signature
207         unsigned int            flags;                  // Misc flags
208         unsigned int            ipAddr;                 // IP address of device (net byte order)
209         unsigned int            ipGate;                 // IP address of gateway (net byte order)
210         unsigned int            ipMask;                 // Subnet mask
211         unsigned char           macAddr[6];             // Ether address of device (net byte order)
212         edbg_os_config_data edbgConfig;         // EDBG services info
213 }
214 ce_driver_globals;
215
216
217 #pragma pack()
218
219
220
221 typedef struct
222 {
223         unsigned int rtiPhysAddr;
224         unsigned int rtiPhysLen;
225         unsigned int ePhysAddr;
226         unsigned int ePhysLen;
227         unsigned int eChkSum;
228
229         unsigned int eEntryPoint;
230         unsigned int eRamStart;
231         unsigned int eRamLen;
232         unsigned int eDrvGlb;
233         
234         unsigned char parseState;
235         unsigned int parseChkSum;
236         int parseLen;
237         unsigned char* parsePtr;
238         int secion;
239         
240         int dataLen;
241         unsigned char* data;
242         
243         int binLen;
244         int endOfBin;
245
246         edbg_os_config_data edbgConfig;
247 }
248 ce_bin;
249
250
251
252
253
254
255
256
257 // IPv4 support
258
259 // Socket/connection information
260 struct sockaddr_in {
261     IPaddr_t sin_addr;
262     unsigned short sin_port;
263     unsigned short sin_family;
264     short          sin_len;
265 };
266 #define AF_INET      1
267 #define INADDR_ANY   0
268
269
270
271
272
273
274
275
276
277 typedef struct
278 {
279         int verbose;
280         int link;
281         struct sockaddr_in locAddr;
282         struct sockaddr_in srvAddrSend;
283         struct sockaddr_in srvAddrRecv;
284         int gotJumpingRequest;
285         unsigned char secNum;
286         unsigned short blockNum;
287         int dataLen;
288         int align_offset;
289         int got_packet_4me;
290         unsigned char data[PKTSIZE_ALIGN];
291 }
292 ce_net;
293
294
295 struct timeval {
296         long    tv_sec;         /* seconds */
297         long    tv_usec;        /* and microseconds */
298 };
299
300
301
302 // Default UDP ports used for Ethernet download and EDBG messages.  May be overriden
303 // by device in BOOTME message.
304
305 #define  EDBG_DOWNLOAD_PORT                             980   // For downloading images to bootloader via TFTP
306 #define  EDBG_SVC_PORT                                  981   // Other types of transfers
307
308 // Byte string for Id field (note - must not conflict with valid TFTP
309 // opcodes (0-5), as we share the download port with TFTP)
310
311 #define EDBG_ID                                                 0x47424445 // "EDBG"
312
313 // Defs for reserved values of the Service field
314
315 #define EDBG_SVC_DBGMSG                                 0   // Debug messages
316 #define EDBG_SVC_PPSH                                   1   // Text shell and PPFS file system
317 #define EDBG_SVC_KDBG                                   2   // Kernel debugger
318 #define EDBG_SVC_ADMIN                                  0xFF  // Administrative messages 
319
320 // Commands
321
322 #define EDBG_CMD_READ_REQ                               1       // Read request
323 #define EDBG_CMD_WRITE_REQ                              2       // Write request
324 #define EDBG_CMD_WRITE                                  3       // Host ack
325 #define EDBG_CMD_WRITE_ACK                              4       // Target ack
326 #define EDBG_CMD_ERROR                                  5       // Error
327
328 // Service Ids from 3-FE are used for user apps
329
330 #define NUM_DFLT_EDBG_SERVICES                  3  
331
332 // Size of send and receive windows (except for stop and wait mode)
333
334 #define EDBG_WINDOW_SIZE                                8
335
336 // The window size can be negotiated up to this amount if a client provides
337 // enough memory.
338 #define EDBG_MAX_WINDOW_SIZE                    16
339
340 // Max size for an EDBG frame.  Based on ethernet MTU - protocol overhead.
341 // Limited to one MTU because we don't do IP fragmentation on device.
342
343 #define EDBG_MAX_DATA_SIZE                              1446
344
345 // Defs for Flags field.
346 #define EDBG_FL_FROM_DEV                                0x01   // Set if message is from the device
347 #define EDBG_FL_NACK                                    0x02   // Set if frame is a nack
348 #define EDBG_FL_ACK                                             0x04   // Set if frame is an ack
349 #define EDBG_FL_SYNC                                    0x08   // Can be used to reset sequence # to 0
350 #define EDBG_FL_ADMIN_RESP                              0x10    // For admin messages, indicate whether this is a response
351
352 // Definitions for Cmd field (used for administrative messages)
353 // Msgs from device
354
355 #define EDBG_CMD_BOOTME                                 0   // Initial bootup message from device
356
357 // Msgs from PC
358
359 #define EDBG_CMD_SETDEBUG                               1       // Used to set debug zones on device (TBD)
360 #define EDBG_CMD_JUMPIMG                                2       // Command to tell bootloader to jump to existing
361                                                                                         // flash or RAM image. Data is same as CMD_OS_CONFIG.
362 #define EDBG_CMD_OS_CONFIG                              3       // Configure OS for debug ethernet services
363 #define EDBG_CMD_QUERYINFO                              4       // "Ping" device, and return information (same fmt as bootme)
364 #define EDBG_CMD_RESET                                  5       // Command to have platform perform SW reset (e.g. so it
365                                                                                         // can be reprogrammed).  Support for this command is
366                                                                                         // processor dependant, and may not be implemented
367                                                                                         // on all platforms (requires HW mods for Odo).
368
369 // Msgs from device or PC 
370
371 #define EDBG_CMD_SVC_CONFIG                             6
372 #define EDBG_CMD_SVC_DATA                               7
373
374 #define EDBG_CMD_DEBUGBREAK                             8 // Break into debugger
375
376 // Structures for Data portion of EDBG packets
377
378 #define EDBG_MAX_DEV_NAMELEN                    16
379
380 // BOOTME message - Devices broadcast this message when booted to request configuration
381
382 #define EDBG_CURRENT_BOOTME_VERSION             2
383
384 //
385 // Capability and boot Flags for dwBootFlags in EDBG_BOOTME_DATA
386 // LOWORD for boot flags, HIWORD for capability flags
387 //
388
389 // Always download image
390
391 #define EDBG_BOOTFLAG_FORCE_DOWNLOAD    0x00000001  
392
393 // Support passive-kitl
394
395 #define EDBG_CAPS_PASSIVEKITL           0x00010000  
396
397 // Defs for CPUId
398
399 #define EDBG_CPU_TYPE_SHX                               0x10
400 #define EDBG_CPU_TYPE_MIPS                              0x20
401 #define EDBG_CPU_TYPE_X86                               0x30
402 #define EDBG_CPU_TYPE_ARM                               0x40
403 #define EDBG_CPU_TYPE_PPC                               0x50
404 #define EDBG_CPU_TYPE_THUMB                             0x60
405     
406 #define EDBG_CPU_SH3                                    (EDBG_CPU_TYPE_SHX  | 0)
407 #define EDBG_CPU_SH4                                    (EDBG_CPU_TYPE_SHX  | 1)
408 #define EDBG_CPU_R3000                                  (EDBG_CPU_TYPE_MIPS | 0)
409 #define EDBG_CPU_R4101                                  (EDBG_CPU_TYPE_MIPS | 1)
410 #define EDBG_CPU_R4102                                  (EDBG_CPU_TYPE_MIPS | 2)
411 #define EDBG_CPU_R4111                                  (EDBG_CPU_TYPE_MIPS | 3)
412 #define EDBG_CPU_R4200                                  (EDBG_CPU_TYPE_MIPS | 4)
413 #define EDBG_CPU_R4300                                  (EDBG_CPU_TYPE_MIPS | 5)
414 #define EDBG_CPU_R5230                                  (EDBG_CPU_TYPE_MIPS | 6)
415 #define EDBG_CPU_R5432                                  (EDBG_CPU_TYPE_MIPS | 7)
416 #define EDBG_CPU_i486                                   (EDBG_CPU_TYPE_X86  | 0)
417 #define EDBG_CPU_SA1100                                 (EDBG_CPU_TYPE_ARM | 0)
418 #define EDBG_CPU_ARM720                                 (EDBG_CPU_TYPE_ARM | 1)
419 #define EDBG_CPU_PPC821                                 (EDBG_CPU_TYPE_PPC | 0)
420 #define EDBG_CPU_PPC403                                 (EDBG_CPU_TYPE_PPC | 1)
421 #define EDBG_CPU_THUMB720                               (EDBG_CPU_TYPE_THUMB | 0)
422
423
424
425 #endif
426
427
428 int ce_bin_load(void* image, int imglen);
429 int ce_is_bin_image(void* image, int imglen);
430 void ce_bin_init_parser(void);
431 int ce_bin_parse_next(void* parseBuffer, int len);
432 void ce_init_bin(ce_bin* bin, unsigned char* dataBuffer);
433 int ce_parse_bin(ce_bin* bin);
434 int ce_lookup_ep_bin(ce_bin* bin);
435 void ce_prepare_run_bin(ce_bin* bin);
436 void ce_run_bin(ce_bin* bin);
437
438 int ce_recv_frame(ce_net* net, int timeout);
439 int ce_process_download(ce_net* net, ce_bin* bin);
440 void ce_init_edbg_link(ce_net* net);
441 void ce_process_edbg(ce_net* net, ce_bin* bin);
442
443 int ce_recv_frame(ce_net* net, int timeout);
444 int ce_process_download(ce_net* net, ce_bin* bin);
445 void ce_init_edbg_link(ce_net* net);
446 void ce_process_edbg(ce_net* net, ce_bin* bin);
447 int ce_send_write_ack(ce_net* net);
448 int ce_send_frame(ce_net* net);
449 int ce_recv_packet(char *buf, int len, struct sockaddr_in *from, struct sockaddr_in *local, struct timeval *timeout);
450 void ce_dump_block(unsigned char *ptr, int length);