wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame^] | 1 | #include <common.h> |
| 2 | #include <syscall.h> |
| 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; |
| 11 | mon_printf("U-Boot Firmware Updater\n\n\n"); |
| 12 | mon_printf("****************************************************\n" |
| 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"); |
| 18 | mon_printf("Program fails, your computer might be unusable, and\n" |
| 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; |
| 26 | while (!mon_tstc()); |
| 27 | x = mon_getc(); |
| 28 | if (x == ' ') break; |
| 29 | } while (1); |
| 30 | |
| 31 | do_updater(); |
| 32 | |
| 33 | i = 5; |
| 34 | |
| 35 | mon_printf("\nUpdate done. Please remove diskette.\n"); |
| 36 | mon_printf("The machine will automatically reset in %d seconds\n", i); |
| 37 | mon_printf("You can switch off/reset now when the floppy is removed\n\n"); |
| 38 | |
| 39 | while (i) |
| 40 | { |
| 41 | mon_printf("Resetting in %d\r", i); |
| 42 | mon_udelay(1000000); |
| 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); |
| 60 | mon_printf("Erasing "); |
| 61 | flash_sect_erase(0xFFF00000, 0xFFF7FFFF); |
| 62 | mon_printf("Writing "); |
| 63 | rc = flash_write((uchar *)addr, 0xFFF00000, 0x7FFFF); |
| 64 | if (rc != 0) mon_printf("\nFlashing failed due to error %d\n", rc); |
| 65 | else mon_printf("\ndone\n"); |
| 66 | flash_sect_protect(1, 0xFFF00000, 0xFFF7FFFF); |
| 67 | } |