From c784ce50e8c10eaf70e1f97e24e8324aef45faf5 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Wed, 1 May 2019 13:13:58 -0700 Subject: libbootloader_message: write recovery to any device Test: cuttlefish Bug: 79094284 Change-Id: If1a6460a8cbed2e2d22fa9e16e6d7ca84f4592d0 --- bootloader_message/bootloader_message.cpp | 8 ++++++++ .../include/bootloader_message/bootloader_message.h | 5 +++++ 2 files changed, 13 insertions(+) (limited to 'bootloader_message') diff --git a/bootloader_message/bootloader_message.cpp b/bootloader_message/bootloader_message.cpp index 8c1d63bdd..0ebc04a30 100644 --- a/bootloader_message/bootloader_message.cpp +++ b/bootloader_message/bootloader_message.cpp @@ -168,6 +168,14 @@ bool write_bootloader_message(const std::vector& options, std::stri return write_bootloader_message(boot, err); } +bool write_bootloader_message_to(const std::vector& options, + const std::string& misc_blk_device, std::string* err) { + bootloader_message boot = {}; + update_bootloader_message_in_struct(&boot, options); + + return write_bootloader_message_to(boot, misc_blk_device, err); +} + bool update_bootloader_message(const std::vector& options, std::string* err) { bootloader_message boot; if (!read_bootloader_message(&boot, err)) { diff --git a/bootloader_message/include/bootloader_message/bootloader_message.h b/bootloader_message/include/bootloader_message/bootloader_message.h index 95c19ae54..2207d4cb3 100644 --- a/bootloader_message/include/bootloader_message/bootloader_message.h +++ b/bootloader_message/include/bootloader_message/bootloader_message.h @@ -207,6 +207,11 @@ bool write_bootloader_message_to(const bootloader_message& boot, // set the command and recovery fields, and reset the rest. bool write_bootloader_message(const std::vector& options, std::string* err); +// Write bootloader message (boots into recovery with the options) to the specific BCB device. Will +// set the command and recovery fields, and reset the rest. +bool write_bootloader_message_to(const std::vector& options, + const std::string& misc_blk_device, std::string* err); + // Update bootloader message (boots into recovery with the options) to BCB. Will // only update the command and recovery fields. bool update_bootloader_message(const std::vector& options, std::string* err); -- cgit v1.2.3 From d83070ddb902a5319cf9cdfcc71127b2ef6e8d1e Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Wed, 1 May 2019 13:12:57 -0700 Subject: libbootloader_message: host_supported. Also, strlcat is not available on host, so use std::string::operator+= instead. Test: cuttlefish Bug: 79094284 Change-Id: I1e69daeb522ca73f43e0c4855cf099a021ed4d47 --- bootloader_message/Android.bp | 18 +++++++++++++++++- bootloader_message/bootloader_message.cpp | 12 +++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'bootloader_message') diff --git a/bootloader_message/Android.bp b/bootloader_message/Android.bp index 5cd21323c..4ea7c8680 100644 --- a/bootloader_message/Android.bp +++ b/bootloader_message/Android.bp @@ -17,6 +17,7 @@ cc_library { name: "libbootloader_message", recovery_available: true, + host_supported: true, srcs: ["bootloader_message.cpp"], cflags: [ "-Wall", @@ -24,7 +25,22 @@ cc_library { ], shared_libs: [ "libbase", - "libfs_mgr", ], export_include_dirs: ["include"], + + target: { + android: { + shared_libs: [ + "libfs_mgr", + ], + }, + host: { + shared_libs: [ + "libcutils", // for strlcpy + ], + static_libs: [ + "libfstab", + ], + } + } } diff --git a/bootloader_message/bootloader_message.cpp b/bootloader_message/bootloader_message.cpp index 0ebc04a30..331a42b2a 100644 --- a/bootloader_message/bootloader_message.cpp +++ b/bootloader_message/bootloader_message.cpp @@ -29,6 +29,10 @@ #include #include +#ifndef __ANDROID__ +#include // for strlcpy +#endif + using android::fs_mgr::Fstab; using android::fs_mgr::ReadDefaultFstab; @@ -194,13 +198,15 @@ bool update_bootloader_message_in_struct(bootloader_message* boot, memset(boot->recovery, 0, sizeof(boot->recovery)); strlcpy(boot->command, "boot-recovery", sizeof(boot->command)); - strlcpy(boot->recovery, "recovery\n", sizeof(boot->recovery)); + + std::string recovery = "recovery\n"; for (const auto& s : options) { - strlcat(boot->recovery, s.c_str(), sizeof(boot->recovery)); + recovery += s; if (s.back() != '\n') { - strlcat(boot->recovery, "\n", sizeof(boot->recovery)); + recovery += '\n'; } } + strlcpy(boot->recovery, recovery.c_str(), sizeof(boot->recovery)); return true; } -- cgit v1.2.3