FreeCalypso > hg > freecalypso-tools
changeset 668:cd48bc4c5460
fc-loadtool code: erase command split out into flerase.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 08 Mar 2020 00:29:11 +0000 (2020-03-08) |
parents | 2772cf8435b4 |
children | ba9523ca6ed8 |
files | loadtools/Makefile loadtools/flerase.c loadtools/flmisc.c |
diffstat | 3 files changed, 83 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- 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 \
--- /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 <sys/types.h> +#include <stdio.h> +#include <stdint.h> +#include <string.h> +#include <strings.h> +#include <stdlib.h> +#include <time.h> +#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); +}
--- 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 <string.h> #include <strings.h> #include <stdlib.h> -#include <time.h> #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; {