summaryrefslogtreecommitdiff
path: root/cleopatre/u-boot-1.1.6/common
diff options
context:
space:
mode:
authorJérémy Dufour2012-11-19 14:53:01 +0100
committerJérémy Dufour2012-11-21 17:10:03 +0100
commit8ed0ce42d28896b083acec8a759c58152021c6d4 (patch)
tree03aeef31d3d46734cc2eb426d220d7b07bfd2841 /cleopatre/u-boot-1.1.6/common
parent15a6f2660cf247a8c86b15e64fcbfe75b91d9b37 (diff)
cleo/uboot: use new spidcom image descriptor in spid{boot,update}, refs #3452
This commit uses the new spidcom image descriptor format. It also adds support for the SPC200C (arch, version). It also adds a sanity check in spidboot to return an error if the image is invalid (rather than ignoring it).
Diffstat (limited to 'cleopatre/u-boot-1.1.6/common')
-rw-r--r--cleopatre/u-boot-1.1.6/common/cmd_spidboot.c157
1 files changed, 105 insertions, 52 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 4c351e93e8..cda1a5e2f7 100644
--- a/cleopatre/u-boot-1.1.6/common/cmd_spidboot.c
+++ b/cleopatre/u-boot-1.1.6/common/cmd_spidboot.c
@@ -50,7 +50,7 @@ extern void flush_dcache(void);
#define MAX_IMG 10 /* supported num of images */
static unsigned long img_addr[MAX_IMG] = {0};
-static spidcom_image_desc_t img_desc[MAX_IMG];
+static spidcom_image_desc_generic_t img_desc[MAX_IMG];
#define LINUX_LOAD_ADDR (char *)0x40008000
@@ -131,14 +131,17 @@ static void setup_commandline_tag (bd_t *bd, char *commandline)
#ifdef CONFIG_SPC300_TAG
-void setup_spc300_tag (bd_t *bd, spidcom_image_desc_t *hdr, struct tag **tmp)
+void setup_spc300_tag (bd_t *bd, spidcom_image_desc_generic_t *hdr, struct tag **tmp)
{
struct tag *params = *tmp;
params->hdr.tag = ATAG_SPC300;
params->hdr.size = tag_size(tag_spc300);
params->u.spc300.nvram_offset = bd->bi_nvram_addr - PHYS_FLASH_SPI_1;
- params->u.spc300.plc_mem_size = hdr->plc_ram;
+ if (hdr->type == SPIDCOM_IMG_DESC_IMAGE_TYPE_300)
+ {
+ params->u.spc300.plc_mem_size = hdr->img_300.plc_ram;
+ }
params = tag_next (params);
*tmp = params;
}
@@ -186,12 +189,16 @@ static void setup_end_tag (bd_t *bd)
#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG */
/* --- SPiDBOOT --- */
-static int load_header(spidcom_image_desc_t *desc, char *addr)
+static int load_header(spidcom_image_desc_generic_t *desc, char *addr)
{
if (IS_IN_SPI_RANGE(addr))
{
/* first read image header, to see what is the len of the image */
- if ( flash_read_spi ((unsigned char *)addr, (unsigned char *)desc, sizeof(spidcom_image_desc_t), 1, 0) != ERR_OK )
+ if ( flash_read_spi ((unsigned char *)addr,
+ (unsigned char *)&(desc->img_common),
+ sizeof(spidcom_image_desc_common_200_300_t),
+ 1, 0)
+ != ERR_OK )
{
printf("ERROR : loading image header from SPI flash failed.\n");
return -1;
@@ -199,28 +206,30 @@ static int load_header(spidcom_image_desc_t *desc, char *addr)
}
else /* we boot from SDRAM */
{
- memmove (desc, (char *)addr, sizeof(spidcom_image_desc_t));
+ memmove (&(desc->img_common), (char *)addr,
+ sizeof(spidcom_image_desc_common_200_300_t));
}
- return 0;
+ return spidcom_image_desc_load (desc);
}
-static int check_img(spidcom_image_desc_t *desc, char *addr)
+static int check_img(spidcom_image_desc_generic_t *desc, char *addr)
{
int descriptor_changed = 0;
int result = IMAGE_OK;
/* First check image validity. If it was set as a non valid before,
* we will not even bother to look further. */
- if (desc->is_valid == 0)
+ if (desc->img_common.is_valid == 0)
{
return IMAGE_NOT_VALID;
}
/* Now check other flags... */
- if ( memcmp(desc->magic, SPIDCOM_IMG_DESC_MAGIC, sizeof(desc->magic)) )
+ if ( memcmp(desc->img_common.magic, SPIDCOM_IMG_DESC_MAGIC,
+ sizeof(desc->img_common.magic)) )
{
- desc->is_valid = 0;
+ desc->img_common.is_valid = 0;
/* Mark descriptor has changed to write this new value under flash */
descriptor_changed = 1;
result = BAD_MAGIC_NUMBER;
@@ -228,50 +237,60 @@ static int check_img(spidcom_image_desc_t *desc, char *addr)
}
#if defined(__ARM__)
- if (desc->arch != SPIDCOM_IMG_DESC_SPC300)
+ if (((desc->type == SPIDCOM_IMG_DESC_IMAGE_TYPE_300)
+ && (desc->img_300.arch != SPIDCOM_IMG_DESC_SPC300))
+ ||
+ ((desc->type == SPIDCOM_IMG_DESC_IMAGE_TYPE_200)
+ && (desc->img_200.arch != SPIDCOM_IMG_DESC_SPC200C
+ || desc->img_200.arch != SPIDCOM_IMG_DESC_SPC200E)))
#else
# error Unknown CPU type
#endif
{
- desc->is_valid = 0;
+ desc->img_common.is_valid = 0;
/* Mark descriptor has changed to write this new value under flash */
descriptor_changed = 1;
result = WRONG_IMAGE_ARCH;
goto outahere;
}
- if (desc->type != SPIDCOM_IMG_DESC_NORMAL_TYPE)
+ if (desc->img_common.type != SPIDCOM_IMG_DESC_NORMAL_TYPE)
{
- desc->is_valid = 0;
+ desc->img_common.is_valid = 0;
/* Mark descriptor has changed to write this new value under flash */
descriptor_changed = 1;
result = WRONG_IMAGE_TYPE;
goto outahere;
}
- if (desc->index == SPIDCOM_IMG_DESC_ORIGIN_INDEX)
+ if (desc->img_common.index == SPIDCOM_IMG_DESC_ORIGIN_INDEX)
{
/* image was downloaded by JTAG */
- desc->is_not_update = 0;
+ if (desc->type == SPIDCOM_IMG_DESC_IMAGE_TYPE_300)
+ {
+ desc->img_300.is_not_update = 0;
+ /* Mark descriptor has changed to write this new value under
+ * flash */
+ descriptor_changed = 1;
+ }
- /* Mark descriptor has changed to write this new value under flash */
- descriptor_changed = 1;
result = IMAGE_OK_ORIGIN;
goto outahere;
}
- if (desc->is_not_update != 0)
+ if ((desc->type == SPIDCOM_IMG_DESC_IMAGE_TYPE_300)
+ && (desc->img_300.is_not_update != 0))
{
- desc->is_valid = 0;
+ desc->img_300.is_valid = 0;
/* Mark descriptor has changed to write this new value under flash */
descriptor_changed = 1;
result = UPD_NOT_FINISHED;
goto outahere;
}
- if (desc->index == SPIDCOM_IMG_DESC_INVALID_INDEX)
+ if (desc->img_common.index == SPIDCOM_IMG_DESC_INVALID_INDEX)
{
- desc->is_valid = 0;
+ desc->img_common.is_valid = 0;
/* Mark descriptor has changed to write this new value under flash */
descriptor_changed = 1;
result = INDEX_NOT_VALID;
@@ -279,10 +298,10 @@ static int check_img(spidcom_image_desc_t *desc, char *addr)
}
/* fix image validity based on previous booting attempt */
- if(!desc->is_1st_boot && desc->is_not_success)
+ if(!desc->img_common.is_1st_boot && desc->img_common.is_not_success)
{
/* image is corrupted : invalidate it !!! */
- desc->is_valid = 0;
+ desc->img_common.is_valid = 0;
/* Mark descriptor has changed to write this new value under flash */
descriptor_changed = 1;
result = IMAGE_NOT_SUCCESS;
@@ -297,54 +316,67 @@ outahere:
* We will write whole structure (it is allowed to write unchanged parts,
* just transition 0->1 is impossible without erase
*/
- flash_write( (char *)desc, (ulong)addr, sizeof(spidcom_image_desc_t) );
+ flash_write( (char *)&desc->img_common, (ulong)addr,
+ sizeof(spidcom_image_desc_common_200_300_t) );
}
return result;
}
-static void update_origin_index(spidcom_image_desc_t *desc, char *addr, ulong index)
+static void update_origin_index(spidcom_image_desc_generic_t *desc,
+ char *addr, ulong index)
{
- desc->index = index;
+ desc->img_common.index = index;
/* Replacing 1s with 0s is allowed without erase.
* We will write whole structure (it is allowed to write unchanged parts,
* just transition 0->1 is impossible without erase
*/
- flash_write( (char *)desc, (ulong)addr, sizeof(spidcom_image_desc_t) );
+ flash_write( (char *)&desc->img_common, (ulong)addr,
+ sizeof(spidcom_image_desc_common_200_300_t) );
}
static int select_image(int img_nb)
{
int sel_img = -1; /* will hold the index of selected image */
- spidcom_image_desc_t *desc;
+ spidcom_image_desc_generic_t *desc;
int img_state[MAX_IMG] = {0};
ulong max_index = 0;
- char img_version[17];
+ char img_version[65];
+ uint version_len;
int i;
for (i=0; i<img_nb; i++)
{
desc = &img_desc[i];
- load_header(desc, (char *)img_addr[i]);
- img_state[i] = check_img(desc, (char *)img_addr[i]);
-
- if(!memcmp(desc->magic, SPIDCOM_IMG_DESC_MAGIC, sizeof(desc->magic)))
+ if (load_header(desc, (char *)img_addr[i]) >= 0)
{
- strncpy(img_version, desc->version, sizeof(img_version));
- img_version[sizeof(img_version)-1] = '\0';
+ img_state[i] = check_img(desc, (char *)img_addr[i]);
+
+ if(!memcmp(desc->img_common.magic, SPIDCOM_IMG_DESC_MAGIC,
+ sizeof(desc->img_common.magic)))
+ {
+ version_len
+ = spidcom_image_desc_read_version (desc, img_version);
+ img_version[version_len] = '\0';
+ }
+ else
+ {
+ strcpy(img_version, "Unknown");
+ }
}
else
{
- strcpy(img_version, "Unknown");
+ strcpy(img_version, "Invalid");
+ img_state[i] = IMAGE_NOT_VALID;
}
switch(img_state[i])
{
case IMAGE_OK:
printf("IMG (%-16s) at address %#x is OK.\n", img_version, img_addr[i]);
- if (desc->index >= max_index)
+ if (desc->img_common.index >= max_index)
{
- max_index = desc->index;
+ max_index = desc->img_common.index;
sel_img = i;
}
break;
@@ -431,7 +463,7 @@ int do_spidboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
int i;
char *s;
void (*appl)(int zero, int arch, uint params);
- spidcom_image_desc_t *hdr = NULL;
+ spidcom_image_desc_generic_t *hdr = NULL;
int use_spi_flash = 0;
char *img_load_addr = NULL;
bd_t *bd = gd->bd;
@@ -439,7 +471,9 @@ int do_spidboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
ulong img_0_addr;
ulong img_max_size;
int sel_img = -1; /* image selected for boot after all the checks */
- char img_version[17];
+ char img_version[65];
+ uint version_size;
+ char *version_addr;
#ifdef CONFIG_CMDLINE_TAG
char *commandline = getenv ("bootargs");
@@ -505,13 +539,28 @@ int do_spidboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
* selected image => we will not check it's validity */
}
- strncpy(img_version, hdr->version, sizeof(img_version));
- img_version[sizeof(img_version)-1] = '\0';
+ switch (hdr->type)
+ {
+ case SPIDCOM_IMG_DESC_IMAGE_TYPE_300:
+ version_addr = hdr->img_300.version;
+ version_size = sizeof (hdr->img_300.version);
+ break;
+ case SPIDCOM_IMG_DESC_IMAGE_TYPE_200:
+ version_addr = hdr->img_200.version;
+ version_size = sizeof (hdr->img_200.version);
+ break;
+ default:
+ printf ("Unsupported image type\n");
+ return -1;
+ }
+ strncpy(img_version, version_addr, version_size);
+ img_version[version_size] = '\0';
+
printf ("## Booting image \"%s\" at 0x%08lx ...\n", img_version, addr);
/* do the image transfer */
- data = (int)addr + sizeof(spidcom_image_desc_t);
- len = hdr->size;
+ data = (int)addr + sizeof(spidcom_image_desc_common_200_300_t);
+ len = hdr->img_common.size;
if ( IS_IN_SPI_RANGE(data) )
{
@@ -567,26 +616,30 @@ int do_spidboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
/* we transfered img from to SDRAM load addr -
* data pointer to point to image in RAM from now on */
data = (ulong)(img_load_addr); /* we are positioned at image load addr */
- len = hdr->size;
+ len = hdr->img_common.size;
/*
* before starting Linux, set correct image descriptor flags
*/
/* we will boot - it will not be 1st boot any more */
- if (hdr->is_1st_boot == 1)
+ if (hdr->img_common.is_1st_boot == 1)
{
- hdr->is_1st_boot = 0;
+ hdr->img_common.is_1st_boot = 0;
/* Replacing 1s with 0s is allowed without erase.
* We will write whole structure (it is allowed to write unchanged parts,
* just transition 0->1 is impossible without erase
*/
if(argc < 2)
- flash_write( (char *)hdr, (ulong)img_addr[sel_img], sizeof(spidcom_image_desc_t) );
+ flash_write( (char *)&hdr->img_common, (ulong)img_addr[sel_img],
+ sizeof(spidcom_image_desc_common_200_300_t) );
}
- /* Get PLC processor needed RAM space and reduce Linux one */
- gd->bd->bi_dram[0].size -= hdr->plc_ram;
+ if (hdr->type == SPIDCOM_IMG_DESC_IMAGE_TYPE_300)
+ {
+ /* Get PLC processor needed RAM space and reduce Linux one */
+ gd->bd->bi_dram[0].size -= hdr->img_300.plc_ram;
+ }
/*
* We have reached the point of no return: we are going to