summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Jeffery <andrew@aj.id.au>2018-03-09 15:27:03 +1030
committerAndrew Jeffery <andrew@aj.id.au>2018-03-19 10:56:22 +1030
commitf34db31d768e38c3add58a83cd943609771fd212 (patch)
tree659f3f17e8405f5edd7000f251345f5c889d5a22
parent25eca77fabceb86e10ac4eb0cbe32484cbf21c14 (diff)
downloadphosphor-mboxd-f34db31d768e38c3add58a83cd943609771fd212.tar.gz
phosphor-mboxd-f34db31d768e38c3add58a83cd943609771fd212.zip
Format C++ files according to OpenBMC style guide
We don't touch the C yet as upstream hasn't got such a change in place. Change-Id: Ie6cab4bf99df520bb6655b9b00ae31e762e3c57b Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
-rw-r--r--.clang-format-c6
-rw-r--r--.clang-format-c++85
-rwxr-xr-xformat-code.sh34
-rw-r--r--mboxd_flash_virtual.cpp52
-rw-r--r--mboxd_pnor_partition_table.cpp52
-rw-r--r--pnor_partition.cpp67
-rw-r--r--pnor_partition.hpp213
-rw-r--r--pnor_partition_table.cpp50
-rw-r--r--pnor_partition_table.hpp329
-rw-r--r--test/create_pnor_partition_table.cpp8
-rw-r--r--test/create_read_window_vpnor.cpp44
-rw-r--r--test/write_flash_vpnor.cpp60
12 files changed, 546 insertions, 454 deletions
diff --git a/.clang-format-c b/.clang-format-c
new file mode 100644
index 0000000..a3ef233
--- /dev/null
+++ b/.clang-format-c
@@ -0,0 +1,6 @@
+BasedOnStyle: LLVM
+IndentWidth: 8
+UseTab: Always
+BreakBeforeBraces: Linux
+AllowShortIfStatementsOnASingleLine: false
+IndentCaseLabels: false
diff --git a/.clang-format-c++ b/.clang-format-c++
new file mode 100644
index 0000000..309a9d6
--- /dev/null
+++ b/.clang-format-c++
@@ -0,0 +1,85 @@
+---
+Language: Cpp
+# BasedOnStyle: LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: false
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: true
+ AfterControlStatement: true
+ AfterEnum: true
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: true
+ AfterStruct: true
+ AfterUnion: true
+ BeforeCatch: true
+ BeforeElse: true
+ IndentBraces: false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: AfterColon
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: true
+PointerAlignment: Left
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IndentCaseLabels: true
+IndentWidth: 4
+IndentWrappedFunctionNames: false
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Right
+ReflowComments: true
+SortIncludes: false
+SpaceAfterCStyleCast: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 4
+UseTab: Never
+...
+
diff --git a/format-code.sh b/format-code.sh
new file mode 100755
index 0000000..a824ad1
--- /dev/null
+++ b/format-code.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+set -euo
+
+set -x
+
+[ -f .clang-format ] && rm .clang-format
+
+CLANG_FORMAT="$(which clang-format-5.0)"
+
+# phosphor-mboxd is a fork of mboxbridge, the reference mbox daemon
+# implementation. mboxbridge is C written with the style of the Linux kernel.
+#
+# phosphor-mboxd extended the reference in C++, and used the OpenBMC C++ style.
+#
+# To remain compliant with the C++ style guide *and* preserve source
+# compatibility with the upstream reference implementation, use two separate
+# styles.
+#
+# Further, clang-format supports describing styles for multiple languages in
+# the one .clang-format file, but *doesn't* make a distinction between C and
+# C++. So we need two files. It gets worse: the -style parameter doesn't take
+# the path to a configuration file as an argument, you instead specify the
+# literal 'file' and it goes looking for a .clang-format or _clang-format file.
+# So now we need to symlink different files in place before calling
+# ${CLANG_FORMAT}. Everything is terrible.
+#
+# ln -sf .clang-format-c .clang-format
+# git ls-files | grep '\.[ch]$' | xargs "${CLANG_FORMAT}" -i -style=file
+
+ln -sf .clang-format-c++ .clang-format
+git ls-files | grep '\.[ch]pp$' | xargs "${CLANG_FORMAT}" -i -style=file
+
+rm .clang-format
diff --git a/mboxd_flash_virtual.cpp b/mboxd_flash_virtual.cpp
index 442593b..9575705 100644
--- a/mboxd_flash_virtual.cpp
+++ b/mboxd_flash_virtual.cpp
@@ -53,7 +53,7 @@ struct StringDeleter
};
using StringPtr = std::unique_ptr<char, StringDeleter>;
-int init_flash_dev(struct mbox_context *context)
+int init_flash_dev(struct mbox_context* context)
{
StringPtr filename(get_dev_mtd());
int fd = 0;
@@ -70,16 +70,15 @@ int init_flash_dev(struct mbox_context *context)
fd = open(filename.get(), O_RDWR);
if (fd < 0)
{
- MSG_ERR("Couldn't open %s with flags O_RDWR: %s\n",
- filename.get(), strerror(errno));
+ MSG_ERR("Couldn't open %s with flags O_RDWR: %s\n", filename.get(),
+ strerror(errno));
return -errno;
}
// Read the Flash Info
if (ioctl(fd, MEMGETINFO, &context->mtd_info) == -1)
{
- MSG_ERR("Couldn't get information about MTD: %s\n",
- strerror(errno));
+ MSG_ERR("Couldn't get information about MTD: %s\n", strerror(errno));
close(fd);
return -errno;
}
@@ -101,19 +100,19 @@ int init_flash_dev(struct mbox_context *context)
return rc;
}
-void free_flash_dev(struct mbox_context *context)
+void free_flash_dev(struct mbox_context* context)
{
// No-op
}
-int set_flash_bytemap(struct mbox_context *context, uint32_t offset,
+int set_flash_bytemap(struct mbox_context* context, uint32_t offset,
uint32_t count, uint8_t val)
{
// No-op
return 0;
}
-int erase_flash(struct mbox_context *context, uint32_t offset, uint32_t count)
+int erase_flash(struct mbox_context* context, uint32_t offset, uint32_t count)
{
// No-op
return 0;
@@ -138,8 +137,8 @@ int64_t copy_flash(struct mbox_context* context, uint32_t offset, void* mem,
int rc = size;
- MSG_DBG("Copy virtual pnor to %p for size 0x%.8x from offset 0x%.8x\n",
- mem, size, offset);
+ MSG_DBG("Copy virtual pnor to %p for size 0x%.8x from offset 0x%.8x\n", mem,
+ size, offset);
/* The virtual PNOR partition table starts at offset 0 in the virtual
* pnor image. Check if host asked for an offset that lies within the
@@ -147,8 +146,8 @@ int64_t copy_flash(struct mbox_context* context, uint32_t offset, void* mem,
*/
try
{
- size_t sz =
- vpnor_get_partition_table_size(context) << context->block_size_shift;
+ size_t sz = vpnor_get_partition_table_size(context)
+ << context->block_size_shift;
if (offset < sz)
{
const struct pnor_partition_table* table =
@@ -161,8 +160,8 @@ int64_t copy_flash(struct mbox_context* context, uint32_t offset, void* mem,
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)
{
@@ -175,11 +174,12 @@ int64_t copy_flash(struct mbox_context* context, uint32_t offset, void* mem,
// 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
+ 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);
+ memcpy(mem, (char*)mapped_mem + diffOffset, rc);
munmap(mapped_mem, partitionInfo->data.actual);
}
}
@@ -215,10 +215,9 @@ int write_flash(struct mbox_context* context, uint32_t offset, void* buf,
openpower::virtual_pnor::RWRequest rwRequest;
auto partitionInfo = rwRequest.getPartitionInfo(context, offset);
-
- auto mapped_mem = mmap(NULL, partitionInfo->data.actual,
- PROT_READ | PROT_WRITE,
- MAP_SHARED, rwRequest.fd(), 0);
+ auto mapped_mem =
+ mmap(NULL, partitionInfo->data.actual, PROT_READ | PROT_WRITE,
+ MAP_SHARED, rwRequest.fd(), 0);
if (mapped_mem == MAP_FAILED)
{
MSG_ERR("Failed to map partition=%s:Error=%s\n",
@@ -226,27 +225,28 @@ int write_flash(struct mbox_context* context, uint32_t offset, void* buf,
elog<InternalFailure>();
}
- //copy to the mapped memory.
+ // copy to the mapped memory.
- uint32_t baseOffset = partitionInfo->data.base << context->block_size_shift;
+ uint32_t baseOffset = partitionInfo->data.base
+ << context->block_size_shift;
// if the asked offset + no of bytes to write is greater
// then size of the partition file then throw error.
if ((offset + count) > (baseOffset + partitionInfo->data.actual))
{
MSG_ERR("Offset is beyond the partition file length[0x%.8x]\n",
- partitionInfo->data.actual);
+ partitionInfo->data.actual);
munmap(mapped_mem, partitionInfo->data.actual);
elog<InternalFailure>();
}
auto diffOffset = offset - baseOffset;
- memcpy((char*)mapped_mem + diffOffset , buf, count);
+ memcpy((char*)mapped_mem + diffOffset, buf, count);
munmap(mapped_mem, partitionInfo->data.actual);
set_flash_bytemap(context, offset, count, FLASH_DIRTY);
}
- catch (InternalFailure & e)
+ catch (InternalFailure& e)
{
rc = -1;
}
diff --git a/mboxd_pnor_partition_table.cpp b/mboxd_pnor_partition_table.cpp
index 4837aa3..3a09c92 100644
--- a/mboxd_pnor_partition_table.cpp
+++ b/mboxd_pnor_partition_table.cpp
@@ -10,7 +10,7 @@
struct vpnor_partition_table
{
- openpower::virtual_pnor::partition::Table* table = nullptr;
+ openpower::virtual_pnor::partition::Table *table = nullptr;
};
void init_vpnor(struct mbox_context *context)
@@ -23,10 +23,8 @@ void init_vpnor(struct mbox_context *context)
strcpy(context->paths.patch_loc, PARTITION_FILES_PATCH_LOC);
context->vpnor = new vpnor_partition_table;
- context->vpnor->table =
- new openpower::virtual_pnor::partition::Table(
- 1 << context->erase_size_shift,
- context->flash_size);
+ context->vpnor->table = new openpower::virtual_pnor::partition::Table(
+ 1 << context->erase_size_shift, context->flash_size);
}
}
@@ -38,33 +36,30 @@ void vpnor_create_partition_table_from_path(struct mbox_context *context,
if (context && !context->vpnor)
{
context->vpnor = new vpnor_partition_table;
- context->vpnor->table =
- new openpower::virtual_pnor::partition::Table(
- std::move(dir),
- 1 << context->erase_size_shift,
- context->flash_size);
+ context->vpnor->table = new openpower::virtual_pnor::partition::Table(
+ std::move(dir), 1 << context->erase_size_shift,
+ context->flash_size);
}
}
size_t vpnor_get_partition_table_size(const struct mbox_context *context)
{
- return context && context->vpnor ?
- context->vpnor->table->size() : 0;
+ return context && context->vpnor ? context->vpnor->table->size() : 0;
}
-const struct pnor_partition_table* vpnor_get_partition_table(
- const struct mbox_context *context)
+const struct pnor_partition_table *
+vpnor_get_partition_table(const struct mbox_context *context)
{
- return context && context->vpnor ?
- &(context->vpnor->table->getHostTable()) : nullptr;
+ return context && context->vpnor ? &(context->vpnor->table->getHostTable())
+ : nullptr;
}
-const struct pnor_partition* vpnor_get_partition(
- const struct mbox_context *context,
- const size_t offset)
+const struct pnor_partition *
+vpnor_get_partition(const struct mbox_context *context, const size_t offset)
{
- return context && context->vpnor ?
- &(context->vpnor->table->partition(offset)) : nullptr;
+ return context && context->vpnor
+ ? &(context->vpnor->table->partition(offset))
+ : nullptr;
}
void vpnor_copy_bootloader_partition(const struct mbox_context *context)
@@ -87,7 +82,9 @@ void vpnor_copy_bootloader_partition(const struct mbox_context *context)
openpower::virtual_pnor::partition::Table blTable(eraseSize, pnorSize);
vpnor_partition_table vtbl{};
vtbl.table = &blTable;
- struct mbox_context local{};
+ struct mbox_context local
+ {
+ };
local.vpnor = &vtbl;
local.block_size_shift = log_2(eraseSize);
memcpy(&local.paths, &context->paths, sizeof(local.paths));
@@ -100,16 +97,15 @@ void vpnor_copy_bootloader_partition(const struct mbox_context *context)
{
// Copy TOC
copy_flash(&local, tocOffset,
- static_cast<uint8_t*>(context->mem) + tocStart,
- tocSize);
- const pnor_partition& partition = blTable.partition(blPartitionName);
+ static_cast<uint8_t *>(context->mem) + tocStart, tocSize);
+ const pnor_partition &partition = blTable.partition(blPartitionName);
size_t hbbOffset = partition.data.base * eraseSize;
uint32_t hbbSize = partition.data.actual;
// Copy HBB
copy_flash(&local, hbbOffset,
- static_cast<uint8_t*>(context->mem) + hbbOffset, hbbSize);
+ static_cast<uint8_t *>(context->mem) + hbbOffset, hbbSize);
}
- catch (InternalFailure& e)
+ catch (InternalFailure &e)
{
commit<InternalFailure>();
}
@@ -117,7 +113,7 @@ void vpnor_copy_bootloader_partition(const struct mbox_context *context)
void destroy_vpnor(struct mbox_context *context)
{
- if(context && context->vpnor)
+ if (context && context->vpnor)
{
delete context->vpnor->table;
delete context->vpnor;
diff --git a/pnor_partition.cpp b/pnor_partition.cpp
index 52a1275..f8c5fa3 100644
--- a/pnor_partition.cpp
+++ b/pnor_partition.cpp
@@ -28,11 +28,9 @@ using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
using namespace std::string_literals;
-ReturnCode Request::open(const std::string& path,
- int mode)
+ReturnCode Request::open(const std::string& path, int mode)
{
- if (mode == O_RDWR &&
- partition->data.user.data[1] & PARTITION_READONLY)
+ if (mode == O_RDWR && partition->data.user.data[1] & PARTITION_READONLY)
{
MSG_ERR("Can't open the RO partition for write");
return ReturnCode::PARTITION_READ_ONLY;
@@ -63,10 +61,10 @@ std::string Request::getPartitionFilePath(struct mbox_context* context,
partition = vpnor_get_partition(context, offset);
if (!partition)
{
- MSG_ERR("Couldn't get the partition info for offset[0x%.8x]",offset);
+ MSG_ERR("Couldn't get the partition info for offset[0x%.8x]", offset);
log<level::ERR>("Request::getPartitionFilePath error in call to "
- "vpnor_get_partition",
- entry("OFFSET=%d", offset));
+ "vpnor_get_partition",
+ entry("OFFSET=%d", offset));
elog<InternalFailure>();
}
@@ -111,10 +109,9 @@ const pnor_partition* RORequest::getPartitionInfo(struct mbox_context* context,
if (rc != ReturnCode::FILE_NOT_FOUND)
{
log<level::ERR>("RORequest::getPartitionInfo error in opening "
- "partition file",
- entry("RC=%d", rc),
- entry("FILE_NAME=%s", path.c_str()),
- entry("OFFSET=%d", offset));
+ "partition file",
+ entry("RC=%d", rc), entry("FILE_NAME=%s", path.c_str()),
+ entry("OFFSET=%d", offset));
elog<InternalFailure>();
}
@@ -123,10 +120,10 @@ const pnor_partition* RORequest::getPartitionInfo(struct mbox_context* context,
{
MSG_ERR("Can't open the partition file");
log<level::ERR>("RORequest::getPartitionInfo error offset is "
- "in read only partition",
- entry("FILE_NAME=%s", path.c_str()),
- entry("OFFSET=%d", offset),
- entry("USER_DATA=%s", partition->data.user.data[1]));
+ "in read only partition",
+ entry("FILE_NAME=%s", path.c_str()),
+ entry("OFFSET=%d", offset),
+ entry("USER_DATA=%s", partition->data.user.data[1]));
elog<InternalFailure>();
}
@@ -140,14 +137,13 @@ const pnor_partition* RORequest::getPartitionInfo(struct mbox_context* context,
if (rc != ReturnCode::SUCCESS)
{
log<level::ERR>("RORequest::getPartitionInfo error in opening "
- "partition file from read only location",
- entry("RC=%d", rc),
- entry("FILE_NAME=%s", partitionFilePath.c_str()));
+ "partition file from read only location",
+ entry("RC=%d", rc),
+ entry("FILE_NAME=%s", partitionFilePath.c_str()));
elog<InternalFailure>();
}
return partition;
-
}
const pnor_partition* RWRequest::getPartitionInfo(struct mbox_context* context,
@@ -164,10 +160,9 @@ const pnor_partition* RWRequest::getPartitionInfo(struct mbox_context* context,
if (rc != ReturnCode::FILE_NOT_FOUND)
{
log<level::ERR>("RWRequest::getPartitionInfo error in opening "
- "partition file",
- entry("RC=%d", rc),
- entry("FILE_NAME=%s", path.c_str()),
- entry("OFFSET=%d", offset));
+ "partition file",
+ entry("RC=%d", rc), entry("FILE_NAME=%s", path.c_str()),
+ entry("OFFSET=%d", offset));
elog<InternalFailure>();
}
@@ -179,14 +174,14 @@ const pnor_partition* RWRequest::getPartitionInfo(struct mbox_context* context,
fromPath /= partition->data.name;
if (!fs::exists(fromPath))
{
- MSG_ERR("Couldn't find the file[%s]",fromPath.c_str());
+ MSG_ERR("Couldn't find the file[%s]", fromPath.c_str());
log<level::ERR>("RWRequest::getPartitionInfo error in opening "
- "partition file from read only location",
- entry("FILE_NAME=%s", fromPath.c_str()),
- entry("OFFSET=%d", offset));
+ "partition file from read only location",
+ entry("FILE_NAME=%s", fromPath.c_str()),
+ entry("OFFSET=%d", offset));
elog<InternalFailure>();
}
- //copy the file from ro to respective partition
+ // copy the file from ro to respective partition
fs::path toPath = context->paths.rw_loc;
if (partition->data.user.data[1] & PARTITION_PRESERVED)
@@ -201,23 +196,23 @@ const pnor_partition* RWRequest::getPartitionInfo(struct mbox_context* context,
if (fs::copy_file(fromPath, toPath))
{
- MSG_DBG("File copied from[%s] to [%s]\n",
- fromPath.c_str(), toPath.c_str());
+ MSG_DBG("File copied from[%s] to [%s]\n", fromPath.c_str(),
+ toPath.c_str());
}
- rc = Request::open(toPath.c_str(), O_RDWR);
+ rc = Request::open(toPath.c_str(), O_RDWR);
if (rc != ReturnCode::SUCCESS)
{
log<level::ERR>("RWRequest::getPartitionInfo error in opening "
- "partition file from read write location",
- entry("RC=%d", rc),
- entry("FILE_NAME=%s", toPath.c_str()));
+ "partition file from read write location",
+ entry("RC=%d", rc),
+ entry("FILE_NAME=%s", toPath.c_str()));
elog<InternalFailure>();
}
return partition;
}
-}// namespace virtual_pnor
-}// namespace openpower
+} // namespace virtual_pnor
+} // namespace openpower
diff --git a/pnor_partition.hpp b/pnor_partition.hpp
index 004dca6..242da37 100644
--- a/pnor_partition.hpp
+++ b/pnor_partition.hpp
@@ -13,39 +13,41 @@ namespace file
class Descriptor
{
- private:
- /** default value */
- int fd = -1;
-
- public:
- Descriptor() = default;
- Descriptor(const Descriptor&) = delete;
- Descriptor& operator=(const Descriptor&) = delete;
- Descriptor(Descriptor&&) = delete;
- Descriptor& operator=(Descriptor &&) = delete;
-
- Descriptor(int fd) : fd(fd) {}
-
- ~Descriptor()
+ private:
+ /** default value */
+ int fd = -1;
+
+ public:
+ Descriptor() = default;
+ Descriptor(const Descriptor&) = delete;
+ Descriptor& operator=(const Descriptor&) = delete;
+ Descriptor(Descriptor&&) = delete;
+ Descriptor& operator=(Descriptor&&) = delete;
+
+ Descriptor(int fd) : fd(fd)
+ {
+ }
+
+ ~Descriptor()
+ {
+ if (fd >= 0)
{
- if (fd >= 0)
- {
- close(fd);
- }
+ close(fd);
}
+ }
- int operator()() const
- {
- return fd;
- }
+ int operator()() const
+ {
+ return fd;
+ }
- void set(int descriptor)
- {
- fd = descriptor;
- }
+ void set(int descriptor)
+ {
+ fd = descriptor;
+ }
};
-}// namespace file
+} // namespace file
namespace virtual_pnor
{
@@ -63,35 +65,34 @@ enum class ReturnCode : uint8_t
class Request
{
- public:
-
- Request() = default;
- Request(const Request&) = delete;
- Request& operator=(const Request&) = delete;
- Request(Request&&) = default;
- Request& operator=(Request&&) = default;
- ~Request() = default;
-
- openpower::file::Descriptor fd;
-
- protected:
- /** @brief opens the partition file
- *
- * @param[in] filePath - Absolute file path.
- * @param[in] mode - File open mode.
- */
- ReturnCode open(const std::string& filePath, int mode);
-
- /** @brief returns the partition file path associated with the offset.
- *
- * @param[in] context - The mbox context pointer.
- * @param[in] offset - The pnor offset(bytes).
- */
-
- std::string getPartitionFilePath(struct mbox_context* context,
- uint32_t offset);
-
- const pnor_partition* partition = nullptr;
+ public:
+ Request() = default;
+ Request(const Request&) = delete;
+ Request& operator=(const Request&) = delete;
+ Request(Request&&) = default;
+ Request& operator=(Request&&) = default;
+ ~Request() = default;
+
+ openpower::file::Descriptor fd;
+
+ protected:
+ /** @brief opens the partition file
+ *
+ * @param[in] filePath - Absolute file path.
+ * @param[in] mode - File open mode.
+ */
+ ReturnCode open(const std::string& filePath, int mode);
+
+ /** @brief returns the partition file path associated with the offset.
+ *
+ * @param[in] context - The mbox context pointer.
+ * @param[in] offset - The pnor offset(bytes).
+ */
+
+ std::string getPartitionFilePath(struct mbox_context* context,
+ uint32_t offset);
+
+ const pnor_partition* partition = nullptr;
};
/** @class RORequest
@@ -100,30 +101,30 @@ class Request
*/
class RORequest : public Request
{
- public:
- RORequest() = default;
- RORequest(const RORequest&) = delete;
- RORequest& operator=(const RORequest&) = delete;
- RORequest(RORequest&&) = default;
- RORequest& operator=(RORequest&&) = default;
- ~RORequest(){};
-
- /** @brief opens the partition file associated with the offset
- * in read only mode and gets the partition details.
- *
- * 1. Depending on the partition type,tries to open the file
- * from the associated partition(RW/PRSV/RO).
- * 1a. if file not found in the corresponding
- * partition(RW/PRSV/RO) then tries to read the file from
- * the read only partition.
- * 1b. if the file not found in the read only partition then
- * throw exception.
- *
- * @param[in] context - The mbox context pointer.
- * @param[in] offset - The pnor offset(bytes).
- */
- const pnor_partition* getPartitionInfo(struct mbox_context* context,
- uint32_t offset);
+ public:
+ RORequest() = default;
+ RORequest(const RORequest&) = delete;
+ RORequest& operator=(const RORequest&) = delete;
+ RORequest(RORequest&&) = default;
+ RORequest& operator=(RORequest&&) = default;
+ ~RORequest(){};
+
+ /** @brief opens the partition file associated with the offset
+ * in read only mode and gets the partition details.
+ *
+ * 1. Depending on the partition type,tries to open the file
+ * from the associated partition(RW/PRSV/RO).
+ * 1a. if file not found in the corresponding
+ * partition(RW/PRSV/RO) then tries to read the file from
+ * the read only partition.
+ * 1b. if the file not found in the read only partition then
+ * throw exception.
+ *
+ * @param[in] context - The mbox context pointer.
+ * @param[in] offset - The pnor offset(bytes).
+ */
+ const pnor_partition* getPartitionInfo(struct mbox_context* context,
+ uint32_t offset);
};
/** @class RWRequest
@@ -132,31 +133,31 @@ class RORequest : public Request
*/
class RWRequest : public Request
{
- public:
-
- RWRequest() = default;
- RWRequest(const RWRequest&) = delete;
- RWRequest& operator=(const RWRequest&) = delete;
- RWRequest(RWRequest&&) = default;
- RWRequest& operator=(RWRequest&&) = default;
- ~RWRequest() {};
-
- /** @brief opens the partition file associated with the offset
- * in write mode and gets the parttition details.
- *
- * 1. Depending on the partition type tries to open the file
- * from the associated partition.
- * 1a. if file not found in the corresponding partition(RW/PRSV)
- * then copy the file from the read only partition to the (RW/PRSV)
- * partition depending on the partition type.
- * 1b. if the file not found in the read only partition then throw exception.
- *
- * @param[in] context - The mbox context pointer.
- * @param[in] offset - The pnor offset(bytes).
- */
- const pnor_partition* getPartitionInfo(struct mbox_context* context,
- uint32_t offset);
+ public:
+ RWRequest() = default;
+ RWRequest(const RWRequest&) = delete;
+ RWRequest& operator=(const RWRequest&) = delete;
+ RWRequest(RWRequest&&) = default;
+ RWRequest& operator=(RWRequest&&) = default;
+ ~RWRequest(){};
+
+ /** @brief opens the partition file associated with the offset
+ * in write mode and gets the parttition details.
+ *
+ * 1. Depending on the partition type tries to open the file
+ * from the associated partition.
+ * 1a. if file not found in the corresponding partition(RW/PRSV)
+ * then copy the file from the read only partition to the (RW/PRSV)
+ * partition depending on the partition type.
+ * 1b. if the file not found in the read only partition then throw
+ * exception.
+ *
+ * @param[in] context - The mbox context pointer.
+ * @param[in] offset - The pnor offset(bytes).
+ */
+ const pnor_partition* getPartitionInfo(struct mbox_context* context,
+ uint32_t offset);
};
-}// namespace virtual_pnor
-}// namespace openpower
+} // namespace virtual_pnor
+} // namespace openpower
diff --git a/pnor_partition_table.cpp b/pnor_partition_table.cpp
index b42907c..7f00f31 100644
--- a/pnor_partition_table.cpp
+++ b/pnor_partition_table.cpp
@@ -20,18 +20,14 @@ using namespace sdbusplus::xyz::openbmc_project::Common::Error;
namespace partition
{
-Table::Table(size_t blockSize, size_t pnorSize):
+Table::Table(size_t blockSize, size_t pnorSize) :
Table(fs::path(PARTITION_FILES_RO_LOC), blockSize, pnorSize)
{
}
-Table::Table(fs::path&& directory,
- size_t blockSize, size_t pnorSize):
- szBlocks(0),
- directory(std::move(directory)),
- numParts(0),
- blockSize(blockSize),
- pnorSize(pnorSize)
+Table::Table(fs::path&& directory, size_t blockSize, size_t pnorSize) :
+ szBlocks(0), directory(std::move(directory)), numParts(0),
+ blockSize(blockSize), pnorSize(pnorSize)
{
preparePartitions();
prepareHeader();
@@ -71,8 +67,8 @@ inline void Table::allocateMemory(const fs::path& tocFile)
}
}
- size_t totalSizeBytes = sizeof(pnor_partition_table) +
- (num * sizeof(pnor_partition));
+ size_t totalSizeBytes =
+ sizeof(pnor_partition_table) + (num * sizeof(pnor_partition));
size_t totalSizeAligned = align_up(totalSizeBytes, blockSize);
szBlocks = totalSizeAligned / blockSize;
tbl.resize(totalSizeAligned);
@@ -91,8 +87,8 @@ inline void Table::writeSizes(pnor_partition& part, size_t start, size_t end)
patchFile /= part.data.name;
if (fs::is_regular_file(patchFile))
{
- part.data.actual = std::min(
- size, static_cast<size_t>(fs::file_size(patchFile)));
+ part.data.actual =
+ std::min(size, static_cast<size_t>(fs::file_size(patchFile)));
}
else
{
@@ -100,12 +96,11 @@ inline void Table::writeSizes(pnor_partition& part, size_t start, size_t end)
}
}
-inline void Table::writeUserdata(pnor_partition& part,
- uint32_t version,
+inline void Table::writeUserdata(pnor_partition& part, uint32_t version,
const std::string& data)
{
std::istringstream stream(data);
- std::string flag {};
+ std::string flag{};
auto perms = 0;
while (std::getline(stream, flag, ','))
@@ -152,9 +147,7 @@ inline void Table::writeNameAndId(pnor_partition& part, std::string&& name,
const std::string& id)
{
name.resize(PARTITION_NAME_MAX);
- memcpy(part.data.name,
- name.c_str(),
- sizeof(part.data.name));
+ memcpy(part.data.name, name.c_str(), sizeof(part.data.name));
part.data.id = std::stoul(id);
}
@@ -173,12 +166,10 @@ void Table::preparePartitions()
// Parse PNOR toc (table of contents) file, which has lines like :
// partition01=HBB,0x00010000,0x000a0000,0x80,ECC,PRESERVED, to indicate
// partition information
- std::regex regex
- {
+ std::regex regex{
"^partition([0-9]+)=([A-Za-z0-9_]+),"
"(0x)?([0-9a-fA-F]+),(0x)?([0-9a-fA-F]+),(0x)?([A-Fa-f0-9]{2})",
- std::regex::extended
- };
+ std::regex::extended};
std::smatch match;
std::string line;
constexpr auto versionShift = 24;
@@ -194,12 +185,11 @@ void Table::preparePartitions()
if (!fs::exists(partitionFile))
{
MSG_ERR("Partition file %s does not exist",
- partitionFile.c_str());
+ partitionFile.c_str());
continue;
}
- writeNameAndId(table.partitions[numParts],
- match[NAME_MATCH].str(),
+ writeNameAndId(table.partitions[numParts], match[NAME_MATCH].str(),
match[ID_MATCH].str());
writeDefaults(table.partitions[numParts]);
writeSizes(table.partitions[numParts],
@@ -207,8 +197,8 @@ void Table::preparePartitions()
std::stoul(match[END_ADDR_MATCH].str(), nullptr, 16));
writeUserdata(
table.partitions[numParts],
- std::stoul(match[VERSION_MATCH].str(), nullptr, 16) <<
- versionShift, // For eg, convert "80" to 0x80000000
+ std::stoul(match[VERSION_MATCH].str(), nullptr, 16)
+ << versionShift, // For eg, convert "80" to 0x80000000
match.suffix().str());
table.partitions[numParts].checksum =
details::checksum(table.partitions[numParts].data);
@@ -226,8 +216,8 @@ const pnor_partition& Table::partition(size_t offset) const
for (decltype(numParts) i{}; i < numParts; ++i)
{
if ((offt >= table.partitions[i].data.base) &&
- (offt < (table.partitions[i].data.base +
- table.partitions[i].data.size)))
+ (offt <
+ (table.partitions[i].data.base + table.partitions[i].data.size)))
{
return table.partitions[i];
}
@@ -254,7 +244,7 @@ const pnor_partition& Table::partition(const std::string& name) const
MSG_ERR("Partition %s not found", name.c_str());
log<level::ERR>("Table::partition partition not found ",
- entry("PARTITION_NAME=%s", name.c_str()));
+ entry("PARTITION_NAME=%s", name.c_str()));
elog<InternalFailure>();
static pnor_partition p{};
return p;
diff --git a/pnor_partition_table.hpp b/pnor_partition_table.hpp
index 2d0d007..d3d7fa4 100644
--- a/pnor_partition_table.hpp
+++ b/pnor_partition_table.hpp
@@ -34,8 +34,7 @@ namespace details
*
* @returns computed checksum
*/
-template <class T>
-checksum_t checksum(const T& data)
+template <class T> checksum_t checksum(const T& data)
{
static_assert(sizeof(decltype(data)) % sizeof(checksum_t) == 0,
"sizeof(data) is not aligned to sizeof(checksum_t) boundary");
@@ -70,171 +69,167 @@ namespace partition
*/
class Table
{
- public:
- /** @brief Constructor accepting the path of the directory
- * that houses the PNOR partition files.
- *
- * @param[in] directory - path of the directory housing PNOR partitions
- * @param[in] blockSize - PNOR block size, in bytes. See
- * open-power/hostboot/blob/master/src/usr/pnor/ffs.h for
- * the PNOR FFS structure.
- * @param[in] pnorSize - PNOR size, in bytes
- */
- Table(fs::path&& directory,
- size_t blockSize,
- size_t pnorSize);
-
- /** @brief Constructor - creates partition table
- *
- * @param[in] blockSize - PNOR block size, in bytes
- * @param[in] pnorSize - PNOR size, in bytes
- */
- Table(size_t blockSize,
- size_t pnorSize);
-
- Table(const Table&) = delete;
- Table& operator=(const Table&) = delete;
- Table(Table&&) = delete;
- Table& operator=(Table&&) = delete;
- ~Table() = default;
-
- /** @brief Return size of partition table
- *
- * @returns size_t - size of partition table in blocks
- */
- size_t size() const
- {
- return szBlocks;
- }
-
- /** @brief Return a partition table having byte-ordering
- * that the host expects.
- *
- * The host needs the partion table in big-endian.
- *
- * @returns const reference to host partition table.
- */
- const pnor_partition_table& getHostTable() const
- {
- return *(reinterpret_cast<
- const pnor_partition_table*>(hostTbl.data()));
- }
-
- /** @brief Return a little-endian partition table
- *
- * @returns const reference to native partition table
- */
- const pnor_partition_table& getNativeTable() const
- {
- return *(reinterpret_cast<const pnor_partition_table*>(tbl.data()));
- }
-
- /** @brief Return partition corresponding to PNOR offset, the offset
- * is within returned partition.
- *
- * @param[in] offset - PNOR offset in bytes
- *
- * @returns const reference to pnor_partition, if found, else an
- * exception will be thrown.
- */
- const pnor_partition& partition(size_t offset) const;
-
- /** @brief Return partition corresponding to input partition name.
- *
- * @param[in] name - PNOR partition name
- *
- * @returns const reference to pnor_partition, if found, else an
- * exception will be thrown.
- */
- const pnor_partition& partition(const std::string& name) const;
-
- private:
- /** @brief Prepares a vector of PNOR partition structures.
- */
- void preparePartitions();
-
- /** @brief Prepares the PNOR header.
- */
- void prepareHeader();
-
- /** @brief Allocate memory to hold the partion table. Determine the
- * amount needed based on the partition files in the toc file.
- *
- * @param[in] tocFile - Table of contents file path.
- */
- void allocateMemory(const fs::path& tocFile);
-
- /** @brief Populate fields related to sizes for the input
- * pnor_partition structure.
- *
- * @param[in/out] part - pnor_partition structure
- * @param[in] start - partition start address
- * @param[in] end - partition end address
- */
- void writeSizes(pnor_partition& part, size_t start, size_t end);
-
- /** @brief Populate userdata bits for the input
- * pnor_partition structure.
- *
- * @param[in/out] part - pnor_partition structure
- * @param[in] version - partition version check algorithm to be used
- * (see pnor_partition_defs.h)
- * @param[in] data - string having userdata fields in a
- * comma-separated line.
- */
- void writeUserdata(pnor_partition& part, uint32_t version,
- const std::string& data);
-
- /** @brief Populate the name and id fields for the input
- * pnor_partition structure.
- *
- * @param[in/out] part - pnor_partition structure
- * @param[in] name - partition name
- * @param[id] id - partition id
- */
- void writeNameAndId(pnor_partition& part, std::string&& name,
- const std::string& id);
-
- /** @brief Populate default/unused fields for the input
- * pnor_partition structure.
- *
- * @param[in/out] part - pnor_partition structure
- */
- void writeDefaults(pnor_partition& part);
-
- /** @brief Return a little-endian partition table
- *
- * @returns reference to native partition table
- */
- pnor_partition_table& getNativeTable()
- {
- return *(reinterpret_cast<pnor_partition_table*>(tbl.data()));
- }
-
- /** @brief Size of the PNOR partition table -
- * sizeof(pnor_partition_table) +
- * (no. of partitions * sizeof(pnor_partition)),
- * measured in erase-blocks.
- */
- size_t szBlocks;
-
- /** @brief Partition table */
- PartitionTable tbl;
-
- /** @brief Partition table with host byte ordering */
- PartitionTable hostTbl;
-
- /** @brief Directory housing generated PNOR partition files */
- fs::path directory;
-
- /** @brief Number of partitions */
- size_t numParts;
-
- /** @brief PNOR block size, in bytes */
- size_t blockSize;
-
- /** @brief PNOR size, in bytes */
- size_t pnorSize;
+ public:
+ /** @brief Constructor accepting the path of the directory
+ * that houses the PNOR partition files.
+ *
+ * @param[in] directory - path of the directory housing PNOR partitions
+ * @param[in] blockSize - PNOR block size, in bytes. See
+ * open-power/hostboot/blob/master/src/usr/pnor/ffs.h for
+ * the PNOR FFS structure.
+ * @param[in] pnorSize - PNOR size, in bytes
+ */
+ Table(fs::path&& directory, size_t blockSize, size_t pnorSize);
+
+ /** @brief Constructor - creates partition table
+ *
+ * @param[in] blockSize - PNOR block size, in bytes
+ * @param[in] pnorSize - PNOR size, in bytes
+ */
+ Table(size_t blockSize, size_t pnorSize);
+
+ Table(const Table&) = delete;
+ Table& operator=(const Table&) = delete;
+ Table(Table&&) = delete;
+ Table& operator=(Table&&) = delete;
+ ~Table() = default;
+
+ /** @brief Return size of partition table
+ *
+ * @returns size_t - size of partition table in blocks
+ */
+ size_t size() const
+ {
+ return szBlocks;
+ }
+
+ /** @brief Return a partition table having byte-ordering
+ * that the host expects.
+ *
+ * The host needs the partion table in big-endian.
+ *
+ * @returns const reference to host partition table.
+ */
+ const pnor_partition_table& getHostTable() const
+ {
+ return *(reinterpret_cast<const pnor_partition_table*>(hostTbl.data()));
+ }
+
+ /** @brief Return a little-endian partition table
+ *
+ * @returns const reference to native partition table
+ */
+ const pnor_partition_table& getNativeTable() const
+ {
+ return *(reinterpret_cast<const pnor_partition_table*>(tbl.data()));
+ }
+
+ /** @brief Return partition corresponding to PNOR offset, the offset
+ * is within returned partition.
+ *
+ * @param[in] offset - PNOR offset in bytes
+ *
+ * @returns const reference to pnor_partition, if found, else an
+ * exception will be thrown.
+ */
+ const pnor_partition& partition(size_t offset) const;
+
+ /** @brief Return partition corresponding to input partition name.
+ *
+ * @param[in] name - PNOR partition name
+ *
+ * @returns const reference to pnor_partition, if found, else an
+ * exception will be thrown.
+ */
+ const pnor_partition& partition(const std::string& name) const;
+
+ private:
+ /** @brief Prepares a vector of PNOR partition structures.
+ */
+ void preparePartitions();
+
+ /** @brief Prepares the PNOR header.
+ */
+ void prepareHeader();
+
+ /** @brief Allocate memory to hold the partion table. Determine the
+ * amount needed based on the partition files in the toc file.
+ *
+ * @param[in] tocFile - Table of contents file path.
+ */
+ void allocateMemory(const fs::path& tocFile);
+
+ /** @brief Populate fields related to sizes for the input
+ * pnor_partition structure.
+ *
+ * @param[in/out] part - pnor_partition structure
+ * @param[in] start - partition start address
+ * @param[in] end - partition end address
+ */
+ void writeSizes(pnor_partition& part, size_t start, size_t end);
+
+ /** @brief Populate userdata bits for the input
+ * pnor_partition structure.
+ *
+ * @param[in/out] part - pnor_partition structure
+ * @param[in] version - partition version check algorithm to be used
+ * (see pnor_partition_defs.h)
+ * @param[in] data - string having userdata fields in a
+ * comma-separated line.
+ */
+ void writeUserdata(pnor_partition& part, uint32_t version,
+ const std::string& data);
+
+ /** @brief Populate the name and id fields for the input
+ * pnor_partition structure.
+ *
+ * @param[in/out] part - pnor_partition structure
+ * @param[in] name - partition name
+ * @param[id] id - partition id
+ */
+ void writeNameAndId(pnor_partition& part, std::string&& name,
+ const std::string& id);
+
+ /** @brief Populate default/unused fields for the input
+ * pnor_partition structure.
+ *
+ * @param[in/out] part - pnor_partition structure
+ */
+ void writeDefaults(pnor_partition& part);
+
+ /** @brief Return a little-endian partition table
+ *
+ * @returns reference to native partition table
+ */
+ pnor_partition_table& getNativeTable()
+ {
+ return *(reinterpret_cast<pnor_partition_table*>(tbl.data()));
+ }
+
+ /** @brief Size of the PNOR partition table -
+ * sizeof(pnor_partition_table) +
+ * (no. of partitions * sizeof(pnor_partition)),
+ * measured in erase-blocks.
+ */
+ size_t szBlocks;
+
+ /** @brief Partition table */
+ PartitionTable tbl;
+
+ /** @brief Partition table with host byte ordering */
+ PartitionTable hostTbl;
+
+ /** @brief Directory housing generated PNOR partition files */
+ fs::path directory;
+
+ /** @brief Number of partitions */
+ size_t numParts;
+
+ /** @brief PNOR block size, in bytes */
+ size_t blockSize;
+
+ /** @brief PNOR size, in bytes */
+ size_t pnorSize;
};
} // namespace partition
diff --git a/test/create_pnor_partition_table.cpp b/test/create_pnor_partition_table.cpp
index d542299..57bb675 100644
--- a/test/create_pnor_partition_table.cpp
+++ b/test/create_pnor_partition_table.cpp
@@ -30,8 +30,8 @@ int main()
partitionFile.write(empty.data(), empty.size());
partitionFile.close();
- const openpower::virtual_pnor::partition::Table
- table(fs::path{tmpdir}, 4 * 1024, 64 * 1024 * 1024);
+ const openpower::virtual_pnor::partition::Table table(
+ fs::path{tmpdir}, 4 * 1024, 64 * 1024 * 1024);
pnor_partition_table expectedTable{};
expectedTable.data.magic = PARTITION_HEADER_MAGIC;
@@ -47,8 +47,8 @@ int main()
pnor_partition expectedPartition{};
strcpy(expectedPartition.data.name, partitionName);
- expectedPartition.data.base = 0; // starts at offset 0
- expectedPartition.data.size = 1; // 1 block
+ expectedPartition.data.base = 0; // starts at offset 0
+ expectedPartition.data.size = 1; // 1 block
expectedPartition.data.actual = 0x400; // 1024 bytes
expectedPartition.data.id = 1;
expectedPartition.data.pid = PARENT_PATITION_ID;
diff --git a/test/create_read_window_vpnor.cpp b/test/create_read_window_vpnor.cpp
index 7c344f7..3ea6bb5 100644
--- a/test/create_read_window_vpnor.cpp
+++ b/test/create_read_window_vpnor.cpp
@@ -18,28 +18,24 @@ extern "C" {
constexpr auto line = "partition01=HBB,00000100,0001000,ECC,PRESERVED";
constexpr auto partition = "HBB";
char tmplt[] = "/tmp/create_read_test.XXXXXX";
-uint8_t data[8] = { 0xaa, 0x55, 0xaa, 0x66, 0x77, 0x88, 0x99, 0xab };
+uint8_t data[8] = {0xaa, 0x55, 0xaa, 0x66, 0x77, 0x88, 0x99, 0xab};
-#define BLOCK_SIZE 4096
-#define MEM_SIZE (BLOCK_SIZE *2)
-#define ERASE_SIZE BLOCK_SIZE
-#define N_WINDOWS 1
+#define BLOCK_SIZE 4096
+#define MEM_SIZE (BLOCK_SIZE * 2)
+#define ERASE_SIZE BLOCK_SIZE
+#define N_WINDOWS 1
#define WINDOW_SIZE BLOCK_SIZE
-static const uint8_t get_info[] = {
- 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
+static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00};
// offset 0x100 and size 6
-static const uint8_t create_read_window[] = {
- 0x04, 0x01, 0x01, 0x00, 0x06, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
+static const uint8_t create_read_window[] = {0x04, 0x01, 0x01, 0x00, 0x06, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00};
-static const uint8_t response[] = {
- 0x04, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
-};
+static const uint8_t response[] = {0x04, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
namespace fs = std::experimental::filesystem;
@@ -60,16 +56,16 @@ int main()
partitionFilePath /= partition;
std::ofstream partitionFile(partitionFilePath.c_str());
- partitionFile.write((char*)data,sizeof(data));
+ partitionFile.write((char*)data, sizeof(data));
partitionFile.close();
system_set_reserved_size(MEM_SIZE);
system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
- struct mbox_context *ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
- strcpy(ctx->paths.ro_loc,tmpdir);
- strcpy(ctx->paths.rw_loc,tmpdir);
- strcpy(ctx->paths.prsv_loc,tmpdir);
+ struct mbox_context* ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
+ strcpy(ctx->paths.ro_loc, tmpdir);
+ strcpy(ctx->paths.rw_loc, tmpdir);
+ strcpy(ctx->paths.prsv_loc, tmpdir);
vpnor_create_partition_table_from_path(ctx, tmpdir);
@@ -78,7 +74,7 @@ int main()
// send the request for partition1
rc = mbox_command_dispatch(ctx, create_read_window,
- sizeof(create_read_window));
+ sizeof(create_read_window));
assert(rc == 1);
rc = mbox_cmp(ctx, response, sizeof(response));
@@ -88,7 +84,7 @@ int main()
rc = memcmp(ctx->mem, data, 6);
assert(rc == 0);
- //TODO: Add few more test cases for read from multiple partitions(PRSV/RW)
+ // TODO: Add few more test cases for read from multiple partitions(PRSV/RW)
// Read beyond the partition file size.
// openbmc/openbmc#1868
diff --git a/test/write_flash_vpnor.cpp b/test/write_flash_vpnor.cpp
index 78b9ad8..e78c79c 100644
--- a/test/write_flash_vpnor.cpp
+++ b/test/write_flash_vpnor.cpp
@@ -37,35 +37,31 @@ extern "C" {
#include <sys/ioctl.h>
#include <fcntl.h>
+uint8_t data[8] = {0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7};
-uint8_t data[8] = { 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7 };
-
-#define BLOCK_SIZE 4096
-#define OFFSET BLOCK_SIZE
-#define MEM_SIZE (BLOCK_SIZE *2)
+#define BLOCK_SIZE 4096
+#define OFFSET BLOCK_SIZE
+#define MEM_SIZE (BLOCK_SIZE * 2)
#define DATA_SIZE sizeof(data)
#define ERASE_SIZE BLOCK_SIZE
#define BLOCK_SIZE_SHIFT 12
-
void init(struct mbox_context* ctx)
{
namespace fs = std::experimental::filesystem;
using namespace std::string_literals;
- std::string tocData = "partition01=TEST1,00001000,00001400,ECC,READONLY\n"s
- + "partition02=TEST2,00002000,00002008,ECC,READWRITE\n"s
- + "partition03=TEST3,00003000,00003400,ECC,PRESERVED"s;
-
- std::vector<std::string> templatePaths = { "/tmp/ro.XXXXXX",
- "/tmp/rw.XXXXXX" ,
- "/tmp/prsv.XXXXXX",
- "/tmp/patch.XXXXXX"
- };
+ std::string tocData =
+ "partition01=TEST1,00001000,00001400,ECC,READONLY\n"s +
+ "partition02=TEST2,00002000,00002008,ECC,READWRITE\n"s +
+ "partition03=TEST3,00003000,00003400,ECC,PRESERVED"s;
- std::vector<std::string>partitions = { "TEST1", "TEST2", "TEST3" };
+ std::vector<std::string> templatePaths = {
+ "/tmp/ro.XXXXXX", "/tmp/rw.XXXXXX", "/tmp/prsv.XXXXXX",
+ "/tmp/patch.XXXXXX"};
+ std::vector<std::string> partitions = {"TEST1", "TEST2", "TEST3"};
// create various partition directory
@@ -75,10 +71,12 @@ void init(struct mbox_context* ctx)
std::string tmpRWdir = mkdtemp(const_cast<char*>(templatePaths[1].c_str()));
assert(tmpRWdir.length() != 0);
- std::string tmpPRSVdir = mkdtemp(const_cast<char*>(templatePaths[2].c_str()));
+ std::string tmpPRSVdir =
+ mkdtemp(const_cast<char*>(templatePaths[2].c_str()));
assert(tmpPRSVdir.length() != 0);
- std::string tmpPATCHdir = mkdtemp(const_cast<char*>(templatePaths[3].c_str()));
+ std::string tmpPATCHdir =
+ mkdtemp(const_cast<char*>(templatePaths[3].c_str()));
assert(tmpPATCHdir.length() != 0);
// create the toc file
@@ -92,12 +90,11 @@ void init(struct mbox_context* ctx)
// create the partition files in the ro directory
for (auto partition : partitions)
{
- fs::path partitionFilePath {tmpROdir};
+ fs::path partitionFilePath{tmpROdir};
partitionFilePath /= partition;
std::ofstream partitionFile(partitionFilePath.c_str());
partitionFile.write(reinterpret_cast<char*>(data), sizeof(data));
partitionFile.close();
-
}
// copy partition2 file from ro to rw
@@ -112,28 +109,25 @@ void init(struct mbox_context* ctx)
ctx->erase_size_shift = BLOCK_SIZE_SHIFT;
ctx->block_size_shift = BLOCK_SIZE_SHIFT;
ctx->flash_bmap = reinterpret_cast<uint8_t*>(
- calloc(MEM_SIZE >> ctx->erase_size_shift,
- sizeof(*ctx->flash_bmap)));
+ calloc(MEM_SIZE >> ctx->erase_size_shift, sizeof(*ctx->flash_bmap)));
strcpy(ctx->paths.ro_loc, tmpROdir.c_str());
strcpy(ctx->paths.rw_loc, tmpRWdir.c_str());
strcpy(ctx->paths.prsv_loc, tmpPRSVdir.c_str());
strcpy(ctx->paths.patch_loc, tmpPATCHdir.c_str());
-
}
-
int main(void)
{
namespace fs = std::experimental::filesystem;
- int rc {};
- char src[DATA_SIZE] {0};
+ int rc{};
+ char src[DATA_SIZE]{0};
struct mbox_context context;
struct mbox_context* ctx = &context;
memset(ctx, 0, sizeof(mbox_context));
- //Initialize the context before running the test case.
+ // Initialize the context before running the test case.
init(ctx);
std::string tmpROdir = ctx->paths.ro_loc;
@@ -151,7 +145,7 @@ int main(void)
memset(src, 0xaa, sizeof(src));
- rc = write_flash(ctx, (OFFSET * 3) , src, sizeof(src));
+ rc = write_flash(ctx, (OFFSET * 3), src, sizeof(src));
assert(rc == 0);
auto fd = open((tmpPRSVdir + "/" + "TEST3").c_str(), O_RDONLY);
@@ -229,7 +223,7 @@ int main(void)
assert(fs::copy_file(roFile, patchFile) == true);
// Write arbitrary data
- char srcPatch[DATA_SIZE] {0};
+ char srcPatch[DATA_SIZE]{0};
memset(srcPatch, 0x33, sizeof(srcPatch));
rc = write_flash(ctx, (OFFSET * 2), srcPatch, sizeof(srcPatch));
assert(rc == 0);
@@ -258,10 +252,10 @@ int main(void)
fs::remove(patchFile);
// END Test patch location
- fs::remove_all(fs::path {tmpROdir});
- fs::remove_all(fs::path {tmpRWdir});
- fs::remove_all(fs::path {tmpPRSVdir});
- fs::remove_all(fs::path {tmpPATCHdir});
+ fs::remove_all(fs::path{tmpROdir});
+ fs::remove_all(fs::path{tmpRWdir});
+ fs::remove_all(fs::path{tmpPRSVdir});
+ fs::remove_all(fs::path{tmpPATCHdir});
destroy_vpnor(ctx);
free(ctx->flash_bmap);
OpenPOWER on IntegriCloud