Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 1 | /* |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 2 | * flash_rom.c: Flash programming utility |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright 2000 Silicon Integrated System Corporation |
Yinghai Lu | ad8ffd2 | 2004-10-20 05:07:16 +0000 | [diff] [blame] | 5 | * Copyright 2004 Tyan Corp |
| 6 | * yhlu yhlu@tyan.com add exclude start and end option |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 7 | * Copyright 2005 coresystems GmbH |
| 8 | * Stefan Reinauer <stepan@core-systems.de> added rom layout |
| 9 | * support, and checking for suitable rom image |
| 10 | * |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 24 | * |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 25 | */ |
| 26 | |
| 27 | #include <errno.h> |
| 28 | #include <fcntl.h> |
| 29 | #include <sys/mman.h> |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 30 | #include <unistd.h> |
| 31 | #include <stdio.h> |
Ronald G. Minnich | ceec420 | 2003-07-25 04:37:41 +0000 | [diff] [blame] | 32 | #include <string.h> |
Ronald G. Minnich | eaab50b | 2003-09-12 22:41:53 +0000 | [diff] [blame] | 33 | #include <stdlib.h> |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 34 | #include <getopt.h> |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 35 | |
| 36 | #include "flash.h" |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 37 | #include "lbtable.h" |
| 38 | #include "layout.h" |
| 39 | #include "debug.h" |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 40 | |
Ronald G. Minnich | ceec420 | 2003-07-25 04:37:41 +0000 | [diff] [blame] | 41 | char *chip_to_probe = NULL; |
Ronald G. Minnich | 7bd1dee | 2003-05-08 19:33:19 +0000 | [diff] [blame] | 42 | |
Stefan Reinauer | e370528 | 2005-12-18 16:41:10 +0000 | [diff] [blame] | 43 | int exclude_start_page, exclude_end_page; |
| 44 | int force=0, verbose=0; |
| 45 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 46 | struct flashchip *probe_flash(struct flashchip *flash) |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 47 | { |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 48 | int fd_mem; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 49 | volatile uint8_t *bios; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 50 | unsigned long size; |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 51 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 52 | if ((fd_mem = open("/dev/mem", O_RDWR)) < 0) { |
| 53 | perror("Can not open /dev/mem"); |
| 54 | exit(1); |
| 55 | } |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 56 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 57 | while (flash->name != NULL) { |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 58 | if (chip_to_probe && strcmp(flash->name, chip_to_probe) != 0) { |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 59 | flash++; |
| 60 | continue; |
| 61 | } |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 62 | printf_debug("Trying %s, %d KB\n", flash->name, flash->total_size); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 63 | size = flash->total_size * 1024; |
| 64 | /* BUG? what happens if getpagesize() > size!? |
| 65 | -> ``Error MMAP /dev/mem: Invalid argument'' NIKI */ |
| 66 | if (getpagesize() > size) { |
| 67 | size = getpagesize(); |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 68 | printf("%s: warning: size: %d -> %ld\n", |
| 69 | __FUNCTION__, flash->total_size * 1024, |
| 70 | (unsigned long) size); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 71 | } |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 72 | bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED, |
| 73 | fd_mem, (off_t) (0xffffffff - size + 1)); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 74 | if (bios == MAP_FAILED) { |
| 75 | perror("Error MMAP /dev/mem"); |
| 76 | exit(1); |
| 77 | } |
| 78 | flash->virt_addr = bios; |
| 79 | flash->fd_mem = fd_mem; |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 80 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 81 | if (flash->probe(flash) == 1) { |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 82 | printf("%s found at physical address: 0x%lx\n", |
| 83 | flash->name, (0xffffffff - size + 1)); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 84 | return flash; |
| 85 | } |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 86 | munmap((void *) bios, size); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 87 | flash++; |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 88 | } |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 89 | return NULL; |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Stefan Reinauer | e370528 | 2005-12-18 16:41:10 +0000 | [diff] [blame] | 92 | int verify_flash(struct flashchip *flash, uint8_t *buf) |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 93 | { |
Ollie Lho | f51a766 | 2004-03-20 17:05:01 +0000 | [diff] [blame] | 94 | int i; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 95 | int total_size = flash->total_size * 1024; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 96 | volatile uint8_t *bios = flash->virt_addr; |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 97 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 98 | printf("Verifying address: "); |
Ollie Lho | f51a766 | 2004-03-20 17:05:01 +0000 | [diff] [blame] | 99 | for (i = 0; i < total_size; i++) { |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 100 | if (verbose) |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 101 | printf("0x%08x", i); |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 102 | if (*(bios + i) != *(buf + i)) { |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 103 | printf("FAILED\n"); |
| 104 | return 0; |
| 105 | } |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 106 | if (verbose) |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 107 | printf("\b\b\b\b\b\b\b\b\b\b"); |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 108 | } |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 109 | if (verbose) |
| 110 | printf("\n"); |
| 111 | else |
| 112 | printf("VERIFIED\n"); |
| 113 | return 1; |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Ronald G. Minnich | c73ad98 | 2003-02-11 21:06:09 +0000 | [diff] [blame] | 116 | |
Ronald G. Minnich | e555957 | 2003-03-28 03:29:43 +0000 | [diff] [blame] | 117 | void usage(const char *name) |
| 118 | { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 119 | printf("usage: %s [-rwvE] [-V] [-c chipname] [-s exclude_start] [-e exclude_end] [file]\n", name); |
| 120 | printf(" -r | --read: read flash and save into file\n" |
| 121 | " -w | --write: write file into flash (default when file is specified)\n" |
| 122 | " -v | --verify: verify flash against file\n" |
| 123 | " -E | --erase: Erase flash device\n" |
| 124 | " -V | --verbose: more verbose output\n\n" |
| 125 | " -c | --chip <chipname>: probe only for specified flash chip\n" |
| 126 | " -s | --estart <addr>: exclude start position\n" |
| 127 | " -e | --eend <addr>: exclude end postion\n" |
| 128 | " -m | --mainboard <vendor:part>: override mainboard settings\n" |
| 129 | " -f | --force: force write without checking image\n" |
| 130 | " -l | --layout <file.layout>: read rom layout from file\n" |
| 131 | " -i | --image <name>: only flash image name from flash layout\n" |
| 132 | "\n" |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 133 | " If no file is specified, then all that happens\n" |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 134 | " is that flash info is dumped\n\n"); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 135 | exit(1); |
Ronald G. Minnich | e555957 | 2003-03-28 03:29:43 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 138 | int main(int argc, char *argv[]) |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 139 | { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 140 | uint8_t *buf; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 141 | unsigned long size; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 142 | FILE *image; |
| 143 | struct flashchip *flash; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 144 | int opt; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 145 | int option_index = 0; |
| 146 | int read_it = 0, |
| 147 | write_it = 0, |
| 148 | erase_it = 0, |
| 149 | verify_it = 0; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 150 | |
| 151 | static struct option long_options[]= { |
| 152 | { "read", 0, 0, 'r' }, |
| 153 | { "write", 0, 0, 'w' }, |
| 154 | { "erase", 0, 0, 'E' }, |
| 155 | { "verify", 0, 0, 'v' }, |
| 156 | { "chip", 1, 0, 'c' }, |
| 157 | { "estart", 1, 0, 's' }, |
| 158 | { "eend", 1, 0, 'e' }, |
| 159 | { "mainboard", 1, 0, 'm' }, |
| 160 | { "verbose", 0, 0, 'V' }, |
| 161 | { "force", 0, 0, 'f' }, |
| 162 | { "layout", 1, 0, 'l' }, |
| 163 | { "image", 1, 0, 'i' }, |
| 164 | { "help", 0, 0, 'h' }, |
| 165 | { 0, 0, 0, 0 } |
| 166 | }; |
| 167 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 168 | char *filename = NULL; |
Ronald G. Minnich | ceec420 | 2003-07-25 04:37:41 +0000 | [diff] [blame] | 169 | |
Yinghai Lu | ad8ffd2 | 2004-10-20 05:07:16 +0000 | [diff] [blame] | 170 | |
| 171 | unsigned int exclude_start_position=0, exclude_end_position=0; // [x,y) |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 172 | char *tempstr=NULL, *tempstr2=NULL; |
Yinghai Lu | ad8ffd2 | 2004-10-20 05:07:16 +0000 | [diff] [blame] | 173 | |
| 174 | if (argc > 1) { |
| 175 | /* Yes, print them. */ |
| 176 | int i; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 177 | printf_debug ("The arguments are:\n"); |
Yinghai Lu | ad8ffd2 | 2004-10-20 05:07:16 +0000 | [diff] [blame] | 178 | for (i = 1; i < argc; ++i) |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 179 | printf_debug ("%s\n", argv[i]); |
Yinghai Lu | ad8ffd2 | 2004-10-20 05:07:16 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 182 | setbuf(stdout, NULL); |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 183 | while ((opt = getopt_long(argc, argv, "rwvVEfc:s:e:m:l:i:h", long_options, |
| 184 | &option_index)) != EOF) { |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 185 | switch (opt) { |
| 186 | case 'r': |
| 187 | read_it = 1; |
| 188 | break; |
| 189 | case 'w': |
| 190 | write_it = 1; |
| 191 | break; |
| 192 | case 'v': |
| 193 | verify_it = 1; |
| 194 | break; |
| 195 | case 'c': |
| 196 | chip_to_probe = strdup(optarg); |
| 197 | break; |
Ollie Lho | 789ad3d | 2004-03-18 20:27:33 +0000 | [diff] [blame] | 198 | case 'V': |
| 199 | verbose = 1; |
| 200 | break; |
Ollie Lho | efa2858 | 2004-12-08 20:10:01 +0000 | [diff] [blame] | 201 | case 'E': |
| 202 | erase_it = 1; |
| 203 | break; |
Yinghai Lu | ad8ffd2 | 2004-10-20 05:07:16 +0000 | [diff] [blame] | 204 | case 's': |
| 205 | tempstr = strdup(optarg); |
| 206 | sscanf(tempstr,"%x",&exclude_start_position); |
| 207 | break; |
| 208 | case 'e': |
Ollie Lho | 98bea8a | 2004-12-07 03:15:51 +0000 | [diff] [blame] | 209 | tempstr = strdup(optarg); |
| 210 | sscanf(tempstr,"%x",&exclude_end_position); |
| 211 | break; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 212 | case 'm': |
| 213 | tempstr = strdup(optarg); |
| 214 | strtok(tempstr, ":"); |
| 215 | tempstr2=strtok(NULL, ":"); |
| 216 | if (tempstr2) { |
| 217 | lb_vendor=tempstr; |
| 218 | lb_part=tempstr2; |
| 219 | } else { |
| 220 | printf("warning: ignored wrong format of" |
| 221 | " mainboard: %s\n", tempstr); |
| 222 | } |
| 223 | break; |
| 224 | case 'f': |
| 225 | force=1; |
| 226 | break; |
| 227 | case 'l': |
| 228 | tempstr=strdup(optarg); |
| 229 | read_romlayout(tempstr); |
| 230 | break; |
| 231 | case 'i': |
| 232 | tempstr=strdup(optarg); |
| 233 | find_romentry(tempstr); |
| 234 | break; |
| 235 | case 'h': |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 236 | default: |
| 237 | usage(argv[0]); |
| 238 | break; |
| 239 | } |
| 240 | } |
Yinghai Lu | ad8ffd2 | 2004-10-20 05:07:16 +0000 | [diff] [blame] | 241 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 242 | if (read_it && write_it) { |
| 243 | printf("-r and -w are mutually exclusive\n"); |
| 244 | usage(argv[0]); |
| 245 | } |
Ronald G. Minnich | e555957 | 2003-03-28 03:29:43 +0000 | [diff] [blame] | 246 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 247 | if (optind < argc) |
| 248 | filename = argv[optind++]; |
Ronald G. Minnich | e555957 | 2003-03-28 03:29:43 +0000 | [diff] [blame] | 249 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 250 | printf("Calibrating delay loop... "); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 251 | myusec_calibrate_delay(); |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 252 | printf("ok\n"); |
| 253 | |
| 254 | /* We look at the lbtable first to see if we need a |
| 255 | * mainboard specific flash enable sequence. |
| 256 | */ |
| 257 | linuxbios_init(); |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 258 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 259 | /* try to enable it. Failure IS an option, since not all motherboards |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 260 | * really need this to be done, etc., etc. |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 261 | */ |
| 262 | (void) enable_flash_write(); |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 263 | |
| 264 | if ((flash = probe_flash(flashchips)) == NULL) { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 265 | printf("No EEPROM/flash device found.\n"); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 266 | exit(1); |
| 267 | } |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 268 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 269 | printf("Flash part is %s\n", flash->name); |
| 270 | |
Ollie Lho | efa2858 | 2004-12-08 20:10:01 +0000 | [diff] [blame] | 271 | if (!filename && !erase_it) { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 272 | // FIXME: Do we really want this feature implicitly? |
| 273 | printf("OK, only ENABLING flash write, but NOT FLASHING.\n"); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 274 | return 0; |
| 275 | } |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 276 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 277 | size = flash->total_size * 1024; |
| 278 | buf = (uint8_t *) calloc(size, sizeof(char)); |
| 279 | |
Ollie Lho | efa2858 | 2004-12-08 20:10:01 +0000 | [diff] [blame] | 280 | if (erase_it) { |
| 281 | printf("Erasing flash chip\n"); |
| 282 | flash->erase(flash); |
| 283 | exit(0); |
| 284 | } else if (read_it) { |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 285 | if ((image = fopen(filename, "w")) == NULL) { |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 286 | perror(filename); |
| 287 | exit(1); |
| 288 | } |
| 289 | printf("Reading Flash..."); |
Ollie Lho | 73eca80 | 2004-03-19 22:10:07 +0000 | [diff] [blame] | 290 | if (flash->read == NULL) |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 291 | memcpy(buf, (const char *) flash->virt_addr, size); |
| 292 | else |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 293 | flash->read(flash, buf); |
Yinghai Lu | ad8ffd2 | 2004-10-20 05:07:16 +0000 | [diff] [blame] | 294 | |
Ollie Lho | 98bea8a | 2004-12-07 03:15:51 +0000 | [diff] [blame] | 295 | if (exclude_end_position - exclude_start_position > 0) |
| 296 | memset(buf+exclude_start_position, 0, |
| 297 | exclude_end_position-exclude_start_position); |
Yinghai Lu | ad8ffd2 | 2004-10-20 05:07:16 +0000 | [diff] [blame] | 298 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 299 | fwrite(buf, sizeof(char), size, image); |
| 300 | fclose(image); |
| 301 | printf("done\n"); |
| 302 | } else { |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 303 | if ((image = fopen(filename, "r")) == NULL) { |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 304 | perror(filename); |
| 305 | exit(1); |
| 306 | } |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 307 | fread(buf, sizeof(char), size, image); |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 308 | show_id(buf, size); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 309 | fclose(image); |
| 310 | } |
| 311 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 312 | /* exclude range stuff. Nice idea, but at the moment it is only |
| 313 | * supported in hardware by the pm49fl004 chips. |
| 314 | * Instead of implementing this for all chips I suggest advancing |
| 315 | * it to the rom layout feature below and drop exclude range |
| 316 | * completely once all flash chips can do rom layouts. stepan |
| 317 | */ |
| 318 | |
| 319 | // //////////////////////////////////////////////////////////// |
Ollie Lho | 98bea8a | 2004-12-07 03:15:51 +0000 | [diff] [blame] | 320 | if (exclude_end_position - exclude_start_position > 0) |
Ollie Lho | d11f361 | 2004-12-07 17:19:04 +0000 | [diff] [blame] | 321 | memcpy(buf+exclude_start_position, |
Ollie Lho | 98bea8a | 2004-12-07 03:15:51 +0000 | [diff] [blame] | 322 | (const char *) flash->virt_addr+exclude_start_position, |
| 323 | exclude_end_position-exclude_start_position); |
| 324 | |
Yinghai Lu | ad8ffd2 | 2004-10-20 05:07:16 +0000 | [diff] [blame] | 325 | exclude_start_page = exclude_start_position/flash->page_size; |
Ollie Lho | 98bea8a | 2004-12-07 03:15:51 +0000 | [diff] [blame] | 326 | if ((exclude_start_position%flash->page_size) != 0) { |
| 327 | exclude_start_page++; |
| 328 | } |
| 329 | exclude_end_page = exclude_end_position/flash->page_size; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 330 | // //////////////////////////////////////////////////////////// |
Yinghai Lu | ad8ffd2 | 2004-10-20 05:07:16 +0000 | [diff] [blame] | 331 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 332 | // This should be moved into each flash part's code to do it |
| 333 | // cleanly. This does the job. |
| 334 | handle_romentries(buf, (uint8_t *)flash->virt_addr); |
| 335 | |
| 336 | // //////////////////////////////////////////////////////////// |
| 337 | |
| 338 | if (write_it) |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 339 | flash->write(flash, buf); |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 340 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 341 | if (verify_it) |
Stefan Reinauer | e370528 | 2005-12-18 16:41:10 +0000 | [diff] [blame] | 342 | verify_flash(flash, buf); |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 343 | |
Ronald G. Minnich | c73ad98 | 2003-02-11 21:06:09 +0000 | [diff] [blame] | 344 | return 0; |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 345 | } |