clang-format: Pull the format rules from the openbmc/docs repo

This makes it consistent with other openbmc projects for c++ formatting.

Tested:
    Run through the unit test suite.

Change-Id: I92030ce5b42de01360393687fb438faf26f36ac8
Signed-off-by: default avatarWilliam A. Kennington III <wak@google.com>
parent b7c49b22
......@@ -17,7 +17,7 @@ AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
......@@ -42,15 +42,29 @@ ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DerivePointerAlignment: false
PointerAlignment: Left
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^[<"](gtest|gmock)'
Priority: 5
- Regex: '^"config.h"'
Priority: -1
- Regex: '^".*\.hpp"'
Priority: 1
- Regex: '^<.*\.h>'
Priority: 2
- Regex: '^<.*'
Priority: 3
- Regex: '.*'
Priority: 4
IndentCaseLabels: true
IndentWidth: 4
IndentWrappedFunctionNames: false
IndentWrappedFunctionNames: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
......@@ -65,9 +79,9 @@ PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
......
......@@ -4,10 +4,11 @@
#include <fcntl.h>
#include <stdint.h>
#include <stdlib.h>
#include <syslog.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <syslog.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <algorithm>
extern "C" {
......@@ -16,17 +17,19 @@ extern "C" {
}
#include "config.h"
#include "mboxd_pnor_partition_table.h"
#include "pnor_partition.hpp"
#include "pnor_partition_table.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
#include <phosphor-logging/log.hpp>
#include <phosphor-logging/elog-errors.hpp>
#include <memory>
#include <string>
#include <exception>
#include <memory>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/log.hpp>
#include <stdexcept>
#include <string>
#include "mboxd_pnor_partition_table.h"
namespace err = sdbusplus::xyz::openbmc_project::Common::Error;
namespace fs = std::experimental::filesystem;
......
......@@ -18,8 +18,8 @@
*/
extern "C" {
#include "mboxd.h"
#include "lpc.h"
#include "mboxd.h"
}
#include "mboxd_pnor_partition_table.h"
......@@ -30,7 +30,7 @@ extern "C" {
*
* Return 0 on success otherwise negative error code
*/
int lpc_reset(struct mbox_context *context)
int lpc_reset(struct mbox_context* context)
{
int rc;
......
......@@ -4,17 +4,19 @@ extern "C" {
#include "flash.h"
}
#include "mboxd_pnor_partition_table.h"
#include "pnor_partition_table.hpp"
#include "common.h"
#include "mboxd.h"
#include "pnor_partition_table.hpp"
#include "config.h"
#include "pnor_partition_table.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
#include <phosphor-logging/elog-errors.hpp>
#include <experimental/filesystem>
#include <phosphor-logging/elog-errors.hpp>
#include "common.h"
#include "mboxd.h"
#include "mboxd_pnor_partition_table.h"
int init_vpnor(struct mbox_context *context)
int init_vpnor(struct mbox_context* context)
{
if (context && !context->vpnor)
{
......@@ -39,7 +41,7 @@ int init_vpnor(struct mbox_context *context)
return 0;
}
int init_vpnor_from_paths(struct mbox_context *context)
int init_vpnor_from_paths(struct mbox_context* context)
{
namespace err = sdbusplus::xyz::openbmc_project::Common::Error;
namespace fs = std::experimental::filesystem;
......@@ -53,7 +55,7 @@ int init_vpnor_from_paths(struct mbox_context *context)
context->vpnor->table =
new openpower::virtual_pnor::partition::Table(context);
}
catch (vpnor::TocEntryError &e)
catch (vpnor::TocEntryError& e)
{
MSG_ERR("%s\n", e.what());
phosphor::logging::commit<err::InternalFailure>();
......@@ -64,7 +66,7 @@ int init_vpnor_from_paths(struct mbox_context *context)
return 0;
}
int vpnor_copy_bootloader_partition(const struct mbox_context *context)
int vpnor_copy_bootloader_partition(const struct mbox_context* context)
{
// The hostboot bootloader has certain size/offset assumptions, so
// we need a special partition table here.
......@@ -100,21 +102,21 @@ int vpnor_copy_bootloader_partition(const struct mbox_context *context)
// Copy TOC
flash_copy(&local, tocOffset,
static_cast<uint8_t *>(context->mem) + tocStart,
static_cast<uint8_t*>(context->mem) + tocStart,
blTable.capacity());
const pnor_partition &partition = blTable.partition(blPartitionName);
const pnor_partition& partition = blTable.partition(blPartitionName);
size_t hbbOffset = partition.data.base * eraseSize;
uint32_t hbbSize = partition.data.actual;
// Copy HBB
flash_copy(&local, hbbOffset,
static_cast<uint8_t *>(context->mem) + hbbOffset, hbbSize);
static_cast<uint8_t*>(context->mem) + hbbOffset, hbbSize);
}
catch (err::InternalFailure &e)
catch (err::InternalFailure& e)
{
phosphor::logging::commit<err::InternalFailure>();
return -EIO;
}
catch (vpnor::ReasonedError &e)
catch (vpnor::ReasonedError& e)
{
MSG_ERR("%s\n", e.what());
phosphor::logging::commit<err::InternalFailure>();
......@@ -124,7 +126,7 @@ int vpnor_copy_bootloader_partition(const struct mbox_context *context)
return 0;
}
void destroy_vpnor(struct mbox_context *context)
void destroy_vpnor(struct mbox_context* context)
{
if (context && context->vpnor)
{
......
......@@ -4,30 +4,31 @@ extern "C" {
#include "flash.h"
}
#include "config.h"
#include "pnor_partition.hpp"
#include "pnor_partition_table.hpp"
#include "config.h"
#include "mboxd_pnor_partition_table.h"
#include "xyz/openbmc_project/Common/error.hpp"
#include <phosphor-logging/log.hpp>
#include <phosphor-logging/elog-errors.hpp>
#include <assert.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdlib.h>
#include <syslog.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <syslog.h>
#include <unistd.h>
#include "common.h"
#include <string>
#include <exception>
#include <stdexcept>
#include <iostream>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/log.hpp>
#include <stdexcept>
#include <string>
#include "common.h"
#include "mboxd_pnor_partition_table.h"
namespace openpower
{
......@@ -99,7 +100,7 @@ size_t Request::clamp(size_t len)
return std::min(maxAccess, partSize) - offset;
}
void Request::resize(const fs::path &path, size_t len)
void Request::resize(const fs::path& path, size_t len)
{
size_t maxAccess = offset + len;
size_t fileSize = fs::file_size(path);
......@@ -116,7 +117,7 @@ void Request::resize(const fs::path &path, size_t len)
}
}
size_t Request::fulfil(const fs::path &path, int flags, void *buf, size_t len)
size_t Request::fulfil(const fs::path& path, int flags, void* buf, size_t len)
{
if (!(flags == O_RDONLY || flags == O_RDWR))
{
......@@ -162,11 +163,11 @@ size_t Request::fulfil(const fs::path &path, int flags, void *buf, size_t len)
if (flags == O_RDONLY)
{
memset(buf, 0xff, len);
memcpy(buf, (char *)map + offset, std::min(len, fileSize));
memcpy(buf, (char*)map + offset, std::min(len, fileSize));
}
else
{
memcpy((char *)map + offset, buf, len);
memcpy((char*)map + offset, buf, len);
flash_set_bytemap(ctx, base + offset, len, FLASH_DIRTY);
}
munmap(map, fileSize);
......
......@@ -6,12 +6,15 @@ extern "C" {
#include "mboxd.h"
};
#include "mboxd_pnor_partition_table.h"
#include "pnor_partition_table.hpp"
#include <fcntl.h>
#include <string>
#include <unistd.h>
#include <experimental/filesystem>
#include <string>
#include "mboxd_pnor_partition_table.h"
namespace openpower
{
......
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2018 IBM Corp.
#include "pnor_partition_table.hpp"
#include "common.h"
#include "config.h"
#include "mboxd.h"
#include "pnor_partition_table.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
#include <phosphor-logging/elog-errors.hpp>
#include <syslog.h>
#include <endian.h>
#include <regex>
#include <fstream>
#include <syslog.h>
#include <algorithm>
#include <fstream>
#include <phosphor-logging/elog-errors.hpp>
#include <regex>
#include "common.h"
#include "mboxd.h"
namespace openpower
{
......
......@@ -2,10 +2,11 @@
/* Copyright (C) 2018 IBM Corp. */
#pragma once
#include <vector>
#include <experimental/filesystem>
#include <memory>
#include <numeric>
#include <experimental/filesystem>
#include <vector>
#include "common.h"
#include "pnor_partition_defs.h"
......@@ -52,7 +53,8 @@ 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");
......
......@@ -11,16 +11,16 @@ extern "C" {
#include "vpnor/pnor_partition_table.hpp"
/* XXX: Maybe this should be a method on a class? */
static bool vpnor_partition_is_readonly(const pnor_partition &part)
static bool vpnor_partition_is_readonly(const pnor_partition& part)
{
return part.data.user.data[1] & PARTITION_READONLY;
}
typedef int (*create_window_fn)(struct mbox_context *context,
struct protocol_create_window *io);
typedef int (*create_window_fn)(struct mbox_context* context,
struct protocol_create_window* io);
static int generic_vpnor_create_window(struct mbox_context *context,
struct protocol_create_window *io,
static int generic_vpnor_create_window(struct mbox_context* context,
struct protocol_create_window* io,
create_window_fn create_window)
{
if (io->req.ro)
......@@ -33,13 +33,13 @@ static int generic_vpnor_create_window(struct mbox_context *context,
offset <<= context->block_size_shift;
try
{
const pnor_partition &part = context->vpnor->table->partition(offset);
const pnor_partition& part = context->vpnor->table->partition(offset);
if (vpnor_partition_is_readonly(part))
{
return -EPERM;
}
}
catch (const openpower::virtual_pnor::UnmappedOffset &e)
catch (const openpower::virtual_pnor::UnmappedOffset& e)
{
/*
* Writes to unmapped areas are not meaningful, so deny the request.
......@@ -52,14 +52,14 @@ static int generic_vpnor_create_window(struct mbox_context *context,
return create_window(context, io);
}
int protocol_v1_vpnor_create_window(struct mbox_context *context,
struct protocol_create_window *io)
int protocol_v1_vpnor_create_window(struct mbox_context* context,
struct protocol_create_window* io)
{
return generic_vpnor_create_window(context, io, protocol_v1_create_window);
}
int protocol_v2_vpnor_create_window(struct mbox_context *context,
struct protocol_create_window *io)
int protocol_v2_vpnor_create_window(struct mbox_context* context,
struct protocol_create_window* io)
{
return generic_vpnor_create_window(context, io, protocol_v2_create_window);
}
......@@ -36,13 +36,13 @@ static const struct protocol_ops protocol_ops_v2 = {
.ack = protocol_v1_ack,
};
static const struct protocol_ops *protocol_ops_map[] = {
static const struct protocol_ops* protocol_ops_map[] = {
[0] = NULL,
[1] = &protocol_ops_v1,
[2] = &protocol_ops_v2,
};
int protocol_negotiate_version(struct mbox_context *context, uint8_t requested)
int protocol_negotiate_version(struct mbox_context* context, uint8_t requested)
{
/* Check we support the version requested */
if (requested < API_MIN_VERSION)
......
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2018 IBM Corp.
#include <assert.h>
#include <string.h>
#include "config.h"
#include "vpnor/pnor_partition_table.hpp"
#include <assert.h>
#include <string.h>
extern "C" {
#include "test/mbox.h"
#include "test/system.h"
......
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2018 IBM Corp.
#include "config.h"
#include <assert.h>
#include <string.h>
#include "config.h"
#include "vpnor/mboxd_pnor_partition_table.h"
extern "C" {
......@@ -41,7 +42,7 @@ int main()
{
namespace test = openpower::virtual_pnor::test;
struct mbox_context *ctx;
struct mbox_context* ctx;
int rc;
system_set_reserved_size(MEM_SIZE);
......
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2018 IBM Corp.
#include "config.h"
#include <assert.h>
#include <string.h>
#include <experimental/filesystem>
#include <fstream>
#include <string.h>
#include <vector>
#include "config.h"
#include "vpnor/mboxd_pnor_partition_table.h"
extern "C" {
......@@ -47,7 +49,7 @@ namespace test = openpower::virtual_pnor::test;
int main()
{
struct mbox_context *ctx;
struct mbox_context* ctx;
system_set_reserved_size(MEM_SIZE);
system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
......
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2018 IBM Corp.
#include "config.h"
#include <assert.h>
#include <string.h>
#include "config.h"
#include "vpnor/mboxd_pnor_partition_table.h"
extern "C" {
......@@ -37,7 +38,7 @@ int main()
{
namespace test = openpower::virtual_pnor::test;
struct mbox_context *ctx;
struct mbox_context* ctx;
int rc;
system_set_reserved_size(MEM_SIZE);
......
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2018 IBM Corp.
#include "config.h"
#include <assert.h>
#include <string.h>
#include <experimental/filesystem>
#include <fstream>
#include <string.h>
#include <vector>
#include "config.h"
#include "vpnor/mboxd_pnor_partition_table.h"
extern "C" {
......@@ -41,7 +43,7 @@ int main()
uint8_t response[] = {0x04, 0x01, 0xe0, 0xff, 0x10, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
struct mbox_context *ctx;
struct mbox_context* ctx;
system_set_reserved_size(MEM_SIZE);
system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
......
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2018 IBM Corp.
#include "config.h"
#include <assert.h>
#include <experimental/filesystem>
#include "config.h"
#include "vpnor/mboxd_pnor_partition_table.h"
extern "C" {
......@@ -49,7 +51,7 @@ namespace test = openpower::virtual_pnor::test;
int main()
{
struct mbox_context *ctx;
struct mbox_context* ctx;
system_set_reserved_size(MEM_SIZE);
system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE);
......
......@@ -47,7 +47,7 @@ int main()
namespace test = openpower::virtual_pnor::test;
namespace fs = std::experimental::filesystem;
struct mbox_context *ctx;
struct mbox_context* ctx;
system_set_reserved_size(MEM_SIZE);
system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE);
......
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2018 IBM Corp.
#include <assert.h>
#include <sys/mman.h>
#include <string.h>
#include "config.h"
#include "vpnor/pnor_partition_table.hpp"
#include <assert.h>
#include <string.h>
#include <sys/mman.h>
extern "C" {
#include "test/mbox.h"
#include "test/system.h"
......
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2018 IBM Corp.
#include "config.h"
#include <assert.h>
#include "config.h"
#include "vpnor/mboxd_pnor_partition_table.h"
extern "C" {
......@@ -39,7 +40,7 @@ namespace test = openpower::virtual_pnor::test;
int main()
{
struct mbox_context *ctx;
struct mbox_context* ctx;
system_set_reserved_size(MEM_SIZE);
system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
......
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2018 IBM Corp.
#include "config.h"
#include <assert.h>
#include "config.h"
#include "vpnor/mboxd_pnor_partition_table.h"
extern "C" {
......@@ -39,7 +40,7 @@ namespace test = openpower::virtual_pnor::test;
int main()
{
struct mbox_context *ctx;
struct mbox_context* ctx;
system_set_reserved_size(MEM_SIZE);
system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
......
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2018 IBM Corp.
#include "config.h"
#include <assert.h>
#include "config.h"
#include "vpnor/mboxd_pnor_partition_table.h"
extern "C" {
......@@ -40,7 +41,7 @@ namespace test = openpower::virtual_pnor::test;
int main()
{
struct mbox_context *ctx;
struct mbox_context* ctx;
system_set_reserved_size(MEM_SIZE);
system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE);
......
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2018 IBM Corp.
#include "config.h"
#include <assert.h>
#include <string.h>
#include "config.h"
#include "transport_mbox.h"
#include "vpnor/mboxd_pnor_partition_table.h"
......@@ -18,7 +19,7 @@ extern "C" {
struct test_context
{
uint8_t seq;
struct mbox_context *ctx;
struct mbox_context* ctx;
};
// Configure the system and the paritions such that we eventually request a
......@@ -41,7 +42,7 @@ static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
static constexpr auto MBOX_CREATE_READ_WINDOW = 4;
static int mbox_create_read_window(struct test_context *tctx, size_t offset,
static int mbox_create_read_window(struct test_context* tctx, size_t offset,
size_t len)
{
union mbox_regs regs;
......
......@@ -2,11 +2,12 @@
// Copyright (C) 2018 IBM Corp.
#include "config.h"
#include "common.h"
#include "vpnor/mboxd_pnor_partition_table.h"
#include <assert.h>
#include "common.h"
#include "vpnor/mboxd_pnor_partition_table.h"
extern "C" {
#include "test/mbox.h"
#include "test/system.h"
......@@ -42,7 +43,7 @@ int main()
{
namespace test = openpower::virtual_pnor::test;
struct mbox_context *ctx;
struct mbox_context* ctx;
system_set_reserved_size(MEM_SIZE);
system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE);
......
......@@ -12,7 +12,7 @@ namespace test
namespace fs = std::experimental::filesystem;
size_t VpnorRoot::write(const std::string &name, const void *data, size_t len)
size_t VpnorRoot::write(const std::string& name, const void* data, size_t len)
{
// write() is for test environment setup - always write to ro section
fs::path path = root / "ro" / name;
......@@ -21,18 +21,18 @@ size_t VpnorRoot::write(const std::string &name, const void *data, size_t len)
/* It's not in the ToC */
throw std::invalid_argument(name);
std::ofstream(path).write((const char *)data, len);
std::ofstream(path).write((const char*)data, len);
return len;
}
size_t VpnorRoot::patch(const std::string &name, const void *data, size_t len)
size_t VpnorRoot::patch(const std::string& name, const void* data, size_t len)
{
if (!fs::exists(root / "ro" / name))
/* It's not in the ToC */
throw std::invalid_argument(name);
std::ofstream(root / "patch" / name).write((const char *)data, len);
std::ofstream(root / "patch" / name).write((const char*)data, len);
return len;