Add misc_writer.
bootloader_message.h currently divides /misc into four segments. The
space between 2K and 16K is reserved for vendor use (e.g. bootloader
persists flags). This CL adds a vendor tool "misc_writer", to allow
writing data to the vendor space in /misc, before getting a dedicated
HAL for accessing /misc partition (b/131775112).
Targets need to explicitly include the module, then invoke the
executable to write data. For example, the following command will write
3-byte data ("0xABCDEF") to offset 4 in vendor space (i.e. 2048 + 4 in
/misc).
$ /vendor/bin/misc_writer --vendor-space-offset 4 --hex-string 0xABCDEF
Bug: 132906936
Test: Run recovery_unit_test on crosshatch.
Test: Call the command via init.hardware.rc on crosshatch. Check that
the call finishes successfully. Then check the contents written to
/misc (`dd bs=1 skip=2048 if=/dev/block/sda2 count=32 | xxd`).
Change-Id: I79548fc63fc79b705a0320868690569c3106949f
Merged-In: I79548fc63fc79b705a0320868690569c3106949f
(cherry picked from commit 7ae0169842)
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <android-base/file.h>
|
||||
@@ -22,6 +23,10 @@
|
||||
#include <bootloader_message/bootloader_message.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace std::string_literals;
|
||||
|
||||
extern void SetMiscBlockDeviceForTest(std::string_view misc_device);
|
||||
|
||||
TEST(BootloaderMessageTest, read_and_write_bootloader_message) {
|
||||
TemporaryFile temp_misc;
|
||||
|
||||
@@ -114,3 +119,36 @@ TEST(BootloaderMessageTest, update_bootloader_message_recovery_options_long) {
|
||||
std::string(boot.reserved, sizeof(boot.reserved)));
|
||||
}
|
||||
|
||||
TEST(BootloaderMessageTest, WriteMiscPartitionVendorSpace) {
|
||||
TemporaryFile temp_misc;
|
||||
ASSERT_TRUE(android::base::WriteStringToFile(std::string(4096, '\x00'), temp_misc.path));
|
||||
SetMiscBlockDeviceForTest(temp_misc.path);
|
||||
|
||||
constexpr std::string_view kTestMessage = "kTestMessage";
|
||||
std::string err;
|
||||
ASSERT_TRUE(WriteMiscPartitionVendorSpace(kTestMessage.data(), kTestMessage.size(), 0, &err));
|
||||
|
||||
std::string message;
|
||||
message.resize(kTestMessage.size());
|
||||
ASSERT_TRUE(ReadMiscPartitionVendorSpace(message.data(), message.size(), 0, &err));
|
||||
ASSERT_EQ(kTestMessage, message);
|
||||
|
||||
// Write with an offset.
|
||||
ASSERT_TRUE(WriteMiscPartitionVendorSpace("\x00\x00", 2, 5, &err));
|
||||
ASSERT_TRUE(ReadMiscPartitionVendorSpace(message.data(), message.size(), 0, &err));
|
||||
ASSERT_EQ("kTest\x00\x00ssage"s, message);
|
||||
|
||||
// Write with the right size.
|
||||
auto start_offset =
|
||||
WIPE_PACKAGE_OFFSET_IN_MISC - VENDOR_SPACE_OFFSET_IN_MISC - kTestMessage.size();
|
||||
ASSERT_TRUE(
|
||||
WriteMiscPartitionVendorSpace(kTestMessage.data(), kTestMessage.size(), start_offset, &err));
|
||||
|
||||
// Out-of-bound write.
|
||||
ASSERT_FALSE(WriteMiscPartitionVendorSpace(kTestMessage.data(), kTestMessage.size(),
|
||||
start_offset + 1, &err));
|
||||
|
||||
// Message won't fit.
|
||||
std::string long_message(WIPE_PACKAGE_OFFSET_IN_MISC - VENDOR_SPACE_OFFSET_IN_MISC + 1, 'a');
|
||||
ASSERT_FALSE(WriteMiscPartitionVendorSpace(long_message.data(), long_message.size(), 0, &err));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user