Commit 0297e5b8 authored by Andrew Jeffery's avatar Andrew Jeffery

mboxd: Remove flash API compatibility shim

The flash API compatibility was kept to reduce the line noise in the
previous backend patch. Remove the compatibility layer now and convert
the remaining call-sites.

Change-Id: I4b6e54f4463059a7804918add81e7572db7b7c21
Signed-off-by: Andrew Jeffery's avatarAndrew Jeffery <andrew@aj.id.au>
parent f1e547c7
......@@ -62,7 +62,7 @@ int control_kill(struct mbox_context *context)
int control_modified(struct mbox_context *context)
{
/* Flash has been modified - can no longer trust our erased bytemap */
flash_set_bytemap(context, 0, context->backend.flash_size,
backend_set_bytemap(&context->backend, 0, context->backend.flash_size,
FLASH_DIRTY);
/* Force daemon to reload all windows -> Set BMC event to notify host */
......
......@@ -138,8 +138,8 @@ int lpc_map_flash(struct mbox_context *context)
* Since the host now has access to the flash it can change it out from
* under us
*/
return flash_set_bytemap(context, 0, context->backend.flash_size,
FLASH_DIRTY);
return backend_set_bytemap(&context->backend, 0,
context->backend.flash_size, FLASH_DIRTY);
}
/*
......
......@@ -437,9 +437,6 @@ finish:
protocol_events_put(context, mbox_ops);
protocol_events_put(context, dbus_ops);
#ifdef VIRTUAL_PNOR_ENABLED
vpnor_destroy(&context->backend);
#endif
dbus_free(context);
backend_free(&context->backend);
lpc_dev_free(context);
......
......@@ -103,30 +103,4 @@ struct mbox_context {
uint32_t lpc_base;
};
/* Temporary flash API compatibility */
static inline int64_t flash_copy(struct mbox_context *context, uint32_t offset,
void *mem, uint32_t size)
{
return backend_copy(&context->backend, offset, mem, size);
}
static inline int flash_set_bytemap(struct mbox_context *context,
uint32_t offset, uint32_t count,
uint8_t val)
{
return backend_set_bytemap(&context->backend, offset, count, val);
}
static inline int flash_erase(struct mbox_context *context, uint32_t offset,
uint32_t count)
{
return backend_erase(&context->backend, offset, count);
}
static inline int flash_write(struct mbox_context *context, uint32_t offset,
void *buf, uint32_t count)
{
return backend_write(&context->backend, offset, buf, count);
}
#endif /* MBOX_H */
......@@ -71,7 +71,7 @@ int main(void)
assert(!backend_probe_mtd(&context.backend, tmp.path));
flash_copy(&context, 0, dst, TEST_SIZE);
backend_copy(&context.backend, 0, dst, TEST_SIZE);
assert(0 == memcmp(src, dst, TEST_SIZE));
backend_free(&context.backend);
......
......@@ -117,7 +117,7 @@ int main(void)
assert(!backend_probe_mtd(backend, get_dev_mtd()));
/* Erase from an unknown state */
rc = flash_erase(&context, 0, sizeof(data));
rc = backend_erase(backend, 0, sizeof(data));
assert(rc == 0);
assert(n_ioctls == 1);
......@@ -129,7 +129,7 @@ int main(void)
n_ioctls = 0;
/* Erase an erased flash */
rc = flash_erase(&context, 0, sizeof(data));
rc = backend_erase(backend, 0, sizeof(data));
assert(rc == 0);
assert(n_ioctls == 0);
......@@ -137,9 +137,9 @@ int main(void)
memset(data, 0xaa, sizeof(data));
/* Erase written flash */
rc = flash_write(&context, 0, data, sizeof(data));
rc = backend_write(backend, 0, data, sizeof(data));
assert(rc == 0);
rc = flash_erase(&context, 0, sizeof(data));
rc = backend_erase(backend, 0, sizeof(data));
assert(rc == 0);
assert(n_ioctls == 1);
......@@ -151,9 +151,9 @@ int main(void)
n_ioctls = 0;
/* Erase the start of flash */
rc = flash_write(&context, 0, data, sizeof(data) - 1);
rc = backend_write(backend, 0, data, sizeof(data) - 1);
assert(rc == 0);
rc = flash_erase(&context, 0, sizeof(data));
rc = backend_erase(backend, 0, sizeof(data));
assert(rc == 0);
assert(n_ioctls == 1);
......@@ -165,9 +165,9 @@ int main(void)
n_ioctls = 0;
/* Erase the end of flash */
rc = flash_write(&context, 1, data, sizeof(data) - 1);
rc = backend_write(backend, 1, data, sizeof(data) - 1);
assert(rc == 0);
rc = flash_erase(&context, 0, sizeof(data));
rc = backend_erase(backend, 0, sizeof(data));
assert(rc == 0);
assert(n_ioctls == 1);
......@@ -179,10 +179,10 @@ int main(void)
n_ioctls = 0;
/* Erase each end of flash */
rc = flash_write(&context, 0, data, 1);
rc = flash_write(&context, 2, data, 1);
rc = backend_write(backend, 0, data, 1);
rc = backend_write(backend, 2, data, 1);
assert(rc == 0);
rc = flash_erase(&context, 0, sizeof(data));
rc = backend_erase(backend, 0, sizeof(data));
assert(rc == 0);
assert(n_ioctls == 2);
......@@ -196,9 +196,9 @@ int main(void)
n_ioctls = 0;
/* Erase the middle of flash */
rc = flash_write(&context, 1, data, 1);
rc = backend_write(backend, 1, data, 1);
assert(rc == 0);
rc = flash_erase(&context, 0, sizeof(data));
rc = backend_erase(backend, 0, sizeof(data));
assert(rc == 0);
assert(n_ioctls == 1);
......
......@@ -74,31 +74,31 @@ int main(void)
assert(map != MAP_FAILED);
memset(src, 0xaa, sizeof(src));
rc = flash_write(context, 0, src, sizeof(src));
rc = backend_write(backend, 0, src, sizeof(src));
assert(rc == 0);
rc = memcmp(src, map, sizeof(src));
assert(rc == 0);
memset(src, 0x55, sizeof(src));
rc = flash_write(context, 0, src, sizeof(src));
rc = backend_write(backend, 0, src, sizeof(src));
assert(rc == 0);
rc = memcmp(src, map, sizeof(src));
assert(rc == 0);
src[0] = 0xff;
rc = flash_write(context, 0, src, 1);
rc = backend_write(backend, 0, src, 1);
assert(rc == 0);
rc = memcmp(src, map, sizeof(src));
assert(rc == 0);
src[1] = 0xff;
rc = flash_write(context, 1, &src[1], 1);
rc = backend_write(backend, 1, &src[1], 1);
assert(rc == 0);
rc = memcmp(src, map, sizeof(src));
assert(rc == 0);
src[2] = 0xff;
rc = flash_write(context, 2, &src[2], 1);
rc = backend_write(backend, 2, &src[2], 1);
assert(rc == 0);
rc = memcmp(src, map, sizeof(src));
assert(rc == 0);
......
......@@ -57,7 +57,7 @@ int main(void)
/* Test */
memset(src, 0x33, sizeof(src));
rc = flash_write(ctx, 0x1000, src, sizeof(src));
rc = backend_write(&ctx->backend, 0x1000, src, sizeof(src));
assert(rc == 0);
/* Check that RW file is unmodified after the patch write */
......
......@@ -56,7 +56,7 @@ int main(void)
/* Test */
std::vector<uint8_t> update(UPDATE_SIZE, 0x55);
rc = flash_write(ctx, 0x1000, update.data(), update.size());
rc = backend_write(&ctx->backend, 0x1000, update.data(), update.size());
assert(rc == 0);
/* Check that PATCH is modified with the new data */
......
......@@ -46,7 +46,7 @@ int main(void)
/* Test */
memset(src, 0xaa, sizeof(src));
rc = flash_write(ctx, 0x1000, src, sizeof(src));
rc = backend_write(&ctx->backend, 0x1000, src, sizeof(src));
assert(rc == 0);
/* Verify */
......
......@@ -43,7 +43,7 @@ int main(void)
test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE);
/* Test */
rc = flash_write(ctx, 0x1000, src, sizeof(src));
rc = backend_write(&ctx->backend, 0x1000, src, sizeof(src));
/* Verify we can't write to RO partitions */
assert(rc != 0);
......
......@@ -48,7 +48,7 @@ int main(void)
/* Test */
memset(src, 0xbb, sizeof(src));
rc = flash_write(ctx, 0x1000, src, sizeof(src));
rc = backend_write(&ctx->backend, 0x1000, src, sizeof(src));
assert(rc == 0);
fd = open((root.rw() / "TEST1").c_str(), O_RDONLY);
map = mmap(NULL, sizeof(src), PROT_READ, MAP_SHARED, fd, 0);
......@@ -58,31 +58,31 @@ int main(void)
/* Ensure single byte writes function */
memset(src, 0xcc, sizeof(src));
rc = flash_write(ctx, 0x1000, src, sizeof(src));
rc = backend_write(&ctx->backend, 0x1000, src, sizeof(src));
assert(rc == 0);
rc = memcmp(src, map, sizeof(src));
assert(rc == 0);
src[0] = 0xff;
rc = flash_write(ctx, 0x1000, src, 1);
rc = backend_write(&ctx->backend, 0x1000, src, 1);
assert(rc == 0);
rc = memcmp(src, map, sizeof(src));
assert(rc == 0);
src[1] = 0xff;
rc = flash_write(ctx, 0x1000 + 1, &src[1], 1);
rc = backend_write(&ctx->backend, 0x1000 + 1, &src[1], 1);
assert(rc == 0);
rc = memcmp(src, map, sizeof(src));
assert(rc == 0);
src[2] = 0xff;
rc = flash_write(ctx, 0x1000 + 2, &src[2], 1);
rc = backend_write(&ctx->backend, 0x1000 + 2, &src[2], 1);
assert(rc == 0);
rc = memcmp(src, map, sizeof(src));
assert(rc == 0);
/* Writes past the end of the partition should fail */
rc = flash_write(ctx, 0x1000 + 0xff9, src, sizeof(src));
rc = backend_write(&ctx->backend, 0x1000 + 0xff9, src, sizeof(src));
assert(rc < 0);
/* Check that RW file is unmodified after the bad write */
......
......@@ -191,8 +191,8 @@ int window_flush_v1(struct mbox_context *context,
MSG_ERR("Unable to allocate memory\n");
return -ENOMEM;
}
rc = flash_copy(context, low_mem.flash_offset,
low_mem.mem, low_mem.size);
rc = backend_copy(&context->backend, low_mem.flash_offset,
low_mem.mem, low_mem.size);
if (rc < 0) {
goto out;
}
......@@ -206,8 +206,8 @@ int window_flush_v1(struct mbox_context *context,
rc = -ENOMEM;
goto out;
}
rc = flash_copy(context, high_mem.flash_offset,
high_mem.mem, high_mem.size);
rc = backend_copy(&context->backend, high_mem.flash_offset,
high_mem.mem, high_mem.size);
if (rc < 0) {
goto out;
}
......@@ -217,9 +217,9 @@ int window_flush_v1(struct mbox_context *context,
* We need to erase the flash from low_mem.flash_offset->
* high_mem.flash_offset + high_mem.size
*/
rc = flash_erase(context, low_mem.flash_offset,
(high_mem.flash_offset - low_mem.flash_offset) +
high_mem.size);
rc = backend_erase(&context->backend, low_mem.flash_offset,
(high_mem.flash_offset - low_mem.flash_offset) +
high_mem.size);
if (rc < 0) {
MSG_ERR("Couldn't erase flash\n");
goto out;
......@@ -228,13 +228,13 @@ int window_flush_v1(struct mbox_context *context,
/* Write back over the erased area */
if (low_mem.mem) {
/* Exceed window at the start */
rc = flash_write(context, low_mem.flash_offset, low_mem.mem,
low_mem.size);
rc = backend_write(&context->backend, low_mem.flash_offset,
low_mem.mem, low_mem.size);
if (rc < 0) {
goto out;
}
}
rc = flash_write(context, flash_offset,
rc = backend_write(&context->backend, flash_offset,
context->current->mem + offset_bytes, count_bytes);
if (rc < 0) {
goto out;
......@@ -245,16 +245,16 @@ int window_flush_v1(struct mbox_context *context,
*/
if (high_mem.mem) {
/* Exceed window at the end */
rc = flash_write(context, high_mem.flash_offset, high_mem.mem,
high_mem.size);
rc = backend_write(&context->backend, high_mem.flash_offset,
high_mem.mem, high_mem.size);
if (rc < 0) {
goto out;
}
} else {
/* Write from the current window - it's atleast that big */
rc = flash_write(context, high_mem.flash_offset,
context->current->mem + offset_bytes +
count_bytes, high_mem.size);
rc = backend_write(&context->backend, high_mem.flash_offset,
context->current->mem + offset_bytes +
count_bytes, high_mem.size);
if (rc < 0) {
goto out;
}
......@@ -285,7 +285,8 @@ int window_flush(struct mbox_context *context, uint32_t offset,
switch (type) {
case WINDOW_ERASED: /* >= V2 ONLY -> block_size == erasesize */
flash_offset = context->current->flash_offset + offset_bytes;
rc = flash_erase(context, flash_offset, count_bytes);
rc = backend_erase(&context->backend, flash_offset,
count_bytes);
if (rc < 0) {
MSG_ERR("Couldn't erase flash\n");
return rc;
......@@ -305,15 +306,16 @@ int window_flush(struct mbox_context *context, uint32_t offset,
flash_offset = context->current->flash_offset + offset_bytes;
/* Erase the flash */
rc = flash_erase(context, flash_offset, count_bytes);
rc = backend_erase(&context->backend, flash_offset,
count_bytes);
if (rc < 0) {
return rc;
}
/* Write to the erased flash */
rc = flash_write(context, flash_offset,
context->current->mem + offset_bytes,
count_bytes);
rc = backend_write(&context->backend, flash_offset,
context->current->mem + offset_bytes,
count_bytes);
if (rc < 0) {
return rc;
}
......@@ -620,7 +622,7 @@ int windows_create_map(struct mbox_context *context,
}
/* Copy from flash into the window buffer */
rc = flash_copy(context, offset, cur->mem, cur->size);
rc = backend_copy(&context->backend, offset, cur->mem, cur->size);
if (rc < 0) {
/* We don't know how much we've copied -> better reset window */
window_reset(context, cur);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment