summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepak Kodihalli <dkodihal@in.ibm.com>2017-07-12 03:41:08 -0500
committerPatrick Williams <patrick@stwcx.xyz>2017-07-19 23:00:12 +0000
commit7ee307c7e88ba0c1aae1791e95c2573c6b1e62cb (patch)
treee29fdfef5456cbad240bfd6001e61241bf5cacdc
parent017e45c3f202116ad09d5abdcaeb88f5b5f52594 (diff)
downloadphosphor-mboxd-7ee307c7e88ba0c1aae1791e95c2573c6b1e62cb.tar.gz
phosphor-mboxd-7ee307c7e88ba0c1aae1791e95c2573c6b1e62cb.zip
copy_flash: update window size
When a pnor partition is copied to a window, update the window size with the actual number of blocks copied. This is required in the response of the V2 Read Window Command. Change-Id: I2c158df1bd261a4e62b9cbb2765e7623a7fb3dc9 Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
-rw-r--r--mboxd_flash.h4
-rw-r--r--mboxd_flash_physical.c12
-rw-r--r--mboxd_flash_virtual.cpp17
-rw-r--r--mboxd_pnor_partition_table.cpp5
-rw-r--r--mboxd_windows.c2
5 files changed, 22 insertions, 18 deletions
diff --git a/mboxd_flash.h b/mboxd_flash.h
index d8b0d0d..7c02445 100644
--- a/mboxd_flash.h
+++ b/mboxd_flash.h
@@ -29,8 +29,8 @@ extern "C" {
int init_flash_dev(struct mbox_context *context);
void free_flash_dev(struct mbox_context *context);
-int copy_flash(struct mbox_context *context, uint32_t offset, void *mem,
- uint32_t size);
+int64_t copy_flash(struct mbox_context *context, uint32_t offset, void *mem,
+ uint32_t size);
int set_flash_bytemap(struct mbox_context *context, uint32_t offset,
uint32_t count, uint8_t val);
int erase_flash(struct mbox_context *context, uint32_t offset, uint32_t count);
diff --git a/mboxd_flash_physical.c b/mboxd_flash_physical.c
index 55624d9..69d2f3c 100644
--- a/mboxd_flash_physical.c
+++ b/mboxd_flash_physical.c
@@ -240,13 +240,15 @@ int erase_flash(struct mbox_context *context, uint32_t offset, uint32_t count)
* @offset: The flash offset to copy from (bytes)
* @mem: The buffer to copy into (must be of atleast 'size' bytes)
* @size: The number of bytes to copy
- *
- * Return: 0 on success otherwise negative error code
+ * Return: Number of bytes copied on success, otherwise negative error
+ * code. copy_flash will copy at most 'size' bytes, but it may
+ * copy less.
*/
-int copy_flash(struct mbox_context *context, uint32_t offset, void *mem,
- uint32_t size)
+int64_t copy_flash(struct mbox_context *context, uint32_t offset, void *mem,
+ uint32_t size)
{
int32_t size_read;
+ void *start = mem;
MSG_DBG("Copy flash to %p for size 0x%.8x from offset 0x%.8x\n",
mem, size, offset);
@@ -269,7 +271,7 @@ int copy_flash(struct mbox_context *context, uint32_t offset, void *mem,
mem += size_read;
} while (size && size_read);
- return size ? -MBOX_R_SYSTEM_ERROR : 0;
+ return size_read ? mem - start : -MBOX_R_SYSTEM_ERROR;
}
/*
diff --git a/mboxd_flash_virtual.cpp b/mboxd_flash_virtual.cpp
index 6e3af71..182278b 100644
--- a/mboxd_flash_virtual.cpp
+++ b/mboxd_flash_virtual.cpp
@@ -24,6 +24,7 @@
#include <sys/mman.h>
#include <unistd.h>
#include <sys/ioctl.h>
+#include <algorithm>
extern "C" {
#include "common.h"
@@ -124,17 +125,18 @@ int erase_flash(struct mbox_context *context, uint32_t offset, uint32_t count)
* @offset: The pnor offset to copy from (bytes)
* @mem: The buffer to copy into (must be of atleast 'size' bytes)
* @size: The number of bytes to copy
- *
- * Return: 0 on success otherwise negative error code
+ * Return: Number of bytes copied on success, otherwise negative error
+ * code. copy_flash will copy at most 'size' bytes, but it may
+ * copy less.
*/
-int copy_flash(struct mbox_context* context, uint32_t offset, void* mem,
- uint32_t size)
+int64_t copy_flash(struct mbox_context* context, uint32_t offset, void* mem,
+ uint32_t size)
{
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
using namespace std::string_literals;
- int rc = 0;
+ int rc = size;
MSG_DBG("Copy virtual pnor to %p for size 0x%.8x from offset 0x%.8x\n",
mem, size, offset);
@@ -151,9 +153,8 @@ int copy_flash(struct mbox_context* context, uint32_t offset, void* mem,
{
const struct pnor_partition_table* table =
vpnor_get_partition_table(context);
- memcpy(mem,
- ((uint8_t*)table) + offset,
- min_u32(sz - offset, size));
+ rc = std::min(sz - offset, static_cast<size_t>(size));
+ memcpy(mem, ((uint8_t*)table) + offset, rc);
}
else
{
diff --git a/mboxd_pnor_partition_table.cpp b/mboxd_pnor_partition_table.cpp
index d2fdba3..60066f5 100644
--- a/mboxd_pnor_partition_table.cpp
+++ b/mboxd_pnor_partition_table.cpp
@@ -85,13 +85,14 @@ void vpnor_copy_bootloader_partition(const struct mbox_context *context)
memcpy(&local.paths, &context->paths, sizeof(local.paths));
size_t tocOffset = 0;
+ uint32_t tocSize = blTable.size() * eraseSize;
// Copy TOC
copy_flash(&local, tocOffset,
static_cast<uint8_t*>(context->mem) + tocStart,
- blTable.size() * eraseSize);
+ tocSize);
const pnor_partition& partition = blTable.partition(blPartitionName);
size_t hbbOffset = partition.data.base * eraseSize;
- size_t hbbSize = partition.data.actual;
+ uint32_t hbbSize = partition.data.actual;
// Copy HBB
copy_flash(&local, hbbOffset,
static_cast<uint8_t*>(context->mem) + hbbOffset, hbbSize);
diff --git a/mboxd_windows.c b/mboxd_windows.c
index 451ecd1..1755c4a 100644
--- a/mboxd_windows.c
+++ b/mboxd_windows.c
@@ -417,7 +417,6 @@ void close_current_window(struct mbox_context *context, bool set_bmc_event,
context->current->age = 0;
}
- context->current->size = context->windows.default_size;
context->current = NULL;
context->current_is_write = false;
}
@@ -627,6 +626,7 @@ int create_map_window(struct mbox_context *context,
reset_window(context, cur);
return rc;
}
+ cur->size = rc;
/*
* Since for V1 windows aren't constrained to start at multiples of
OpenPOWER on IntegriCloud