Hi,
Thanks for posting BootDrive. Nice work... I migrated it to an AVR109 based booter. I did find one issue and a solution. If the HEX file contains a line shorter than 16 bytes, BootDrive does not load the correct code after that. Here is the code to correct that:
int leftover = 0;
unsigned char leftoverbuf[16];
int readPage(File input, AVRMEM *buf)
{
int len;
int address;
int total_len = leftover;
if (leftover > 0){
memcpy(buf->buf,leftoverbuf,leftover);
}
// grab 128 bytes or less (one page)
int i = 0;
while (total_len < 128){
len = readIntelHexLine(input, &address, &linemembuffer[0]);
if (len < 0){
if (i==0) total_len = len;
break;
}
// else
// total_len=total_len+len;
if (i==0)// first record determines the page address
{
buf->pageaddress = address - leftover;
leftover = 0;
}
i++;
// memcpy((buf->buf)+(i*16), linemembuffer, len);
if ((total_len+len) > 128)
{
leftover = (total_len+len)-128;
memcpy(buf->buf+total_len, linemembuffer,128-total_len);
int kk = 0;
for (int k =(128-total_len);k<len;k++)
leftoverbuf[kk++] = linemembuffer[k];
leftover = kk;
total_len = 128;
}
else
{
memcpy((buf->buf)+total_len, linemembuffer, len);
total_len=total_len+len;
}
}
buf->size = total_len;
return total_len;
}
Now, this page and all the subsequent ones will contain 128 bytes, until the last page (when it doesn't matter). I have tested it against another boot loader and was finally able to verify the code in memory was correct in two distinct ways.
Bill