9 static void make_srec(struct serial_if
*sif
, char type
, size_t addr
,
10 const void *data
, size_t len
)
12 char buf
[80]; /* More than the largest possible size */
14 const uint8_t *dp
= data
;
15 size_t alen
= (type
== '0') ? 4 : 8;
19 p
+= sprintf(p
, "S%c%02X%0*zX", type
, len
+alen
+1, alen
, addr
);
21 csum
= (len
+alen
+1) + addr
+ (addr
>> 8) + (addr
>> 16) + (addr
>> 24);
23 p
+= sprintf(p
, "%02X", *dp
);
28 p
+= sprintf(p
, "%02X\r\n", csum
);
30 sif
->write(sif
, buf
, p
-buf
);
33 void send_srec(struct serial_if
*sif
, struct file_info
*fileinfo
,
34 void (*gen_data
) (void *, size_t, struct file_info
*, size_t))
36 uint8_t blk_buf
[1024];
38 size_t addr
, len
, bytes
, chunk
, offset
, pos
;
43 make_srec(sif
, '0', 0, NULL
, 0);
47 addr
= fileinfo
->base
;
49 gen_data(blk_buf
, sizeof blk_buf
, fileinfo
, pos
);
50 pos
+= sizeof blk_buf
;
51 bytes
= sizeof blk_buf
;
56 printf("Sending block %d...\r", blk
);
60 chunk
= bytes
> 32 ? 32 : bytes
;
62 make_srec(sif
, '3', addr
, np
, chunk
);
72 printf("\nSending EOT...\n");
73 make_srec(sif
, '7', fileinfo
->base
, NULL
, 0);