aboutsummaryrefslogtreecommitdiff
path: root/tools/updater/update.c
blob: 18f122ad238b3a85e79a7084590c0e5d8fb86703 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <common.h>
#include <exports.h>

extern unsigned long __dummy;
void do_reset (void);
void do_updater(void);

void _main(void)
{
    int i;
    printf("U-Boot Firmware Updater\n\n\n");
    printf("****************************************************\n"
	       "*  ATTENTION!! PLEASE READ THIS NOTICE CAREFULLY!  *\n"
	       "****************************************************\n\n"
	       "This program  will update your computer's  firmware.\n"
	       "Do NOT  remove the disk,  reset the  machine,  or do\n"
	       "anything that  might disrupt functionality.  If this\n");
    printf("Program fails, your computer  might be unusable, and\n"
	       "you will  need to return your  board for reflashing.\n"
	       "If you find this too risky,  remove the diskette and\n"
	       "switch off your  machine now.  Otherwise  press the \n"
	       "SPACE key now to start the process\n\n");
    do
    {
	char x;
	while (!tstc());
	x = getc();
	if (x == ' ') break;
    } while (1);

    do_updater();

    i = 5;

    printf("\nUpdate done. Please remove diskette.\n");
    printf("The machine will automatically reset in %d seconds\n", i);
    printf("You can switch off/reset now when the floppy is removed\n\n");

    while (i)
    {
	printf("Resetting in %d\r", i);
	udelay(1000000);
	i--;
    }
    do_reset();
    while (1);
}

void do_updater(void)
{
    unsigned long *addr = &__dummy + 65;
    unsigned long flash_size = flash_init();
    int rc;

    flash_sect_protect(0, 0xFFF00000, 0xFFF7FFFF);
    printf("Erasing ");
    flash_sect_erase(0xFFF00000, 0xFFF7FFFF);
    printf("Writing ");
    rc = flash_write((uchar *)addr, 0xFFF00000, 0x7FFFF);
    if (rc != 0) printf("\nFlashing failed due to error %d\n", rc);
    else printf("\ndone\n");
    flash_sect_protect(1, 0xFFF00000, 0xFFF7FFFF);
}