annotate target-utils/libload/intelflash.c @ 404:7daea2476062

loadagent: Intel flash support added, compiles
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 16 Jun 2014 01:15:17 +0000
parents
children d7f409493eb6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
404
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module implements the INFB and INFW commands for programming
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * Intel-style flash memories. The syntax and operation are exactly
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 * the same as the AMD flash counterparts AMFB and AMFW.
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 */
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <sys/types.h>
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include "types.h"
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 static u32 base_addr;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 void
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 cmd_INFB(argbulk)
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 char *argbulk;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 {
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 char *argv[2];
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 u_long addr;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 if (parse_args(argbulk, 1, 1, argv, 0) < 0)
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 return;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 if (parse_hexarg(argv[0], 8, &addr) < 0) {
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 printf("ERROR: argument must be a valid 32-bit hex address\n");
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 return;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 }
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 if (addr & 1) {
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 printf("ERROR: odd address\n");
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 return;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 }
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 base_addr = addr;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 }
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 void
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 cmd_INFW(argbulk)
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 char *argbulk;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 {
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 char *argv[3], *s;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 u_long offset;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 volatile u16 *flashptr;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 u32 datum; /* needs to be u32 for decode_hex_digits() */
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 u16 stat;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 int i;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 if (parse_args(argbulk, 2, 2, argv, 0) < 0)
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 return;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 if (parse_hexarg(argv[0], 8, &offset) < 0) {
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 printf("ERROR: offset argument must a valid 32-bit hex value\n");
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 return;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 }
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 if (offset & 1) {
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 printf("ERROR: odd offset argument\n");
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 return;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 }
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 flashptr = (volatile u16 *)(base_addr + offset);
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 for (s = argv[1]; *s; flashptr++, s += 4) {
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 if (decode_hex_digits(s, 4, &datum) < 0) {
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 printf("ERROR: bad INFW hex string argument\n");
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 return;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 }
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 *flashptr = 0x40;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 *flashptr = datum;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 for (i = 10000; i; i--) {
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 stat = *flashptr;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 if (stat & 0x80)
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 break;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 }
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 if (!i) {
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 printf("ERROR: flash write timeout at %08X\n",
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 (u_long) flashptr);
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 return;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 }
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 if (stat & 0x10) {
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 printf("ERROR: program operation failed at %08X\n",
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 (u_long) flashptr);
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 return;
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 }
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 }
7daea2476062 loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 }