bootctrl: run clang-format

Bug: 156694052
Signed-off-by: Fernando Lugo <flugo@google.com>
Change-Id: I003fb99e96bcee2d745365992b3c8d4a3816f818
This commit is contained in:
Fernando Lugo 2021-03-08 15:36:55 -08:00
parent fa50bf6c7c
commit 2b75765719
5 changed files with 53 additions and 54 deletions

View file

@ -17,16 +17,15 @@
#define LOG_TAG "bootcontrolhal"
#include "BootControl.h"
#include "GptUtils.h"
#include <android-base/file.h>
#include <android-base/unique_fd.h>
#include <bootloader_message/bootloader_message.h>
#include <cutils/properties.h>
//#include <hardware/boot_control.h>
#include <libboot_control/libboot_control.h>
#include <log/log.h>
#include "GptUtils.h"
namespace android {
namespace hardware {
@ -37,12 +36,14 @@ namespace implementation {
using android::bootable::GetMiscVirtualAbMergeStatus;
using android::bootable::InitMiscVirtualAbMessageIfNeeded;
using android::bootable::SetMiscVirtualAbMergeStatus;
using android::hardware::boot::V1_1::MergeStatus;
using android::hardware::boot::V1_0::CommandResult;
using android::hardware::boot::V1_0::BoolResult;
using android::hardware::boot::V1_0::CommandResult;
using android::hardware::boot::V1_1::MergeStatus;
namespace {
// clang-format off
#define BOOT_A_PATH "/dev/block/by-name/boot_a"
#define BOOT_B_PATH "/dev/block/by-name/boot_b"
@ -59,6 +60,8 @@ namespace {
#define AB_ATTR_MAX_PRIORITY 3UL
#define AB_ATTR_MAX_RETRY_COUNT 3UL
// clang-format on
static std::string getDevPath(uint32_t slot) {
char real_path[PATH_MAX];
@ -122,7 +125,7 @@ static int setSlotFlag(uint32_t slot, uint64_t flag) {
return 0;
}
}
} // namespace
// Methods from ::android::hardware::boot::V1_0::IBootControl follow.
Return<uint32_t> BootControl::getNumberSlots() {
@ -189,14 +192,14 @@ Return<void> BootControl::setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb
return Void();
}
std::string boot_lun_path = std::string("/sys/devices/platform/") +
boot_dev + "/pixel/boot_lun_enabled";
std::string boot_lun_path =
std::string("/sys/devices/platform/") + boot_dev + "/pixel/boot_lun_enabled";
int fd = open(boot_lun_path.c_str(), O_RDWR);
if (fd < 0) {
// Try old path for kernels < 5.4
// TODO: remove once kernel 4.19 support is deprecated
std::string boot_lun_path = std::string("/sys/devices/platform/") +
boot_dev + "/attributes/boot_lun_enabled";
std::string boot_lun_path =
std::string("/sys/devices/platform/") + boot_dev + "/attributes/boot_lun_enabled";
fd = open(boot_lun_path.c_str(), O_RDWR);
if (fd < 0) {
_hidl_cb({false, "failed to open ufs attr boot_lun_enabled"});
@ -257,7 +260,8 @@ Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotBootable(
return isSlotFlagSet(slot, AB_ATTR_UNBOOTABLE) ? BoolResult::FALSE : BoolResult::TRUE;
}
Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotMarkedSuccessful(uint32_t slot) {
Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotMarkedSuccessful(
uint32_t slot) {
if (getNumberSlots() == 0) {
// just return true so that we don't we another call trying to mark it as successful
// when there is no slots
@ -278,7 +282,8 @@ bool BootControl::Init() {
return InitMiscVirtualAbMessageIfNeeded();
}
Return<bool> BootControl::setSnapshotMergeStatus(::android::hardware::boot::V1_1::MergeStatus status) {
Return<bool> BootControl::setSnapshotMergeStatus(
::android::hardware::boot::V1_1::MergeStatus status) {
return SetMiscVirtualAbMergeStatus(getCurrentSlot(), status);
}
@ -300,8 +305,7 @@ Return<uint32_t> BootControl::getActiveBootSlot() {
// Methods from ::android::hidl::base::V1_0::IBase follow.
IBootControl* HIDL_FETCH_IBootControl(const char* /* name */) {
IBootControl *HIDL_FETCH_IBootControl(const char * /* name */) {
auto module = new BootControl();
module->Init();

View file

@ -26,16 +26,15 @@ namespace boot {
namespace V1_2 {
namespace implementation {
using ::android::sp;
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::sp;
struct BootControl : public IBootControl {
bool Init();
// Methods from ::android::hardware::boot::V1_0::IBootControl follow.
@ -45,22 +44,23 @@ struct BootControl : public IBootControl {
Return<void> setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) override;
Return<void> setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) override;
Return<::android::hardware::boot::V1_0::BoolResult> isSlotBootable(uint32_t slot) override;
Return<::android::hardware::boot::V1_0::BoolResult> isSlotMarkedSuccessful(uint32_t slot) override;
Return<::android::hardware::boot::V1_0::BoolResult> isSlotMarkedSuccessful(
uint32_t slot) override;
Return<void> getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) override;
// Methods from ::android::hardware::boot::V1_1::IBootControl follow.
Return<bool> setSnapshotMergeStatus(::android::hardware::boot::V1_1::MergeStatus status) override;
Return<bool> setSnapshotMergeStatus(
::android::hardware::boot::V1_1::MergeStatus status) override;
Return<::android::hardware::boot::V1_1::MergeStatus> getSnapshotMergeStatus() override;
// Methods from ::android::hardware::boot::V1_2::IBootControl follow.
Return<uint32_t> getActiveBootSlot() override;
// Methods from ::android::hidl::base::V1_0::IBase follow.
};
// FIXME: most likely delete, this is only for passthrough implementations
extern "C" IBootControl* HIDL_FETCH_IBootControl(const char* name);
extern "C" IBootControl *HIDL_FETCH_IBootControl(const char *name);
} // namespace implementation
} // namespace V1_2

View file

@ -18,10 +18,10 @@
#include "GptUtils.h"
#include <errno.h>
#include <log/log.h>
#include <android-base/file.h>
#include <errno.h>
#include <linux/fs.h>
#include <log/log.h>
#include <zlib.h>
namespace android {
@ -32,8 +32,7 @@ namespace implementation {
namespace {
static int ValidateGptHeader(gpt_header *gpt)
{
static int ValidateGptHeader(gpt_header *gpt) {
if (gpt->signature != GPT_SIGNATURE) {
ALOGE("invalid gpt signature 0x%lx\n", gpt->signature);
return -1;
@ -52,12 +51,11 @@ static int ValidateGptHeader(gpt_header *gpt)
return 0;
}
}
} // namespace
GptUtils::GptUtils(const std::string dev_path) : dev_path(dev_path), fd(0) {}
int GptUtils::Load(void)
{
int GptUtils::Load(void) {
fd = open(dev_path.c_str(), O_RDWR);
if (fd < 0) {
ALOGE("failed to open block dev %s, %d\n", dev_path.c_str(), errno);
@ -108,12 +106,11 @@ int GptUtils::Load(void)
// Create map <partition name, gpt_entry pointer>
auto get_name = [](const uint16_t *efi_name) {
char name[37] = {};
for (int i = 0; efi_name[i] && i < sizeof name - 1; ++i)
name[i] = efi_name[i];
for (int i = 0; efi_name[i] && i < sizeof name - 1; ++i) name[i] = efi_name[i];
return std::string(name);
};
for (auto const &e: entry_array) {
for (auto const &e : entry_array) {
if (e.name[0] == 0)
break; // stop at the first partition with no name
std::string s = get_name(e.name);
@ -123,13 +120,11 @@ int GptUtils::Load(void)
return 0;
}
gpt_entry *GptUtils::GetPartitionEntry(std::string name)
{
gpt_entry *GptUtils::GetPartitionEntry(std::string name) {
return entries.find(name) != entries.end() ? entries[name] : nullptr;
}
int GptUtils::Sync(void)
{
int GptUtils::Sync(void) {
if (!fd)
return -1;
@ -161,7 +156,7 @@ int GptUtils::Sync(void)
return -1;
}
//update GPT backup entries and backup
// update GPT backup entries and backup
lseek64(fd, block_size * gpt_backup.start_lba, SEEK_SET);
ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry));
if (ret < 0) {
@ -184,8 +179,7 @@ int GptUtils::Sync(void)
return 0;
}
GptUtils::~GptUtils()
{
GptUtils::~GptUtils() {
if (fd) {
Sync();
close(fd);

View file

@ -16,9 +16,9 @@
#pragma once
#include <map>
#include <string>
#include <vector>
#include <map>
namespace android {
namespace hardware {
@ -69,7 +69,7 @@ class GptUtils {
gpt_header gpt_primary;
gpt_header gpt_backup;
std::vector<gpt_entry> entry_array;
std::map<std::string, gpt_entry *>entries;
std::map<std::string, gpt_entry *> entries;
};
} // namespace implementation

View file

@ -16,10 +16,11 @@
#define LOG_TAG "android.hardware.boot@1.2-service"
#include <log/log.h>
#include <android/hardware/boot/1.2/IBootControl.h>
#include <hidl/HidlTransportSupport.h>
#include <hidl/Status.h>
#include <android/hardware/boot/1.2/IBootControl.h>
#include <log/log.h>
#include "BootControl.h"
using ::android::status_t;
@ -27,9 +28,9 @@ using ::android::status_t;
using ::android::hardware::boot::V1_2::IBootControl;
using ::android::hardware::boot::V1_2::implementation::BootControl;
//using ::android::hardware::boot::implementation::BootControl;
// using ::android::hardware::boot::implementation::BootControl;
int main (int /* argc */, char * /* argv */ []) {
int main(int /* argc */, char * /* argv */[]) {
// This function must be called before you join to ensure the proper
// number of threads are created. The threadpool will never exceed
// size one because of this call.