# HG changeset patch # User Mychaela Falconia # Date 1583088869 0 # Node ID 5385aca4d813e8c5387cfdd88dbeba29ba7b0e10 # Parent 963d15a808eb5de628e9d7b45dc6f4f4ea83228a fc-loadtool module refactoring: CRC-32 functions split out diff -r 963d15a808eb -r 5385aca4d813 loadtools/Makefile --- a/loadtools/Makefile Sun Mar 01 18:28:10 2020 +0000 +++ b/loadtools/Makefile Sun Mar 01 18:54:29 2020 +0000 @@ -16,7 +16,7 @@ LOADTOOL_OBJS= compalload.o crc32tab.o defpath.o flashid.o flashops.o \ flcmplboot.o flconf.o fldevs.o flmain.o flmisc.o flprogbin.o \ - flprogsrec.o flutil.o hexdecode.o hwparam.o labaud.o \ + flprogsrec.o flutil.o hexdecode.o hwparam.o labaud.o lacrc32.o \ ltdispatch.o ltdump.o ltexit.o lthelp.o ltmain.o ltmisc.o \ ltpassthru.o ltscript.o romload.o srecreader.o tpinterf.o \ tpinterf2.o tpinterf3.o diff -r 963d15a808eb -r 5385aca4d813 loadtools/lacrc32.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loadtools/lacrc32.c Sun Mar 01 18:54:29 2020 +0000 @@ -0,0 +1,42 @@ +/* + * This module implements the function for getting a CRC-32 computation + * from loadagent. + */ + +#include +#include +#include +#include +#include +#include + +extern char target_response_line[]; + +crc32_on_target(area_base, area_len, retptr) + u_long area_base, area_len, *retptr; +{ + char arg1[10], arg2[10], *argv[4]; + int stat; + char *strtoul_endp; + + sprintf(arg1, "%lx", area_base); + sprintf(arg2, "%lx", area_len); + argv[0] = "crc32"; + argv[1] = arg1; + argv[2] = arg2; + argv[3] = 0; + tpinterf_make_cmd(argv); + if (tpinterf_send_cmd() < 0) + return(-1); + stat = tpinterf_capture_output_oneline(10); /* 10 s timeout */ + if (stat != 1) { +errout: fprintf(stderr, "error: malformed response to crc32 command\n"); + return(-1); + } + if (strlen(target_response_line) != 8) + goto errout; + *retptr = strtoul(target_response_line, &strtoul_endp, 16); + if (strtoul_endp != target_response_line + 8) + goto errout; + return(0); +} diff -r 963d15a808eb -r 5385aca4d813 loadtools/ltdump.c --- a/loadtools/ltdump.c Sun Mar 01 18:28:10 2020 +0000 +++ b/loadtools/ltdump.c Sun Mar 01 18:54:29 2020 +0000 @@ -12,60 +12,6 @@ #include extern uint32_t crc32_table[]; -extern char target_response_line[]; - -crc32_on_target(area_base, area_len, retptr) - u_long area_base, area_len, *retptr; -{ - char arg1[10], arg2[10], *argv[4]; - int stat; - char *strtoul_endp; - - sprintf(arg1, "%lx", area_base); - sprintf(arg2, "%lx", area_len); - argv[0] = "crc32"; - argv[1] = arg1; - argv[2] = arg2; - argv[3] = 0; - tpinterf_make_cmd(argv); - if (tpinterf_send_cmd() < 0) - return(-1); - stat = tpinterf_capture_output_oneline(10); /* 10 s timeout */ - if (stat != 1) { -errout: fprintf(stderr, "error: malformed response to crc32 command\n"); - return(-1); - } - if (strlen(target_response_line) != 8) - goto errout; - *retptr = strtoul(target_response_line, &strtoul_endp, 16); - if (strtoul_endp != target_response_line + 8) - goto errout; - return(0); -} - -cmd_crc32(argc, argv) - char **argv; -{ - u_long area_base, area_len; - char *strtoul_endp; - u_long crc_result; - int stat; - - area_base = strtoul(argv[1], &strtoul_endp, 16); - if (*strtoul_endp) { -inv: fprintf(stderr, "usage: crc32 hex-start hex-len\n"); - return(-1); - } - area_len = strtoul(argv[2], &strtoul_endp, 16); - if (*strtoul_endp) - goto inv; - stat = crc32_on_target(area_base, area_len, &crc_result); - if (stat == 0) - printf("%08lX\n", crc_result); - return(stat); -} - -/* the actual dump facility */ static FILE *dump_outfile; static int dump_save_srec; diff -r 963d15a808eb -r 5385aca4d813 loadtools/ltmisc.c --- a/loadtools/ltmisc.c Sun Mar 01 18:28:10 2020 +0000 +++ b/loadtools/ltmisc.c Sun Mar 01 18:54:29 2020 +0000 @@ -6,6 +6,29 @@ #include #include #include +#include + +cmd_crc32(argc, argv) + char **argv; +{ + u_long area_base, area_len; + char *strtoul_endp; + u_long crc_result; + int stat; + + area_base = strtoul(argv[1], &strtoul_endp, 16); + if (*strtoul_endp) { +inv: fprintf(stderr, "usage: crc32 hex-start hex-len\n"); + return(-1); + } + area_len = strtoul(argv[2], &strtoul_endp, 16); + if (*strtoul_endp) + goto inv; + stat = crc32_on_target(area_base, area_len, &crc_result); + if (stat == 0) + printf("%08lX\n", crc_result); + return(stat); +} cmd_dieid(argc, argv) char **argv;