comparison 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
comparison
equal deleted inserted replaced
403:7602443edf0d 404:7daea2476062
1 /*
2 * This module implements the INFB and INFW commands for programming
3 * Intel-style flash memories. The syntax and operation are exactly
4 * the same as the AMD flash counterparts AMFB and AMFW.
5 */
6
7 #include <sys/types.h>
8 #include "types.h"
9
10 static u32 base_addr;
11
12 void
13 cmd_INFB(argbulk)
14 char *argbulk;
15 {
16 char *argv[2];
17 u_long addr;
18
19 if (parse_args(argbulk, 1, 1, argv, 0) < 0)
20 return;
21 if (parse_hexarg(argv[0], 8, &addr) < 0) {
22 printf("ERROR: argument must be a valid 32-bit hex address\n");
23 return;
24 }
25 if (addr & 1) {
26 printf("ERROR: odd address\n");
27 return;
28 }
29 base_addr = addr;
30 }
31
32 void
33 cmd_INFW(argbulk)
34 char *argbulk;
35 {
36 char *argv[3], *s;
37 u_long offset;
38 volatile u16 *flashptr;
39 u32 datum; /* needs to be u32 for decode_hex_digits() */
40 u16 stat;
41 int i;
42
43 if (parse_args(argbulk, 2, 2, argv, 0) < 0)
44 return;
45 if (parse_hexarg(argv[0], 8, &offset) < 0) {
46 printf("ERROR: offset argument must a valid 32-bit hex value\n");
47 return;
48 }
49 if (offset & 1) {
50 printf("ERROR: odd offset argument\n");
51 return;
52 }
53 flashptr = (volatile u16 *)(base_addr + offset);
54 for (s = argv[1]; *s; flashptr++, s += 4) {
55 if (decode_hex_digits(s, 4, &datum) < 0) {
56 printf("ERROR: bad INFW hex string argument\n");
57 return;
58 }
59 *flashptr = 0x40;
60 *flashptr = datum;
61 for (i = 10000; i; i--) {
62 stat = *flashptr;
63 if (stat & 0x80)
64 break;
65 }
66 if (!i) {
67 printf("ERROR: flash write timeout at %08X\n",
68 (u_long) flashptr);
69 return;
70 }
71 if (stat & 0x10) {
72 printf("ERROR: program operation failed at %08X\n",
73 (u_long) flashptr);
74 return;
75 }
76 }
77 }