summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util')
-rw-r--r--src/lib/util/jedparse.cpp15
-rw-r--r--src/lib/util/jedparse.h9
2 files changed, 21 insertions, 3 deletions
diff --git a/src/lib/util/jedparse.cpp b/src/lib/util/jedparse.cpp
index d25b35c3328..14cc503f18f 100644
--- a/src/lib/util/jedparse.cpp
+++ b/src/lib/util/jedparse.cpp
@@ -391,9 +391,24 @@ int jedbin_parse(const void *data, size_t length, jed_data *result)
/* first unpack the number of fuses */
result->numfuses = (cursrc[0] << 24) | (cursrc[1] << 16) | (cursrc[2] << 8) | cursrc[3];
cursrc += 4;
+
if (result->numfuses == 0 || result->numfuses > JED_MAX_FUSES)
return JEDERR_INVALID_DATA;
+ /* Detect DataIO binary format and prepare for conversion. This transformation is based on observation of an 82S100 dump */
+ if (result->numfuses == ((cursrc[0] << 24) | (cursrc[1] << 16) | (cursrc[2] << 8) | cursrc[3]))
+ {
+ result->numfuses = (result->numfuses - 9) * 8; // Double 32 bit byte file size header + trailing byte to Single 32 byte fuse count
+ cursrc = cursrc + 4; // Adjust start of buffer, trailing byte will not be copied below
+ result->binfmt = DATAIO; // DataIO also has swapped inverted/non-inverted line fuses so remember origin
+ if (LOG_PARSE) printf("DATAIO format detected\n");
+ }
+ else
+ {
+ result->binfmt = MAXLOADER; // This is the old format just set for completeness.
+ if (LOG_PARSE) printf("MAXLOADER format detected\n");
+ }
+
/* now make sure we have enough data in the source */
if (length < 4 + (result->numfuses + 7) / 8)
return JEDERR_INVALID_DATA;
diff --git a/src/lib/util/jedparse.h b/src/lib/util/jedparse.h
index f12101ca154..adb9010de1c 100644
--- a/src/lib/util/jedparse.h
+++ b/src/lib/util/jedparse.h
@@ -29,7 +29,9 @@
#define JEDERR_BAD_XMIT_SUM 2
#define JEDERR_BAD_FUSE_SUM 3
-
+/* binary file formats */
+#define MAXLOADER 0
+#define DATAIO 1
/***************************************************************************
TYPE DEFINITIONS
@@ -37,8 +39,9 @@
struct jed_data
{
- uint32_t numfuses; /* number of defined fuses */
- uint8_t fusemap[JED_MAX_FUSES / 8];/* array of bit-packed data */
+ uint32_t numfuses; /* number of defined fuses */
+ uint8_t fusemap[JED_MAX_FUSES / 8]; /* array of bit-packed data */
+ uint8_t binfmt; /* file format MAXLOADER or DATAIO */
};