FreeCalypso > hg > freecalypso-tools
changeset 672:57cb825b505a
fc-loadtool code: flprogbin.c refactoring in prep for e-program-bin
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 08 Mar 2020 04:09:08 +0000 |
parents | e66fafeeb377 |
children | f67e5ad30324 |
files | loadtools/flmain.c loadtools/flprogbin.c |
diffstat | 2 files changed, 52 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/loadtools/flmain.c Sun Mar 08 03:43:11 2020 +0000 +++ b/loadtools/flmain.c Sun Mar 08 04:09:08 2020 +0000 @@ -95,7 +95,7 @@ extern int flashcmd_dump2file(); extern int flashcmd_erase(); extern int flashcmd_erase_program_boot(); -extern int flashcmd_progbin(); +extern int flashcmd_progbin_wrap(); extern int flashcmd_program_m0(); extern int flashcmd_program_srec(); extern int flashcmd_quickprog(); @@ -119,7 +119,7 @@ {"help", flashcmd_help}, {"id", flashcmd_id}, {"info", flashcmd_info}, - {"program-bin", flashcmd_progbin}, + {"program-bin", flashcmd_progbin_wrap}, {"program-m0", flashcmd_program_m0}, {"program-srec", flashcmd_program_srec}, {"quickprog", flashcmd_quickprog},
--- a/loadtools/flprogbin.c Sun Mar 08 03:43:11 2020 +0000 +++ b/loadtools/flprogbin.c Sun Mar 08 04:09:08 2020 +0000 @@ -17,14 +17,15 @@ extern struct flash_bank_info flash_bank_info[2]; extern uint32_t crc32_table[]; -flashcmd_progbin(argc, argv, bank) - char **argv; +flashcmd_progbin_int(bank, with_erase, flashoff, imgfile, fileoff, len, + len_given) + u_long flashoff, fileoff, len; + char *imgfile; { struct flash_bank_info *bi; - u_long flashoff, fileoff, len, origlen, bytesdone; + u_long origlen, bytesdone; u_long crc_base_addr, crc_from_target; uint32_t crcaccum; - char *strtoul_endp; FILE *binf; struct stat filestat; char *targv[3], shortarg[10]; @@ -33,15 +34,6 @@ time_t initial_time, curtime, last_time; unsigned duration, mm, ss; - if (argc < 4 || argc > 6) { -inv: fprintf(stderr, - "usage: %s %s flash-offset binfile [file-offset [length]]\n", - argv[0], argv[1]); - return(-1); - } - flashoff = strtoul(argv[2], &strtoul_endp, 16); - if (*strtoul_endp) - goto inv; if (flash_detect(bank, 0) < 0) return(-1); bi = flash_bank_info + bank; @@ -55,37 +47,24 @@ fprintf(stderr, "error: flash offset must be even\n"); return(-1); } - binf = fopen(argv[3], "r"); + binf = fopen(imgfile, "r"); if (!binf) { - perror(argv[3]); + perror(imgfile); return(-1); } fstat(fileno(binf), &filestat); if (!S_ISREG(filestat.st_mode)) { - fprintf(stderr, "%s is not a regular file\n", argv[3]); + fprintf(stderr, "error: %s is not a regular file\n", imgfile); fclose(binf); return(-1); } - if (argc > 4) { - fileoff = strtoul(argv[4], &strtoul_endp, 16); - if (*strtoul_endp) { - fclose(binf); - goto inv; - } - if (fileoff > filestat.st_size) { - fprintf(stderr, + if (fileoff > filestat.st_size) { + fprintf(stderr, "error: specified file offset exceeds file length\n"); - fclose(binf); - return(-1); - } - } else - fileoff = 0; - if (argc > 5) { - len = strtoul(argv[5], &strtoul_endp, 16); - if (*strtoul_endp) { - fclose(binf); - goto inv; - } + fclose(binf); + return(-1); + } + if (len_given) { if (len > filestat.st_size - fileoff) { fprintf(stderr, "error: specified file offset+length exceed file length\n"); @@ -156,7 +135,7 @@ cc = fread(databuf + 7, 1, reclen, binf); if (cc != reclen) { fclose(binf); - fprintf(stderr, "error reading from %s\n", argv[3]); + fprintf(stderr, "error reading from %s\n", imgfile); /* don't leave loadagent in binary flash mode */ databuf[0] = 0x04; write(target_fd, databuf, 1); @@ -239,3 +218,38 @@ return(-1); } } + +flashcmd_progbin_wrap(argc, argv, bank) + char **argv; +{ + u_long flashoff, fileoff, len; + int len_given; + char *strtoul_endp; + + if (argc < 4 || argc > 6) { +inv: fprintf(stderr, + "usage: %s %s flash-offset binfile [file-offset [length]]\n", + argv[0], argv[1]); + return(-1); + } + flashoff = strtoul(argv[2], &strtoul_endp, 16); + if (*strtoul_endp) + goto inv; + if (argc > 4) { + fileoff = strtoul(argv[4], &strtoul_endp, 16); + if (*strtoul_endp) + goto inv; + } else + fileoff = 0; + if (argc > 5) { + len = strtoul(argv[5], &strtoul_endp, 16); + if (*strtoul_endp) + goto inv; + len_given = 1; + } else { + len = 0; /* dummy */ + len_given = 0; + } + return flashcmd_progbin_int(bank, argv[1][0] == 'e', flashoff, argv[3], + fileoff, len, len_given); +}