4 #define CE_DOFFSET (net->align_offset + ETHER_HDR_SIZE + IP_HDR_SIZE)
6 /* Bin image parse results */
17 /* Edbg BOOTME packet structures */
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) */
31 #define OFFSETOF(s,m) ((unsigned int)&(((s*)0)->m))
32 #define EDBG_DATA_OFFSET (OFFSETOF(eth_dbg_hdr, data))
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)
55 #define BOOTME_PKT_SIZE (EDBG_DATA_OFFSET + sizeof(edbg_bootme_data))
57 // WinCE .BIN file format signature
59 #define CE_BIN_SIGN "B000FF\x0A"
60 #define CE_BIN_SIGN_LEN 7
65 unsigned char sign[ CE_BIN_SIGN_LEN ];
66 unsigned int rtiPhysAddr;
67 unsigned int rtiPhysLen;
73 unsigned int physAddr;
76 unsigned char data[ 1 ];
80 // CE ROM image structures
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).
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
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
120 // Win32 FILETIME strcuture
124 unsigned int loDateTime;
125 unsigned int hiDateTime;
129 // Table Of Contents entry structure
133 unsigned int fileAttributes;
134 ce_file_time fileTime;
135 unsigned int fileSize;
137 unsigned int e32Offset; // Offset to E32 structure
138 unsigned int o32Offset; // Offset to O32 structure
139 unsigned int loadOffset; // MODULE load buffer offset
144 { /* Extra information header block */
145 unsigned int rva; /* Virtual relative address of info */
146 unsigned int size; /* Size of information block */
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 */
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
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
185 // The following specify addressing info, only valid if the corresponding
186 // flag is set in the Flags field.
188 unsigned int dbgMsgIPAddr;
189 unsigned short dbgMsgPort;
190 unsigned int ppshIPAddr;
191 unsigned short ppshPort;
192 unsigned int kdbgIPAddr;
193 unsigned short kdbgPort;
195 } edbg_os_config_data;
199 // Driver globals structure
200 // Used to pass driver globals info from RedBoot to WinCE core
202 #define DRV_GLB_SIGNATURE 0x424C4744 // "DGLB"
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
223 unsigned int rtiPhysAddr;
224 unsigned int rtiPhysLen;
225 unsigned int ePhysAddr;
226 unsigned int ePhysLen;
227 unsigned int eChkSum;
229 unsigned int eEntryPoint;
230 unsigned int eRamStart;
231 unsigned int eRamLen;
232 unsigned int eDrvGlb;
234 unsigned char parseState;
235 unsigned int parseChkSum;
237 unsigned char* parsePtr;
246 edbg_os_config_data edbgConfig;
259 // Socket/connection information
262 unsigned short sin_port;
263 unsigned short sin_family;
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;
290 unsigned char data[PKTSIZE_ALIGN];
296 long tv_sec; /* seconds */
297 long tv_usec; /* and microseconds */
302 // Default UDP ports used for Ethernet download and EDBG messages. May be overriden
303 // by device in BOOTME message.
305 #define EDBG_DOWNLOAD_PORT 980 // For downloading images to bootloader via TFTP
306 #define EDBG_SVC_PORT 981 // Other types of transfers
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)
311 #define EDBG_ID 0x47424445 // "EDBG"
313 // Defs for reserved values of the Service field
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
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
328 // Service Ids from 3-FE are used for user apps
330 #define NUM_DFLT_EDBG_SERVICES 3
332 // Size of send and receive windows (except for stop and wait mode)
334 #define EDBG_WINDOW_SIZE 8
336 // The window size can be negotiated up to this amount if a client provides
338 #define EDBG_MAX_WINDOW_SIZE 16
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.
343 #define EDBG_MAX_DATA_SIZE 1446
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
352 // Definitions for Cmd field (used for administrative messages)
355 #define EDBG_CMD_BOOTME 0 // Initial bootup message from device
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).
369 // Msgs from device or PC
371 #define EDBG_CMD_SVC_CONFIG 6
372 #define EDBG_CMD_SVC_DATA 7
374 #define EDBG_CMD_DEBUGBREAK 8 // Break into debugger
376 // Structures for Data portion of EDBG packets
378 #define EDBG_MAX_DEV_NAMELEN 16
380 // BOOTME message - Devices broadcast this message when booted to request configuration
382 #define EDBG_CURRENT_BOOTME_VERSION 2
385 // Capability and boot Flags for dwBootFlags in EDBG_BOOTME_DATA
386 // LOWORD for boot flags, HIWORD for capability flags
389 // Always download image
391 #define EDBG_BOOTFLAG_FORCE_DOWNLOAD 0x00000001
393 // Support passive-kitl
395 #define EDBG_CAPS_PASSIVEKITL 0x00010000
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
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)
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);
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);
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);