summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Chang <richardycc@google.com>2023-05-18 11:30:14 +0000
committerRichard Chang <richardycc@google.com>2023-05-24 04:04:25 +0000
commitdef16296b0e4a2431d31b7f5126541d8bea23b65 (patch)
tree52f860e0f6fc2abafa729a0c2c016a55377a293c
parent7bc2dc895e10ff9c3361165e6b56474fbb0c3f49 (diff)
downloadpixel-def16296b0e4a2431d31b7f5126541d8bea23b65.tar.gz
misc_writer: add max_ram_size configuration
Communicate the max_ram_size settings with bootloader by writing to misc. This configuration will be used in experiments that limit the maximum ddr size on the devices instead of the hardware ddr size. Bootloader will generally ignore this configuration on secured devices. Ignore the clang_format and cpplint from repo hooks. Bug: 279871595 Test: Run misc_writer_test Test: misc_writer --set-max-ram-size 8192, and check misc partition Test: misc_writer --set-max-ram-size -1, and check misc partition Change-Id: I9546e9dceba341a92eff0c769560114bd069760c
-rw-r--r--misc_writer/include/misc_writer/misc_writer.h9
-rw-r--r--misc_writer/misc_writer.cpp7
-rw-r--r--misc_writer/misc_writer_main.cpp25
-rw-r--r--misc_writer/misc_writer_test.cpp13
4 files changed, 54 insertions, 0 deletions
diff --git a/misc_writer/include/misc_writer/misc_writer.h b/misc_writer/include/misc_writer/misc_writer.h
index 3ae0a15b..ce3da5c8 100644
--- a/misc_writer/include/misc_writer/misc_writer.h
+++ b/misc_writer/include/misc_writer/misc_writer.h
@@ -38,6 +38,8 @@ enum class MiscWriterActions : int32_t {
kClearWristOrientationFlag,
kWriteTimeFormat,
kWriteTimeOffset,
+ kSetMaxRamSize,
+ kClearMaxRamSize,
kUnset = -1,
};
@@ -57,6 +59,13 @@ class MiscWriter {
static constexpr char kTimeFormat[] = "timeformat=";
static constexpr uint32_t kTimeOffsetValOffsetInVendorSpace = 160;
static constexpr char kTimeOffset[] = "timeoffset=";
+ static constexpr uint32_t kMaxRamSizeOffsetInVendorSpace = 192;
+ static constexpr char kMaxRamSize[] = "max-ram-size=";
+
+ // Minimum and maximum valid value for max-ram-size
+ static constexpr int32_t kRamSizeDefault = -1;
+ static constexpr uint32_t kRamSizeMin = 2048;
+ static constexpr uint32_t kRamSizeMax = 65536;
// Minimum and maximum time zone are -12 and 14 hours from GMT
static constexpr int32_t kMinTimeOffset = -12 * 60 * 60 * 1000;
diff --git a/misc_writer/misc_writer.cpp b/misc_writer/misc_writer.cpp
index f3ef1418..8458649f 100644
--- a/misc_writer/misc_writer.cpp
+++ b/misc_writer/misc_writer.cpp
@@ -86,6 +86,13 @@ bool MiscWriter::PerformAction(std::optional<size_t> override_offset) {
content = std::string(kTimeOffset) + stringdata_;
content.resize(strlen(kTimeOffset) + std::to_string(kMinTimeOffset).size(), 0);
break;
+ case MiscWriterActions::kSetMaxRamSize:
+ case MiscWriterActions::kClearMaxRamSize:
+ offset = override_offset.value_or(kMaxRamSizeOffsetInVendorSpace);
+ content = (action_ == MiscWriterActions::kSetMaxRamSize)
+ ? std::string(kMaxRamSize).append(stringdata_).append("\n")
+ : std::string(32, 0);
+ break;
case MiscWriterActions::kUnset:
LOG(ERROR) << "The misc writer action must be set";
return false;
diff --git a/misc_writer/misc_writer_main.cpp b/misc_writer/misc_writer_main.cpp
index 164d27e4..0af45a91 100644
--- a/misc_writer/misc_writer_main.cpp
+++ b/misc_writer/misc_writer_main.cpp
@@ -48,6 +48,8 @@ static int Usage(std::string_view name) {
std::cerr << " --clear-wrist-orientation Clear the wrist orientation flag\n";
std::cerr << " --set-timeformat Write the time format value (1=24hr, 0=12hr)\n";
std::cerr << " --set-timeoffset Write the time offset value (tz_time - utc_time)\n";
+ std::cerr << " --set-max-ram-size <2048-65536> Write the sw limit max ram size in MB\n";
+ std::cerr << " --set-max-ram-size <-1> Clear the sw limit max ram size\n";
std::cerr << "Writes the given hex string to the specified offset in vendor space in /misc "
"partition.\nDefault offset is used for each action unless "
"--override-vendor-space-offset is specified.\n";
@@ -68,6 +70,7 @@ int main(int argc, char** argv) {
{ "set-disable-pkvm", no_argument, nullptr, 0 },
{ "set-timeformat", required_argument, nullptr, 0},
{ "set-timeoffset", required_argument, nullptr, 0},
+ { "set-max-ram-size", required_argument, nullptr, 0},
{ nullptr, 0, nullptr, 0 },
};
@@ -148,6 +151,28 @@ int main(int argc, char** argv) {
}
misc_writer = std::make_unique<MiscWriter>(MiscWriterActions::kWriteTimeOffset,
std::to_string(timeoffset));
+ } else if (option_name == "set-max-ram-size"s) {
+ int max_ram_size;
+ if (!android::base::ParseInt(optarg, &max_ram_size)) {
+ LOG(ERROR) << "Failed to parse the max_ram_size: " << optarg;
+ return Usage(argv[0]);
+ }
+ if (max_ram_size != MiscWriter::kRamSizeDefault &&
+ (max_ram_size < MiscWriter::kRamSizeMin || max_ram_size > MiscWriter::kRamSizeMax)) {
+ LOG(ERROR) << "max_ram_size out of range: " << optarg;
+ return Usage(argv[0]);
+ }
+ if (misc_writer) {
+ LOG(ERROR) << "Misc writer action has already been set";
+ return Usage(argv[0]);
+ }
+
+ if (max_ram_size == MiscWriter::kRamSizeDefault) {
+ misc_writer = std::make_unique<MiscWriter>(MiscWriterActions::kClearMaxRamSize);
+ } else {
+ misc_writer = std::make_unique<MiscWriter>(MiscWriterActions::kSetMaxRamSize,
+ std::to_string(max_ram_size));
+ }
} else if (auto iter = action_map.find(option_name); iter != action_map.end()) {
if (misc_writer) {
LOG(ERROR) << "Misc writer action has already been set";
diff --git a/misc_writer/misc_writer_test.cpp b/misc_writer/misc_writer_test.cpp
index e8b207af..651f6409 100644
--- a/misc_writer/misc_writer_test.cpp
+++ b/misc_writer/misc_writer_test.cpp
@@ -106,6 +106,19 @@ TEST_F(MiscWriterTest, SetClearSota) {
CheckMiscPartitionVendorSpaceContent(32, zeros);
}
+TEST_F(MiscWriterTest, SetMaxRamSize) {
+ misc_writer_ = std::make_unique<MiscWriter>(MiscWriterActions::kSetMaxRamSize, "8192");
+ size_t offset = MiscWriter::kMaxRamSizeOffsetInVendorSpace;
+ ASSERT_TRUE(misc_writer_->PerformAction(offset));
+ std::string expected = std::string(MiscWriter::kMaxRamSize) + "8192";
+ CheckMiscPartitionVendorSpaceContent(offset, expected);
+
+ misc_writer_ = std::make_unique<MiscWriter>(MiscWriterActions::kClearMaxRamSize);
+ ASSERT_TRUE(misc_writer_->PerformAction(offset));
+ std::string zeros(expected.size(), 0);
+ CheckMiscPartitionVendorSpaceContent(offset, zeros);
+}
+
TEST_F(MiscWriterTest, WriteMiscPartitionVendorSpace) {
std::string kTestMessage = "kTestMessage";
std::string err;