summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Jeffery <andrew@aj.id.au>2018-02-28 22:20:19 +1030
committerAndrew Jeffery <andrew@aj.id.au>2018-03-24 13:59:32 +1030
commitfc62158caeaef009cd0055ce8cc35586581840b8 (patch)
treeb7197eb066ea71dc71addda7045785953c734ae1
parent730e3b0409894112d1984fb26e2cfacf886f983c (diff)
downloadphosphor-mboxd-fc62158caeaef009cd0055ce8cc35586581840b8.zip
phosphor-mboxd-fc62158caeaef009cd0055ce8cc35586581840b8.tar.gz
mboxd_flash_virtual: Remove dependence on vpnor_get_partition_table_size
Change-Id: Ide8012846732649780a8989c8040bece8ffdf272 Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
-rw-r--r--mboxd_flash_virtual.cpp68
1 files changed, 37 insertions, 31 deletions
diff --git a/mboxd_flash_virtual.cpp b/mboxd_flash_virtual.cpp
index 42d4ee6..1561396 100644
--- a/mboxd_flash_virtual.cpp
+++ b/mboxd_flash_virtual.cpp
@@ -123,8 +123,17 @@ int64_t copy_flash(struct mbox_context* context, uint32_t offset, void* mem,
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
using namespace std::string_literals;
+ vpnor::partition::Table* table;
int rc = size;
+ if (!(context && context->vpnor && context->vpnor->table))
+ {
+ MSG_ERR("Trying to copy data with uninitialised context!\n");
+ return -MBOX_R_SYSTEM_ERROR;
+ }
+
+ table = context->vpnor->table;
+
MSG_DBG("Copy virtual pnor to %p for size 0x%.8x from offset 0x%.8x\n", mem,
size, offset);
@@ -132,44 +141,41 @@ int64_t copy_flash(struct mbox_context* context, uint32_t offset, void* mem,
* pnor image. Check if host asked for an offset that lies within the
* partition table.
*/
+ size_t sz = table->size();
+ if (offset < sz)
+ {
+ const pnor_partition_table& toc = table->getHostTable();
+ rc = std::min(sz - offset, static_cast<size_t>(size));
+ memcpy(mem, ((uint8_t*)&toc) + offset, rc);
+ return rc;
+ }
+
try
{
- size_t sz = vpnor_get_partition_table_size(context)
- << context->block_size_shift;
- if (offset < sz)
- {
- const struct pnor_partition_table* table =
- vpnor_get_partition_table(context);
- rc = std::min(sz - offset, static_cast<size_t>(size));
- memcpy(mem, ((uint8_t*)table) + offset, rc);
- }
- else
- {
- openpower::virtual_pnor::RORequest roRequest;
- auto partitionInfo = roRequest.getPartitionInfo(context, offset);
+ openpower::virtual_pnor::RORequest roRequest;
+ auto partitionInfo = roRequest.getPartitionInfo(context, offset);
- auto mapped_mem = mmap(NULL, partitionInfo->data.actual, PROT_READ,
- MAP_PRIVATE, roRequest.fd(), 0);
+ auto mapped_mem = mmap(NULL, partitionInfo->data.actual, PROT_READ,
+ MAP_PRIVATE, roRequest.fd(), 0);
- if (mapped_mem == MAP_FAILED)
- {
- MSG_ERR("Failed to map partition=%s:Error=%s\n",
- partitionInfo->data.name, strerror(errno));
+ if (mapped_mem == MAP_FAILED)
+ {
+ MSG_ERR("Failed to map partition=%s:Error=%s\n",
+ partitionInfo->data.name, strerror(errno));
- elog<InternalFailure>();
- }
+ elog<InternalFailure>();
+ }
- // if the asked offset + no of bytes to read is greater
- // then size of the partition file then throw error.
+ // if the asked offset + no of bytes to read is greater
+ // then size of the partition file then throw error.
- uint32_t baseOffset = partitionInfo->data.base
- << context->block_size_shift;
- // copy to the reserved memory area
- auto diffOffset = offset - baseOffset;
- rc = std::min(partitionInfo->data.actual - diffOffset, size);
- memcpy(mem, (char*)mapped_mem + diffOffset, rc);
- munmap(mapped_mem, partitionInfo->data.actual);
- }
+ uint32_t baseOffset = partitionInfo->data.base
+ << context->block_size_shift;
+ // copy to the reserved memory area
+ auto diffOffset = offset - baseOffset;
+ rc = std::min(partitionInfo->data.actual - diffOffset, size);
+ memcpy(mem, (char*)mapped_mem + diffOffset, rc);
+ munmap(mapped_mem, partitionInfo->data.actual);
}
catch (vpnor::UnmappedOffset& e)
{
OpenPOWER on IntegriCloud