2004-12-16 18:43:13 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2003-2004
|
|
|
|
* Gary Jennejohn, DENX Software Engineering, gj@denx.de.
|
|
|
|
* Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2006-03-05 17:57:33 +00:00
|
|
|
|
2004-12-16 18:43:13 +00:00
|
|
|
#include <command.h>
|
|
|
|
#include <image.h>
|
|
|
|
#include <asm/byteorder.h>
|
2008-08-12 23:40:43 +00:00
|
|
|
#if defined(CONFIG_NAND_LEGACY)
|
2006-03-05 17:57:33 +00:00
|
|
|
#include <linux/mtd/nand_legacy.h>
|
2007-07-09 08:10:04 +00:00
|
|
|
#endif
|
2004-12-16 18:43:13 +00:00
|
|
|
#include <fat.h>
|
2007-02-20 08:04:34 +00:00
|
|
|
#include <part.h>
|
2004-12-16 18:43:13 +00:00
|
|
|
|
|
|
|
#include "auto_update.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUTO_UPDATE
|
|
|
|
|
2007-07-09 23:24:55 +00:00
|
|
|
#if !defined(CONFIG_CMD_FAT)
|
2007-07-10 15:39:10 +00:00
|
|
|
#error "must define CONFIG_CMD_FAT"
|
2004-12-16 18:43:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
extern au_image_t au_image[];
|
|
|
|
extern int N_AU_IMAGES;
|
|
|
|
|
2008-04-21 12:42:06 +00:00
|
|
|
/* where to load files into memory */
|
|
|
|
#define LOAD_ADDR ((unsigned char *)0x100000)
|
|
|
|
#define MAX_LOADSZ 0x1c00000
|
2004-12-16 18:43:13 +00:00
|
|
|
|
|
|
|
/* externals */
|
|
|
|
extern int fat_register_device(block_dev_desc_t *, int);
|
|
|
|
extern int file_fat_detectfs(void);
|
|
|
|
extern long file_fat_read(const char *, void *, unsigned long);
|
2008-04-21 12:42:06 +00:00
|
|
|
long do_fat_read (const char *filename, void *buffer,
|
|
|
|
unsigned long maxsize, int dols);
|
2004-12-16 18:43:13 +00:00
|
|
|
extern int flash_sect_erase(ulong, ulong);
|
|
|
|
extern int flash_sect_protect (int, ulong, ulong);
|
2005-10-20 14:39:16 +00:00
|
|
|
extern int flash_write (char *, ulong, ulong);
|
2004-12-16 18:43:13 +00:00
|
|
|
|
2008-08-12 23:40:43 +00:00
|
|
|
#if defined(CONFIG_CMD_NAND) && defined(CONFIG_NAND_LEGACY)
|
2004-12-16 18:43:13 +00:00
|
|
|
/* references to names in cmd_nand.c */
|
|
|
|
#define NANDRW_READ 0x01
|
|
|
|
#define NANDRW_WRITE 0x00
|
|
|
|
#define NANDRW_JFFS2 0x02
|
|
|
|
#define NANDRW_JFFS2_SKIP 0x04
|
|
|
|
extern struct nand_chip nand_dev_desc[];
|
2008-04-21 12:42:06 +00:00
|
|
|
extern int nand_legacy_rw(struct nand_chip* nand, int cmd,
|
|
|
|
size_t start, size_t len,
|
|
|
|
size_t * retlen, u_char * buf);
|
|
|
|
extern int nand_legacy_erase(struct nand_chip* nand, size_t ofs,
|
|
|
|
size_t len, int clean);
|
2007-07-09 23:24:55 +00:00
|
|
|
#endif
|
2004-12-16 18:43:13 +00:00
|
|
|
|
|
|
|
extern block_dev_desc_t ide_dev_desc[CFG_IDE_MAXDEVICE];
|
|
|
|
|
|
|
|
int au_check_cksum_valid(int i, long nbytes)
|
|
|
|
{
|
|
|
|
image_header_t *hdr;
|
|
|
|
|
|
|
|
hdr = (image_header_t *)LOAD_ADDR;
|
2008-02-04 07:28:09 +00:00
|
|
|
#if defined(CONFIG_FIT)
|
2008-02-29 13:58:34 +00:00
|
|
|
if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
|
2008-02-04 07:28:09 +00:00
|
|
|
puts ("Non legacy image format not supported\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
2004-12-16 18:43:13 +00:00
|
|
|
|
2008-01-08 17:14:09 +00:00
|
|
|
if ((au_image[i].type == AU_FIRMWARE) &&
|
|
|
|
(au_image[i].size != image_get_data_size (hdr))) {
|
2004-12-16 18:43:13 +00:00
|
|
|
printf ("Image %s has wrong size\n", au_image[i].name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-01-08 17:14:09 +00:00
|
|
|
if (nbytes != (image_get_image_size (hdr))) {
|
2004-12-16 18:43:13 +00:00
|
|
|
printf ("Image %s bad total SIZE\n", au_image[i].name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-01-08 17:14:09 +00:00
|
|
|
/* check the data CRC */
|
|
|
|
if (!image_check_dcrc (hdr)) {
|
2004-12-16 18:43:13 +00:00
|
|
|
printf ("Image %s bad data checksum\n", au_image[i].name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int au_check_header_valid(int i, long nbytes)
|
|
|
|
{
|
|
|
|
image_header_t *hdr;
|
|
|
|
unsigned long checksum;
|
|
|
|
|
|
|
|
hdr = (image_header_t *)LOAD_ADDR;
|
2008-02-04 07:28:09 +00:00
|
|
|
#if defined(CONFIG_FIT)
|
2008-02-29 13:58:34 +00:00
|
|
|
if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
|
2008-02-04 07:28:09 +00:00
|
|
|
puts ("Non legacy image format not supported\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-12-16 18:43:13 +00:00
|
|
|
/* check the easy ones first */
|
2008-04-21 12:42:06 +00:00
|
|
|
if (nbytes < image_get_header_size ()) {
|
2004-12-16 18:43:13 +00:00
|
|
|
printf ("Image %s bad header SIZE\n", au_image[i].name);
|
|
|
|
return -1;
|
|
|
|
}
|
2008-04-21 12:42:06 +00:00
|
|
|
if (!image_check_magic (hdr) || !image_check_arch (hdr, IH_ARCH_PPC)) {
|
2004-12-16 18:43:13 +00:00
|
|
|
printf ("Image %s bad MAGIC or ARCH\n", au_image[i].name);
|
|
|
|
return -1;
|
|
|
|
}
|
2008-01-08 17:14:09 +00:00
|
|
|
if (!image_check_hcrc (hdr)) {
|
2004-12-16 18:43:13 +00:00
|
|
|
printf ("Image %s bad header checksum\n", au_image[i].name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check the type - could do this all in one gigantic if() */
|
2008-04-21 12:42:06 +00:00
|
|
|
if (((au_image[i].type & AU_TYPEMASK) == AU_FIRMWARE) &&
|
|
|
|
!image_check_type (hdr, IH_TYPE_FIRMWARE)) {
|
2004-12-16 18:43:13 +00:00
|
|
|
printf ("Image %s wrong type\n", au_image[i].name);
|
|
|
|
return -1;
|
|
|
|
}
|
2008-04-21 12:42:06 +00:00
|
|
|
if (((au_image[i].type & AU_TYPEMASK) == AU_SCRIPT) &&
|
|
|
|
!image_check_type (hdr, IH_TYPE_SCRIPT)) {
|
2004-12-16 18:43:13 +00:00
|
|
|
printf ("Image %s wrong type\n", au_image[i].name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* recycle checksum */
|
2008-01-08 17:14:09 +00:00
|
|
|
checksum = image_get_data_size (hdr);
|
2004-12-16 18:43:13 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int au_do_update(int i, long sz)
|
|
|
|
{
|
|
|
|
image_header_t *hdr;
|
|
|
|
char *addr;
|
|
|
|
long start, end;
|
|
|
|
int off, rc;
|
|
|
|
uint nbytes;
|
|
|
|
int k;
|
2008-08-12 23:40:43 +00:00
|
|
|
#if defined(CONFIG_CMD_NAND) && defined(CONFIG_NAND_LEGACY)
|
2004-12-16 18:43:13 +00:00
|
|
|
int total;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
hdr = (image_header_t *)LOAD_ADDR;
|
2008-02-04 07:28:09 +00:00
|
|
|
#if defined(CONFIG_FIT)
|
2008-02-29 13:58:34 +00:00
|
|
|
if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
|
2008-02-04 07:28:09 +00:00
|
|
|
puts ("Non legacy image format not supported\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
2004-12-16 18:43:13 +00:00
|
|
|
|
2008-04-21 12:42:06 +00:00
|
|
|
switch (au_image[i].type & AU_TYPEMASK) {
|
2004-12-16 18:43:13 +00:00
|
|
|
case AU_SCRIPT:
|
|
|
|
printf("Executing script %s\n", au_image[i].name);
|
|
|
|
|
|
|
|
/* execute a script */
|
2008-01-08 17:14:09 +00:00
|
|
|
if (image_check_type (hdr, IH_TYPE_SCRIPT)) {
|
|
|
|
addr = (char *)((char *)hdr + image_get_header_size ());
|
2004-12-16 18:43:13 +00:00
|
|
|
/* stick a NULL at the end of the script, otherwise */
|
|
|
|
/* parse_string_outer() runs off the end. */
|
2008-01-08 17:14:09 +00:00
|
|
|
addr[image_get_data_size (hdr)] = 0;
|
2004-12-16 18:43:13 +00:00
|
|
|
addr += 8;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Replace cr/lf with ;
|
|
|
|
*/
|
|
|
|
k = 0;
|
|
|
|
while (addr[k] != 0) {
|
|
|
|
if ((addr[k] == 10) || (addr[k] == 13)) {
|
|
|
|
addr[k] = ';';
|
|
|
|
}
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
|
|
|
|
run_command(addr, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AU_FIRMWARE:
|
|
|
|
case AU_NOR:
|
|
|
|
case AU_NAND:
|
|
|
|
start = au_image[i].start;
|
|
|
|
end = au_image[i].start + au_image[i].size - 1;
|
|
|
|
|
2005-03-16 20:58:31 +00:00
|
|
|
/*
|
|
|
|
* do not update firmware when image is already in flash.
|
|
|
|
*/
|
|
|
|
if (au_image[i].type == AU_FIRMWARE) {
|
|
|
|
char *orig = (char*)start;
|
2008-04-21 12:42:06 +00:00
|
|
|
char *new = (char *)((char *)hdr +
|
|
|
|
image_get_header_size ());
|
2008-01-08 17:14:09 +00:00
|
|
|
nbytes = image_get_data_size (hdr);
|
2005-03-16 20:58:31 +00:00
|
|
|
|
2008-04-21 12:42:06 +00:00
|
|
|
while (--nbytes) {
|
2005-03-16 20:58:31 +00:00
|
|
|
if (*orig++ != *new++) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!nbytes) {
|
2008-04-21 12:42:06 +00:00
|
|
|
printf ("Skipping firmware update - "
|
|
|
|
"images are identical\n");
|
2005-03-16 20:58:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-16 18:43:13 +00:00
|
|
|
/* unprotect the address range */
|
2008-04-21 12:42:06 +00:00
|
|
|
if (((au_image[i].type & AU_FLAGMASK) == AU_PROTECT) ||
|
|
|
|
(au_image[i].type == AU_FIRMWARE)) {
|
|
|
|
flash_sect_protect (0, start, end);
|
2004-12-16 18:43:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* erase the address range.
|
|
|
|
*/
|
|
|
|
if (au_image[i].type != AU_NAND) {
|
2008-04-21 12:42:06 +00:00
|
|
|
printf ("Updating NOR FLASH with image %s\n",
|
|
|
|
au_image[i].name);
|
2004-12-16 18:43:13 +00:00
|
|
|
debug ("flash_sect_erase(%lx, %lx);\n", start, end);
|
2008-04-21 12:42:06 +00:00
|
|
|
flash_sect_erase (start, end);
|
2004-12-16 18:43:13 +00:00
|
|
|
} else {
|
2008-08-12 23:40:43 +00:00
|
|
|
#if defined(CONFIG_CMD_NAND) && defined(CONFIG_NAND_LEGACY)
|
2008-04-21 12:42:06 +00:00
|
|
|
printf ("Updating NAND FLASH with image %s\n",
|
|
|
|
au_image[i].name);
|
2006-03-05 17:57:33 +00:00
|
|
|
debug ("nand_legacy_erase(%lx, %lx);\n", start, end);
|
2008-04-21 12:42:06 +00:00
|
|
|
rc = nand_legacy_erase (nand_dev_desc, start,
|
|
|
|
end - start + 1, 0);
|
2006-03-05 17:57:33 +00:00
|
|
|
debug ("nand_legacy_erase returned %x\n", rc);
|
2004-12-16 18:43:13 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
udelay(10000);
|
|
|
|
|
|
|
|
/* strip the header - except for the kernel and ramdisk */
|
|
|
|
if (au_image[i].type != AU_FIRMWARE) {
|
|
|
|
addr = (char *)hdr;
|
2008-01-08 17:14:09 +00:00
|
|
|
off = image_get_header_size ();
|
|
|
|
nbytes = image_get_image_size (hdr);
|
2004-12-16 18:43:13 +00:00
|
|
|
} else {
|
2008-01-08 17:14:09 +00:00
|
|
|
addr = (char *)((char *)hdr + image_get_header_size ());
|
2004-12-16 18:43:13 +00:00
|
|
|
off = 0;
|
2008-01-08 17:14:09 +00:00
|
|
|
nbytes = image_get_data_size (hdr);
|
2004-12-16 18:43:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* copy the data from RAM to FLASH
|
|
|
|
*/
|
|
|
|
if (au_image[i].type != AU_NAND) {
|
2008-04-21 12:42:06 +00:00
|
|
|
debug ("flash_write(%p, %lx, %x)\n",
|
|
|
|
addr, start, nbytes);
|
|
|
|
rc = flash_write ((char *)addr, start,
|
|
|
|
(nbytes + 1) & ~1);
|
2004-12-16 18:43:13 +00:00
|
|
|
} else {
|
2008-08-12 23:40:43 +00:00
|
|
|
#if defined(CONFIG_CMD_NAND) && defined(CONFIG_NAND_LEGACY)
|
2008-04-21 12:42:06 +00:00
|
|
|
debug ("nand_legacy_rw(%p, %lx, %x)\n",
|
|
|
|
addr, start, nbytes);
|
|
|
|
rc = nand_legacy_rw (nand_dev_desc,
|
|
|
|
NANDRW_WRITE | NANDRW_JFFS2,
|
|
|
|
start, nbytes, (size_t *)&total,
|
|
|
|
(uchar *)addr);
|
|
|
|
debug ("nand_legacy_rw: ret=%x total=%d nbytes=%d\n",
|
|
|
|
rc, total, nbytes);
|
2007-07-09 08:10:04 +00:00
|
|
|
#else
|
|
|
|
rc = -1;
|
2004-12-16 18:43:13 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (rc != 0) {
|
2008-04-21 12:42:06 +00:00
|
|
|
printf ("Flashing failed due to error %d\n", rc);
|
2004-12-16 18:43:13 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check the dcrc of the copy
|
|
|
|
*/
|
|
|
|
if (au_image[i].type != AU_NAND) {
|
2008-04-21 12:42:06 +00:00
|
|
|
rc = crc32 (0, (uchar *)(start + off),
|
|
|
|
image_get_data_size (hdr));
|
2004-12-16 18:43:13 +00:00
|
|
|
} else {
|
2008-08-12 23:40:43 +00:00
|
|
|
#if defined(CONFIG_CMD_NAND) && defined(CONFIG_NAND_LEGACY)
|
2008-04-21 12:42:06 +00:00
|
|
|
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),
|
|
|
|
image_get_data_size (hdr));
|
2004-12-16 18:43:13 +00:00
|
|
|
#endif
|
|
|
|
}
|
2008-01-08 17:14:09 +00:00
|
|
|
if (rc != image_get_dcrc (hdr)) {
|
2008-04-21 12:42:06 +00:00
|
|
|
printf ("Image %s Bad Data Checksum After COPY\n",
|
|
|
|
au_image[i].name);
|
2004-12-16 18:43:13 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* protect the address range */
|
|
|
|
/* this assumes that ONLY the firmware is protected! */
|
2008-04-21 12:42:06 +00:00
|
|
|
if (((au_image[i].type & AU_FLAGMASK) == AU_PROTECT) ||
|
|
|
|
(au_image[i].type == AU_FIRMWARE)) {
|
|
|
|
flash_sect_protect (1, start, end);
|
2004-12-16 18:43:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("Wrong image type selected!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void process_macros (const char *input, char *output)
|
|
|
|
{
|
|
|
|
char c, prev;
|
|
|
|
const char *varname_start = NULL;
|
|
|
|
int inputcnt = strlen (input);
|
|
|
|
int outputcnt = CFG_CBSIZE;
|
|
|
|
int state = 0; /* 0 = waiting for '$' */
|
|
|
|
/* 1 = waiting for '(' or '{' */
|
|
|
|
/* 2 = waiting for ')' or '}' */
|
|
|
|
/* 3 = waiting for ''' */
|
|
|
|
#ifdef DEBUG_PARSER
|
|
|
|
char *output_start = output;
|
|
|
|
|
2008-04-21 12:42:06 +00:00
|
|
|
printf ("[PROCESS_MACROS] INPUT len %d: \"%s\"\n",
|
|
|
|
strlen(input), input);
|
2004-12-16 18:43:13 +00:00
|
|
|
#endif
|
|
|
|
|
2008-04-21 12:42:06 +00:00
|
|
|
prev = '\0'; /* previous character */
|
2004-12-16 18:43:13 +00:00
|
|
|
|
|
|
|
while (inputcnt && outputcnt) {
|
|
|
|
c = *input++;
|
|
|
|
inputcnt--;
|
|
|
|
|
2008-04-21 12:42:06 +00:00
|
|
|
if (state != 3) {
|
2004-12-16 18:43:13 +00:00
|
|
|
/* remove one level of escape characters */
|
|
|
|
if ((c == '\\') && (prev != '\\')) {
|
|
|
|
if (inputcnt-- == 0)
|
|
|
|
break;
|
|
|
|
prev = c;
|
|
|
|
c = *input++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (state) {
|
2008-04-21 12:42:06 +00:00
|
|
|
case 0: /* Waiting for (unescaped) $ */
|
2004-12-16 18:43:13 +00:00
|
|
|
if ((c == '\'') && (prev != '\\')) {
|
|
|
|
state = 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((c == '$') && (prev != '\\')) {
|
|
|
|
state++;
|
|
|
|
} else {
|
|
|
|
*(output++) = c;
|
|
|
|
outputcnt--;
|
|
|
|
}
|
|
|
|
break;
|
2008-04-21 12:42:06 +00:00
|
|
|
case 1: /* Waiting for ( */
|
2004-12-16 18:43:13 +00:00
|
|
|
if (c == '(' || c == '{') {
|
|
|
|
state++;
|
|
|
|
varname_start = input;
|
|
|
|
} else {
|
|
|
|
state = 0;
|
|
|
|
*(output++) = '$';
|
|
|
|
outputcnt--;
|
|
|
|
|
|
|
|
if (outputcnt) {
|
|
|
|
*(output++) = c;
|
|
|
|
outputcnt--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2: /* Waiting for ) */
|
|
|
|
if (c == ')' || c == '}') {
|
|
|
|
int i;
|
|
|
|
char envname[CFG_CBSIZE], *envval;
|
2008-04-21 12:42:06 +00:00
|
|
|
/* Varname # of chars */
|
|
|
|
int envcnt = input - varname_start - 1;
|
2004-12-16 18:43:13 +00:00
|
|
|
|
|
|
|
/* Get the varname */
|
|
|
|
for (i = 0; i < envcnt; i++) {
|
|
|
|
envname[i] = varname_start[i];
|
|
|
|
}
|
|
|
|
envname[i] = 0;
|
|
|
|
|
|
|
|
/* Get its value */
|
|
|
|
envval = getenv (envname);
|
|
|
|
|
|
|
|
/* Copy into the line if it exists */
|
|
|
|
if (envval != NULL)
|
|
|
|
while ((*envval) && outputcnt) {
|
|
|
|
*(output++) = *(envval++);
|
|
|
|
outputcnt--;
|
|
|
|
}
|
|
|
|
/* Look for another '$' */
|
|
|
|
state = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3: /* Waiting for ' */
|
|
|
|
if ((c == '\'') && (prev != '\\')) {
|
|
|
|
state = 0;
|
|
|
|
} else {
|
|
|
|
*(output++) = c;
|
|
|
|
outputcnt--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prev = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outputcnt)
|
|
|
|
*output = 0;
|
|
|
|
|
|
|
|
#ifdef DEBUG_PARSER
|
|
|
|
printf ("[PROCESS_MACROS] OUTPUT len %d: \"%s\"\n",
|
2008-04-21 12:42:06 +00:00
|
|
|
strlen (output_start), output_start);
|
2004-12-16 18:43:13 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* this is called from board_init() after the hardware has been set up
|
|
|
|
* and is usable. That seems like a good time to do this.
|
|
|
|
* Right now the return value is ignored.
|
|
|
|
*/
|
|
|
|
int do_auto_update(void)
|
|
|
|
{
|
2008-04-21 12:42:06 +00:00
|
|
|
block_dev_desc_t *stor_dev = NULL;
|
2004-12-16 18:43:13 +00:00
|
|
|
long sz;
|
|
|
|
int i, res, cnt, old_ctrlc, got_ctrlc;
|
|
|
|
char buffer[32];
|
|
|
|
char str[80];
|
2008-04-21 12:42:06 +00:00
|
|
|
int n;
|
2004-12-16 18:43:13 +00:00
|
|
|
|
2008-04-21 12:42:06 +00:00
|
|
|
if (ide_dev_desc[0].type != DEV_TYPE_UNKNOWN) {
|
|
|
|
stor_dev = get_dev ("ide", 0);
|
|
|
|
if (stor_dev == NULL) {
|
|
|
|
debug ("ide: unknown device\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2004-12-16 18:43:13 +00:00
|
|
|
}
|
|
|
|
|
2008-04-21 12:42:06 +00:00
|
|
|
if (fat_register_device (stor_dev, 1) != 0) {
|
|
|
|
debug ("Unable to register ide disk 0:1\n");
|
2004-12-16 18:43:13 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if magic file is present
|
|
|
|
*/
|
2008-04-21 12:42:06 +00:00
|
|
|
if ((n = do_fat_read (AU_MAGIC_FILE, buffer,
|
|
|
|
sizeof(buffer), LS_NO)) <= 0) {
|
|
|
|
debug ("No auto_update magic file (n=%d)\n", n);
|
2004-12-16 18:43:13 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUTO_UPDATE_SHOW
|
2008-04-21 12:42:06 +00:00
|
|
|
board_auto_update_show (1);
|
2004-12-16 18:43:13 +00:00
|
|
|
#endif
|
|
|
|
puts("\nAutoUpdate Disk detected! Trying to update system...\n");
|
|
|
|
|
|
|
|
/* make sure that we see CTRL-C and save the old state */
|
2008-04-21 12:42:06 +00:00
|
|
|
old_ctrlc = disable_ctrlc (0);
|
2004-12-16 18:43:13 +00:00
|
|
|
|
|
|
|
/* just loop thru all the possible files */
|
|
|
|
for (i = 0; i < N_AU_IMAGES; i++) {
|
|
|
|
/*
|
|
|
|
* Try to expand the environment var in the fname
|
|
|
|
*/
|
2008-04-21 12:42:06 +00:00
|
|
|
process_macros (au_image[i].name, str);
|
|
|
|
strcpy (au_image[i].name, str);
|
2004-12-16 18:43:13 +00:00
|
|
|
|
|
|
|
printf("Reading %s ...", au_image[i].name);
|
|
|
|
/* just read the header */
|
2008-04-21 12:42:06 +00:00
|
|
|
sz = do_fat_read (au_image[i].name, LOAD_ADDR,
|
|
|
|
image_get_header_size (), LS_NO);
|
2004-12-16 18:43:13 +00:00
|
|
|
debug ("read %s sz %ld hdr %d\n",
|
2008-01-08 17:14:09 +00:00
|
|
|
au_image[i].name, sz, image_get_header_size ());
|
|
|
|
if (sz <= 0 || sz < image_get_header_size ()) {
|
2004-12-16 18:43:13 +00:00
|
|
|
puts(" not found\n");
|
|
|
|
continue;
|
|
|
|
}
|
2008-04-21 12:42:06 +00:00
|
|
|
if (au_check_header_valid (i, sz) < 0) {
|
2004-12-16 18:43:13 +00:00
|
|
|
puts(" header not valid\n");
|
|
|
|
continue;
|
|
|
|
}
|
2008-04-21 12:42:06 +00:00
|
|
|
sz = do_fat_read (au_image[i].name, LOAD_ADDR,
|
|
|
|
MAX_LOADSZ, LS_NO);
|
2004-12-16 18:43:13 +00:00
|
|
|
debug ("read %s sz %ld hdr %d\n",
|
2008-01-08 17:14:09 +00:00
|
|
|
au_image[i].name, sz, image_get_header_size ());
|
|
|
|
if (sz <= 0 || sz <= image_get_header_size ()) {
|
2004-12-16 18:43:13 +00:00
|
|
|
puts(" not found\n");
|
|
|
|
continue;
|
|
|
|
}
|
2008-04-21 12:42:06 +00:00
|
|
|
if (au_check_cksum_valid (i, sz) < 0) {
|
2004-12-16 18:43:13 +00:00
|
|
|
puts(" checksum not valid\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
puts(" done\n");
|
|
|
|
|
|
|
|
do {
|
2008-04-21 12:42:06 +00:00
|
|
|
res = au_do_update (i, sz);
|
2004-12-16 18:43:13 +00:00
|
|
|
/* let the user break out of the loop */
|
2008-04-21 12:42:06 +00:00
|
|
|
if (ctrlc() || had_ctrlc ()) {
|
|
|
|
clear_ctrlc ();
|
2004-12-16 18:43:13 +00:00
|
|
|
if (res < 0)
|
|
|
|
got_ctrlc = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cnt++;
|
|
|
|
} while (res < 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* restore the old state */
|
2008-04-21 12:42:06 +00:00
|
|
|
disable_ctrlc (old_ctrlc);
|
2004-12-16 18:43:13 +00:00
|
|
|
|
|
|
|
puts("AutoUpdate finished\n\n");
|
|
|
|
#ifdef CONFIG_AUTO_UPDATE_SHOW
|
2008-04-21 12:42:06 +00:00
|
|
|
board_auto_update_show (0);
|
2004-12-16 18:43:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int auto_update(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
do_auto_update();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
U_BOOT_CMD(
|
|
|
|
autoupd, 1, 1, auto_update,
|
|
|
|
"autoupd - Automatically update images\n",
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
#endif /* CONFIG_AUTO_UPDATE */
|