wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
Detlev Zundel | 792a09e | 2009-05-13 10:54:10 +0200 | [diff] [blame] | 3 | * Gary Jennejohn, DENX Software Engineering, garyj@denx.de. |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 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 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 31 | #ifdef CONFIG_SYS_HUSH_PARSER |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 32 | #include <hush.h> |
| 33 | #endif |
| 34 | |
| 35 | #ifdef CONFIG_AUTO_UPDATE |
| 36 | |
Markus Klotzbuecher | 7b59b3c | 2006-11-27 11:44:58 +0100 | [diff] [blame] | 37 | #ifndef CONFIG_USB_OHCI_NEW |
wdenk | f54ebdf | 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 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 45 | #ifndef CONFIG_SYS_HUSH_PARSER |
| 46 | #error "must define CONFIG_SYS_HUSH_PARSER" |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 47 | #endif |
| 48 | |
Jon Loeliger | ab3abcb | 2007-07-09 18:45:16 -0500 | [diff] [blame] | 49 | #if !defined(CONFIG_CMD_FAT) |
Jon Loeliger | d39b574 | 2007-07-10 10:48:22 -0500 | [diff] [blame] | 50 | #error "must define CONFIG_CMD_FAT" |
wdenk | f54ebdf | 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 | b0639ca | 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 | c786f42 | 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 | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 61 | * burn it into FLASH and update the EEPROM. |
Wolfgang Denk | c786f42 | 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 | b0639ca | 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 | f54ebdf | 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 | c786f42 | 2006-07-19 14:40:43 +0200 | [diff] [blame] | 84 | #define AU_FIRMWARE "firmw_01.img" |
| 85 | #define AU_KERNEL "kernl_01.img" |
wdenk | f54ebdf | 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 | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 90 | struct flash_layout |
| 91 | { |
| 92 | long start; |
| 93 | long end; |
| 94 | }; |
| 95 | |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 96 | /* layout of the FLASH. ST = start address, ND = end address. */ |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 97 | #ifndef CONFIG_FLASH_8MB /* 16 MB Flash, 32 MB RAM */ |
wdenk | f54ebdf | 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 | 8a42eac | 2003-09-29 21:55:54 +0000 | [diff] [blame] | 108 | #else /* 8 MB Flash, 32 MB RAM */ |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 109 | #define AU_FL_FIRMWARE_ST 0x00000000 |
dzu | 8a42eac | 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 | f54ebdf | 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 | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 119 | #endif /* CONFIG_FLASH_8MB */ |
wdenk | f54ebdf | 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 | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 124 | int time; |
| 125 | int size; |
| 126 | int dcrc; |
wdenk | f54ebdf | 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 | b0639ca | 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 | f54ebdf | 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 | b0639ca | 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 | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 185 | /* where to load files into memory */ |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 186 | #define LOAD_ADDR ((unsigned char *)0x0C100000) |
dzu | 8a42eac | 2003-09-29 21:55:54 +0000 | [diff] [blame] | 187 | /* the app is the largest image */ |
| 188 | #define MAX_LOADSZ ausize[IDX_APP] |
wdenk | f54ebdf | 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 | a0ff7f2 | 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 | 170d5e6 | 2005-10-28 15:29:43 +0200 | [diff] [blame] | 202 | extern int flash_write (char *, ulong, ulong); |
wdenk | b0639ca | 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 | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 206 | extern int u_boot_hush_start(void); |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 207 | |
| 208 | int |
wdenk | fa1399e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 209 | au_check_cksum_valid(int idx, long nbytes) |
| 210 | { |
| 211 | image_header_t *hdr; |
wdenk | fa1399e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 212 | |
| 213 | hdr = (image_header_t *)LOAD_ADDR; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 214 | #if defined(CONFIG_FIT) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 215 | if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 216 | puts ("Non legacy image format not supported\n"); |
| 217 | return -1; |
| 218 | } |
| 219 | #endif |
wdenk | fa1399e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 220 | |
Bartlomiej Sieka | 5e339fd | 2008-03-19 10:00:06 +0100 | [diff] [blame] | 221 | if (nbytes != image_get_image_size (hdr)) { |
wdenk | fa1399e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 222 | printf ("Image %s bad total SIZE\n", aufile[idx]); |
| 223 | return -1; |
| 224 | } |
| 225 | /* check the data CRC */ |
Bartlomiej Sieka | 5e339fd | 2008-03-19 10:00:06 +0100 | [diff] [blame] | 226 | if (!image_check_dcrc (hdr)) { |
wdenk | fa1399e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 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) |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 235 | { |
| 236 | image_header_t *hdr; |
| 237 | unsigned long checksum; |
| 238 | unsigned char buf[4]; |
| 239 | |
| 240 | hdr = (image_header_t *)LOAD_ADDR; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 241 | #if defined(CONFIG_FIT) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 242 | if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 243 | puts ("Non legacy image format not supported\n"); |
| 244 | return -1; |
| 245 | } |
| 246 | #endif |
| 247 | |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 248 | /* check the easy ones first */ |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 249 | #undef CHECK_VALID_DEBUG |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 250 | #ifdef CHECK_VALID_DEBUG |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 251 | printf("magic %#x %#x ", image_get_magic (hdr), IH_MAGIC); |
| 252 | printf("arch %#x %#x ", image_get_arch (hdr), IH_ARCH_ARM); |
| 253 | printf("size %#x %#lx ", image_get_data_size (hdr), nbytes); |
| 254 | printf("type %#x %#x ", image_get_type (hdr), IH_TYPE_KERNEL); |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 255 | #endif |
Bartlomiej Sieka | 5e339fd | 2008-03-19 10:00:06 +0100 | [diff] [blame] | 256 | if (nbytes < image_get_header_size ()) { |
wdenk | fa1399e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 257 | printf ("Image %s bad header SIZE\n", aufile[idx]); |
| 258 | return -1; |
| 259 | } |
Bartlomiej Sieka | 5e339fd | 2008-03-19 10:00:06 +0100 | [diff] [blame] | 260 | if (!image_check_magic (hdr) || !image_check_arch (hdr, IH_ARCH_ARM)) { |
wdenk | fa1399e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 261 | printf ("Image %s bad MAGIC or ARCH\n", aufile[idx]); |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 262 | return -1; |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 263 | } |
| 264 | /* check the hdr CRC */ |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 265 | if (!image_check_hcrc (hdr)) { |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 266 | printf ("Image %s bad header checksum\n", aufile[idx]); |
| 267 | return -1; |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 268 | } |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 269 | /* check the type - could do this all in one gigantic if() */ |
Bartlomiej Sieka | 5e339fd | 2008-03-19 10:00:06 +0100 | [diff] [blame] | 270 | if ((idx == IDX_FIRMWARE) && |
| 271 | !image_check_type (hdr, IH_TYPE_FIRMWARE)) { |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 272 | printf ("Image %s wrong type\n", aufile[idx]); |
| 273 | return -1; |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 274 | } |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 275 | if ((idx == IDX_KERNEL) && !image_check_type (hdr, IH_TYPE_KERNEL)) { |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 276 | printf ("Image %s wrong type\n", aufile[idx]); |
| 277 | return -1; |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 278 | } |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 279 | if ((idx == IDX_DISK) && !image_check_type (hdr, IH_TYPE_FILESYSTEM)) { |
wdenk | d9a405a | 2003-10-07 20:01:55 +0000 | [diff] [blame] | 280 | printf ("Image %s wrong type\n", aufile[idx]); |
| 281 | return -1; |
| 282 | } |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 283 | if ((idx == IDX_APP) && !image_check_type (hdr, IH_TYPE_RAMDISK) |
Marian Balakowicz | 1d1cb42 | 2008-03-12 10:35:51 +0100 | [diff] [blame] | 284 | && !image_check_type (hdr, IH_TYPE_FILESYSTEM)) { |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 285 | printf ("Image %s wrong type\n", aufile[idx]); |
| 286 | return -1; |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 287 | } |
| 288 | if ((idx == IDX_PREPARE || idx == IDX_PREINST || idx == IDX_POSTINST) |
Bartlomiej Sieka | 5e339fd | 2008-03-19 10:00:06 +0100 | [diff] [blame] | 289 | && !image_check_type (hdr, IH_TYPE_SCRIPT)) { |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 290 | printf ("Image %s wrong type\n", aufile[idx]); |
| 291 | return -1; |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 292 | } |
| 293 | /* special case for prepare.img */ |
| 294 | if (idx == IDX_PREPARE) |
| 295 | return 0; |
wdenk | d9a405a | 2003-10-07 20:01:55 +0000 | [diff] [blame] | 296 | /* recycle checksum */ |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 297 | checksum = image_get_data_size (hdr); |
wdenk | d9a405a | 2003-10-07 20:01:55 +0000 | [diff] [blame] | 298 | /* for kernel and app the image header must also fit into flash */ |
Wolfgang Denk | 8b4c9e7 | 2005-09-21 15:31:25 +0200 | [diff] [blame] | 299 | if ((idx != IDX_DISK) && (idx != IDX_FIRMWARE)) |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 300 | checksum += image_get_header_size (); |
wdenk | d9a405a | 2003-10-07 20:01:55 +0000 | [diff] [blame] | 301 | /* check the size does not exceed space in flash. HUSH scripts */ |
| 302 | /* all have ausize[] set to 0 */ |
| 303 | if ((ausize[idx] != 0) && (ausize[idx] < checksum)) { |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 304 | printf ("Image %s is bigger than FLASH\n", aufile[idx]); |
| 305 | return -1; |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 306 | } |
| 307 | /* check the time stamp from the EEPROM */ |
| 308 | /* read it in */ |
| 309 | i2c_read_multiple(0x54, auee_off[idx].time, 1, buf, sizeof(buf)); |
| 310 | #ifdef CHECK_VALID_DEBUG |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 311 | printf ("buf[0] %#x buf[1] %#x buf[2] %#x buf[3] %#x " |
| 312 | "as int %#x time %#x\n", |
| 313 | buf[0], buf[1], buf[2], buf[3], |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 314 | *((unsigned int *)buf), image_get_time (hdr)); |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 315 | #endif |
| 316 | /* check it */ |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 317 | if (*((unsigned int *)buf) >= image_get_time (hdr)) { |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 318 | printf ("Image %s is too old\n", aufile[idx]); |
| 319 | return -1; |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | /* power control defines */ |
| 326 | #define CPLD_VFD_BK ((volatile char *)0x04038002) |
| 327 | #define POWER_OFF (1 << 1) |
| 328 | |
| 329 | int |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 330 | au_do_update(int idx, long sz) |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 331 | { |
| 332 | image_header_t *hdr; |
| 333 | char *addr; |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 334 | long start, end; |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 335 | int off, rc; |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 336 | uint nbytes; |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 337 | |
| 338 | hdr = (image_header_t *)LOAD_ADDR; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 339 | #if defined(CONFIG_FIT) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 340 | if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 341 | puts ("Non legacy image format not supported\n"); |
| 342 | return -1; |
| 343 | } |
| 344 | #endif |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 345 | |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 346 | /* disable the power switch */ |
| 347 | *CPLD_VFD_BK |= POWER_OFF; |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 348 | |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 349 | /* execute a script */ |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 350 | if (image_check_type (hdr, IH_TYPE_SCRIPT)) { |
| 351 | addr = (char *)((char *)hdr + image_get_header_size ()); |
wdenk | fbe4b5c | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 352 | /* stick a NULL at the end of the script, otherwise */ |
| 353 | /* parse_string_outer() runs off the end. */ |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 354 | addr[image_get_data_size (hdr)] = 0; |
wdenk | fbe4b5c | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 355 | addr += 8; |
| 356 | parse_string_outer(addr, FLAG_PARSE_SEMICOLON); |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 357 | return 0; |
| 358 | } |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 359 | |
| 360 | start = aufl_layout[FIDX_TO_LIDX(idx)].start; |
| 361 | end = aufl_layout[FIDX_TO_LIDX(idx)].end; |
| 362 | |
| 363 | /* unprotect the address range */ |
| 364 | /* this assumes that ONLY the firmware is protected! */ |
| 365 | if (idx == IDX_FIRMWARE) { |
| 366 | #undef AU_UPDATE_TEST |
| 367 | #ifdef AU_UPDATE_TEST |
| 368 | /* erase it where Linux goes */ |
| 369 | start = aufl_layout[1].start; |
| 370 | end = aufl_layout[1].end; |
| 371 | #endif |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 372 | flash_sect_protect(0, start, end); |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 373 | } |
| 374 | |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 375 | /* |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 376 | * erase the address range. |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 377 | */ |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 378 | debug ("flash_sect_erase(%lx, %lx);\n", start, end); |
| 379 | flash_sect_erase(start, end); |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 380 | wait_ms(100); |
wdenk | 3d1e8a9 | 2003-10-16 12:53:35 +0000 | [diff] [blame] | 381 | /* strip the header - except for the kernel and ramdisk */ |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 382 | if (image_check_type (hdr, IH_TYPE_KERNEL) || |
| 383 | image_check_type (hdr, IH_TYPE_RAMDISK)) { |
wdenk | 3d1e8a9 | 2003-10-16 12:53:35 +0000 | [diff] [blame] | 384 | addr = (char *)hdr; |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 385 | off = image_get_header_size (); |
| 386 | nbytes = image_get_image_size (hdr); |
wdenk | 3d1e8a9 | 2003-10-16 12:53:35 +0000 | [diff] [blame] | 387 | } else { |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 388 | addr = (char *)((char *)hdr + image_get_header_size ()); |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 389 | #ifdef AU_UPDATE_TEST |
| 390 | /* copy it to where Linux goes */ |
| 391 | if (idx == IDX_FIRMWARE) |
| 392 | start = aufl_layout[1].start; |
| 393 | #endif |
| 394 | off = 0; |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 395 | nbytes = image_get_data_size (hdr); |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | /* copy the data from RAM to FLASH */ |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 399 | debug ("flash_write(%p, %lx %x)\n", addr, start, nbytes); |
| 400 | rc = flash_write(addr, start, nbytes); |
| 401 | if (rc != 0) { |
| 402 | printf("Flashing failed due to error %d\n", rc); |
| 403 | return -1; |
| 404 | } |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 405 | |
| 406 | /* check the dcrc of the copy */ |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 407 | if (crc32 (0, (uchar *)(start + off), image_get_data_size (hdr)) != |
| 408 | image_get_dcrc (hdr)) { |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 409 | printf ("Image %s Bad Data Checksum After COPY\n", aufile[idx]); |
| 410 | return -1; |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /* protect the address range */ |
| 414 | /* this assumes that ONLY the firmware is protected! */ |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 415 | if (idx == IDX_FIRMWARE) |
| 416 | flash_sect_protect(1, start, end); |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | int |
| 421 | au_update_eeprom(int idx) |
| 422 | { |
| 423 | image_header_t *hdr; |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 424 | int off; |
| 425 | uint32_t val; |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 426 | |
wdenk | 151ab83 | 2005-02-24 22:44:16 +0000 | [diff] [blame] | 427 | /* special case for prepare.img */ |
| 428 | if (idx == IDX_PREPARE) { |
| 429 | /* enable the power switch */ |
| 430 | *CPLD_VFD_BK &= ~POWER_OFF; |
| 431 | return 0; |
| 432 | } |
| 433 | |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 434 | hdr = (image_header_t *)LOAD_ADDR; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 435 | #if defined(CONFIG_FIT) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 436 | if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 437 | puts ("Non legacy image format not supported\n"); |
| 438 | return -1; |
| 439 | } |
| 440 | #endif |
| 441 | |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 442 | /* write the time field into EEPROM */ |
| 443 | off = auee_off[idx].time; |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 444 | val = image_get_time (hdr); |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 445 | i2c_write_multiple(0x54, off, 1, &val, sizeof(val)); |
| 446 | /* write the size field into EEPROM */ |
| 447 | off = auee_off[idx].size; |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 448 | val = image_get_data_size (hdr); |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 449 | i2c_write_multiple(0x54, off, 1, &val, sizeof(val)); |
| 450 | /* write the dcrc field into EEPROM */ |
| 451 | off = auee_off[idx].dcrc; |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 452 | val = image_get_dcrc (hdr); |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 453 | i2c_write_multiple(0x54, off, 1, &val, sizeof(val)); |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 454 | /* enable the power switch */ |
| 455 | *CPLD_VFD_BK &= ~POWER_OFF; |
| 456 | return 0; |
| 457 | } |
| 458 | |
| 459 | /* |
| 460 | * this is called from board_init() after the hardware has been set up |
| 461 | * and is usable. That seems like a good time to do this. |
| 462 | * Right now the return value is ignored. |
| 463 | */ |
| 464 | int |
| 465 | do_auto_update(void) |
| 466 | { |
| 467 | block_dev_desc_t *stor_dev; |
| 468 | long sz; |
Wolfgang Denk | a4d2636 | 2007-08-12 15:11:38 +0200 | [diff] [blame] | 469 | int i, res = 0, bitmap_first, cnt, old_ctrlc, got_ctrlc; |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 470 | char *env; |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 471 | long start, end; |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 472 | |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 473 | #undef ERASE_EEPROM |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 474 | #ifdef ERASE_EEPROM |
| 475 | int arr[18]; |
| 476 | memset(arr, 0, sizeof(arr)); |
| 477 | i2c_write_multiple(0x54, 64, 1, arr, sizeof(arr)); |
| 478 | #endif |
| 479 | au_usb_stor_curr_dev = -1; |
| 480 | /* start USB */ |
| 481 | if (usb_stop() < 0) { |
| 482 | debug ("usb_stop failed\n"); |
| 483 | return -1; |
| 484 | } |
| 485 | if (usb_init() < 0) { |
| 486 | debug ("usb_init failed\n"); |
| 487 | return -1; |
| 488 | } |
| 489 | /* |
| 490 | * check whether a storage device is attached (assume that it's |
| 491 | * a USB memory stick, since nothing else should be attached). |
| 492 | */ |
wdenk | 9fd5e31 | 2003-12-07 23:55:12 +0000 | [diff] [blame] | 493 | au_usb_stor_curr_dev = usb_stor_scan(0); |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 494 | if (au_usb_stor_curr_dev == -1) { |
| 495 | debug ("No device found. Not initialized?\n"); |
Wolfgang Denk | a4d2636 | 2007-08-12 15:11:38 +0200 | [diff] [blame] | 496 | res = -1; |
| 497 | goto xit; |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 498 | } |
| 499 | /* check whether it has a partition table */ |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 500 | stor_dev = get_dev("usb", 0); |
| 501 | if (stor_dev == NULL) { |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 502 | debug ("uknown device type\n"); |
Wolfgang Denk | a4d2636 | 2007-08-12 15:11:38 +0200 | [diff] [blame] | 503 | res = -1; |
| 504 | goto xit; |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 505 | } |
| 506 | if (fat_register_device(stor_dev, 1) != 0) { |
| 507 | debug ("Unable to use USB %d:%d for fatls\n", |
| 508 | au_usb_stor_curr_dev, 1); |
Wolfgang Denk | a4d2636 | 2007-08-12 15:11:38 +0200 | [diff] [blame] | 509 | res = -1; |
| 510 | goto xit; |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 511 | } |
| 512 | if (file_fat_detectfs() != 0) { |
| 513 | debug ("file_fat_detectfs failed\n"); |
| 514 | } |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 515 | |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 516 | /* initialize the array of file names */ |
| 517 | memset(aufile, 0, sizeof(aufile)); |
| 518 | aufile[IDX_PREPARE] = AU_PREPARE; |
| 519 | aufile[IDX_PREINST] = AU_PREINST; |
| 520 | aufile[IDX_FIRMWARE] = AU_FIRMWARE; |
| 521 | aufile[IDX_KERNEL] = AU_KERNEL; |
| 522 | aufile[IDX_APP] = AU_APP; |
| 523 | aufile[IDX_DISK] = AU_DISK; |
| 524 | aufile[IDX_POSTINST] = AU_POSTINST; |
| 525 | /* initialize the array of flash sizes */ |
| 526 | memset(ausize, 0, sizeof(ausize)); |
| 527 | ausize[IDX_FIRMWARE] = (AU_FL_FIRMWARE_ND + 1) - AU_FL_FIRMWARE_ST; |
| 528 | ausize[IDX_KERNEL] = (AU_FL_KERNEL_ND + 1) - AU_FL_KERNEL_ST; |
| 529 | ausize[IDX_APP] = (AU_FL_APP_ND + 1) - AU_FL_APP_ST; |
| 530 | ausize[IDX_DISK] = (AU_FL_DISK_ND + 1) - AU_FL_DISK_ST; |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 531 | /* |
| 532 | * now check whether start and end are defined using environment |
| 533 | * variables. |
| 534 | */ |
wdenk | 1d70468 | 2003-09-19 08:29:25 +0000 | [diff] [blame] | 535 | start = -1; |
| 536 | end = 0; |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 537 | env = getenv("firmware_st"); |
| 538 | if (env != NULL) |
| 539 | start = simple_strtoul(env, NULL, 16); |
| 540 | env = getenv("firmware_nd"); |
| 541 | if (env != NULL) |
| 542 | end = simple_strtoul(env, NULL, 16); |
wdenk | fbe4b5c | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 543 | if (start >= 0 && end && end > start) { |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 544 | ausize[IDX_FIRMWARE] = (end + 1) - start; |
wdenk | fbe4b5c | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 545 | aufl_layout[0].start = start; |
| 546 | aufl_layout[0].end = end; |
| 547 | } |
wdenk | 1d70468 | 2003-09-19 08:29:25 +0000 | [diff] [blame] | 548 | start = -1; |
| 549 | end = 0; |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 550 | env = getenv("kernel_st"); |
| 551 | if (env != NULL) |
| 552 | start = simple_strtoul(env, NULL, 16); |
| 553 | env = getenv("kernel_nd"); |
| 554 | if (env != NULL) |
| 555 | end = simple_strtoul(env, NULL, 16); |
wdenk | fbe4b5c | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 556 | if (start >= 0 && end && end > start) { |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 557 | ausize[IDX_KERNEL] = (end + 1) - start; |
wdenk | fbe4b5c | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 558 | aufl_layout[1].start = start; |
| 559 | aufl_layout[1].end = end; |
| 560 | } |
wdenk | 1d70468 | 2003-09-19 08:29:25 +0000 | [diff] [blame] | 561 | start = -1; |
| 562 | end = 0; |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 563 | env = getenv("app_st"); |
| 564 | if (env != NULL) |
| 565 | start = simple_strtoul(env, NULL, 16); |
| 566 | env = getenv("app_nd"); |
| 567 | if (env != NULL) |
| 568 | end = simple_strtoul(env, NULL, 16); |
wdenk | fbe4b5c | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 569 | if (start >= 0 && end && end > start) { |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 570 | ausize[IDX_APP] = (end + 1) - start; |
wdenk | fbe4b5c | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 571 | aufl_layout[2].start = start; |
| 572 | aufl_layout[2].end = end; |
| 573 | } |
wdenk | 1d70468 | 2003-09-19 08:29:25 +0000 | [diff] [blame] | 574 | start = -1; |
| 575 | end = 0; |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 576 | env = getenv("disk_st"); |
| 577 | if (env != NULL) |
| 578 | start = simple_strtoul(env, NULL, 16); |
| 579 | env = getenv("disk_nd"); |
| 580 | if (env != NULL) |
| 581 | end = simple_strtoul(env, NULL, 16); |
wdenk | fbe4b5c | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 582 | if (start >= 0 && end && end > start) { |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 583 | ausize[IDX_DISK] = (end + 1) - start; |
wdenk | fbe4b5c | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 584 | aufl_layout[3].start = start; |
| 585 | aufl_layout[3].end = end; |
| 586 | } |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 587 | /* make certain that HUSH is runnable */ |
| 588 | u_boot_hush_start(); |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 589 | /* make sure that we see CTRL-C and save the old state */ |
| 590 | old_ctrlc = disable_ctrlc(0); |
| 591 | |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 592 | bitmap_first = 0; |
| 593 | /* just loop thru all the possible files */ |
| 594 | for (i = 0; i < AU_MAXFILES; i++) { |
wdenk | fa1399e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 595 | /* just read the header */ |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 596 | sz = file_fat_read(aufile[i], LOAD_ADDR, image_get_header_size ()); |
wdenk | fa1399e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 597 | debug ("read %s sz %ld hdr %d\n", |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 598 | aufile[i], sz, image_get_header_size ()); |
| 599 | if (sz <= 0 || sz < image_get_header_size ()) { |
wdenk | fa1399e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 600 | debug ("%s not found\n", aufile[i]); |
| 601 | continue; |
| 602 | } |
| 603 | if (au_check_header_valid(i, sz) < 0) { |
| 604 | debug ("%s header not valid\n", aufile[i]); |
| 605 | continue; |
| 606 | } |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 607 | sz = file_fat_read(aufile[i], LOAD_ADDR, MAX_LOADSZ); |
| 608 | debug ("read %s sz %ld hdr %d\n", |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 609 | aufile[i], sz, image_get_header_size ()); |
| 610 | if (sz <= 0 || sz <= image_get_header_size ()) { |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 611 | debug ("%s not found\n", aufile[i]); |
| 612 | continue; |
| 613 | } |
wdenk | fa1399e | 2003-12-06 11:20:01 +0000 | [diff] [blame] | 614 | if (au_check_cksum_valid(i, sz) < 0) { |
| 615 | debug ("%s checksum not valid\n", aufile[i]); |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 616 | continue; |
| 617 | } |
| 618 | #ifdef CONFIG_VFD |
| 619 | /* now that we have a valid file we can display the */ |
| 620 | /* bitmap. */ |
| 621 | if (bitmap_first == 0) { |
| 622 | env = getenv("bitmap2"); |
| 623 | if (env == NULL) { |
| 624 | trab_vfd(0); |
| 625 | } else { |
| 626 | /* not so simple - bitmap2 is supposed to */ |
| 627 | /* contain the address of the bitmap */ |
| 628 | env = (char *)simple_strtoul(env, NULL, 16); |
| 629 | /* NOTE: these are taken from vfd_logo.h. If that file changes then */ |
| 630 | /* these defines MUST also be updated! These may be wrong for bitmap2. */ |
| 631 | #define VFD_LOGO_WIDTH 112 |
| 632 | #define VFD_LOGO_HEIGHT 72 |
| 633 | /* must call transfer_pic directly */ |
Wolfgang Denk | a63c31c | 2006-06-26 10:54:52 +0200 | [diff] [blame] | 634 | transfer_pic(3, (unsigned char *)env, |
| 635 | VFD_LOGO_HEIGHT, VFD_LOGO_WIDTH); |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 636 | } |
| 637 | bitmap_first = 1; |
| 638 | } |
| 639 | #endif |
| 640 | /* this is really not a good idea, but it's what the */ |
| 641 | /* customer wants. */ |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 642 | cnt = 0; |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 643 | got_ctrlc = 0; |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 644 | do { |
wdenk | a0ff7f2 | 2003-10-09 13:16:55 +0000 | [diff] [blame] | 645 | res = au_do_update(i, sz); |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 646 | /* let the user break out of the loop */ |
| 647 | if (ctrlc() || had_ctrlc()) { |
| 648 | clear_ctrlc(); |
| 649 | if (res < 0) |
| 650 | got_ctrlc = 1; |
| 651 | break; |
| 652 | } |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 653 | cnt++; |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 654 | #ifdef AU_TEST_ONLY |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 655 | } while (res < 0 && cnt < 3); |
| 656 | if (cnt < 3) |
| 657 | #else |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 658 | } while (res < 0); |
wdenk | b0639ca | 2003-09-17 22:48:07 +0000 | [diff] [blame] | 659 | #endif |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 660 | /* |
| 661 | * it doesn't make sense to update the EEPROM if the |
| 662 | * update was interrupted by the user due to errors. |
| 663 | */ |
| 664 | if (got_ctrlc == 0) |
| 665 | au_update_eeprom(i); |
dzu | 8a42eac | 2003-09-29 21:55:54 +0000 | [diff] [blame] | 666 | else |
| 667 | /* enable the power switch */ |
| 668 | *CPLD_VFD_BK &= ~POWER_OFF; |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 669 | } |
wdenk | 8036986 | 2003-09-18 18:55:25 +0000 | [diff] [blame] | 670 | /* restore the old state */ |
| 671 | disable_ctrlc(old_ctrlc); |
Wolfgang Denk | a4d2636 | 2007-08-12 15:11:38 +0200 | [diff] [blame] | 672 | xit: |
| 673 | usb_stop(); |
| 674 | return res; |
wdenk | f54ebdf | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 675 | } |
| 676 | #endif /* CONFIG_AUTO_UPDATE */ |