2 * Copyright (C) 2012 Lothar Waßmann <LW@KARO-electronics.de>
3 * based on: code from RedBoot (C) Uwe Steinkohl <US@KARO-electronics.de>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 #include <asm/errno.h>
31 #include <jffs2/load_kernel.h>
33 DECLARE_GLOBAL_DATA_PTR;
35 #define WINCE_VRAM_BASE 0x80000000
36 #define CE_FIX_ADDRESS(a) ((void *)((a) - WINCE_VRAM_BASE + CONFIG_SYS_SDRAM_BASE))
39 #define INT_MAX ((int)(~0U >> 1))
42 /* Bin image parse states */
43 #define CE_PS_RTI_ADDR 0
44 #define CE_PS_RTI_LEN 1
45 #define CE_PS_E_ADDR 2
47 #define CE_PS_E_CHKSUM 4
48 #define CE_PS_E_DATA 5
50 #define CE_MIN(a, b) (((a) < (b)) ? (a) : (b))
51 #define CE_MAX(a, b) (((a) > (b)) ? (a) : (b))
53 static ce_bin __attribute__ ((aligned (32))) g_bin;
54 static ce_net __attribute__ ((aligned (32))) g_net;
55 static struct in_addr server_ip;
57 static void ce_init_bin(ce_bin *bin, unsigned char *dataBuffer)
59 memset(bin, 0, sizeof(*bin));
61 bin->data = dataBuffer;
62 bin->parseState = CE_PS_RTI_ADDR;
63 bin->parsePtr = (unsigned char *)bin;
66 static int ce_is_bin_image(void *image, int imglen)
68 if (imglen < CE_BIN_SIGN_LEN) {
72 return memcmp(image, CE_BIN_SIGN, CE_BIN_SIGN_LEN) == 0;
75 static const struct ce_magic {
78 ce_std_driver_globals drv_glb;
79 } ce_magic_template = {
81 .size = sizeof(ce_std_driver_globals),
84 .signature = STD_DRV_GLB_SIGNATURE,
92 static void __attribute__((unused)) ce_dump_block(void *ptr, int length)
98 for (i = 0; i < length; i++) {
100 printf("\n%p: ", ptr + i);
103 printf("%02x ", p[i]);
104 if (!((i + 1) % 16)){
106 for (j = i - 15; j <= i; j++){
107 if((p[j] > 0x1f) && (p[j] < 0x7f)) {
118 static inline void ce_dump_block(void *ptr, int length)
123 static void ce_setup_std_drv_globals(ce_std_driver_globals *std_drv_glb)
125 char *mtdparts = getenv("mtdparts");
126 size_t max_len = ALIGN((unsigned long)std_drv_glb, SZ_4K) -
127 (unsigned long)&std_drv_glb->mtdparts;
130 memcpy(&std_drv_glb->kitl.mac, eth_get_dev()->enetaddr,
131 sizeof(std_drv_glb->kitl.mac));
133 snprintf(std_drv_glb->deviceId, sizeof(std_drv_glb->deviceId),
134 "Triton%02X", eth_get_dev()->enetaddr[5]);
136 net_copy_ip(&std_drv_glb->kitl.ipAddress, &net_ip);
137 std_drv_glb->kitl.ipMask = getenv_ip("netmask");
138 std_drv_glb->kitl.ipRoute = getenv_ip("gatewayip");
141 strncpy(std_drv_glb->mtdparts, mtdparts, max_len);
142 std_drv_glb->mtdparts[max_len - 1] = '\0';
144 printf("Failed to get mtdparts environment variable\n");
148 static void ce_init_drv_globals(void)
150 struct ce_magic *ce_magic = (void *)CONFIG_SYS_SDRAM_BASE + 0x160;
151 ce_std_driver_globals *std_drv_glb = &ce_magic->drv_glb;
153 debug("Copying CE MAGIC from %p to %p..%p\n",
154 &ce_magic_template, ce_magic,
155 (void *)ce_magic + sizeof(*ce_magic) - 1);
156 memcpy(ce_magic, &ce_magic_template, sizeof(*ce_magic));
158 ce_setup_std_drv_globals(std_drv_glb);
159 ce_magic->size = sizeof(*std_drv_glb) +
160 strlen(std_drv_glb->mtdparts) + 1;
161 ce_dump_block(ce_magic, offsetof(struct ce_magic, drv_glb) +
165 static void ce_prepare_run_bin(ce_bin *bin)
167 /* Clear os RAM area (if needed) */
168 if (bin->edbgConfig.flags & EDBG_FL_CLEANBOOT) {
169 debug("cleaning memory from %p to %p\n",
170 bin->eRamStart, bin->eRamStart + bin->eRamLen);
172 printf("Preparing clean boot ... ");
173 memset(bin->eRamStart, 0, bin->eRamLen);
177 ce_init_drv_globals();
180 * Make sure, all the above makes it into SDRAM because
181 * WinCE switches the cache & MMU off, obviously without
187 static int ce_lookup_ep_bin(ce_bin *bin)
190 ce_toc_entry *tentry;
193 uint32_t *sig = (uint32_t *)(bin->rtiPhysAddr + ROM_SIGNATURE_OFFSET);
195 debug("Looking for TOC signature at %p\n", sig);
197 /* Check image Table Of Contents (TOC) signature */
198 if (*sig != ROM_SIGNATURE) {
199 printf("Error: Did not find image TOC signature!\n");
200 printf("Expected %08x at address %p; found %08x instead\n",
201 ROM_SIGNATURE, sig, *sig);
205 /* Lookup entry point */
206 header = CE_FIX_ADDRESS(*(unsigned int *)(bin->rtiPhysAddr +
207 ROM_SIGNATURE_OFFSET +
208 sizeof(unsigned int)));
209 tentry = (ce_toc_entry *)(header + 1);
211 for (i = 0; i < header->nummods; i++) {
212 // Look for 'nk.exe' module
213 if (strcmp(CE_FIX_ADDRESS(tentry[i].fileName), "nk.exe") == 0) {
214 // Save entry point and RAM addresses
216 e32 = CE_FIX_ADDRESS(tentry[i].e32Offset);
218 bin->eEntryPoint = CE_FIX_ADDRESS(tentry[i].loadOffset) +
220 bin->eRamStart = CE_FIX_ADDRESS(header->ramStart);
221 bin->eRamLen = header->ramEnd - header->ramStart;
226 // Error: Did not find 'nk.exe' module
230 static int ce_parse_bin(ce_bin *bin)
232 unsigned char *pbData = bin->data;
233 int len = bin->dataLen;
236 debug("starting ce image parsing:\n\tbin->binLen: 0x%08X\n", bin->binLen);
239 if (bin->binLen == 0) {
240 // Check for the .BIN signature first
241 if (!ce_is_bin_image(pbData, len)) {
242 printf("Error: Invalid or corrupted .BIN image!\n");
246 printf("Loading Windows CE .BIN image ...\n");
248 len -= CE_BIN_SIGN_LEN;
249 pbData += CE_BIN_SIGN_LEN;
253 switch (bin->parseState) {
259 copyLen = CE_MIN(sizeof(unsigned int) - bin->parseLen, len);
260 memcpy(&bin->parsePtr[bin->parseLen], pbData, copyLen);
262 bin->parseLen += copyLen;
266 if (bin->parseLen == sizeof(unsigned int)) {
267 if (bin->parseState == CE_PS_RTI_ADDR)
268 bin->rtiPhysAddr = CE_FIX_ADDRESS(bin->rtiPhysAddr);
269 else if (bin->parseState == CE_PS_E_ADDR &&
271 bin->ePhysAddr = CE_FIX_ADDRESS(bin->ePhysAddr);
275 bin->parsePtr += sizeof(unsigned int);
277 if (bin->parseState == CE_PS_E_DATA) {
278 if (bin->ePhysAddr) {
279 bin->parsePtr = bin->ePhysAddr;
280 bin->parseChkSum = 0;
291 debug("ePhysAddr=%p physlen=%08x parselen=%08x\n",
292 bin->ePhysAddr, bin->ePhysLen, bin->parseLen);
293 if (bin->ePhysAddr) {
294 copyLen = CE_MIN(bin->ePhysLen - bin->parseLen, len);
295 bin->parseLen += copyLen;
299 bin->parseChkSum += *pbData;
300 *bin->parsePtr++ = *pbData++;
303 if (bin->parseLen == bin->ePhysLen) {
304 printf("Section [%02d]: address %p, size 0x%08X, checksum %s\n",
308 (bin->eChkSum == bin->parseChkSum) ? "ok" : "fail");
310 if (bin->eChkSum != bin->parseChkSum) {
311 printf("Error: Checksum error, corrupted .BIN file!\n");
312 printf("checksum calculated: 0x%08x from file: 0x%08x\n",
313 bin->parseChkSum, bin->eChkSum);
319 bin->parseState = CE_PS_E_ADDR;
321 bin->parsePtr = (unsigned char *)&bin->ePhysAddr;
334 if (!ce_lookup_ep_bin(bin)) {
335 printf("Error: entry point not found!\n");
340 printf("Entry point: %p, address range: %p-%p\n",
343 bin->rtiPhysAddr + bin->rtiPhysLen);
349 bin->binLen += bin->dataLen;
353 static int ce_bin_load(void *image, int imglen)
355 ce_init_bin(&g_bin, image);
356 g_bin.dataLen = imglen;
357 if (ce_parse_bin(&g_bin) == CE_PR_EOF) {
358 ce_prepare_run_bin(&g_bin);
365 static void ce_run_bin(void (*entry)(void))
367 printf("Launching Windows CE ...\n");
374 static int do_bootce(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
380 if (strcmp(argv[1], "-i") == 0) {
381 ce_init_drv_globals();
382 return CMD_RET_SUCCESS;
384 addr = (void *)simple_strtoul(argv[1], NULL, 16);
385 image_size = INT_MAX; /* actually we do not know the image size */
386 } else if (getenv("fileaddr") != NULL) {
387 addr = (void *)getenv_ulong("fileaddr", 16, 0);
388 image_size = getenv_ulong("filesize", 16, INT_MAX);
390 return CMD_RET_USAGE;
393 printf ("## Booting Windows CE Image from address %p ...\n", addr);
395 /* check if there is a valid windows CE image */
396 if (ce_is_bin_image(addr, image_size)) {
397 if (!ce_bin_load(addr, image_size)) {
398 /* Ops! Corrupted .BIN image! */
399 /* Handle error here ... */
400 printf("corrupted .BIN image !!!\n");
401 return CMD_RET_FAILURE;
403 if (getenv_yesno("autostart") != 1) {
405 * just use bootce to load the image to SDRAM;
406 * Do not start it automatically.
408 setenv_addr("fileaddr", g_bin.eEntryPoint);
409 return CMD_RET_SUCCESS;
411 ce_run_bin(g_bin.eEntryPoint); /* start the image */
413 printf("Image does not seem to be a valid Windows CE image!\n");
414 return CMD_RET_FAILURE;
416 return CMD_RET_FAILURE; /* never reached - just to keep compiler happy */
419 bootce, 2, 0, do_bootce,
420 "Boot a Windows CE image from RAM",
422 "\taddr\t\tboot image from address addr (default ${fileaddr})\n"
424 "\t-i\t\tinitialize the WinCE globals data structure (before loading a .nb0 image)"
427 #ifdef CONFIG_CMD_NAND
428 static int ce_nand_load(ce_bin *bin, loff_t *offset, void *buf, size_t max_len)
431 size_t len = max_len;
432 nand_info_t *nand = &nand_info[0];
434 while (nand_block_isbad(nand, *offset & ~(max_len - 1))) {
435 printf("Skipping bad block 0x%08llx\n",
436 *offset & ~(max_len - 1));
438 if (*offset + max_len > nand->size)
442 ret = nand_read(nand, *offset, &len, buf);
450 static int do_nbootce(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
453 struct mtd_device *dev;
454 struct part_info *part_info;
459 size_t bufsize = nand_info[0].erasesize, len;
461 if (argc < 2 || argc > 3)
462 return CMD_RET_USAGE;
464 ret = mtdparts_init();
466 return CMD_RET_FAILURE;
468 offset = simple_strtoul(argv[1], &end, 16);
470 ret = find_dev_and_part(argv[1], &dev, &part_num,
473 printf("Partition '%s' not found\n", argv[1]);
474 return CMD_RET_FAILURE;
476 offset = part_info->offset;
477 printf ("## Booting Windows CE Image from NAND partition %s at offset %08llx\n",
480 printf ("## Booting Windows CE Image from NAND offset %08llx\n",
484 buffer = malloc(bufsize);
485 if (buffer == NULL) {
486 printf("Failed to allocate %u byte buffer\n", bufsize);
487 return CMD_RET_FAILURE;
490 ce_init_bin(&g_bin, buffer);
492 ret = ce_nand_load(&g_bin, &offset, buffer, bufsize);
494 printf("Failed to read NAND: %d\n", ret);
498 /* check if there is a valid windows CE image header */
499 if (ce_is_bin_image(buffer, len)) {
501 ret = ce_parse_bin(&g_bin);
506 printf("NBOOTCE - canceled by user\n");
510 len = ce_nand_load(&g_bin, &offset, buffer,
513 printf("Nand read error: %d\n", len);
521 ce_prepare_run_bin(&g_bin);
527 } while (ret == CE_PR_MORE);
529 if (ret != CE_PR_EOF)
530 return CMD_RET_FAILURE;
532 if (getenv_yesno("autostart") != 1) {
534 * just use bootce to load the image to SDRAM;
535 * Do not start it automatically.
537 setenv_addr("fileaddr", g_bin.eEntryPoint);
538 return CMD_RET_SUCCESS;
540 ce_run_bin(g_bin.eEntryPoint); /* start the image */
542 printf("Image does not seem to be a valid Windows CE image!\n");
546 return CMD_RET_FAILURE;
549 nbootce, 2, 0, do_nbootce,
550 "Boot a Windows CE image from NAND",
552 "\toff\t\t- flash offset (hex)\n"
553 "\tpartition\t- partition name"
557 static int ce_send_write_ack(ce_net *net)
560 unsigned short wdata[2];
563 wdata[0] = htons(EDBG_CMD_WRITE_ACK);
564 wdata[1] = htons(net->blockNum);
565 net->dataLen = sizeof(wdata);
566 memcpy(net->data, wdata, net->dataLen);
569 ret = bootme_send_frame(net->data, net->dataLen);
571 printf("Failed to send write ack %d; retries=%d\n",
574 } while (ret != 0 && retries-- > 0);
578 static enum bootme_state ce_process_download(ce_net *net, ce_bin *bin)
580 int ret = net->state;
582 if (net->dataLen >= 4) {
583 unsigned short command;
584 unsigned short blknum;
586 memcpy(&command, net->data, sizeof(command));
587 command = ntohs(command);
588 debug("command found: 0x%04X\n", command);
590 if (net->state == BOOTME_DOWNLOAD) {
591 unsigned short nxt = net->blockNum + 1;
593 memcpy(&blknum, &net->data[2], sizeof(blknum));
594 blknum = ntohs(blknum);
596 net->blockNum = blknum;
598 int rc = ce_send_write_ack(net);
601 printf("Dropping out of sequence packet with ID %d (expected %d)\n",
611 case EDBG_CMD_WRITE_REQ:
612 if (net->state == BOOTME_INIT) {
613 // Check file name for WRITE request
614 // CE EShell uses "boot.bin" file name
615 if (strncmp((char *)&net->data[2],
616 "boot.bin", 8) == 0) {
619 printf("Locked Down download link, IP: %pI4\n",
621 printf("Sending BOOTME request [%d] to %pI4\n",
622 net->seqNum, &net_server_ip);
625 // Lock down EShell download link
626 ret = BOOTME_DOWNLOAD;
629 printf("Unknown link\n");
632 if (ret == BOOTME_DOWNLOAD) {
633 int rc = ce_send_write_ack(net);
642 bin->data = &net->data[4];
643 bin->dataLen = net->dataLen - 4;
644 ret = ce_parse_bin(bin);
645 if (ret != CE_PR_ERROR) {
646 int rc = ce_send_write_ack(net);
649 if (ret == CE_PR_EOF)
656 case EDBG_CMD_READ_REQ:
657 printf("Ignoring EDBG_CMD_READ_REQ\n");
658 /* Read requests are not supported
664 printf("Error: unknown error on the host side\n");
671 printf("unknown command 0x%04X\n", command);
672 net->state = BOOTME_ERROR;
678 static enum bootme_state ce_process_edbg(ce_net *net, ce_bin *bin)
680 enum bootme_state ret = net->state;
683 if (net->dataLen < sizeof(header)) {
685 printf("Invalid packet size %u\n", net->dataLen);
689 memcpy(&header, net->data, sizeof(header));
690 if (header.id != EDBG_ID) {
692 printf("Bad EDBG ID %08x\n", header.id);
697 if (header.service != EDBG_SVC_ADMIN) {
698 /* Unknown service */
699 printf("Bad EDBG service %02x\n", header.service);
704 if (net->state == BOOTME_INIT) {
705 /* Some diag output */
707 printf("Locked Down EDBG service link, IP: %pI4\n",
711 /* Lock down EDBG link */
712 net->state = BOOTME_DEBUG;
715 switch (header.cmd) {
716 case EDBG_CMD_JUMPIMG:
717 net->gotJumpingRequest = 1;
720 printf("Received JUMPING command\n");
722 /* Just pass through and copy CONFIG structure */
724 case EDBG_CMD_OS_CONFIG:
725 /* Copy config structure */
726 memcpy(&bin->edbgConfig, &net->data[sizeof(header)],
727 sizeof(edbg_os_config_data));
729 printf("Received CONFIG command\n");
730 if (bin->edbgConfig.flags & EDBG_FL_DBGMSG) {
731 printf("--> Enabling DBGMSG service, IP: %pI4, port: %d\n",
732 &bin->edbgConfig.dbgMsgIPAddr,
733 ntohs(bin->edbgConfig.dbgMsgPort));
736 if (bin->edbgConfig.flags & EDBG_FL_PPSH) {
737 printf("--> Enabling PPSH service, IP: %pI4, port: %d\n",
738 &bin->edbgConfig.ppshIPAddr,
739 ntohs(bin->edbgConfig.ppshPort));
742 if (bin->edbgConfig.flags & EDBG_FL_KDBG) {
743 printf("--> Enabling KDBG service, IP: %pI4, port: %d\n",
744 &bin->edbgConfig.kdbgIPAddr,
745 ntohs(bin->edbgConfig.kdbgPort));
748 if (bin->edbgConfig.flags & EDBG_FL_CLEANBOOT) {
749 printf("--> Force clean boot\n");
756 printf("Received unknown command: %08X\n", header.cmd);
761 /* Respond with ack */
762 header.flags = EDBG_FL_FROM_DEV | EDBG_FL_ACK;
763 memcpy(net->data, &header, sizeof(header));
764 net->dataLen = EDBG_DATA_OFFSET;
769 rc = bootme_send_frame(net->data, net->dataLen);
771 printf("Failed to send ACK: %d\n", rc);
773 } while (rc && retries-- > 0);
777 static enum bootme_state ce_edbg_handler(const void *buf, size_t len)
782 g_net.data = (void *)buf;
785 return ce_process_edbg(&g_net, &g_bin);
788 static void ce_init_edbg_link(ce_net *net)
790 /* Initialize EDBG link for commands */
791 net->state = BOOTME_INIT;
794 static enum bootme_state ce_download_handler(const void *buf, size_t len)
796 g_net.data = (void *)buf;
799 g_net.state = ce_process_download(&g_net, &g_bin);
803 static int ce_send_bootme(ce_net *net)
806 edbg_bootme_data *data;
807 unsigned char txbuf[PKTSIZE_ALIGN];
812 /* Fill out BOOTME packet */
815 memset(net->data, 0, PKTSIZE);
816 header = (eth_dbg_hdr *)net->data;
817 data = (edbg_bootme_data *)header->data;
819 header->id = EDBG_ID;
820 header->service = EDBG_SVC_ADMIN;
821 header->flags = EDBG_FL_FROM_DEV;
822 header->seqNum = net->seqNum++;
823 header->cmd = EDBG_CMD_BOOTME;
825 data->versionMajor = 0;
826 data->versionMinor = 0;
827 data->cpuId = EDBG_CPU_TYPE_ARM;
828 data->bootmeVer = EDBG_CURRENT_BOOTME_VERSION;
830 data->downloadPort = 0;
833 /* MAC address from environment*/
834 if (!eth_getenv_enetaddr("ethaddr", data->macAddr)) {
835 printf("'ethaddr' is not set or invalid\n");
836 memset(data->macAddr, 0, sizeof(data->macAddr));
839 /* IP address from active config */
840 net_copy_ip(&data->ipAddr, &net_ip);
842 // Device name string (NULL terminated). Should include
843 // platform and number based on Ether address (e.g. Odo42, CEPCLS2346, etc)
845 // We will use lower MAC address segment to create device name
846 // eg. MAC '00-0C-C6-69-09-05', device name 'Triton05'
848 strncpy(data->platformId, "Triton", sizeof(data->platformId));
849 snprintf(data->deviceName, sizeof(data->deviceName), "%s%02X",
850 data->platformId, data->macAddr[5]);
853 printf("header->id: %08X\n", header->id);
854 printf("header->service: %08X\n", header->service);
855 printf("header->flags: %08X\n", header->flags);
856 printf("header->seqNum: %08X\n", header->seqNum);
857 printf("header->cmd: %08X\n\n", header->cmd);
859 printf("data->versionMajor: %08X\n", data->versionMajor);
860 printf("data->versionMinor: %08X\n", data->versionMinor);
861 printf("data->cpuId: %08X\n", data->cpuId);
862 printf("data->bootmeVer: %08X\n", data->bootmeVer);
863 printf("data->bootFlags: %08X\n", data->bootFlags);
864 printf("data->svcPort: %08X\n\n", ntohs(data->svcPort));
866 printf("data->macAddr: %pM\n", data->macAddr);
867 printf("data->ipAddr: %pI4\n", &data->ipAddr);
868 printf("data->platformId: %s\n", data->platformId);
869 printf("data->deviceName: %s\n", data->deviceName);
871 // Some diag output ...
873 printf("Sending BOOTME request [%d] to %pI4\n", net->seqNum,
877 net->dataLen = BOOTME_PKT_SIZE;
878 // net->status = CE_PR_MORE;
879 net->state = BOOTME_INIT;
881 debug("Start of buffer: %p\n", net->data);
882 debug("Start of ethernet buffer: %p\n", net->data);
883 debug("Start of CE header: %p\n", header);
884 debug("Start of CE data: %p\n", data);
887 debug("packet to send (ceconnect): \n");
888 for (i = 0; i < net->dataLen; i++) {
889 debug("0x%02X ", pkt[i]);
895 return BootMeRequest(server_ip, net->data, net->dataLen, 1);
898 static inline int ce_init_download_link(ce_net *net, ce_bin *bin, int verbose)
900 if (!eth_get_dev()) {
901 printf("No network interface available\n");
904 printf("Using device '%s'\n", eth_get_name());
906 /* Initialize EDBG link for download */
907 memset(net, 0, sizeof(*net));
909 net->verbose = verbose;
911 /* buffer will be dynamically assigned in ce_download_handler() */
912 ce_init_bin(bin, NULL);
916 static inline int ce_download_file(ce_net *net, ulong timeout)
918 ulong start = get_timer_masked();
920 while (net->state == BOOTME_INIT) {
923 if (timeout && get_timer(start) > timeout) {
924 printf("CELOAD - Canceled, timeout\n");
929 printf("CELOAD - canceled by user\n");
933 if (ce_send_bootme(&g_net)) {
934 printf("CELOAD - error while sending BOOTME request\n");
939 printf("Waiting for connection, timeout %lu sec\n",
940 DIV_ROUND_UP(timeout - get_timer(start),
943 printf("Waiting for connection, enter ^C to abort\n");
947 ret = BootMeDownload(ce_download_handler);
948 if (ret == BOOTME_ERROR) {
949 printf("CELOAD - aborted\n");
956 static void ce_disconnect(void)
958 net_set_udp_handler(NULL);
962 static int do_ceconnect(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
969 server_ip.s_addr = 0;
971 for (i = 1; i < argc; i++){
974 if (argv[i][1] == 'v') {
976 } else if (argv[i][1] == 't') {
979 timeout = simple_strtoul(argv[i],
981 if (timeout >= UINT_MAX / CONFIG_SYS_HZ) {
982 printf("Timeout value %lu out of range (max.: %u)\n",
983 timeout, UINT_MAX / CONFIG_SYS_HZ - 1);
984 return CMD_RET_USAGE;
986 timeout *= CONFIG_SYS_HZ;
988 printf("Option requires an argument - t\n");
989 return CMD_RET_USAGE;
991 } else if (argv[i][1] == 'h') {
994 server_ip = string_to_ip(argv[i]);
995 printf("Using server %pI4\n", &server_ip);
997 printf("Option requires an argument - h\n");
998 return CMD_RET_USAGE;
1003 if (ce_init_download_link(&g_net, &g_bin, verbose) != 0)
1006 if (ce_download_file(&g_net, timeout))
1010 // Try to receive edbg commands from host
1011 ce_init_edbg_link(&g_net);
1013 printf("Waiting for EDBG commands ...\n");
1015 ret = BootMeDebugStart(ce_edbg_handler);
1016 if (ret != BOOTME_DONE)
1019 // Prepare WinCE image for execution
1020 ce_prepare_run_bin(&g_bin);
1022 // Launch WinCE, if necessary
1023 if (g_net.gotJumpingRequest)
1024 ce_run_bin(g_bin.eEntryPoint);
1029 return ret == 0 ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
1032 ceconnect, 6, 1, do_ceconnect,
1033 "Set up a connection to the CE host PC over TCP/IP and download the run-time image",
1034 "[-v] [-t <timeout>] [-h host]\n"
1035 " -v - verbose operation\n"
1036 " -t <timeout> - max wait time (#sec) for the connection\n"
1037 " -h <host> - send BOOTME requests to <host> (default: broadcast address 255.255.255.255)"