summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2015-05-26 13:37:49 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2015-05-26 14:33:18 +0200
commit8fba554f888493103d104c1acceca449a0a105ed (patch)
treef61a12bfa3dbb63477d66e56d25790f1c03334cf
parent20fc5623a3e52313e8cada72c196a83571155797 (diff)
downloadbarebox-8fba554f888493103d104c1acceca449a0a105ed.tar.gz
barebox-8fba554f888493103d104c1acceca449a0a105ed.tar.xz
state: backend_raw: properly align write and erase size
This patch makes it easier to share the code with linux, on Linux the ease and write size have to be aligned. Use stride (which is already aligned to erase block size) during erase, align size_full to writesize and use it while writing. Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--common/state.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/common/state.c b/common/state.c
index fb2e3e0022..dd921e7c56 100644
--- a/common/state.c
+++ b/common/state.c
@@ -1150,7 +1150,7 @@ static int backend_raw_write_one(struct state_backend_raw *backend_raw,
return ret;
if (backend_raw->need_erase) {
- ret = erase(fd, backend_raw->size_full, offset);
+ ret = erase(fd, backend_raw->stride, offset);
if (ret)
return ret;
}
@@ -1167,14 +1167,12 @@ static int state_backend_raw_save(struct state_backend *backend,
{
struct state_backend_raw *backend_raw = container_of(backend,
struct state_backend_raw, backend);
- int ret = 0, size, fd, i;
+ int ret = 0, fd, i;
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);
@@ -1198,14 +1196,14 @@ static int state_backend_raw_save(struct state_backend *backend,
continue;
ret = backend_raw_write_one(backend_raw, state, fd,
- i, buf, size);
+ i, 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;
@@ -1277,6 +1275,8 @@ int state_backend_raw_file(struct state *state, const char *of_path,
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->stride = ALIGN(backend_raw->size_full,
meminfo.erasesize);
dev_dbg(&state->dev, "is a mtd, adjust stepsize to %ld\n",