35 #include <avr/pgmspace.h>
39 #include "lib/assert.h"
44 #define PRINTF(...) printf(__VA_ARGS__)
46 #define PRINTF(...) do {} while (0)
51 rom_erase(
long nbytes, off_t offset)
55 if(nbytes % ROM_ERASE_UNIT_SIZE != 0) {
59 if(offset % ROM_ERASE_UNIT_SIZE != 0) {
63 PRINTF(
"rom_erase(%ld, %06lx)\n", nbytes, offset);
70 boot_page_erase(offset);
77 nbytes -= ROM_ERASE_UNIT_SIZE;
78 offset += ROM_ERASE_UNIT_SIZE;
85 rom_pread(
void *buf,
int nbytes, off_t offset)
87 PRINTF(
"rom_pread(%p, %d, %06lx)\n", buf, nbytes, offset);
89 assert(offset == (uintptr_t)offset);
90 assert((offset + nbytes) == (uintptr_t)(offset + nbytes));
91 memcpy_P(buf, (PGM_P)(uintptr_t)offset, nbytes);
97 rom_pwrite(
const void *buf,
int nbytes, off_t offset)
100 const unsigned char *from = buf;
102 PRINTF(
"rom_pwrite(%p, %d, %06lx)\n", buf, nbytes, offset);
105 int i, n = (nbytes > ROM_ERASE_UNIT_SIZE) ? ROM_ERASE_UNIT_SIZE : nbytes;
110 for (i = 0; i < n; i += 2) {
111 uint16_t w = *from++;
113 boot_page_fill(offset + i, w);
115 boot_page_write(offset);
116 boot_spm_busy_wait();
122 nbytes -= ROM_ERASE_UNIT_SIZE;
123 offset += ROM_ERASE_UNIT_SIZE;