From 2292db819bacc74a38334dc7da543856ac14de4e Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Tue, 13 Dec 2016 21:53:31 -0800 Subject: Add update_bootloader_message() to fix two-step OTAs. This is a retry of commit 7e31f421a514da09b90e46dbd642a5e9b16e0003. Commit bd56f1590c967205dc45eb2ec298aa8d2aacb740 switches to calling write_bootloader_message() in get_args(), which unintentionally resets the stage field thus breaks two-step OTAs. This CL adds update_bootloader_message(), which only sets the command field (to "boot-recovery") and the recovery field (with the specified options). Bug: 33534933 Test: Apply a two-step package. Test: recovery_component_test passes. Change-Id: Ie0b1ed4053d2d3c97d9cb84310d616b28fcfc72e --- tests/component/bootloader_message_test.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests') diff --git a/tests/component/bootloader_message_test.cpp b/tests/component/bootloader_message_test.cpp index cff129cfc..dbcaf619e 100644 --- a/tests/component/bootloader_message_test.cpp +++ b/tests/component/bootloader_message_test.cpp @@ -137,3 +137,29 @@ TEST_F(BootloaderMessageTest, write_bootloader_message_options_long) { ASSERT_EQ(std::string(sizeof(boot.reserved), '\0'), std::string(boot.reserved, sizeof(boot.reserved))); } + +TEST_F(BootloaderMessageTest, update_bootloader_message) { + // Inject some bytes into boot, which should be not overwritten later. + bootloader_message boot; + strlcpy(boot.recovery, "random message", sizeof(boot.recovery)); + strlcpy(boot.reserved, "reserved bytes", sizeof(boot.reserved)); + std::string err; + ASSERT_TRUE(write_bootloader_message(boot, &err)) << "Failed to write BCB: " << err; + + // Update the BCB message. + std::vector options = { "option1", "option2" }; + ASSERT_TRUE(update_bootloader_message(options, &err)) << "Failed to update BCB: " << err; + + bootloader_message boot_verify; + ASSERT_TRUE(read_bootloader_message(&boot_verify, &err)) << "Failed to read BCB: " << err; + + // Verify that command and recovery fields should be set. + ASSERT_EQ("boot-recovery", std::string(boot_verify.command)); + std::string expected = "recovery\n" + android::base::Join(options, "\n") + "\n"; + ASSERT_EQ(expected, std::string(boot_verify.recovery)); + + // The rest should be intact. + ASSERT_EQ(std::string(boot.status), std::string(boot_verify.status)); + ASSERT_EQ(std::string(boot.stage), std::string(boot_verify.stage)); + ASSERT_EQ(std::string(boot.reserved), std::string(boot_verify.reserved)); +} -- cgit v1.2.3