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

View file

@ -26,16 +26,15 @@ namespace boot {
namespace V1_2 { namespace V1_2 {
namespace implementation { namespace implementation {
using ::android::sp;
using ::android::hardware::hidl_array; using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory; using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string; using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec; using ::android::hardware::hidl_vec;
using ::android::hardware::Return; using ::android::hardware::Return;
using ::android::hardware::Void; using ::android::hardware::Void;
using ::android::sp;
struct BootControl : public IBootControl { struct BootControl : public IBootControl {
bool Init(); bool Init();
// Methods from ::android::hardware::boot::V1_0::IBootControl follow. // Methods from ::android::hardware::boot::V1_0::IBootControl follow.
@ -45,18 +44,19 @@ struct BootControl : public IBootControl {
Return<void> setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) override; Return<void> setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) override;
Return<void> setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_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> 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; Return<void> getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) override;
// Methods from ::android::hardware::boot::V1_1::IBootControl follow. // 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; Return<::android::hardware::boot::V1_1::MergeStatus> getSnapshotMergeStatus() override;
// Methods from ::android::hardware::boot::V1_2::IBootControl follow. // Methods from ::android::hardware::boot::V1_2::IBootControl follow.
Return<uint32_t> getActiveBootSlot() override; Return<uint32_t> getActiveBootSlot() override;
// Methods from ::android::hidl::base::V1_0::IBase follow. // Methods from ::android::hidl::base::V1_0::IBase follow.
}; };
// FIXME: most likely delete, this is only for passthrough implementations // FIXME: most likely delete, this is only for passthrough implementations

View file

@ -18,10 +18,10 @@
#include "GptUtils.h" #include "GptUtils.h"
#include <errno.h>
#include <log/log.h>
#include <android-base/file.h> #include <android-base/file.h>
#include <errno.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <log/log.h>
#include <zlib.h> #include <zlib.h>
namespace android { namespace android {
@ -32,8 +32,7 @@ namespace implementation {
namespace { namespace {
static int ValidateGptHeader(gpt_header *gpt) static int ValidateGptHeader(gpt_header *gpt) {
{
if (gpt->signature != GPT_SIGNATURE) { if (gpt->signature != GPT_SIGNATURE) {
ALOGE("invalid gpt signature 0x%lx\n", gpt->signature); ALOGE("invalid gpt signature 0x%lx\n", gpt->signature);
return -1; return -1;
@ -52,12 +51,11 @@ static int ValidateGptHeader(gpt_header *gpt)
return 0; return 0;
} }
} } // namespace
GptUtils::GptUtils(const std::string dev_path) : dev_path(dev_path), fd(0) {} 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); fd = open(dev_path.c_str(), O_RDWR);
if (fd < 0) { if (fd < 0) {
ALOGE("failed to open block dev %s, %d\n", dev_path.c_str(), errno); ALOGE("failed to open block dev %s, %d\n", dev_path.c_str(), errno);
@ -108,8 +106,7 @@ int GptUtils::Load(void)
// Create map <partition name, gpt_entry pointer> // Create map <partition name, gpt_entry pointer>
auto get_name = [](const uint16_t *efi_name) { auto get_name = [](const uint16_t *efi_name) {
char name[37] = {}; char name[37] = {};
for (int i = 0; efi_name[i] && i < sizeof name - 1; ++i) for (int i = 0; efi_name[i] && i < sizeof name - 1; ++i) name[i] = efi_name[i];
name[i] = efi_name[i];
return std::string(name); return std::string(name);
}; };
@ -123,13 +120,11 @@ int GptUtils::Load(void)
return 0; 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; return entries.find(name) != entries.end() ? entries[name] : nullptr;
} }
int GptUtils::Sync(void) int GptUtils::Sync(void) {
{
if (!fd) if (!fd)
return -1; return -1;
@ -184,8 +179,7 @@ int GptUtils::Sync(void)
return 0; return 0;
} }
GptUtils::~GptUtils() GptUtils::~GptUtils() {
{
if (fd) { if (fd) {
Sync(); Sync();
close(fd); close(fd);

View file

@ -16,9 +16,9 @@
#pragma once #pragma once
#include <map>
#include <string> #include <string>
#include <vector> #include <vector>
#include <map>
namespace android { namespace android {
namespace hardware { namespace hardware {

View file

@ -16,10 +16,11 @@
#define LOG_TAG "android.hardware.boot@1.2-service" #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/HidlTransportSupport.h>
#include <hidl/Status.h> #include <hidl/Status.h>
#include <android/hardware/boot/1.2/IBootControl.h> #include <log/log.h>
#include "BootControl.h" #include "BootControl.h"
using ::android::status_t; using ::android::status_t;