summaryrefslogtreecommitdiffstats
path: root/init/util.cpp
diff options
context:
space:
mode:
authorYu Ning <yu.ning@intel.com>2017-07-26 17:54:08 +0800
committerYu Ning <yu.ning@intel.com>2017-07-28 11:10:48 +0800
commitc01022a62e6517b1e7ea7231305a0ab996bd2964 (patch)
treee69b4b58ddfc7435a31956864fc3fa1c561f543a /init/util.cpp
parent603cae8b4812c21b92f559d190c7d21534dbeef7 (diff)
downloadsystem_core-c01022a62e6517b1e7ea7231305a0ab996bd2964.tar.gz
system_core-c01022a62e6517b1e7ea7231305a0ab996bd2964.tar.bz2
system_core-c01022a62e6517b1e7ea7231305a0ab996bd2964.zip
Allow the use of a custom Android DT directory
On platforms that use ACPI instead of Device Tree (DT), such as Ranchu x86/x86_64, /proc/device-tree/firmware/android/ does not exist. As a result, Android O is unable to mount /system, etc. at the first stage of init: init: First stage mount skipped (missing/incompatible fstab in device tree) Those platforms may create another directory that mimics the layout of the standard DT directory in procfs, and store early mount configuration there. E.g., Ranchu x86/x86_64 creates one in sysfs using information encoded in the ACPI tables: https://android-review.googlesource.com/442472 https://android-review.googlesource.com/443432 https://android-review.googlesource.com/442393 https://android-review.googlesource.com/442395 Therefore, instead of hardcoding the Android DT path, load it from the kernel command line using a new Android-specific property key ("androidboot.android_dt_dir"). If no such property exists, fall back to the standard procfs path (so no change is needed for DT- aware platforms). Note that init/ and fs_mgr/ each have their own copy of the Android DT path, because they do not share any global state. A future CL should remove the duplication by refactoring. With this CL as well as the above ones, the said warning is gone, but early mount fails. That is a separate bug, though, and will be addressed by another CL. Test: Boot patched sdk_phone_x86-userdebug system image with patched Goldfish 3.18 x86 kernel in patched Android Emulator, verify the "init: First stage mount skipped" warning no longer shows in dmesg. Change-Id: Ib6df577319503ec1ca778de2b5458cc72ce07415 Signed-off-by: Yu Ning <yu.ning@intel.com>
Diffstat (limited to 'init/util.cpp')
-rw-r--r--init/util.cpp27
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.