comparison target-utils/libload/cmd_memload.c @ 40:9b4c5ce3db8b

loadagent: ML command (support for fc-chainload) implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 13 May 2013 22:59:08 +0000
parents
children eee03b6ac615
comparison
equal deleted inserted replaced
39:d67bfcb9e351 40:9b4c5ce3db8b
1 /*
2 * This module implements the ML (memory load) command, which will be
3 * used by fc-chainload.
4 *
5 * The sole argument to the ML command is the body of an S3 record
6 * with the initial "S3" characters stripped, i.e., starting with the
7 * "count" byte, followed by the address, data and checksum bytes
8 * exactly as in the original S3 record.
9 */
10
11 #include "types.h"
12
13 void
14 cmd_memload(argbulk)
15 char *argbulk;
16 {
17 char *argv[2], *s;
18 u8 srecbin[256];
19 int len, i, c;
20 u32 addr;
21
22 if (parse_args(argbulk, 1, 1, argv, 0) < 0)
23 return;
24 s = argv[0];
25 if (decode_hex_digits(s, 2, &len) < 0) {
26 inv: printf("ERROR: ML argument is invalid\n");
27 return;
28 }
29 s += 2;
30 if (len < 6)
31 goto inv;
32 srecbin[0] = len;
33 for (i = 1; i <= len; i++) {
34 if (decode_hex_digits(s, 2, &c) < 0)
35 goto inv;
36 s += 2;
37 srecbin[i] = c;
38 }
39 c = 0;
40 for (i = 0; i <= len; i++)
41 c += srecbin[i];
42 if (c != 0xFF) {
43 printf("ERROR: bad ML S-record checksum\n");
44 return;
45 }
46 len -= 5;
47 addr = ((u32)srecbin[1] << 24) |
48 ((u32)srecbin[2] << 16) |
49 ((u32)srecbin[3] << 8) |
50 (u32)srecbin[4];
51 bcopy(srecbin + 5, addr, len);
52 }