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