Fix flash buffer alignment in target layer.
This commit is contained in:
parent
7202db5860
commit
36f749fed9
@ -131,6 +131,8 @@ struct target_flash {
|
|||||||
flash_done_func done;
|
flash_done_func done;
|
||||||
target *t;
|
target *t;
|
||||||
struct target_flash *next;
|
struct target_flash *next;
|
||||||
|
int align;
|
||||||
|
uint8_t erased;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct target_s {
|
struct target_s {
|
||||||
|
10
src/target.c
10
src/target.c
@ -189,7 +189,15 @@ int target_flash_write(target *t,
|
|||||||
while (len) {
|
while (len) {
|
||||||
struct target_flash *f = flash_for_addr(t, dest);
|
struct target_flash *f = flash_for_addr(t, dest);
|
||||||
size_t tmplen = MIN(len, f->length - (dest % f->length));
|
size_t tmplen = MIN(len, f->length - (dest % f->length));
|
||||||
ret |= f->write(f, dest, src, tmplen);
|
if (f->align > 1) {
|
||||||
|
uint32_t offset = dest % f->align;
|
||||||
|
uint8_t data[ALIGN(offset + len, f->align)];
|
||||||
|
memset(data, f->erased, sizeof(data));
|
||||||
|
memcpy((uint8_t *)data + offset, src, len);
|
||||||
|
ret |= f->write(f, dest - offset, data, sizeof(data));
|
||||||
|
} else {
|
||||||
|
ret |= f->write(f, dest, src, tmplen);
|
||||||
|
}
|
||||||
src += tmplen;
|
src += tmplen;
|
||||||
len -= tmplen;
|
len -= tmplen;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user