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 /* Bin image parse results */
28 /* Edbg BOOTME packet structures */
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)
40 #define OFFSETOF(s,m) ((unsigned int)&(((s*)0)->m))
41 #define EDBG_DATA_OFFSET (OFFSETOF(eth_dbg_hdr, data))
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)
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.
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) */
64 #define BOOTME_PKT_SIZE (EDBG_DATA_OFFSET + sizeof(edbg_bootme_data))
66 // WinCE .BIN file format signature
67 #define CE_BIN_SIGN "B000FF\x0A"
68 #define CE_BIN_SIGN_LEN 7
71 unsigned char sign[CE_BIN_SIGN_LEN];
72 unsigned int rtiPhysAddr;
73 unsigned int rtiPhysLen;
77 unsigned int physAddr;
83 // CE ROM image structures
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). */
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
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 */
121 /* Win32 FILETIME strcuture */
123 unsigned int loDateTime;
124 unsigned int hiDateTime;
127 /* Table Of Contents entry structure */
129 unsigned int fileAttributes;
130 ce_file_time fileTime;
131 unsigned int fileSize;
133 unsigned int e32Offset; /* Offset to E32 structure */
134 unsigned int o32Offset; /* Offset to O32 structure */
135 unsigned int loadOffset; /* MODULE load buffer offset */
138 /* Extra information header block */
140 unsigned int rva; /* Virtual relative address of info */
141 unsigned int size; /* Size of information block */
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 */
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 */
170 unsigned char flags; /* Flags that will be used to determine what features are
171 * enabled over ethernet (saved in driver globals by bootloader)
173 unsigned char kitlTransport; /* Tells KITL which transport to start */
175 /* The following specify addressing info, only valid if the corresponding
176 * flag is set in the Flags field.
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;
186 /* Driver globals structure
187 * Used to pass driver globals info from RedBoot to WinCE core
189 #define DRV_GLB_SIGNATURE 0x424C4744 /* "DGLB" */
190 #define STD_DRV_GLB_SIGNATURE 0x53475241 /* "ARGS" */
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 */
206 unsigned long signature;
207 unsigned short oalVersion;
208 unsigned short bspVersion;
211 typedef struct _DEVICE_LOCATION
213 unsigned long IfcType;
214 unsigned long BusNumber;
215 unsigned long LogicalLoc;
223 DEVICE_LOCATION devLoc;
226 unsigned long baudRate;
227 unsigned long dataBits;
228 unsigned long stopBits;
229 unsigned long parity;
232 unsigned short mac[3];
233 unsigned long ipAddress;
234 unsigned long ipMask;
235 unsigned long ipRoute;
242 OAL_ARGS_HEADER header;
243 char deviceId[16]; // Device identification
246 } ce_std_driver_globals;
250 unsigned int rtiPhysLen;
252 unsigned int ePhysLen;
253 unsigned int eChkSum;
257 unsigned int eRamLen;
259 unsigned char parseState;
260 unsigned int parseChkSum;
262 unsigned char *parsePtr;
271 edbg_os_config_data edbgConfig;
276 /* Socket/connection information */
279 unsigned short sin_port;
280 unsigned short sin_family;
303 struct sockaddr_in locAddr;
304 struct sockaddr_in srvAddrSend;
305 struct sockaddr_in srvAddrRecv;
309 int gotJumpingRequest;
312 // int got_packet_4me;
314 enum bootme_state state;
315 unsigned short blockNum;
316 unsigned char seqNum;
319 unsigned char data[PKTSIZE_ALIGN];
326 long tv_sec; /* seconds */
327 long tv_usec; /* and microseconds */
330 /* Default UDP ports used for Ethernet download and EDBG messages. May be overriden
331 * by device in BOOTME message.
333 #define EDBG_DOWNLOAD_PORT 980 /* For downloading images to bootloader via TFTP */
334 #define EDBG_SVC_PORT 981 /* Other types of transfers */
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)
339 #define EDBG_ID 0x47424445 /* "EDBG" */
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 */
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 */
354 /* Service Ids from 3-FE are used for user apps */
355 #define NUM_DFLT_EDBG_SERVICES 3
357 /* Size of send and receive windows (except for stop and wait mode) */
358 #define EDBG_WINDOW_SIZE 8
360 /* The window size can be negotiated up to this amount if a client provides
363 #define EDBG_MAX_WINDOW_SIZE 16
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.
368 #define EDBG_MAX_DATA_SIZE 1446
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 */
377 /* Definitions for Cmd field (used for administrative messages) */
378 /* Msgs from device */
379 #define EDBG_CMD_BOOTME 0 /* Initial bootup message from device */
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).
392 /* Msgs from device or PC */
393 #define EDBG_CMD_SVC_CONFIG 6
394 #define EDBG_CMD_SVC_DATA 7
396 #define EDBG_CMD_DEBUGBREAK 8 /* Break into debugger */
398 /* Structures for Data portion of EDBG packets */
399 #define EDBG_MAX_DEV_NAMELEN 16
401 /* BOOTME message - Devices broadcast this message when booted to request configuration */
402 #define EDBG_CURRENT_BOOTME_VERSION 2
405 * Capability and boot Flags for dwBootFlags in EDBG_BOOTME_DATA
406 * LOWORD for boot flags, HIWORD for capability flags
409 /* Always download image */
410 #define EDBG_BOOTFLAG_FORCE_DOWNLOAD 0x00000001
412 /* Support passive-kitl */
413 #define EDBG_CAPS_PASSIVEKITL 0x00010000
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
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)
440 typedef enum bootme_state bootme_hand_f(const void *pkt, size_t len);
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(IPaddr_t server_ip);
445 int BootMeRequest(IPaddr_t 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);