#ifdef CONFIG_AUTO_UPDATE
-#ifndef CONFIG_USB_OHCI
+#ifndef CONFIG_USB_OHCI_NEW
#error "must define CONFIG_USB_OHCI"
#endif
#error "must define CFG_HUSH_PARSER"
#endif
-#if !(CONFIG_COMMANDS & CFG_CMD_FAT)
-#error "must define CFG_CMD_FAT"
+#if !defined(CONFIG_CMD_FAT)
+#error "must define CONFIG_CMD_FAT"
#endif
/*
* valid then run it.
* 2) if preinst.img is found load it into memory. If it is
* valid then run it. Update the EEPROM.
- * 3) if firmware.img is found load it into memory. If it is valid,
+ * 3) if firmw_01.img is found load it into memory. If it is valid,
* burn it into FLASH and update the EEPROM.
- * 4) if kernel.img is found load it into memory. If it is valid,
+ * 4) if kernl_01.img is found load it into memory. If it is valid,
* burn it into FLASH and update the EEPROM.
* 5) if app.img is found load it into memory. If it is valid,
* burn it into FLASH and update the EEPROM.
/* possible names of files on the USB stick. */
#define AU_PREPARE "prepare.img"
#define AU_PREINST "preinst.img"
-#define AU_FIRMWARE "firmware.img"
-#define AU_KERNEL "kernel.img"
+#define AU_FIRMWARE "firmw_01.img"
+#define AU_KERNEL "kernl_01.img"
#define AU_APP "app.img"
#define AU_DISK "disk.img"
#define AU_POSTINST "postinst.img"
#define FIDX_TO_LIDX(idx) ((idx) - 2)
/* where to load files into memory */
-#define LOAD_ADDR ((unsigned char *)0x0C100100)
-/* where to build strings in memory - 256 bytes should be enough */
-#define STRING_ADDR ((char *)0x0C100000)
+#define LOAD_ADDR ((unsigned char *)0x0C100000)
/* the app is the largest image */
#define MAX_LOADSZ ausize[IDX_APP]
extern int trab_vfd (ulong);
extern int transfer_pic(unsigned char, unsigned char *, int, int);
#endif
+extern int flash_sect_erase(ulong, ulong);
+extern int flash_sect_protect (int, ulong, ulong);
+extern int flash_write (char *, ulong, ulong);
/* change char* to void* to shutup the compiler */
extern int i2c_write_multiple (uchar, uint, int, void *, int);
extern int i2c_read_multiple (uchar, uint, int, void *, int);
-extern block_dev_desc_t *get_dev (char*, int);
+extern int u_boot_hush_start(void);
int
-au_check_valid(int idx, long nbytes)
+au_check_cksum_valid(int idx, long nbytes)
+{
+ image_header_t *hdr;
+
+ 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 != image_get_image_size (hdr)) {
+ printf ("Image %s bad total SIZE\n", aufile[idx]);
+ return -1;
+ }
+ /* check the data CRC */
+ if (!image_check_dcrc (hdr)) {
+ printf ("Image %s bad data checksum\n", aufile[idx]);
+ return -1;
+ }
+ return 0;
+}
+
+int
+au_check_header_valid(int idx, long nbytes)
{
image_header_t *hdr;
unsigned long checksum;
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 (ntohl(hdr->ih_magic) != IH_MAGIC ||
- hdr->ih_arch != IH_CPU_ARM ||
- nbytes != (sizeof(*hdr) + ntohl(hdr->ih_size)))
- {
- printf ("Image %s bad MAGIC or ARCH or SIZE\n", aufile[idx]);
+ if (nbytes < image_get_header_size ()) {
+ printf ("Image %s bad header SIZE\n", aufile[idx]);
+ return -1;
+ }
+ 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, (char *)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 data CRC */
- checksum = ntohl(hdr->ih_dcrc);
-
- if (crc32 (0, (char *)(LOAD_ADDR + sizeof(*hdr)), ntohl(hdr->ih_size))
- != checksum)
- {
- printf ("Image %s bad data checksum\n", aufile[idx]);
+ /* check the type - could do this all in one gigantic if() */
+ if ((idx == IDX_FIRMWARE) &&
+ !image_check_type (hdr, IH_TYPE_FIRMWARE)) {
+ printf ("Image %s wrong type\n", aufile[idx]);
return -1;
}
- /* check the type - could do this all in one gigantic if() */
- if ((idx == IDX_FIRMWARE) && (hdr->ih_type != IH_TYPE_FIRMWARE)) {
+ if ((idx == IDX_KERNEL) && !image_check_type (hdr, IH_TYPE_KERNEL)) {
printf ("Image %s wrong type\n", aufile[idx]);
return -1;
}
- if ((idx == IDX_KERNEL) && (hdr->ih_type != IH_TYPE_KERNEL)) {
+ if ((idx == IDX_DISK) && !image_check_type (hdr, IH_TYPE_FILESYSTEM)) {
printf ("Image %s wrong type\n", aufile[idx]);
return -1;
}
- if ((idx == IDX_DISK || idx == IDX_APP)
- && (hdr->ih_type != IH_TYPE_RAMDISK))
- {
+ 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;
}
/* special case for prepare.img */
if (idx == IDX_PREPARE)
return 0;
- /* check the size does not exceed space in flash */
- if ((ausize[idx] != 0) && (ausize[idx] < ntohl(hdr->ih_size))) {
+ /* recycle checksum */
+ 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 += 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)) {
printf ("Image %s is bigger than FLASH\n", aufile[idx]);
return -1;
}
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;
}
#define POWER_OFF (1 << 1)
int
-au_do_update(int idx, long sz, int repeat)
+au_do_update(int idx, long sz)
{
image_header_t *hdr;
char *addr;
long start, end;
- char *strbuf = STRING_ADDR;
- int off;
+ int off, rc;
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) + 8);
- parse_string_outer(addr,
- FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP);
+ 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[image_get_data_size (hdr)] = 0;
+ addr += 8;
+ parse_string_outer(addr, FLAG_PARSE_SEMICOLON);
return 0;
}
start = aufl_layout[1].start;
end = aufl_layout[1].end;
#endif
- debug ("protect off %lx %lx\n", start, end);
- sprintf(strbuf, "protect off %lx %lx\n", start, end);
- parse_string_outer(strbuf,
- FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP);
+ flash_sect_protect(0, start, end);
}
/*
- * erase the address range. Multiple erases seem to cause
- * problems.
+ * erase the address range.
*/
- if (repeat == 0) {
- debug ("erase %lx %lx\n", start, end);
- sprintf(strbuf, "erase %lx %lx\n", start, end);
- parse_string_outer(strbuf,
- FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP);
- }
+ debug ("flash_sect_erase(%lx, %lx);\n", start, end);
+ flash_sect_erase(start, end);
wait_ms(100);
- /* strip the header - except for the kernel */
- if (idx == IDX_FIRMWARE || idx == IDX_DISK || idx == IDX_APP) {
- addr = (char *)((char *)hdr + sizeof(*hdr));
+ /* strip the header - except for the kernel and ramdisk */
+ if (image_check_type (hdr, IH_TYPE_KERNEL) ||
+ image_check_type (hdr, IH_TYPE_RAMDISK)) {
+ addr = (char *)hdr;
+ off = image_get_header_size ();
+ nbytes = image_get_image_size (hdr);
+ } else {
+ 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);
- } else {
- addr = (char *)hdr;
- off = sizeof(*hdr);
- nbytes = sizeof(*hdr) + ntohl(hdr->ih_size);
+ nbytes = image_get_data_size (hdr);
}
/* copy the data from RAM to FLASH */
- debug ("cp.b %p %lx %x\n", addr, start, nbytes);
- sprintf(strbuf, "cp.b %p %lx %x\n", addr, start, nbytes);
- parse_string_outer(strbuf,
- FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP);
+ debug ("flash_write(%p, %lx %x)\n", addr, start, nbytes);
+ rc = flash_write(addr, start, nbytes);
+ if (rc != 0) {
+ printf("Flashing failed due to error %d\n", rc);
+ return -1;
+ }
/* check the dcrc of the copy */
- if (crc32 (0, (char *)(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;
}
/* protect the address range */
/* this assumes that ONLY the firmware is protected! */
- if (idx == IDX_FIRMWARE) {
- debug ("protect on %lx %lx\n", start, end);
- sprintf(strbuf, "protect on %lx %lx\n", start, end);
- parse_string_outer(strbuf,
- FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP);
- }
+ if (idx == IDX_FIRMWARE)
+ flash_sect_protect(1, start, end);
return 0;
}
int off;
uint32_t val;
+ /* special case for prepare.img */
+ if (idx == IDX_PREPARE) {
+ /* enable the power switch */
+ *CPLD_VFD_BK &= ~POWER_OFF;
+ return 0;
+ }
+
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;
{
block_dev_desc_t *stor_dev;
long sz;
- int i, res, bitmap_first, cnt, old_ctrlc, got_ctrlc;
+ int i, res = 0, bitmap_first, cnt, old_ctrlc, got_ctrlc;
char *env;
long start, end;
* check whether a storage device is attached (assume that it's
* a USB memory stick, since nothing else should be attached).
*/
- au_usb_stor_curr_dev = usb_stor_scan(1);
+ au_usb_stor_curr_dev = usb_stor_scan(0);
if (au_usb_stor_curr_dev == -1) {
debug ("No device found. Not initialized?\n");
- return -1;
+ res = -1;
+ goto xit;
}
/* check whether it has a partition table */
stor_dev = get_dev("usb", 0);
if (stor_dev == NULL) {
debug ("uknown device type\n");
- return -1;
+ res = -1;
+ goto xit;
}
if (fat_register_device(stor_dev, 1) != 0) {
debug ("Unable to use USB %d:%d for fatls\n",
au_usb_stor_curr_dev, 1);
- return -1;
+ res = -1;
+ goto xit;
}
if (file_fat_detectfs() != 0) {
debug ("file_fat_detectfs failed\n");
env = getenv("firmware_nd");
if (env != NULL)
end = simple_strtoul(env, NULL, 16);
- if (start >= 0 && end && end > start)
+ if (start >= 0 && end && end > start) {
ausize[IDX_FIRMWARE] = (end + 1) - start;
+ aufl_layout[0].start = start;
+ aufl_layout[0].end = end;
+ }
start = -1;
end = 0;
env = getenv("kernel_st");
env = getenv("kernel_nd");
if (env != NULL)
end = simple_strtoul(env, NULL, 16);
- if (start >= 0 && end && end > start)
+ if (start >= 0 && end && end > start) {
ausize[IDX_KERNEL] = (end + 1) - start;
+ aufl_layout[1].start = start;
+ aufl_layout[1].end = end;
+ }
start = -1;
end = 0;
env = getenv("app_st");
env = getenv("app_nd");
if (env != NULL)
end = simple_strtoul(env, NULL, 16);
- if (start >= 0 && end && end > start)
+ if (start >= 0 && end && end > start) {
ausize[IDX_APP] = (end + 1) - start;
+ aufl_layout[2].start = start;
+ aufl_layout[2].end = end;
+ }
start = -1;
end = 0;
env = getenv("disk_st");
env = getenv("disk_nd");
if (env != NULL)
end = simple_strtoul(env, NULL, 16);
- if (start >= 0 && end && end > start)
+ if (start >= 0 && end && end > start) {
ausize[IDX_DISK] = (end + 1) - start;
+ aufl_layout[3].start = start;
+ aufl_layout[3].end = end;
+ }
+ /* make certain that HUSH is runnable */
+ u_boot_hush_start();
/* make sure that we see CTRL-C and save the old state */
old_ctrlc = disable_ctrlc(0);
bitmap_first = 0;
/* 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, image_get_header_size ());
+ debug ("read %s sz %ld hdr %d\n",
+ aufile[i], sz, image_get_header_size ());
+ if (sz <= 0 || sz < image_get_header_size ()) {
+ debug ("%s not found\n", aufile[i]);
+ continue;
+ }
+ if (au_check_header_valid(i, sz) < 0) {
+ debug ("%s header not valid\n", aufile[i]);
+ continue;
+ }
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;
}
- if (au_check_valid(i, sz) < 0) {
- debug ("%s not valid\n", aufile[i]);
+ if (au_check_cksum_valid(i, sz) < 0) {
+ debug ("%s checksum not valid\n", aufile[i]);
continue;
}
#ifdef CONFIG_VFD
#define VFD_LOGO_WIDTH 112
#define VFD_LOGO_HEIGHT 72
/* must call transfer_pic directly */
- transfer_pic(3, env, VFD_LOGO_HEIGHT, VFD_LOGO_WIDTH);
+ transfer_pic(3, (unsigned char *)env,
+ VFD_LOGO_HEIGHT, VFD_LOGO_WIDTH);
}
bitmap_first = 1;
}
cnt = 0;
got_ctrlc = 0;
do {
- res = au_do_update(i, sz, cnt);
+ res = au_do_update(i, sz);
/* let the user break out of the loop */
if (ctrlc() || had_ctrlc()) {
clear_ctrlc();
/* enable the power switch */
*CPLD_VFD_BK &= ~POWER_OFF;
}
- usb_stop();
/* restore the old state */
disable_ctrlc(old_ctrlc);
- return 0;
+xit:
+ usb_stop();
+ return res;
}
#endif /* CONFIG_AUTO_UPDATE */