diff options
Diffstat (limited to 'bootloader_message')
-rw-r--r-- | bootloader_message/Android.bp | 26 | ||||
-rw-r--r-- | bootloader_message/bootloader_message.cpp | 42 | ||||
-rw-r--r-- | bootloader_message/include/bootloader_message/bootloader_message.h | 5 |
3 files changed, 58 insertions, 15 deletions
diff --git a/bootloader_message/Android.bp b/bootloader_message/Android.bp index c81c67bdb..e76305fd7 100644 --- a/bootloader_message/Android.bp +++ b/bootloader_message/Android.bp @@ -14,16 +14,36 @@ // limitations under the License. // -cc_library_static { +cc_library { name: "libbootloader_message", + recovery_available: true, + host_supported: true, srcs: ["bootloader_message.cpp"], cflags: [ "-Wall", "-Werror", ], - static_libs: [ + shared_libs: [ "libbase", - "libfs_mgr", ], export_include_dirs: ["include"], + + target: { + android: { + shared_libs: [ + "libfs_mgr", + ], + }, + host: { + shared_libs: [ + "libcutils", // for strlcpy + ], + static_libs: [ + "libfstab", + ], + }, + darwin: { + enabled: false, + }, + } } diff --git a/bootloader_message/bootloader_message.cpp b/bootloader_message/bootloader_message.cpp index aaeffdc5c..331a42b2a 100644 --- a/bootloader_message/bootloader_message.cpp +++ b/bootloader_message/bootloader_message.cpp @@ -27,21 +27,29 @@ #include <android-base/properties.h> #include <android-base/stringprintf.h> #include <android-base/unique_fd.h> -#include <fs_mgr.h> +#include <fstab/fstab.h> + +#ifndef __ANDROID__ +#include <cutils/memory.h> // for strlcpy +#endif + +using android::fs_mgr::Fstab; +using android::fs_mgr::ReadDefaultFstab; static std::string get_misc_blk_device(std::string* err) { - std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab_default(), - fs_mgr_free_fstab); - if (!fstab) { + Fstab fstab; + if (!ReadDefaultFstab(&fstab)) { *err = "failed to read default fstab"; return ""; } - fstab_rec* record = fs_mgr_get_entry_for_mount_point(fstab.get(), "/misc"); - if (record == nullptr) { - *err = "failed to find /misc partition"; - return ""; + for (const auto& entry : fstab) { + if (entry.mount_point == "/misc") { + return entry.blk_device; + } } - return record->blk_device; + + *err = "failed to find /misc partition"; + return ""; } // In recovery mode, recovery can get started and try to access the misc @@ -164,6 +172,14 @@ bool write_bootloader_message(const std::vector<std::string>& options, std::stri return write_bootloader_message(boot, err); } +bool write_bootloader_message_to(const std::vector<std::string>& 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<std::string>& options, std::string* err) { bootloader_message boot; if (!read_bootloader_message(&boot, err)) { @@ -182,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; } 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<std::string>& 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<std::string>& 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<std::string>& options, std::string* err); |