[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: e100boot for Windows UPDATE AGAIN



Thanks for all your work! I think many can benefit from this.

/Mikael

-----Original Message-----
From: owner-dev-etrax@xxxxxxx.com]On">mailto:owner-dev-etrax@xxxxxxx.com]On
Behalf Of David Kilp
Sent: Thursday, February 06, 2003 9:44 PM
To: David Kilp; Mikael Starvik; dev-etrax
Subject: RE: e100boot for Windows UPDATE AGAIN


As promised, here's my changes to the Windows eboot.c code (from http://www.elphel.com/downloads/index.html) that works with the latest latest (R2_0_5) tools build. I basically just tried to incorporate the same changes that were made to the linux boot code to the windows version.

This update is much better than the previous as it gives immediate feedback on the state of progress (erasing, verifying, etc...) and will give error codes if something goes wrong during the flashing process (as does the new Linux version of e100boot).

The tool seems pretty stable and works pretty well for me so hopefully others will have sucess too.

Regards,

--David Kilp

-----------------[CUT]-----------------------------

*** ../eboot.c	Thu Feb  6 11:15:59 2003
--- eboot.c	Mon Feb  3 13:33:51 2003
***************
*** 42,54 ****
   * rebuild
   */
  
- #define PAKET_TYPE_STRING 0
- #define PAKET_TYPE_INT    1
- #define PAKET_TYPE_ACK    2
- #define PAKET_TYPE_BOOT_PACKET 3
- #define PAKET_TYPE_BOOT_CMDS   4
- #define PAKET_TYPE_REJECT   5
- 
  // #include <windows.h>
  
  #include <stdio.h>
--- 42,47 ----
***************
*** 64,74 ****
--- 57,77 ----
  #include "winpcap/ntddndis.h" //for PacketRequest
  #include "zlib/zlib.h"
  
+ /**************************  Constants and macros  *************************/
  #define SIMULTANEOU_READS 10
  #define MAX_ETHERNET_FRAME_SIZE 1514
  
  #define Max_Num_Adapter 10
  
+ #define PAKET_TYPE_STRING 0
+ #define PAKET_TYPE_INT    1
+ #define PAKET_TYPE_ACK    2
+ #define PAKET_TYPE_BOOT_PACKET 3
+ #define PAKET_TYPE_BOOT_CMDS   4
+ #define PAKET_TYPE_REJECT   5
+ 
+ /* max length of argument strings */
+ #define MAX_STRING_LEN 256
  
  #define byte   unsigned char
  #define uword  unsigned short
***************
*** 101,109 ****
--- 104,129 ----
  
  #pragma pack( pop )
  
+ #define STRING      0
+ #define INT         1
+ #define ACK         2
+ #define BOOT_PACKET 3
+ #define BOOT_CMDS   4
+ #define NET_INT     5
+ #define NET_INT_NL  6
+ 
+ /**************************  Global variables  *****************************/
+ 
+ char needle[MAX_STRING_LEN] = "END";    /* search needle for --find */
+ int needle_len = 3;
+ int exitonfind = FALSE;
+ udword TotalCount;
+ NeedLF = FALSE;
+ 
  // Prototypes
  
  int isAckn(LPPACKET lpPacket, udword seq);
+ void find_string(char *str);
  void printHeader(struct packet_header_T* hd);
  
  char        AdapterList[Max_Num_Adapter][1024];
***************
*** 357,363 ****
  		exit(1);
      }
  	comprAct = (uLong) fread(compr,1,comprLen,fd);
! 	printf("Compressed data length= %d bytes\n",(int) comprAct);
  	fclose (fd);
  #endif
  // now decompress data
--- 377,383 ----
  		exit(1);
      }
  	comprAct = (uLong) fread(compr,1,comprLen,fd);
! 	//printf("Compressed data length= %d bytes\n",(int) comprAct);
  	fclose (fd);
  #endif
  // now decompress data
***************
*** 370,386 ****
  
      i = uncompress(uncompr, &uncomprAct, &compr[i], comprAct-i);
      CHECK_ERR(i, "uncompress");
! 	printf("Decompressed data length to be sent to model 303 camera= %d bytes\n",(int) uncomprAct);
  	mrp=(char*) uncompr;
  	mre=mrp+ uncomprAct;
  
  	// obtain the name of the adapters installed on this machine
  	AdapterLength=4096;
! /*	
  //  Does not work with olde WinPCap
! 	printf("WinPcap library verision %s\n"
! 		   "Adapters installed:\n",PacketGetVersion());
! */
  	printf("\nAdapters installed:\n");
  
  	i=0;	
--- 390,405 ----
  
      i = uncompress(uncompr, &uncomprAct, &compr[i], comprAct-i);
      CHECK_ERR(i, "uncompress");
! 	printf("Decompressed data length to be sent to device = %d bytes\n",(int) uncomprAct);
  	mrp=(char*) uncompr;
  	mre=mrp+ uncomprAct;
  
  	// obtain the name of the adapters installed on this machine
  	AdapterLength=4096;
! 	
  //  Does not work with olde WinPCap
! 	printf("WinPcap library verision %s\n",PacketGetVersion());
! 
  	printf("\nAdapters installed:\n");
  
  	i=0;	
***************
*** 469,475 ****
  
  	do 
  	{
! 		printf("Please set the camera to firmware download mode\nand select the number of the network adapter to use : ");scanf("%d",&Open);
  		if (Open>AdapterNum) printf("\nThe number must be smaller than %d",AdapterNum); 
  	} while (Open>AdapterNum);
  	
--- 488,494 ----
  
  	do 
  	{
! 		printf("Put the device in firmware download mode\nand select the number of the network adapter to use : ");scanf("%d",&Open);
  		if (Open>AdapterNum) printf("\nThe number must be smaller than %d",AdapterNum); 
  	} while (Open>AdapterNum);
  	
***************
*** 541,548 ****
  		do {
  		  i=ntohl(seq);
  		  PacketSendPacket(lpAdapter,lpPacketS,TRUE);
! //	printf("TRANSMITTED ------------------------------\n");
! //	printHeader((struct packet_header_T*) bufferS);
  
  
  		  ackn=0;
--- 560,568 ----
  		do {
  		  i=ntohl(seq);
  		  PacketSendPacket(lpAdapter,lpPacketS,TRUE);
! 	      
! 		  // printf("TRANSMITTED ------------------------------\n");
! 	      // printHeader((struct packet_header_T*) bufferS);
  
  
  		  ackn=0;
***************
*** 559,564 ****
--- 579,592 ----
  
  	}
  
+ 	/* Now just wait for the status strings */
+ 	while (1) {
+ 		  if(PacketReceivePacket(lpAdapter,lpPacketR,TRUE)==FALSE){
+ 			printf("Error: PacketReceivePacket failed");
+ 			return (-1);
+ 		  }
+ 		  isAckn(lpPacketR, 0);
+ 	}
  
  	PacketFreePacket(lpPacketS);
  	PacketFreePacket(lpPacketR);
***************
*** 584,589 ****
--- 612,619 ----
  	struct bpf_hdr *hdr;
  	struct packet_header_T *rhead;
  	int i;
+ 	char *data;
+ 	char *str;
  	
  	
  		ulBytesReceived = lpPacket->ulBytesReceived;
***************
*** 591,596 ****
--- 621,630 ----
  		off=0;
  
  		while(off<ulBytesReceived){	
+ 			if ( (++TotalCount % 100) == 0 ) {	// every 500 bytes..
+ 				NeedLF = TRUE;
+ 				printf(".");
+ 			}
  			if(kbhit()) {
  				printf("aborted due to keypress\n");
  				exit (0);	//
***************
*** 600,612 ****
  			tlen=hdr->bh_caplen;
  			off+=hdr->bh_hdrlen;
  			rhead= (struct packet_header_T *) (buf+off);	// actual packet data
! //	printf("RECEIVED ==============================\n");
! //	printHeader(rhead);
  
! 		off=Packet_WORDALIGN(off+tlen1);
  		
  
! // compare address
  			if ((rhead->src[0] == src_addr_of_device[0]) &&
  				(rhead->src[1] == src_addr_of_device[1]) &&
  				(rhead->src[2] == src_addr_of_device[2]) &&
--- 634,708 ----
  			tlen=hdr->bh_caplen;
  			off+=hdr->bh_hdrlen;
  			rhead= (struct packet_header_T *) (buf+off);	// actual packet data
! 			data = (char *)rhead + sizeof(struct packet_header_T);
! 			
! 			 // printf("RECEIVED ==============================\n");
! 			 // printHeader(rhead);
! 
! 			 switch (ntohl(rhead->type)) {
! 
! 			 case STRING:
! 
! 				if (NeedLF) {
! 					printf("\n");
! 					NeedLF = FALSE;
! 				}
! 	
! 			    str = "(STRING)";
! 				//fprintf(stderr, "%s", &rhead[sizeof(struct packet_header_T)]);
! 				fprintf(stderr, "%s", data);
! 				find_string(data);
! 				if ( strncmp(data, "PAUSE_LOOP", 10) == 0 ) {
! 					//printf("Found Pause, sleeping for 1.5 secsn");
! 					Sleep(1500);
! 				}
! 				break;
! 
! 			  case NET_INT: {
! 				char search_str[20];
  
! 			    str = "(NET_INT)";
! 				sprintf(search_str, "0x%8.8x", ntohl(*(udword*)data));
! 				fprintf(stderr, search_str);
! 				find_string(search_str);
! 				break;
! 			  }
! 
! 			  case NET_INT_NL: {
! 				char search_str[20];
!     
! 			    str = "(NET_INT_NL)";
! 				sprintf(search_str, "0x%8.8x\n", ntohl(*(udword*)data));
! 				fprintf(stderr, search_str);
! 				find_string(search_str);
! 				break;
! 			  }
! 
! 			  case ACK:
! 				str = "(ACK)";
! 				break;
! 
! 			  case BOOT_PACKET:
! 				str = "(bootpacket)";
! 				break;
! 
! 			  case BOOT_CMDS:
! 				str = "(bootcmds)";
! 				break;
! 
! 			  default:
! 				str = "(unknown)";
! 				break;
! 			 }
! 
!      // printf("(type    : %8.8lx %s)\n", (unsigned long)ntohl(rhead->type), str);
!      // printf("(id      : %8.8lx)\n", (unsigned long)ntohl(rhead->id));
! 
! 
! 			off=Packet_WORDALIGN(off+tlen1);
  		
  
! 			// compare address
  			if ((rhead->src[0] == src_addr_of_device[0]) &&
  				(rhead->src[1] == src_addr_of_device[1]) &&
  				(rhead->src[2] == src_addr_of_device[2]) &&
***************
*** 614,620 ****
  				(rhead->src[4] == src_addr_of_device[4]) &&
  				(rhead->src[5] == src_addr_of_device[5])) { // mismatch
  
! // compare seq
  				i=ntohl(rhead->seq);
  				i=ntohl(rhead->type);
  				if (rhead->seq == seq){
--- 710,716 ----
  				(rhead->src[4] == src_addr_of_device[4]) &&
  				(rhead->src[5] == src_addr_of_device[5])) { // mismatch
  
! 				// compare seq
  				i=ntohl(rhead->seq);
  				i=ntohl(rhead->type);
  				if (rhead->seq == seq){
***************
*** 645,647 ****
--- 741,834 ----
  	printf ("Snap1 = %x,\tSnap2 = %x\tTag = %x\n",ntohl(hd->snap1),ntohl(hd->snap2),ntohl(hd->tag));
  	printf ("seq   = %x,\ttype  = %x\tid  = %x\n",ntohl(hd->seq), ntohl(hd->type), ntohl(hd->id));
  }
+ 
+ /****************************************************************************
+ *#
+ *#  FUNCTION NAME: find_string
+ *#
+ *#  PARAMETERS: New string to search.
+ *#
+ *#  DESCRIPTION: Searches a number of strings for needle[], including strings
+ *#  overlapping between different calls.
+ *#
+ *#---------------------------------------------------------------------------
+ *#  HISTORY
+ *#
+ *#  DATE     NAME     CHANGES
+ *#  ----     ----     -------
+ *#  020502   ronny    Initial version
+ *#
+ *#***************************************************************************/
+ 
+ void find_string(char *str)
+ {
+   static int matched = 0;
+   int hs[MAX_STRING_LEN];
+   static int cur_hs = 0;
+   static int hs_len = 0;
+   static int last_hs = 0;
+ 
+   static int cur_needle = 0;
+ 
+   if (!needle[0]) {
+     return;
+   }
+   //    printf("# adding >%s<\n", str);
+ 
+   {
+     int c = 0;
+     int s = 0;
+ 
+     while((c = str[s])) {
+       //    printf("\n# cur_hs %d, hs_len %d\n", cur_hs, hs_len);
+       {
+         int i;
+ 
+         for(i = 0; i != hs_len; i++) {
+           //      printf("hs[%d] = %d(%c)\n", i, (int)hs[i], hs[i] < 32 ? 'X' : hs[i]);
+         }
+       }
+ 
+       if (cur_hs == hs_len) {
+         //      printf("adding char %d(%c) at hs[%d]\n", (int)c, c < 32 ? 'X' : c, hs_len);
+         hs[hs_len] = c;
+         hs_len++;
+         s++;
+       }
+ 
+       //      printf("testing %d at cur_hs %d against %d at cur_needle  %d\n",
+       //             (int)hs[cur_hs], cur_hs, (int)needle[cur_needle], cur_needle);
+ 
+       if (hs[cur_hs] == needle[cur_needle]) {
+         if (cur_needle+1 == needle_len) {
+           int exitcode = EXIT_SUCCESS;
+ 
+           //      printf("\nFound needle from --find option.\n");
+           if (exitonfind) {
+             int ret;
+             //      printf("scanf (s=%d)'%s'\n", s, &str[s+1]);
+             ret = sscanf(&str[s+1], "%i", &exitcode);
+             //      printf("ret %d, '%s'\n", ret, &str[s+1]);
+           }
+           printf("Exiting with code %d\n", exitcode);
+           exit(exitcode);
+         }
+         cur_needle++;
+         cur_hs++;
+       }
+       else {
+         //      printf("no match, shifting hs.\n");
+         {
+           int i;
+           for(i=0; i!= hs_len-1; i++) {
+             hs[i] = hs[i+1];
+           }
+         }
+         hs_len--;
+         cur_needle = 0;
+         cur_hs = 0;
+       }
+     }
+   }
+ }
+ 
 
-----------------[CUT]-----------------------------


> > -----Original Message-----
> > From: Mikael Starvik [mailto:mikael.starvik@xxxxxxx.com]
> > Sent: Friday, January 31, 2003 1:05 AM
> > To: David Kilp; dev-etrax
> > Subject: RE: e100boot for Windows available?
> > 
> > 
> > Nice! Would it be possible for you to share the code with the rest
> > of the world?
> > 
> > (e100boot has no license AFAIK and is not contaminated by GPL
> > which means that you can choose to keep the code proprietary)
> > 
> > /Mikael
> > 
> > -----Original Message-----
> > From: owner-dev-etrax@xxxxxxx.com]On">mailto:owner-dev-etrax@xxxxxxx.com]On
> > Behalf Of David Kilp
> > Sent: Thursday, January 30, 2003 11:31 PM
> > To: dev-etrax
> > Subject: RE: e100boot for Windows available?
> > 
> > 
> > Thanks for the information. After a few minor tweaks to my 
> > existing e100boot.c file, I was able to use this program and 
> > perform a successful network upgrade from a Win-2K laptop. 
> > 
> > You certainly saved me a bunch of time! Thanks!
> > 
> > --David Kilp 
> > 
> > > -----Original Message-----
> > > From: Mikael Starvik [mailto:starvik@xxxxxxx.com]
> > > Sent: Thursday, January 30, 2003 1:19 AM
> > > To: David Kilp; dev-etrax
> > > Subject: RE: e100boot for Windows available?
> > > 
> > > 
> > > One of our customers have made a flashing utility for windows.
> > > http://www.elphel.com/downloads/index.html.
> > > 
> > > I have never tested it and I don' know how compatible it is
> > > with e100boot. Otherwise I agree that I should be rater simple to
> > >  port e100boot to windows with libpcap for windows or similar.
> > > Maybe it I can be tricky to get it to work on all different
> > > Windows versions.
> > > 
> > > /Mikael
> > > 
> > > -----Original Message-----
> > > From: owner-dev-etrax@xxxxxxx.com]On">mailto:owner-dev-etrax@xxxxxxx.com]On
> > > Behalf Of David Kilp
> > > Sent: Wednesday, January 29, 2003 11:56 PM
> > > To: dev-etrax
> > > Subject: e100boot for Windows available?
> > > 
> > > 
> > > Just wondering if anyone has ported the flashing utility, 
> > > e100boot, to a Windows platform? There are times where it 
> > > would be useful to reflash a unit without having a Linux box 
> > > around (sad as that may seem....). 
> > > 
> > > Looking at the code, it seems like it's doable at least for 
> > > the server-side portion (sbl). The client side part would 
> > > still have to be built on the Linux side and the resulting 
> > > images copied over but seems possible. Just thought I'd see 
> > > if somebody has already done it and would like to share 
> the results.
> > > 
> > > Thanks,
> > > 
> > > David Kilp
> > > 
> > 
> 
>