wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Gary Jennejohn, DENX Software Engineering, gj@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <command.h> |
| 26 | #include <malloc.h> |
| 27 | #include <image.h> |
| 28 | #include <asm/byteorder.h> |
| 29 | #include <usb.h> |
| 30 | |
| 31 | #ifdef CFG_HUSH_PARSER |
| 32 | #include <hush.h> |
| 33 | #endif |
| 34 | |
| 35 | #ifdef CONFIG_AUTO_UPDATE |
| 36 | |
Markus Klotzbuecher | 43c8b31 | 2006-11-27 11:44:58 +0100 | [diff] [blame] | 37 | #ifndef CONFIG_USB_OHCI_NEW |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 38 | #error "must define CONFIG_USB_OHCI" |
| 39 | #endif |
| 40 | |
| 41 | #ifndef CONFIG_USB_STORAGE |
| 42 | #error "must define CONFIG_USB_STORAGE" |
| 43 | #endif |
| 44 | |
| 45 | #ifndef CFG_HUSH_PARSER |
| 46 | #error "must define CFG_HUSH_PARSER" |
| 47 | #endif |
| 48 | |
Jon Loeliger | e11c123 | 2007-07-09 18:45:16 -0500 | [diff] [blame] | 49 | #if !defined(CONFIG_CMD_FAT) |
Jon Loeliger | 761ea74 | 2007-07-10 10:48:22 -0500 | [diff] [blame] | 50 | #error "must define CONFIG_CMD_FAT" |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 51 | #endif |
| 52 | |
| 53 | /* |
| 54 | * Check whether a USB memory stick is plugged in. |
| 55 | * If one is found: |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 56 | * 1) if prepare.img ist found load it into memory. If it is |
| 57 | * valid then run it. |
| 58 | * 2) if preinst.img is found load it into memory. If it is |
| 59 | * valid then run it. Update the EEPROM. |
Wolfgang Denk | 5ac2a5c | 2006-07-19 14:40:43 +0200 | [diff] [blame] | 60 | * 3) if firmw_01.img is found load it into memory. If it is valid, |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 61 | * burn it into FLASH and update the EEPROM. |
Wolfgang Denk | 5ac2a5c | 2006-07-19 14:40:43 +0200 | [diff] [blame] | 62 | * 4) if kernl_01.img is found load it into memory. If it is valid, |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 63 | * burn it into FLASH and update the EEPROM. |
| 64 | * 5) if app.img is found load it into memory. If it is valid, |
| 65 | * burn it into FLASH and update the EEPROM. |
| 66 | * 6) if disk.img is found load it into memory. If it is valid, |
| 67 | * burn it into FLASH and update the EEPROM. |
| 68 | * 7) if postinst.img is found load it into memory. If it is |
| 69 | * valid then run it. Update the EEPROM. |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 70 | */ |
| 71 | |
| 72 | #undef AU_DEBUG |
| 73 | |
| 74 | #undef debug |
| 75 | #ifdef AU_DEBUG |
| 76 | #define debug(fmt,args...) printf (fmt ,##args) |
| 77 | #else |
| 78 | #define debug(fmt,args...) |
| 79 | #endif /* AU_DEBUG */ |
| 80 | |
| 81 | /* possible names of files on the USB stick. */ |
| 82 | #define AU_PREPARE "prepare.img" |
| 83 | #define AU_PREINST "preinst.img" |
Wolfgang Denk | 5ac2a5c | 2006-07-19 14:40:43 +0200 | [diff] [blame] | 84 | #define AU_FIRMWARE "firmw_01.img" |
| 85 | #define AU_KERNEL "kernl_01.img" |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 86 | #define AU_APP "app.img" |
| 87 | #define AU_DISK "disk.img" |
| 88 | #define AU_POSTINST "postinst.img" |
| 89 | |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 90 | struct flash_layout |
| 91 | { |
| 92 | long start; |
| 93 | long end; |
| 94 | }; |
| 95 | |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 96 | /* layout of the FLASH. ST = start address, ND = end address. */ |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 97 | #ifndef CONFIG_FLASH_8MB /* 16 MB Flash, 32 MB RAM */ |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 98 | #define AU_FL_FIRMWARE_ST 0x00000000 |
| 99 | #define AU_FL_FIRMWARE_ND 0x0009FFFF |
| 100 | #define AU_FL_VFD_ST 0x000A0000 |
| 101 | #define AU_FL_VFD_ND 0x000BFFFF |
| 102 | #define AU_FL_KERNEL_ST 0x000C0000 |
| 103 | #define AU_FL_KERNEL_ND 0x001BFFFF |
| 104 | #define AU_FL_APP_ST 0x001C0000 |
| 105 | #define AU_FL_APP_ND 0x005BFFFF |
| 106 | #define AU_FL_DISK_ST 0x005C0000 |
| 107 | #define AU_FL_DISK_ND 0x00FFFFFF |
dzu | 8d7e4d1 | 2003-09-29 21:55:54 +0000 | [diff] [blame] | 108 | #else /* 8 MB Flash, 32 MB RAM */ |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 109 | #define AU_FL_FIRMWARE_ST 0x00000000 |
dzu | 8d7e4d1 | 2003-09-29 21:55:54 +0000 | [diff] [blame] | 110 | #define AU_FL_FIRMWARE_ND 0x0005FFFF |
| 111 | #define AU_FL_KERNEL_ST 0x00060000 |
| 112 | #define AU_FL_KERNEL_ND 0x0013FFFF |
| 113 | #define AU_FL_APP_ST 0x00140000 |
| 114 | #define AU_FL_APP_ND 0x0067FFFF |
| 115 | #define AU_FL_DISK_ST 0x00680000 |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 116 | #define AU_FL_DISK_ND 0x007DFFFF |
| 117 | #define AU_FL_VFD_ST 0x007E0000 |
| 118 | #define AU_FL_VFD_ND 0x007FFFFF |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 119 | #endif /* CONFIG_FLASH_8MB */ |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 120 | |
| 121 | /* a structure with the offsets to values in the EEPROM */ |
| 122 | struct eeprom_layout |
| 123 | { |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 124 | int time; |
| 125 | int size; |
| 126 | int dcrc; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | /* layout of the EEPROM - offset from the start. All entries are 32 bit. */ |
| 130 | #define AU_EEPROM_TIME_PREINST 64 |
| 131 | #define AU_EEPROM_SIZE_PREINST 68 |
| 132 | #define AU_EEPROM_DCRC_PREINST 72 |
| 133 | #define AU_EEPROM_TIME_FIRMWARE 76 |
| 134 | #define AU_EEPROM_SIZE_FIRMWARE 80 |
| 135 | #define AU_EEPROM_DCRC_FIRMWARE 84 |
| 136 | #define AU_EEPROM_TIME_KERNEL 88 |
| 137 | #define AU_EEPROM_SIZE_KERNEL 92 |
| 138 | #define AU_EEPROM_DCRC_KERNEL 96 |
| 139 | #define AU_EEPROM_TIME_APP 100 |
| 140 | #define AU_EEPROM_SIZE_APP 104 |
| 141 | #define AU_EEPROM_DCRC_APP 108 |
| 142 | #define AU_EEPROM_TIME_DISK 112 |
| 143 | #define AU_EEPROM_SIZE_DISK 116 |
| 144 | #define AU_EEPROM_DCRC_DISK 120 |
| 145 | #define AU_EEPROM_TIME_POSTINST 124 |
| 146 | #define AU_EEPROM_SIZE_POSTINST 128 |
| 147 | #define AU_EEPROM_DCRC_POSTINST 132 |
| 148 | |
| 149 | static int au_usb_stor_curr_dev; /* current device */ |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 150 | |
| 151 | /* index of each file in the following arrays */ |
| 152 | #define IDX_PREPARE 0 |
| 153 | #define IDX_PREINST 1 |
| 154 | #define IDX_FIRMWARE 2 |
| 155 | #define IDX_KERNEL 3 |
| 156 | #define IDX_APP 4 |
| 157 | #define IDX_DISK 5 |
| 158 | #define IDX_POSTINST 6 |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 159 | /* max. number of files which could interest us */ |
| 160 | #define AU_MAXFILES 7 |
| 161 | /* pointers to file names */ |
| 162 | char *aufile[AU_MAXFILES]; |
| 163 | /* sizes of flash areas for each file */ |
| 164 | long ausize[AU_MAXFILES]; |
| 165 | /* offsets into the EEEPROM */ |
| 166 | struct eeprom_layout auee_off[AU_MAXFILES] = { \ |
| 167 | {0}, \ |
| 168 | {AU_EEPROM_TIME_PREINST, AU_EEPROM_SIZE_PREINST, AU_EEPROM_DCRC_PREINST,}, \ |
| 169 | {AU_EEPROM_TIME_FIRMWARE, AU_EEPROM_SIZE_FIRMWARE, AU_EEPROM_DCRC_FIRMWARE,}, \ |
| 170 | {AU_EEPROM_TIME_KERNEL, AU_EEPROM_SIZE_KERNEL, AU_EEPROM_DCRC_KERNEL,}, \ |
| 171 | {AU_EEPROM_TIME_APP, AU_EEPROM_SIZE_APP, AU_EEPROM_DCRC_APP,}, \ |
| 172 | {AU_EEPROM_TIME_DISK, AU_EEPROM_SIZE_DISK, AU_EEPROM_DCRC_DISK,}, \ |
| 173 | {AU_EEPROM_TIME_POSTINST, AU_EEPROM_SIZE_POSTINST, AU_EEPROM_DCRC_POSTINST,} \ |
| 174 | }; |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 175 | /* array of flash areas start and end addresses */ |
| 176 | struct flash_layout aufl_layout[AU_MAXFILES - 3] = { \ |
| 177 | {AU_FL_FIRMWARE_ST, AU_FL_FIRMWARE_ND,}, \ |
| 178 | {AU_FL_KERNEL_ST, AU_FL_KERNEL_ND,}, \ |
| 179 | {AU_FL_APP_ST, AU_FL_APP_ND,}, \ |
| 180 | {AU_FL_DISK_ST, AU_FL_DISK_ND,}, \ |
| 181 | }; |
| 182 | /* convert the index into aufile[] to an index into aufl_layout[] */ |
| 183 | #define FIDX_TO_LIDX(idx) ((idx) - 2) |
| 184 | |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 185 | /* where to load files into memory */ |
wdenk | 61970fd | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 186 | #define LOAD_ADDR ((unsigned char *)0x0C100000) |
dzu | 8d7e4d1 | 2003-09-29 21:55:54 +0000 | [diff] [blame] | 187 | /* the app is the largest image */ |
| 188 | #define MAX_LOADSZ ausize[IDX_APP] |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 189 | |
| 190 | /* externals */ |
| 191 | extern int fat_register_device(block_dev_desc_t *, int); |
| 192 | extern int file_fat_detectfs(void); |
| 193 | extern long file_fat_read(const char *, void *, unsigned long); |
| 194 | extern int i2c_read (unsigned char, unsigned int, int , unsigned char* , int); |
| 195 | extern int i2c_write (uchar, uint, int , uchar* , int); |
| 196 | #ifdef CONFIG_VFD |
| 197 | extern int trab_vfd (ulong); |
| 198 | extern int transfer_pic(unsigned char, unsigned char *, int, int); |
| 199 | #endif |
wdenk | 61970fd | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 200 | extern int flash_sect_erase(ulong, ulong); |
| 201 | extern int flash_sect_protect (int, ulong, ulong); |
Marian Balakowicz | 06918cd | 2005-10-28 15:29:43 +0200 | [diff] [blame] | 202 | extern int flash_write (char *, ulong, ulong); |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 203 | /* change char* to void* to shutup the compiler */ |
| 204 | extern int i2c_write_multiple (uchar, uint, int, void *, int); |
| 205 | extern int i2c_read_multiple (uchar, uint, int, void *, int); |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 206 | extern int u_boot_hush_start(void); |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 207 | |
| 208 | int |
wdenk | 768844e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 209 | au_check_cksum_valid(int idx, long nbytes) |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 210 | { |
| 211 | image_header_t *hdr; |
| 212 | unsigned long checksum; |
wdenk | 768844e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 213 | |
| 214 | hdr = (image_header_t *)LOAD_ADDR; |
| 215 | |
| 216 | if (nbytes != (sizeof(*hdr) + ntohl(hdr->ih_size))) |
| 217 | { |
| 218 | printf ("Image %s bad total SIZE\n", aufile[idx]); |
| 219 | return -1; |
| 220 | } |
| 221 | /* check the data CRC */ |
| 222 | checksum = ntohl(hdr->ih_dcrc); |
| 223 | |
Wolfgang Denk | 031621b | 2006-06-26 10:54:52 +0200 | [diff] [blame] | 224 | if (crc32 (0, (uchar *)(LOAD_ADDR + sizeof(*hdr)), ntohl(hdr->ih_size)) |
wdenk | 768844e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 225 | != checksum) |
| 226 | { |
| 227 | printf ("Image %s bad data checksum\n", aufile[idx]); |
| 228 | return -1; |
| 229 | } |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | int |
| 234 | au_check_header_valid(int idx, long nbytes) |
| 235 | { |
| 236 | image_header_t *hdr; |
| 237 | unsigned long checksum; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 238 | unsigned char buf[4]; |
| 239 | |
| 240 | hdr = (image_header_t *)LOAD_ADDR; |
| 241 | /* check the easy ones first */ |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 242 | #undef CHECK_VALID_DEBUG |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 243 | #ifdef CHECK_VALID_DEBUG |
| 244 | printf("magic %#x %#x ", ntohl(hdr->ih_magic), IH_MAGIC); |
| 245 | printf("arch %#x %#x ", hdr->ih_arch, IH_CPU_ARM); |
| 246 | printf("size %#x %#lx ", ntohl(hdr->ih_size), nbytes); |
| 247 | printf("type %#x %#x ", hdr->ih_type, IH_TYPE_KERNEL); |
| 248 | #endif |
wdenk | 768844e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 249 | if (nbytes < sizeof(*hdr)) |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 250 | { |
wdenk | 768844e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 251 | printf ("Image %s bad header SIZE\n", aufile[idx]); |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 252 | return -1; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 253 | } |
wdenk | 768844e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 254 | if (ntohl(hdr->ih_magic) != IH_MAGIC || hdr->ih_arch != IH_CPU_ARM) |
| 255 | { |
| 256 | printf ("Image %s bad MAGIC or ARCH\n", aufile[idx]); |
| 257 | return -1; |
| 258 | } |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 259 | /* check the hdr CRC */ |
| 260 | checksum = ntohl(hdr->ih_hcrc); |
| 261 | hdr->ih_hcrc = 0; |
| 262 | |
Wolfgang Denk | 031621b | 2006-06-26 10:54:52 +0200 | [diff] [blame] | 263 | if (crc32 (0, (uchar *)hdr, sizeof(*hdr)) != checksum) { |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 264 | printf ("Image %s bad header checksum\n", aufile[idx]); |
| 265 | return -1; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 266 | } |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 267 | hdr->ih_hcrc = htonl(checksum); |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 268 | /* check the type - could do this all in one gigantic if() */ |
| 269 | if ((idx == IDX_FIRMWARE) && (hdr->ih_type != IH_TYPE_FIRMWARE)) { |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 270 | printf ("Image %s wrong type\n", aufile[idx]); |
| 271 | return -1; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 272 | } |
| 273 | if ((idx == IDX_KERNEL) && (hdr->ih_type != IH_TYPE_KERNEL)) { |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 274 | printf ("Image %s wrong type\n", aufile[idx]); |
| 275 | return -1; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 276 | } |
wdenk | ec207f9 | 2003-10-07 20:01:55 +0000 | [diff] [blame] | 277 | if ((idx == IDX_DISK) && (hdr->ih_type != IH_TYPE_FILESYSTEM)) { |
| 278 | printf ("Image %s wrong type\n", aufile[idx]); |
| 279 | return -1; |
| 280 | } |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 281 | if ((idx == IDX_APP) && (hdr->ih_type != IH_TYPE_RAMDISK) |
| 282 | && (hdr->ih_type != IH_TYPE_FILESYSTEM)) { |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 283 | printf ("Image %s wrong type\n", aufile[idx]); |
| 284 | return -1; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 285 | } |
| 286 | if ((idx == IDX_PREPARE || idx == IDX_PREINST || idx == IDX_POSTINST) |
| 287 | && (hdr->ih_type != IH_TYPE_SCRIPT)) |
| 288 | { |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 289 | printf ("Image %s wrong type\n", aufile[idx]); |
| 290 | return -1; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 291 | } |
| 292 | /* special case for prepare.img */ |
| 293 | if (idx == IDX_PREPARE) |
| 294 | return 0; |
wdenk | ec207f9 | 2003-10-07 20:01:55 +0000 | [diff] [blame] | 295 | /* recycle checksum */ |
| 296 | checksum = ntohl(hdr->ih_size); |
| 297 | /* for kernel and app the image header must also fit into flash */ |
Wolfgang Denk | 78b7b56 | 2005-09-21 15:31:25 +0200 | [diff] [blame] | 298 | if ((idx != IDX_DISK) && (idx != IDX_FIRMWARE)) |
wdenk | ec207f9 | 2003-10-07 20:01:55 +0000 | [diff] [blame] | 299 | checksum += sizeof(*hdr); |
| 300 | /* check the size does not exceed space in flash. HUSH scripts */ |
| 301 | /* all have ausize[] set to 0 */ |
| 302 | if ((ausize[idx] != 0) && (ausize[idx] < checksum)) { |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 303 | printf ("Image %s is bigger than FLASH\n", aufile[idx]); |
| 304 | return -1; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 305 | } |
| 306 | /* check the time stamp from the EEPROM */ |
| 307 | /* read it in */ |
| 308 | i2c_read_multiple(0x54, auee_off[idx].time, 1, buf, sizeof(buf)); |
| 309 | #ifdef CHECK_VALID_DEBUG |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 310 | printf ("buf[0] %#x buf[1] %#x buf[2] %#x buf[3] %#x " |
| 311 | "as int %#x time %#x\n", |
| 312 | buf[0], buf[1], buf[2], buf[3], |
| 313 | *((unsigned int *)buf), ntohl(hdr->ih_time)); |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 314 | #endif |
| 315 | /* check it */ |
| 316 | if (*((unsigned int *)buf) >= ntohl(hdr->ih_time)) { |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 317 | printf ("Image %s is too old\n", aufile[idx]); |
| 318 | return -1; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | return 0; |
| 322 | } |
| 323 | |
| 324 | /* power control defines */ |
| 325 | #define CPLD_VFD_BK ((volatile char *)0x04038002) |
| 326 | #define POWER_OFF (1 << 1) |
| 327 | |
| 328 | int |
wdenk | 61970fd | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 329 | au_do_update(int idx, long sz) |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 330 | { |
| 331 | image_header_t *hdr; |
| 332 | char *addr; |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 333 | long start, end; |
wdenk | 61970fd | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 334 | int off, rc; |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 335 | uint nbytes; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 336 | |
| 337 | hdr = (image_header_t *)LOAD_ADDR; |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 338 | |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 339 | /* disable the power switch */ |
| 340 | *CPLD_VFD_BK |= POWER_OFF; |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 341 | |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 342 | /* execute a script */ |
| 343 | if (hdr->ih_type == IH_TYPE_SCRIPT) { |
wdenk | 7182b0f | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 344 | addr = (char *)((char *)hdr + sizeof(*hdr)); |
| 345 | /* stick a NULL at the end of the script, otherwise */ |
| 346 | /* parse_string_outer() runs off the end. */ |
| 347 | addr[ntohl(hdr->ih_size)] = 0; |
| 348 | addr += 8; |
| 349 | parse_string_outer(addr, FLAG_PARSE_SEMICOLON); |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 350 | return 0; |
| 351 | } |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 352 | |
| 353 | start = aufl_layout[FIDX_TO_LIDX(idx)].start; |
| 354 | end = aufl_layout[FIDX_TO_LIDX(idx)].end; |
| 355 | |
| 356 | /* unprotect the address range */ |
| 357 | /* this assumes that ONLY the firmware is protected! */ |
| 358 | if (idx == IDX_FIRMWARE) { |
| 359 | #undef AU_UPDATE_TEST |
| 360 | #ifdef AU_UPDATE_TEST |
| 361 | /* erase it where Linux goes */ |
| 362 | start = aufl_layout[1].start; |
| 363 | end = aufl_layout[1].end; |
| 364 | #endif |
wdenk | 61970fd | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 365 | flash_sect_protect(0, start, end); |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 366 | } |
| 367 | |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 368 | /* |
wdenk | 61970fd | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 369 | * erase the address range. |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 370 | */ |
wdenk | 61970fd | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 371 | debug ("flash_sect_erase(%lx, %lx);\n", start, end); |
| 372 | flash_sect_erase(start, end); |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 373 | wait_ms(100); |
wdenk | 17d1a1d | 2003-10-16 12:53:35 +0000 | [diff] [blame] | 374 | /* strip the header - except for the kernel and ramdisk */ |
| 375 | if (hdr->ih_type == IH_TYPE_KERNEL || hdr->ih_type == IH_TYPE_RAMDISK) { |
| 376 | addr = (char *)hdr; |
| 377 | off = sizeof(*hdr); |
| 378 | nbytes = sizeof(*hdr) + ntohl(hdr->ih_size); |
| 379 | } else { |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 380 | addr = (char *)((char *)hdr + sizeof(*hdr)); |
| 381 | #ifdef AU_UPDATE_TEST |
| 382 | /* copy it to where Linux goes */ |
| 383 | if (idx == IDX_FIRMWARE) |
| 384 | start = aufl_layout[1].start; |
| 385 | #endif |
| 386 | off = 0; |
| 387 | nbytes = ntohl(hdr->ih_size); |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | /* copy the data from RAM to FLASH */ |
wdenk | 61970fd | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 391 | debug ("flash_write(%p, %lx %x)\n", addr, start, nbytes); |
| 392 | rc = flash_write(addr, start, nbytes); |
| 393 | if (rc != 0) { |
| 394 | printf("Flashing failed due to error %d\n", rc); |
| 395 | return -1; |
| 396 | } |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 397 | |
| 398 | /* check the dcrc of the copy */ |
Wolfgang Denk | 031621b | 2006-06-26 10:54:52 +0200 | [diff] [blame] | 399 | if (crc32 (0, (uchar *)(start + off), ntohl(hdr->ih_size)) != ntohl(hdr->ih_dcrc)) { |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 400 | printf ("Image %s Bad Data Checksum After COPY\n", aufile[idx]); |
| 401 | return -1; |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | /* protect the address range */ |
| 405 | /* this assumes that ONLY the firmware is protected! */ |
wdenk | 61970fd | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 406 | if (idx == IDX_FIRMWARE) |
| 407 | flash_sect_protect(1, start, end); |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | int |
| 412 | au_update_eeprom(int idx) |
| 413 | { |
| 414 | image_header_t *hdr; |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 415 | int off; |
| 416 | uint32_t val; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 417 | |
wdenk | 99408ba | 2005-02-24 22:44:16 +0000 | [diff] [blame] | 418 | /* special case for prepare.img */ |
| 419 | if (idx == IDX_PREPARE) { |
| 420 | /* enable the power switch */ |
| 421 | *CPLD_VFD_BK &= ~POWER_OFF; |
| 422 | return 0; |
| 423 | } |
| 424 | |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 425 | hdr = (image_header_t *)LOAD_ADDR; |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 426 | /* write the time field into EEPROM */ |
| 427 | off = auee_off[idx].time; |
| 428 | val = ntohl(hdr->ih_time); |
| 429 | i2c_write_multiple(0x54, off, 1, &val, sizeof(val)); |
| 430 | /* write the size field into EEPROM */ |
| 431 | off = auee_off[idx].size; |
| 432 | val = ntohl(hdr->ih_size); |
| 433 | i2c_write_multiple(0x54, off, 1, &val, sizeof(val)); |
| 434 | /* write the dcrc field into EEPROM */ |
| 435 | off = auee_off[idx].dcrc; |
| 436 | val = ntohl(hdr->ih_dcrc); |
| 437 | i2c_write_multiple(0x54, off, 1, &val, sizeof(val)); |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 438 | /* enable the power switch */ |
| 439 | *CPLD_VFD_BK &= ~POWER_OFF; |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | /* |
| 444 | * this is called from board_init() after the hardware has been set up |
| 445 | * and is usable. That seems like a good time to do this. |
| 446 | * Right now the return value is ignored. |
| 447 | */ |
| 448 | int |
| 449 | do_auto_update(void) |
| 450 | { |
| 451 | block_dev_desc_t *stor_dev; |
| 452 | long sz; |
Wolfgang Denk | 036384c | 2007-08-12 15:11:38 +0200 | [diff] [blame] | 453 | int i, res = 0, bitmap_first, cnt, old_ctrlc, got_ctrlc; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 454 | char *env; |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 455 | long start, end; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 456 | |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 457 | #undef ERASE_EEPROM |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 458 | #ifdef ERASE_EEPROM |
| 459 | int arr[18]; |
| 460 | memset(arr, 0, sizeof(arr)); |
| 461 | i2c_write_multiple(0x54, 64, 1, arr, sizeof(arr)); |
| 462 | #endif |
| 463 | au_usb_stor_curr_dev = -1; |
| 464 | /* start USB */ |
| 465 | if (usb_stop() < 0) { |
| 466 | debug ("usb_stop failed\n"); |
| 467 | return -1; |
| 468 | } |
| 469 | if (usb_init() < 0) { |
| 470 | debug ("usb_init failed\n"); |
| 471 | return -1; |
| 472 | } |
| 473 | /* |
| 474 | * check whether a storage device is attached (assume that it's |
| 475 | * a USB memory stick, since nothing else should be attached). |
| 476 | */ |
wdenk | 7f00b94 | 2003-12-07 23:55:12 +0000 | [diff] [blame] | 477 | au_usb_stor_curr_dev = usb_stor_scan(0); |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 478 | if (au_usb_stor_curr_dev == -1) { |
| 479 | debug ("No device found. Not initialized?\n"); |
Wolfgang Denk | 036384c | 2007-08-12 15:11:38 +0200 | [diff] [blame] | 480 | res = -1; |
| 481 | goto xit; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 482 | } |
| 483 | /* check whether it has a partition table */ |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 484 | stor_dev = get_dev("usb", 0); |
| 485 | if (stor_dev == NULL) { |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 486 | debug ("uknown device type\n"); |
Wolfgang Denk | 036384c | 2007-08-12 15:11:38 +0200 | [diff] [blame] | 487 | res = -1; |
| 488 | goto xit; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 489 | } |
| 490 | if (fat_register_device(stor_dev, 1) != 0) { |
| 491 | debug ("Unable to use USB %d:%d for fatls\n", |
| 492 | au_usb_stor_curr_dev, 1); |
Wolfgang Denk | 036384c | 2007-08-12 15:11:38 +0200 | [diff] [blame] | 493 | res = -1; |
| 494 | goto xit; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 495 | } |
| 496 | if (file_fat_detectfs() != 0) { |
| 497 | debug ("file_fat_detectfs failed\n"); |
| 498 | } |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 499 | |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 500 | /* initialize the array of file names */ |
| 501 | memset(aufile, 0, sizeof(aufile)); |
| 502 | aufile[IDX_PREPARE] = AU_PREPARE; |
| 503 | aufile[IDX_PREINST] = AU_PREINST; |
| 504 | aufile[IDX_FIRMWARE] = AU_FIRMWARE; |
| 505 | aufile[IDX_KERNEL] = AU_KERNEL; |
| 506 | aufile[IDX_APP] = AU_APP; |
| 507 | aufile[IDX_DISK] = AU_DISK; |
| 508 | aufile[IDX_POSTINST] = AU_POSTINST; |
| 509 | /* initialize the array of flash sizes */ |
| 510 | memset(ausize, 0, sizeof(ausize)); |
| 511 | ausize[IDX_FIRMWARE] = (AU_FL_FIRMWARE_ND + 1) - AU_FL_FIRMWARE_ST; |
| 512 | ausize[IDX_KERNEL] = (AU_FL_KERNEL_ND + 1) - AU_FL_KERNEL_ST; |
| 513 | ausize[IDX_APP] = (AU_FL_APP_ND + 1) - AU_FL_APP_ST; |
| 514 | ausize[IDX_DISK] = (AU_FL_DISK_ND + 1) - AU_FL_DISK_ST; |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 515 | /* |
| 516 | * now check whether start and end are defined using environment |
| 517 | * variables. |
| 518 | */ |
wdenk | f2eba1f | 2003-09-19 08:29:25 +0000 | [diff] [blame] | 519 | start = -1; |
| 520 | end = 0; |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 521 | env = getenv("firmware_st"); |
| 522 | if (env != NULL) |
| 523 | start = simple_strtoul(env, NULL, 16); |
| 524 | env = getenv("firmware_nd"); |
| 525 | if (env != NULL) |
| 526 | end = simple_strtoul(env, NULL, 16); |
wdenk | 7182b0f | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 527 | if (start >= 0 && end && end > start) { |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 528 | ausize[IDX_FIRMWARE] = (end + 1) - start; |
wdenk | 7182b0f | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 529 | aufl_layout[0].start = start; |
| 530 | aufl_layout[0].end = end; |
| 531 | } |
wdenk | f2eba1f | 2003-09-19 08:29:25 +0000 | [diff] [blame] | 532 | start = -1; |
| 533 | end = 0; |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 534 | env = getenv("kernel_st"); |
| 535 | if (env != NULL) |
| 536 | start = simple_strtoul(env, NULL, 16); |
| 537 | env = getenv("kernel_nd"); |
| 538 | if (env != NULL) |
| 539 | end = simple_strtoul(env, NULL, 16); |
wdenk | 7182b0f | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 540 | if (start >= 0 && end && end > start) { |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 541 | ausize[IDX_KERNEL] = (end + 1) - start; |
wdenk | 7182b0f | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 542 | aufl_layout[1].start = start; |
| 543 | aufl_layout[1].end = end; |
| 544 | } |
wdenk | f2eba1f | 2003-09-19 08:29:25 +0000 | [diff] [blame] | 545 | start = -1; |
| 546 | end = 0; |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 547 | env = getenv("app_st"); |
| 548 | if (env != NULL) |
| 549 | start = simple_strtoul(env, NULL, 16); |
| 550 | env = getenv("app_nd"); |
| 551 | if (env != NULL) |
| 552 | end = simple_strtoul(env, NULL, 16); |
wdenk | 7182b0f | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 553 | if (start >= 0 && end && end > start) { |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 554 | ausize[IDX_APP] = (end + 1) - start; |
wdenk | 7182b0f | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 555 | aufl_layout[2].start = start; |
| 556 | aufl_layout[2].end = end; |
| 557 | } |
wdenk | f2eba1f | 2003-09-19 08:29:25 +0000 | [diff] [blame] | 558 | start = -1; |
| 559 | end = 0; |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 560 | env = getenv("disk_st"); |
| 561 | if (env != NULL) |
| 562 | start = simple_strtoul(env, NULL, 16); |
| 563 | env = getenv("disk_nd"); |
| 564 | if (env != NULL) |
| 565 | end = simple_strtoul(env, NULL, 16); |
wdenk | 7182b0f | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 566 | if (start >= 0 && end && end > start) { |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 567 | ausize[IDX_DISK] = (end + 1) - start; |
wdenk | 7182b0f | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 568 | aufl_layout[3].start = start; |
| 569 | aufl_layout[3].end = end; |
| 570 | } |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 571 | /* make certain that HUSH is runnable */ |
| 572 | u_boot_hush_start(); |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 573 | /* make sure that we see CTRL-C and save the old state */ |
| 574 | old_ctrlc = disable_ctrlc(0); |
| 575 | |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 576 | bitmap_first = 0; |
| 577 | /* just loop thru all the possible files */ |
| 578 | for (i = 0; i < AU_MAXFILES; i++) { |
wdenk | 768844e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 579 | /* just read the header */ |
| 580 | sz = file_fat_read(aufile[i], LOAD_ADDR, sizeof(image_header_t)); |
| 581 | debug ("read %s sz %ld hdr %d\n", |
| 582 | aufile[i], sz, sizeof(image_header_t)); |
| 583 | if (sz <= 0 || sz < sizeof(image_header_t)) { |
| 584 | debug ("%s not found\n", aufile[i]); |
| 585 | continue; |
| 586 | } |
| 587 | if (au_check_header_valid(i, sz) < 0) { |
| 588 | debug ("%s header not valid\n", aufile[i]); |
| 589 | continue; |
| 590 | } |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 591 | sz = file_fat_read(aufile[i], LOAD_ADDR, MAX_LOADSZ); |
| 592 | debug ("read %s sz %ld hdr %d\n", |
| 593 | aufile[i], sz, sizeof(image_header_t)); |
| 594 | if (sz <= 0 || sz <= sizeof(image_header_t)) { |
| 595 | debug ("%s not found\n", aufile[i]); |
| 596 | continue; |
| 597 | } |
wdenk | 768844e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 598 | if (au_check_cksum_valid(i, sz) < 0) { |
| 599 | debug ("%s checksum not valid\n", aufile[i]); |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 600 | continue; |
| 601 | } |
| 602 | #ifdef CONFIG_VFD |
| 603 | /* now that we have a valid file we can display the */ |
| 604 | /* bitmap. */ |
| 605 | if (bitmap_first == 0) { |
| 606 | env = getenv("bitmap2"); |
| 607 | if (env == NULL) { |
| 608 | trab_vfd(0); |
| 609 | } else { |
| 610 | /* not so simple - bitmap2 is supposed to */ |
| 611 | /* contain the address of the bitmap */ |
| 612 | env = (char *)simple_strtoul(env, NULL, 16); |
| 613 | /* NOTE: these are taken from vfd_logo.h. If that file changes then */ |
| 614 | /* these defines MUST also be updated! These may be wrong for bitmap2. */ |
| 615 | #define VFD_LOGO_WIDTH 112 |
| 616 | #define VFD_LOGO_HEIGHT 72 |
| 617 | /* must call transfer_pic directly */ |
Wolfgang Denk | 031621b | 2006-06-26 10:54:52 +0200 | [diff] [blame] | 618 | transfer_pic(3, (unsigned char *)env, |
| 619 | VFD_LOGO_HEIGHT, VFD_LOGO_WIDTH); |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 620 | } |
| 621 | bitmap_first = 1; |
| 622 | } |
| 623 | #endif |
| 624 | /* this is really not a good idea, but it's what the */ |
| 625 | /* customer wants. */ |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 626 | cnt = 0; |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 627 | got_ctrlc = 0; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 628 | do { |
wdenk | 61970fd | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 629 | res = au_do_update(i, sz); |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 630 | /* let the user break out of the loop */ |
| 631 | if (ctrlc() || had_ctrlc()) { |
| 632 | clear_ctrlc(); |
| 633 | if (res < 0) |
| 634 | got_ctrlc = 1; |
| 635 | break; |
| 636 | } |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 637 | cnt++; |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 638 | #ifdef AU_TEST_ONLY |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 639 | } while (res < 0 && cnt < 3); |
| 640 | if (cnt < 3) |
| 641 | #else |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 642 | } while (res < 0); |
wdenk | b6b2f0e | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 643 | #endif |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 644 | /* |
| 645 | * it doesn't make sense to update the EEPROM if the |
| 646 | * update was interrupted by the user due to errors. |
| 647 | */ |
| 648 | if (got_ctrlc == 0) |
| 649 | au_update_eeprom(i); |
dzu | 8d7e4d1 | 2003-09-29 21:55:54 +0000 | [diff] [blame] | 650 | else |
| 651 | /* enable the power switch */ |
| 652 | *CPLD_VFD_BK &= ~POWER_OFF; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 653 | } |
wdenk | 504331b | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 654 | /* restore the old state */ |
| 655 | disable_ctrlc(old_ctrlc); |
Wolfgang Denk | 036384c | 2007-08-12 15:11:38 +0200 | [diff] [blame] | 656 | xit: |
| 657 | usb_stop(); |
| 658 | return res; |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 659 | } |
| 660 | #endif /* CONFIG_AUTO_UPDATE */ |