summaryrefslogtreecommitdiff
path: root/cleopatre/u-boot-1.1.6/net
diff options
context:
space:
mode:
authorsave2010-05-06 15:31:14 +0000
committersave2010-05-06 15:31:14 +0000
commit3d66eb17b5433ee4f3e51013535ef359dcc6695e (patch)
tree212fbf7a9866142ddc91e7293cf9ac65fa73c857 /cleopatre/u-boot-1.1.6/net
parent732b2f6ef7f449c45baa38fec866e63bd54e072f (diff)
cleo/u-boot/spidupd: implement img_max_size NVRAM field, refs #711
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@6985 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/spidupd.c116
1 files changed, 34 insertions, 82 deletions
diff --git a/cleopatre/u-boot-1.1.6/net/spidupd.c b/cleopatre/u-boot-1.1.6/net/spidupd.c
index a8dedff57b..704837b685 100644
--- a/cleopatre/u-boot-1.1.6/net/spidupd.c
+++ b/cleopatre/u-boot-1.1.6/net/spidupd.c
@@ -53,11 +53,6 @@
/** Max flash images allowed */
#define MAX_IMG 10
-/** Flash addresses of present images */
-static unsigned long img_addr[MAX_IMG] = {0};
-
-/** Size of a sImage type (Normal type */
-#define SIMG_FLASH_SIZE 0x360000
#if (CONFIG_COMMANDS & CFG_CMD_NET)
@@ -212,6 +207,21 @@ static int check_img(spidcom_image_desc_t *desc)
}
/**
+ * Find image max size.
+ *
+ * \param bd board info structure.
+ * \return image max size.
+ */
+static __inline__ ulong find_img_max_size(bd_t *bd)
+{
+ /* First image address is stored under NVRAM */
+ spc300_nvram_t *nvram = (spc300_nvram_t *)(bd->bi_nvram_addr);
+
+ /* We can use SPI Direct Access because image_max_size is a uint32_t */
+ return nvram->img_max_size;
+}
+
+/**
* Find Flash offset of image 0.
*
* \param bd board info structure.
@@ -242,73 +252,14 @@ static __inline__ ulong find_nb_images(bd_t* bd)
}
/**
- * Find Flash images addresses of already present images.
- *
- * \param img_nb number of allowed images in flash.
- * \param img_0_offset offset of flash images area.
- * \param addrs addresses of found images.
- * \return number of image found or -1 if error.
- */
-static int find_images(ulong img_nb, ulong img_0_addr, ulong addrs[])
-{
- flash_info_t *flinfo = &(flash_info[0]); /* we expect HW to have only one flash, thus only one flinfo */
- char img_magic[8];
- int i = 0; /* found image number */
- int sect = 0;
-
- /* we know addr of IMG_0, even if it has bad magic word */
- addrs[0] = img_0_addr;
- i++;
-
- /* if there is only one img_nb address is set to img_0_addr and we can return */
- if(img_nb == 1)
- {
- return 1;
- }
-
- /* Search for the "SPIDIMG\0" string on the beginning of the each sector */
- for(sect=0 ; sect<flinfo->sector_count ; ++sect)
- {
- /* Sector lower than images area -> continue */
- if(flinfo->start[sect] <= img_0_addr)
- continue;
-
- /* Copy beginning of the sector in local array variable */
- if(flash_read_spi((unsigned char *)flinfo->start[sect], (unsigned char *)img_magic, 8, 1, 0) != ERR_OK)
- {
- printf("Error (Flash Read).\n");
- return -1;
- }
- /* Compare this with magic word (for SPC300 that is "SPIDIMG\0") */
- if(memcmp(img_magic, SPIDCOM_IMG_DESC_MAGIC, 8) != 0)
- {
- continue;
- }
- else
- {
- /* Found it */
- addrs[i] = flinfo->start[sect];
-
- /* Number of images found, and index for next image */
- i++;
-
- /* Check if we found all images */
- if(i == img_nb)
- break;
- }
- }/* for */
- return i;
-}
-
-/**
* Choose the better update place.
*
* \param img_nb number of allowed images in flash.
- * \param addrs addresses of found images.
+ * \param img_max_size max size of an image.
* \param place update place information structure.
* \return error code.
*/
-static int select_image(int img_nb, ulong img_0_addr, ulong addrs[], struct update_place *place)
+static int select_image(int img_nb, ulong img_0_addr, ulong img_max_size, struct update_place *place)
{
spidcom_image_desc_t *desc = &g_img_desc;
int img_state;
@@ -330,7 +281,7 @@ static int select_image(int img_nb, ulong img_0_addr, ulong addrs[], struct upda
{
/* Copy the descriptor to RAM because SPI direct allows only
* 32bits access */
- load_header(desc, (uchar*)addrs[i]);
+ load_header(desc, (uchar*)(img_0_addr + (img_max_size * i)));
/* Check flash Image */
img_state = check_img(desc);
@@ -342,7 +293,7 @@ static int select_image(int img_nb, ulong img_0_addr, ulong addrs[], struct upda
{
case IMAGE_OK:
/* It's correct image */
- one_img_ok++;
+ one_img_ok = 1;
/* Smaller index -> select it */
if (desc->index <= min_index)
{
@@ -371,7 +322,7 @@ static int select_image(int img_nb, ulong img_0_addr, ulong addrs[], struct upda
/* It's a corrupt image */
if (sel_img_ko == -1) /* change sel_img_ko just first time */
{
- sel_img_ko = i; /* we are taking first currupt image for update candidate */
+ sel_img_ko = i; /* we are taking first corrupt image for update candidate */
}
}
}
@@ -391,7 +342,7 @@ static int select_image(int img_nb, ulong img_0_addr, ulong addrs[], struct upda
if(sel_img_ko != -1)
{
- place->flash_addr = (sel_img_ko * SIMG_FLASH_SIZE) + img_0_addr;
+ place->flash_addr = (sel_img_ko * img_max_size) + img_0_addr;
return 0;
}
else if(sel_img_ok != -1)
@@ -402,12 +353,12 @@ static int select_image(int img_nb, ulong img_0_addr, ulong addrs[], struct upda
/* update index will be 0 */
place->index = 0;
}
- place->flash_addr = (sel_img_ok * SIMG_FLASH_SIZE) + img_0_addr;
+ place->flash_addr = (sel_img_ok * img_max_size) + img_0_addr;
return 0;
}
else if(sel_img_or != -1)
{
- place->flash_addr = (sel_img_or * SIMG_FLASH_SIZE) + img_0_addr;
+ place->flash_addr = (sel_img_or * img_max_size) + img_0_addr;
return 0;
}
/* Never use */
@@ -947,32 +898,33 @@ void SpidupdStart(void)
DECLARE_GLOBAL_DATA_PTR;
ulong nb_img;
ulong img_0_addr;
- int i;
+ ulong img_max_size;
/* Flush caches just to be sure */
flush_caches();
puts("SPiDUpdate...");
- /* Clear an eventually previous call */
- for(i=0 ; i<MAX_IMG ; i++)
- img_addr[i] = 0;
-
/* Prepare Networking Handler and timeout */
NetSetTimeout(TIMEOUT * CFG_HZ, SpidupdTimeout);
NetSetHandler(SpidupdHandler);
- /* Find number of allowed places under flash */
+ /* Find number of allowed places on flash */
nb_img = find_nb_images(gd->bd);
+ if(nb_img > MAX_IMG)
+ {
+ printf("Max allowed images is %d\n", MAX_IMG);
+ nb_img = MAX_IMG;
+ }
- /* Find the first image offset under flash */
+ /* Find the first image offset on flash */
img_0_addr = PHYS_FLASH_SPI_1 + find_img_1st_offset(gd->bd);
- /* Find addresses of already present images */
- find_images(nb_img, img_0_addr, img_addr);
+ /* Find max image size */
+ img_max_size = find_img_max_size(gd->bd);
/* Find better place to update a new image */
- select_image(nb_img, img_0_addr, img_addr, &g_upd_place);
+ select_image(nb_img, img_0_addr, img_max_size, &g_upd_place);
/* Reset globals */
g_upd_place.nb_img = nb_img;