comparison target-utils/loadagent/cmd_memload.c @ 658:0da2cf5a999c

target-utils: libload eliminated
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 03 Mar 2020 06:06:17 +0000
parents target-utils/libload/cmd_memload.c@9214118ae941
children
comparison
equal deleted inserted replaced
657:742c99c1ff52 658:0da2cf5a999c
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 memcpy(addr, srecbin + 5, len);
52 }