diff options
Diffstat (limited to 'init/util.cpp')
-rw-r--r-- | init/util.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/init/util.cpp b/init/util.cpp index 2792794c5..fdcb22d1c 100644 --- a/init/util.cpp +++ b/init/util.cpp @@ -53,6 +53,8 @@ using namespace std::literals::string_literals; namespace android { namespace init { +const std::string kDefaultAndroidDtDir("/proc/device-tree/firmware/android/"); + // DecodeUid() - decodes and returns the given string, which can be either the // numeric or name representation, into the integer uid or gid. Returns // UINT_MAX on error. @@ -374,10 +376,31 @@ void panic() { DoReboot(ANDROID_RB_RESTART2, "reboot", "bootloader", false); } -// Reads the content of device tree file under kAndroidDtDir directory. +static std::string init_android_dt_dir() { + // Use the standard procfs-based path by default + std::string android_dt_dir = kDefaultAndroidDtDir; + // The platform may specify a custom Android DT path in kernel cmdline + import_kernel_cmdline(false, + [&](const std::string& key, const std::string& value, bool in_qemu) { + if (key == "androidboot.android_dt_dir") { + android_dt_dir = value; + } + }); + LOG(INFO) << "Using Android DT directory " << android_dt_dir; + return android_dt_dir; +} + +// FIXME: The same logic is duplicated in system/core/fs_mgr/ +const std::string& get_android_dt_dir() { + // Set once and saves time for subsequent calls to this function + static const std::string kAndroidDtDir = init_android_dt_dir(); + return kAndroidDtDir; +} + +// Reads the content of device tree file under the platform's Android DT directory. // Returns true if the read is success, false otherwise. bool read_android_dt_file(const std::string& sub_path, std::string* dt_content) { - const std::string file_name = kAndroidDtDir + sub_path; + const std::string file_name = get_android_dt_dir() + sub_path; if (android::base::ReadFileToString(file_name, dt_content)) { if (!dt_content->empty()) { dt_content->pop_back(); // Trims the trailing '\0' out. |