summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cleopatre/u-boot-1.1.6/net/net.c6
-rw-r--r--cleopatre/u-boot-1.1.6/net/spidupd.c250
-rw-r--r--cleopatre/u-boot-1.1.6/net/spidupd.h14
-rw-r--r--cleopatre/u-boot-1.1.6/test/spidupd_test/spidupd_test.c275
-rw-r--r--cleopatre/u-boot-1.1.6/test/spidupd_test/spidupd_test.h2
5 files changed, 342 insertions, 205 deletions
diff --git a/cleopatre/u-boot-1.1.6/net/net.c b/cleopatre/u-boot-1.1.6/net/net.c
index 62711e12f7..05bbc1a407 100644
--- a/cleopatre/u-boot-1.1.6/net/net.c
+++ b/cleopatre/u-boot-1.1.6/net/net.c
@@ -108,9 +108,9 @@ DECLARE_GLOBAL_DATA_PTR;
# define ARP_TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT)
#endif
-//#if 0
+#if 0
#define ET_DEBUG
-//#endif
+#endif
/** BOOTP EXTENTIONS **/
@@ -542,12 +542,12 @@ restart:
}
# endif /* CFG_FAULT_ECHO_LINK_DOWN, ... */
#endif /* CONFIG_MII, ... */
+
x = timeHandler;
timeHandler = (thand_f *)0;
(*x)();
}
-
switch (NetState) {
case NETLOOP_RESTART:
diff --git a/cleopatre/u-boot-1.1.6/net/spidupd.c b/cleopatre/u-boot-1.1.6/net/spidupd.c
index 5a9136f93b..58a8d41666 100644
--- a/cleopatre/u-boot-1.1.6/net/spidupd.c
+++ b/cleopatre/u-boot-1.1.6/net/spidupd.c
@@ -28,29 +28,22 @@
#include <md5.h>
#include "spidupd.h"
-//#undef ET_DEBUG
-#define ET_DEBUG
+#undef ET_DEBUG
+//#define ET_DEBUG
#if (CONFIG_COMMANDS & CFG_CMD_NET)
-#if 0
-
#define TIMEOUT 5 /* Seconds to timeout for a lost pkt */
#ifndef CONFIG_NET_RETRY_COUNT
-# define TIMEOUT_COUNT 10 /* # of timeouts before giving up */
+# define TIMEOUT_COUNT 0 /* # of timeouts before giving up */
#else
# define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT * 2)
#endif
-#endif // if 0
-
-#define TIMEOUT 300
-# define TIMEOUT_COUNT 1
+#define FLASH_WRITE_TIMEOUT 10*60 /* Writing Linux image to flash TO in seconds */
- /* (for checking the image size) */
-#define HASHES_PER_LINE 65 /* Number of "loading" hashes per line */
static int SpidupdTimeoutCount;
static int SpidupdState, NextSpidupdState; /* current and next state */
@@ -146,9 +139,9 @@ store_img (void)
{
int rc = 0;
-unsigned char *last_sector = (volatile unsigned char *)0x787f0000;
+ unsigned char *upd_sector = (unsigned char *)0x78100000;
- rc = flash_write (UPD_IMG_RAM_ADDR, (ulong)(last_sector), upd_img_len);
+ rc = flash_write (UPD_IMG_RAM_ADDR, (ulong)(upd_sector), upd_img_len);
if (rc) {
flash_perror (rc);
NetState = NETLOOP_FAIL;
@@ -175,11 +168,10 @@ SpidupdSend (void)
VsUpdTransfCnf_t *p_transfer_cnf;
VsUpdEndCnf_t *p_end_cnf;
-
-int j;
-
-
-printf ("Inside SpidupdSend()...\n");
+#ifdef ET_DEBUG
+ printf ("Inside SpidupdSend()\n");
+ printf ("SpidupdState = %d\n", SpidupdState);
+#endif
/*
* We will always be sending some sort of packet, so
@@ -191,26 +183,7 @@ printf ("Inside SpidupdSend()...\n");
s = (volatile MME_t *)pkt;
s->mmv = MME_MMV;
-printf("dst : ");
-for (j=0; j<6; j++)
- printf( "%#x ", (s->mme_dest)[j] );
-putc('\n');
-
-printf("src : ");
-for (j=0; j<6; j++)
- printf( "%#x ", (s->mme_src)[j] );
-putc('\n');
-
-printf( "mtype : %#x\n", s->mtype );
-printf( "mmv : %#x\n", s->mmv );
-
-printf ("SpidupdState = %d\n", SpidupdState);
-
-
-
-
switch (SpidupdState) {
-
case STATE_WAIT_UPD_START:
/* set mmtype to VS_UPDATE_START_CNF */
s->mmtype = htommes(VS_UPDATE_START_CNF);
@@ -222,14 +195,6 @@ printf ("SpidupdState = %d\n", SpidupdState);
p_start_cnf = (VsUpdStartCnf_t *)pkt;
p_start_cnf->start_update = vs_update_start_cnf->start_update;
-
-printf( "start_update : %#x\n", vs_update_start_cnf->start_update );
-
-printf("pkt : ");
-for (j=0; j<20; j++)
- printf( "%#x ", xp[j] );
-putc('\n');
-
/* we finished with the message, skip it */
p_start_cnf++;
pkt = (uchar *)p_start_cnf;
@@ -239,52 +204,63 @@ putc('\n');
break;
case STATE_WAIT_UPD_TRANSFER:
- /* set mmtype to VS_UPDATE_START_CNF */
- s->mmtype = htommes(VS_UPDATE_TRANSFER_CNF);
- /* skip the MME header */
- s++;
- pkt = (uchar *)s;
-
- /* append the message */
- p_transfer_cnf = (VsUpdTransfCnf_t *)pkt;
- p_transfer_cnf->ack = vs_update_transfer_cnf->ack;
- p_transfer_cnf->next_block = htommel(vs_update_transfer_cnf->next_block);
- /* we finished with the message, skip it */
- p_transfer_cnf++;
- pkt = (uchar *)p_transfer_cnf;
+ if (NextSpidupdState == STATE_WAIT_UPD_TRANSFER)
+ {
+ /* set mmtype to VS_UPDATE_START_CNF */
+ s->mmtype = htommes(VS_UPDATE_TRANSFER_CNF);
+ /* skip the MME header */
+ s++;
+ pkt = (uchar *)s;
+
+ /* append the message */
+ p_transfer_cnf = (VsUpdTransfCnf_t *)pkt;
+ p_transfer_cnf->ack = vs_update_transfer_cnf->ack;
+ p_transfer_cnf->next_block = htommel(vs_update_transfer_cnf->next_block);
+ /* we finished with the message, skip it */
+ p_transfer_cnf++;
+ pkt = (uchar *)p_transfer_cnf;
+
+ /* this is the end of packet, determine length */
+ len = pkt - xp;
+ }
+ else if (NextSpidupdState == STATE_UPD_END)
+ {
+ /* set mmtype to VS_UPDATE_START_CNF */
+ s->mmtype = htommes(VS_UPDATE_END_CNF);
+ /* skip the MME header */
+ s++;
+ pkt = (uchar *)s;
+
+ /* append the message */
+ p_end_cnf = (VsUpdEndCnf_t *)pkt;
+ p_end_cnf->result = vs_update_end_cnf->result;
+ /* we finished with the message, skip it */
+ p_end_cnf++;
+ pkt = (uchar *)p_end_cnf;
+ /* this is the end of packet, determine length */
+ len = pkt - xp;
+
+ /* if we do not have valid image in the flash, we must do update again */
+ if ( img_is_valid == 0 )
+ NextSpidupdState = STATE_WAIT_UPD_START;
+ }
+ else
+ {
+ /* WOW - How the hell did we get here ? */
+ printf("Error - server in unknown state...\n");
+ NetState = NETLOOP_FAIL;
+ return(-1);
+ }
- /* this is the end of packet, determine length */
- len = pkt - xp;
break;
- case STATE_UPD_END:
- /* set mmtype to VS_UPDATE_START_CNF */
- s->mmtype = htommes(VS_UPDATE_END_CNF);
- /* skip the MME header */
- s++;
- pkt = (uchar *)s;
-
- /* append the message */
- p_end_cnf = (VsUpdEndCnf_t *)pkt;
- p_end_cnf->result = vs_update_end_cnf->result;
- /* we finished with the message, skip it */
- p_end_cnf++;
- pkt = (uchar *)p_end_cnf;
- /* this is the end of packet, determine length */
- len = pkt - xp;
-
- /* if we do not have valid image in the flash, we must do update again */
- if ( img_is_valid == 0 )
- NextSpidupdState = STATE_WAIT_UPD_START;
-
- break;
+ default :
+ break;
}
/* We sent a response - we can now change state */
SpidupdState = NextSpidupdState;
-printf ("length of package to send from server = %d\n", len);
-
/* Position to packet begining, and send packet */
pkt = xp;
NetSendPacket(pkt, len);
@@ -303,16 +279,11 @@ SpidupdHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
unsigned char md5_server[16];
unsigned char md5_client[16];
- int i;
+ /* We received MME packet from PC client, reset the Netloop watchdog */
+ NetSetTimeout (TIMEOUT * CFG_HZ, SpidupdTimeout);
-
-printf ("SpidupdHandler called to serve packet received from PC client at : "); print_ETHaddr (NetClientEther);
-putc ('\n');
-
-
-
- /* We received packet from PC client.
- * Server will analyze the message and
+ /*
+ * Server will now analyze the message and
* depending on the message and current state :
* 1) shape the cnf message (struct members)
* 2) send the response
@@ -325,35 +296,22 @@ putc ('\n');
s = (MME_t *)pkt;
proto = s->mmtype;
-
-
-//printf( "mme_dest : %#x\n", ntohl( *( (unsigned long *)s->mme_dest ) ) );
-//printf( "mme_src : %#x\n", ntohl( *( (unsigned long *)s->mme_src ) ) );
-//printf( "vlan_tag : %#x\n", ntohl(s->vlan_tag) );
-printf( "mmtype : %#x\n", mmetohs(s->mmtype) );
-printf( "mtype : %#x\n", mmetohs(s->mtype) );
-printf( "mmv : %#x\n", s->mmv );
-
-
-
-
s++; /* skip the header */
pkt = (uchar *)s;
-
-
switch (mmetohs(proto))
{
case VS_UPDATE_START_REQ:
#ifdef ET_DEBUG
- printf("Got VS_UPDATE_START_REQ");
+ printf("Got VS_UPDATE_START_REQ\n");
#endif
vs_update_start_req = (VsUpdStartReq_t *)pkt;
-
-printf("version_id = %#x\n", vs_update_start_req->version_id);
-printf("arch = %#x\n", vs_update_start_req->arch);
-printf("upd_type = %#x\n", vs_update_start_req->upd_type);
+#ifdef ET_DEBUG
+ printf("version_id = %#x\n", vs_update_start_req->version_id);
+ printf("arch = %#x\n", vs_update_start_req->arch);
+ printf("upd_type = %#x\n", vs_update_start_req->upd_type);
+#endif
@@ -379,8 +337,6 @@ printf("upd_type = %#x\n", vs_update_start_req->upd_type);
"Update type not supported.\n" );
vs_update_start_cnf->start_update = SPIDUPD_BAD_UPD_TYPE;
-
-printf( "start_update set to : %#x\n", vs_update_start_cnf->start_update );
}
else
{
@@ -399,15 +355,15 @@ printf( "start_update set to : %#x\n", vs_update_start_cnf->start_update );
case VS_UPDATE_TRANSFER_REQ:
#ifdef ET_DEBUG
- printf("Got VS_UPDATE_TRANSFER_REQ");
+ printf("Got VS_UPDATE_TRANSFER_REQ\n");
#endif
vs_update_transfer_req = (VsUpdTransfReq_t *)pkt;
-
-printf("received_block = %#x\n", received_block);
-printf("block_id = %#x\n", mmetohl(vs_update_transfer_req->block_id) );
-printf("length = %d\n", mmetohl(vs_update_transfer_req->length) );
-
+#ifdef ET_DEBUG
+ printf("received_block = %#x\n", received_block);
+ printf("block_id = %#x\n", mmetohl(vs_update_transfer_req->block_id) );
+ printf("length = %d\n", mmetohl(vs_update_transfer_req->length) );
+#endif
if (SpidupdState == STATE_WAIT_UPD_TRANSFER)
@@ -426,6 +382,12 @@ printf("length = %d\n", mmetohl(vs_update_transfer_req->length) );
}
else /* OK, we received block we expected */
{
+ /* give a small visual indication */
+ if ( (received_block % 50) == 0 )
+ printf("D");
+ if ( (received_block != 0) && ( (received_block % 2500) == 0 ) )
+ printf("\n");
+
/* put block in RAM */
memcpy ( UPD_IMG_RAM_ADDR + upd_img_len,
vs_update_transfer_req->data,
@@ -438,7 +400,7 @@ printf("length = %d\n", mmetohl(vs_update_transfer_req->length) );
/* we sucesfully received block, increment received counter */
received_block++;
- vs_update_transfer_cnf->ack = SPIDUPD_SUCESS;
+ vs_update_transfer_cnf->ack = SPIDUPD_SUCCESS;
/* REMEMBER: block IDs are starting from 1, not from 0.
* That means that received_block number is also
@@ -459,12 +421,13 @@ printf("length = %d\n", mmetohl(vs_update_transfer_req->length) );
case VS_UPDATE_END_REQ:
#ifdef ET_DEBUG
- printf("Got VS_UPDATE_END_REQ");
+ printf("Got VS_UPDATE_END_REQ\n");
#endif
vs_update_end_req = (VsUpdEndReq_t *)pkt;
if (SpidupdState == STATE_WAIT_UPD_TRANSFER)
{
+ printf("|\n");
memcpy (md5_client, vs_update_end_req->md5_sum, 16);
md5_image( (md5_byte_t *)md5_server );
@@ -495,9 +458,9 @@ printf("length = %d\n", mmetohl(vs_update_transfer_req->length) );
}
else /* MD5 sum OK */
{
- printf("MD5 sum OK, will burn image.");
+ printf("MD5 sum OK, will burn image...\n");
/* write that image is valid to descriptors */
- NetSetTimeout (TIMEOUT * CFG_HZ, SpidupdTimeout);
+ NetSetTimeout (FLASH_WRITE_TIMEOUT * CFG_HZ, SpidupdTimeout);
if ( store_img() != ERR_OK )
{
/* error writing flash */
@@ -514,8 +477,8 @@ printf("length = %d\n", mmetohl(vs_update_transfer_req->length) );
}
else /* flash write OK */
{
- printf ("Update image sucessfully written to flash.\n");
- vs_update_end_cnf->result = SPIDUPD_SUCESS;
+ printf ("Update image successfully written to flash.\n");
+ vs_update_end_cnf->result = SPIDUPD_SUCCESS;
NetBootFileXferSize = upd_img_len;
@@ -543,21 +506,40 @@ printf("length = %d\n", mmetohl(vs_update_transfer_req->length) );
* the client for the next one.
*/
-printf ("Calling SpidupdSend()...\n");
-
SpidupdSend ();
}
static void
SpidupdTimeout (void)
{
- if (++SpidupdTimeoutCount > TIMEOUT_COUNT) {
- puts ("\nSPIDUPD retry count exceeded; starting again\n");
- NetStartAgain ();
- } else {
+ if (++SpidupdTimeoutCount > TIMEOUT_COUNT)
+ {
+
+ printf ("Timeout error : no response from the client.\n");
+
+ /* TIMEOUT occured - abort or restart the update operation */
+ if (img_is_valid == 0)
+ {
+ /*
+ * We have no valid image anymore!
+ * We must start update again!
+ */
+ NetState = NETLOOP_SUCCESS;
+ }
+ else
+ {
+ /* We did not suceed with update,
+ * but we did not corrupted old image.
+ * Bail out of NetLoop
+ * and boot old image
+ */
+ NetState = NETLOOP_FAIL;
+ }
+ } else
+ {
puts ("T ");
NetSetTimeout (TIMEOUT * CFG_HZ, SpidupdTimeout);
- //SpidupdSend ();
+ SpidupdSend ();
}
}
@@ -581,7 +563,7 @@ SpidupdStart (void)
printf ("Load address: 0x%lx\n", load_addr);
- puts ("Loading: *\b");
+ puts (">>> SPIDUPD server started <<<\n");
NetSetTimeout (TIMEOUT * CFG_HZ, SpidupdTimeout);
NetSetHandler (SpidupdHandler);
@@ -594,8 +576,6 @@ SpidupdStart (void)
SpidupdTimeoutCount = 0;
SpidupdState = STATE_WAIT_UPD_START;
NextSpidupdState = STATE_WAIT_UPD_START;
-
- /* zero out server ether in case the server ip has changed */
}
#endif /* CFG_CMD_NET */
diff --git a/cleopatre/u-boot-1.1.6/net/spidupd.h b/cleopatre/u-boot-1.1.6/net/spidupd.h
index 7eb073cab5..8dd66f98bd 100644
--- a/cleopatre/u-boot-1.1.6/net/spidupd.h
+++ b/cleopatre/u-boot-1.1.6/net/spidupd.h
@@ -65,7 +65,7 @@ typedef struct
typedef struct
{
- unsigned char start_update; /* 0 - sucess, 0x1..0x5 - error messages */
+ unsigned char start_update; /* 0 - success, 0x1..0x5 - error messages */
} __attribute__ ((__packed__)) VsUpdStartCnf_t;
typedef struct
@@ -77,23 +77,23 @@ typedef struct
typedef struct
{
- unsigned char ack; /* 0 - sucess, 0x1 - failure */
+ unsigned char ack; /* 0 - success, 0x1 - failure */
unsigned int next_block; /* next block ID that server expects */
} __attribute__ ((__packed__)) VsUpdTransfCnf_t;
typedef struct
{
- unsigned char md5_sum[16]; /* 0 - sucess, 0x1 - failure */
+ unsigned char md5_sum[16]; /* 0 - success, 0x1 - failure */
} __attribute__ ((__packed__)) VsUpdEndReq_t;
typedef struct
{
- unsigned char result; /* 0 - sucess, 0x1 - failure */
+ unsigned char result; /* 0 - success, 0x1 - failure */
} __attribute__ ((__packed__)) VsUpdEndCnf_t;
typedef struct
{
- unsigned char result; /* 0 - sucess, 0x1..0x2 - error messages */
+ unsigned char result; /* 0 - success, 0x1..0x2 - error messages */
} __attribute__ ((__packed__)) VsUpdEndInd_t;
@@ -106,7 +106,7 @@ typedef struct
#define SPIDUPD_MODEM_BUSY 0x04
/* tansfer_cnf and end_cnf */
-#define SPIDUPD_SUCESS 0x00
+#define SPIDUPD_SUCCESS 0x00
#define SPIDUPD_FAILURE 0x01
/* end_cnf */
@@ -114,7 +114,7 @@ typedef struct
#define SPIDUPD_FLASH_WRITE_ERROR 0x02
/* end_ind */
-#define SPIDUPD_FLASH_WRITE_TOUT 0x02
+#define SPIDUPD_FLASH_WRITE_TOUT 0x03
diff --git a/cleopatre/u-boot-1.1.6/test/spidupd_test/spidupd_test.c b/cleopatre/u-boot-1.1.6/test/spidupd_test/spidupd_test.c
index 0e10344c66..b7505ced19 100644
--- a/cleopatre/u-boot-1.1.6/test/spidupd_test/spidupd_test.c
+++ b/cleopatre/u-boot-1.1.6/test/spidupd_test/spidupd_test.c
@@ -41,16 +41,15 @@
#define SRC_ETHER_ADDR "00:11:95:dc:d1:3f"
#define DST_ETHER_ADDR "00:50:c2:38:00:0B"
-#define PROT_SPIDUPD 0x88E1 /* MME Ethertype (SPiDCOM Update) */
-#define RCV_TIMEOUT 5 /* receive timeout in seconds */
+#define PROT_SPIDUPD 0x88E1 /* MME Ethertype (SPiDCOM Update) */
+#define SRV_CNF_TIMEOUT 5 /* server response timeout in seconds */
+#define SRV_TIMEOUT_ERR_CODE -111 /* arbitrary chosen error code for server timeout event */
+
+#define MAX_TMO_RETRY 5 /* Number of retries in case of server response timeout */
+#define MAX_TMO_END_RETRY 120 /* Wait a little longer for UPDATE_END_CNF, because it takes time to write flash */
+#define MAX_PKT_RETRY 5 /* Number of retries in case of server not ack the package */
+
-/* SPIDUPD message primitives */
-static VsUpdStartReq_t *vs_update_start_req;
-static VsUpdStartCnf_t *vs_update_start_cnf;
-static VsUpdTransfReq_t *vs_update_transfer_req;
-static VsUpdTransfCnf_t *vs_update_transfer_cnf;
-static VsUpdEndReq_t *vs_update_end_req;
-static VsUpdEndCnf_t *vs_update_end_cnf;
static void sprintf_hex(unsigned char * str, const unsigned char * ptr,
int len, unsigned char delim)
@@ -86,9 +85,7 @@ int GetMacAddr (char *device, int rawsock, unsigned char our_addr[6])
for( i = 0; i < 6; i++ )
{
our_addr[i] = (unsigned char)ifr.ifr_hwaddr.sa_data[i];
- printf("%.2x ", our_addr[i]);
}
- printf("\n");
return 0;
}
@@ -141,7 +138,6 @@ int BindRawSocketToInterface(char *device, int rawsock, int protocol)
int SendRawPacket(int rawsock, unsigned char *pkt, int pkt_len)
{
int sent= 0;
- printf("Packet len: %d\n", pkt_len);
/* A simple write on the socket ..thats all it takes ! */
if((sent = write(rawsock, pkt, pkt_len)) != pkt_len)
@@ -235,31 +231,80 @@ int ListenSocket(int raw)
int len;
struct sockaddr_ll packet_info;
int packet_info_size = sizeof(packet_info);
- MME_t s;
+ MME_t *s;
+ int res;
+
+ fd_set readset;
+ struct timeval srv_cnf_timeout;
+
+ int rc;
+
+ VsUpdStartCnf_t *vs_update_start_cnf;
+ VsUpdTransfCnf_t *vs_update_transfer_cnf;
+ VsUpdEndCnf_t *vs_update_end_cnf;
packet_buffer = (unsigned char *)calloc(PKTSIZE, sizeof(char));
pkt_start= packet_buffer;
- /* Set socket receive timeout */
- SetSocketTimeout(raw, RCV_TIMEOUT*1000);
+ /*
+ * check for socket timeout
+ */
+ FD_ZERO(&readset);
+ FD_SET(raw, &readset);
+ srv_cnf_timeout.tv_sec = SRV_CNF_TIMEOUT;
+ srv_cnf_timeout.tv_usec = 0;
+
+ /* readset fd_set is containing only our socket, so no need to check with FD_ISSET() */
+ res = select(raw + 1, &readset, NULL, NULL, &srv_cnf_timeout);
+ if (res < 0)
+ {
+ perror("select() failed");
+ }
+ else if (res == 0) /* timeout */
+ {
+ //printf("Server response timeout.\n");
+ rc = SRV_TIMEOUT_ERR_CODE;
+ }
+ else /* everything is cool, socket is ready for reading */
+ {
- if( ( len = recvfrom(raw, packet_buffer, PKTSIZE, 0, (struct sockaddr*)&packet_info, &packet_info_size) ) < 0 )
- {
- perror("Recv from returned error: ");
- exit(-1);
- }
- else
- {
- /* Packet has been received successfully !! */
- PrintPacketInHex(packet_buffer, len);
- }
+ if( ( len = recvfrom(raw, packet_buffer, PKTSIZE, 0, (struct sockaddr*)&packet_info, &packet_info_size) ) < 0 )
+ {
+ perror("Recv from returned error: ");
+ exit(-1);
+ }
+ else
+ {
+ /* Packet has been received successfully !! */
+ //PrintPacketInHex(packet_buffer, len);
+ }
- //packet_buffer += MME_HDR_SIZE;
- packet_buffer += sizeof(s);
+ s = (MME_t *)packet_buffer;
+ packet_buffer += MME_HDR_SIZE;
- vs_update_start_cnf = (VsUpdStartCnf_t *)packet_buffer;
+ switch ( mmetohs(s->mmtype) )
+ {
+ case VS_UPDATE_START_CNF :
+ vs_update_start_cnf = (VsUpdStartCnf_t *)packet_buffer;
+ rc = vs_update_start_cnf->start_update;
+ break;
+
+ case VS_UPDATE_TRANSFER_CNF :
+ vs_update_transfer_cnf = (VsUpdTransfCnf_t *)packet_buffer;
+ rc = vs_update_transfer_cnf->ack;
+ break;
+
+ case VS_UPDATE_END_CNF :
+ vs_update_end_cnf = (VsUpdEndCnf_t *)packet_buffer;
+ rc = vs_update_end_cnf->result;
+ break;
+
+ deafault :
+ break;
+ }
+ }
- return vs_update_start_cnf->start_update;
+ return rc;
}
/* argv[1] is the device e.g. eth0 */
@@ -283,6 +328,17 @@ main(int argc, char **argv)
MD5_CTX ctx;
int read_bytes;
int i;
+ int pkt_retry = 0;
+ int tmo_retry = 0;
+ int res;
+
+ static VsUpdStartReq_t *vs_update_start_req;
+ static VsUpdTransfReq_t *vs_update_transfer_req;
+ static VsUpdEndReq_t *vs_update_end_req;
+
+
+
+
/* Create the raw socket */
raw = CreateRawSocket(ETH_P_ALL);
@@ -329,36 +385,63 @@ main(int argc, char **argv)
/*Detertermine total packet length */
pkt_len = packet - pkt_start;
- /* Position packet pointer to strt of tyhe packet,
- and send the packet */
+ /* Position packet pointer to strt of the packet */
packet = pkt_start;
- if(!SendRawPacket(raw, packet, pkt_len))
- {
- perror("Error sending packet");
- }
- else
- printf("Packet sent successfully\n");
- if ( ListenSocket(raw) != SPIDUPD_SUCESS )
+
+ /* if packet is not acknowledged ot it is timed out,
+ * try several times to re-send same packet */
+ printf("Requesting update start... ");
+ fflush(stdout);
+ tmo_retry = MAX_TMO_RETRY;
+ while (tmo_retry > 0)
{
- perror("Cannot start update.");
+ if(!SendRawPacket(raw, packet, pkt_len))
+ {
+ perror("Error sending packet");
+ }
+ else
+ //printf("Requested update start...");
+
+ if ( ( res = ListenSocket(raw) ) == SRV_TIMEOUT_ERR_CODE )
+ {
+ tmo_retry--;
+ continue;
+ }
+ else if (res != SPIDUPD_SUCCESS)
+ {
+ printf("Error - Cannot start update.\n");
+ exit(-1);
+ }
+ else /* success */
+ {
+ printf("OK\n");
+ break;
+ }
+ }
+
+ if (tmo_retry == 0)
+ {
+ printf("\nTimeout error : no response from the server.\n");
+ exit(-1);
}
/*
* VS_UPDATE_TRANSFER_REQ
*/
- //pImgFile = fopen("linux-kernel-2.6.25.10-arm", "r");
- pImgFile = fopen("test.bin", "r");
+ pImgFile = fopen("linux-kernel-2.6.25.10-arm", "r");
+ //pImgFile = fopen("test.bin", "r");
read_bytes = fread (tmp_buffer, 1 , SPIDUPD_BLOCK_SIZE, pImgFile);
/* init md5 context before we start calculating md5_sum
* we will need md5 sum to send in the end */
MD5_Init(&ctx);
+ printf("Uploading Linux image :\n");
+
do
{
-
/* We are about to send new block */
block_counter++;
@@ -392,24 +475,68 @@ main(int argc, char **argv)
/*Detertermine total packet length */
pkt_len = packet - pkt_start;
- /* Position packet pointer to strt of tyhe packet,
- and send the packet */
+ /* Position packet pointer to strt of the packet */
packet = pkt_start;
- if(!SendRawPacket(raw, packet, pkt_len))
+
+ /* if packet is not acknowledged ot it is timed out,
+ * try several times to re-send same packet */
+ tmo_retry = MAX_TMO_RETRY;
+ pkt_retry = MAX_PKT_RETRY;
+ while ( (tmo_retry > 0) && (pkt_retry > 0) )
{
- perror("Error sending packet");
+ if(!SendRawPacket(raw, packet, pkt_len))
+ {
+ perror("Error sending packet");
+ }
+ else
+ {
+ if ( (block_counter % 50) == 0 )
+ {
+ printf("#");
+ fflush(stdout);
+ }
+
+ if ( (block_counter % 2500) == 0 )
+ {
+ putchar('\n');
+ fflush(stdout);
+ }
+ }
+
+ if ( ( res = ListenSocket(raw) ) == SRV_TIMEOUT_ERR_CODE )
+ {
+ tmo_retry--;
+ continue;
+ }
+ else if (res != SPIDUPD_SUCCESS)
+ {
+ printf("Packet not acknowledged. ");
+
+ pkt_retry--;
+ continue;
+ }
+ else /* success */
+ {
+ break;
+ }
+ }
+
+ if (tmo_retry == 0)
+ {
+ printf("timeout error : no response from the server.\n");
+ exit(-1);
}
- else
- printf("Packet sent successfully\n");
-
- if ( ListenSocket(raw) != SPIDUPD_SUCESS )
+ if (pkt_retry == 0)
{
- perror("Cannot do transfer.");
+ printf("Maximum number of packet retries exceeded.\n");
+ exit(-1);
}
} while ( (read_bytes = fread (tmp_buffer, 1 , SPIDUPD_BLOCK_SIZE, pImgFile) ) > 0 );
+ printf("\nDone.\n");
+
/* Get final md5 */
MD5_Final(md5_sum, &ctx);
@@ -445,18 +572,48 @@ main(int argc, char **argv)
and send the packet */
packet = pkt_start;
- if(!SendRawPacket(raw, packet, pkt_len))
- {
- perror("Error sending packet");
- }
- else
- printf("Packet sent successfully\n");
+ /* if packet is not timed-out try several times to re-send same packet */
+ printf("Waiting on the server to burn image on flash :\n");
+ fflush(stdout);
+ tmo_retry = MAX_TMO_END_RETRY;
+ while (tmo_retry > 0)
+ {
+ if(!SendRawPacket(raw, packet, pkt_len))
+ {
+ perror("Error sending packet");
+ }
+ else
+ //printf("UPD_END_REQ sent : ");
- if ( ListenSocket(raw) != SPIDUPD_SUCESS )
+
+ if ( ( res = ListenSocket(raw) ) == SRV_TIMEOUT_ERR_CODE )
+ {
+ printf(">");
+ fflush(stdout);
+ tmo_retry--;
+ continue;
+ }
+ else if (res != SPIDUPD_SUCCESS)
+ {
+ printf("Error - Cannot finish update.\n");
+ exit(-1);
+ }
+ else /* success */
+ {
+ printf("| Done.\n");
+ break;
+ }
+ }
+
+ if (tmo_retry == 0)
{
- perror("Cannot end update.");
+ printf("Timeout error : no response from the server.\n");
+ exit(-1);
}
+ /* if we came this far, image was well updated */
+ printf("\nImage has been sucesfully updated.\n\n");
+
/* --- END OF MESSAGES --- */
/* Free the ethernet_header back to the heavenly heap */
diff --git a/cleopatre/u-boot-1.1.6/test/spidupd_test/spidupd_test.h b/cleopatre/u-boot-1.1.6/test/spidupd_test/spidupd_test.h
index 0872f63f67..66f9445f1c 100644
--- a/cleopatre/u-boot-1.1.6/test/spidupd_test/spidupd_test.h
+++ b/cleopatre/u-boot-1.1.6/test/spidupd_test/spidupd_test.h
@@ -139,7 +139,7 @@ typedef struct
#define SPIDUPD_MODEM_BUSY 0x04
/* tansfer_cnf and end_cnf */
-#define SPIDUPD_SUCESS 0x00
+#define SPIDUPD_SUCCESS 0x00
#define SPIDUPD_FAILURE 0x01
/* end_cnf */