Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <bootloader_message/bootloader_message.h> |
| 18 | |
| 19 | #include <errno.h> |
| 20 | #include <fcntl.h> |
| 21 | #include <string.h> |
| 22 | |
Vic Yang | e94b64a | 2019-08-06 14:18:33 -0700 | [diff] [blame] | 23 | #include <optional> |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 24 | #include <string> |
Tao Bao | 7ae0169 | 2019-05-16 14:42:42 -0700 | [diff] [blame] | 25 | #include <string_view> |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 26 | #include <vector> |
| 27 | |
| 28 | #include <android-base/file.h> |
Steven Moreland | 1dba6a8 | 2024-02-16 22:32:43 +0000 | [diff] [blame^] | 29 | #include <android-base/hex.h> |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 30 | #include <android-base/properties.h> |
| 31 | #include <android-base/stringprintf.h> |
| 32 | #include <android-base/unique_fd.h> |
Tom Cherry | 772c93c | 2018-12-04 09:37:39 -0800 | [diff] [blame] | 33 | #include <fstab/fstab.h> |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 34 | |
Yifan Hong | d83070d | 2019-05-01 13:12:57 -0700 | [diff] [blame] | 35 | #ifndef __ANDROID__ |
| 36 | #include <cutils/memory.h> // for strlcpy |
| 37 | #endif |
| 38 | |
Tom Cherry | 72a114a | 2019-01-30 15:59:53 -0800 | [diff] [blame] | 39 | using android::fs_mgr::Fstab; |
| 40 | using android::fs_mgr::ReadDefaultFstab; |
| 41 | |
Vic Yang | e94b64a | 2019-08-06 14:18:33 -0700 | [diff] [blame] | 42 | static std::optional<std::string> g_misc_device_for_test; |
Tao Bao | 7ae0169 | 2019-05-16 14:42:42 -0700 | [diff] [blame] | 43 | |
| 44 | // Exposed for test purpose. |
| 45 | void SetMiscBlockDeviceForTest(std::string_view misc_device) { |
| 46 | g_misc_device_for_test = misc_device; |
| 47 | } |
| 48 | |
Tianjie Xu | 3d57c84 | 2019-11-09 22:07:20 -0800 | [diff] [blame] | 49 | std::string get_misc_blk_device(std::string* err) { |
Vic Yang | e94b64a | 2019-08-06 14:18:33 -0700 | [diff] [blame] | 50 | if (g_misc_device_for_test.has_value() && !g_misc_device_for_test->empty()) { |
| 51 | return *g_misc_device_for_test; |
Tao Bao | 7ae0169 | 2019-05-16 14:42:42 -0700 | [diff] [blame] | 52 | } |
Tom Cherry | 772c93c | 2018-12-04 09:37:39 -0800 | [diff] [blame] | 53 | Fstab fstab; |
| 54 | if (!ReadDefaultFstab(&fstab)) { |
Bowgo Tsai | d13b6cf | 2017-03-10 16:00:40 +0800 | [diff] [blame] | 55 | *err = "failed to read default fstab"; |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 56 | return ""; |
| 57 | } |
Tom Cherry | 772c93c | 2018-12-04 09:37:39 -0800 | [diff] [blame] | 58 | for (const auto& entry : fstab) { |
| 59 | if (entry.mount_point == "/misc") { |
| 60 | return entry.blk_device; |
| 61 | } |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 62 | } |
Tom Cherry | 772c93c | 2018-12-04 09:37:39 -0800 | [diff] [blame] | 63 | |
| 64 | *err = "failed to find /misc partition"; |
| 65 | return ""; |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | // In recovery mode, recovery can get started and try to access the misc |
| 69 | // device before the kernel has actually created it. |
| 70 | static bool wait_for_device(const std::string& blk_device, std::string* err) { |
| 71 | int tries = 0; |
| 72 | int ret; |
| 73 | err->clear(); |
| 74 | do { |
| 75 | ++tries; |
| 76 | struct stat buf; |
| 77 | ret = stat(blk_device.c_str(), &buf); |
| 78 | if (ret == -1) { |
| 79 | *err += android::base::StringPrintf("failed to stat %s try %d: %s\n", |
| 80 | blk_device.c_str(), tries, strerror(errno)); |
| 81 | sleep(1); |
| 82 | } |
| 83 | } while (ret && tries < 10); |
| 84 | |
| 85 | if (ret) { |
| 86 | *err += android::base::StringPrintf("failed to stat %s\n", blk_device.c_str()); |
| 87 | } |
| 88 | return ret == 0; |
| 89 | } |
| 90 | |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 91 | static bool read_misc_partition(void* p, size_t size, const std::string& misc_blk_device, |
| 92 | size_t offset, std::string* err) { |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 93 | if (!wait_for_device(misc_blk_device, err)) { |
| 94 | return false; |
| 95 | } |
Yabin Cui | 0d5b859 | 2016-07-06 11:47:23 -0700 | [diff] [blame] | 96 | android::base::unique_fd fd(open(misc_blk_device.c_str(), O_RDONLY)); |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 97 | if (fd == -1) { |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 98 | *err = android::base::StringPrintf("failed to open %s: %s", misc_blk_device.c_str(), |
| 99 | strerror(errno)); |
| 100 | return false; |
| 101 | } |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 102 | if (lseek(fd, static_cast<off_t>(offset), SEEK_SET) != static_cast<off_t>(offset)) { |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 103 | *err = android::base::StringPrintf("failed to lseek %s: %s", misc_blk_device.c_str(), |
| 104 | strerror(errno)); |
| 105 | return false; |
| 106 | } |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 107 | if (!android::base::ReadFully(fd, p, size)) { |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 108 | *err = android::base::StringPrintf("failed to read %s: %s", misc_blk_device.c_str(), |
| 109 | strerror(errno)); |
| 110 | return false; |
| 111 | } |
| 112 | return true; |
| 113 | } |
| 114 | |
Tianjie Xu | 3d57c84 | 2019-11-09 22:07:20 -0800 | [diff] [blame] | 115 | bool write_misc_partition(const void* p, size_t size, const std::string& misc_blk_device, |
| 116 | size_t offset, std::string* err) { |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 117 | android::base::unique_fd fd(open(misc_blk_device.c_str(), O_WRONLY)); |
| 118 | if (fd == -1) { |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 119 | *err = android::base::StringPrintf("failed to open %s: %s", misc_blk_device.c_str(), |
| 120 | strerror(errno)); |
| 121 | return false; |
| 122 | } |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 123 | if (lseek(fd, static_cast<off_t>(offset), SEEK_SET) != static_cast<off_t>(offset)) { |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 124 | *err = android::base::StringPrintf("failed to lseek %s: %s", misc_blk_device.c_str(), |
| 125 | strerror(errno)); |
| 126 | return false; |
| 127 | } |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 128 | if (!android::base::WriteFully(fd, p, size)) { |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 129 | *err = android::base::StringPrintf("failed to write %s: %s", misc_blk_device.c_str(), |
| 130 | strerror(errno)); |
| 131 | return false; |
| 132 | } |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 133 | if (fsync(fd) == -1) { |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 134 | *err = android::base::StringPrintf("failed to fsync %s: %s", misc_blk_device.c_str(), |
| 135 | strerror(errno)); |
| 136 | return false; |
| 137 | } |
| 138 | return true; |
| 139 | } |
| 140 | |
Alex Deymo | fb00d82 | 2016-11-08 15:46:07 -0800 | [diff] [blame] | 141 | std::string get_bootloader_message_blk_device(std::string* err) { |
| 142 | std::string misc_blk_device = get_misc_blk_device(err); |
| 143 | if (misc_blk_device.empty()) return ""; |
| 144 | if (!wait_for_device(misc_blk_device, err)) return ""; |
| 145 | return misc_blk_device; |
| 146 | } |
| 147 | |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 148 | bool read_bootloader_message_from(bootloader_message* boot, const std::string& misc_blk_device, |
| 149 | std::string* err) { |
| 150 | return read_misc_partition(boot, sizeof(*boot), misc_blk_device, |
| 151 | BOOTLOADER_MESSAGE_OFFSET_IN_MISC, err); |
| 152 | } |
| 153 | |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 154 | bool read_bootloader_message(bootloader_message* boot, std::string* err) { |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 155 | std::string misc_blk_device = get_misc_blk_device(err); |
| 156 | if (misc_blk_device.empty()) { |
| 157 | return false; |
| 158 | } |
| 159 | return read_bootloader_message_from(boot, misc_blk_device, err); |
| 160 | } |
| 161 | |
| 162 | bool write_bootloader_message_to(const bootloader_message& boot, const std::string& misc_blk_device, |
| 163 | std::string* err) { |
| 164 | return write_misc_partition(&boot, sizeof(boot), misc_blk_device, |
| 165 | BOOTLOADER_MESSAGE_OFFSET_IN_MISC, err); |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | bool write_bootloader_message(const bootloader_message& boot, std::string* err) { |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 169 | std::string misc_blk_device = get_misc_blk_device(err); |
| 170 | if (misc_blk_device.empty()) { |
| 171 | return false; |
| 172 | } |
| 173 | return write_bootloader_message_to(boot, misc_blk_device, err); |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | bool clear_bootloader_message(std::string* err) { |
| 177 | bootloader_message boot = {}; |
| 178 | return write_bootloader_message(boot, err); |
| 179 | } |
| 180 | |
| 181 | bool write_bootloader_message(const std::vector<std::string>& options, std::string* err) { |
Tao Bao | 26d5ae7 | 2016-12-13 01:06:24 +0000 | [diff] [blame] | 182 | bootloader_message boot = {}; |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 183 | update_bootloader_message_in_struct(&boot, options); |
| 184 | |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 185 | return write_bootloader_message(boot, err); |
| 186 | } |
| 187 | |
Yifan Hong | c784ce5 | 2019-05-01 13:13:58 -0700 | [diff] [blame] | 188 | bool write_bootloader_message_to(const std::vector<std::string>& options, |
| 189 | const std::string& misc_blk_device, std::string* err) { |
| 190 | bootloader_message boot = {}; |
| 191 | update_bootloader_message_in_struct(&boot, options); |
| 192 | |
| 193 | return write_bootloader_message_to(boot, misc_blk_device, err); |
| 194 | } |
| 195 | |
Tao Bao | 2292db8 | 2016-12-13 21:53:31 -0800 | [diff] [blame] | 196 | bool update_bootloader_message(const std::vector<std::string>& options, std::string* err) { |
| 197 | bootloader_message boot; |
| 198 | if (!read_bootloader_message(&boot, err)) { |
| 199 | return false; |
| 200 | } |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 201 | update_bootloader_message_in_struct(&boot, options); |
Tao Bao | 2292db8 | 2016-12-13 21:53:31 -0800 | [diff] [blame] | 202 | |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 203 | return write_bootloader_message(boot, err); |
| 204 | } |
Tao Bao | 2292db8 | 2016-12-13 21:53:31 -0800 | [diff] [blame] | 205 | |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 206 | bool update_bootloader_message_in_struct(bootloader_message* boot, |
| 207 | const std::vector<std::string>& options) { |
| 208 | if (!boot) return false; |
| 209 | // Replace the command & recovery fields. |
| 210 | memset(boot->command, 0, sizeof(boot->command)); |
| 211 | memset(boot->recovery, 0, sizeof(boot->recovery)); |
| 212 | |
Gregory Montoir | 4a4ada9 | 2023-02-14 07:23:42 +0000 | [diff] [blame] | 213 | strlcpy(boot->command, "boot-recovery", sizeof(boot->command)); |
Yifan Hong | d83070d | 2019-05-01 13:12:57 -0700 | [diff] [blame] | 214 | |
| 215 | std::string recovery = "recovery\n"; |
Tao Bao | 2292db8 | 2016-12-13 21:53:31 -0800 | [diff] [blame] | 216 | for (const auto& s : options) { |
Yifan Hong | d83070d | 2019-05-01 13:12:57 -0700 | [diff] [blame] | 217 | recovery += s; |
Tao Bao | 2292db8 | 2016-12-13 21:53:31 -0800 | [diff] [blame] | 218 | if (s.back() != '\n') { |
Yifan Hong | d83070d | 2019-05-01 13:12:57 -0700 | [diff] [blame] | 219 | recovery += '\n'; |
Tao Bao | 2292db8 | 2016-12-13 21:53:31 -0800 | [diff] [blame] | 220 | } |
| 221 | } |
Yifan Hong | d83070d | 2019-05-01 13:12:57 -0700 | [diff] [blame] | 222 | strlcpy(boot->recovery, recovery.c_str(), sizeof(boot->recovery)); |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 223 | return true; |
Tao Bao | 2292db8 | 2016-12-13 21:53:31 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Vineela Tummalapalli | cba7fa8 | 2016-10-28 19:44:40 -0700 | [diff] [blame] | 226 | bool write_reboot_bootloader(std::string* err) { |
| 227 | bootloader_message boot; |
| 228 | if (!read_bootloader_message(&boot, err)) { |
| 229 | return false; |
| 230 | } |
| 231 | if (boot.command[0] != '\0') { |
| 232 | *err = "Bootloader command pending."; |
| 233 | return false; |
| 234 | } |
| 235 | strlcpy(boot.command, "bootonce-bootloader", sizeof(boot.command)); |
| 236 | return write_bootloader_message(boot, err); |
| 237 | } |
| 238 | |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 239 | bool read_wipe_package(std::string* package_data, size_t size, std::string* err) { |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 240 | std::string misc_blk_device = get_misc_blk_device(err); |
| 241 | if (misc_blk_device.empty()) { |
| 242 | return false; |
| 243 | } |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 244 | package_data->resize(size); |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 245 | return read_misc_partition(&(*package_data)[0], size, misc_blk_device, |
| 246 | WIPE_PACKAGE_OFFSET_IN_MISC, err); |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | bool write_wipe_package(const std::string& package_data, std::string* err) { |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 250 | std::string misc_blk_device = get_misc_blk_device(err); |
| 251 | if (misc_blk_device.empty()) { |
| 252 | return false; |
| 253 | } |
David Anderson | 4ff4cbd | 2019-11-04 13:09:38 -0800 | [diff] [blame] | 254 | static constexpr size_t kMaximumWipePackageSize = |
| 255 | SYSTEM_SPACE_OFFSET_IN_MISC - WIPE_PACKAGE_OFFSET_IN_MISC; |
| 256 | if (package_data.size() > kMaximumWipePackageSize) { |
| 257 | *err = "Wipe package size " + std::to_string(package_data.size()) + " exceeds " + |
| 258 | std::to_string(kMaximumWipePackageSize) + " bytes"; |
| 259 | return false; |
| 260 | } |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 261 | return write_misc_partition(package_data.data(), package_data.size(), misc_blk_device, |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 262 | WIPE_PACKAGE_OFFSET_IN_MISC, err); |
| 263 | } |
| 264 | |
David Anderson | cf8427a | 2019-11-04 14:08:11 -0800 | [diff] [blame] | 265 | static bool ValidateSystemSpaceRegion(size_t offset, size_t size, std::string* err) { |
| 266 | if (size <= SYSTEM_SPACE_SIZE_IN_MISC && offset <= (SYSTEM_SPACE_SIZE_IN_MISC - size)) { |
| 267 | return true; |
| 268 | } |
| 269 | *err = android::base::StringPrintf("Out of bound access (offset %zu size %zu)", offset, size); |
| 270 | return false; |
| 271 | } |
| 272 | |
| 273 | static bool ReadMiscPartitionSystemSpace(void* data, size_t size, size_t offset, std::string* err) { |
| 274 | if (!ValidateSystemSpaceRegion(offset, size, err)) { |
| 275 | return false; |
| 276 | } |
| 277 | auto misc_blk_device = get_misc_blk_device(err); |
| 278 | if (misc_blk_device.empty()) { |
| 279 | return false; |
| 280 | } |
| 281 | return read_misc_partition(data, size, misc_blk_device, SYSTEM_SPACE_OFFSET_IN_MISC + offset, |
| 282 | err); |
| 283 | } |
| 284 | |
| 285 | static bool WriteMiscPartitionSystemSpace(const void* data, size_t size, size_t offset, |
| 286 | std::string* err) { |
| 287 | if (!ValidateSystemSpaceRegion(offset, size, err)) { |
| 288 | return false; |
| 289 | } |
| 290 | auto misc_blk_device = get_misc_blk_device(err); |
| 291 | if (misc_blk_device.empty()) { |
| 292 | return false; |
| 293 | } |
| 294 | return write_misc_partition(data, size, misc_blk_device, SYSTEM_SPACE_OFFSET_IN_MISC + offset, |
| 295 | err); |
| 296 | } |
| 297 | |
| 298 | bool ReadMiscVirtualAbMessage(misc_virtual_ab_message* message, std::string* err) { |
| 299 | return ReadMiscPartitionSystemSpace(message, sizeof(*message), |
| 300 | offsetof(misc_system_space_layout, virtual_ab_message), err); |
| 301 | } |
| 302 | |
| 303 | bool WriteMiscVirtualAbMessage(const misc_virtual_ab_message& message, std::string* err) { |
| 304 | return WriteMiscPartitionSystemSpace(&message, sizeof(message), |
| 305 | offsetof(misc_system_space_layout, virtual_ab_message), err); |
| 306 | } |
| 307 | |
Florian Mayer | cf3234a | 2021-12-08 17:49:09 -0800 | [diff] [blame] | 308 | bool ReadMiscMemtagMessage(misc_memtag_message* message, std::string* err) { |
| 309 | return ReadMiscPartitionSystemSpace(message, sizeof(*message), |
| 310 | offsetof(misc_system_space_layout, memtag_message), err); |
| 311 | } |
| 312 | |
| 313 | bool WriteMiscMemtagMessage(const misc_memtag_message& message, std::string* err) { |
| 314 | return WriteMiscPartitionSystemSpace(&message, sizeof(message), |
| 315 | offsetof(misc_system_space_layout, memtag_message), err); |
| 316 | } |
| 317 | |
Alice Ryhl | a4aec2f | 2024-01-12 13:10:05 +0000 | [diff] [blame] | 318 | bool ReadMiscKcmdlineMessage(misc_kcmdline_message* message, std::string* err) { |
| 319 | return ReadMiscPartitionSystemSpace(message, sizeof(*message), |
| 320 | offsetof(misc_system_space_layout, kcmdline_message), err); |
| 321 | } |
| 322 | |
| 323 | bool WriteMiscKcmdlineMessage(const misc_kcmdline_message& message, std::string* err) { |
| 324 | return WriteMiscPartitionSystemSpace(&message, sizeof(message), |
| 325 | offsetof(misc_system_space_layout, kcmdline_message), err); |
| 326 | } |
| 327 | |
Steven Moreland | 1dba6a8 | 2024-02-16 22:32:43 +0000 | [diff] [blame^] | 328 | bool CheckReservedSystemSpaceEmpty(bool* empty, std::string* err) { |
| 329 | constexpr size_t kReservedSize = SYSTEM_SPACE_SIZE_IN_MISC - sizeof(misc_system_space_layout); |
| 330 | |
| 331 | uint8_t space[kReservedSize]; |
| 332 | if (!ReadMiscPartitionSystemSpace(&space, kReservedSize, sizeof(misc_system_space_layout), err)) { |
| 333 | return false; |
| 334 | } |
| 335 | |
| 336 | *empty = space[0] == 0 && 0 == memcmp(space, space + 1, kReservedSize - 1); |
| 337 | |
| 338 | if (!*empty) { |
| 339 | *err = android::base::HexString(space, kReservedSize); |
| 340 | } |
| 341 | |
| 342 | return true; |
| 343 | } |
| 344 | |
Vineela Tummalapalli | cba7fa8 | 2016-10-28 19:44:40 -0700 | [diff] [blame] | 345 | extern "C" bool write_reboot_bootloader(void) { |
| 346 | std::string err; |
| 347 | return write_reboot_bootloader(&err); |
| 348 | } |
| 349 | |
Yabin Cui | 8b309f6 | 2016-06-24 18:22:02 -0700 | [diff] [blame] | 350 | extern "C" bool write_bootloader_message(const char* options) { |
| 351 | std::string err; |
| 352 | return write_bootloader_message({options}, &err); |
| 353 | } |