summaryrefslogtreecommitdiff
path: root/xpp/utils/hexfile.c
diff options
context:
space:
mode:
authortzafrir <tzafrir@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2006-05-22 16:41:06 +0000
committertzafrir <tzafrir@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2006-05-22 16:41:06 +0000
commit117fcbf3e26236b41ec3fb932e4f73b4b34f289e (patch)
treebe3e5f1e3a4e2bd70cd429f957ad1a9c30b836a7 /xpp/utils/hexfile.c
parentf3ba7804d8358e041cf38eb84ebce9bdbc8757cb (diff)
* Now possible to load FPGA (second stage) firmware with USB1
* fixed locking of xpd-lock * slightly newer FPGA firmware: slight improvements. git-svn-id: http://svn.digium.com/svn/zaptel/trunk@1078 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'xpp/utils/hexfile.c')
-rw-r--r--xpp/utils/hexfile.c67
1 files changed, 65 insertions, 2 deletions
diff --git a/xpp/utils/hexfile.c b/xpp/utils/hexfile.c
index e228517..9862ecc 100644
--- a/xpp/utils/hexfile.c
+++ b/xpp/utils/hexfile.c
@@ -27,7 +27,7 @@
#include <errno.h>
#include "hexfile.h"
-static const char rcsid[] = "$Id:$";
+static const char rcsid[] = "$Id$";
static parse_hexfile_report_func_t report_func = NULL;
@@ -200,6 +200,69 @@ int dump_hexfile(struct hexdata *hexdata, FILE *outfile)
return 0;
}
+int dump_hexfile2(struct hexdata *hexdata, FILE *outfile, uint8_t maxwidth)
+{
+ uint8_t ll;
+ uint8_t tt;
+ uint8_t new_chksum;
+ uint8_t *data;
+ unsigned int i;
+ unsigned int j;
+
+ if (maxwidth <= sizeof(hexdata->lines[0]->d.content.header) ){
+ if(report_func)
+ report_func(LOG_ERR, "Line width too small %d\n", maxwidth);
+ return -EINVAL;
+ }
+
+ for(i = 0; i <= hexdata->last_line; i++) {
+ struct hexline *line = hexdata->lines[i];
+ struct hexline *extraline;
+ int allocsize;
+ int bytesleft = 0;
+ int extra_offset = 0;
+ unsigned int this_line = 0;
+
+ if(!line) {
+ if(report_func)
+ report_func(LOG_ERR, "Missing line at #%d\n", i);
+ return -EINVAL;
+ }
+ ll = line->d.content.header.ll;
+ bytesleft = ll;
+ // split the line into several lines
+ tt = line->d.content.header.tt;
+ while (bytesleft > 0) {
+ this_line = (bytesleft >= maxwidth) ? maxwidth : bytesleft;
+ allocsize = sizeof(struct hexline) + this_line + 1;
+ // generate the new line
+ if((extraline = (struct hexline *)malloc(allocsize)) == NULL) {
+ if(report_func)
+ report_func(LOG_ERR, "No more memory for hexfile lines\n");
+ return -EINVAL;
+ }
+ memset( extraline, 0, allocsize );
+ extraline->d.content.header.ll = this_line;
+ extraline->d.content.header.offset = line->d.content.header.offset + extra_offset;
+ extraline->d.content.header.tt = tt;
+ memcpy( extraline->d.content.tt_data.data, line->d.content.tt_data.data+extra_offset, this_line);
+ new_chksum = 0xFF - checksum(extraline) + 1;
+ // print it
+ data = extraline->d.content.tt_data.data;
+ fprintf(outfile, ":%02X%04X%02X", extraline->d.content.header.ll, extraline->d.content.header.offset, tt);
+ for(j = 0; j < this_line; j++) {
+ fprintf(outfile, "%02X", data[j]);
+ }
+ fprintf(outfile, "%02X\n", new_chksum);
+ // cleanups
+ free( extraline);
+ extra_offset += this_line;
+ bytesleft -= this_line;
+ }
+ }
+ return 0;
+}
+
struct hexdata *parse_hexfile(const char *fname, unsigned int maxlines)
{
FILE *fp;
@@ -247,7 +310,7 @@ struct hexdata *parse_hexfile(const char *fname, unsigned int maxlines)
}
if((ret = update_hexline(hexdata, buf + 1)) < 0) {
if(report_func)
- report_func(LOG_ERR, "Failed parsing line %s:%d\n", fname, line);
+ report_func(LOG_ERR, "Failed parsing %s at line: %d\n", fname, line);
goto err;
}
}