wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 1 | #include <common.h> |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 2 | #include <exports.h> |
wdenk | 452cfd6 | 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 | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 11 | printf("U-Boot Firmware Updater\n\n\n"); |
| 12 | printf("****************************************************\n" |
wdenk | 452cfd6 | 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 | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 18 | printf("Program fails, your computer might be unusable, and\n" |
wdenk | 452cfd6 | 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 | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 26 | while (!tstc()); |
| 27 | x = getc(); |
wdenk | 452cfd6 | 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 | 874ac26 | 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 | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 38 | |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 39 | while (i) |
| 40 | { |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 41 | printf("Resetting in %d\r", i); |
| 42 | udelay(1000000); |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 43 | i--; |
| 44 | } |
| 45 | do_reset(); |
| 46 | while (1); |
| 47 | } |
| 48 | |
| 49 | int flash_sect_protect (int p, ulong addr_first, ulong addr_last); |
| 50 | int flash_sect_erase (ulong addr_first, ulong addr_last); |
| 51 | int flash_write (uchar *src, ulong addr, ulong cnt); |
| 52 | |
| 53 | void do_updater(void) |
| 54 | { |
| 55 | unsigned long *addr = &__dummy + 65; |
| 56 | unsigned long flash_size = flash_init(); |
| 57 | int rc; |
| 58 | |
| 59 | flash_sect_protect(0, 0xFFF00000, 0xFFF7FFFF); |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 60 | printf("Erasing "); |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 61 | flash_sect_erase(0xFFF00000, 0xFFF7FFFF); |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 62 | printf("Writing "); |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 63 | rc = flash_write((uchar *)addr, 0xFFF00000, 0x7FFFF); |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 64 | if (rc != 0) printf("\nFlashing failed due to error %d\n", rc); |
| 65 | else printf("\ndone\n"); |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 66 | flash_sect_protect(1, 0xFFF00000, 0xFFF7FFFF); |
| 67 | } |