annotate loadtools/flashops.c @ 405:a212b4968b29

fc-loadtool flash: another refactoring: geometry vs. command set
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 17 Jun 2014 00:33:05 +0000
parents
children f2cc551e597f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
405
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module implements those flash operations which are dependent
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * on the AMD vs. Intel command set style.
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 */
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/types.h>
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdio.h>
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdint.h>
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <stdlib.h>
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <time.h>
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "flash.h"
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 /* common stub functions */
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 static
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 noop()
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 {
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 return(0);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 }
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 static
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 invalid()
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 {
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 fprintf(stderr,
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 "This operation is not applicable to the selected flash type\n");
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 return(-1);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 }
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 /* AMD flash functions */
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 amd_reset_cmd(bi)
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 struct flash_bank_info *bi;
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 {
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 if (do_w16(bi->base_addr + 0xAAA, 0xF0)) {
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 fprintf(stderr,
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 "unexpected response to w16 when resetting flash to read mode!\n");
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 return(-1);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 }
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 return(0);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 }
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 amd_sector_erase(bi, sp)
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 struct flash_bank_info *bi;
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 struct sector_info *sp;
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 {
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 int stat;
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 uint16_t flstat;
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 time_t start_time, curtime;
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 stat = do_w16(bi->base_addr + sp->start + 0xAAA, 0xAA);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 if (stat) {
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 bad_w16: fprintf(stderr,
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 "unexpected response to w16 in erase cmd sequence - aborting\n");
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 return(-1);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 }
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 stat = do_w16(bi->base_addr + sp->start + 0x554, 0x55);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 if (stat)
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 goto bad_w16;
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 stat = do_w16(bi->base_addr + sp->start + 0xAAA, 0x80);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 if (stat)
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 goto bad_w16;
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 stat = do_w16(bi->base_addr + sp->start + 0xAAA, 0xAA);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 if (stat)
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 goto bad_w16;
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 stat = do_w16(bi->base_addr + sp->start + 0x554, 0x55);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 if (stat)
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 goto bad_w16;
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 stat = do_w16(bi->base_addr + sp->start + 0xAAA, 0x30);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 if (stat)
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 goto bad_w16;
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 start_time = time(0);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 for (;;) {
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 stat = do_r16(bi->base_addr + sp->start, &flstat);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 if (stat)
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 return(stat); /* error msg already printed */
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 if (flstat == 0xFFFF)
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 return(0);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 curtime = time(0);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 if (curtime >= start_time + 20) {
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 fprintf(stderr, "erase timeout, aborting\n");
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 return(-1);
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 }
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 }
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 }
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 struct flash_cmdset flash_cmdset_amd = {
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 .cmdset_name = "AMD",
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 .reset_cmd = amd_reset_cmd,
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 .status_cmd = invalid,
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 .unlock_sector = invalid,
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 .erase_sector = amd_sector_erase,
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 .prep_for_program = noop,
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 .loadagent_setbase_cmd = "AMFB",
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 .loadagent_program_cmd = "AMFW",
a212b4968b29 fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 };