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