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").s_addr;
138 std_drv_glb->kitl.ipRoute = getenv_ip("gatewayip").s_addr;
141 strncpy(std_drv_glb->mtdparts, mtdparts, max_len);
142 std_drv_glb->mtdparts[max_len - 1] = '\0';
144 if (CONFIG_IS_ENABLED(CMD_MTDPARTS))
145 printf("Failed to get mtdparts environment variable\n");
149 static void ce_init_drv_globals(void)
151 struct ce_magic *ce_magic = (void *)CONFIG_SYS_SDRAM_BASE + 0x160;
152 ce_std_driver_globals *std_drv_glb = &ce_magic->drv_glb;
154 debug("Copying CE MAGIC from %p to %p..%p\n",
155 &ce_magic_template, ce_magic,
156 (void *)ce_magic + sizeof(*ce_magic) - 1);
157 memcpy(ce_magic, &ce_magic_template, sizeof(*ce_magic));
159 ce_setup_std_drv_globals(std_drv_glb);
160 ce_magic->size = sizeof(*std_drv_glb) +
161 strlen(std_drv_glb->mtdparts) + 1;
162 ce_dump_block(ce_magic, offsetof(struct ce_magic, drv_glb) +
166 static void ce_prepare_run_bin(ce_bin *bin)
168 /* Clear os RAM area (if needed) */
169 if (bin->edbgConfig.flags & EDBG_FL_CLEANBOOT) {
170 debug("cleaning memory from %p to %p\n",
171 bin->eRamStart, bin->eRamStart + bin->eRamLen);
173 printf("Preparing clean boot ... ");
174 memset(bin->eRamStart, 0, bin->eRamLen);
178 ce_init_drv_globals();
181 * Make sure, all the above makes it into SDRAM because
182 * WinCE switches the cache & MMU off, obviously without
188 static int ce_lookup_ep_bin(ce_bin *bin)
191 ce_toc_entry *tentry;
194 uint32_t *sig = (uint32_t *)(bin->rtiPhysAddr + ROM_SIGNATURE_OFFSET);
196 debug("Looking for TOC signature at %p\n", sig);
198 /* Check image Table Of Contents (TOC) signature */
199 if (*sig != ROM_SIGNATURE) {
200 printf("Error: Did not find image TOC signature!\n");
201 printf("Expected %08x at address %p; found %08x instead\n",
202 ROM_SIGNATURE, sig, *sig);
206 /* Lookup entry point */
207 header = CE_FIX_ADDRESS(*(unsigned int *)(bin->rtiPhysAddr +
208 ROM_SIGNATURE_OFFSET +
209 sizeof(unsigned int)));
210 tentry = (ce_toc_entry *)(header + 1);
212 for (i = 0; i < header->nummods; i++) {
213 // Look for 'nk.exe' module
214 if (strcmp(CE_FIX_ADDRESS(tentry[i].fileName), "nk.exe") == 0) {
215 // Save entry point and RAM addresses
217 e32 = CE_FIX_ADDRESS(tentry[i].e32Offset);
219 bin->eEntryPoint = CE_FIX_ADDRESS(tentry[i].loadOffset) +
221 bin->eRamStart = CE_FIX_ADDRESS(header->ramStart);
222 bin->eRamLen = header->ramEnd - header->ramStart;
227 // Error: Did not find 'nk.exe' module
231 static int ce_parse_bin(ce_bin *bin)
233 unsigned char *pbData = bin->data;
234 int len = bin->dataLen;
237 debug("starting ce image parsing:\n\tbin->binLen: 0x%08X\n", bin->binLen);
240 if (bin->binLen == 0) {
241 // Check for the .BIN signature first
242 if (!ce_is_bin_image(pbData, len)) {
243 printf("Error: Invalid or corrupted .BIN image!\n");
247 printf("Loading Windows CE .BIN image ...\n");
249 len -= CE_BIN_SIGN_LEN;
250 pbData += CE_BIN_SIGN_LEN;
254 switch (bin->parseState) {
260 copyLen = CE_MIN(sizeof(unsigned int) - bin->parseLen, len);
261 memcpy(&bin->parsePtr[bin->parseLen], pbData, copyLen);
263 bin->parseLen += copyLen;
267 if (bin->parseLen == sizeof(unsigned int)) {
268 if (bin->parseState == CE_PS_RTI_ADDR)
269 bin->rtiPhysAddr = CE_FIX_ADDRESS(bin->rtiPhysAddr);
270 else if (bin->parseState == CE_PS_E_ADDR &&
272 bin->ePhysAddr = CE_FIX_ADDRESS(bin->ePhysAddr);
276 bin->parsePtr += sizeof(unsigned int);
278 if (bin->parseState == CE_PS_E_DATA) {
279 if (bin->ePhysAddr) {
280 bin->parsePtr = bin->ePhysAddr;
281 bin->parseChkSum = 0;
292 debug("ePhysAddr=%p physlen=%08x parselen=%08x\n",
293 bin->ePhysAddr, bin->ePhysLen, bin->parseLen);
294 if (bin->ePhysAddr) {
295 copyLen = CE_MIN(bin->ePhysLen - bin->parseLen, len);
296 bin->parseLen += copyLen;
300 bin->parseChkSum += *pbData;
301 *bin->parsePtr++ = *pbData++;
304 if (bin->parseLen == bin->ePhysLen) {
305 printf("Section [%02d]: address %p, size 0x%08X, checksum %s\n",
309 (bin->eChkSum == bin->parseChkSum) ? "ok" : "fail");
311 if (bin->eChkSum != bin->parseChkSum) {
312 printf("Error: Checksum error, corrupted .BIN file!\n");
313 printf("checksum calculated: 0x%08x from file: 0x%08x\n",
314 bin->parseChkSum, bin->eChkSum);
320 bin->parseState = CE_PS_E_ADDR;
322 bin->parsePtr = (unsigned char *)&bin->ePhysAddr;
335 if (!ce_lookup_ep_bin(bin)) {
336 printf("Error: entry point not found!\n");
341 printf("Entry point: %p, address range: %p-%p\n",
344 bin->rtiPhysAddr + bin->rtiPhysLen);
350 bin->binLen += bin->dataLen;
354 static int ce_bin_load(void *image, int imglen)
356 ce_init_bin(&g_bin, image);
357 g_bin.dataLen = imglen;
358 if (ce_parse_bin(&g_bin) == CE_PR_EOF) {
359 ce_prepare_run_bin(&g_bin);
366 static void ce_run_bin(void (*entry)(void))
368 printf("Launching Windows CE ...\n");
375 static int do_bootce(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
381 if (strcmp(argv[1], "-i") == 0) {
382 ce_init_drv_globals();
383 return CMD_RET_SUCCESS;
385 addr = (void *)simple_strtoul(argv[1], NULL, 16);
386 image_size = INT_MAX; /* actually we do not know the image size */
387 } else if (getenv("fileaddr") != NULL) {
388 addr = (void *)getenv_ulong("fileaddr", 16, 0);
389 image_size = getenv_ulong("filesize", 16, INT_MAX);
391 return CMD_RET_USAGE;
394 printf ("## Booting Windows CE Image from address %p ...\n", addr);
396 /* check if there is a valid windows CE image */
397 if (ce_is_bin_image(addr, image_size)) {
398 if (!ce_bin_load(addr, image_size)) {
399 /* Ops! Corrupted .BIN image! */
400 /* Handle error here ... */
401 printf("corrupted .BIN image !!!\n");
402 return CMD_RET_FAILURE;
404 if (getenv_yesno("autostart") != 1) {
406 * just use bootce to load the image to SDRAM;
407 * Do not start it automatically.
409 setenv_addr("fileaddr", g_bin.eEntryPoint);
410 return CMD_RET_SUCCESS;
412 ce_run_bin(g_bin.eEntryPoint); /* start the image */
414 printf("Image does not seem to be a valid Windows CE image!\n");
415 return CMD_RET_FAILURE;
417 return CMD_RET_FAILURE; /* never reached - just to keep compiler happy */
420 bootce, 2, 0, do_bootce,
421 "Boot a Windows CE image from RAM",
423 "\taddr\t\tboot image from address addr (default ${fileaddr})\n"
425 "\t-i\t\tinitialize the WinCE globals data structure (before loading a .nb0 image)"
428 #ifdef CONFIG_CMD_NAND
429 static int ce_nand_load(ce_bin *bin, loff_t *offset, void *buf, size_t max_len)
432 size_t len = max_len;
433 nand_info_t *nand = &nand_info[0];
435 while (nand_block_isbad(nand, *offset & ~(max_len - 1))) {
436 printf("Skipping bad block 0x%08llx\n",
437 *offset & ~(max_len - 1));
439 if (*offset + max_len > nand->size)
443 ret = nand_read(nand, *offset, &len, buf);
451 static int do_nbootce(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
454 struct mtd_device *dev;
455 struct part_info *part_info;
460 size_t bufsize = nand_info[0].erasesize, len;
462 if (argc < 2 || argc > 3)
463 return CMD_RET_USAGE;
465 ret = mtdparts_init();
467 return CMD_RET_FAILURE;
469 offset = simple_strtoul(argv[1], &end, 16);
471 ret = find_dev_and_part(argv[1], &dev, &part_num,
474 printf("Partition '%s' not found\n", argv[1]);
475 return CMD_RET_FAILURE;
477 offset = part_info->offset;
478 printf ("## Booting Windows CE Image from NAND partition %s at offset %08llx\n",
481 printf ("## Booting Windows CE Image from NAND offset %08llx\n",
485 buffer = malloc(bufsize);
486 if (buffer == NULL) {
487 printf("Failed to allocate %u byte buffer\n", bufsize);
488 return CMD_RET_FAILURE;
491 ce_init_bin(&g_bin, buffer);
493 ret = ce_nand_load(&g_bin, &offset, buffer, bufsize);
495 printf("Failed to read NAND: %d\n", ret);
499 /* check if there is a valid windows CE image header */
500 if (ce_is_bin_image(buffer, len)) {
502 ret = ce_parse_bin(&g_bin);
507 printf("NBOOTCE - canceled by user\n");
511 len = ce_nand_load(&g_bin, &offset, buffer,
514 printf("Nand read error: %d\n", len);
522 ce_prepare_run_bin(&g_bin);
528 } while (ret == CE_PR_MORE);
530 if (ret != CE_PR_EOF)
531 return CMD_RET_FAILURE;
533 if (getenv_yesno("autostart") != 1) {
535 * just use bootce to load the image to SDRAM;
536 * Do not start it automatically.
538 setenv_addr("fileaddr", g_bin.eEntryPoint);
539 return CMD_RET_SUCCESS;
541 ce_run_bin(g_bin.eEntryPoint); /* start the image */
543 printf("Image does not seem to be a valid Windows CE image!\n");
547 return CMD_RET_FAILURE;
550 nbootce, 2, 0, do_nbootce,
551 "Boot a Windows CE image from NAND",
553 "\toff\t\t- flash offset (hex)\n"
554 "\tpartition\t- partition name"
558 static int ce_send_write_ack(ce_net *net)
561 unsigned short wdata[2];
564 wdata[0] = htons(EDBG_CMD_WRITE_ACK);
565 wdata[1] = htons(net->blockNum);
566 net->dataLen = sizeof(wdata);
567 memcpy(net->data, wdata, net->dataLen);
570 ret = bootme_send_frame(net->data, net->dataLen);
572 printf("Failed to send write ack %d; retries=%d\n",
575 } while (ret != 0 && retries-- > 0);
579 static enum bootme_state ce_process_download(ce_net *net, ce_bin *bin)
581 int ret = net->state;
583 if (net->dataLen >= 4) {
584 unsigned short command;
585 unsigned short blknum;
587 memcpy(&command, net->data, sizeof(command));
588 command = ntohs(command);
589 debug("command found: 0x%04X\n", command);
591 if (net->state == BOOTME_DOWNLOAD) {
592 unsigned short nxt = net->blockNum + 1;
594 memcpy(&blknum, &net->data[2], sizeof(blknum));
595 blknum = ntohs(blknum);
597 net->blockNum = blknum;
599 int rc = ce_send_write_ack(net);
602 printf("Dropping out of sequence packet with ID %d (expected %d)\n",
612 case EDBG_CMD_WRITE_REQ:
613 if (net->state == BOOTME_INIT) {
614 // Check file name for WRITE request
615 // CE EShell uses "boot.bin" file name
616 if (strncmp((char *)&net->data[2],
617 "boot.bin", 8) == 0) {
620 printf("Locked Down download link, IP: %pI4\n",
622 printf("Sending BOOTME request [%d] to %pI4\n",
623 net->seqNum, &net_server_ip);
626 // Lock down EShell download link
627 ret = BOOTME_DOWNLOAD;
630 printf("Unknown link\n");
633 if (ret == BOOTME_DOWNLOAD) {
634 int rc = ce_send_write_ack(net);
643 bin->data = &net->data[4];
644 bin->dataLen = net->dataLen - 4;
645 ret = ce_parse_bin(bin);
646 if (ret != CE_PR_ERROR) {
647 int rc = ce_send_write_ack(net);
650 if (ret == CE_PR_EOF)
657 case EDBG_CMD_READ_REQ:
658 printf("Ignoring EDBG_CMD_READ_REQ\n");
659 /* Read requests are not supported
665 printf("Error: unknown error on the host side\n");
672 printf("unknown command 0x%04X\n", command);
673 net->state = BOOTME_ERROR;
679 static enum bootme_state ce_process_edbg(ce_net *net, ce_bin *bin)
681 enum bootme_state ret = net->state;
684 if (net->dataLen < sizeof(header)) {
686 printf("Invalid packet size %u\n", net->dataLen);
690 memcpy(&header, net->data, sizeof(header));
691 if (header.id != EDBG_ID) {
693 printf("Bad EDBG ID %08x\n", header.id);
698 if (header.service != EDBG_SVC_ADMIN) {
699 /* Unknown service */
700 printf("Bad EDBG service %02x\n", header.service);
705 if (net->state == BOOTME_INIT) {
706 /* Some diag output */
708 printf("Locked Down EDBG service link, IP: %pI4\n",
712 /* Lock down EDBG link */
713 net->state = BOOTME_DEBUG;
716 switch (header.cmd) {
717 case EDBG_CMD_JUMPIMG:
718 net->gotJumpingRequest = 1;
721 printf("Received JUMPING command\n");
723 /* Just pass through and copy CONFIG structure */
725 case EDBG_CMD_OS_CONFIG:
726 /* Copy config structure */
727 memcpy(&bin->edbgConfig, &net->data[sizeof(header)],
728 sizeof(edbg_os_config_data));
730 printf("Received CONFIG command\n");
731 if (bin->edbgConfig.flags & EDBG_FL_DBGMSG) {
732 printf("--> Enabling DBGMSG service, IP: %pI4, port: %d\n",
733 &bin->edbgConfig.dbgMsgIPAddr,
734 ntohs(bin->edbgConfig.dbgMsgPort));
737 if (bin->edbgConfig.flags & EDBG_FL_PPSH) {
738 printf("--> Enabling PPSH service, IP: %pI4, port: %d\n",
739 &bin->edbgConfig.ppshIPAddr,
740 ntohs(bin->edbgConfig.ppshPort));
743 if (bin->edbgConfig.flags & EDBG_FL_KDBG) {
744 printf("--> Enabling KDBG service, IP: %pI4, port: %d\n",
745 &bin->edbgConfig.kdbgIPAddr,
746 ntohs(bin->edbgConfig.kdbgPort));
749 if (bin->edbgConfig.flags & EDBG_FL_CLEANBOOT) {
750 printf("--> Force clean boot\n");
757 printf("Received unknown command: %08X\n", header.cmd);
762 /* Respond with ack */
763 header.flags = EDBG_FL_FROM_DEV | EDBG_FL_ACK;
764 memcpy(net->data, &header, sizeof(header));
765 net->dataLen = EDBG_DATA_OFFSET;
770 rc = bootme_send_frame(net->data, net->dataLen);
772 printf("Failed to send ACK: %d\n", rc);
774 } while (rc && retries-- > 0);
778 static enum bootme_state ce_edbg_handler(const void *buf, size_t len)
783 g_net.data = (void *)buf;
786 return ce_process_edbg(&g_net, &g_bin);
789 static void ce_init_edbg_link(ce_net *net)
791 /* Initialize EDBG link for commands */
792 net->state = BOOTME_INIT;
795 static enum bootme_state ce_download_handler(const void *buf, size_t len)
797 g_net.data = (void *)buf;
800 g_net.state = ce_process_download(&g_net, &g_bin);
804 static int ce_send_bootme(ce_net *net)
807 edbg_bootme_data *data;
808 unsigned char txbuf[PKTSIZE_ALIGN];
813 /* Fill out BOOTME packet */
816 memset(net->data, 0, PKTSIZE);
817 header = (eth_dbg_hdr *)net->data;
818 data = (edbg_bootme_data *)header->data;
820 header->id = EDBG_ID;
821 header->service = EDBG_SVC_ADMIN;
822 header->flags = EDBG_FL_FROM_DEV;
823 header->seqNum = net->seqNum++;
824 header->cmd = EDBG_CMD_BOOTME;
826 data->versionMajor = 0;
827 data->versionMinor = 0;
828 data->cpuId = EDBG_CPU_TYPE_ARM;
829 data->bootmeVer = EDBG_CURRENT_BOOTME_VERSION;
831 data->downloadPort = 0;
834 /* MAC address from environment*/
835 if (!eth_getenv_enetaddr("ethaddr", data->macAddr)) {
836 printf("'ethaddr' is not set or invalid\n");
837 memset(data->macAddr, 0, sizeof(data->macAddr));
840 /* IP address from active config */
841 net_copy_ip(&data->ipAddr, &net_ip);
843 // Device name string (NULL terminated). Should include
844 // platform and number based on Ether address (e.g. Odo42, CEPCLS2346, etc)
846 // We will use lower MAC address segment to create device name
847 // eg. MAC '00-0C-C6-69-09-05', device name 'Triton05'
849 strncpy(data->platformId, "Triton", sizeof(data->platformId));
850 snprintf(data->deviceName, sizeof(data->deviceName), "%s%02X",
851 data->platformId, data->macAddr[5]);
854 printf("header->id: %08X\n", header->id);
855 printf("header->service: %08X\n", header->service);
856 printf("header->flags: %08X\n", header->flags);
857 printf("header->seqNum: %08X\n", header->seqNum);
858 printf("header->cmd: %08X\n\n", header->cmd);
860 printf("data->versionMajor: %08X\n", data->versionMajor);
861 printf("data->versionMinor: %08X\n", data->versionMinor);
862 printf("data->cpuId: %08X\n", data->cpuId);
863 printf("data->bootmeVer: %08X\n", data->bootmeVer);
864 printf("data->bootFlags: %08X\n", data->bootFlags);
865 printf("data->svcPort: %08X\n\n", ntohs(data->svcPort));
867 printf("data->macAddr: %pM\n", data->macAddr);
868 printf("data->ipAddr: %pI4\n", &data->ipAddr);
869 printf("data->platformId: %s\n", data->platformId);
870 printf("data->deviceName: %s\n", data->deviceName);
872 // Some diag output ...
874 printf("Sending BOOTME request [%d] to %pI4\n", net->seqNum,
878 net->dataLen = BOOTME_PKT_SIZE;
879 // net->status = CE_PR_MORE;
880 net->state = BOOTME_INIT;
882 debug("Start of buffer: %p\n", net->data);
883 debug("Start of ethernet buffer: %p\n", net->data);
884 debug("Start of CE header: %p\n", header);
885 debug("Start of CE data: %p\n", data);
888 debug("packet to send (ceconnect): \n");
889 for (i = 0; i < net->dataLen; i++) {
890 debug("0x%02X ", pkt[i]);
896 return BootMeRequest(server_ip, net->data, net->dataLen, 1);
899 static inline int ce_init_download_link(ce_net *net, ce_bin *bin, int verbose)
901 if (!eth_get_dev()) {
902 printf("No network interface available\n");
905 printf("Using device '%s'\n", eth_get_name());
907 /* Initialize EDBG link for download */
908 memset(net, 0, sizeof(*net));
910 net->verbose = verbose;
912 /* buffer will be dynamically assigned in ce_download_handler() */
913 ce_init_bin(bin, NULL);
917 static inline int ce_download_file(ce_net *net, ulong timeout)
919 ulong start = get_timer_masked();
921 while (net->state == BOOTME_INIT) {
924 if (timeout && get_timer(start) > timeout) {
925 printf("CELOAD - Canceled, timeout\n");
930 printf("CELOAD - canceled by user\n");
934 if (ce_send_bootme(&g_net)) {
935 printf("CELOAD - error while sending BOOTME request\n");
940 printf("Waiting for connection, timeout %lu sec\n",
941 DIV_ROUND_UP(timeout - get_timer(start),
944 printf("Waiting for connection, enter ^C to abort\n");
948 ret = BootMeDownload(ce_download_handler);
949 if (ret == BOOTME_ERROR) {
950 printf("CELOAD - aborted\n");
957 static void ce_disconnect(void)
959 net_set_udp_handler(NULL);
963 static int do_ceconnect(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
970 server_ip.s_addr = 0;
972 for (i = 1; i < argc; i++){
975 if (argv[i][1] == 'v') {
977 } else if (argv[i][1] == 't') {
980 timeout = simple_strtoul(argv[i],
982 if (timeout >= UINT_MAX / CONFIG_SYS_HZ) {
983 printf("Timeout value %lu out of range (max.: %u)\n",
984 timeout, UINT_MAX / CONFIG_SYS_HZ - 1);
985 return CMD_RET_USAGE;
987 timeout *= CONFIG_SYS_HZ;
989 printf("Option requires an argument - t\n");
990 return CMD_RET_USAGE;
992 } else if (argv[i][1] == 'h') {
995 server_ip = string_to_ip(argv[i]);
996 printf("Using server %pI4\n", &server_ip);
998 printf("Option requires an argument - h\n");
999 return CMD_RET_USAGE;
1004 if (ce_init_download_link(&g_net, &g_bin, verbose) != 0)
1007 if (ce_download_file(&g_net, timeout))
1011 // Try to receive edbg commands from host
1012 ce_init_edbg_link(&g_net);
1014 printf("Waiting for EDBG commands ...\n");
1016 ret = BootMeDebugStart(ce_edbg_handler);
1017 if (ret != BOOTME_DONE)
1020 // Prepare WinCE image for execution
1021 ce_prepare_run_bin(&g_bin);
1023 // Launch WinCE, if necessary
1024 if (g_net.gotJumpingRequest)
1025 ce_run_bin(g_bin.eEntryPoint);
1030 return ret == 0 ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
1033 ceconnect, 6, 1, do_ceconnect,
1034 "Set up a connection to the CE host PC over TCP/IP and download the run-time image",
1035 "[-v] [-t <timeout>] [-h host]\n"
1036 " -v - verbose operation\n"
1037 " -t <timeout> - max wait time (#sec) for the connection\n"
1038 " -h <host> - send BOOTME requests to <host> (default: broadcast address 255.255.255.255)"