#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 (uchar *, 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)
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_DISK) && (hdr->ih_type != 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)) {
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 = ntohl(hdr->ih_size);
+ /* for kernel and app the image header must also fit into flash */
+ if (idx != IDX_DISK)
+ checksum += sizeof(*hdr);
+ /* 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;
}
#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;
/* 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);
+ addr = (char *)((char *)hdr + sizeof(*hdr));
+ /* stick a NULL at the end of the script, otherwise */
+ /* parse_string_outer() runs off the end. */
+ addr[ntohl(hdr->ih_size)] = 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) {
+ /* strip the header - except for the kernel and ramdisk */
+ if (hdr->ih_type == IH_TYPE_KERNEL || hdr->ih_type == IH_TYPE_RAMDISK) {
+ addr = (char *)hdr;
+ off = sizeof(*hdr);
+ nbytes = sizeof(*hdr) + ntohl(hdr->ih_size);
+ } else {
addr = (char *)((char *)hdr + sizeof(*hdr));
#ifdef AU_UPDATE_TEST
/* copy it to where Linux goes */
#endif
off = 0;
nbytes = ntohl(hdr->ih_size);
- } else {
- addr = (char *)hdr;
- off = sizeof(*hdr);
- nbytes = sizeof(*hdr) + ntohl(hdr->ih_size);
}
/* 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)) {
/* 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;
}
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);
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();