# HG changeset patch # User Michael Spacefalcon # Date 1402983981 0 # Node ID a2df77833c2184cf66bbfd1756cf27ba517491b6 # Parent 1ed2d78f150c7b8af6848786128f0516e23ca1f4 fc-loadtool: started implementing flash erase-program-boot command diff -r 1ed2d78f150c -r a2df77833c21 loadtools/flcmplboot.c --- a/loadtools/flcmplboot.c Tue Jun 17 05:11:25 2014 +0000 +++ b/loadtools/flcmplboot.c Tue Jun 17 05:46:21 2014 +0000 @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -12,6 +13,9 @@ #include #include "flash.h" +extern struct flash_bank_info flash_bank_info[2]; +extern struct flash_cmdset flash_cmdset_intel; + static int hack_enabled; static uint32_t boot_sector_size; static uint32_t ram_buffer_addr; @@ -72,3 +76,69 @@ } hack_enabled = 1; } + +flashcmd_erase_program_boot(argc, argv) + char **argv; +{ + FILE *binf; + struct stat filestat; + size_t len; + char *strtoul_endp; + + if (!hack_enabled) { + fprintf(stderr, + "Operation not applicable to this target device\n"); + return(-1); + } + if (argc < 3 || argc > 4) { +inv: fprintf(stderr, "usage: %s %s binfile [length]\n", + argv[0], argv[1]); + return(-1); + } + if (flash_get_cfi(0) < 0) + return(-1); + if (flash_bank_info[0].geom->regions[0].sector_size + != boot_sector_size) { + fprintf(stderr, + "error: detected flash boot sector size differs from config\n"); + return(-1); + } + if (flash_bank_info[0].ops != &flash_cmdset_intel) { + fprintf(stderr, + "error: operation implemented for Intel flash only\n"); + return(-1); + } + + binf = fopen(argv[2], "r"); + if (!binf) { + perror(argv[2]); + return(-1); + } + fstat(fileno(binf), &filestat); + if (!S_ISREG(filestat.st_mode)) { + fprintf(stderr, "%s is not a regular file\n", argv[2]); + fclose(binf); + return(-1); + } + if (argc > 3) { + len = strtoul(argv[3], &strtoul_endp, 16); + if (*strtoul_endp) { + fclose(binf); + goto inv; + } + if (len > filestat.st_size) { + fprintf(stderr, + "error: specified length exceeds file length\n"); + fclose(binf); + return(-1); + } + } else + len = filestat.st_size; + if (len > boot_sector_size) { + fprintf(stderr, "error: length exceeds boot sector size\n"); + fclose(binf); + return(-1); + } + + +}