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