wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 1 | #include <common.h> |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 2 | #include <exports.h> |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 3 | |
| 4 | extern unsigned long __dummy; |
| 5 | void do_reset (void); |
| 6 | void do_updater(void); |
| 7 | |
| 8 | void _main(void) |
| 9 | { |
| 10 | int i; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 11 | printf("U-Boot Firmware Updater\n\n\n"); |
| 12 | printf("****************************************************\n" |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 13 | "* ATTENTION!! PLEASE READ THIS NOTICE CAREFULLY! *\n" |
| 14 | "****************************************************\n\n" |
| 15 | "This program will update your computer's firmware.\n" |
| 16 | "Do NOT remove the disk, reset the machine, or do\n" |
| 17 | "anything that might disrupt functionality. If this\n"); |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 18 | printf("Program fails, your computer might be unusable, and\n" |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 19 | "you will need to return your board for reflashing.\n" |
| 20 | "If you find this too risky, remove the diskette and\n" |
| 21 | "switch off your machine now. Otherwise press the \n" |
| 22 | "SPACE key now to start the process\n\n"); |
| 23 | do |
| 24 | { |
| 25 | char x; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 26 | while (!tstc()); |
| 27 | x = getc(); |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 28 | if (x == ' ') break; |
| 29 | } while (1); |
| 30 | |
| 31 | do_updater(); |
| 32 | |
| 33 | i = 5; |
| 34 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 35 | printf("\nUpdate done. Please remove diskette.\n"); |
| 36 | printf("The machine will automatically reset in %d seconds\n", i); |
| 37 | printf("You can switch off/reset now when the floppy is removed\n\n"); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 38 | |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 39 | while (i) |
| 40 | { |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 41 | printf("Resetting in %d\r", i); |
| 42 | udelay(1000000); |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 43 | i--; |
| 44 | } |
| 45 | do_reset(); |
| 46 | while (1); |
| 47 | } |
| 48 | |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 49 | void do_updater(void) |
| 50 | { |
| 51 | unsigned long *addr = &__dummy + 65; |
| 52 | unsigned long flash_size = flash_init(); |
| 53 | int rc; |
| 54 | |
| 55 | flash_sect_protect(0, 0xFFF00000, 0xFFF7FFFF); |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 56 | printf("Erasing "); |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 57 | flash_sect_erase(0xFFF00000, 0xFFF7FFFF); |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 58 | printf("Writing "); |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 59 | rc = flash_write((uchar *)addr, 0xFFF00000, 0x7FFFF); |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 60 | if (rc != 0) printf("\nFlashing failed due to error %d\n", rc); |
| 61 | else printf("\ndone\n"); |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 62 | flash_sect_protect(1, 0xFFF00000, 0xFFF7FFFF); |
| 63 | } |