MCPcopy Create free account
hub / github.com/OpenHD/OpenHD / internal_discover_platform

Function internal_discover_platform

OpenHD/ohd_common/src/openhd_platform.cpp:44–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42static constexpr auto QUALCOMM_BOARDID_PATH = "/proc/device-tree/model";
43
44static int internal_discover_platform() {
45 openhd::log::get_default()->warn("OpenHD Platform Discovery started!");
46
47 if (OHDFilesystemUtil::exists("/proc/device-tree/model")) {
48 const std::string model_content =
49 OHDFilesystemUtil::read_file("/proc/device-tree/model");
50 if (OHDUtil::contains_after_uppercase(model_content, "ORQA")) {
51 openhd::log::get_default()->warn("Detected Willy platform.");
52 return X_PLATFORM_TYPE_WILLY;
53 }
54 }
55 if (OHDFilesystemUtil::exists(ALLWINNER_BOARDID_PATH)) {
56 openhd::log::get_default()->warn("Detected Allwinner platform (X20).");
57 return X_PLATFORM_TYPE_ALWINNER_X20;
58 }
59
60 if (OHDFilesystemUtil::exists("/boot/config.txt")) {
61 openhd::log::get_default()->warn(
62 "Detected potential Raspberry Pi platform.");
63 const auto filename_proc_cpuinfo = "/proc/cpuinfo";
64 const auto proc_cpuinfo_opt =
65 OHDFilesystemUtil::opt_read_file("/proc/cpuinfo");
66
67 if (!proc_cpuinfo_opt.has_value()) {
68 openhd::log::get_default()->warn(
69 "File {} does not exist. Unable to complete Raspberry Pi detection.",
70 filename_proc_cpuinfo);
71 return X_PLATFORM_TYPE_RPI_OLD;
72 }
73
74 openhd::log::get_default()->warn("Checking Raspberry Pi hardware...");
75 if (OHDUtil::contains(proc_cpuinfo_opt.value(), "BCM2711")) {
76 openhd::log::get_default()->warn("Raspberry Pi 4 detected.");
77 return X_PLATFORM_TYPE_RPI_4;
78 }
79
80 openhd::log::get_default()->warn("Detected an older Raspberry Pi (<=3).");
81 return X_PLATFORM_TYPE_RPI_OLD;
82 }
83
84 if (OHDFilesystemUtil::exists(SIGMASTAR_BOARDID_PATH)) {
85 openhd::log::get_default()->warn("Detected SigmaStar platform.");
86 return X_PLATFORM_TYPE_OPENIPC_SIGMASTAR_UNDEFINED;
87 }
88
89 if (OHDFilesystemUtil::exists(DEVICE_TREE_COMPATIBLE_PATH)) {
90 openhd::log::get_default()->warn("Checking for Rockchip platforms...");
91
92 const std::string compatible_content =
93 OHDFilesystemUtil::read_file(DEVICE_TREE_COMPATIBLE_PATH);
94 const std::string device_tree_model =
95 OHDFilesystemUtil::read_file("/proc/device-tree/model");
96 std::regex r("rockchip,(r[kv][0-9]+)");
97 std::smatch sm;
98
99 if (regex_search(compatible_content, sm, r)) {
100 const std::string chip = sm[1];
101 openhd::log::get_default()->warn("Rockchip chip identified: {}", chip);

Callers 1

Calls 2

contains_after_uppercaseFunction · 0.85
containsFunction · 0.85

Tested by

no test coverage detected