blob: 18f122ad238b3a85e79a7084590c0e5d8fb86703 [file] [log] [blame]
wdenkc7de8292002-11-19 11:04:11 +00001#include <common.h>
wdenk27b207f2003-07-24 23:38:38 +00002#include <exports.h>
wdenkc7de8292002-11-19 11:04:11 +00003
4extern unsigned long __dummy;
5void do_reset (void);
6void do_updater(void);
7
8void _main(void)
9{
10 int i;
wdenk27b207f2003-07-24 23:38:38 +000011 printf("U-Boot Firmware Updater\n\n\n");
12 printf("****************************************************\n"
wdenkc7de8292002-11-19 11:04:11 +000013 "* 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");
wdenk27b207f2003-07-24 23:38:38 +000018 printf("Program fails, your computer might be unusable, and\n"
wdenkc7de8292002-11-19 11:04:11 +000019 "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;
wdenk27b207f2003-07-24 23:38:38 +000026 while (!tstc());
27 x = getc();
wdenkc7de8292002-11-19 11:04:11 +000028 if (x == ' ') break;
29 } while (1);
30
31 do_updater();
32
33 i = 5;
34
wdenk27b207f2003-07-24 23:38:38 +000035 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");
wdenk8bde7f72003-06-27 21:31:46 +000038
wdenkc7de8292002-11-19 11:04:11 +000039 while (i)
40 {
wdenk27b207f2003-07-24 23:38:38 +000041 printf("Resetting in %d\r", i);
42 udelay(1000000);
wdenkc7de8292002-11-19 11:04:11 +000043 i--;
44 }
45 do_reset();
46 while (1);
47}
48
wdenkc7de8292002-11-19 11:04:11 +000049void 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);
wdenk27b207f2003-07-24 23:38:38 +000056 printf("Erasing ");
wdenkc7de8292002-11-19 11:04:11 +000057 flash_sect_erase(0xFFF00000, 0xFFF7FFFF);
wdenk27b207f2003-07-24 23:38:38 +000058 printf("Writing ");
wdenkc7de8292002-11-19 11:04:11 +000059 rc = flash_write((uchar *)addr, 0xFFF00000, 0x7FFFF);
wdenk27b207f2003-07-24 23:38:38 +000060 if (rc != 0) printf("\nFlashing failed due to error %d\n", rc);
61 else printf("\ndone\n");
wdenkc7de8292002-11-19 11:04:11 +000062 flash_sect_protect(1, 0xFFF00000, 0xFFF7FFFF);
63}