Loading fastboot/Android.bp +8 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ cc_library_host_static { "libgtest_main", "libbase", "libadb_host", "liblp", ], header_libs: [ Loading Loading @@ -173,6 +174,11 @@ cc_defaults { host_ldlibs: ["-lws2_32"], }, not_windows: { static_libs: [ "libext4_utils", ], }, }, stl: "libc++_static", Loading @@ -193,6 +199,8 @@ cc_defaults { "libbase", "libcutils", "libgtest_host", "liblp", "libcrypto", ], } Loading fastboot/fastboot.cpp +41 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,7 @@ #include <android-base/strings.h> #include <android-base/unique_fd.h> #include <build/version.h> #include <liblp/liblp.h> #include <platform_tools_version.h> #include <sparse/sparse.h> #include <ziparchive/zip_archive.h> Loading Loading @@ -407,6 +408,7 @@ static int show_help() { " -s SERIAL Specify a USB device.\n" " -s tcp|udp:HOST[:PORT] Specify a network device.\n" " -S SIZE[K|M|G] Break into sparse files no larger than SIZE.\n" " --force Force a flash operation that may be unsafe.\n" " --slot SLOT Use SLOT; 'all' for both slots, 'other' for\n" " non-current slot (default: current active slot).\n" " --set-active[=SLOT] Sets the active slot before rebooting.\n" Loading Loading @@ -1505,6 +1507,31 @@ failed: fprintf(stderr, "FAILED (%s)\n", fb->Error().c_str()); } static bool should_flash_in_userspace(const std::string& partition_name) { auto path = find_item_given_name("super_empty.img"); if (path.empty()) { return false; } auto metadata = android::fs_mgr::ReadFromImageFile(path); if (!metadata) { return false; } for (const auto& partition : metadata->partitions) { auto candidate = android::fs_mgr::GetPartitionName(partition); if (partition.attributes & LP_PARTITION_ATTR_SLOT_SUFFIXED) { // On retrofit devices, we don't know if, or whether, the A or B // slot has been flashed for dynamic partitions. Instead we add // both names to the list as a conservative guess. if (candidate + "_a" == partition_name || candidate + "_b" == partition_name) { return true; } } else if (candidate == partition_name) { return true; } } return false; } int FastBootTool::Main(int argc, char* argv[]) { bool wants_wipe = false; bool wants_reboot = false; Loading @@ -1515,6 +1542,7 @@ int FastBootTool::Main(int argc, char* argv[]) { bool wants_set_active = false; bool skip_secondary = false; bool set_fbe_marker = false; bool force_flash = false; int longindex; std::string slot_override; std::string next_active; Loading @@ -1530,6 +1558,7 @@ int FastBootTool::Main(int argc, char* argv[]) { {"cmdline", required_argument, 0, 0}, {"disable-verification", no_argument, 0, 0}, {"disable-verity", no_argument, 0, 0}, {"force", no_argument, 0, 0}, {"header-version", required_argument, 0, 0}, {"help", no_argument, 0, 'h'}, {"kernel-offset", required_argument, 0, 0}, Loading Loading @@ -1565,6 +1594,8 @@ int FastBootTool::Main(int argc, char* argv[]) { g_disable_verification = true; } else if (name == "disable-verity") { g_disable_verity = true; } else if (name == "force") { force_flash = true; } else if (name == "header-version") { g_boot_img_hdr.header_version = strtoul(optarg, nullptr, 0); } else if (name == "kernel-offset") { Loading Loading @@ -1779,6 +1810,16 @@ int FastBootTool::Main(int argc, char* argv[]) { if (fname.empty()) die("cannot determine image filename for '%s'", pname.c_str()); auto flash = [&](const std::string &partition) { if (should_flash_in_userspace(partition) && !is_userspace_fastboot() && !force_flash) { die("The partition you are trying to flash is dynamic, and " "should be flashed via fastbootd. Please run:\n" "\n" " fastboot reboot fastboot\n" "\n" "And try again. If you are intentionally trying to " "overwrite a fixed partition, use --force."); } do_flash(partition.c_str(), fname.c_str()); }; do_for_partitions(pname.c_str(), slot_override, flash, true); Loading fastboot/fuzzy_fastboot/Android.bp +3 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,9 @@ cc_test_host { "libadb_host", "libtinyxml2", "libsparse", "liblp", "libcrypto", "libext4_utils", ], // Static libs (libfastboot2) shared library dependencies are not transitively included Loading fs_mgr/liblp/images.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -67,10 +67,10 @@ std::unique_ptr<LpMetadata> ReadFromImageBlob(const void* data, size_t bytes) { return ParseMetadata(geometry, metadata_buffer, metadata_buffer_size); } std::unique_ptr<LpMetadata> ReadFromImageFile(const char* file) { unique_fd fd(open(file, O_RDONLY | O_CLOEXEC)); std::unique_ptr<LpMetadata> ReadFromImageFile(const std::string& image_file) { unique_fd fd(open(image_file.c_str(), O_RDONLY | O_CLOEXEC)); if (fd < 0) { PERROR << __PRETTY_FUNCTION__ << " open failed: " << file; PERROR << __PRETTY_FUNCTION__ << " open failed: " << image_file; return nullptr; } return ReadFromImageFile(fd); Loading fs_mgr/liblp/include/liblp/liblp.h +1 −1 Original line number Diff line number Diff line Loading @@ -75,7 +75,7 @@ std::unique_ptr<LpMetadata> ReadMetadata(const std::string& super_partition, uin bool WriteToSparseFile(const char* file, const LpMetadata& metadata, uint32_t block_size, const std::map<std::string, std::string>& images); bool WriteToImageFile(const char* file, const LpMetadata& metadata); std::unique_ptr<LpMetadata> ReadFromImageFile(const char* file); std::unique_ptr<LpMetadata> ReadFromImageFile(const std::string& image_file); std::unique_ptr<LpMetadata> ReadFromImageBlob(const void* data, size_t bytes); // Similar to WriteToSparseFile, this will generate an image that can be Loading Loading
fastboot/Android.bp +8 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ cc_library_host_static { "libgtest_main", "libbase", "libadb_host", "liblp", ], header_libs: [ Loading Loading @@ -173,6 +174,11 @@ cc_defaults { host_ldlibs: ["-lws2_32"], }, not_windows: { static_libs: [ "libext4_utils", ], }, }, stl: "libc++_static", Loading @@ -193,6 +199,8 @@ cc_defaults { "libbase", "libcutils", "libgtest_host", "liblp", "libcrypto", ], } Loading
fastboot/fastboot.cpp +41 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,7 @@ #include <android-base/strings.h> #include <android-base/unique_fd.h> #include <build/version.h> #include <liblp/liblp.h> #include <platform_tools_version.h> #include <sparse/sparse.h> #include <ziparchive/zip_archive.h> Loading Loading @@ -407,6 +408,7 @@ static int show_help() { " -s SERIAL Specify a USB device.\n" " -s tcp|udp:HOST[:PORT] Specify a network device.\n" " -S SIZE[K|M|G] Break into sparse files no larger than SIZE.\n" " --force Force a flash operation that may be unsafe.\n" " --slot SLOT Use SLOT; 'all' for both slots, 'other' for\n" " non-current slot (default: current active slot).\n" " --set-active[=SLOT] Sets the active slot before rebooting.\n" Loading Loading @@ -1505,6 +1507,31 @@ failed: fprintf(stderr, "FAILED (%s)\n", fb->Error().c_str()); } static bool should_flash_in_userspace(const std::string& partition_name) { auto path = find_item_given_name("super_empty.img"); if (path.empty()) { return false; } auto metadata = android::fs_mgr::ReadFromImageFile(path); if (!metadata) { return false; } for (const auto& partition : metadata->partitions) { auto candidate = android::fs_mgr::GetPartitionName(partition); if (partition.attributes & LP_PARTITION_ATTR_SLOT_SUFFIXED) { // On retrofit devices, we don't know if, or whether, the A or B // slot has been flashed for dynamic partitions. Instead we add // both names to the list as a conservative guess. if (candidate + "_a" == partition_name || candidate + "_b" == partition_name) { return true; } } else if (candidate == partition_name) { return true; } } return false; } int FastBootTool::Main(int argc, char* argv[]) { bool wants_wipe = false; bool wants_reboot = false; Loading @@ -1515,6 +1542,7 @@ int FastBootTool::Main(int argc, char* argv[]) { bool wants_set_active = false; bool skip_secondary = false; bool set_fbe_marker = false; bool force_flash = false; int longindex; std::string slot_override; std::string next_active; Loading @@ -1530,6 +1558,7 @@ int FastBootTool::Main(int argc, char* argv[]) { {"cmdline", required_argument, 0, 0}, {"disable-verification", no_argument, 0, 0}, {"disable-verity", no_argument, 0, 0}, {"force", no_argument, 0, 0}, {"header-version", required_argument, 0, 0}, {"help", no_argument, 0, 'h'}, {"kernel-offset", required_argument, 0, 0}, Loading Loading @@ -1565,6 +1594,8 @@ int FastBootTool::Main(int argc, char* argv[]) { g_disable_verification = true; } else if (name == "disable-verity") { g_disable_verity = true; } else if (name == "force") { force_flash = true; } else if (name == "header-version") { g_boot_img_hdr.header_version = strtoul(optarg, nullptr, 0); } else if (name == "kernel-offset") { Loading Loading @@ -1779,6 +1810,16 @@ int FastBootTool::Main(int argc, char* argv[]) { if (fname.empty()) die("cannot determine image filename for '%s'", pname.c_str()); auto flash = [&](const std::string &partition) { if (should_flash_in_userspace(partition) && !is_userspace_fastboot() && !force_flash) { die("The partition you are trying to flash is dynamic, and " "should be flashed via fastbootd. Please run:\n" "\n" " fastboot reboot fastboot\n" "\n" "And try again. If you are intentionally trying to " "overwrite a fixed partition, use --force."); } do_flash(partition.c_str(), fname.c_str()); }; do_for_partitions(pname.c_str(), slot_override, flash, true); Loading
fastboot/fuzzy_fastboot/Android.bp +3 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,9 @@ cc_test_host { "libadb_host", "libtinyxml2", "libsparse", "liblp", "libcrypto", "libext4_utils", ], // Static libs (libfastboot2) shared library dependencies are not transitively included Loading
fs_mgr/liblp/images.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -67,10 +67,10 @@ std::unique_ptr<LpMetadata> ReadFromImageBlob(const void* data, size_t bytes) { return ParseMetadata(geometry, metadata_buffer, metadata_buffer_size); } std::unique_ptr<LpMetadata> ReadFromImageFile(const char* file) { unique_fd fd(open(file, O_RDONLY | O_CLOEXEC)); std::unique_ptr<LpMetadata> ReadFromImageFile(const std::string& image_file) { unique_fd fd(open(image_file.c_str(), O_RDONLY | O_CLOEXEC)); if (fd < 0) { PERROR << __PRETTY_FUNCTION__ << " open failed: " << file; PERROR << __PRETTY_FUNCTION__ << " open failed: " << image_file; return nullptr; } return ReadFromImageFile(fd); Loading
fs_mgr/liblp/include/liblp/liblp.h +1 −1 Original line number Diff line number Diff line Loading @@ -75,7 +75,7 @@ std::unique_ptr<LpMetadata> ReadMetadata(const std::string& super_partition, uin bool WriteToSparseFile(const char* file, const LpMetadata& metadata, uint32_t block_size, const std::map<std::string, std::string>& images); bool WriteToImageFile(const char* file, const LpMetadata& metadata); std::unique_ptr<LpMetadata> ReadFromImageFile(const char* file); std::unique_ptr<LpMetadata> ReadFromImageFile(const std::string& image_file); std::unique_ptr<LpMetadata> ReadFromImageBlob(const void* data, size_t bytes); // Similar to WriteToSparseFile, this will generate an image that can be Loading