summaryrefslogtreecommitdiff
path: root/cleopatre/u-boot-1.1.6/net
diff options
context:
space:
mode:
authordraskovic2009-03-17 17:12:58 +0000
committerdraskovic2009-03-17 17:12:58 +0000
commitdd9bb36ed9440f1fed1f3d517dd9394f152651ee (patch)
treef1437a021de26bac16d14fc71aec4d37f16a3fe0 /cleopatre/u-boot-1.1.6/net
parentad15b5dd2105581d35fe10158e1f53516244a737 (diff)
[CLEO][U-BOOT]SPIDUPD update protocol implementation
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@4241 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cleopatre/u-boot-1.1.6/net')
-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
3 files changed, 125 insertions, 145 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