2021-06-08 14:46:22 -06:00
|
|
|
#include <cassert>
|
2021-01-19 13:16:12 -07:00
|
|
|
#include <string>
|
2021-05-08 23:15:17 -06:00
|
|
|
|
|
|
|
#include "cereal/messaging/messaging.h"
|
|
|
|
#include "selfdrive/common/swaglog.h"
|
|
|
|
#include "selfdrive/loggerd/logger.h"
|
2021-02-02 04:07:52 -07:00
|
|
|
|
2021-11-10 08:07:22 -07:00
|
|
|
|
2021-02-02 04:07:52 -07:00
|
|
|
static kj::Array<capnp::word> build_boot_log() {
|
2021-11-10 08:07:22 -07:00
|
|
|
std::vector<std::string> bootlog_commands;
|
|
|
|
if (Hardware::TICI()) {
|
|
|
|
bootlog_commands.push_back("journalctl");
|
|
|
|
bootlog_commands.push_back("sudo nvme smart-log --output-format=json /dev/nvme0");
|
2021-12-14 12:54:54 -07:00
|
|
|
} else if (Hardware::EON()) {
|
|
|
|
bootlog_commands.push_back("logcat -d");
|
2021-11-10 08:07:22 -07:00
|
|
|
}
|
|
|
|
|
2021-02-02 04:07:52 -07:00
|
|
|
MessageBuilder msg;
|
|
|
|
auto boot = msg.initEvent().initBoot();
|
|
|
|
|
|
|
|
boot.setWallTimeNanos(nanos_since_epoch());
|
|
|
|
|
2021-05-12 03:15:54 -06:00
|
|
|
std::string pstore = "/sys/fs/pstore";
|
2021-08-02 02:59:54 -06:00
|
|
|
std::map<std::string, std::string> pstore_map = util::read_files_in_dir(pstore);
|
2021-05-12 03:15:54 -06:00
|
|
|
|
|
|
|
int i = 0;
|
2022-01-24 22:15:14 -07:00
|
|
|
auto lpstore = boot.initPstore().initEntries(pstore_map.size());
|
2021-05-12 03:15:54 -06:00
|
|
|
for (auto& kv : pstore_map) {
|
|
|
|
auto lentry = lpstore[i];
|
|
|
|
lentry.setKey(kv.first);
|
|
|
|
lentry.setValue(capnp::Data::Reader((const kj::byte*)kv.second.data(), kv.second.size()));
|
|
|
|
i++;
|
|
|
|
}
|
2021-02-02 04:07:52 -07:00
|
|
|
|
2021-11-10 08:07:22 -07:00
|
|
|
// Gather output of commands
|
|
|
|
i = 0;
|
|
|
|
auto commands = boot.initCommands().initEntries(bootlog_commands.size());
|
|
|
|
for (auto &command : bootlog_commands) {
|
|
|
|
auto lentry = commands[i];
|
|
|
|
|
|
|
|
lentry.setKey(command);
|
|
|
|
|
|
|
|
const std::string result = util::check_output(command);
|
|
|
|
lentry.setValue(capnp::Data::Reader((const kj::byte*)result.data(), result.size()));
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2021-08-19 14:49:08 -06:00
|
|
|
boot.setLaunchLog(util::read_file("/tmp/launch_log"));
|
2021-02-02 04:07:52 -07:00
|
|
|
return capnp::messageToFlatArray(msg);
|
|
|
|
}
|
2021-01-19 13:16:12 -07:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2021-02-02 04:09:27 -07:00
|
|
|
const std::string path = LOG_ROOT + "/boot/" + logger_get_route_name() + ".bz2";
|
2021-01-27 14:36:40 -07:00
|
|
|
LOGW("bootlog to %s", path.c_str());
|
|
|
|
|
|
|
|
// Open bootlog
|
2021-10-29 04:27:35 -06:00
|
|
|
bool r = util::create_directories(LOG_ROOT + "/boot/", 0775);
|
|
|
|
assert(r);
|
2021-01-19 13:16:12 -07:00
|
|
|
|
2021-02-01 22:00:42 -07:00
|
|
|
BZFile bz_file(path.c_str());
|
2021-01-19 13:16:12 -07:00
|
|
|
|
2021-01-27 14:36:40 -07:00
|
|
|
// Write initdata
|
2021-02-01 22:00:42 -07:00
|
|
|
bz_file.write(logger_build_init_data().asBytes());
|
2021-01-19 13:16:12 -07:00
|
|
|
|
2021-01-27 14:36:40 -07:00
|
|
|
// Write bootlog
|
2021-02-02 04:07:52 -07:00
|
|
|
bz_file.write(build_boot_log().asBytes());
|
2021-01-19 13:16:12 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|