summaryrefslogtreecommitdiff
path: root/cleopatre/u-boot-1.1.6/common
diff options
context:
space:
mode:
authorsave2009-07-27 12:49:35 +0000
committersave2009-07-27 12:49:35 +0000
commit7d6aa6554dec54c7834725a2cf0f2d601561efd8 (patch)
tree8e0ef8f680dc75868928cd8f104502ccd4fa8289 /cleopatre/u-boot-1.1.6/common
parent92e41c26578d36c31490c4343d09484c08c6c85e (diff)
[CLEO][U-BOOT]Adapt trace and correct some bugs under spidboot command
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@5078 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cleopatre/u-boot-1.1.6/common')
-rw-r--r--cleopatre/u-boot-1.1.6/common/cmd_spidboot.c349
1 files changed, 172 insertions, 177 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 4d9e6cd938..c48a2d1937 100644
--- a/cleopatre/u-boot-1.1.6/common/cmd_spidboot.c
+++ b/cleopatre/u-boot-1.1.6/common/cmd_spidboot.c
@@ -28,12 +28,9 @@
#include <common.h>
#include <watchdog.h>
#include <command.h>
-
-#include <md5.h>
-#include "asm/arch-spc300/image_desc.h"
#include <net.h>
-#include "../net/spidupd.h"
-#include <asm-arm/arch-spc300/spc300_nvram.h>
+#include <asm/arch/image_desc.h>
+#include <asm/arch/spc300_nvram.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -49,11 +46,8 @@ extern flash_info_t flash_info[]; /* info for SPI FLASH chip */
# define CHUNKSZ (64 * 1024)
#endif
-#define IMG_0_ADDR (char *)0x00140000
-#define IMG_1_ADDR (char *)0x004a0000
-
#define MAX_IMG 10 /* supported num of images */
-static unsigned long img_addr[MAX_IMG] = {0};
+static unsigned long img_addr[MAX_IMG] = {0};
static spidcom_image_desc_t img_desc[MAX_IMG];
#define LINUX_LOAD_ADDR (char *)0x40008000
@@ -64,13 +58,13 @@ static spidcom_image_desc_t img_desc[MAX_IMG];
#define WRONG_IMAGE_ARCH 4
#define WRONG_IMAGE_TYPE 5
#define UPD_NOT_FINISHED 6
-#define IMAGE_OK 7
-#define NO_VALID_IMAGE 8
+#define IMAGE_NOT_SUCCESS 7
+#define IMAGE_OK 8
+#define IMAGE_OK_ORIGIN 9
/* Util functions */
#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
defined (CONFIG_CMDLINE_TAG) || \
- defined (CONFIG_INITRD_TAG) || \
defined (CONFIG_SERIAL_TAG) || \
defined (CONFIG_REVISION_TAG)
static struct tag *params;
@@ -186,8 +180,9 @@ static void setup_end_tag (bd_t *bd)
params->hdr.size = 0;
}
-#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
+#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG */
+#if 0
static void
print_img_desc (spidcom_image_desc_t *hdr)
{
@@ -204,34 +199,23 @@ print_img_desc (spidcom_image_desc_t *hdr)
printf ("Image First Boot: %d\n", hdr->is_1st_boot);
printf ("Image First Boot Sucessful: %d\n", hdr->is_not_success);
printf ("Is update process not finished : %d\n", hdr->is_not_update);
-#if 0
- printf ("Data Size: %d Bytes = %.2f kB = %.2f MB\n",
- size, (double)size / 1.024e3, (double)size / 1.048576e6 );
-#endif
printf ("Data Size: %d Bytes = %.2d kB = %.2d MB\n",
size, size / 1024, size / 1048576 );
}
+#endif
/* --- SPiDBOOT --- */
static int load_header(spidcom_image_desc_t *desc, char *addr)
{
- int use_spi_flash = 0;
-
- if ( IS_IN_SPI_RANGE(addr) )
- use_spi_flash = 1;
-
- if (use_spi_flash)
+ if (IS_IN_SPI_RANGE(addr))
{
-
- //printf ("\nLoading image header from SPI to RAM ... ");
-
/* 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 )
{
printf("ERROR : loading image from SPI flash failed.\n");
return -1;
}
- } /*IS_IN_SPI_RANGE(addr) */
+ }
else /* we boot from SDRAM */
{
memmove (desc, (char *)addr, sizeof(spidcom_image_desc_t));
@@ -241,9 +225,11 @@ static int load_header(spidcom_image_desc_t *desc, char *addr)
static int check_img(spidcom_image_desc_t *desc, char *addr)
{
+ int descriptor_changed = 0;
+ int result = IMAGE_OK;
+
if ( strcmp(desc->magic, SPIDCOM_IMG_DESC_MAGIC) )
{
- puts ("Bad Magic Number.\n");
return BAD_MAGIC_NUMBER;
}
@@ -253,33 +239,43 @@ static int check_img(spidcom_image_desc_t *desc, char *addr)
# error Unknown CPU type
#endif
{
- printf ("Unsupported Architecture 0x%x\n", desc->arch);
return WRONG_IMAGE_ARCH;
}
if (desc->type != SPIDCOM_IMG_DESC_NORMAL_TYPE)
{
- printf ("Wrong Image Type for command\n");
return WRONG_IMAGE_TYPE;
}
- if (desc->is_not_update != 0)
+ if (desc->index == SPIDCOM_IMG_DESC_ORIGIN_INDEX)
{
- printf ("Update process never finished correctly.\n");
- desc->is_valid = 0;
- return UPD_NOT_FINISHED;
- }
+ /* image was downloaded by JTAG */
+ desc->is_not_update = 0;
+
+ /* Mark descriptor has changed to write this new value under flash */
+ descriptor_changed = 1;
+ result = IMAGE_OK_ORIGIN;
+ }
if (desc->is_valid == 0)
{
- puts ("Image is not valid.\n");
return IMAGE_NOT_VALID;
}
+ if (desc->is_not_update != 0)
+ {
+ desc->is_valid = 0;
+ /* Mark descriptor has changed to write this new value under flash */
+ descriptor_changed = 1;
+ result = UPD_NOT_FINISHED;
+ }
+
if (desc->index == SPIDCOM_IMG_DESC_INVALID_INDEX)
{
- puts ("Image index has not been updated - that means that image update process never finished correctly.\n");
- return INDEX_NOT_VALID;
+ desc->is_valid = 0;
+ /* Mark descriptor has changed to write this new value under flash */
+ descriptor_changed = 1;
+ result = INDEX_NOT_VALID;
}
/* fix image validity based on previous booting attempt */
@@ -288,43 +284,102 @@ static int check_img(spidcom_image_desc_t *desc, char *addr)
/* image is corrupted : invalidate it !!! */
if(desc->is_valid)
{
- printf("Previous boot failed: set image as invalid\n");
desc->is_valid = 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
- */
- flash_write( (char *)desc, (ulong)addr, sizeof(spidcom_image_desc_t) );
+
+ /* Mark descriptor has changed to write this new value under flash */
+ descriptor_changed = 1;
}
- return IMAGE_NOT_VALID;
+ result = IMAGE_NOT_SUCCESS;
+ }
+
+ if(descriptor_changed)
+ {
+ /* 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) );
}
- /* all went good... */
- return IMAGE_OK;
+ return result;
+}
+
+static void update_origin_index(spidcom_image_desc_t *desc, char *addr, ulong index)
+{
+ desc->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) );
}
static int select_image(int img_nb)
{
int sel_img = -1; /* will hold the index of selected image */
- spidcom_image_desc_t *desc[MAX_IMG];
+ spidcom_image_desc_t *desc;
int img_state[MAX_IMG] = {0};
- int max_index = 0;
+ ulong max_index = 0;
int i;
for (i=0; i<img_nb; i++)
{
- desc[i] = &img_desc[i];
- load_header(desc[i], (char *)img_addr[i]);
- img_state[i] = check_img(desc[i], (char *)img_addr[i]);
+ desc = &img_desc[i];
+ load_header(desc, (char *)img_addr[i]);
+ img_state[i] = check_img(desc, (char *)img_addr[i]);
- if (img_state[i] == IMAGE_OK)
+ switch(img_state[i])
{
- if (desc[i]->index >= max_index)
+ case IMAGE_OK:
+ printf("IMG_%d is OK.\n", i);
+ if (desc->index >= max_index)
{
- max_index = desc[i]->index;
+ max_index = desc->index;
sel_img = i;
}
+ break;
+
+ case IMAGE_OK_ORIGIN:
+ printf("IMG_%d is OK.\n", i);
+ break;
+
+ case BAD_MAGIC_NUMBER:
+ printf("IMG_%d is not OK (bad magic number).\n", i);
+ break;
+
+ case WRONG_IMAGE_ARCH:
+ printf("IMG_%d is not OK (architecture error).\n", i);
+ break;
+
+ case WRONG_IMAGE_TYPE:
+ printf("IMG_%d is not OK (type error).\n", i);
+ break;
+
+ case UPD_NOT_FINISHED:
+ printf("IMG_%d is not OK (update error).\n", i);
+ break;
+
+ case INDEX_NOT_VALID:
+ printf("IMG_%d is not OK (index error).\n", i);
+ break;
+
+ case IMAGE_NOT_SUCCESS:
+ printf("IMG_%d is not OK (image error).\n", i);
+ break;
+
+ default: /* IMAGE_NOT_VALID */
+ printf("IMG_%d is not OK (valid error).\n", i);
+ }
+ }
+
+ /* Check a JTAG image, cause it will be better to boot it */
+ for (i=0; i<img_nb; i++)
+ {
+ if(img_state[i] == IMAGE_OK_ORIGIN)
+ {
+ update_origin_index(&img_desc[i], (char*)img_addr[i], max_index+1);
+ sel_img = i;
+ break;
}
}
@@ -334,57 +389,33 @@ static int select_image(int img_nb)
static int
find_nb_images (void)
{
- spc300_nvram_t *nvram = NULL;
- uint32_t nb_images = 0;
+ spc300_nvram_t *nvram = (spc300_nvram_t *)(gd->bd->bi_nvram_addr);
- nvram = (spc300_nvram_t *)(gd->bd->bi_nvram_addr);
- if ( nvram == NULL )
- {
- printf ("Error : NVRAM not found in flash.\n");
- return 0;
- }
- printf("sizeof(nb_images) = %d\n", sizeof(nb_images) );
-
- /* read begining of the sector in local array variable */
- if ( flash_read_spi ( (unsigned char *)( &(nvram->nb_images) ), (unsigned char *)(&nb_images), sizeof(nb_images), 1, 0) != ERR_OK )
- {
- printf("ERROR : read from SPI flash failed.\n");
- return 0;
- }
-
- //printf("nb_images = %d (NVRAM at addr %#x)\n", (int)nb_images, nvram);
-
- return (int)nb_images;
+ /* We can use SPI Direct Access because nb_images is a uint32_t */
+ return nvram->nb_images;
}
-int
+static int
find_images(int img_nb)
{
- 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;
- int start = 0;
+ 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);
- if ( nvram == NULL )
- {
- printf ("Error : NVRAM not found in flash.\n");
- return -1;
- }
-
- /* search for the "SPIDIMG\0" string on the begining of the each sector */
+ /* 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] < nvram->img_0_offset)
continue;
- /* read begining of the sector in local array variable */
+ /* 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");
+ printf("ERROR : read from SPI flash failed.\n");
return -1;
}
/* compare this with magic word (for SPC300 that is "SPIDIMG\0") */
@@ -397,30 +428,28 @@ find_images(int img_nb)
/* found it! */
img_addr[i] = flinfo->start[sect];
-#ifndef CONFIG_EXEC_FROM_SPI
+#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 */
- printf ("FOUND image %d at address %#x\n", i, img_addr[i]);
i++; /* number of images found, and index for next image */
-
+
/* check if we found all images */
if (i == img_nb)
{
- return i;
+ break;
}
}
} /* for */
+ return i;
}
int do_spidboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
- ulong iflag;
- ulong addr;
- ulong data, len;
- ulong *len_ptr;
- int verify;
- char *name, *s;
+ ulong addr;
+ ulong data, len;
+ int verify;
+ char *s;
void (*appl)(int zero, int arch, uint params);
spidcom_image_desc_t *hdr = NULL;
int use_spi_flash = 0;
@@ -435,6 +464,11 @@ int do_spidboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
/* set load addr of the kernel */
img_load_addr = LINUX_LOAD_ADDR;
+ /* A second argument overwrites the load address */
+ if (argc > 2)
+ {
+ img_load_addr = (char*)simple_strtoul(argv[2], NULL, 16);
+ }
s = getenv ("verify");
verify = (s && (*s == 'n')) ? 0 : 1;
@@ -443,19 +477,18 @@ int do_spidboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
if (argc < 2) /* no address was given - normal multiboot */
{
- /* give a chance of 1sec tomeout for user to initiate the update */
- do_spidupd();
-
- find_images(img_nb);
- sel_img = select_image(img_nb);
while(sel_img < 0)
{
+ /* give a chance of 1sec timeout for user to initiate the update */
do_spidupd();
- sel_img = select_image(img_nb);
+ find_images(img_nb);
+ sel_img = select_image(img_nb);
}
addr = img_addr[sel_img];
hdr = &img_desc[sel_img];
+
+ printf("Selecting IMG_%d.\n", sel_img);
}
else
{
@@ -473,8 +506,6 @@ int do_spidboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
printf ("## Booting image at %08lx ...\n", addr);
- print_img_desc (hdr);
-
/* do the image transfer */
data = (int)addr + sizeof(spidcom_image_desc_t);
len = hdr->size;
@@ -482,7 +513,6 @@ int do_spidboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
if ( IS_IN_SPI_RANGE(data) )
{
use_spi_flash = 1;
- printf ("\nLoading Linux image from SPI to RAM ... \n");
}
#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
@@ -518,7 +548,7 @@ int do_spidboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
if (use_spi_flash)
{
- if ( flash_read_spi ( (uchar *)data, (void *)(img_load_addr), len, 1, 0 ) != ERR_OK )
+ if ( flash_read_spi ( (uchar *)data, (void *)(img_load_addr), len, 1, 0 ) != ERR_OK )
{
printf("ERROR : loading image from SPI flash failed.\n");
return -1;
@@ -528,8 +558,6 @@ int do_spidboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
memmove ((void *)(img_load_addr), (uchar *)data, len);
}
-
- putc ('\n');
}
#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
@@ -538,110 +566,77 @@ int do_spidboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
data = (ulong)(img_load_addr); /* we are positioned at image load addr */
len = hdr->size;
- len_ptr = (ulong *)data;
-
- /* for now, there is only one valid type,
- * but switch is used for the ease of adding
- * new types in the future */
- switch (hdr->type) {
- case SPIDCOM_IMG_DESC_NORMAL_TYPE:
- name = "SPC300 Linux image";
- /* A second argument overwrites the load address */
- if (argc > 2) {
- img_load_addr = (char*)simple_strtoul(argv[2], NULL, 16);
- }
- break;
- default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
- return 1;
- }
-
/*
* 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)
{
- char *dest = NULL;
-
hdr->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
*/
- flash_write( (char *)hdr, (ulong)img_addr[sel_img], sizeof(spidcom_image_desc_t) );
+ if(argc < 2)
+ flash_write( (char *)hdr, (ulong)img_addr[sel_img], sizeof(spidcom_image_desc_t) );
}
+ /* Get PLC processor needed RAM space and reduce Linux one */
+ //gd->bd->bi_dram[0].size -= hdr->plc_ram;
+
/*
* We have reached the point of no return: we are going to
* overwrite all exception vector code, so we cannot easily
* recover from any failures any more...
*/
- iflag = disable_interrupts();
-
- printf (" BOOTING %s ... ", name);
- puts ("OK\n");
-
- switch (hdr->type) {
- case SPIDCOM_IMG_DESC_NORMAL_TYPE:
- if (iflag)
- enable_interrupts();
-
- /* load (and uncompress), but don't start if "autostart"
- * is set to "no"
- */
- if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0)) {
- char buf[32];
- sprintf(buf, "%lX", len);
- setenv("filesize", buf);
- return 0;
- }
+ /* load (and uncompress), but don't start if "autostart"
+ * is set to "no"
+ */
+ if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0))
+ {
+ char buf[32];
+ sprintf(buf, "%lX", len);
+ setenv("filesize", buf);
+ return 0;
+ }
#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
- defined (CONFIG_CMDLINE_TAG) || \
- defined (CONFIG_INITRD_TAG) || \
- defined (CONFIG_SERIAL_TAG) || \
- defined (CONFIG_REVISION_TAG)
- setup_start_tag (bd);
+ defined (CONFIG_CMDLINE_TAG) || \
+ defined (CONFIG_SERIAL_TAG) || \
+ defined (CONFIG_REVISION_TAG)
+ setup_start_tag (bd);
#ifdef CONFIG_SERIAL_TAG
- setup_serial_tag (&params);
+ setup_serial_tag (&params);
#endif
#ifdef CONFIG_REVISION_TAG
- setup_revision_tag (&params);
+ setup_revision_tag (&params);
#endif
#ifdef CONFIG_SETUP_MEMORY_TAGS
- setup_memory_tags (bd);
+ setup_memory_tags (bd);
#endif
#ifdef CONFIG_CMDLINE_TAG
- setup_commandline_tag (bd, commandline);
+ setup_commandline_tag (bd, commandline);
#endif
-
#ifdef CONFIG_SPC300_TAG
- setup_spc300_tag (bd, &params);
+ setup_spc300_tag (bd, &params);
#endif
- setup_end_tag (bd);
+ setup_end_tag (bd);
#endif
- /* disable D/I caches and flush them */
- cleanup_before_linux ();
- /* GO */
- appl = (void (*) (int, int, uint))(img_load_addr) ;
- appl(0, bd->bi_arch_number, bd->bi_boot_params);
- return 0;
- default:
- if (iflag)
- enable_interrupts();
- printf ("Can't boot image type %d\n", hdr->type);
- return 1;
- }
+ /* disable D/I caches and flush them */
+ cleanup_before_linux ();
+ /* GO */
+ appl = (void (*) (int, int, uint))(img_load_addr) ;
+ appl(0, bd->bi_arch_number, bd->bi_boot_params);
+ return 0;
}
U_BOOT_CMD(
spidboot, 2, 1, do_spidboot,
"spidboot - boot application image from memory\n",
"[addr [arg ...]]\n - boot application image stored in memory\n"
- "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
- "\t'arg' can be the address of an initrd image\n"
+ "\tpassing arguments 'arg ...'; to precise a Linux install address.\n"
);