diff --git a/src/barebox-state.c b/src/barebox-state.c index 61f8a2d..3e3cb41 100644 --- a/src/barebox-state.c +++ b/src/barebox-state.c @@ -1097,7 +1097,7 @@ return ret; if (backend_raw->need_erase) { - ret = erase(fd, backend_raw->size_full, offset); + ret = erase(fd, backend_raw->step, offset); if (ret) return ret; } @@ -1114,14 +1114,12 @@ { struct state_backend_raw *backend_raw = container_of(backend, struct state_backend_raw, backend); - int ret = 0, size, fd; + int ret = 0, fd; void *buf, *data; struct backend_raw_header *header; struct state_variable *sv; - size = backend_raw->size_data + sizeof(struct backend_raw_header); - - buf = xzalloc(size); + buf = xzalloc(backend_raw->size_full); header = buf; data = buf + sizeof(*header); @@ -1140,12 +1138,12 @@ goto out_free; ret = backend_raw_write_one(backend_raw, state, fd, - !backend_raw->num_copy_read, buf, size); + !backend_raw->num_copy_read, buf, backend_raw->size_full); if (ret) goto out_close; ret = backend_raw_write_one(backend_raw, state, fd, - backend_raw->num_copy_read, buf, size); + backend_raw->num_copy_read, buf, backend_raw->size_full); if (ret) goto out_close; @@ -1216,6 +1214,8 @@ ret = mtd_get_meminfo(backend->path, &meminfo); if (!ret && !(meminfo.flags & MTD_NO_ERASE)) { backend_raw->need_erase = true; + backend_raw->size_full = ALIGN(backend_raw->size_full, + meminfo.writesize); backend_raw->step = ALIGN(backend_raw->size_full, meminfo.erasesize); dev_dbg(&state->dev, "is a mtd, adjust stepsize to %ld\n",