summaryrefslogtreecommitdiff
path: root/cleopatre
diff options
context:
space:
mode:
authorsave2010-05-06 15:31:12 +0000
committersave2010-05-06 15:31:12 +0000
commit732b2f6ef7f449c45baa38fec866e63bd54e072f (patch)
treecb265adc1262fab6245976db2ad0a870bac77027 /cleopatre
parentc304753589b6122095ebfde22c2b2ff18c5c3638 (diff)
cleo/u-boot/spidboot: implement img_max_size NVRAM field on spidboot command
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@6984 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cleopatre')
-rw-r--r--cleopatre/u-boot-1.1.6/common/cmd_spidboot.c126
1 files changed, 40 insertions, 86 deletions
diff --git a/cleopatre/u-boot-1.1.6/common/cmd_spidboot.c b/cleopatre/u-boot-1.1.6/common/cmd_spidboot.c
index 08405e01a3..2b150b8ef8 100644
--- a/cleopatre/u-boot-1.1.6/common/cmd_spidboot.c
+++ b/cleopatre/u-boot-1.1.6/common/cmd_spidboot.c
@@ -335,19 +335,15 @@ static void update_origin_index(spidcom_image_desc_t *desc, char *addr, ulong in
flash_write( (char *)desc, (ulong)addr, sizeof(spidcom_image_desc_t) );
}
-static int select_image(int found_nb, int img_nb)
+static int select_image(int img_nb)
{
int sel_img = -1; /* will hold the index of selected image */
spidcom_image_desc_t *desc;
int img_state[MAX_IMG] = {0};
ulong max_index = 0;
int i;
- int bnb = 0; /* number of bootable images */
- int bmnb = 0; /* number of images with BAD_MAGIC_NUMBER */
- bmnb = img_nb - found_nb; /* the ones that we did not found on flash-scan */
-
- for (i=0; i<found_nb; i++)
+ for (i=0; i<img_nb; i++)
{
desc = &img_desc[i];
load_header(desc, (char *)img_addr[i]);
@@ -362,17 +358,14 @@ static int select_image(int found_nb, int img_nb)
max_index = desc->index;
sel_img = i;
}
- bnb++;
break;
case IMAGE_OK_ORIGIN:
printf("IMG at address %#x is OK.\n", img_addr[i]);
- bnb++;
break;
case BAD_MAGIC_NUMBER:
printf("IMG at address %#x is not OK (bad magic number).\n", img_addr[i]);
- bmnb++; /* IMG_0 is always found, but can have BAD_MAGIC_NUMBER */
break;
case WRONG_IMAGE_ARCH:
@@ -401,7 +394,7 @@ static int select_image(int found_nb, int img_nb)
}
/* Check a JTAG image, cause it will be better to boot it */
- for (i=0; i<found_nb; i++)
+ for (i=0; i<img_nb; i++)
{
if(img_state[i] == IMAGE_OK_ORIGIN)
{
@@ -411,16 +404,10 @@ static int select_image(int found_nb, int img_nb)
}
}
- if (found_nb < img_nb)
- {
- printf("%d system images found : %d bootable images and "
- "%d unbootable images (of which %d images have BAD_MAGIC_NUMBER)\n",
- img_nb, bnb, img_nb - bnb, bmnb);
- }
return sel_img;
}
-static int
+static ulong
find_nb_images (void)
{
spc300_nvram_t *nvram = (spc300_nvram_t *)(gd->bd->bi_nvram_addr);
@@ -429,66 +416,22 @@ find_nb_images (void)
return nvram->nb_images;
}
-static int
-find_images(int img_nb)
+static ulong
+find_image_start_addr (void)
{
- flash_info_t *flinfo = &( flash_info[0] ); /* we expect HW to have only one flash, thus only one flinfo */
- char img_magic[8]; /* to match with magic number = "SPIDIMG\0" */
- int i = 0;
- spc300_nvram_t *nvram = NULL;
- int sect = 0;
-
- nvram = (spc300_nvram_t *)(gd->bd->bi_nvram_addr);
-
- /* we know addr of IMG_0, even if it has bad magic word */
- img_addr[0] = PHYS_FLASH_SPI_1 + nvram->img_0_offset;
-#if defined(CONFIG_ARCH_ARIZONA) && !defined(CONFIG_EXEC_FROM_SPI)
- img_addr[0] -= 0x78000000; /* FCM3 fix when executed from Flash NOR -- remove later!!! */
-#endif /* CONFIG_EXEC_FROM_SPI */
- 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)
- {
- if (flinfo->start[sect] <= PHYS_FLASH_SPI_1 + nvram->img_0_offset)
- continue;
-
- /* read 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 : read from SPI flash failed.\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! */
- img_addr[i] = flinfo->start[sect];
+ spc300_nvram_t *nvram = (spc300_nvram_t *)(gd->bd->bi_nvram_addr);
-#if defined(CONFIG_ARCH_ARIZONA) && !defined(CONFIG_EXEC_FROM_SPI)
- img_addr[i] -= 0x78000000; /* FCM3 fix when executed from Flash NOR -- remove later!!! */
-#endif /* CONFIG_EXEC_FROM_SPI */
+ /* We can use SPI Direct Access because nb_images is a uint32_t */
+ return PHYS_FLASH_SPI_1 + nvram->img_0_offset;
+}
- i++; /* number of images found, and index for next image */
+static ulong
+find_image_max_size (void)
+{
+ spc300_nvram_t *nvram = (spc300_nvram_t *)(gd->bd->bi_nvram_addr);
- /* check if we found all images */
- if (i == img_nb)
- {
- break;
- }
- }
- } /* for */
- return i;
+ /* We can use SPI Direct Access because nb_images is a uint32_t */
+ return nvram->img_max_size;
}
int do_spidboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
@@ -496,14 +439,16 @@ int do_spidboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
ulong addr;
ulong data, len;
int verify;
+ int i;
char *s;
void (*appl)(int zero, int arch, uint params);
spidcom_image_desc_t *hdr = NULL;
int use_spi_flash = 0;
char *img_load_addr = NULL;
bd_t *bd = gd->bd;
- int img_nb = 0;
- int found_nb = 0;
+ ulong img_nb = 0;
+ ulong img_0_addr;
+ ulong img_max_size;
int sel_img = -1; /* image selected for boot after all the checks */
#ifdef CONFIG_CMDLINE_TAG
@@ -521,21 +466,31 @@ int do_spidboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
s = getenv ("verify");
verify = (s && (*s == 'n')) ? 0 : 1;
- img_nb = find_nb_images();
-
if (argc < 2) /* no address was given - normal multiboot */
{
+ img_nb = find_nb_images();
+ img_max_size = find_image_max_size();
+ img_0_addr = find_image_start_addr();
+
+ if(img_max_size == 0xFFFFFFFF)
+ {
+ /* max_size unknown force mapping to one image */
+ img_nb = 1;
+ img_max_size = flash_info[0].size + PHYS_FLASH_SPI_1 - img_0_addr;
+
+ }
+
+ for(i=0 ; i < img_nb ; i++)
+ {
+ img_addr[i] = (img_max_size * i) + img_0_addr;
+ }
+
while(sel_img < 0)
{
/* give a chance of 1sec timeout for user to initiate the update */
do_spidupd();
- found_nb = find_images(img_nb);
- if ( found_nb == 0 )
- {
- continue;
- }
- sel_img = select_image(found_nb, img_nb);
+ sel_img = select_image(img_nb);
if ( ctrlc() )
{
return -1;
@@ -544,8 +499,6 @@ int do_spidboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
addr = img_addr[sel_img];
hdr = &img_desc[sel_img];
-
- printf("Selecting IMG at address %#x.\n", addr);
}
else
{
@@ -553,6 +506,7 @@ int do_spidboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
* we are in the single boot mode;
* we are also in developer mode, trying to force the boot of
* chosen image => we will not call do_update() here */
+ sel_img = 0;
addr = simple_strtoul(argv[1], NULL, 16);
hdr = &img_desc[0]; /* we will use img_0_desc structure for single boot */
load_header(hdr, (char *)addr);
@@ -561,7 +515,7 @@ int do_spidboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
* selected image => we will not check it's validity */
}
- printf ("## Booting image at %08lx ...\n", addr);
+ printf ("## Booting image at 0x%08lx ...\n", addr);
/* do the image transfer */
data = (int)addr + sizeof(spidcom_image_desc_t);