# HG changeset patch # User Mychaela Falconia # Date 1583627351 0 # Node ID cd48bc4c54600086ba5a4435f7e82e35ffbfdbb4 # Parent 2772cf8435b46c693bcc04a93011b6ca1606beeb fc-loadtool code: erase command split out into flerase.c diff -r 2772cf8435b4 -r cd48bc4c5460 loadtools/Makefile --- a/loadtools/Makefile Sat Mar 07 19:43:10 2020 +0000 +++ b/loadtools/Makefile Sun Mar 08 00:29:11 2020 +0000 @@ -15,11 +15,11 @@ ttypassthru.o 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 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 tpinterfb.o + flcmplboot.o flconf.o fldevs.o flerase.o flmain.o flmisc.o \ + flprogbin.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 tpinterfb.o XRAM_OBJS= chainload.o clmain.o compalload.o crc32tab.o defexitstub.o \ defpath.o flashstubs.o hexdecode.o hwparam.o initscript.o \ diff -r 2772cf8435b4 -r cd48bc4c5460 loadtools/flerase.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loadtools/flerase.c Sun Mar 08 00:29:11 2020 +0000 @@ -0,0 +1,78 @@ +/* + * Flash erase operations are implemented here + */ + +#include +#include +#include +#include +#include +#include +#include +#include "flash.h" + +extern struct flash_bank_info flash_bank_info[2]; + +flashcmd_erase(argc, argv, bank) + char **argv; +{ + struct flash_bank_info *bi; + u_long offset, len; + char *strtoul_endp; + struct sector_info *startsec, *endsec, *sp; + int stat; + time_t start_time, finish_time; + unsigned duration, mm, ss; + + if (argc != 4) { +inv: fprintf(stderr, "usage: %s %s hex-start-offset hex-length\n", + argv[0], argv[1]); + return(-1); + } + offset = strtoul(argv[2], &strtoul_endp, 16); + if (*strtoul_endp) + goto inv; + if (flash_detect(bank, 0) < 0) + return(-1); + bi = flash_bank_info + bank; + if (offset >= bi->geom->total_size) { + fprintf(stderr, + "error: specified offset exceeds flash bank size (0x%lx)\n", + (u_long) bi->geom->total_size); + return(-1); + } + len = strtoul(argv[3], &strtoul_endp, 16); + if (*strtoul_endp) + goto inv; + if (len > bi->geom->total_size - offset) { + fprintf(stderr, + "error: specified offset+length exceed flash bank size (0x%lx)\n", + (u_long) bi->geom->total_size); + return(-1); + } + if (!len) { + printf("Zero length specified - nothing to do!\n"); + return(0); + } + /* now enforce sector alignment for both offset and length */ + if (get_flash_sector_table(bank) < 0) + return(-1); + if (get_flash_sector_range(bi, offset, len, &startsec, &endsec) < 0) + return(-1); + printf("Erasing %d sector(s)\n", endsec - startsec); + time(&start_time); + for (sp = startsec; sp < endsec; sp++) { + stat = bi->ops->erase_sector(bi, sp); + if (stat) + return(stat); + putchar('.'); + fflush(stdout); + } + time(&finish_time); + putchar('\n'); + duration = finish_time - start_time; + mm = duration / 60; + ss = duration - mm * 60; + printf("Operation completed in %um%us\n", mm, ss); + return(0); +} diff -r 2772cf8435b4 -r cd48bc4c5460 loadtools/flmisc.c --- a/loadtools/flmisc.c Sat Mar 07 19:43:10 2020 +0000 +++ b/loadtools/flmisc.c Sun Mar 08 00:29:11 2020 +0000 @@ -8,7 +8,6 @@ #include #include #include -#include #include "flash.h" extern struct flash_bank_info flash_bank_info[2]; @@ -122,70 +121,6 @@ format); } -flashcmd_erase(argc, argv, bank) - char **argv; -{ - struct flash_bank_info *bi; - u_long offset, len; - char *strtoul_endp; - struct sector_info *startsec, *endsec, *sp; - int stat; - time_t start_time, finish_time; - unsigned duration, mm, ss; - - if (argc != 4) { -inv: fprintf(stderr, "usage: %s %s hex-start-offset hex-length\n", - argv[0], argv[1]); - return(-1); - } - offset = strtoul(argv[2], &strtoul_endp, 16); - if (*strtoul_endp) - goto inv; - if (flash_detect(bank, 0) < 0) - return(-1); - bi = flash_bank_info + bank; - if (offset >= bi->geom->total_size) { - fprintf(stderr, - "error: specified offset exceeds flash bank size (0x%lx)\n", - (u_long) bi->geom->total_size); - return(-1); - } - len = strtoul(argv[3], &strtoul_endp, 16); - if (*strtoul_endp) - goto inv; - if (len > bi->geom->total_size - offset) { - fprintf(stderr, - "error: specified offset+length exceed flash bank size (0x%lx)\n", - (u_long) bi->geom->total_size); - return(-1); - } - if (!len) { - printf("Zero length specified - nothing to do!\n"); - return(0); - } - /* now enforce sector alignment for both offset and length */ - if (get_flash_sector_table(bank) < 0) - return(-1); - if (get_flash_sector_range(bi, offset, len, &startsec, &endsec) < 0) - return(-1); - printf("Erasing %d sector(s)\n", endsec - startsec); - time(&start_time); - for (sp = startsec; sp < endsec; sp++) { - stat = bi->ops->erase_sector(bi, sp); - if (stat) - return(stat); - putchar('.'); - fflush(stdout); - } - time(&finish_time); - putchar('\n'); - duration = finish_time - start_time; - mm = duration / 60; - ss = duration - mm * 60; - printf("Operation completed in %um%us\n", mm, ss); - return(0); -} - flashcmd_quickprog(argc, argv, bank) char **argv; {