Commit d5934ad7 authored by Marian Balakowicz's avatar Marian Balakowicz

[new uImage] Add dual format uImage support framework

This patch adds framework for dual format images. Format detection is added
and the bootm controll flow is updated to include cases for new FIT format
uImages.

When the legacy (image_header based) format is detected appropriate
legacy specific handling is invoked. For the new (FIT based) format uImages
dual boot framework has a minial support, that will only print out a
corresponding debug messages. Implementation of the FIT specific handling will
be added in following patches.
Signed-off-by: default avatarMarian Balakowicz <m8@semihalf.com>
parent 5583cbf7
......@@ -140,6 +140,13 @@ int misc_init_r (void)
char bootcmd[32];
hdr = (image_header_t *) (CFG_MONITOR_BASE - image_get_header_size ());
#if defined(CONFIG_FIT)
if (gen_image_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);
......
......@@ -91,6 +91,12 @@ int au_check_cksum_valid(int i, long nbytes)
image_header_t *hdr;
hdr = (image_header_t *)LOAD_ADDR;
#if defined(CONFIG_FIT)
if (gen_image_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 != image_get_data_size (hdr))) {
......@@ -118,6 +124,13 @@ int au_check_header_valid(int i, long nbytes)
unsigned long checksum;
hdr = (image_header_t *)LOAD_ADDR;
#if defined(CONFIG_FIT)
if (gen_image_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
......@@ -183,6 +196,12 @@ int au_do_update(int i, long sz)
#endif
hdr = (image_header_t *)LOAD_ADDR;
#if defined(CONFIG_FIT)
if (gen_image_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:
......
......@@ -143,6 +143,12 @@ int au_check_cksum_valid(int idx, long nbytes)
image_header_t *hdr;
hdr = (image_header_t *)LOAD_ADDR;
#if defined(CONFIG_FIT)
if (gen_image_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
puts ("Non legacy image format not supported\n");
return -1;
}
#endif
if (nbytes != image_get_image_size (hdr)) {
printf ("Image %s bad total SIZE\n", aufile[idx]);
......@@ -162,6 +168,13 @@ int au_check_header_valid(int idx, long nbytes)
unsigned long checksum, fsize;
hdr = (image_header_t *)LOAD_ADDR;
#if defined(CONFIG_FIT)
if (gen_image_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
......@@ -233,6 +246,12 @@ int au_do_update(int idx, long sz)
uint nbytes;
hdr = (image_header_t *)LOAD_ADDR;
#if defined(CONFIG_FIT)
if (gen_image_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
puts ("Non legacy image format not supported\n");
return -1;
}
#endif
/* execute a script */
if (image_check_type (hdr, IH_TYPE_SCRIPT)) {
......
......@@ -181,6 +181,13 @@ mpl_prg_image(uchar *ld_addr)
image_header_t *hdr = (image_header_t *)ld_addr;
int rc;
#if defined(CONFIG_FIT)
if (gen_image_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;
......
......@@ -137,6 +137,13 @@ static int fpga_load (fpga_t* fpga, ulong addr, int checkall)
char msg[32];
int verify, i;
#if defined(CONFIG_FIT)
if (gen_image_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
*/
......@@ -333,6 +340,13 @@ int fpga_init (void)
}
hdr = (image_header_t *)addr;
#if defined(CONFIG_FIT)
if (gen_image_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;
......
......@@ -211,6 +211,12 @@ au_check_cksum_valid(int idx, long nbytes)
image_header_t *hdr;
hdr = (image_header_t *)LOAD_ADDR;
#if defined(CONFIG_FIT)
if (gen_image_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
puts ("Non legacy image format not supported\n");
return -1;
}
#endif
if (nbytes != image_get_image_size (hdr))
{
......@@ -234,6 +240,13 @@ au_check_header_valid(int idx, long nbytes)
unsigned char buf[4];
hdr = (image_header_t *)LOAD_ADDR;
#if defined(CONFIG_FIT)
if (gen_image_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
......@@ -327,6 +340,12 @@ au_do_update(int idx, long sz)
uint nbytes;
hdr = (image_header_t *)LOAD_ADDR;
#if defined(CONFIG_FIT)
if (gen_image_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;
......@@ -417,6 +436,13 @@ au_update_eeprom(int idx)
}
hdr = (image_header_t *)LOAD_ADDR;
#if defined(CONFIG_FIT)
if (gen_image_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 = image_get_time (hdr);
......
......@@ -53,7 +53,7 @@ int
autoscript (ulong addr)
{
ulong len;
image_header_t *hdr = (image_header_t *)addr;
image_header_t *hdr;
ulong *data;
char *cmd;
int rcode = 0;
......@@ -61,33 +61,47 @@ autoscript (ulong addr)
verify = getenv_verify ();
if (!image_check_magic (hdr)) {
puts ("Bad magic number\n");
return 1;
}
switch (gen_image_get_format ((void *)addr)) {
case IMAGE_FORMAT_LEGACY:
hdr = (image_header_t *)addr;
if (!image_check_hcrc (hdr)) {
puts ("Bad header crc\n");
return 1;
}
if (!image_check_magic (hdr)) {
puts ("Bad magic number\n");
return 1;
}
if (verify) {
if (!image_check_dcrc (hdr)) {
puts ("Bad data crc\n");
if (!image_check_hcrc (hdr)) {
puts ("Bad header crc\n");
return 1;
}
}
if (!image_check_type (hdr, IH_TYPE_SCRIPT)) {
puts ("Bad image type\n");
return 1;
}
if (verify) {
if (!image_check_dcrc (hdr)) {
puts ("Bad data crc\n");
return 1;
}
}
if (!image_check_type (hdr, IH_TYPE_SCRIPT)) {
puts ("Bad image type\n");
return 1;
}
/* get length of script */
data = (ulong *)image_get_data (hdr);
/* get length of script */
data = (ulong *)image_get_data (hdr);
if ((len = image_to_cpu (*data)) == 0) {
puts ("Empty Script\n");
if ((len = image_to_cpu (*data)) == 0) {
puts ("Empty Script\n");
return 1;
}
break;
#if defined(CONFIG_FIT)
case IMAGE_FORMAT_FIT:
fit_unsupported ("autoscript");
return 1;
#endif
default:
puts ("Wrong image format for autoscript\n");
return 1;
}
......
This diff is collapsed.
......@@ -261,17 +261,29 @@ int do_docboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
}
show_boot_progress (38);
hdr = (image_header_t *)addr;
switch (gen_image_get_format ((void *)addr)) {
case IMAGE_FORMAT_LEGACY:
hdr = (image_header_t *)addr;
if (image_check_magic (hdr)) {
if (image_check_magic (hdr)) {
image_print_contents (hdr);
image_print_contents (hdr);
cnt = image_get_image_size (hdr);
cnt -= SECTORSIZE;
} else {
puts ("\n** Bad Magic Number **\n");
show_boot_progress (-39);
cnt = image_get_image_size (hdr);
cnt -= SECTORSIZE;
} else {
puts ("\n** Bad Magic Number **\n");
show_boot_progress (-39);
return 1;
}
break;
#if defined(CONFIG_FIT)
case IMAGE_FORMAT_FIT:
fit_unsupported ("docboot");
return 1;
#endif
default:
puts ("** Unknown image type\n");
return 1;
}
show_boot_progress (39);
......
......@@ -835,14 +835,28 @@ int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
printf("result%d: 0x%02X\n",i,pCMD->result[i]);
return 1;
}
hdr = (image_header_t *)addr;
if (!image_check_magic (hdr)) {
printf ("Bad Magic Number\n");
switch (gen_image_get_format ((void *)addr)) {
case IMAGE_FORMAT_LEGACY:
hdr = (image_header_t *)addr;
if (!image_check_magic (hdr)) {
printf ("Bad Magic Number\n");
return 1;
}
image_print_contents (hdr);
imsize = image_get_image_size (hdr);
break;
#if defined(CONFIG_FIT)
case IMAGE_FORMAT_FIT:
fit_unsupported ("fdcboot");
return 1;
#endif
default:
puts ("** Unknown image type\n");
return 1;
}
image_print_contents (hdr);
imsize= image_get_image_size (hdr);
nrofblk=imsize/512;
if((imsize%512)>0)
nrofblk++;
......@@ -861,20 +875,18 @@ int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
/* Loading ok, update default load address */
load_addr = addr;
if(image_check_type (hdr, IH_TYPE_KERNEL)) {
/* Check if we should attempt an auto-start */
if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) {
char *local_args[2];
extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
/* Check if we should attempt an auto-start */
if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) {
char *local_args[2];
extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
local_args[0] = argv[0];
local_args[1] = NULL;
local_args[0] = argv[0];
local_args[1] = NULL;
printf ("Automatic boot of image at addr 0x%08lX ...\n", addr);
printf ("Automatic boot of image at addr 0x%08lX ...\n", addr);
do_bootm (cmdtp, 0, 1, local_args);
rcode ++;
}
do_bootm (cmdtp, 0, 1, local_args);
rcode ++;
}
return rcode;
}
......
......@@ -216,19 +216,31 @@ int do_fpga (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
break;
case FPGA_LOADMK:
{
image_header_t header;
image_header_t *hdr = &header;
ulong data;
memmove (&header, (char *)fpga_data, image_get_header_size ());
if (!image_check_magic (hdr)) {
puts ("Bad Magic Number\n");
return 1;
switch (gen_image_get_format (fpga_data)) {
case IMAGE_FORMAT_LEGACY:
{
image_header_t *hdr = (image_header_t *)fpga_data;
ulong data;
if (!image_check_magic (hdr)) {
puts ("Bad Magic Number\n");
return 1;
}
data = (ulong)image_get_data (hdr);
data_size = image_get_data_size (hdr);
rc = fpga_load (dev, (void *)data, data_size);
}
data = ((ulong)fpga_data + image_get_header_size ());
data_size = image_get_data_size (hdr);
rc = fpga_load (dev, (void *)data, data_size);
break;
#if defined(CONFIG_FIT)
case IMAGE_FORMAT_FIT:
fit_unsupported ("fpga");
rc = FPGA_FAIL;
break;
#endif
default:
puts ("** Unknown image type\n");
rc = FPGA_FAIL;
break;
}
break;
......
......@@ -446,25 +446,38 @@ int do_diskboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
}
show_boot_progress (48);
hdr = (image_header_t *)addr;
switch (gen_image_get_format ((void *)addr)) {
case IMAGE_FORMAT_LEGACY:
hdr = (image_header_t *)addr;
if (!image_check_magic (hdr)) {
printf("\n** Bad Magic Number **\n");
show_boot_progress (-49);
return 1;
}
show_boot_progress (49);
if (!image_check_magic (hdr)) {
printf("\n** Bad Magic Number **\n");
show_boot_progress (-49);
return 1;
}
show_boot_progress (49);
if (!image_check_hcrc (hdr)) {
puts ("\n** Bad Header Checksum **\n");
show_boot_progress (-50);
return 1;
}
show_boot_progress (50);
if (!image_check_hcrc (hdr)) {
puts ("\n** Bad Header Checksum **\n");
show_boot_progress (-50);
image_print_contents (hdr);
cnt = image_get_image_size (hdr);
break;
#if defined(CONFIG_FIT)
case IMAGE_FORMAT_FIT:
fit_unsupported ("diskboot");
return 1;
#endif
default:
puts ("** Unknown image type\n");
return 1;
}
show_boot_progress (50);
image_print_contents (hdr);
cnt = image_get_image_size (hdr);
cnt += info.blksz - 1;
cnt /= info.blksz;
cnt -= 1;
......
......@@ -512,18 +512,32 @@ static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand,
}
show_boot_progress (56);
hdr = (image_header_t *) addr;
switch (gen_image_get_format ((void *)addr)) {
case IMAGE_FORMAT_LEGACY:
hdr = (image_header_t *)addr;
if (!image_check_magic (hdr)) {
printf("\n** Bad Magic Number 0x%x **\n",
image_get_magic (hdr));
show_boot_progress (-57);
return 1;
}
show_boot_progress (57);
image_print_contents (hdr);
if (!image_check_magic (hdr)) {
printf("\n** Bad Magic Number 0x%x **\n", image_get_magic (hdr));
show_boot_progress (-57);
cnt = image_get_image_size (hdr);
break;
#if defined(CONFIG_FIT)
case IMAGE_FORMAT_FIT:
fit_unsupported ("nand_load_image");
return 1;
#endif
default:
puts ("** Unknown image type\n");
return 1;
}
show_boot_progress (57);
image_print_contents (hdr);
cnt = image_get_image_size (hdr);
if (jffs2) {
nand_read_options_t opts;
memset(&opts, 0, sizeof(opts));
......@@ -980,17 +994,30 @@ int do_nandboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
}
show_boot_progress (56);
hdr = (image_header_t *)addr;
switch (gen_image_get_format ((void *)addr)) {
case IMAGE_FORMAT_LEGACY:
hdr = (image_header_t *)addr;
if (image_check_magic (hdr)) {
if (image_check_magic (hdr)) {
image_print_contents (hdr);
image_print_contents (hdr);
cnt = image_get_image_size (hdr);
cnt -= SECTORSIZE;
} else {
printf ("\n** Bad Magic Number 0x%x **\n", image_get_magic (hdr));
show_boot_progress (-57);
cnt = image_get_image_size (hdr);
cnt -= SECTORSIZE;
} else {
printf ("\n** Bad Magic Number 0x%x **\n",
image_get_magic (hdr));
show_boot_progress (-57);
return 1;
}
break;
#if defined(CONFIG_FIT)
case IMAGE_FORMAT_FIT:
fit_unsupported ("nboot");
return 1;
#endif
default:
puts ("** Unknown image type\n");
return 1;
}
show_boot_progress (57);
......
......@@ -273,20 +273,33 @@ int do_scsiboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
return 1;
}
hdr = (image_header_t *)addr;
switch (gen_image_get_format ((void *)addr)) {
case IMAGE_FORMAT_LEGACY:
hdr = (image_header_t *)addr;
if (!image_check_magic (hdr)) {
printf("\n** Bad Magic Number **\n");
return 1;
}
if (!image_check_magic (hdr)) {
printf("\n** Bad Magic Number **\n");
return 1;
}
if (!image_check_hcrc (hdr)) {
puts ("\n** Bad Header Checksum **\n");
if (!image_check_hcrc (hdr)) {
puts ("\n** Bad Header Checksum **\n");
return 1;
}
image_print_contents (hdr);
cnt = image_get_image_size (hdr);
break;
#if defined(CONFIG_FIT)
case IMAGE_FORMAT_FIT:
fit_unsupported ("scsi");
return 1;
#endif
default:
puts ("** Unknown image type\n");
return 1;
}
image_print_contents (hdr);
cnt = image_get_image_size (hdr);
cnt += info.blksz - 1;
cnt /= info.blksz;
cnt -= 1;
......
......@@ -386,21 +386,34 @@ int do_usbboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
return 1;
}
hdr = (image_header_t *)addr;
switch (gen_image_get_format ((void *)addr)) {
case IMAGE_FORMAT_LEGACY:
hdr = (image_header_t *)addr;
if (!image_check_magic (hdr)) {
printf("\n** Bad Magic Number **\n");
return 1;
}
if (!image_check_magic (hdr)) {
printf("\n** Bad Magic Number **\n");
return 1;
}
if (!image_check_hcrc (hdr)) {
puts ("\n** Bad Header Checksum **\n");
return 1;
}
if (!image_check_hcrc (hdr)) {
puts ("\n** Bad Header Checksum **\n");
image_print_contents (hdr);
cnt = image_get_image_size (hdr);
break;
#if defined(CONFIG_FIT)
case IMAGE_FORMAT_FIT:
fit_unsupported ("usbboot");
return 1;
#endif
default:
puts ("** Unknown image type\n");
return 1;
}
image_print_contents (hdr);
cnt = image_get_image_size (hdr);
cnt += info.blksz - 1;
cnt /= info.blksz;
cnt -= 1;
......
......@@ -56,63 +56,76 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
dest = simple_strtoul(argv[3], NULL, 16);
}
printf("## Copying from image at %08lx ...\n", addr);
hdr = (image_header_t *)addr;
switch (gen_image_get_format ((void *)addr)) {
case IMAGE_FORMAT_LEGACY:
if (!image_check_magic (hdr)) {
printf("Bad Magic Number\n");
return 1;
}
if (!image_check_hcrc (hdr)) {
printf("Bad Header Checksum\n");
return 1;
}
#ifdef DEBUG
image_print_contents (hdr);
#endif
printf("## Copying from legacy image at %08lx ...\n", addr);
hdr = (image_header_t *)addr;
if (!image_check_magic (hdr)) {
printf("Bad Magic Number\n");
return 1;
}
if (!image_check_type (hdr, IH_TYPE_MULTI)) {
printf("Wrong Image Type for %s command\n", cmdtp->name);
return 1;
}
if (!image_check_hcrc (hdr)) {
printf("Bad Header Checksum\n");
return 1;
}
#ifdef DEBUG
image_print_contents (hdr);
#endif
if (image_get_comp (hdr) != IH_COMP_NONE) {
printf("Wrong Compression Type for %s command\n", cmdtp->name);
return 1;
}
if (!image_check_type (hdr, IH_TYPE_MULTI)) {
printf("Wrong Image Type for %s command\n",
cmdtp->name);
return 1;
}
if (verify) {
printf(" Verifying Checksum ... ");
if (!image_check_dcrc (hdr)) {
printf("Bad Data CRC\n");
if (image_get_comp (hdr) != IH_COMP_NONE) {
printf("Wrong Compression Type for %s command\n",
cmdtp->name);
return 1;
}
printf("OK\n");
}
data = image_get_data (hdr);
len_ptr = (ulong *) data;
data += 4; /* terminator */
for (i = 0; len_ptr[i]; ++i) {
data += 4;
if (argc > 2 && part > i) {
u_long tail;
len = image_to_cpu (len_ptr[i]);
tail = len % 4;
data += len;
if (tail) {
data += 4 - tail;
if (verify) {
printf(" Verifying Checksum ... ");
if (!image_check_dcrc (hdr)) {
printf("Bad Data CRC\n");
return 1;
}
printf("OK\n");
}
}
if (argc > 2 && part >= i) {
printf("Bad Image Part\n");
data = image_get_data (hdr);
len_ptr = (ulong *) data;
data += 4; /* terminator */
for (i = 0; len_ptr[i]; ++i) {
data += 4;
if (argc > 2 && part > i) {
u_long tail;