Lines Matching refs:transport

66 #include "transport.h"
249 static Transport* transport = nullptr;
252 if (transport != nullptr) {
253 return transport;
286 transport = tcp::Connect(host, port, &error).release();
288 transport = udp::Connect(host, port, &error).release();
291 if (transport == nullptr && announce) {
295 transport = usb_open(match_fastboot);
298 if (transport != nullptr) {
299 return transport;
748 static int64_t get_target_sparse_limit(Transport* transport) {
750 if (!fb_getvar(transport, "max-download-size", &max_download_size) ||
770 static int64_t get_sparse_limit(Transport* transport, int64_t size) {
779 target_sparse_limit = get_target_sparse_limit(transport);
798 static bool needs_erase(Transport* transport, const char* partition) {
800 if (!fb_getvar(transport, std::string("partition-type:") + partition, &partition_type)) {
806 static bool load_buf_fd(Transport* transport, int fd, struct fastboot_buffer* buf) {
813 int64_t limit = get_sparse_limit(transport, sz);
832 static bool load_buf(Transport* transport, const char* fname, struct fastboot_buffer* buf) {
837 return load_buf_fd(transport, fd, buf);
869 static std::string get_current_slot(Transport* transport)
872 if (fb_getvar(transport, "current-slot", &current_slot)) {
881 static std::vector<std::string> get_suffixes_obsolete(Transport* transport) {
884 if (!fb_getvar(transport, "slot-suffixes", &suffix_list)) {
898 static bool supports_AB_obsolete(Transport* transport) {
899 return !get_suffixes_obsolete(transport).empty();
902 static int get_slot_count(Transport* transport) {
905 if (!fb_getvar(transport, "slot-count", &var)) {
906 if (supports_AB_obsolete(transport)) return 2; // Legacy support
912 static bool supports_AB(Transport* transport) {
913 return get_slot_count(transport) >= 2;
924 static std::string get_other_slot(Transport* transport, const std::string& current_slot) {
925 return get_other_slot(current_slot, get_slot_count(transport));
928 static std::string get_other_slot(Transport* transport, int count) {
929 return get_other_slot(get_current_slot(transport), count);
932 static std::string get_other_slot(Transport* transport) {
933 return get_other_slot(get_current_slot(transport), get_slot_count(transport));
936 static std::string verify_slot(Transport* transport, const std::string& slot_name, bool allow_all) {
944 int count = get_slot_count(transport);
953 int count = get_slot_count(transport);
957 std::string other = get_other_slot(transport, count);
974 static std::string verify_slot(Transport* transport, const std::string& slot) {
975 return verify_slot(transport, slot, true);
978 static void do_for_partition(Transport* transport, const std::string& part, const std::string& slot,
983 if (!fb_getvar(transport, "has-slot:" + part, &has_slot)) {
989 current_slot = get_current_slot(transport);
1011 static void do_for_partitions(Transport* transport, const std::string& part, const std::string& slot,
1016 if (!fb_getvar(transport, "has-slot:" + part, &has_slot)) {
1020 for (int i=0; i < get_slot_count(transport); i++) {
1021 do_for_partition(transport, part, std::string(1, (char)(i + 'a')), func, force_slot);
1024 do_for_partition(transport, part, "", func, force_slot);
1027 do_for_partition(transport, part, slot, func, force_slot);
1031 static void do_flash(Transport* transport, const char* pname, const char* fname) {
1034 if (!load_buf(transport, fname, &buf)) {
1050 static void set_active(Transport* transport, const std::string& slot_override) {
1052 if (!supports_AB(transport)) {
1053 if (supports_AB_obsolete(transport)) {
1062 std::string current_slot = get_current_slot(transport);
1069 static void do_update(Transport* transport, const char* filename, const std::string& slot_override, bool erase_first, bool skip_secondary) {
1093 secondary = get_other_slot(transport, slot_override);
1095 secondary = get_other_slot(transport);
1098 if (supports_AB(transport)) {
1123 if (!load_buf_fd(transport, fd, &buf)) {
1129 if (erase_first && needs_erase(transport, partition.c_str())) {
1138 do_for_partitions(transport, images[i].part_name, slot, update, false);
1143 set_active(transport, "a");
1145 set_active(transport, slot_override);
1163 static void do_flashall(Transport* transport, const std::string& slot_override, int erase_first, bool skip_secondary) {
1181 secondary = get_other_slot(transport, slot_override);
1183 secondary = get_other_slot(transport);
1186 if (supports_AB(transport)) {
1203 if (!load_buf(transport, fname.c_str(), &buf)) {
1210 if (erase_first && needs_erase(transport, partition.c_str())) {
1215 do_for_partitions(transport, images[i].part_name, slot, flashall, false);
1219 set_active(transport, "a");
1221 set_active(transport, slot_override);
1312 static unsigned fb_get_flash_block_size(Transport* transport, std::string name) {
1314 if (!fb_getvar(transport, name.c_str(), &sizeString)) {
1333 static void fb_perform_format(Transport* transport,
1352 if (!fb_getvar(transport, std::string("partition-type:") + partition, &partition_type)) {
1364 if (!fb_getvar(transport, std::string("partition-size:") + partition, &partition_size)) {
1398 eraseBlkSize = fb_get_flash_block_size(transport, "erase-block-size");
1399 logicalBlkSize = fb_get_flash_block_size(transport, "logical-block-size");
1407 if (!load_buf_fd(transport, fd, &buf)) {
1581 Transport* transport = open_device();
1582 if (transport == nullptr) {
1586 if (!supports_AB(transport) && supports_AB_obsolete(transport)) {
1589 if (slot_override != "") slot_override = verify_slot(transport, slot_override);
1590 if (next_active != "") next_active = verify_slot(transport, next_active, false);
1596 if (fb_getvar(transport, "current-slot", &current_slot)) {
1597 next_active = verify_slot(transport, current_slot, false);
1602 next_active = verify_slot(transport, slot_override, false);
1617 if (fb_getvar(transport, std::string("partition-type:") + argv[1], &partition_type) &&
1625 do_for_partitions(transport, argv[1], slot_override, erase, true);
1655 if (erase_first && needs_erase(transport, partition.c_str())) {
1658 fb_perform_format(transport, partition.c_str(), 0,
1661 do_for_partitions(transport, argv[1], slot_override, format, true);
1727 if (erase_first && needs_erase(transport, partition.c_str())) {
1730 do_flash(transport, partition.c_str(), fname.c_str());
1732 do_for_partitions(transport, pname, slot_override, flash, true);
1752 do_for_partitions(transport, argv[1], slot_override, flashraw, true);
1757 do_flashall(transport, slot_override, erase_first, true);
1759 do_flashall(transport, slot_override, erase_first, skip_secondary);
1768 do_update(transport, argv[1], slot_override, erase_first, skip_secondary || slot_all);
1771 do_update(transport, "update.zip", slot_override, erase_first, skip_secondary || slot_all);
1777 std::string slot = verify_slot(transport, std::string(argv[1]), false);
1782 if (!fb_getvar(transport, "slot-count", &var) &&
1783 fb_getvar(transport, "slot-suffixes", &var)) {
1821 fb_perform_format(transport, "userdata", 1, nullptr, nullptr, initial_userdata_dir);
1824 fb_perform_format(transport, "userdata", 1, nullptr, nullptr, "");
1828 if (fb_getvar(transport, "partition-type:cache", &cache_type) && !cache_type.empty()) {
1831 fb_perform_format(transport, "cache", 1, nullptr, nullptr, "");
1848 return fb_execute_queue(transport) ? EXIT_FAILURE : EXIT_SUCCESS;