diff --git a/control.c b/control.c index a02b1196eb7007ef089e338f9450a753021e3e84..acca924f99e797ff1bd1a3b1a3dfc995e3868641 100644 --- a/control.c +++ b/control.c @@ -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 */ diff --git a/lpc.c b/lpc.c index 3dc761abe4ee44ea23fcc5c0433e6671306ccdf3..f3f999ff6ecacde35177614afd82a35554e5c492 100644 --- a/lpc.c +++ b/lpc.c @@ -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); } /* diff --git a/mboxd.c b/mboxd.c index d0c44908534bbd4a4de965498f7e477d5c991528..a7b2283244b1636e504b474f83954cbbeae54a78 100644 --- a/mboxd.c +++ b/mboxd.c @@ -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); diff --git a/mboxd.h b/mboxd.h index e046785503b97a1ffa7ef31ea021fca53f07fe21..7930242b67b60c0c9365d5d7da22e7e87cf2f4ae 100644 --- a/mboxd.h +++ b/mboxd.h @@ -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 */ diff --git a/test/flash_copy.c b/test/flash_copy.c index 472315b26cd3a3cf06532aeb8af6bb21dcecf750..9300cffcf5ac5324122fb1c9fd267a334076efe4 100644 --- a/test/flash_copy.c +++ b/test/flash_copy.c @@ -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); diff --git a/test/flash_erase.c b/test/flash_erase.c index ad4e535b7d9c82e84550f2e24dbbc7285d6c531b..fe80f3b7fd0b4dcac2b5ee65bf9f047c62640573 100644 --- a/test/flash_erase.c +++ b/test/flash_erase.c @@ -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); diff --git a/test/flash_write.c b/test/flash_write.c index 168b2aa2ad7618da73910f1209db906fb11bdf87..c5f998c9586314a72bc7d21ecc473261d308da5a 100644 --- a/test/flash_write.c +++ b/test/flash_write.c @@ -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); diff --git a/vpnor/test/write_patch.cpp b/vpnor/test/write_patch.cpp index 4f59db5c9cc8fd86bbd162eb2f46aadf01485a36..4a200c07f35c76d05ae55fdcbdd7cbde061b551c 100644 --- a/vpnor/test/write_patch.cpp +++ b/vpnor/test/write_patch.cpp @@ -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 */ diff --git a/vpnor/test/write_patch_resize.cpp b/vpnor/test/write_patch_resize.cpp index ce128c82a753752aa4b10b97a2c37945d0a2c612..38effd63800aa97b898ad146163dadc99deae73d 100644 --- a/vpnor/test/write_patch_resize.cpp +++ b/vpnor/test/write_patch_resize.cpp @@ -56,7 +56,7 @@ int main(void) /* Test */ std::vector 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 */ diff --git a/vpnor/test/write_prsv.cpp b/vpnor/test/write_prsv.cpp index 9ee1fb3852f28ed51248fabad41477cb7744f89f..134a98e016392c2860d5952168b5a5a7475bf177 100644 --- a/vpnor/test/write_prsv.cpp +++ b/vpnor/test/write_prsv.cpp @@ -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 */ diff --git a/vpnor/test/write_ro.cpp b/vpnor/test/write_ro.cpp index e6bedd35c390b704a6b8c30b0dcc1d0b337ba40a..5965ebfa35f0014956b8027b08e52e7906d7d448 100644 --- a/vpnor/test/write_ro.cpp +++ b/vpnor/test/write_ro.cpp @@ -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); diff --git a/vpnor/test/write_rw.cpp b/vpnor/test/write_rw.cpp index 3b742a11a3a8a4fc0b620ed54b73d72ad18dc036..cf9bf7b26847c08c32056e71be463bd4e0f0f59e 100644 --- a/vpnor/test/write_rw.cpp +++ b/vpnor/test/write_rw.cpp @@ -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 */ diff --git a/windows.c b/windows.c index 8f9fb022b8e103afdec007a1385181558aac06cc..ebe16c1f0e7b1ae4718cb18aa09692240bd5de65 100644 --- a/windows.c +++ b/windows.c @@ -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);