summaryrefslogtreecommitdiff
path: root/board
diff options
context:
space:
mode:
Diffstat (limited to 'board')
-rw-r--r--board/cray/L1/L1.c11
-rw-r--r--board/esd/common/auto_update.c92
-rw-r--r--board/mcc200/auto_update.c90
-rw-r--r--board/mpl/common/common_util.c46
-rw-r--r--board/pn62/cmd_pn62.c11
-rw-r--r--board/siemens/common/fpga.c48
-rw-r--r--board/trab/auto_update.c114
7 files changed, 237 insertions, 175 deletions
diff --git a/board/cray/L1/L1.c b/board/cray/L1/L1.c
index 5264baf..a72ba46 100644
--- a/board/cray/L1/L1.c
+++ b/board/cray/L1/L1.c
@@ -139,8 +139,15 @@ int misc_init_r (void)
struct rtc_time tm;
char bootcmd[32];
- hdr = (image_header_t *) (CFG_MONITOR_BASE - sizeof (image_header_t));
- timestamp = (time_t) hdr->ih_time;
+ hdr = (image_header_t *) (CFG_MONITOR_BASE - image_get_header_size ());
+#if defined(CONFIG_FIT)
+ if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
+ puts ("Non legacy image format not supported\n");
+ return -1;
+ }
+#endif
+
+ timestamp = (time_t)image_get_time (hdr);
to_tm (timestamp, &tm);
printf ("Welcome to U-Boot on Cray L1. Compiled %4d-%02d-%02d %2d:%02d:%02d (UTC)\n", tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
diff --git a/board/esd/common/auto_update.c b/board/esd/common/auto_update.c
index a76b00f..1bf81c6 100644
--- a/board/esd/common/auto_update.c
+++ b/board/esd/common/auto_update.c
@@ -89,24 +89,28 @@ extern block_dev_desc_t ide_dev_desc[CFG_IDE_MAXDEVICE];
int au_check_cksum_valid(int i, long nbytes)
{
image_header_t *hdr;
- unsigned long checksum;
hdr = (image_header_t *)LOAD_ADDR;
+#if defined(CONFIG_FIT)
+ if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
+ puts ("Non legacy image format not supported\n");
+ return -1;
+ }
+#endif
- if ((au_image[i].type == AU_FIRMWARE) && (au_image[i].size != ntohl(hdr->ih_size))) {
+ if ((au_image[i].type == AU_FIRMWARE) &&
+ (au_image[i].size != image_get_data_size (hdr))) {
printf ("Image %s has wrong size\n", au_image[i].name);
return -1;
}
- if (nbytes != (sizeof(*hdr) + ntohl(hdr->ih_size))) {
+ if (nbytes != (image_get_image_size (hdr))) {
printf ("Image %s bad total SIZE\n", au_image[i].name);
return -1;
}
- /* check the data CRC */
- checksum = ntohl(hdr->ih_dcrc);
- if (crc32 (0, (uchar *)(LOAD_ADDR + sizeof(*hdr)), ntohl(hdr->ih_size))
- != checksum) {
+ /* check the data CRC */
+ if (!image_check_dcrc (hdr)) {
printf ("Image %s bad data checksum\n", au_image[i].name);
return -1;
}
@@ -120,51 +124,53 @@ int au_check_header_valid(int i, long nbytes)
unsigned long checksum;
hdr = (image_header_t *)LOAD_ADDR;
+#if defined(CONFIG_FIT)
+ if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
+ puts ("Non legacy image format not supported\n");
+ return -1;
+ }
+#endif
+
/* check the easy ones first */
#undef CHECK_VALID_DEBUG
#ifdef CHECK_VALID_DEBUG
- printf("magic %#x %#x ", ntohl(hdr->ih_magic), IH_MAGIC);
- printf("arch %#x %#x ", hdr->ih_arch, IH_CPU_PPC);
- printf("size %#x %#lx ", ntohl(hdr->ih_size), nbytes);
- printf("type %#x %#x ", hdr->ih_type, IH_TYPE_KERNEL);
+ printf("magic %#x %#x ", image_get_magic (hdr), IH_MAGIC);
+ printf("arch %#x %#x ", image_get_arch (hdr), IH_ARCH_PPC);
+ printf("size %#x %#lx ", image_get_data_size (hdr), nbytes);
+ printf("type %#x %#x ", image_get_type (hdr), IH_TYPE_KERNEL);
#endif
- if (nbytes < sizeof(*hdr))
+ if (nbytes < image_get_header_size ())
{
printf ("Image %s bad header SIZE\n", au_image[i].name);
return -1;
}
- if (ntohl(hdr->ih_magic) != IH_MAGIC || hdr->ih_arch != IH_CPU_PPC)
+ if (!image_check_magic (hdr) || !image_check_arch (hdr, IH_ARCH_PPC))
{
printf ("Image %s bad MAGIC or ARCH\n", au_image[i].name);
return -1;
}
- /* check the hdr CRC */
- checksum = ntohl(hdr->ih_hcrc);
- hdr->ih_hcrc = 0;
-
- if (crc32 (0, (uchar *)hdr, sizeof(*hdr)) != checksum) {
+ if (!image_check_hcrc (hdr)) {
printf ("Image %s bad header checksum\n", au_image[i].name);
return -1;
}
- hdr->ih_hcrc = htonl(checksum);
/* check the type - could do this all in one gigantic if() */
- if ((au_image[i].type == AU_FIRMWARE) && (hdr->ih_type != IH_TYPE_FIRMWARE)) {
+ if ((au_image[i].type == AU_FIRMWARE) && !image_check_type (hdr, IH_TYPE_FIRMWARE)) {
printf ("Image %s wrong type\n", au_image[i].name);
return -1;
}
- if ((au_image[i].type == AU_SCRIPT) && (hdr->ih_type != IH_TYPE_SCRIPT)) {
+ if ((au_image[i].type == AU_SCRIPT) && !image_check_type (hdr, IH_TYPE_SCRIPT)) {
printf ("Image %s wrong type\n", au_image[i].name);
return -1;
}
/* recycle checksum */
- checksum = ntohl(hdr->ih_size);
+ checksum = image_get_data_size (hdr);
#if 0 /* test-only */
/* for kernel and app the image header must also fit into flash */
if (idx != IDX_DISK)
- checksum += sizeof(*hdr);
+ checksum += image_get_header_size ();
/* check the size does not exceed space in flash. HUSH scripts */
/* all have ausize[] set to 0 */
if ((ausize[idx] != 0) && (ausize[idx] < checksum)) {
@@ -190,17 +196,23 @@ int au_do_update(int i, long sz)
#endif
hdr = (image_header_t *)LOAD_ADDR;
+#if defined(CONFIG_FIT)
+ if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
+ puts ("Non legacy image format not supported\n");
+ return -1;
+ }
+#endif
switch (au_image[i].type) {
case AU_SCRIPT:
printf("Executing script %s\n", au_image[i].name);
/* execute a script */
- if (hdr->ih_type == IH_TYPE_SCRIPT) {
- addr = (char *)((char *)hdr + sizeof(*hdr));
+ if (image_check_type (hdr, IH_TYPE_SCRIPT)) {
+ addr = (char *)((char *)hdr + image_get_header_size ());
/* stick a NULL at the end of the script, otherwise */
/* parse_string_outer() runs off the end. */
- addr[ntohl(hdr->ih_size)] = 0;
+ addr[image_get_data_size (hdr)] = 0;
addr += 8;
/*
@@ -231,8 +243,8 @@ int au_do_update(int i, long sz)
*/
if (au_image[i].type == AU_FIRMWARE) {
char *orig = (char*)start;
- char *new = (char *)((char *)hdr + sizeof(*hdr));
- nbytes = ntohl(hdr->ih_size);
+ char *new = (char *)((char *)hdr + image_get_header_size ());
+ nbytes = image_get_data_size (hdr);
while(--nbytes) {
if (*orig++ != *new++) {
@@ -272,12 +284,12 @@ int au_do_update(int i, long sz)
/* strip the header - except for the kernel and ramdisk */
if (au_image[i].type != AU_FIRMWARE) {
addr = (char *)hdr;
- off = sizeof(*hdr);
- nbytes = sizeof(*hdr) + ntohl(hdr->ih_size);
+ off = image_get_header_size ();
+ nbytes = image_get_image_size (hdr);
} else {
- addr = (char *)((char *)hdr + sizeof(*hdr));
+ addr = (char *)((char *)hdr + image_get_header_size ());
off = 0;
- nbytes = ntohl(hdr->ih_size);
+ nbytes = image_get_data_size (hdr);
}
/*
@@ -305,15 +317,15 @@ int au_do_update(int i, long sz)
* check the dcrc of the copy
*/
if (au_image[i].type != AU_NAND) {
- rc = crc32 (0, (uchar *)(start + off), ntohl(hdr->ih_size));
+ rc = crc32 (0, (uchar *)(start + off), image_get_data_size (hdr));
} else {
#if defined(CONFIG_CMD_NAND) && defined(CFG_NAND_LEGACY)
rc = nand_legacy_rw(nand_dev_desc, NANDRW_READ | NANDRW_JFFS2 | NANDRW_JFFS2_SKIP,
start, nbytes, (size_t *)&total, (uchar *)addr);
- rc = crc32 (0, (uchar *)(addr + off), ntohl(hdr->ih_size));
+ rc = crc32 (0, (uchar *)(addr + off), image_get_data_size (hdr));
#endif
}
- if (rc != ntohl(hdr->ih_dcrc)) {
+ if (rc != image_get_dcrc (hdr)) {
printf ("Image %s Bad Data Checksum After COPY\n", au_image[i].name);
return -1;
}
@@ -497,10 +509,10 @@ int do_auto_update(void)
printf("Reading %s ...", au_image[i].name);
/* just read the header */
- sz = do_fat_read(au_image[i].name, LOAD_ADDR, sizeof(image_header_t), LS_NO);
+ sz = do_fat_read(au_image[i].name, LOAD_ADDR, image_get_header_size (), LS_NO);
debug ("read %s sz %ld hdr %d\n",
- au_image[i].name, sz, sizeof(image_header_t));
- if (sz <= 0 || sz < sizeof(image_header_t)) {
+ au_image[i].name, sz, image_get_header_size ());
+ if (sz <= 0 || sz < image_get_header_size ()) {
puts(" not found\n");
continue;
}
@@ -510,8 +522,8 @@ int do_auto_update(void)
}
sz = do_fat_read(au_image[i].name, LOAD_ADDR, MAX_LOADSZ, LS_NO);
debug ("read %s sz %ld hdr %d\n",
- au_image[i].name, sz, sizeof(image_header_t));
- if (sz <= 0 || sz <= sizeof(image_header_t)) {
+ au_image[i].name, sz, image_get_header_size ());
+ if (sz <= 0 || sz <= image_get_header_size ()) {
puts(" not found\n");
continue;
}
diff --git a/board/mcc200/auto_update.c b/board/mcc200/auto_update.c
index 28e4c87..5580c11 100644
--- a/board/mcc200/auto_update.c
+++ b/board/mcc200/auto_update.c
@@ -141,18 +141,21 @@ extern void lcd_enable(void);
int au_check_cksum_valid(int idx, long nbytes)
{
image_header_t *hdr;
- unsigned long checksum;
hdr = (image_header_t *)LOAD_ADDR;
+#if defined(CONFIG_FIT)
+ if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
+ puts ("Non legacy image format not supported\n");
+ return -1;
+ }
+#endif
- if (nbytes != (sizeof(*hdr) + ntohl(hdr->ih_size))) {
+ if (nbytes != image_get_image_size (hdr)) {
printf ("Image %s bad total SIZE\n", aufile[idx]);
return -1;
}
/* check the data CRC */
- checksum = ntohl(hdr->ih_dcrc);
-
- if (crc32 (0, (uchar *)(LOAD_ADDR + sizeof(*hdr)), ntohl(hdr->ih_size)) != checksum) {
+ if (!image_check_dcrc (hdr)) {
printf ("Image %s bad data checksum\n", aufile[idx]);
return -1;
}
@@ -165,59 +168,62 @@ int au_check_header_valid(int idx, long nbytes)
unsigned long checksum, fsize;
hdr = (image_header_t *)LOAD_ADDR;
+#if defined(CONFIG_FIT)
+ if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
+ puts ("Non legacy image format not supported\n");
+ return -1;
+ }
+#endif
+
/* check the easy ones first */
#undef CHECK_VALID_DEBUG
#ifdef CHECK_VALID_DEBUG
- printf("magic %#x %#x ", ntohl(hdr->ih_magic), IH_MAGIC);
- printf("arch %#x %#x ", hdr->ih_arch, IH_CPU_ARM);
- printf("size %#x %#lx ", ntohl(hdr->ih_size), nbytes);
- printf("type %#x %#x ", hdr->ih_type, IH_TYPE_KERNEL);
+ printf("magic %#x %#x ", image_get_magic (hdr), IH_MAGIC);
+ printf("arch %#x %#x ", image_get_arch (hdr), IH_ARCH_ARM);
+ printf("size %#x %#lx ", image_get_data_size (hdr), nbytes);
+ printf("type %#x %#x ", image_get_type (hdr), IH_TYPE_KERNEL);
#endif
- if (nbytes < sizeof(*hdr)) {
+ if (nbytes < image_get_header_size ()) {
printf ("Image %s bad header SIZE\n", aufile[idx]);
ausize[idx] = 0;
return -1;
}
- if (ntohl(hdr->ih_magic) != IH_MAGIC || hdr->ih_arch != IH_CPU_PPC) {
+ if (!image_check_magic (hdr) || !image_check_arch (hdr, IH_ARCH_PPC)) {
printf ("Image %s bad MAGIC or ARCH\n", aufile[idx]);
ausize[idx] = 0;
return -1;
}
/* check the hdr CRC */
- checksum = ntohl(hdr->ih_hcrc);
- hdr->ih_hcrc = 0;
-
- if (crc32 (0, (uchar *)hdr, sizeof(*hdr)) != checksum) {
+ if (!image_check_hcrc (hdr)) {
printf ("Image %s bad header checksum\n", aufile[idx]);
ausize[idx] = 0;
return -1;
}
- hdr->ih_hcrc = htonl(checksum);
/* check the type - could do this all in one gigantic if() */
- if ((idx == IDX_FIRMWARE) && (hdr->ih_type != IH_TYPE_FIRMWARE)) {
+ if ((idx == IDX_FIRMWARE) && !image_check_type (hdr, IH_TYPE_FIRMWARE)) {
printf ("Image %s wrong type\n", aufile[idx]);
ausize[idx] = 0;
return -1;
}
- if ((idx == IDX_KERNEL) && (hdr->ih_type != IH_TYPE_KERNEL)) {
+ if ((idx == IDX_KERNEL) && !image_check_type (hdr, IH_TYPE_KERNEL)) {
printf ("Image %s wrong type\n", aufile[idx]);
ausize[idx] = 0;
return -1;
}
if ((idx == IDX_ROOTFS) &&
- ( (hdr->ih_type != IH_TYPE_RAMDISK) && (hdr->ih_type != IH_TYPE_FILESYSTEM) )
- ) {
+ (!image_check_type (hdr, IH_TYPE_RAMDISK) &&
+ !image_check_type (hdr, IH_TYPE_FILESYSTEM))) {
printf ("Image %s wrong type\n", aufile[idx]);
ausize[idx] = 0;
return -1;
}
/* recycle checksum */
- checksum = ntohl(hdr->ih_size);
+ checksum = image_get_data_size (hdr);
- fsize = checksum + sizeof(*hdr);
+ fsize = checksum + image_get_header_size ();
/* for kernel and ramdisk the image header must also fit into flash */
- if (idx == IDX_KERNEL || hdr->ih_type == IH_TYPE_RAMDISK)
- checksum += sizeof(*hdr);
+ if (idx == IDX_KERNEL || image_check_type (hdr, IH_TYPE_RAMDISK))
+ checksum += image_get_header_size ();
/* check the size does not exceed space in flash. HUSH scripts */
if ((ausize[idx] != 0) && (ausize[idx] < checksum)) {
@@ -240,13 +246,19 @@ int au_do_update(int idx, long sz)
uint nbytes;
hdr = (image_header_t *)LOAD_ADDR;
+#if defined(CONFIG_FIT)
+ if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
+ puts ("Non legacy image format not supported\n");
+ return -1;
+ }
+#endif
/* execute a script */
- if (hdr->ih_type == IH_TYPE_SCRIPT) {
- addr = (char *)((char *)hdr + sizeof(*hdr));
+ if (image_check_type (hdr, IH_TYPE_SCRIPT)) {
+ addr = (char *)((char *)hdr + image_get_header_size ());
/* stick a NULL at the end of the script, otherwise */
/* parse_string_outer() runs off the end. */
- addr[ntohl(hdr->ih_size)] = 0;
+ addr[image_get_data_size (hdr)] = 0;
addr += 8;
parse_string_outer(addr, FLAG_PARSE_SEMICOLON);
return 0;
@@ -278,19 +290,20 @@ int au_do_update(int idx, long sz)
#endif
/* strip the header - except for the kernel and ramdisk */
- if (hdr->ih_type == IH_TYPE_KERNEL || hdr->ih_type == IH_TYPE_RAMDISK) {
+ if (image_check_type (hdr, IH_TYPE_KERNEL) ||
+ image_check_type (hdr, IH_TYPE_RAMDISK)) {
addr = (char *)hdr;
- off = sizeof(*hdr);
- nbytes = sizeof(*hdr) + ntohl(hdr->ih_size);
+ off = image_get_header_size ();
+ nbytes = image_get_image_size (hdr);
} else {
- addr = (char *)((char *)hdr + sizeof(*hdr));
+ addr = (char *)((char *)hdr + image_get_header_size ());
#ifdef AU_UPDATE_TEST
/* copy it to where Linux goes */
if (idx == IDX_FIRMWARE)
start = aufl_layout[1].start;
#endif
off = 0;
- nbytes = ntohl(hdr->ih_size);
+ nbytes = image_get_data_size (hdr);
}
/* copy the data from RAM to FLASH */
@@ -306,7 +319,8 @@ int au_do_update(int idx, long sz)
#endif
/* check the data CRC of the copy */
- if (crc32 (0, (uchar *)(start + off), ntohl(hdr->ih_size)) != ntohl(hdr->ih_dcrc)) {
+ if (crc32 (0, (uchar *)(start + off), image_get_data_size (hdr)) !=
+ image_get_dcrc (hdr)) {
printf ("Image %s Bad Data Checksum after COPY\n", aufile[idx]);
return -1;
}
@@ -442,10 +456,10 @@ int do_auto_update(void)
for (i = 0; i < AU_MAXFILES; i++) {
ulong imsize;
/* just read the header */
- sz = file_fat_read(aufile[i], LOAD_ADDR, sizeof(image_header_t));
+ sz = file_fat_read(aufile[i], LOAD_ADDR, image_get_header_size ());
debug ("read %s sz %ld hdr %d\n",
- aufile[i], sz, sizeof(image_header_t));
- if (sz <= 0 || sz < sizeof(image_header_t)) {
+ aufile[i], sz, image_get_header_size ());
+ if (sz <= 0 || sz < image_get_header_size ()) {
debug ("%s not found\n", aufile[i]);
ausize[i] = 0;
continue;
@@ -474,14 +488,14 @@ int do_auto_update(void)
sz = file_fat_read(aufile[i], LOAD_ADDR, ausize[i]);
debug ("read %s sz %ld hdr %d\n",
- aufile[i], sz, sizeof(image_header_t));
+ aufile[i], sz, image_get_header_size ());
if (sz != ausize[i]) {
printf ("%s: size %d read %d?\n", aufile[i], ausize[i], sz);
continue;
}
- if (sz <= 0 || sz <= sizeof(image_header_t)) {
+ if (sz <= 0 || sz <= image_get_header_size ()) {
debug ("%s not found\n", aufile[i]);
continue;
}
diff --git a/board/mpl/common/common_util.c b/board/mpl/common/common_util.c
index 8d4cbe8..785d204 100644
--- a/board/mpl/common/common_util.c
+++ b/board/mpl/common/common_util.c
@@ -57,9 +57,6 @@ extern int mem_test(ulong start, ulong ramsize, int quiet);
extern flash_info_t flash_info[]; /* info for FLASH chips */
-static image_header_t header;
-
-
static int
mpl_prg(uchar *src, ulong size)
{
@@ -77,7 +74,7 @@ mpl_prg(uchar *src, ulong size)
info = &flash_info[0];
#if defined(CONFIG_PIP405) || defined(CONFIG_MIP405) || defined(CONFIG_PATI)
- if (ntohl(magic[0]) != IH_MAGIC) {
+ if (uimage_to_cpu (magic[0]) != IH_MAGIC) {
puts("Bad Magic number\n");
return -1;
}
@@ -179,44 +176,46 @@ mpl_prg(uchar *src, ulong size)
static int
mpl_prg_image(uchar *ld_addr)
{
- unsigned long len, checksum;
+ unsigned long len;
uchar *data;
- image_header_t *hdr = &header;
+ image_header_t *hdr = (image_header_t *)ld_addr;
int rc;
- /* Copy header so we can blank CRC field for re-calculation */
- memcpy (&header, (char *)ld_addr, sizeof(image_header_t));
- if (ntohl(hdr->ih_magic) != IH_MAGIC) {
+#if defined(CONFIG_FIT)
+ if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
+ puts ("Non legacy image format not supported\n");
+ return -1;
+ }
+#endif
+
+ if (!image_check_magic (hdr)) {
puts("Bad Magic Number\n");
return 1;
}
- print_image_hdr(hdr);
- if (hdr->ih_os != IH_OS_U_BOOT) {
+ image_print_contents (hdr);
+ if (!image_check_os (hdr, IH_OS_U_BOOT)) {
puts("No U-Boot Image\n");
return 1;
}
- if (hdr->ih_type != IH_TYPE_FIRMWARE) {
+ if (!image_check_type (hdr, IH_TYPE_FIRMWARE)) {
puts("No Firmware Image\n");
return 1;
}
- data = (uchar *)&header;
- len = sizeof(image_header_t);
- checksum = ntohl(hdr->ih_hcrc);
- hdr->ih_hcrc = 0;
- if (crc32 (0, (uchar *)data, len) != checksum) {
+ if (!image_check_hcrc (hdr)) {
puts("Bad Header Checksum\n");
return 1;
}
- data = ld_addr + sizeof(image_header_t);
- len = ntohl(hdr->ih_size);
puts("Verifying Checksum ... ");
- if (crc32 (0, (uchar *)data, len) != ntohl(hdr->ih_dcrc)) {
+ if (!image_check_dcrc (hdr)) {
puts("Bad Data CRC\n");
return 1;
}
puts("OK\n");
- if (hdr->ih_comp != IH_COMP_NONE) {
+ data = (uchar *)image_get_data (hdr);
+ len = image_get_data_size (hdr);
+
+ if (image_get_comp (hdr) != IH_COMP_NONE) {
uchar *buf;
/* reserve space for uncompressed image */
if ((buf = malloc(IMAGE_SIZE)) == NULL) {
@@ -224,7 +223,7 @@ mpl_prg_image(uchar *ld_addr)
return 1;
}
- switch (hdr->ih_comp) {
+ switch (image_get_comp (hdr)) {
case IH_COMP_GZIP:
puts("Uncompressing (GZIP) ... ");
rc = gunzip ((void *)(buf), IMAGE_SIZE, data, &len);
@@ -253,7 +252,8 @@ mpl_prg_image(uchar *ld_addr)
break;
#endif
default:
- printf ("Unimplemented compression type %d\n", hdr->ih_comp);
+ printf ("Unimplemented compression type %d\n",
+ image_get_comp (hdr));
free(buf);
return 1;
}
diff --git a/board/pn62/cmd_pn62.c b/board/pn62/cmd_pn62.c
index ffa20cd..3f53e4b 100644
--- a/board/pn62/cmd_pn62.c
+++ b/board/pn62/cmd_pn62.c
@@ -157,8 +157,15 @@ int do_loadpci (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
char *s;
if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) {
- printf("Running autoscript at addr 0x%08lX ...\n", load_addr);
- rcode = autoscript (bd, load_addr);
+ printf ("Running autoscript at addr 0x%08lX", load_addr);
+
+ s = getenv ("autoscript_uname");
+ if (s)
+ printf (":%s ...\n", s);
+ else
+ puts (" ...\n");
+
+ rcode = autoscript (load_addr, s);
}
}
#endif
diff --git a/board/siemens/common/fpga.c b/board/siemens/common/fpga.c
index f022ed6..48c1850 100644
--- a/board/siemens/common/fpga.c
+++ b/board/siemens/common/fpga.c
@@ -131,45 +131,44 @@ static int fpga_reset (fpga_t* fpga)
static int fpga_load (fpga_t* fpga, ulong addr, int checkall)
{
volatile uchar *fpga_addr = (volatile uchar *)fpga->conf_base;
- image_header_t hdr;
- ulong len, checksum;
- uchar *data = (uchar *)&hdr;
- char *s, msg[32];
+ image_header_t *hdr = (image_header_t *)addr;
+ ulong len;
+ uchar *data;
+ char msg[32];
int verify, i;
+#if defined(CONFIG_FIT)
+ if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
+ puts ("Non legacy image format not supported\n");
+ return -1;
+ }
+#endif
+
/*
* Check the image header and data of the net-list
*/
- memcpy (&hdr, (char *)addr, sizeof(image_header_t));
-
- if (hdr.ih_magic != IH_MAGIC) {
+ if (!image_check_magic (hdr)) {
strcpy (msg, "Bad Image Magic Number");
goto failure;
}
- len = sizeof(image_header_t);
-
- checksum = hdr.ih_hcrc;
- hdr.ih_hcrc = 0;
-
- if (crc32 (0, data, len) != checksum) {
+ if (!image_check_hcrc (hdr)) {
strcpy (msg, "Bad Image Header CRC");
goto failure;
}
- data = (uchar*)(addr + sizeof(image_header_t));
- len = hdr.ih_size;
+ data = (uchar*)image_get_data (hdr);
+ len = image_get_data_size (hdr);
- s = getenv ("verify");
- verify = (s && (*s == 'n')) ? 0 : 1;
+ verify = getenv_verify ();
if (verify) {
- if (crc32 (0, data, len) != hdr.ih_dcrc) {
+ if (!image_check_dcrc (hdr)) {
strcpy (msg, "Bad Image Data CRC");
goto failure;
}
}
- if (checkall && fpga_get_version(fpga, (char *)(hdr.ih_name)) < 0)
+ if (checkall && fpga_get_version(fpga, image_get_name (hdr)) < 0)
return 1;
/* align length */
@@ -184,7 +183,7 @@ static int fpga_load (fpga_t* fpga, ulong addr, int checkall)
goto failure;
}
- printf ("(%s)... ", hdr.ih_name);
+ printf ("(%s)... ", image_get_name (hdr));
/*
* Copy data to FPGA
*/
@@ -341,7 +340,14 @@ int fpga_init (void)
}
hdr = (image_header_t *)addr;
- if ((new_id = fpga_get_version(fpga, (char *)(hdr->ih_name))) == -1)
+#if defined(CONFIG_FIT)
+ if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
+ puts ("Non legacy image format not supported\n");
+ return -1;
+ }
+#endif
+
+ if ((new_id = fpga_get_version(fpga, image_get_name (hdr))) == -1)
return 1;
do_load = 1;
diff --git a/board/trab/auto_update.c b/board/trab/auto_update.c
index 54d3645..46110cc 100644
--- a/board/trab/auto_update.c
+++ b/board/trab/auto_update.c
@@ -209,21 +209,21 @@ int
au_check_cksum_valid(int idx, long nbytes)
{
image_header_t *hdr;
- unsigned long checksum;
hdr = (image_header_t *)LOAD_ADDR;
+#if defined(CONFIG_FIT)
+ if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
+ puts ("Non legacy image format not supported\n");
+ return -1;
+ }
+#endif
- if (nbytes != (sizeof(*hdr) + ntohl(hdr->ih_size)))
- {
+ if (nbytes != image_get_image_size (hdr)) {
printf ("Image %s bad total SIZE\n", aufile[idx]);
return -1;
}
/* check the data CRC */
- checksum = ntohl(hdr->ih_dcrc);
-
- if (crc32 (0, (uchar *)(LOAD_ADDR + sizeof(*hdr)), ntohl(hdr->ih_size))
- != checksum)
- {
+ if (!image_check_dcrc (hdr)) {
printf ("Image %s bad data checksum\n", aufile[idx]);
return -1;
}
@@ -238,54 +238,55 @@ au_check_header_valid(int idx, long nbytes)
unsigned char buf[4];
hdr = (image_header_t *)LOAD_ADDR;
+#if defined(CONFIG_FIT)
+ if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
+ puts ("Non legacy image format not supported\n");
+ return -1;
+ }
+#endif
+
/* check the easy ones first */
#undef CHECK_VALID_DEBUG
#ifdef CHECK_VALID_DEBUG
- printf("magic %#x %#x ", ntohl(hdr->ih_magic), IH_MAGIC);
- printf("arch %#x %#x ", hdr->ih_arch, IH_CPU_ARM);
- printf("size %#x %#lx ", ntohl(hdr->ih_size), nbytes);
- printf("type %#x %#x ", hdr->ih_type, IH_TYPE_KERNEL);
+ printf("magic %#x %#x ", image_get_magic (hdr), IH_MAGIC);
+ printf("arch %#x %#x ", image_get_arch (hdr), IH_ARCH_ARM);
+ printf("size %#x %#lx ", image_get_data_size (hdr), nbytes);
+ printf("type %#x %#x ", image_get_type (hdr), IH_TYPE_KERNEL);
#endif
- if (nbytes < sizeof(*hdr))
- {
+ if (nbytes < image_get_header_size ()) {
printf ("Image %s bad header SIZE\n", aufile[idx]);
return -1;
}
- if (ntohl(hdr->ih_magic) != IH_MAGIC || hdr->ih_arch != IH_CPU_ARM)
- {
+ if (!image_check_magic (hdr) || !image_check_arch (hdr, IH_ARCH_ARM)) {
printf ("Image %s bad MAGIC or ARCH\n", aufile[idx]);
return -1;
}
/* check the hdr CRC */
- checksum = ntohl(hdr->ih_hcrc);
- hdr->ih_hcrc = 0;
-
- if (crc32 (0, (uchar *)hdr, sizeof(*hdr)) != checksum) {
+ if (!image_check_hcrc (hdr)) {
printf ("Image %s bad header checksum\n", aufile[idx]);
return -1;
}
- hdr->ih_hcrc = htonl(checksum);
/* check the type - could do this all in one gigantic if() */
- if ((idx == IDX_FIRMWARE) && (hdr->ih_type != IH_TYPE_FIRMWARE)) {
+ if ((idx == IDX_FIRMWARE) &&
+ !image_check_type (hdr, IH_TYPE_FIRMWARE)) {
printf ("Image %s wrong type\n", aufile[idx]);
return -1;
}
- if ((idx == IDX_KERNEL) && (hdr->ih_type != IH_TYPE_KERNEL)) {
+ if ((idx == IDX_KERNEL) && !image_check_type (hdr, IH_TYPE_KERNEL)) {
printf ("Image %s wrong type\n", aufile[idx]);
return -1;
}
- if ((idx == IDX_DISK) && (hdr->ih_type != IH_TYPE_FILESYSTEM)) {
+ if ((idx == IDX_DISK) && !image_check_type (hdr, IH_TYPE_FILESYSTEM)) {
printf ("Image %s wrong type\n", aufile[idx]);
return -1;
}
- if ((idx == IDX_APP) && (hdr->ih_type != IH_TYPE_RAMDISK)
- && (hdr->ih_type != IH_TYPE_FILESYSTEM)) {
+ if ((idx == IDX_APP) && !image_check_type (hdr, IH_TYPE_RAMDISK)
+ && !image_check_type (hdr, IH_TYPE_FILESYSTEM)) {
printf ("Image %s wrong type\n", aufile[idx]);
return -1;
}
if ((idx == IDX_PREPARE || idx == IDX_PREINST || idx == IDX_POSTINST)
- && (hdr->ih_type != IH_TYPE_SCRIPT))
- {
+ && !image_check_type (hdr, IH_TYPE_SCRIPT)) {
printf ("Image %s wrong type\n", aufile[idx]);
return -1;
}
@@ -293,10 +294,10 @@ au_check_header_valid(int idx, long nbytes)
if (idx == IDX_PREPARE)
return 0;
/* recycle checksum */
- checksum = ntohl(hdr->ih_size);
+ checksum = image_get_data_size (hdr);
/* for kernel and app the image header must also fit into flash */
if ((idx != IDX_DISK) && (idx != IDX_FIRMWARE))
- checksum += sizeof(*hdr);
+ checksum += image_get_header_size ();
/* check the size does not exceed space in flash. HUSH scripts */
/* all have ausize[] set to 0 */
if ((ausize[idx] != 0) && (ausize[idx] < checksum)) {
@@ -310,10 +311,10 @@ au_check_header_valid(int idx, long nbytes)
printf ("buf[0] %#x buf[1] %#x buf[2] %#x buf[3] %#x "
"as int %#x time %#x\n",
buf[0], buf[1], buf[2], buf[3],
- *((unsigned int *)buf), ntohl(hdr->ih_time));
+ *((unsigned int *)buf), image_get_time (hdr));
#endif
/* check it */
- if (*((unsigned int *)buf) >= ntohl(hdr->ih_time)) {
+ if (*((unsigned int *)buf) >= image_get_time (hdr)) {
printf ("Image %s is too old\n", aufile[idx]);
return -1;
}
@@ -335,16 +336,22 @@ au_do_update(int idx, long sz)
uint nbytes;
hdr = (image_header_t *)LOAD_ADDR;
+#if defined(CONFIG_FIT)
+ if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
+ puts ("Non legacy image format not supported\n");
+ return -1;
+ }
+#endif
/* disable the power switch */
*CPLD_VFD_BK |= POWER_OFF;
/* execute a script */
- if (hdr->ih_type == IH_TYPE_SCRIPT) {
- addr = (char *)((char *)hdr + sizeof(*hdr));
+ if (image_check_type (hdr, IH_TYPE_SCRIPT)) {
+ addr = (char *)((char *)hdr + image_get_header_size ());
/* stick a NULL at the end of the script, otherwise */
/* parse_string_outer() runs off the end. */
- addr[ntohl(hdr->ih_size)] = 0;
+ addr[image_get_data_size (hdr)] = 0;
addr += 8;
parse_string_outer(addr, FLAG_PARSE_SEMICOLON);
return 0;
@@ -372,19 +379,20 @@ au_do_update(int idx, long sz)
flash_sect_erase(start, end);
wait_ms(100);
/* strip the header - except for the kernel and ramdisk */
- if (hdr->ih_type == IH_TYPE_KERNEL || hdr->ih_type == IH_TYPE_RAMDISK) {
+ if (image_check_type (hdr, IH_TYPE_KERNEL) ||
+ image_check_type (hdr, IH_TYPE_RAMDISK)) {
addr = (char *)hdr;
- off = sizeof(*hdr);
- nbytes = sizeof(*hdr) + ntohl(hdr->ih_size);
+ off = image_get_header_size ();
+ nbytes = image_get_image_size (hdr);
} else {
- addr = (char *)((char *)hdr + sizeof(*hdr));
+ addr = (char *)((char *)hdr + image_get_header_size ());
#ifdef AU_UPDATE_TEST
/* copy it to where Linux goes */
if (idx == IDX_FIRMWARE)
start = aufl_layout[1].start;
#endif
off = 0;
- nbytes = ntohl(hdr->ih_size);
+ nbytes = image_get_data_size (hdr);
}
/* copy the data from RAM to FLASH */
@@ -396,7 +404,8 @@ au_do_update(int idx, long sz)
}
/* check the dcrc of the copy */
- if (crc32 (0, (uchar *)(start + off), ntohl(hdr->ih_size)) != ntohl(hdr->ih_dcrc)) {
+ if (crc32 (0, (uchar *)(start + off), image_get_data_size (hdr)) !=
+ image_get_dcrc (hdr)) {
printf ("Image %s Bad Data Checksum After COPY\n", aufile[idx]);
return -1;
}
@@ -423,17 +432,24 @@ au_update_eeprom(int idx)
}
hdr = (image_header_t *)LOAD_ADDR;
+#if defined(CONFIG_FIT)
+ if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
+ puts ("Non legacy image format not supported\n");
+ return -1;
+ }
+#endif
+
/* write the time field into EEPROM */
off = auee_off[idx].time;
- val = ntohl(hdr->ih_time);
+ val = image_get_time (hdr);
i2c_write_multiple(0x54, off, 1, &val, sizeof(val));
/* write the size field into EEPROM */
off = auee_off[idx].size;
- val = ntohl(hdr->ih_size);
+ val = image_get_data_size (hdr);
i2c_write_multiple(0x54, off, 1, &val, sizeof(val));
/* write the dcrc field into EEPROM */
off = auee_off[idx].dcrc;
- val = ntohl(hdr->ih_dcrc);
+ val = image_get_dcrc (hdr);
i2c_write_multiple(0x54, off, 1, &val, sizeof(val));
/* enable the power switch */
*CPLD_VFD_BK &= ~POWER_OFF;
@@ -577,10 +593,10 @@ do_auto_update(void)
/* just loop thru all the possible files */
for (i = 0; i < AU_MAXFILES; i++) {
/* just read the header */
- sz = file_fat_read(aufile[i], LOAD_ADDR, sizeof(image_header_t));
+ sz = file_fat_read(aufile[i], LOAD_ADDR, image_get_header_size ());
debug ("read %s sz %ld hdr %d\n",
- aufile[i], sz, sizeof(image_header_t));
- if (sz <= 0 || sz < sizeof(image_header_t)) {
+ aufile[i], sz, image_get_header_size ());
+ if (sz <= 0 || sz < image_get_header_size ()) {
debug ("%s not found\n", aufile[i]);
continue;
}
@@ -590,8 +606,8 @@ do_auto_update(void)
}
sz = file_fat_read(aufile[i], LOAD_ADDR, MAX_LOADSZ);
debug ("read %s sz %ld hdr %d\n",
- aufile[i], sz, sizeof(image_header_t));
- if (sz <= 0 || sz <= sizeof(image_header_t)) {
+ aufile[i], sz, image_get_header_size ());
+ if (sz <= 0 || sz <= image_get_header_size ()) {
debug ("%s not found\n", aufile[i]);
continue;
}