FreeCalypso > hg > freecalypso-sw
changeset 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 | d67bfcb9e351 |
children | 1c50add5e202 |
files | target-utils/libload/Makefile target-utils/libload/cmd_memload.c target-utils/libload/hexstrings.c target-utils/loadagent/cmdtab.c |
diffstat | 4 files changed, 89 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/target-utils/libload/Makefile Mon May 13 20:51:04 2013 +0000 +++ b/target-utils/libload/Makefile Mon May 13 22:59:08 2013 +0000 @@ -4,7 +4,8 @@ AR= arm-elf-ar RANLIB= arm-elf-ranlib -OBJS= cmd_blankchk.o cmd_crc32.o cmd_memdump_human.o cmd_memdump_machine.o +OBJS= cmd_blankchk.o cmd_crc32.o cmd_memdump_human.o cmd_memdump_machine.o \ + cmd_memload.o hexstrings.o all: libload.a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/libload/cmd_memload.c Mon May 13 22:59:08 2013 +0000 @@ -0,0 +1,52 @@ +/* + * This module implements the ML (memory load) command, which will be + * used by fc-chainload. + * + * The sole argument to the ML command is the body of an S3 record + * with the initial "S3" characters stripped, i.e., starting with the + * "count" byte, followed by the address, data and checksum bytes + * exactly as in the original S3 record. + */ + +#include "types.h" + +void +cmd_memload(argbulk) + char *argbulk; +{ + char *argv[2], *s; + u8 srecbin[256]; + int len, i, c; + u32 addr; + + if (parse_args(argbulk, 1, 1, argv, 0) < 0) + return; + s = argv[0]; + if (decode_hex_digits(s, 2, &len) < 0) { +inv: printf("ERROR: ML argument is invalid\n"); + return; + } + s += 2; + if (len < 6) + goto inv; + srecbin[0] = len; + for (i = 1; i <= len; i++) { + if (decode_hex_digits(s, 2, &c) < 0) + goto inv; + s += 2; + srecbin[i] = c; + } + c = 0; + for (i = 0; i <= len; i++) + c += srecbin[i]; + if (c != 0xFF) { + printf("ERROR: bad ML S-record checksum\n"); + return; + } + len -= 5; + addr = ((u32)srecbin[1] << 24) | + ((u32)srecbin[2] << 16) | + ((u32)srecbin[3] << 8) | + (u32)srecbin[4]; + bcopy(srecbin + 5, addr, len); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/libload/hexstrings.c Mon May 13 22:59:08 2013 +0000 @@ -0,0 +1,33 @@ +/* + * The decode_hex_digits() function contained in this module + * will be used by the XRAM and flash loading commands + * which take SREC-like long hex string arguments. + */ + +#include <ctype.h> +#include "types.h" + +decode_hex_digits(str, ndigits, valp) + char *str; + int ndigits; + u32 *valp; +{ + u32 accum; + int i, c; + + accum = 0; + for (i = 0; i < ndigits; i++) { + c = *str++; + if (!isxdigit(c)) + return(-1); + accum <<= 4; + if (isdigit(c)) + accum += c - '0'; + else if (islower(c)) + accum += c - 'a' + 10; + else + accum += c - 'A' + 10; + } + *valp = accum; + return(0); +}
--- a/target-utils/loadagent/cmdtab.c Mon May 13 20:51:04 2013 +0000 +++ b/target-utils/loadagent/cmdtab.c Mon May 13 22:59:08 2013 +0000 @@ -13,9 +13,11 @@ extern void cmd_baud_switch(); extern void cmd_memdump_human(); extern void cmd_memdump_machine(); +extern void cmd_memload(); const struct cmdtab cmdtab[] = { {"DUMP", cmd_memdump_machine}, + {"ML", cmd_memload}, {"baud", cmd_baud_switch}, {"blankchk", cmd_blankchk}, {"crc32", cmd_crc32},