2 * Copyright (C) 2012 Lothar Waßmann <LW@KARO-electronics.de>
4 * See file CREDITS for list of people who contributed to this
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.
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.
21 #define CE_DOFFSET (net->align_offset + ETHER_HDR_SIZE + IP_HDR_SIZE)
23 /* Bin image parse results */
30 /* Edbg BOOTME packet structures */
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)
42 #define OFFSETOF(s,m) ((unsigned int)&(((s*)0)->m))
43 #define EDBG_DATA_OFFSET (OFFSETOF(eth_dbg_hdr, data))
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)
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.
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) */
66 #define BOOTME_PKT_SIZE (EDBG_DATA_OFFSET + sizeof(edbg_bootme_data))
68 // WinCE .BIN file format signature
69 #define CE_BIN_SIGN "B000FF\x0A"
70 #define CE_BIN_SIGN_LEN 7
73 unsigned char sign[CE_BIN_SIGN_LEN];
74 unsigned int rtiPhysAddr;
75 unsigned int rtiPhysLen;
79 unsigned int physAddr;
85 // CE ROM image structures
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). */
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
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 */
123 /* Win32 FILETIME strcuture */
125 unsigned int loDateTime;
126 unsigned int hiDateTime;
129 /* Table Of Contents entry structure */
131 unsigned int fileAttributes;
132 ce_file_time fileTime;
133 unsigned int fileSize;
135 unsigned int e32Offset; /* Offset to E32 structure */
136 unsigned int o32Offset; /* Offset to O32 structure */
137 unsigned int loadOffset; /* MODULE load buffer offset */
140 /* Extra information header block */
142 unsigned int rva; /* Virtual relative address of info */
143 unsigned int size; /* Size of information block */
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 */
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 */
174 unsigned char flags; /* Flags that will be used to determine what features are
175 * enabled over ethernet (saved in driver globals by bootloader)
177 unsigned char kitlTransport; /* Tells KITL which transport to start */
179 /* The following specify addressing info, only valid if the corresponding
180 * flag is set in the Flags field.
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;
190 /* Driver globals structure
191 * Used to pass driver globals info from RedBoot to WinCE core
193 #define DRV_GLB_SIGNATURE 0x424C4744 /* "DGLB" */
194 #define STD_DRV_GLB_SIGNATURE 0x53475241 /* "ARGS" */
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 */
210 unsigned long signature;
211 unsigned short oalVersion;
212 unsigned short bspVersion;
215 typedef struct _DEVICE_LOCATION
217 unsigned long IfcType;
218 unsigned long BusNumber;
219 unsigned long LogicalLoc;
227 DEVICE_LOCATION devLoc;
230 unsigned long baudRate;
231 unsigned long dataBits;
232 unsigned long stopBits;
233 unsigned long parity;
236 unsigned short mac[3];
237 unsigned long ipAddress;
238 unsigned long ipMask;
239 unsigned long ipRoute;
246 OAL_ARGS_HEADER header;
247 char deviceId[16]; // Device identification
250 } ce_std_driver_globals;
256 unsigned int rtiPhysLen;
258 unsigned int ePhysLen;
259 unsigned int eChkSum;
263 unsigned int eRamLen;
264 ce_driver_globals *eDrvGlb;
266 unsigned char parseState;
267 unsigned int parseChkSum;
269 unsigned char *parsePtr;
278 edbg_os_config_data edbgConfig;
279 } __attribute__((packed)) ce_bin;
283 /* Socket/connection information */
286 unsigned short sin_port;
287 unsigned short sin_family;
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;
309 unsigned char data[PKTSIZE_ALIGN];
313 long tv_sec; /* seconds */
314 long tv_usec; /* and microseconds */
317 /* Default UDP ports used for Ethernet download and EDBG messages. May be overriden
318 * by device in BOOTME message.
320 #define EDBG_DOWNLOAD_PORT 980 /* For downloading images to bootloader via TFTP */
321 #define EDBG_SVC_PORT 981 /* Other types of transfers */
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)
326 #define EDBG_ID 0x47424445 /* "EDBG" */
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 */
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 */
341 /* Service Ids from 3-FE are used for user apps */
342 #define NUM_DFLT_EDBG_SERVICES 3
344 /* Size of send and receive windows (except for stop and wait mode) */
345 #define EDBG_WINDOW_SIZE 8
347 /* The window size can be negotiated up to this amount if a client provides
350 #define EDBG_MAX_WINDOW_SIZE 16
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.
355 #define EDBG_MAX_DATA_SIZE 1446
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 */
364 /* Definitions for Cmd field (used for administrative messages) */
365 /* Msgs from device */
366 #define EDBG_CMD_BOOTME 0 /* Initial bootup message from device */
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).
379 /* Msgs from device or PC */
380 #define EDBG_CMD_SVC_CONFIG 6
381 #define EDBG_CMD_SVC_DATA 7
383 #define EDBG_CMD_DEBUGBREAK 8 /* Break into debugger */
385 /* Structures for Data portion of EDBG packets */
386 #define EDBG_MAX_DEV_NAMELEN 16
388 /* BOOTME message - Devices broadcast this message when booted to request configuration */
389 #define EDBG_CURRENT_BOOTME_VERSION 2
392 * Capability and boot Flags for dwBootFlags in EDBG_BOOTME_DATA
393 * LOWORD for boot flags, HIWORD for capability flags
396 /* Always download image */
397 #define EDBG_BOOTFLAG_FORCE_DOWNLOAD 0x00000001
399 /* Support passive-kitl */
400 #define EDBG_CAPS_PASSIVEKITL 0x00010000
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
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)