Merge "Set input thread priority to RT" into main
diff --git a/fastboot/Android.bp b/fastboot/Android.bp
index bfe0768..b61fbd4 100644
--- a/fastboot/Android.bp
+++ b/fastboot/Android.bp
@@ -430,6 +430,7 @@
],
data: [
":fastboot_test_dtb",
+ ":fastboot_test_dtb_replace",
":fastboot_test_bootconfig",
":fastboot_test_vendor_ramdisk_none",
":fastboot_test_vendor_ramdisk_platform",
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index 6b9e493..156dc3b 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -552,6 +552,12 @@
" Secondary images may be flashed to inactive slot.\n"
" flash PARTITION [FILENAME] Flash given partition, using the image from\n"
" $ANDROID_PRODUCT_OUT if no filename is given.\n"
+ " flash vendor_boot:RAMDISK [FILENAME]\n"
+ " Flash vendor_boot ramdisk, fetching the existing\n"
+ " vendor_boot image and repackaging it with the new\n"
+ " ramdisk.\n"
+ " --dtb DTB If set with flash vendor_boot:RAMDISK, then\n"
+ " update the vendor_boot image with provided DTB.\n"
"\n"
"basics:\n"
" devices [-l] List devices in bootloader (-l: with device paths).\n"
@@ -1020,6 +1026,8 @@
}
int64_t get_sparse_limit(int64_t size, const FlashingPlan* fp) {
+ if (!fp) return 0;
+
int64_t limit = int64_t(fp->sparse_limit);
if (limit == 0) {
// Unlimited, so see what the target device's limit is.
@@ -1465,6 +1473,7 @@
static std::string repack_ramdisk(const char* pname, struct fastboot_buffer* buf,
fastboot::IFastBootDriver* fb) {
std::string_view pname_sv{pname};
+ struct fastboot_buffer dtb_buf = {.sz = 0, .fd = unique_fd(-1)};
if (!android::base::StartsWith(pname_sv, "vendor_boot:") &&
!android::base::StartsWith(pname_sv, "vendor_boot_a:") &&
@@ -1480,10 +1489,25 @@
std::string partition(pname_sv.substr(0, pname_sv.find(':')));
std::string ramdisk(pname_sv.substr(pname_sv.find(':') + 1));
+ if (!g_dtb_path.empty()) {
+ if (!load_buf(g_dtb_path.c_str(), &dtb_buf, nullptr)) {
+ die("cannot load '%s': %s", g_dtb_path.c_str(), strerror(errno));
+ }
+
+ if (dtb_buf.type != FB_BUFFER_FD) {
+ die("Flashing sparse vendor ramdisk image with dtb is not supported.");
+ }
+ if (dtb_buf.sz <= 0) {
+ die("repack_ramdisk() sees invalid dtb size: %" PRId64, buf->sz);
+ }
+ verbose("Updating DTB with %s", pname_sv.data());
+ }
+
unique_fd vendor_boot(make_temporary_fd("vendor boot repack"));
uint64_t vendor_boot_size = fetch_partition(partition, vendor_boot, fb);
auto repack_res = replace_vendor_ramdisk(vendor_boot, vendor_boot_size, ramdisk, buf->fd,
- static_cast<uint64_t>(buf->sz));
+ static_cast<uint64_t>(buf->sz), dtb_buf.fd,
+ static_cast<uint64_t>(dtb_buf.sz));
if (!repack_res.ok()) {
die("%s", repack_res.error().message().c_str());
}
diff --git a/fastboot/fuzzer/fastboot_fuzzer.cpp b/fastboot/fuzzer/fastboot_fuzzer.cpp
index 60940fe..4594a8a 100644
--- a/fastboot/fuzzer/fastboot_fuzzer.cpp
+++ b/fastboot/fuzzer/fastboot_fuzzer.cpp
@@ -15,6 +15,7 @@
*
*/
#include <android-base/file.h>
+#include <android-base/unique_fd.h>
#include "fastboot.h"
#include "socket.h"
#include "socket_mock_fuzz.h"
@@ -25,6 +26,7 @@
#include <fuzzer/FuzzedDataProvider.h>
using namespace std;
+using android::base::unique_fd;
const size_t kYearMin = 2000;
const size_t kYearMax = 2127;
@@ -255,7 +257,7 @@
uint64_t ramdisk_size =
fdp_->ConsumeBool() ? content_ramdisk_fd.size() : fdp_->ConsumeIntegral<uint64_t>();
(void)replace_vendor_ramdisk(vendor_boot_fd, vendor_boot_size, ramdisk_name, ramdisk_fd,
- ramdisk_size);
+ ramdisk_size, unique_fd(-1), 0);
close(vendor_boot_fd);
close(ramdisk_fd);
}
diff --git a/fastboot/testdata/Android.bp b/fastboot/testdata/Android.bp
index a490fe2..47bf095 100644
--- a/fastboot/testdata/Android.bp
+++ b/fastboot/testdata/Android.bp
@@ -40,6 +40,14 @@
cmd: "$(location fastboot_gen_rand) --seed dtb --length 1024 > $(out)",
}
+// Fake dtb image for replacement.
+genrule {
+ name: "fastboot_test_dtb_replace",
+ defaults: ["fastboot_test_data_gen_defaults"],
+ out: ["dtb_replace.img"],
+ cmd: "$(location fastboot_gen_rand) --seed dtb --length 2048 > $(out)",
+}
+
// Fake bootconfig image.
genrule {
name: "fastboot_test_bootconfig",
diff --git a/fastboot/vendor_boot_img_utils.cpp b/fastboot/vendor_boot_img_utils.cpp
index 9f05253..da547f1 100644
--- a/fastboot/vendor_boot_img_utils.cpp
+++ b/fastboot/vendor_boot_img_utils.cpp
@@ -209,7 +209,8 @@
// Replace the vendor ramdisk as a whole.
[[nodiscard]] Result<std::string> replace_default_vendor_ramdisk(const std::string& vendor_boot,
- const std::string& new_ramdisk) {
+ const std::string& new_ramdisk,
+ const std::string& new_dtb) {
if (auto res = check_vendor_boot_hdr(vendor_boot, 3); !res.ok()) return res.error();
auto hdr = reinterpret_cast<const vendor_boot_img_hdr_v3*>(vendor_boot.data());
auto hdr_size = get_vendor_boot_header_size(hdr);
@@ -244,8 +245,19 @@
return res.error();
if (auto res = updater.CheckOffset(o + p, o + new_p); !res.ok()) return res.error();
- // Copy DTB (Q bytes).
- if (auto res = updater.Copy(q); !res.ok()) return res.error();
+ // Copy DTB (Q bytes). Replace if a new one was provided.
+ new_hdr->dtb_size = !new_dtb.empty() ? new_dtb.size() : hdr->dtb_size;
+ const uint32_t new_q = round_up(new_hdr->dtb_size, new_hdr->page_size);
+ if (new_dtb.empty()) {
+ if (auto res = updater.Copy(q); !res.ok()) return res.error();
+ } else {
+ if (auto res = updater.Replace(hdr->dtb_size, new_dtb); !res.ok()) return res.error();
+ if (auto res = updater.Skip(q - hdr->dtb_size, new_q - new_hdr->dtb_size); !res.ok())
+ return res.error();
+ }
+ if (auto res = updater.CheckOffset(o + p + q, o + new_p + new_q); !res.ok()) {
+ return res.error();
+ }
if (new_hdr->header_version >= 4) {
auto hdr_v4 = static_cast<const vendor_boot_img_hdr_v4*>(hdr);
@@ -256,7 +268,7 @@
auto new_hdr_v4 = static_cast<const vendor_boot_img_hdr_v4*>(new_hdr);
auto new_r = round_up(new_hdr_v4->vendor_ramdisk_table_size, new_hdr->page_size);
if (auto res = updater.Skip(r, new_r); !res.ok()) return res.error();
- if (auto res = updater.CheckOffset(o + p + q + r, o + new_p + q + new_r); !res.ok())
+ if (auto res = updater.CheckOffset(o + p + q + r, o + new_p + new_q + new_r); !res.ok())
return res.error();
// Replace table with single entry representing the full ramdisk.
@@ -303,7 +315,8 @@
// replace it with the content of |new_ramdisk|.
[[nodiscard]] Result<std::string> replace_vendor_ramdisk_fragment(const std::string& ramdisk_name,
const std::string& vendor_boot,
- const std::string& new_ramdisk) {
+ const std::string& new_ramdisk,
+ const std::string& new_dtb) {
if (auto res = check_vendor_boot_hdr(vendor_boot, 4); !res.ok()) return res.error();
auto hdr = reinterpret_cast<const vendor_boot_img_hdr_v4*>(vendor_boot.data());
auto hdr_size = get_vendor_boot_header_size(hdr);
@@ -368,8 +381,19 @@
return res.error();
if (auto res = updater.CheckOffset(o + p, o + new_p); !res.ok()) return res.error();
- // Copy DTB (Q bytes).
- if (auto res = updater.Copy(q); !res.ok()) return res.error();
+ // Copy DTB (Q bytes). Replace if a new one was provided.
+ new_hdr->dtb_size = !new_dtb.empty() ? new_dtb.size() : hdr->dtb_size;
+ const uint32_t new_q = round_up(new_hdr->dtb_size, new_hdr->page_size);
+ if (new_dtb.empty()) {
+ if (auto res = updater.Copy(q); !res.ok()) return res.error();
+ } else {
+ if (auto res = updater.Replace(hdr->dtb_size, new_dtb); !res.ok()) return res.error();
+ if (auto res = updater.Skip(q - hdr->dtb_size, new_q - new_hdr->dtb_size); !res.ok())
+ return res.error();
+ }
+ if (auto res = updater.CheckOffset(o + p + q, o + new_p + new_q); !res.ok()) {
+ return res.error();
+ }
// Copy table, but with corresponding entries modified, including:
// - ramdisk_size of the entry replaced
@@ -392,7 +416,7 @@
hdr->vendor_ramdisk_table_entry_size);
!res.ok())
return res.error();
- if (auto res = updater.CheckOffset(o + p + q + r, o + new_p + q + r); !res.ok())
+ if (auto res = updater.CheckOffset(o + p + q + r, o + new_p + new_q + r); !res.ok())
return res.error();
// Copy bootconfig (S bytes).
@@ -404,11 +428,11 @@
} // namespace
-[[nodiscard]] Result<void> replace_vendor_ramdisk(android::base::borrowed_fd vendor_boot_fd,
- uint64_t vendor_boot_size,
- const std::string& ramdisk_name,
- android::base::borrowed_fd new_ramdisk_fd,
- uint64_t new_ramdisk_size) {
+[[nodiscard]] Result<void> replace_vendor_ramdisk(
+ android::base::borrowed_fd vendor_boot_fd, uint64_t vendor_boot_size,
+ const std::string& ramdisk_name, android::base::borrowed_fd new_ramdisk_fd,
+ uint64_t new_ramdisk_size, android::base::borrowed_fd new_dtb_fd, uint64_t new_dtb_size) {
+ Result<std::string> new_dtb = {""};
if (new_ramdisk_size > std::numeric_limits<uint32_t>::max()) {
return Errorf("New vendor ramdisk is too big");
}
@@ -417,12 +441,17 @@
if (!vendor_boot.ok()) return vendor_boot.error();
auto new_ramdisk = load_file(new_ramdisk_fd, new_ramdisk_size, "new vendor ramdisk");
if (!new_ramdisk.ok()) return new_ramdisk.error();
+ if (new_dtb_size > 0 && new_dtb_fd >= 0) {
+ new_dtb = load_file(new_dtb_fd, new_dtb_size, "new dtb");
+ if (!new_dtb.ok()) return new_dtb.error();
+ }
Result<std::string> new_vendor_boot;
if (ramdisk_name == "default") {
- new_vendor_boot = replace_default_vendor_ramdisk(*vendor_boot, *new_ramdisk);
+ new_vendor_boot = replace_default_vendor_ramdisk(*vendor_boot, *new_ramdisk, *new_dtb);
} else {
- new_vendor_boot = replace_vendor_ramdisk_fragment(ramdisk_name, *vendor_boot, *new_ramdisk);
+ new_vendor_boot =
+ replace_vendor_ramdisk_fragment(ramdisk_name, *vendor_boot, *new_ramdisk, *new_dtb);
}
if (!new_vendor_boot.ok()) return new_vendor_boot.error();
if (auto res = store_file(vendor_boot_fd, *new_vendor_boot, "new vendor boot image"); !res.ok())
diff --git a/fastboot/vendor_boot_img_utils.h b/fastboot/vendor_boot_img_utils.h
index 0b702bc..0ca78da 100644
--- a/fastboot/vendor_boot_img_utils.h
+++ b/fastboot/vendor_boot_img_utils.h
@@ -31,4 +31,4 @@
[[nodiscard]] android::base::Result<void> replace_vendor_ramdisk(
android::base::borrowed_fd vendor_boot_fd, uint64_t vendor_boot_size,
const std::string& ramdisk_name, android::base::borrowed_fd new_ramdisk_fd,
- uint64_t new_ramdisk_size);
+ uint64_t new_ramdisk_size, android::base::borrowed_fd new_dtb_fd, uint64_t new_dtb_size);
diff --git a/fastboot/vendor_boot_img_utils_test.cpp b/fastboot/vendor_boot_img_utils_test.cpp
index 8107270..841e532 100644
--- a/fastboot/vendor_boot_img_utils_test.cpp
+++ b/fastboot/vendor_boot_img_utils_test.cpp
@@ -241,6 +241,7 @@
struct RepackVendorBootImgTestParam {
std::string vendor_boot_file_name;
+ std::string dtb_file_name;
uint32_t expected_header_version;
friend std::ostream& operator<<(std::ostream& os, const RepackVendorBootImgTestParam& param) {
return os << param.vendor_boot_file_name;
@@ -252,22 +253,50 @@
virtual void SetUp() {
vboot = std::make_unique<ReadWriteTestFileHandle>(GetParam().vendor_boot_file_name);
ASSERT_RESULT_OK(vboot->Open());
+
+ if (!GetParam().dtb_file_name.empty()) {
+ dtb_replacement = std::make_unique<ReadOnlyTestFileHandle>(GetParam().dtb_file_name);
+ ASSERT_RESULT_OK(dtb_replacement->Open());
+ }
}
std::unique_ptr<TestFileHandle> vboot;
+ std::unique_ptr<TestFileHandle> dtb_replacement;
};
TEST_P(RepackVendorBootImgTest, InvalidSize) {
- EXPECT_ERROR(replace_vendor_ramdisk(vboot->fd(), vboot->size() + 1, "default",
- env->replace->fd(), env->replace->size()),
- HasSubstr("Size of vendor boot does not match"));
- EXPECT_ERROR(replace_vendor_ramdisk(vboot->fd(), vboot->size(), "default", env->replace->fd(),
- env->replace->size() + 1),
- HasSubstr("Size of new vendor ramdisk does not match"));
+ EXPECT_ERROR(
+ replace_vendor_ramdisk(vboot->fd(), vboot->size() + 1, "default", env->replace->fd(),
+ env->replace->size(),
+ !GetParam().dtb_file_name.empty() ? dtb_replacement->fd()
+ : android::base::unique_fd(-1),
+ !GetParam().dtb_file_name.empty() ? dtb_replacement->size() : 0),
+ HasSubstr("Size of vendor boot does not match"));
+ EXPECT_ERROR(
+ replace_vendor_ramdisk(vboot->fd(), vboot->size(), "default", env->replace->fd(),
+ env->replace->size() + 1,
+ !GetParam().dtb_file_name.empty() ? dtb_replacement->fd()
+ : android::base::unique_fd(-1),
+ !GetParam().dtb_file_name.empty() ? dtb_replacement->size() : 0),
+ HasSubstr("Size of new vendor ramdisk does not match"));
+ if (!GetParam().dtb_file_name.empty()) {
+ EXPECT_ERROR(replace_vendor_ramdisk(vboot->fd(), vboot->size(), "default",
+ env->replace->fd(), env->replace->size(),
+ dtb_replacement->fd(), dtb_replacement->size() + 1),
+ HasSubstr("Size of new dtb does not match"));
+ }
+ EXPECT_ERROR(
+ replace_vendor_ramdisk(
+ vboot->fd(), vboot->size(), "default", env->replace->fd(), env->replace->size(),
+ android::base::unique_fd(std::numeric_limits<int32_t>::max()), 1),
+ HasSubstr("Can't seek to the beginning of new dtb image"));
}
TEST_P(RepackVendorBootImgTest, ReplaceUnknown) {
- auto res = replace_vendor_ramdisk(vboot->fd(), vboot->size(), "unknown", env->replace->fd(),
- env->replace->size());
+ auto res = replace_vendor_ramdisk(
+ vboot->fd(), vboot->size(), "unknown", env->replace->fd(), env->replace->size(),
+ !GetParam().dtb_file_name.empty() ? dtb_replacement->fd()
+ : android::base::unique_fd(-1),
+ !GetParam().dtb_file_name.empty() ? dtb_replacement->size() : 0);
if (GetParam().expected_header_version == 3) {
EXPECT_ERROR(res, Eq("Require vendor boot header V4 but is V3"));
} else if (GetParam().expected_header_version == 4) {
@@ -279,8 +308,11 @@
auto old_content = vboot->Read();
ASSERT_RESULT_OK(old_content);
- ASSERT_RESULT_OK(replace_vendor_ramdisk(vboot->fd(), vboot->size(), "default",
- env->replace->fd(), env->replace->size()));
+ ASSERT_RESULT_OK(replace_vendor_ramdisk(
+ vboot->fd(), vboot->size(), "default", env->replace->fd(), env->replace->size(),
+ !GetParam().dtb_file_name.empty() ? dtb_replacement->fd()
+ : android::base::unique_fd(-1),
+ !GetParam().dtb_file_name.empty() ? dtb_replacement->size() : 0));
EXPECT_RESULT(vboot->fsize(), vboot->size()) << "File size should not change after repack";
auto new_content_res = vboot->Read();
@@ -291,14 +323,23 @@
ASSERT_EQ(0, memcmp(VENDOR_BOOT_MAGIC, hdr->magic, VENDOR_BOOT_MAGIC_SIZE));
ASSERT_EQ(GetParam().expected_header_version, hdr->header_version);
EXPECT_EQ(hdr->vendor_ramdisk_size, env->replace->size());
- EXPECT_EQ(hdr->dtb_size, env->dtb->size());
+ if (GetParam().dtb_file_name.empty()) {
+ EXPECT_EQ(hdr->dtb_size, env->dtb->size());
+ } else {
+ EXPECT_EQ(hdr->dtb_size, dtb_replacement->size());
+ }
auto o = round_up(sizeof(vendor_boot_img_hdr_v3), hdr->page_size);
auto p = round_up(hdr->vendor_ramdisk_size, hdr->page_size);
auto q = round_up(hdr->dtb_size, hdr->page_size);
EXPECT_THAT(new_content.substr(o, p), IsPadded(env->replace_content));
- EXPECT_THAT(new_content.substr(o + p, q), IsPadded(env->dtb_content));
+ if (GetParam().dtb_file_name.empty()) {
+ EXPECT_THAT(new_content.substr(o + p, q), IsPadded(env->dtb_content));
+ } else {
+ auto dtb_content_res = dtb_replacement->Read();
+ EXPECT_THAT(new_content.substr(o + p, q), IsPadded(*dtb_content_res));
+ }
if (hdr->header_version < 4) return;
@@ -321,11 +362,17 @@
INSTANTIATE_TEST_SUITE_P(
RepackVendorBootImgTest, RepackVendorBootImgTest,
- ::testing::Values(RepackVendorBootImgTestParam{"vendor_boot_v3.img", 3},
- RepackVendorBootImgTestParam{"vendor_boot_v4_with_frag.img", 4},
- RepackVendorBootImgTestParam{"vendor_boot_v4_without_frag.img", 4}),
+ ::testing::Values(RepackVendorBootImgTestParam{"vendor_boot_v3.img", "", 3},
+ RepackVendorBootImgTestParam{"vendor_boot_v4_with_frag.img", "", 4},
+ RepackVendorBootImgTestParam{"vendor_boot_v4_without_frag.img", "", 4},
+ RepackVendorBootImgTestParam{"vendor_boot_v4_with_frag.img",
+ "dtb_replace.img", 4},
+ RepackVendorBootImgTestParam{"vendor_boot_v4_without_frag.img",
+ "dtb_replace.img", 4}),
[](const auto& info) {
- return android::base::StringReplace(info.param.vendor_boot_file_name, ".", "_", false);
+ std::string test_name =
+ android::base::StringReplace(info.param.vendor_boot_file_name, ".", "_", false);
+ return test_name + (!info.param.dtb_file_name.empty() ? "_replace_dtb" : "");
});
std::string_view GetRamdiskName(const vendor_ramdisk_table_entry_v4* entry) {
@@ -368,7 +415,8 @@
ASSERT_RESULT_OK(old_content);
ASSERT_RESULT_OK(replace_vendor_ramdisk(vboot->fd(), vboot->size(), replace_ramdisk_name,
- env->replace->fd(), env->replace->size()));
+ env->replace->fd(), env->replace->size(),
+ android::base::unique_fd(-1), 0));
EXPECT_RESULT(vboot->fsize(), vboot->size()) << "File size should not change after repack";
auto new_content_res = vboot->Read();
diff --git a/fs_mgr/fs_mgr.cpp b/fs_mgr/fs_mgr.cpp
index fbd990b..9f52f44 100644
--- a/fs_mgr/fs_mgr.cpp
+++ b/fs_mgr/fs_mgr.cpp
@@ -1603,7 +1603,8 @@
attempted_entry.fs_type,
attempted_entry.fs_mgr_flags.is_zoned ? "true" : "false",
std::to_string(attempted_entry.length),
- android::base::Join(attempted_entry.user_devices, ' ')},
+ android::base::Join(attempted_entry.user_devices, ' '),
+ android::base::Join(attempted_entry.device_aliased, ' ')},
nullptr)) {
LERROR << "Encryption failed";
set_type_property(encryptable);
@@ -1655,7 +1656,8 @@
formattable_entry->fs_type,
formattable_entry->fs_mgr_flags.is_zoned ? "true" : "false",
std::to_string(formattable_entry->length),
- android::base::Join(formattable_entry->user_devices, ' ')},
+ android::base::Join(formattable_entry->user_devices, ' '),
+ android::base::Join(formattable_entry->device_aliased, ' ')},
nullptr)) {
LERROR << "Encryption failed";
} else {
@@ -2213,11 +2215,11 @@
#if ALLOW_ADBD_DISABLE_VERITY == 0
// Allowlist the mount point if user build.
- static const std::vector<const std::string> kAllowedPaths = {
+ static const std::vector<std::string> kAllowedPaths = {
"/odm", "/odm_dlkm", "/oem", "/product",
"/system_dlkm", "/system_ext", "/vendor", "/vendor_dlkm",
};
- static const std::vector<const std::string> kAllowedPrefixes = {
+ static const std::vector<std::string> kAllowedPrefixes = {
"/mnt/product/",
"/mnt/vendor/",
};
@@ -2314,6 +2316,14 @@
return context;
}
+int fs_mgr_f2fs_ideal_block_size() {
+#if defined(__i386__) || defined(__x86_64__)
+ return 4096;
+#else
+ return getpagesize();
+#endif
+}
+
namespace android {
namespace fs_mgr {
diff --git a/fs_mgr/fs_mgr_format.cpp b/fs_mgr/fs_mgr_format.cpp
index 0dde1d3..57e35a2 100644
--- a/fs_mgr/fs_mgr_format.cpp
+++ b/fs_mgr/fs_mgr_format.cpp
@@ -32,6 +32,7 @@
#include <selinux/android.h>
#include <selinux/label.h>
#include <selinux/selinux.h>
+#include <filesystem>
#include <string>
#include "fs_mgr_priv.h"
@@ -126,7 +127,8 @@
static int format_f2fs(const std::string& fs_blkdev, uint64_t dev_sz, bool needs_projid,
bool needs_casefold, bool fs_compress, bool is_zoned,
- const std::vector<std::string>& user_devices) {
+ const std::vector<std::string>& user_devices,
+ const std::vector<int>& device_aliased) {
if (!dev_sz) {
int rc = get_dev_sz(fs_blkdev, &dev_sz);
if (rc) {
@@ -164,9 +166,15 @@
if (is_zoned) {
args.push_back("-m");
}
- for (auto& device : user_devices) {
+ for (size_t i = 0; i < user_devices.size(); i++) {
+ std::string device_name = user_devices[i];
+
args.push_back("-c");
- args.push_back(device.c_str());
+ if (device_aliased[i]) {
+ std::filesystem::path path = device_name;
+ device_name += "@" + path.filename().string();
+ }
+ args.push_back(device_name.c_str());
}
if (user_devices.empty()) {
@@ -191,7 +199,7 @@
if (entry.fs_type == "f2fs") {
return format_f2fs(entry.blk_device, entry.length, needs_projid, needs_casefold,
entry.fs_mgr_flags.fs_compress, entry.fs_mgr_flags.is_zoned,
- entry.user_devices);
+ entry.user_devices, entry.device_aliased);
} else if (entry.fs_type == "ext4") {
return format_ext4(entry.blk_device, entry.mount_point, needs_projid,
entry.fs_mgr_flags.ext_meta_csum);
diff --git a/fs_mgr/fs_mgr_overlayfs_control.cpp b/fs_mgr/fs_mgr_overlayfs_control.cpp
index 08ad80c..489b32e 100644
--- a/fs_mgr/fs_mgr_overlayfs_control.cpp
+++ b/fs_mgr/fs_mgr_overlayfs_control.cpp
@@ -387,10 +387,8 @@
auto command = ""s;
if (!access(kMkF2fs, X_OK) && fs_mgr_filesystem_available("f2fs")) {
fs_type = "f2fs";
- command = kMkF2fs + " -w "s;
- command += std::to_string(getpagesize());
command = kMkF2fs + " -b "s;
- command += std::to_string(getpagesize());
+ command += std::to_string(fs_mgr_f2fs_ideal_block_size());
command += " -f -d1 -l" + android::base::Basename(kScratchMountPoint);
} else if (!access(kMkExt4, X_OK) && fs_mgr_filesystem_available("ext4")) {
fs_type = "ext4";
diff --git a/fs_mgr/include/fs_mgr.h b/fs_mgr/include/fs_mgr.h
index 9cfa93f..7969087 100644
--- a/fs_mgr/include/fs_mgr.h
+++ b/fs_mgr/include/fs_mgr.h
@@ -137,3 +137,6 @@
// File name used to track if encryption was interrupted, leading to a known bad fs state
std::string fs_mgr_metadata_encryption_in_progress_file_name(
const android::fs_mgr::FstabEntry& entry);
+
+// Returns the ideal block size for make_f2fs. Returns -1 on failure.
+int fs_mgr_f2fs_ideal_block_size();
diff --git a/fs_mgr/libfstab/fstab.cpp b/fs_mgr/libfstab/fstab.cpp
index d344b2d..6e4cae1 100644
--- a/fs_mgr/libfstab/fstab.cpp
+++ b/fs_mgr/libfstab/fstab.cpp
@@ -173,6 +173,7 @@
entry->fs_mgr_flags.is_zoned = true;
}
entry->user_devices.push_back(param[1]);
+ entry->device_aliased.push_back(param[0] == "exp_alias" ? 1 : 0);
}
bool ParseFsMgrFlags(const std::string& flags, FstabEntry* entry) {
diff --git a/fs_mgr/libfstab/include/fstab/fstab.h b/fs_mgr/libfstab/include/fstab/fstab.h
index 21fe017..070dd91 100644
--- a/fs_mgr/libfstab/include/fstab/fstab.h
+++ b/fs_mgr/libfstab/include/fstab/fstab.h
@@ -33,6 +33,7 @@
struct FstabEntry {
std::string blk_device;
std::vector<std::string> user_devices;
+ std::vector<int> device_aliased;
std::string logical_partition_name;
std::string mount_point;
std::string fs_type;
diff --git a/init/block_dev_initializer.cpp b/init/block_dev_initializer.cpp
index 8f52158..cabeb01 100644
--- a/init/block_dev_initializer.cpp
+++ b/init/block_dev_initializer.cpp
@@ -98,7 +98,11 @@
LOG(VERBOSE) << __PRETTY_FUNCTION__ << ": found partition: " << name;
- devices->erase(iter);
+ // Remove partition from the list only if it was found on boot device
+ if (device_handler_->IsBootDevice(uevent)) {
+ devices->erase(iter);
+ }
+
device_handler_->HandleUevent(uevent);
return devices->empty() ? ListenerAction::kStop : ListenerAction::kContinue;
}
diff --git a/init/devices.cpp b/init/devices.cpp
index f2bb9d2..6a3a64d 100644
--- a/init/devices.cpp
+++ b/init/devices.cpp
@@ -188,6 +188,28 @@
}
}
+bool DeviceHandler::IsBootDevice(const Uevent& uevent) const {
+ std::string device;
+
+ if (FindPlatformDevice(uevent.path, &device)) {
+ // Skip /devices/platform or /devices/ if present
+ static constexpr std::string_view devices_platform_prefix = "/devices/platform/";
+ static constexpr std::string_view devices_prefix = "/devices/";
+
+ if (StartsWith(device, devices_platform_prefix)) {
+ device = device.substr(devices_platform_prefix.length());
+ } else if (StartsWith(device, devices_prefix)) {
+ device = device.substr(devices_prefix.length());
+ }
+ } else if (FindPciDevicePrefix(uevent.path, &device)) {
+ } else if (FindVbdDevicePrefix(uevent.path, &device)) {
+ } else {
+ return false;
+ }
+
+ return boot_devices_.find(device) != boot_devices_.end();
+}
+
std::string DeviceHandler::GetPartitionNameForDevice(const std::string& query_device) {
static const auto partition_map = [] {
std::vector<std::pair<std::string, std::string>> partition_map;
diff --git a/init/devices.h b/init/devices.h
index 6da1232..4df604d 100644
--- a/init/devices.h
+++ b/init/devices.h
@@ -133,6 +133,7 @@
// `androidboot.partition_map=vdb,metadata;vdc,userdata` maps `vdb` to `metadata` and `vdc` to
// `userdata`.
static std::string GetPartitionNameForDevice(const std::string& device);
+ bool IsBootDevice(const Uevent& uevent) const;
private:
void ColdbootDone() override;
diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp
index d3719ee..9522159 100644
--- a/libprocessgroup/processgroup.cpp
+++ b/libprocessgroup/processgroup.cpp
@@ -37,19 +37,18 @@
#include <mutex>
#include <set>
#include <string>
+#include <string_view>
#include <thread>
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
-#include <android-base/strings.h>
#include <cutils/android_filesystem_config.h>
#include <processgroup/processgroup.h>
#include <task_profiles.h>
using android::base::GetBoolProperty;
-using android::base::StartsWith;
using android::base::StringPrintf;
using android::base::WriteStringToFile;
@@ -255,7 +254,7 @@
continue;
}
- if (!StartsWith(dir->d_name, "pid_")) {
+ if (!std::string_view(dir->d_name).starts_with("pid_")) {
continue;
}
@@ -296,7 +295,7 @@
continue;
}
- if (!StartsWith(dir->d_name, "uid_")) {
+ if (!std::string_view(dir->d_name).starts_with("uid_")) {
continue;
}
diff --git a/libprocessgroup/task_profiles.cpp b/libprocessgroup/task_profiles.cpp
index f3594e3..dc6c8c0 100644
--- a/libprocessgroup/task_profiles.cpp
+++ b/libprocessgroup/task_profiles.cpp
@@ -204,9 +204,6 @@
return true;
}
-// To avoid issues in sdk_mac build
-#if defined(__ANDROID__)
-
bool SetTimerSlackAction::ExecuteForTask(pid_t tid) const {
const auto file = StringPrintf("/proc/%d/timerslack_ns", tid);
if (!WriteStringToFile(std::to_string(slack_), file)) {
@@ -221,14 +218,6 @@
return true;
}
-#else
-
-bool SetTimerSlackAction::ExecuteForTask(int) const {
- return true;
-};
-
-#endif
-
bool SetAttributeAction::WriteValueToFile(const std::string& path) const {
if (!WriteStringToFile(value_, path)) {
if (access(path.c_str(), F_OK) < 0) {
diff --git a/mkbootfs/Android.bp b/mkbootfs/Android.bp
index cd2a624..e0191f0 100644
--- a/mkbootfs/Android.bp
+++ b/mkbootfs/Android.bp
@@ -6,7 +6,7 @@
cc_binary_host {
name: "mkbootfs",
- srcs: ["mkbootfs.c"],
+ srcs: ["mkbootfs.cpp"],
cflags: ["-Werror"],
static_libs: [
"libbase",
diff --git a/mkbootfs/mkbootfs.c b/mkbootfs/mkbootfs.cpp
similarity index 93%
rename from mkbootfs/mkbootfs.c
rename to mkbootfs/mkbootfs.cpp
index 84a0a4e..a45c6a2 100644
--- a/mkbootfs/mkbootfs.c
+++ b/mkbootfs/mkbootfs.cpp
@@ -19,6 +19,9 @@
#include <private/android_filesystem_config.h>
#include <private/fs_config.h>
+#include <android-base/file.h>
+#include <string>
+
/* NOTES
**
** - see https://www.kernel.org/doc/Documentation/early-userspace/buffer-format.txt
@@ -75,7 +78,7 @@
}
}
-static void _eject(struct stat *s, char *out, int olen, char *data, unsigned datasize)
+static void _eject(struct stat *s, const char *out, int olen, char *data, unsigned datasize)
{
// Nothing is special about this value, just picked something in the
// approximate range that was being used already, and avoiding small
@@ -151,9 +154,10 @@
DIR* d = opendir(in);
if (d == NULL) err(1, "cannot open directory '%s'", in);
+ // TODO: switch to std::vector
int size = 32;
int entries = 0;
- char** names = malloc(size * sizeof(char*));
+ char** names = (char**) malloc(size * sizeof(char*));
if (names == NULL) {
errx(1, "failed to allocate dir names array (size %d)", size);
}
@@ -167,7 +171,7 @@
if (entries >= size) {
size *= 2;
- names = realloc(names, size * sizeof(char*));
+ names = (char**) realloc(names, size * sizeof(char*));
if (names == NULL) {
errx(1, "failed to reallocate dir names array (size %d)", size);
}
@@ -211,20 +215,12 @@
if(lstat(in, &s)) err(1, "could not stat '%s'", in);
if(S_ISREG(s.st_mode)){
- int fd = open(in, O_RDONLY);
- if(fd < 0) err(1, "cannot open '%s' for read", in);
-
- char* tmp = (char*) malloc(s.st_size);
- if(tmp == 0) errx(1, "cannot allocate %zd bytes", s.st_size);
-
- if(read(fd, tmp, s.st_size) != s.st_size) {
- err(1, "cannot read %zd bytes", s.st_size);
+ std::string content;
+ if (!android::base::ReadFileToString(in, &content)) {
+ err(1, "cannot read '%s'", in);
}
- _eject(&s, out, olen, tmp, s.st_size);
-
- free(tmp);
- close(fd);
+ _eject(&s, out, olen, content.data(), content.size());
} else if(S_ISDIR(s.st_mode)) {
_eject(&s, out, olen, 0, 0);
_archive_dir(in, out, ilen, olen);
@@ -445,15 +441,12 @@
int num_dirs = argc - optind;
argv += optind;
- while(num_dirs-- > 0){
+ while (num_dirs-- > 0){
char *x = strchr(*argv, '=');
- if(x != 0) {
- *x++ = 0;
- } else {
- x = "";
+ if (x != nullptr) {
+ *x++ = '\0';
}
-
- archive(*argv, x);
+ archive(*argv, x ?: "");
argv++;
}
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 12d9c43..5bb64cc 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -70,6 +70,9 @@
start ueventd
+ # Mount tracefs (with GID=AID_READTRACEFS)
+ mount tracefs tracefs /sys/kernel/tracing gid=3012
+
# Run apexd-bootstrap so that APEXes that provide critical libraries
# become available. Note that this is executed as exec_start to ensure that
# the libraries are available to the processes started after this statement.
@@ -80,9 +83,6 @@
mkdir /dev/boringssl 0755 root root
mkdir /dev/boringssl/selftest 0755 root root
- # Mount tracefs (with GID=AID_READTRACEFS)
- mount tracefs tracefs /sys/kernel/tracing gid=3012
-
# create sys dirctory
mkdir /dev/sys 0755 system system
mkdir /dev/sys/fs 0755 system system
diff --git a/trusty/keymaster/Android.bp b/trusty/keymaster/Android.bp
index aca59b6..cb07829 100644
--- a/trusty/keymaster/Android.bp
+++ b/trusty/keymaster/Android.bp
@@ -105,19 +105,17 @@
"keymint/TrustySharedSecret.cpp",
"keymint/service.cpp",
],
- defaults: [
- "keymint_use_latest_hal_aidl_ndk_shared",
- ],
shared_libs: [
+ "android.hardware.security.keymint-V3-ndk",
"android.hardware.security.rkp-V3-ndk",
"android.hardware.security.secureclock-V1-ndk",
"android.hardware.security.sharedsecret-V1-ndk",
- "lib_android_keymaster_keymint_utils",
+ "lib_android_keymaster_keymint_utils_V3",
"libbase",
"libbinder_ndk",
"libhardware",
"libkeymaster_messages",
- "libkeymint",
+ "libkeymasterconfig",
"liblog",
"libtrusty",
"libutils",