comparison target-utils/libload/cmd_memload.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children 9214118ae941
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
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], cksum;
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 cksum = 0;
40 for (i = 0; i <= len; i++)
41 cksum += srecbin[i];
42 if (cksum != 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 }