2 * S-records dump routine -- dumps S-records on the console
9 #include "upload_backend.h"
11 /* Write a single S-record */
12 static int write_srecord(unsigned int len
, unsigned int alen
,
13 uint32_t addr
, uint8_t type
, const void *data
)
15 char buf
[2+2+8+255*2+2+2];
18 const uint8_t *dptr
= data
;
32 csum
= (len
+alen
+1) + addr
+ (addr
>> 8) + (addr
>> 16) + (addr
>> 24);
33 for (i
= 0; i
< len
; i
++)
37 p
+= sprintf(p
, "S%c%02X%0*X", type
, len
+alen
+1, alen
*2, addr
);
38 for (i
= 0; i
< len
; i
++)
39 p
+= sprintf(p
, "%02X", dptr
[i
]);
40 p
+= sprintf(p
, "%02X\n", csum
);
46 static int upload_srec_write(struct upload_backend
*be
)
50 size_t len
, chunk
, offset
, hdrlen
;
57 hdrlen
= snprintf(name
, sizeof name
, "%.32s",
58 be
->argv
[0] ? be
->argv
[0] : "");
60 /* Write head record */
61 write_srecord(hdrlen
, 2, 0, '0', name
);
63 /* Write data records */
66 chunk
= min(len
, (size_t)32);
68 write_srecord(chunk
, 4, offset
, '3', buf
);
74 /* Write termination record */
75 write_srecord(0, 4, 0, '7', NULL
);
80 struct upload_backend upload_srec
= {
82 .helpmsg
= "[filename]",
84 .write
= upload_srec_write
,