Loading fs_mgr/fs_mgr_boot_config.cpp +24 −12 Original line number Diff line number Diff line Loading @@ -23,19 +23,11 @@ #include "fs_mgr_priv.h" // Tries to get the boot config value in properties, kernel cmdline and // device tree (in that order). returns 'true' if successfully found, 'false' // otherwise bool fs_mgr_get_boot_config(const std::string& key, std::string* out_val) { // Tries to get the given boot config value from kernel cmdline. // Returns true if successfully found, false otherwise. bool fs_mgr_get_boot_config_from_kernel_cmdline(const std::string& key, std::string* out_val) { FS_MGR_CHECK(out_val != nullptr); // first check if we have "ro.boot" property already *out_val = android::base::GetProperty("ro.boot." + key, ""); if (!out_val->empty()) { return true; } // fallback to kernel cmdline, properties may not be ready yet std::string cmdline; std::string cmdline_key("androidboot." + key); if (android::base::ReadFileToString("/proc/cmdline", &cmdline)) { Loading @@ -50,9 +42,29 @@ bool fs_mgr_get_boot_config(const std::string& key, std::string* out_val) { } } return false; } // Tries to get the boot config value in properties, kernel cmdline and // device tree (in that order). returns 'true' if successfully found, 'false' // otherwise bool fs_mgr_get_boot_config(const std::string& key, std::string* out_val) { FS_MGR_CHECK(out_val != nullptr); // first check if we have "ro.boot" property already *out_val = android::base::GetProperty("ro.boot." + key, ""); if (!out_val->empty()) { return true; } // fallback to kernel cmdline, properties may not be ready yet if (fs_mgr_get_boot_config_from_kernel_cmdline(key, out_val)) { return true; } // lastly, check the device tree if (is_dt_compatible()) { std::string file_name = kAndroidDtDir + "/" + key; std::string file_name = get_android_dt_dir() + "/" + key; if (android::base::ReadFileToString(file_name, out_val)) { if (!out_val->empty()) { out_val->pop_back(); // Trims the trailing '\0' out. Loading fs_mgr/fs_mgr_fstab.cpp +22 −3 Original line number Diff line number Diff line Loading @@ -29,6 +29,8 @@ #include "fs_mgr_priv.h" const std::string kDefaultAndroidDtDir("/proc/device-tree/firmware/android"); struct fs_mgr_flag_values { char *key_loc; char *verity_loc; Loading Loading @@ -313,9 +315,26 @@ static int parse_flags(char *flags, struct flag_list *fl, return f; } static std::string init_android_dt_dir() { std::string android_dt_dir; // The platform may specify a custom Android DT path in kernel cmdline if (!fs_mgr_get_boot_config_from_kernel_cmdline("android_dt_dir", &android_dt_dir)) { // Fall back to the standard procfs-based path android_dt_dir = kDefaultAndroidDtDir; } return android_dt_dir; } // FIXME: The same logic is duplicated in system/core/init/ 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; } static bool is_dt_fstab_compatible() { std::string dt_value; std::string file_name = kAndroidDtDir + "/fstab/compatible"; std::string file_name = get_android_dt_dir() + "/fstab/compatible"; if (read_dt_file(file_name, &dt_value)) { if (dt_value == "android,fstab") { return true; Loading @@ -331,7 +350,7 @@ static std::string read_fstab_from_dt() { return fstab; } std::string fstabdir_name = kAndroidDtDir + "/fstab"; std::string fstabdir_name = get_android_dt_dir() + "/fstab"; std::unique_ptr<DIR, int (*)(DIR*)> fstabdir(opendir(fstabdir_name.c_str()), closedir); if (!fstabdir) return fstab; Loading Loading @@ -394,7 +413,7 @@ static std::string read_fstab_from_dt() { } bool is_dt_compatible() { std::string file_name = kAndroidDtDir + "/compatible"; std::string file_name = get_android_dt_dir() + "/compatible"; std::string dt_value; if (read_dt_file(file_name, &dt_value)) { if (dt_value == "android,firmware") { Loading fs_mgr/fs_mgr_priv.h +1 −0 Original line number Diff line number Diff line Loading @@ -119,6 +119,7 @@ bool fs_mgr_wait_for_file(const std::string& filename, const std::chrono::milliseconds relative_timeout); bool fs_mgr_update_for_slotselect(struct fstab *fstab); bool fs_mgr_is_device_unlocked(); const std::string& get_android_dt_dir(); bool is_dt_compatible(); bool is_device_secure(); int load_verity_state(struct fstab_rec* fstab, int* mode); Loading fs_mgr/fs_mgr_priv_boot_config.h +1 −2 Original line number Diff line number Diff line Loading @@ -20,8 +20,7 @@ #include <sys/cdefs.h> #include <string> const std::string kAndroidDtDir("/proc/device-tree/firmware/android"); bool fs_mgr_get_boot_config_from_kernel_cmdline(const std::string& key, std::string* out_val); bool fs_mgr_get_boot_config(const std::string& key, std::string* out_val); #endif /* __CORE_FS_MGR_PRIV_BOOTCONFIG_H */ init/init.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -543,7 +543,7 @@ static void process_kernel_dt() { return; } std::unique_ptr<DIR, int (*)(DIR*)> dir(opendir(kAndroidDtDir.c_str()), closedir); std::unique_ptr<DIR, int (*)(DIR*)> dir(opendir(get_android_dt_dir().c_str()), closedir); if (!dir) return; std::string dt_file; Loading @@ -553,7 +553,7 @@ static void process_kernel_dt() { continue; } std::string file_name = kAndroidDtDir + dp->d_name; std::string file_name = get_android_dt_dir() + dp->d_name; android::base::ReadFileToString(file_name, &dt_file); std::replace(dt_file.begin(), dt_file.end(), ',', '.'); Loading Loading
fs_mgr/fs_mgr_boot_config.cpp +24 −12 Original line number Diff line number Diff line Loading @@ -23,19 +23,11 @@ #include "fs_mgr_priv.h" // Tries to get the boot config value in properties, kernel cmdline and // device tree (in that order). returns 'true' if successfully found, 'false' // otherwise bool fs_mgr_get_boot_config(const std::string& key, std::string* out_val) { // Tries to get the given boot config value from kernel cmdline. // Returns true if successfully found, false otherwise. bool fs_mgr_get_boot_config_from_kernel_cmdline(const std::string& key, std::string* out_val) { FS_MGR_CHECK(out_val != nullptr); // first check if we have "ro.boot" property already *out_val = android::base::GetProperty("ro.boot." + key, ""); if (!out_val->empty()) { return true; } // fallback to kernel cmdline, properties may not be ready yet std::string cmdline; std::string cmdline_key("androidboot." + key); if (android::base::ReadFileToString("/proc/cmdline", &cmdline)) { Loading @@ -50,9 +42,29 @@ bool fs_mgr_get_boot_config(const std::string& key, std::string* out_val) { } } return false; } // Tries to get the boot config value in properties, kernel cmdline and // device tree (in that order). returns 'true' if successfully found, 'false' // otherwise bool fs_mgr_get_boot_config(const std::string& key, std::string* out_val) { FS_MGR_CHECK(out_val != nullptr); // first check if we have "ro.boot" property already *out_val = android::base::GetProperty("ro.boot." + key, ""); if (!out_val->empty()) { return true; } // fallback to kernel cmdline, properties may not be ready yet if (fs_mgr_get_boot_config_from_kernel_cmdline(key, out_val)) { return true; } // lastly, check the device tree if (is_dt_compatible()) { std::string file_name = kAndroidDtDir + "/" + key; std::string file_name = get_android_dt_dir() + "/" + key; if (android::base::ReadFileToString(file_name, out_val)) { if (!out_val->empty()) { out_val->pop_back(); // Trims the trailing '\0' out. Loading
fs_mgr/fs_mgr_fstab.cpp +22 −3 Original line number Diff line number Diff line Loading @@ -29,6 +29,8 @@ #include "fs_mgr_priv.h" const std::string kDefaultAndroidDtDir("/proc/device-tree/firmware/android"); struct fs_mgr_flag_values { char *key_loc; char *verity_loc; Loading Loading @@ -313,9 +315,26 @@ static int parse_flags(char *flags, struct flag_list *fl, return f; } static std::string init_android_dt_dir() { std::string android_dt_dir; // The platform may specify a custom Android DT path in kernel cmdline if (!fs_mgr_get_boot_config_from_kernel_cmdline("android_dt_dir", &android_dt_dir)) { // Fall back to the standard procfs-based path android_dt_dir = kDefaultAndroidDtDir; } return android_dt_dir; } // FIXME: The same logic is duplicated in system/core/init/ 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; } static bool is_dt_fstab_compatible() { std::string dt_value; std::string file_name = kAndroidDtDir + "/fstab/compatible"; std::string file_name = get_android_dt_dir() + "/fstab/compatible"; if (read_dt_file(file_name, &dt_value)) { if (dt_value == "android,fstab") { return true; Loading @@ -331,7 +350,7 @@ static std::string read_fstab_from_dt() { return fstab; } std::string fstabdir_name = kAndroidDtDir + "/fstab"; std::string fstabdir_name = get_android_dt_dir() + "/fstab"; std::unique_ptr<DIR, int (*)(DIR*)> fstabdir(opendir(fstabdir_name.c_str()), closedir); if (!fstabdir) return fstab; Loading Loading @@ -394,7 +413,7 @@ static std::string read_fstab_from_dt() { } bool is_dt_compatible() { std::string file_name = kAndroidDtDir + "/compatible"; std::string file_name = get_android_dt_dir() + "/compatible"; std::string dt_value; if (read_dt_file(file_name, &dt_value)) { if (dt_value == "android,firmware") { Loading
fs_mgr/fs_mgr_priv.h +1 −0 Original line number Diff line number Diff line Loading @@ -119,6 +119,7 @@ bool fs_mgr_wait_for_file(const std::string& filename, const std::chrono::milliseconds relative_timeout); bool fs_mgr_update_for_slotselect(struct fstab *fstab); bool fs_mgr_is_device_unlocked(); const std::string& get_android_dt_dir(); bool is_dt_compatible(); bool is_device_secure(); int load_verity_state(struct fstab_rec* fstab, int* mode); Loading
fs_mgr/fs_mgr_priv_boot_config.h +1 −2 Original line number Diff line number Diff line Loading @@ -20,8 +20,7 @@ #include <sys/cdefs.h> #include <string> const std::string kAndroidDtDir("/proc/device-tree/firmware/android"); bool fs_mgr_get_boot_config_from_kernel_cmdline(const std::string& key, std::string* out_val); bool fs_mgr_get_boot_config(const std::string& key, std::string* out_val); #endif /* __CORE_FS_MGR_PRIV_BOOTCONFIG_H */
init/init.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -543,7 +543,7 @@ static void process_kernel_dt() { return; } std::unique_ptr<DIR, int (*)(DIR*)> dir(opendir(kAndroidDtDir.c_str()), closedir); std::unique_ptr<DIR, int (*)(DIR*)> dir(opendir(get_android_dt_dir().c_str()), closedir); if (!dir) return; std::string dt_file; Loading @@ -553,7 +553,7 @@ static void process_kernel_dt() { continue; } std::string file_name = kAndroidDtDir + dp->d_name; std::string file_name = get_android_dt_dir() + dp->d_name; android::base::ReadFileToString(file_name, &dt_file); std::replace(dt_file.begin(), dt_file.end(), ',', '.'); Loading