Merge "libsnapshot: Fix missing return keyword in error path." into main
diff --git a/bootstat/Android.bp b/bootstat/Android.bp
index ca59ef3..0c8760c 100644
--- a/bootstat/Android.bp
+++ b/bootstat/Android.bp
@@ -72,9 +72,6 @@
],
init_rc: ["bootstat.rc"],
product_variables: {
- pdk: {
- enabled: false,
- },
debuggable: {
init_rc: ["bootstat-debug.rc"],
},
diff --git a/fs_mgr/libfstab/boot_config.cpp b/fs_mgr/libfstab/boot_config.cpp
index 8fb28c6..53c843e 100644
--- a/fs_mgr/libfstab/boot_config.cpp
+++ b/fs_mgr/libfstab/boot_config.cpp
@@ -27,6 +27,92 @@
#include "fstab_priv.h"
#include "logging_macros.h"
+namespace android {
+namespace fs_mgr {
+
+const std::string& GetAndroidDtDir() {
+ // Set once and saves time for subsequent calls to this function
+ static const std::string kAndroidDtDir = [] {
+ std::string android_dt_dir;
+ if ((GetBootconfig("androidboot.android_dt_dir", &android_dt_dir) ||
+ fs_mgr_get_boot_config_from_kernel_cmdline("android_dt_dir", &android_dt_dir)) &&
+ !android_dt_dir.empty()) {
+ // Ensure the returned path ends with a /
+ if (android_dt_dir.back() != '/') {
+ android_dt_dir.push_back('/');
+ }
+ } else {
+ // Fall back to the standard procfs-based path
+ android_dt_dir = "/proc/device-tree/firmware/android/";
+ }
+ LINFO << "Using Android DT directory " << android_dt_dir;
+ return android_dt_dir;
+ }();
+ return kAndroidDtDir;
+}
+
+void ImportBootconfigFromString(const std::string& bootconfig,
+ const std::function<void(std::string, std::string)>& fn) {
+ for (std::string_view line : android::base::Split(bootconfig, "\n")) {
+ const auto equal_pos = line.find('=');
+ std::string key = android::base::Trim(line.substr(0, equal_pos));
+ if (key.empty()) {
+ continue;
+ }
+ std::string value;
+ if (equal_pos != line.npos) {
+ value = android::base::Trim(line.substr(equal_pos + 1));
+ // If the value is a comma-delimited list, the kernel would insert a space between the
+ // list elements when read from /proc/bootconfig.
+ // BoardConfig.mk:
+ // BOARD_BOOTCONFIG := key=value1,value2,value3
+ // /proc/bootconfig:
+ // key = "value1", "value2", "value3"
+ if (key == "androidboot.boot_device" || key == "androidboot.boot_devices") {
+ // boot_device[s] is a special case where a list element can contain comma and the
+ // caller expects a space-delimited list, so don't remove space here.
+ value.erase(std::remove(value.begin(), value.end(), '"'), value.end());
+ } else {
+ // In order to not break the expectations of existing code, we modify the value to
+ // keep the format consistent with the kernel cmdline by removing quote and space.
+ std::string_view sv(value);
+ android::base::ConsumePrefix(&sv, "\"");
+ android::base::ConsumeSuffix(&sv, "\"");
+ value = android::base::StringReplace(sv, R"(", ")", ",", true);
+ }
+ }
+ // "key" and "key =" means empty value.
+ fn(std::move(key), std::move(value));
+ }
+}
+
+bool GetBootconfigFromString(const std::string& bootconfig, const std::string& key,
+ std::string* out) {
+ bool found = false;
+ ImportBootconfigFromString(bootconfig, [&](std::string config_key, std::string value) {
+ if (!found && config_key == key) {
+ *out = std::move(value);
+ found = true;
+ }
+ });
+ return found;
+}
+
+void ImportBootconfig(const std::function<void(std::string, std::string)>& fn) {
+ std::string bootconfig;
+ android::base::ReadFileToString("/proc/bootconfig", &bootconfig);
+ ImportBootconfigFromString(bootconfig, fn);
+}
+
+bool GetBootconfig(const std::string& key, std::string* out) {
+ std::string bootconfig;
+ android::base::ReadFileToString("/proc/bootconfig", &bootconfig);
+ return GetBootconfigFromString(bootconfig, key, out);
+}
+
+} // namespace fs_mgr
+} // namespace android
+
std::vector<std::pair<std::string, std::string>> fs_mgr_parse_cmdline(const std::string& cmdline) {
static constexpr char quote = '"';
@@ -61,44 +147,6 @@
return result;
}
-std::vector<std::pair<std::string, std::string>> fs_mgr_parse_proc_bootconfig(
- const std::string& cmdline) {
- static constexpr char quote = '"';
-
- std::vector<std::pair<std::string, std::string>> result;
- for (auto& line : android::base::Split(cmdline, "\n")) {
- line.erase(std::remove(line.begin(), line.end(), quote), line.end());
- auto equal_sign = line.find('=');
- if (equal_sign == line.npos) {
- if (!line.empty()) {
- // no difference between <key> and <key>=
- result.emplace_back(std::move(line), "");
- }
- } else {
- result.emplace_back(android::base::Trim(line.substr(0, equal_sign)),
- android::base::Trim(line.substr(equal_sign + 1)));
- }
- }
-
- return result;
-}
-
-bool fs_mgr_get_boot_config_from_bootconfig(const std::string& bootconfig,
- const std::string& android_key, std::string* out_val) {
- FSTAB_CHECK(out_val != nullptr);
-
- const std::string bootconfig_key("androidboot." + android_key);
- for (const auto& [key, value] : fs_mgr_parse_proc_bootconfig(bootconfig)) {
- if (key == bootconfig_key) {
- *out_val = value;
- return true;
- }
- }
-
- *out_val = "";
- return false;
-}
-
bool fs_mgr_get_boot_config_from_kernel(const std::string& cmdline, const std::string& android_key,
std::string* out_val) {
FSTAB_CHECK(out_val != nullptr);
@@ -115,17 +163,6 @@
return false;
}
-// Tries to get the given boot config value from bootconfig.
-// Returns true if successfully found, false otherwise.
-bool fs_mgr_get_boot_config_from_bootconfig_source(const std::string& key, std::string* out_val) {
- std::string bootconfig;
- if (!android::base::ReadFileToString("/proc/bootconfig", &bootconfig)) return false;
- if (!bootconfig.empty() && bootconfig.back() == '\n') {
- bootconfig.pop_back();
- }
- return fs_mgr_get_boot_config_from_bootconfig(bootconfig, key, 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) {
@@ -145,7 +182,7 @@
// firstly, check the device tree
if (is_dt_compatible()) {
- std::string file_name = get_android_dt_dir() + "/" + key;
+ std::string file_name = android::fs_mgr::GetAndroidDtDir() + key;
if (android::base::ReadFileToString(file_name, out_val)) {
if (!out_val->empty()) {
out_val->pop_back(); // Trims the trailing '\0' out.
@@ -161,7 +198,8 @@
}
// next, check if we have the property in bootconfig
- if (fs_mgr_get_boot_config_from_bootconfig_source(key, out_val)) {
+ const std::string config_key = "androidboot." + key;
+ if (android::fs_mgr::GetBootconfig(config_key, out_val)) {
return true;
}
diff --git a/fs_mgr/libfstab/fstab.cpp b/fs_mgr/libfstab/fstab.cpp
index 5b5c3d2..3cbd8c8 100644
--- a/fs_mgr/libfstab/fstab.cpp
+++ b/fs_mgr/libfstab/fstab.cpp
@@ -51,7 +51,6 @@
namespace fs_mgr {
namespace {
-constexpr char kDefaultAndroidDtDir[] = "/proc/device-tree/firmware/android";
constexpr char kProcMountsPath[] = "/proc/mounts";
struct FlagList {
@@ -337,25 +336,14 @@
return true;
}
-std::string InitAndroidDtDir() {
- std::string android_dt_dir;
- // The platform may specify a custom Android DT path in kernel cmdline
- if (!fs_mgr_get_boot_config_from_bootconfig_source("android_dt_dir", &android_dt_dir) &&
- !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;
-}
-
bool IsDtFstabCompatible() {
std::string dt_value;
- std::string file_name = get_android_dt_dir() + "/fstab/compatible";
+ std::string file_name = GetAndroidDtDir() + "fstab/compatible";
if (ReadDtFile(file_name, &dt_value) && dt_value == "android,fstab") {
// If there's no status property or its set to "ok" or "okay", then we use the DT fstab.
std::string status_value;
- std::string status_file_name = get_android_dt_dir() + "/fstab/status";
+ std::string status_file_name = GetAndroidDtDir() + "fstab/status";
return !ReadDtFile(status_file_name, &status_value) || status_value == "ok" ||
status_value == "okay";
}
@@ -368,7 +356,7 @@
return {};
}
- std::string fstabdir_name = get_android_dt_dir() + "/fstab";
+ std::string fstabdir_name = GetAndroidDtDir() + "fstab";
std::unique_ptr<DIR, int (*)(DIR*)> fstabdir(opendir(fstabdir_name.c_str()), closedir);
if (!fstabdir) return {};
@@ -876,21 +864,19 @@
std::set<std::string> GetBootDevices() {
// First check bootconfig, then kernel commandline, then the device tree
- std::string dt_file_name = get_android_dt_dir() + "/boot_devices";
std::string value;
- if (fs_mgr_get_boot_config_from_bootconfig_source("boot_devices", &value) ||
- fs_mgr_get_boot_config_from_bootconfig_source("boot_device", &value)) {
+ if (GetBootconfig("androidboot.boot_devices", &value) ||
+ GetBootconfig("androidboot.boot_device", &value)) {
std::set<std::string> boot_devices;
- // remove quotes and split by spaces
- auto boot_device_strings = base::Split(base::StringReplace(value, "\"", "", true), " ");
- for (std::string_view device : boot_device_strings) {
- // trim the trailing comma, keep the rest.
+ // split by spaces and trim the trailing comma.
+ for (std::string_view device : android::base::Split(value, " ")) {
base::ConsumeSuffix(&device, ",");
boot_devices.emplace(device);
}
return boot_devices;
}
+ std::string dt_file_name = GetAndroidDtDir() + "boot_devices";
if (fs_mgr_get_boot_config_from_kernel_cmdline("boot_devices", &value) ||
ReadDtFile(dt_file_name, &value)) {
auto boot_devices = Split(value, ",");
@@ -948,15 +934,8 @@
} // namespace fs_mgr
} // namespace android
-// 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 = android::fs_mgr::InitAndroidDtDir();
- return kAndroidDtDir;
-}
-
bool is_dt_compatible() {
- std::string file_name = get_android_dt_dir() + "/compatible";
+ std::string file_name = android::fs_mgr::GetAndroidDtDir() + "compatible";
std::string dt_value;
if (android::fs_mgr::ReadDtFile(file_name, &dt_value)) {
if (dt_value == "android,firmware") {
diff --git a/fs_mgr/libfstab/fstab_priv.h b/fs_mgr/libfstab/fstab_priv.h
index fb12b9f..cc56825 100644
--- a/fs_mgr/libfstab/fstab_priv.h
+++ b/fs_mgr/libfstab/fstab_priv.h
@@ -16,6 +16,7 @@
#pragma once
+#include <functional>
#include <string>
#include <utility>
#include <vector>
@@ -29,14 +30,8 @@
std::string* out_val);
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);
-std::vector<std::pair<std::string, std::string>> fs_mgr_parse_proc_bootconfig(
- const std::string& bootconfig);
-bool fs_mgr_get_boot_config_from_bootconfig(const std::string& bootconfig, const std::string& key,
- std::string* out_val);
-bool fs_mgr_get_boot_config_from_bootconfig_source(const std::string& key, std::string* out_val);
bool fs_mgr_update_for_slotselect(android::fs_mgr::Fstab* fstab);
-const std::string& get_android_dt_dir();
bool is_dt_compatible();
namespace android {
@@ -47,5 +42,11 @@
bool SkipMountWithConfig(const std::string& skip_config, Fstab* fstab, bool verbose);
std::string GetFstabPath();
+void ImportBootconfigFromString(const std::string& bootconfig,
+ const std::function<void(std::string, std::string)>& fn);
+
+bool GetBootconfigFromString(const std::string& bootconfig, const std::string& key,
+ std::string* out);
+
} // namespace fs_mgr
} // namespace android
diff --git a/fs_mgr/libfstab/include/fstab/fstab.h b/fs_mgr/libfstab/include/fstab/fstab.h
index e0683ac..79a07ee 100644
--- a/fs_mgr/libfstab/include/fstab/fstab.h
+++ b/fs_mgr/libfstab/include/fstab/fstab.h
@@ -19,6 +19,7 @@
#include <stdint.h>
#include <sys/types.h>
+#include <functional>
#include <set>
#include <string>
#include <vector>
@@ -124,5 +125,17 @@
// expected name.
std::string GetVerityDeviceName(const FstabEntry& entry);
+// Returns the Android Device Tree directory as specified in the kernel bootconfig or cmdline.
+// If the platform does not configure a custom DT path, returns the standard one (based in procfs).
+const std::string& GetAndroidDtDir();
+
+// Import the kernel bootconfig by calling the callback |fn| with each key-value pair.
+void ImportBootconfig(const std::function<void(std::string, std::string)>& fn);
+
+// Get the kernel bootconfig value for |key|.
+// Returns true if |key| is found in bootconfig.
+// Otherwise returns false and |*out| is not modified.
+bool GetBootconfig(const std::string& key, std::string* out);
+
} // namespace fs_mgr
} // namespace android
diff --git a/fs_mgr/liblp/super_layout_builder.cpp b/fs_mgr/liblp/super_layout_builder.cpp
index 37f28e1..5349e41 100644
--- a/fs_mgr/liblp/super_layout_builder.cpp
+++ b/fs_mgr/liblp/super_layout_builder.cpp
@@ -46,21 +46,21 @@
bool SuperLayoutBuilder::Open(const LpMetadata& metadata) {
for (const auto& partition : metadata.partitions) {
if (partition.attributes & LP_PARTITION_ATTR_SLOT_SUFFIXED) {
- // Retrofit devices are not supported.
+ LOG(ERROR) << "Retrofit devices are not supported";
return false;
}
if (!(partition.attributes & LP_PARTITION_ATTR_READONLY)) {
- // Writable partitions are not supported.
+ LOG(ERROR) << "Writable partitions are not supported";
return false;
}
}
if (!metadata.extents.empty()) {
- // Partitions that already have extents are not supported (should
- // never be true of super_empty.img).
+ LOG(ERROR) << "Partitions that already have extents are not supported";
+ // should never be true of super_empty.img.
return false;
}
if (metadata.block_devices.size() != 1) {
- // Only one "super" is supported.
+ LOG(ERROR) << "Only one 'super' is supported";
return false;
}
diff --git a/fs_mgr/tests/Android.bp b/fs_mgr/tests/Android.bp
index b7f792f..2aeba0a 100644
--- a/fs_mgr/tests/Android.bp
+++ b/fs_mgr/tests/Android.bp
@@ -38,6 +38,8 @@
],
static_libs: [
"libfs_mgr",
+ "libgmock",
+ "libgtest",
],
srcs: [
"file_wait_test.cpp",
diff --git a/fs_mgr/tests/fs_mgr_test.cpp b/fs_mgr/tests/fs_mgr_test.cpp
index c51df2a..fbed371 100644
--- a/fs_mgr/tests/fs_mgr_test.cpp
+++ b/fs_mgr/tests/fs_mgr_test.cpp
@@ -29,11 +29,13 @@
#include <android-base/strings.h>
#include <fs_mgr.h>
#include <fstab/fstab.h>
+#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "../fs_mgr_priv.h"
using namespace android::fs_mgr;
+using namespace testing;
namespace {
@@ -119,37 +121,42 @@
{"terminator", "truncated"},
};
-const std::string bootconfig =
- "androidboot.bootdevice = \"1d84000.ufshc\"\n"
- "androidboot.boot_devices = \"dev1\", \"dev2,withcomma\", \"dev3\"\n"
- "androidboot.baseband = \"sdy\"\n"
- "androidboot.keymaster = \"1\"\n"
- "androidboot.serialno = \"BLAHBLAHBLAH\"\n"
- "androidboot.slot_suffix = \"_a\"\n"
- "androidboot.hardware.platform = \"sdw813\"\n"
- "androidboot.hardware = \"foo\"\n"
- "androidboot.revision = \"EVT1.0\"\n"
- "androidboot.bootloader = \"burp-0.1-7521\"\n"
- "androidboot.hardware.sku = \"mary\"\n"
- "androidboot.hardware.radio.subtype = \"0\"\n"
- "androidboot.dtbo_idx = \"2\"\n"
- "androidboot.mode = \"normal\"\n"
- "androidboot.hardware.ddr = \"1GB,combuchi,LPDDR4X\"\n"
- "androidboot.ddr_info = \"combuchiandroidboot.ddr_size=2GB\"\n"
- "androidboot.hardware.ufs = \"2GB,combushi\"\n"
- "androidboot.boottime = \"0BLE:58,1BLL:22,1BLE:571,2BLL:105,ODT:0,AVB:123\"\n"
- "androidboot.ramdump = \"disabled\"\n"
- "androidboot.vbmeta.device = \"PARTUUID=aa08f1a4-c7c9-402e-9a66-9707cafa9ceb\"\n"
- "androidboot.vbmeta.avb_version = \"1.1\"\n"
- "androidboot.vbmeta.device_state = \"unlocked\"\n"
- "androidboot.vbmeta.hash_alg = \"sha256\"\n"
- "androidboot.vbmeta.size = \"5248\"\n"
- "androidboot.vbmeta.digest = \""
- "ac13147e959861c20f2a6da97d25fe79e60e902c022a371c5c039d31e7c68860\"\n"
- "androidboot.vbmeta.invalidate_on_error = \"yes\"\n"
- "androidboot.veritymode = \"enforcing\"\n"
- "androidboot.verifiedbootstate = \"orange\"\n"
- "androidboot.space = \"sha256 5248 androidboot.nospace = nope\"\n";
+const std::string bootconfig = R"(
+androidboot.bootdevice = "1d84000.ufshc"
+androidboot.boot_devices = "dev1", "dev2,withcomma", "dev3"
+androidboot.baseband = "sdy"
+androidboot.keymaster = "1"
+androidboot.serialno = "BLAHBLAHBLAH"
+androidboot.slot_suffix = "_a"
+androidboot.hardware.platform = "sdw813"
+androidboot.hardware = "foo"
+androidboot.revision = "EVT1.0"
+androidboot.bootloader = "burp-0.1-7521"
+androidboot.hardware.sku = "mary"
+androidboot.hardware.radio.subtype = "0"
+androidboot.dtbo_idx = "2"
+androidboot.mode = "normal"
+androidboot.hardware.ddr = "1GB,combuchi,LPDDR4X"
+androidboot.ddr_info = "combuchiandroidboot.ddr_size=2GB"
+androidboot.hardware.ufs = "2GB,combushi"
+androidboot.boottime = "0BLE:58,1BLL:22,1BLE:571,2BLL:105,ODT:0,AVB:123"
+androidboot.ramdump = "disabled"
+androidboot.vbmeta.device = "PARTUUID=aa08f1a4-c7c9-402e-9a66-9707cafa9ceb"
+androidboot.vbmeta.avb_version = "1.1"
+androidboot.vbmeta.device_state = "unlocked"
+androidboot.vbmeta.hash_alg = "sha256"
+androidboot.vbmeta.size = "5248"
+androidboot.vbmeta.digest = "ac13147e959861c20f2a6da97d25fe79e60e902c022a371c5c039d31e7c68860"
+androidboot.vbmeta.invalidate_on_error = "yes"
+androidboot.veritymode = "enforcing"
+androidboot.verifiedbootstate = "orange"
+androidboot.space = "sha256 5248 androidboot.nospace = nope"
+just.key
+key.empty.value =
+dessert.value = "ice, cream"
+dessert.list = "ice", "cream"
+ambiguous.list = ", ", ", "
+)";
const std::vector<std::pair<std::string, std::string>> bootconfig_result_space = {
{"androidboot.bootdevice", "1d84000.ufshc"},
@@ -182,6 +189,11 @@
{"androidboot.veritymode", "enforcing"},
{"androidboot.verifiedbootstate", "orange"},
{"androidboot.space", "sha256 5248 androidboot.nospace = nope"},
+ {"just.key", ""},
+ {"key.empty.value", ""},
+ {"dessert.value", "ice, cream"},
+ {"dessert.list", "ice,cream"},
+ {"ambiguous.list", ", ,, "},
};
bool CompareFlags(FstabEntry::FsMgrFlags& lhs, FstabEntry::FsMgrFlags& rhs) {
@@ -231,25 +243,35 @@
EXPECT_TRUE(content.empty()) << content;
}
-TEST(fs_mgr, fs_mgr_parse_bootconfig) {
- EXPECT_EQ(bootconfig_result_space, fs_mgr_parse_proc_bootconfig(bootconfig));
+TEST(fs_mgr, ImportBootconfig) {
+ std::vector<std::pair<std::string, std::string>> result;
+ ImportBootconfigFromString(bootconfig, [&](std::string key, std::string value) {
+ result.emplace_back(key, value);
+ });
+ EXPECT_THAT(result, ContainerEq(bootconfig_result_space));
}
-TEST(fs_mgr, fs_mgr_get_boot_config_from_bootconfig) {
+TEST(fs_mgr, GetBootconfig) {
std::string content;
- for (const auto& entry : bootconfig_result_space) {
- static constexpr char androidboot[] = "androidboot.";
- if (!android::base::StartsWith(entry.first, androidboot)) continue;
- auto key = entry.first.substr(strlen(androidboot));
- EXPECT_TRUE(fs_mgr_get_boot_config_from_bootconfig(bootconfig, key, &content))
- << " for " << key;
- EXPECT_EQ(entry.second, content);
+ for (const auto& [key, value] : bootconfig_result_space) {
+ EXPECT_TRUE(GetBootconfigFromString(bootconfig, key, &content)) << " for " << key;
+ EXPECT_EQ(content, value);
}
- EXPECT_FALSE(fs_mgr_get_boot_config_from_bootconfig(bootconfig, "vbmeta.avb_versio", &content));
- EXPECT_TRUE(content.empty()) << content;
- EXPECT_FALSE(fs_mgr_get_boot_config_from_bootconfig(bootconfig, "nospace", &content));
- EXPECT_TRUE(content.empty()) << content;
+ const std::string kUnmodifiedToken = "<UNMODIFIED>";
+ content = kUnmodifiedToken;
+ EXPECT_FALSE(android::fs_mgr::GetBootconfigFromString(bootconfig, "", &content));
+ EXPECT_EQ(content, kUnmodifiedToken) << "output parameter shouldn't be overridden";
+
+ content = kUnmodifiedToken;
+ EXPECT_FALSE(android::fs_mgr::GetBootconfigFromString(
+ bootconfig, "androidboot.vbmeta.avb_versio", &content));
+ EXPECT_EQ(content, kUnmodifiedToken) << "output parameter shouldn't be overridden";
+
+ content = kUnmodifiedToken;
+ EXPECT_FALSE(
+ android::fs_mgr::GetBootconfigFromString(bootconfig, "androidboot.nospace", &content));
+ EXPECT_EQ(content, kUnmodifiedToken) << "output parameter shouldn't be overridden";
}
TEST(fs_mgr, fs_mgr_read_fstab_file_proc_mounts) {
diff --git a/init/Android.bp b/init/Android.bp
index ee34215..d4852d6 100644
--- a/init/Android.bp
+++ b/init/Android.bp
@@ -539,6 +539,7 @@
"libprotobuf-cpp-lite",
],
static_libs: [
+ "libfs_mgr",
"libhidl-gen-utils",
],
}
diff --git a/init/devices.cpp b/init/devices.cpp
index 7c23492..6b8474e 100644
--- a/init/devices.cpp
+++ b/init/devices.cpp
@@ -32,6 +32,7 @@
#include <android-base/logging.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
+#include <fs_mgr.h>
#include <libdm/dm.h>
#include <private/android_filesystem_config.h>
#include <selinux/android.h>
@@ -204,7 +205,7 @@
}
};
ImportKernelCmdline(parser);
- ImportBootconfig(parser);
+ android::fs_mgr::ImportBootconfig(parser);
return partition_map;
}();
diff --git a/init/property_service.cpp b/init/property_service.cpp
index 8da6982..3557787 100644
--- a/init/property_service.cpp
+++ b/init/property_service.cpp
@@ -57,6 +57,7 @@
#include <android-base/result.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
+#include <fs_mgr.h>
#include <property_info_parser/property_info_parser.h>
#include <property_info_serializer/property_info_serializer.h>
#include <selinux/android.h>
@@ -1317,7 +1318,8 @@
return;
}
- std::unique_ptr<DIR, int (*)(DIR*)> dir(opendir(get_android_dt_dir().c_str()), closedir);
+ std::unique_ptr<DIR, int (*)(DIR*)> dir(opendir(android::fs_mgr::GetAndroidDtDir().c_str()),
+ closedir);
if (!dir) return;
std::string dt_file;
@@ -1328,7 +1330,7 @@
continue;
}
- std::string file_name = get_android_dt_dir() + dp->d_name;
+ std::string file_name = android::fs_mgr::GetAndroidDtDir() + dp->d_name;
android::base::ReadFileToString(file_name, &dt_file);
std::replace(dt_file.begin(), dt_file.end(), ',', '.');
@@ -1349,7 +1351,7 @@
static void ProcessBootconfig() {
- ImportBootconfig([&](const std::string& key, const std::string& value) {
+ android::fs_mgr::ImportBootconfig([&](const std::string& key, const std::string& value) {
if (StartsWith(key, ANDROIDBOOT_PREFIX)) {
InitPropertySet("ro.boot." + key.substr(ANDROIDBOOT_PREFIX.size()), value);
}
diff --git a/init/reboot_utils.cpp b/init/reboot_utils.cpp
index e6b868e..547b186 100644
--- a/init/reboot_utils.cpp
+++ b/init/reboot_utils.cpp
@@ -27,6 +27,7 @@
#include <android-base/properties.h>
#include <android-base/strings.h>
#include <cutils/android_reboot.h>
+#include <fs_mgr.h>
#include <unwindstack/AndroidUnwinder.h>
#include "capabilities.h"
@@ -48,13 +49,9 @@
const std::string kInitFatalPanicParamString = "androidboot.init_fatal_panic";
if (cmdline.find(kInitFatalPanicParamString) == std::string::npos) {
- init_fatal_panic = false;
- ImportBootconfig(
- [kInitFatalPanicParamString](const std::string& key, const std::string& value) {
- if (key == kInitFatalPanicParamString && value == "true") {
- init_fatal_panic = true;
- }
- });
+ std::string value;
+ init_fatal_panic = (android::fs_mgr::GetBootconfig(kInitFatalPanicParamString, &value) &&
+ value == "true");
} else {
const std::string kInitFatalPanicString = kInitFatalPanicParamString + "=true";
init_fatal_panic = cmdline.find(kInitFatalPanicString) != std::string::npos;
@@ -68,11 +65,7 @@
const std::string kRebootTargetString = "androidboot.init_fatal_reboot_target";
auto start_pos = cmdline.find(kRebootTargetString);
if (start_pos == std::string::npos) {
- ImportBootconfig([kRebootTargetString](const std::string& key, const std::string& value) {
- if (key == kRebootTargetString) {
- init_fatal_reboot_target = value;
- }
- });
+ android::fs_mgr::GetBootconfig(kRebootTargetString, &init_fatal_reboot_target);
// We already default to bootloader if no setting is provided.
} else {
const std::string kRebootTargetStringPattern = kRebootTargetString + "=";
diff --git a/init/selinux.cpp b/init/selinux.cpp
index 51093d8..6fb028b 100644
--- a/init/selinux.cpp
+++ b/init/selinux.cpp
@@ -110,11 +110,11 @@
});
if (status == SELINUX_ENFORCING) {
- ImportBootconfig([&](const std::string& key, const std::string& value) {
- if (key == "androidboot.selinux" && value == "permissive") {
- status = SELINUX_PERMISSIVE;
- }
- });
+ std::string value;
+ if (android::fs_mgr::GetBootconfig("androidboot.selinux", &value) &&
+ value == "permissive") {
+ status = SELINUX_PERMISSIVE;
+ }
}
return status;
diff --git a/init/util.cpp b/init/util.cpp
index d0478e8..b34d45d 100644
--- a/init/util.cpp
+++ b/init/util.cpp
@@ -42,6 +42,10 @@
#include <cutils/sockets.h>
#include <selinux/android.h>
+#if defined(__ANDROID__)
+#include <fs_mgr.h>
+#endif
+
#ifdef INIT_FULL_SOURCES
#include <android/api-level.h>
#include <sys/system_properties.h>
@@ -60,8 +64,6 @@
namespace android {
namespace init {
-const std::string kDefaultAndroidDtDir("/proc/device-tree/firmware/android/");
-
const std::string kDataDirPrefix("/data/");
void (*trigger_shutdown)(const std::string& command) = nullptr;
@@ -252,21 +254,6 @@
}
}
-void ImportBootconfig(const std::function<void(const std::string&, const std::string&)>& fn) {
- std::string bootconfig;
- android::base::ReadFileToString("/proc/bootconfig", &bootconfig);
-
- for (const auto& entry : android::base::Split(bootconfig, "\n")) {
- std::vector<std::string> pieces = android::base::Split(entry, "=");
- if (pieces.size() == 2) {
- // get rid of the extra space between a list of values and remove the quotes.
- std::string value = android::base::StringReplace(pieces[1], "\", \"", ",", true);
- value.erase(std::remove(value.begin(), value.end(), '"'), value.end());
- fn(android::base::Trim(pieces[0]), android::base::Trim(value));
- }
- }
-}
-
bool make_dir(const std::string& path, mode_t mode) {
std::string secontext;
if (SelabelLookupFileContext(path, mode, &secontext) && !secontext.empty()) {
@@ -375,45 +362,18 @@
return dst;
}
-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
- ImportKernelCmdline([&](const std::string& key, const std::string& value) {
- if (key == "androidboot.android_dt_dir") {
- android_dt_dir = value;
- }
- });
- // ..Or bootconfig
- if (android_dt_dir == kDefaultAndroidDtDir) {
- ImportBootconfig([&](const std::string& key, const std::string& value) {
- 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 = get_android_dt_dir() + sub_path;
+#if defined(__ANDROID__)
+ const std::string file_name = android::fs_mgr::GetAndroidDtDir() + sub_path;
if (android::base::ReadFileToString(file_name, dt_content)) {
if (!dt_content->empty()) {
dt_content->pop_back(); // Trims the trailing '\0' out.
return true;
}
}
+#endif
return false;
}
diff --git a/init/util.h b/init/util.h
index 3f0a4e0..0b0ef63 100644
--- a/init/util.h
+++ b/init/util.h
@@ -55,14 +55,10 @@
bool mkdir_recursive(const std::string& pathname, mode_t mode);
int wait_for_file(const char *filename, std::chrono::nanoseconds timeout);
void ImportKernelCmdline(const std::function<void(const std::string&, const std::string&)>&);
-void ImportBootconfig(const std::function<void(const std::string&, const std::string&)>&);
bool make_dir(const std::string& path, mode_t mode);
bool is_dir(const char* pathname);
Result<std::string> ExpandProps(const std::string& src);
-// Returns the platform's Android DT directory as specified in the kernel cmdline.
-// If the platform does not configure a custom DT path, returns the standard one (based in procfs).
-const std::string& get_android_dt_dir();
// Reads or compares the content of device tree file under the platform's Android DT directory.
bool read_android_dt_file(const std::string& sub_path, std::string* dt_content);
bool is_android_dt_value_expected(const std::string& sub_path, const std::string& expected_content);