blob: b6d50d5be070d6ba552315a21d7f58a02e0afd33 [file] [log] [blame]
wdenk452cfd62002-11-19 11:04:11 +00001#include <common.h>
wdenk874ac262003-07-24 23:38:38 +00002#include <exports.h>
wdenk452cfd62002-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;
wdenk874ac262003-07-24 23:38:38 +000011 printf("U-Boot Firmware Updater\n\n\n");
12 printf("****************************************************\n"
wdenk452cfd62002-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");
wdenk874ac262003-07-24 23:38:38 +000018 printf("Program fails, your computer might be unusable, and\n"
wdenk452cfd62002-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;
wdenk874ac262003-07-24 23:38:38 +000026 while (!tstc());
27 x = getc();
wdenk452cfd62002-11-19 11:04:11 +000028 if (x == ' ') break;
29 } while (1);
30
31 do_updater();
32
33 i = 5;
34
wdenk874ac262003-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");
wdenk57b2d802003-06-27 21:31:46 +000038
wdenk452cfd62002-11-19 11:04:11 +000039 while (i)
40 {
wdenk874ac262003-07-24 23:38:38 +000041 printf("Resetting in %d\r", i);
42 udelay(1000000);
wdenk452cfd62002-11-19 11:04:11 +000043 i--;
44 }
45 do_reset();
46 while (1);
47}
48
49int flash_sect_protect (int p, ulong addr_first, ulong addr_last);
50int flash_sect_erase (ulong addr_first, ulong addr_last);
51int flash_write (uchar *src, ulong addr, ulong cnt);
52
53void 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);
wdenk874ac262003-07-24 23:38:38 +000060 printf("Erasing ");
wdenk452cfd62002-11-19 11:04:11 +000061 flash_sect_erase(0xFFF00000, 0xFFF7FFFF);
wdenk874ac262003-07-24 23:38:38 +000062 printf("Writing ");
wdenk452cfd62002-11-19 11:04:11 +000063 rc = flash_write((uchar *)addr, 0xFFF00000, 0x7FFFF);
wdenk874ac262003-07-24 23:38:38 +000064 if (rc != 0) printf("\nFlashing failed due to error %d\n", rc);
65 else printf("\ndone\n");
wdenk452cfd62002-11-19 11:04:11 +000066 flash_sect_protect(1, 0xFFF00000, 0xFFF7FFFF);
67}