Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit afffa03f authored by David Anderson's avatar David Anderson Committed by Gerrit Code Review
Browse files

Merge "fastboot: Add a command to get current kernel logs."

parents 3be42ae5 ebc8fe19
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -79,3 +79,4 @@
#define FB_VAR_SECURITY_PATCH_LEVEL "security-patch-level"
#define FB_VAR_TREBLE_ENABLED "treble-enabled"
#define FB_VAR_MAX_FETCH_SIZE "max-fetch-size"
#define FB_VAR_DMESG "dmesg"
+54 −41
Original line number Diff line number Diff line
@@ -112,7 +112,6 @@ static void GetAllVars(FastbootDevice* device, const std::string& name,
    }
}

bool GetVarHandler(FastbootDevice* device, const std::vector<std::string>& args) {
const std::unordered_map<std::string, VariableHandlers> kVariableMap = {
        {FB_VAR_VERSION, {GetVersion, nullptr}},
        {FB_VAR_VERSION_BOOTLOADER, {GetBootloaderVersion, nullptr}},
@@ -150,14 +149,28 @@ bool GetVarHandler(FastbootDevice* device, const std::vector<std::string>& args)
        {FB_VAR_MAX_FETCH_SIZE, {GetMaxFetchSize, nullptr}},
};

static bool GetVarAll(FastbootDevice* device) {
    for (const auto& [name, handlers] : kVariableMap) {
        GetAllVars(device, name, handlers);
    }
    return true;
}

const std::unordered_map<std::string, std::function<bool(FastbootDevice*)>> kSpecialVars = {
        {"all", GetVarAll},
        {"dmesg", GetDmesg},
};

bool GetVarHandler(FastbootDevice* device, const std::vector<std::string>& args) {
    if (args.size() < 2) {
        return device->WriteFail("Missing argument");
    }

    // Special case: return all variables that we can.
    if (args[1] == "all") {
        for (const auto& [name, handlers] : kVariableMap) {
            GetAllVars(device, name, handlers);
    // "all" and "dmesg" are multiline and handled specially.
    auto found_special = kSpecialVars.find(args[1]);
    if (found_special != kSpecialVars.end()) {
        if (!found_special->second(device)) {
            return false;
        }
        return device->WriteOkay("");
    }
+36 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include "variables.h"

#include <inttypes.h>
#include <stdio.h>

#include <android-base/file.h>
#include <android-base/logging.h>
@@ -28,6 +29,7 @@
#include <fs_mgr.h>
#include <liblp/liblp.h>

#include "constants.h"
#include "fastboot_device.h"
#include "flashing.h"
#include "utility.h"
@@ -46,6 +48,7 @@ using ::android::hardware::fastboot::V1_0::Result;
using ::android::hardware::fastboot::V1_0::Status;
using IBootControl1_1 = ::android::hardware::boot::V1_1::IBootControl;
using namespace android::fs_mgr;
using namespace std::string_literals;

constexpr char kFastbootProtocolVersion[] = "0.4";

@@ -518,3 +521,36 @@ bool GetMaxFetchSize(FastbootDevice* /* device */, const std::vector<std::string
    *message = android::base::StringPrintf("0x%X", kMaxFetchSizeDefault);
    return true;
}

bool GetDmesg(FastbootDevice* device) {
    if (GetDeviceLockStatus()) {
        return device->WriteFail("Cannot use when device flashing is locked");
    }

    std::unique_ptr<FILE, decltype(&::fclose)> fp(popen("/system/bin/dmesg", "re"), ::fclose);
    if (!fp) {
        PLOG(ERROR) << "popen /system/bin/dmesg";
        return device->WriteFail("Unable to run dmesg: "s + strerror(errno));
    }

    ssize_t rv;
    size_t n = 0;
    char* str = nullptr;
    while ((rv = ::getline(&str, &n, fp.get())) > 0) {
        if (str[rv - 1] == '\n') {
            rv--;
        }
        device->WriteInfo(std::string(str, rv));
    }

    int saved_errno = errno;
    ::free(str);

    if (rv < 0 && saved_errno) {
        LOG(ERROR) << "dmesg getline: " << strerror(saved_errno);
        device->WriteFail("Unable to read dmesg: "s + strerror(saved_errno));
        return false;
    }

    return true;
}
+3 −0
Original line number Diff line number Diff line
@@ -83,6 +83,9 @@ bool GetTrebleEnabled(FastbootDevice* device, const std::vector<std::string>& ar
bool GetMaxFetchSize(FastbootDevice* /* device */, const std::vector<std::string>& /* args */,
                     std::string* message);

// Complex cases.
bool GetDmesg(FastbootDevice* device);

// Helpers for getvar all.
std::vector<std::vector<std::string>> GetAllPartitionArgsWithSlot(FastbootDevice* device);
std::vector<std::vector<std::string>> GetAllPartitionArgsNoSlot(FastbootDevice* device);