• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

Revisiond28edb60cd1f1af0b53b52b3377252c07a8fa797 (tree)
Time2016-06-29 21:50:46
AuthorEd Heyl <edheyl@goog...>
CommiterAndroid (Google) Code Review

Log Message

Merge "Revert "Add Fastboot support for flashing secondary images"" into nyc-mr1-dev

Change Summary

Incremental Difference

--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -49,7 +49,6 @@
4949
5050 #include <android-base/parseint.h>
5151 #include <android-base/parsenetaddress.h>
52-#include <android-base/stringprintf.h>
5352 #include <android-base/strings.h>
5453 #include <sparse/sparse.h>
5554 #include <ziparchive/zip_archive.h>
@@ -100,40 +99,21 @@ struct fastboot_buffer {
10099 };
101100
102101 static struct {
103- char img_name[17];
104- char sig_name[17];
102+ char img_name[13];
103+ char sig_name[13];
105104 char part_name[9];
106105 bool is_optional;
107- bool is_secondary;
108106 } images[] = {
109- {"boot.img", "boot.sig", "boot", false, false},
110- {"boot_other.img", "boot.sig", "boot", true, true},
111- {"recovery.img", "recovery.sig", "recovery", true, false},
112- {"system.img", "system.sig", "system", false, false},
113- {"system_other.img", "system.sig", "system", true, true},
114- {"vendor.img", "vendor.sig", "vendor", true, false},
115- {"vendor_other.img", "vendor.sig", "vendor", true, true},
107+ {"boot.img", "boot.sig", "boot", false},
108+ {"recovery.img", "recovery.sig", "recovery", true},
109+ {"system.img", "system.sig", "system", false},
110+ {"vendor.img", "vendor.sig", "vendor", true},
116111 };
117112
118-static std::string find_item_given_name(const char* img_name, const char* product) {
113+static char* find_item(const char* item, const char* product) {
119114 char *dir;
120- char path[PATH_MAX + 128];
121-
122- if(product) {
123- get_my_path(path);
124- return android::base::StringPrintf("../../../target/product/%s/%s", product, img_name);
125- }
126-
127- dir = getenv("ANDROID_PRODUCT_OUT");
128- if((dir == 0) || (dir[0] == 0)) {
129- die("neither -p product specified nor ANDROID_PRODUCT_OUT set");
130- }
131-
132- return android::base::StringPrintf("%s/%s", dir, img_name);
133-}
134-
135-std::string find_item(const char* item, const char* product) {
136115 const char *fn;
116+ char path[PATH_MAX + 128];
137117
138118 if(!strcmp(item,"boot")) {
139119 fn = "boot.img";
@@ -151,10 +131,24 @@ std::string find_item(const char* item, const char* product) {
151131 fn = "android-info.txt";
152132 } else {
153133 fprintf(stderr,"unknown partition '%s'\n", item);
154- return "";
134+ return 0;
155135 }
156136
157- return find_item_given_name(fn, product);
137+ if(product) {
138+ get_my_path(path);
139+ sprintf(path + strlen(path),
140+ "../../../target/product/%s/%s", product, fn);
141+ return strdup(path);
142+ }
143+
144+ dir = getenv("ANDROID_PRODUCT_OUT");
145+ if((dir == 0) || (dir[0] == 0)) {
146+ die("neither -p product specified nor ANDROID_PRODUCT_OUT set");
147+ return 0;
148+ }
149+
150+ sprintf(path, "%s/%s", dir, fn);
151+ return strdup(path);
158152 }
159153
160154 static int64_t get_file_size(int fd) {
@@ -325,11 +319,6 @@ static void usage() {
325319 " if found -- recovery. If the device\n"
326320 " supports slots, the slot that has\n"
327321 " been flashed to is set as active.\n"
328- " Secondary images may be flashed to\n"
329- " an inactive slot.\n"
330- " flash-primary Same as flashall, but do not flash\n"
331- " secondary images.\n"
332- " flash-secondary Only flashes the secondary images.\n"
333322 " flash <partition> [ <filename> ] Write a file to a flash partition.\n"
334323 " flashing lock Locks the device. Prevents flashing.\n"
335324 " flashing unlock Unlocks the device. Allows flashing\n"
@@ -878,12 +867,8 @@ static std::vector<std::string> get_suffixes(Transport* transport) {
878867 return suffixes;
879868 }
880869
881-static bool supports_AB(Transport* transport) {
882- return !get_suffixes(transport).empty();
883-}
884-
885870 // Given a current slot, this returns what the 'other' slot is.
886-static std::string get_other_slot(Transport* transport, const std::string& current_slot) {
871+static std::string get_other_slot(Transport* transport, std::string& current_slot) {
887872 std::vector<std::string> suffixes = get_suffixes(transport);
888873
889874 if (!suffixes.empty()) {
@@ -896,12 +881,6 @@ static std::string get_other_slot(Transport* transport, const std::string& curre
896881 return "";
897882 }
898883
899-static std::string get_other_slot(Transport* transport) {
900- std::string current_slot;
901- fb_getvar(transport, "current-slot", &current_slot);
902- return get_other_slot(transport, current_slot);
903-}
904-
905884 static std::string verify_slot(Transport* transport, const char *slot, bool allow_all) {
906885 if (strcmp(slot, "all") == 0) {
907886 if (allow_all) {
@@ -1024,9 +1003,9 @@ static void do_update_signature(ZipArchiveHandle zip, char* fn) {
10241003
10251004 // Sets slot_override as the active slot. If slot_override is blank,
10261005 // set current slot as active instead. This clears slot-unbootable.
1027-static void set_active(Transport* transport, const std::string& slot_override) {
1028- if (slot_override != "") {
1029- fb_set_active(slot_override.c_str());
1006+static void set_active(Transport* transport, const char* slot_override) {
1007+ if (slot_override && slot_override[0]) {
1008+ fb_set_active(slot_override);
10301009 } else {
10311010 std::string current_slot;
10321011 if (fb_getvar(transport, "current-slot", &current_slot)) {
@@ -1036,7 +1015,7 @@ static void set_active(Transport* transport, const std::string& slot_override) {
10361015 }
10371016 }
10381017
1039-static void do_update(Transport* transport, const char* filename, const std::string& slot_override, bool erase_first) {
1018+static void do_update(Transport* transport, const char* filename, const char* slot_override, bool erase_first) {
10401019 queue_info_dump();
10411020
10421021 fb_queue_query_save("product", cur_product, sizeof(cur_product));
@@ -1057,31 +1036,7 @@ static void do_update(Transport* transport, const char* filename, const std::str
10571036
10581037 setup_requirements(reinterpret_cast<char*>(data), sz);
10591038
1060- std::string secondary;
1061- bool update_secondary = slot_override != "all";
1062- if (update_secondary) {
1063- if (slot_override != "") {
1064- secondary = get_other_slot(transport, slot_override);
1065- } else {
1066- secondary = get_other_slot(transport);
1067- }
1068- if (secondary == "") {
1069- if (supports_AB(transport)) {
1070- fprintf(stderr, "Warning: Could not determine slot for secondary images. Ignoring.\n");
1071- }
1072- update_secondary = false;
1073- }
1074- }
10751039 for (size_t i = 0; i < ARRAY_SIZE(images); ++i) {
1076- const char* slot = slot_override.c_str();
1077- if (images[i].is_secondary) {
1078- if (update_secondary) {
1079- slot = secondary.c_str();
1080- } else {
1081- continue;
1082- }
1083- }
1084-
10851040 int fd = unzip_to_file(zip, images[i].img_name);
10861041 if (fd == -1) {
10871042 if (images[i].is_optional) {
@@ -1105,69 +1060,49 @@ static void do_update(Transport* transport, const char* filename, const std::str
11051060 * program exits.
11061061 */
11071062 };
1108- do_for_partitions(transport, images[i].part_name, slot, update, false);
1063+ do_for_partitions(transport, images[i].part_name, slot_override, update, false);
11091064 }
11101065
11111066 CloseArchive(zip);
11121067 set_active(transport, slot_override);
11131068 }
11141069
1115-static void do_send_signature(const std::string& fn) {
1116- std::size_t extension_loc = fn.find(".img");
1117- if (extension_loc == std::string::npos) return;
1070+static void do_send_signature(char* fn) {
1071+ char* xtn = strrchr(fn, '.');
1072+ if (!xtn) return;
11181073
1119- std::string fs_sig = fn.substr(0, extension_loc) + ".sig";
1074+ if (strcmp(xtn, ".img")) return;
1075+
1076+ strcpy(xtn, ".sig");
11201077
11211078 int64_t sz;
1122- void* data = load_file(fs_sig.c_str(), &sz);
1079+ void* data = load_file(fn, &sz);
1080+ strcpy(xtn, ".img");
11231081 if (data == nullptr) return;
11241082 fb_queue_download("signature", data, sz);
11251083 fb_queue_command("signature", "installing signature");
11261084 }
11271085
1128-static void do_flashall(Transport* transport, const std::string& slot_override, int erase_first, bool flash_primary, bool flash_secondary) {
1129- std::string fname;
1130- if (flash_primary) {
1131- queue_info_dump();
1086+static void do_flashall(Transport* transport, const char* slot_override, int erase_first) {
1087+ queue_info_dump();
11321088
1133- fb_queue_query_save("product", cur_product, sizeof(cur_product));
1089+ fb_queue_query_save("product", cur_product, sizeof(cur_product));
11341090
1135- fname = find_item("info", product);
1136- if (fname == "") die("cannot find android-info.txt");
1091+ char* fname = find_item("info", product);
1092+ if (fname == nullptr) die("cannot find android-info.txt");
11371093
1138- int64_t sz;
1139- void* data = load_file(fname.c_str(), &sz);
1140- if (data == nullptr) die("could not load android-info.txt: %s", strerror(errno));
1094+ int64_t sz;
1095+ void* data = load_file(fname, &sz);
1096+ if (data == nullptr) die("could not load android-info.txt: %s", strerror(errno));
11411097
1142- setup_requirements(reinterpret_cast<char*>(data), sz);
1143- }
1144- std::string secondary;
1145- if (flash_secondary) {
1146- if (slot_override != "") {
1147- secondary = get_other_slot(transport, slot_override);
1148- } else {
1149- secondary = get_other_slot(transport);
1150- }
1151- if (secondary == "") {
1152- if (supports_AB(transport)) {
1153- fprintf(stderr, "Warning: Could not determine slot for secondary images. Ignoring.\n");
1154- }
1155- flash_secondary = false;
1156- }
1157- }
1098+ setup_requirements(reinterpret_cast<char*>(data), sz);
11581099
11591100 for (size_t i = 0; i < ARRAY_SIZE(images); i++) {
1160- const char* slot = NULL;
1161- if (images[i].is_secondary) {
1162- if (flash_secondary) slot = secondary.c_str();
1163- } else {
1164- if (flash_primary) slot = slot_override.c_str();
1165- }
1166- if (!slot) continue;
1167- fname = find_item_given_name(images[i].img_name, product);
1101+ fname = find_item(images[i].part_name, product);
11681102 fastboot_buffer buf;
1169- if (load_buf(transport, fname.c_str(), &buf)) {
1170- if (images[i].is_optional) continue;
1103+ if (load_buf(transport, fname, &buf)) {
1104+ if (images[i].is_optional)
1105+ continue;
11711106 die("could not load %s\n", images[i].img_name);
11721107 }
11731108
@@ -1178,10 +1113,10 @@ static void do_flashall(Transport* transport, const std::string& slot_override,
11781113 }
11791114 flash_buf(partition.c_str(), &buf);
11801115 };
1181- do_for_partitions(transport, images[i].part_name, slot, flashall, false);
1116+ do_for_partitions(transport, images[i].part_name, slot_override, flashall, false);
11821117 }
11831118
1184- if (flash_primary) set_active(transport, slot_override);
1119+ set_active(transport, slot_override);
11851120 }
11861121
11871122 #define skip(n) do { argc -= (n); argv += (n); } while (0)
@@ -1508,8 +1443,10 @@ int main(int argc, char **argv)
15081443 return 1;
15091444 }
15101445
1511- if (slot_override != "") slot_override = verify_slot(transport, slot_override.c_str());
1512- if (next_active != "") next_active = verify_slot(transport, next_active.c_str(), false);
1446+ if (slot_override != "")
1447+ slot_override = verify_slot(transport, slot_override.c_str());
1448+ if (next_active != "")
1449+ next_active = verify_slot(transport, next_active.c_str(), false);
15131450
15141451 if (wants_set_active) {
15151452 if (next_active == "") {
@@ -1630,7 +1567,7 @@ int main(int argc, char **argv)
16301567 fb_queue_command("boot", "booting");
16311568 } else if(!strcmp(*argv, "flash")) {
16321569 char *pname = argv[1];
1633- std::string fname;
1570+ char *fname = 0;
16341571 require(2);
16351572 if (argc > 2) {
16361573 fname = argv[2];
@@ -1639,13 +1576,13 @@ int main(int argc, char **argv)
16391576 fname = find_item(pname, product);
16401577 skip(2);
16411578 }
1642- if (fname == "") die("cannot determine image filename for '%s'", pname);
1579+ if (fname == 0) die("cannot determine image filename for '%s'", pname);
16431580
16441581 auto flash = [&](const std::string &partition) {
16451582 if (erase_first && needs_erase(transport, partition.c_str())) {
16461583 fb_queue_erase(partition.c_str());
16471584 }
1648- do_flash(transport, partition.c_str(), fname.c_str());
1585+ do_flash(transport, partition.c_str(), fname);
16491586 };
16501587 do_for_partitions(transport, pname, slot_override.c_str(), flash, true);
16511588 } else if(!strcmp(*argv, "flash:raw")) {
@@ -1670,27 +1607,14 @@ int main(int argc, char **argv)
16701607 do_for_partitions(transport, argv[1], slot_override.c_str(), flashraw, true);
16711608 } else if(!strcmp(*argv, "flashall")) {
16721609 skip(1);
1673- if (slot_override == "all") {
1674- fprintf(stderr, "Warning: slot set to 'all'. Secondary slots will not be flashed.");
1675- do_flashall(transport, slot_override, erase_first, true, false);
1676- } else {
1677- do_flashall(transport, slot_override, erase_first, true, true);
1678- }
1679- wants_reboot = true;
1680- } else if(!strcmp(*argv, "flash-primary")) {
1681- skip(1);
1682- do_flashall(transport, slot_override, erase_first, true, false);
1683- wants_reboot = true;
1684- } else if(!strcmp(*argv, "flash-secondary")) {
1685- skip(1);
1686- do_flashall(transport, slot_override, erase_first, false, true);
1610+ do_flashall(transport, slot_override.c_str(), erase_first);
16871611 wants_reboot = true;
16881612 } else if(!strcmp(*argv, "update")) {
16891613 if (argc > 1) {
1690- do_update(transport, argv[1], slot_override, erase_first);
1614+ do_update(transport, argv[1], slot_override.c_str(), erase_first);
16911615 skip(2);
16921616 } else {
1693- do_update(transport, "update.zip", slot_override, erase_first);
1617+ do_update(transport, "update.zip", slot_override.c_str(), erase_first);
16941618 skip(1);
16951619 }
16961620 wants_reboot = 1;