Work on TRAB's auto_update feature.

Cleanup for submitted patches.
This commit is contained in:
wdenk 2003-09-18 18:55:25 +00:00
parent 65bd0e284b
commit 80369866a4
3 changed files with 111 additions and 41 deletions

View file

@ -202,6 +202,7 @@ extern int transfer_pic(unsigned char, unsigned char *, int, int);
/* 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);
int
au_check_valid(int idx, long nbytes)
@ -221,7 +222,8 @@ au_check_valid(int idx, long nbytes)
#endif
if (ntohl(hdr->ih_magic) != IH_MAGIC ||
hdr->ih_arch != IH_CPU_ARM ||
nbytes < ntohl(hdr->ih_size)) {
nbytes < ntohl(hdr->ih_size))
{
printf ("Image %s bad MAGIC or ARCH or SIZE\n", aufile[idx]);
return -1;
}
@ -233,6 +235,7 @@ au_check_valid(int idx, long nbytes)
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);
@ -275,8 +278,10 @@ au_check_valid(int idx, long nbytes)
/* read it in */
i2c_read_multiple(0x54, auee_off[idx].time, 1, buf, sizeof(buf));
#ifdef CHECK_VALID_DEBUG
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));
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));
#endif
/* check it */
if (*((unsigned int *)buf) >= ntohl(hdr->ih_time)) {
@ -292,7 +297,7 @@ buf[0], buf[1], buf[2], buf[3], *((unsigned int *)buf), ntohl(hdr->ih_time));
#define POWER_OFF (1 << 1)
int
au_do_update(int idx, long sz)
au_do_update(int idx, long sz, int repeat)
{
image_header_t *hdr;
char *addr;
@ -332,12 +337,17 @@ au_do_update(int idx, long sz)
FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP);
}
/* erase the address range */
/*
* erase the address range. Multiple erases seem to cause
* problems.
*/
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);
}
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));
@ -361,8 +371,7 @@ au_do_update(int idx, long sz)
FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP);
/* check the dcrc of the copy */
if (crc32 (0, (char *)(start + off), ntohl(hdr->ih_size))
!= ntohl(hdr->ih_dcrc)) {
if (crc32 (0, (char *)(start + off), ntohl(hdr->ih_size)) != ntohl(hdr->ih_dcrc)) {
printf ("Image %s Bad Data Checksum After COPY\n", aufile[idx]);
return -1;
}
@ -370,7 +379,7 @@ au_do_update(int idx, long sz)
/* protect the address range */
/* this assumes that ONLY the firmware is protected! */
if (idx == IDX_FIRMWARE) {
printf("protect on %lx %lx\n", start, end);
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);
@ -413,8 +422,9 @@ do_auto_update(void)
{
block_dev_desc_t *stor_dev;
long sz;
int i, res, bitmap_first, cnt;
int i, res, bitmap_first, cnt, old_ctrlc, got_ctrlc;
char *env;
long start, end;
#undef ERASE_EEPROM
#ifdef ERASE_EEPROM
@ -442,8 +452,8 @@ do_auto_update(void)
return -1;
}
/* check whether it has a partition table */
stor_dev = usb_stor_get_dev(au_usb_stor_curr_dev);
if (stor_dev->type == DEV_TYPE_UNKNOWN) {
stor_dev = get_dev("usb", 0);
if (stor_dev == NULL) {
debug ("uknown device type\n");
return -1;
}
@ -471,6 +481,49 @@ do_auto_update(void)
ausize[IDX_KERNEL] = (AU_FL_KERNEL_ND + 1) - AU_FL_KERNEL_ST;
ausize[IDX_APP] = (AU_FL_APP_ND + 1) - AU_FL_APP_ST;
ausize[IDX_DISK] = (AU_FL_DISK_ND + 1) - AU_FL_DISK_ST;
/*
* now check whether start and end are defined using environment
* variables.
*/
start = end = 0;
env = getenv("firmware_st");
if (env != NULL)
start = simple_strtoul(env, NULL, 16);
env = getenv("firmware_nd");
if (env != NULL)
end = simple_strtoul(env, NULL, 16);
if (start && end && end > start)
ausize[IDX_FIRMWARE] = (end + 1) - start;
start = end = 0;
env = getenv("kernel_st");
if (env != NULL)
start = simple_strtoul(env, NULL, 16);
env = getenv("kernel_nd");
if (env != NULL)
end = simple_strtoul(env, NULL, 16);
if (start && end && end > start)
ausize[IDX_KERNEL] = (end + 1) - start;
start = end = 0;
env = getenv("app_st");
if (env != NULL)
start = simple_strtoul(env, NULL, 16);
env = getenv("app_nd");
if (env != NULL)
end = simple_strtoul(env, NULL, 16);
if (start && end && end > start)
ausize[IDX_APP] = (end + 1) - start;
start = end = 0;
env = getenv("disk_st");
if (env != NULL)
start = simple_strtoul(env, NULL, 16);
env = getenv("disk_nd");
if (env != NULL)
end = simple_strtoul(env, NULL, 16);
if (start && end && end > start)
ausize[IDX_DISK] = (end + 1) - 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++) {
@ -509,18 +562,33 @@ do_auto_update(void)
/* this is really not a good idea, but it's what the */
/* customer wants. */
cnt = 0;
got_ctrlc = 0;
do {
res = au_do_update(i, sz);
#ifdef AU_TEST_ONLY
res = au_do_update(i, sz, cnt);
/* let the user break out of the loop */
if (ctrlc() || had_ctrlc()) {
clear_ctrlc();
if (res < 0)
got_ctrlc = 1;
break;
}
cnt++;
#ifdef AU_TEST_ONLY
} while (res < 0 && cnt < 3);
if (cnt < 3)
#else
} while (res < 0);
#endif
/*
* it doesn't make sense to update the EEPROM if the
* update was interrupted by the user due to errors.
*/
if (got_ctrlc == 0)
au_update_eeprom(i);
}
usb_stop();
/* restore the old state */
disable_ctrlc(old_ctrlc);
return 0;
}
#endif /* CONFIG_AUTO_UPDATE */

View file

@ -159,6 +159,8 @@ int device_deregister(char *devname)
int devices_init (void)
{
#ifndef CONFIG_ARM /* already relocated for current ARM implementation */
DECLARE_GLOBAL_DATA_PTR;
ulong relocation_offset = gd->reloc_off;
int i;