summaryrefslogtreecommitdiff
path: root/cleopatre/u-boot-1.1.6
diff options
context:
space:
mode:
Diffstat (limited to 'cleopatre/u-boot-1.1.6')
-rw-r--r--cleopatre/u-boot-1.1.6/net/spidupd.c65
1 files changed, 60 insertions, 5 deletions
diff --git a/cleopatre/u-boot-1.1.6/net/spidupd.c b/cleopatre/u-boot-1.1.6/net/spidupd.c
index c4162e10f1..16d77f89d5 100644
--- a/cleopatre/u-boot-1.1.6/net/spidupd.c
+++ b/cleopatre/u-boot-1.1.6/net/spidupd.c
@@ -81,6 +81,8 @@ struct update_place {
ulong ram_addr;
ulong index;
ulong nb_img;
+ ulong img_0_addr;
+ ulong img_max_size;
ulong correct_img_exist;
ulong correct_type;
ulong correct_archi;
@@ -272,7 +274,7 @@ static int select_image(int img_nb, ulong img_0_addr, ulong img_max_size, struct
int sel_img_or = -1;
int sel_img_ko = -1;
int one_img_ok = 0;
- int i, j;
+ int i;
place->correct_img_exist = 0;
@@ -280,7 +282,7 @@ static int select_image(int img_nb, ulong img_0_addr, ulong img_max_size, struct
for(i=0 ; i<MAX_IMG ; i++)
place->versions[i][0] = '\0';
- for(i=0, j=0 ; i<img_nb ; i++)
+ for(i=0 ; i<img_nb ; i++)
{
/* Copy the descriptor to RAM because SPI direct allows only
* 32bits access */
@@ -313,7 +315,7 @@ static int select_image(int img_nb, ulong img_0_addr, ulong img_max_size, struct
place->correct_type = desc->type;
place->correct_archi = desc->arch;
/* Store the version */
- strncpy(place->versions[j++], desc->version, 16);
+ strncpy(place->versions[i], desc->version, 16);
break;
case IMAGE_OK_ORIGIN:
@@ -387,7 +389,7 @@ static int store_img(void)
* which demands first parameter to be on sector boundary, and the second actually last addr in some sector.
* We have to find last adress of the last sector that holds our image.
* Note: if we write 0x360000 bytes long image to address 0x140000
- * last addr will be 49ffff (0x14000 + 0x35ffff), not 0x4a0000 (0x14000 + 0x360000)
+ * last addr will be 49ffff (0x140000 + 0x35ffff), not 0x4a0000 (0x14000 + 0x360000)
*/
if( place->flash_addr + image->len > flinfo->start[0] + flinfo->size )
@@ -458,6 +460,43 @@ static int store_img(void)
return rc;
}
+/**
+ * Update the index of a image already present in flash.
+ *
+ * \param num image number.
+ * \return error code.
+ */
+static int update_img_index(ulong num)
+{
+ flash_info_t *flinfo = &(flash_info[0]);
+ struct update_image *image = ctx.image;
+ struct update_place *place = ctx.place;
+ ulong i;
+
+ place->flash_addr = (num * place->img_max_size) + place->img_0_addr;
+ image->len = sizeof(spidcom_image_desc_t);
+
+ for(i=0 ; ((flinfo->start[i] < place->flash_addr + sizeof(spidcom_image_desc_t)) &&
+ (i < flinfo->sector_count)) ; i++);
+
+ if(i == flinfo->sector_count)
+ image->len = (flinfo->start[0] + flinfo->size) - place->flash_addr;
+ else
+ image->len = flinfo->start[i] - place->flash_addr;
+
+ /* copy image header in ram word by word */
+ for(i=0 ; i < (image->len/4) ; i++)
+ {
+ *(((ulong*)(place->ram_addr))+i) = *(((ulong*)(place->flash_addr))+i);
+ }
+
+ /* change index */
+ ((spidcom_image_desc_t *)place->ram_addr)->index = place->index;
+
+ /* copy header in flash */
+ return store_img();
+}
+
/*
* MD5 functions
*/
@@ -708,12 +747,26 @@ static void SpidupdHandler(uchar *pkt, unsigned dest, unsigned src, unsigned len
break;
}
+ if(vs_update_start_req->version[0] == '0')
+ {
+ printf("Error (Bad Version).\n" );
+ ctx.modem_busy = 0;
+ ctx.start_cnf.start_update = SPIDUPD_BAD_VERSION;
+ ctx.state = STATE_UPD_START;
+ break;
+ }
+
+ NetSetTimeout((ulong)(FLASH_WRITE_TOUT * CFG_HZ), SpidupdTimeout);
+
/* if we already have valid image with the same version, don't update it */
for(i=0 ; i<place->nb_img ; i++)
{
if(strcmp(place->versions[i], (char*)vs_update_start_req->version) == 0)
{
- printf("Error (Same Version).\n" );
+ printf("Same Version, only update index.\n" );
+
+ update_img_index(i);
+
ctx.modem_busy = 0;
ctx.start_cnf.start_update = SPIDUPD_BAD_VERSION;
ctx.state = STATE_UPD_START;
@@ -925,6 +978,8 @@ void SpidupdStart(void)
/* Reset globals */
g_upd_place.nb_img = nb_img;
+ g_upd_place.img_0_addr = img_0_addr;
+ g_upd_place.img_max_size = img_max_size;
/* We will use free space in SDRAM to temporary store incoming image packets,
* before copying it to flash when all image packets are collected.
* Begining address will be right after u-boot image, _bss_end + 1, but aligned to 4 byte boundary */