1
0
mirror of https://github.com/marqs85/ossc.git synced 2026-04-21 05:16:31 +00:00

Factor writing to Flash memory and SD->Flash copying into functions

This is in preparation for the feature to import settings from the
SD card.
This commit is contained in:
Ari Sundholm
2017-11-03 17:07:44 +02:00
parent 7914a2ee83
commit a5b329584e
6 changed files with 60 additions and 27 deletions
+26
View File
@@ -83,6 +83,32 @@ int write_flash_page(alt_u8 *pagedata, alt_u32 length, alt_u32 pagenum)
return 0;
}
int write_flash(alt_u8 *buf, alt_u32 length, alt_u32 pagenum, alt_u8 *tmpbuf)
{
int retval;
alt_u32 bytes_to_w;
while (length > 0) {
bytes_to_w = (length > PAGESIZE) ? PAGESIZE : length;
// Use a temporary buffer if one was given.
// This is to avoid the original buffer from
// being overwritten by write_flash_page().
if (tmpbuf)
memcpy(tmpbuf, buf, bytes_to_w);
retval = write_flash_page(tmpbuf ? tmpbuf : buf, bytes_to_w, pagenum);
if (retval != 0)
return retval;
buf += bytes_to_w;
length -= bytes_to_w;
++pagenum;
}
return 0;
}
int verify_flash(alt_u32 offset, alt_u32 length, alt_u32 golden_crc, alt_u8 *tmpbuf)
{
alt_u32 crcval=0, i, bytes_to_read;