# HG changeset patch # User Michael Spacefalcon # Date 1378061988 0 # Node ID b78db17bfc85ce10f5ecf0e033ce431caa1a1aa0 # Parent b3ed63722eb507df82d097c1951f20dcdf7b6b09 fc-loadtool: flash program-{m0,srec} implemented diff -r b3ed63722eb5 -r b78db17bfc85 loadtools/Makefile --- a/loadtools/Makefile Sun Sep 01 17:20:58 2013 +0000 +++ b/loadtools/Makefile Sun Sep 01 18:59:48 2013 +0000 @@ -11,10 +11,11 @@ IRAM_OBJS= defpath.o hexdecode.o hwparam.o hwparamstubs.o romload.o \ sercomm.o sertool.o srecreader.o ttypassthru.o ${EXTRA_OBJ} -LOADTOOL_OBJS= crc32tab.o defpath.o flerase.o flprogbin.o flutil.o hexdecode.o\ - hwparam.o labaud.o ltdispatch.o ltdump.o ltexit.o ltflash.o \ - ltmain.o ltmisc.o ltpassthru.o ltscript.o romload.o sercomm.o \ - srecreader.o tpinterf.o tpinterf2.o tpinterf3.o ${EXTRA_OBJ} +LOADTOOL_OBJS= crc32tab.o defpath.o flerase.o flprogbin.o flprogsrec.o \ + flutil.o hexdecode.o hwparam.o labaud.o ltdispatch.o ltdump.o \ + ltexit.o ltflash.o ltmain.o ltmisc.o ltpassthru.o ltscript.o \ + romload.o sercomm.o srecreader.o tpinterf.o tpinterf2.o \ + tpinterf3.o ${EXTRA_OBJ} XRAM_OBJS= chainload.o clmain.o defpath.o hexdecode.o hwparam.o \ hwparamstubs.o initscript.o labaud.o romload.o sercomm.o \ diff -r b3ed63722eb5 -r b78db17bfc85 loadtools/flprogsrec.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loadtools/flprogsrec.c Sun Sep 01 18:59:48 2013 +0000 @@ -0,0 +1,146 @@ +/* + * In this module we are going to implement the flash program-srec and + * flash program-m0 commands: programming flash using S-record files + * as the data source. + */ + +#include +#include +#include +#include +#include "flash.h" +#include "srecreader.h" + +extern struct flash_bank_info flash_bank_info[2]; + +flashcmd_progsrec_gen(bank, imgfile, is_m0) + char *imgfile; +{ + struct flash_bank_info *bi; + struct srecreader srr; + char *targv[4], shortarg[10], longarg[513]; + int resp; + unsigned long rec_count; + + srr.filename = imgfile; + resp = open_srec_file(&srr); + if (resp < 0) + return(resp); + bi = flash_bank_info + bank; + sprintf(shortarg, "%lx", (u_long) bi->base_addr); + targv[0] = "AMFB"; + targv[1] = shortarg; + targv[2] = 0; + printf("Setting flash base address: %s %s\n", targv[0], targv[1]); + tpinterf_make_cmd(targv); + if (tpinterf_send_cmd() < 0) { + fclose(srr.openfile); + return(-1); + } + resp = tpinterf_pass_output(1); + if (resp) { + fclose(srr.openfile); + return(resp); + } + targv[0] = "AMFW"; + targv[1] = shortarg; + targv[2] = longarg; + targv[3] = 0; + for (rec_count = 0; ; ) { + if (read_s_record(&srr) < 0) { + /* error msg already printed */ + fclose(srr.openfile); + return(-1); + } + if (srr.record_type == '0') { + if (srr.lineno == 1) + continue; + fprintf(stderr, + "Warning: S0 record found in line %d of %s (expected in line 1 only)\n", + srr.lineno, srr.filename); + continue; + } else if (srr.record_type == '7') + break; + else if (srr.record_type != '3') { + fprintf(stderr, + "Warning: unsupported S%c record type in line %d of %s\n", + srr.record_type, srr.lineno, srr.filename); + continue; + } + /* must be S3 */ + if (s3s7_get_addr_data(&srr) < 0) { + /* error msg already printed */ + fclose(srr.openfile); + return(-1); + } + if (srr.datalen < 1) { + fprintf(stderr, + "%s line %d: S3 record of zero data length ignored\n", + srr.filename, srr.lineno); + continue; + } + if (srr.addr & 1 || srr.datalen & 1) { + fprintf(stderr, + "%s line %d: violates word alignment requirement\n", + srr.filename, srr.lineno); + fclose(srr.openfile); + return(-1); + } + srr.addr &= bi->total_size - 1; + if (srr.addr + srr.datalen > bi->total_size) { + fprintf(stderr, + "%s line %d: goes past the end of the flash bank\n", + srr.filename, srr.lineno); + fclose(srr.openfile); + return(-1); + } + if (!rec_count) + printf("Programming flash, each \'.\' is one S-record\n"); + sprintf(shortarg, "%lx", (u_long) srr.addr); + build_flashw_hex_string(srr.record + 5, longarg, + srr.datalen >> 1, is_m0); + tpinterf_make_cmd(targv); + if (tpinterf_send_cmd() < 0) { + fclose(srr.openfile); + return(-1); + } + resp = tpinterf_pass_output(8); /* 8 s timeout */ + if (resp) { + fclose(srr.openfile); + return(resp); + } + putchar('.'); + fflush(stdout); + rec_count++; + } + /* got S7 */ + fclose(srr.openfile); + if (!rec_count) { + fprintf(stderr, + "%s line %d: S7 without any preceding S3 data records\n", + srr.filename, srr.lineno); + return(-1); + } + printf("\nProgramming complete\n"); + return(0); +} + +flashcmd_program_srec(argc, argv, bank) + char **argv; +{ + if (argc != 3) { + fprintf(stderr, "usage: %s %s image.srec\n", argv[0], argv[1]); + return(-1); + } + return flashcmd_progsrec_gen(bank, argv[2], 0); +} + +flashcmd_program_m0(argc, argv, bank) + char **argv; +{ + if (argc != 3) { + fprintf(stderr, "usage: %s %s image.m0\n", argv[0], argv[1]); + return(-1); + } + return flashcmd_progsrec_gen(bank, argv[2], 1); +} diff -r b3ed63722eb5 -r b78db17bfc85 loadtools/ltflash.c --- a/loadtools/ltflash.c Sun Sep 01 17:20:58 2013 +0000 +++ b/loadtools/ltflash.c Sun Sep 01 18:59:48 2013 +0000 @@ -297,6 +297,8 @@ extern int flashcmd_erase(); extern int flashcmd_progbin(); +extern int flashcmd_program_m0(); +extern int flashcmd_program_srec(); extern int flashcmd_sectors(); static struct cmdtab { @@ -309,6 +311,8 @@ {"erase", flashcmd_erase}, {"info", flashcmd_info}, {"program-bin", flashcmd_progbin}, + {"program-m0", flashcmd_program_m0}, + {"program-srec", flashcmd_program_srec}, {"quickprog", flashcmd_quickprog}, {"sectors", flashcmd_sectors}, {0, 0}