system/corennnnn
Revision | efa8604a1d1b3acd156d6aefdf7840d9e6486dd0 (tree) |
---|---|
Time | 2016-07-16 10:21:21 |
Author | TreeHugger Robot <treehugger-gerrit@goog...> |
Commiter | Android (Google) Code Review |
Merge "Add skip-secondary flag" into nyc-mr1-dev
@@ -327,9 +327,6 @@ static void usage() { | ||
327 | 327 | " been flashed to is set as active.\n" |
328 | 328 | " Secondary images may be flashed to\n" |
329 | 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" | |
333 | 330 | " flash <partition> [ <filename> ] Write a file to a flash partition.\n" |
334 | 331 | " flashing lock Locks the device. Prevents flashing.\n" |
335 | 332 | " flashing unlock Unlocks the device. Allows flashing\n" |
@@ -404,6 +401,9 @@ static void usage() { | ||
404 | 401 | " supported, this sets the current slot\n" |
405 | 402 | " to be active. This will run after all\n" |
406 | 403 | " non-reboot commands.\n" |
404 | + " --skip-secondary Will not flash secondary slots when\n" | |
405 | + " performing a flashall or update. This\n" | |
406 | + " will preserve data on other slots.\n" | |
407 | 407 | #if !defined(_WIN32) |
408 | 408 | " --wipe-and-use-fbe On devices which support it,\n" |
409 | 409 | " erase userdata and cache, and\n" |
@@ -1064,7 +1064,7 @@ static void set_active(Transport* transport, const std::string& slot_override) { | ||
1064 | 1064 | } |
1065 | 1065 | } |
1066 | 1066 | |
1067 | -static void do_update(Transport* transport, const char* filename, const std::string& slot_override, bool erase_first) { | |
1067 | +static void do_update(Transport* transport, const char* filename, const std::string& slot_override, bool erase_first, bool skip_secondary) { | |
1068 | 1068 | queue_info_dump(); |
1069 | 1069 | |
1070 | 1070 | fb_queue_query_save("product", cur_product, sizeof(cur_product)); |
@@ -1086,8 +1086,7 @@ static void do_update(Transport* transport, const char* filename, const std::str | ||
1086 | 1086 | setup_requirements(reinterpret_cast<char*>(data), sz); |
1087 | 1087 | |
1088 | 1088 | std::string secondary; |
1089 | - bool update_secondary = slot_override != "all"; | |
1090 | - if (update_secondary) { | |
1089 | + if (!skip_secondary) { | |
1091 | 1090 | if (slot_override != "") { |
1092 | 1091 | secondary = get_other_slot(transport, slot_override); |
1093 | 1092 | } else { |
@@ -1097,13 +1096,13 @@ static void do_update(Transport* transport, const char* filename, const std::str | ||
1097 | 1096 | if (supports_AB(transport)) { |
1098 | 1097 | fprintf(stderr, "Warning: Could not determine slot for secondary images. Ignoring.\n"); |
1099 | 1098 | } |
1100 | - update_secondary = false; | |
1099 | + skip_secondary = true; | |
1101 | 1100 | } |
1102 | 1101 | } |
1103 | 1102 | for (size_t i = 0; i < ARRAY_SIZE(images); ++i) { |
1104 | 1103 | const char* slot = slot_override.c_str(); |
1105 | 1104 | if (images[i].is_secondary) { |
1106 | - if (update_secondary) { | |
1105 | + if (!skip_secondary) { | |
1107 | 1106 | slot = secondary.c_str(); |
1108 | 1107 | } else { |
1109 | 1108 | continue; |
@@ -1137,7 +1136,11 @@ static void do_update(Transport* transport, const char* filename, const std::str | ||
1137 | 1136 | } |
1138 | 1137 | |
1139 | 1138 | CloseArchive(zip); |
1140 | - set_active(transport, slot_override); | |
1139 | + if (slot_override == "all") { | |
1140 | + set_active(transport, "a"); | |
1141 | + } else { | |
1142 | + set_active(transport, slot_override); | |
1143 | + } | |
1141 | 1144 | } |
1142 | 1145 | |
1143 | 1146 | static void do_send_signature(const std::string& fn) { |
@@ -1153,24 +1156,23 @@ static void do_send_signature(const std::string& fn) { | ||
1153 | 1156 | fb_queue_command("signature", "installing signature"); |
1154 | 1157 | } |
1155 | 1158 | |
1156 | -static void do_flashall(Transport* transport, const std::string& slot_override, int erase_first, bool flash_primary, bool flash_secondary) { | |
1159 | +static void do_flashall(Transport* transport, const std::string& slot_override, int erase_first, bool skip_secondary) { | |
1157 | 1160 | std::string fname; |
1158 | - if (flash_primary) { | |
1159 | - queue_info_dump(); | |
1161 | + queue_info_dump(); | |
1162 | + | |
1163 | + fb_queue_query_save("product", cur_product, sizeof(cur_product)); | |
1160 | 1164 | |
1161 | - fb_queue_query_save("product", cur_product, sizeof(cur_product)); | |
1165 | + fname = find_item("info", product); | |
1166 | + if (fname == "") die("cannot find android-info.txt"); | |
1162 | 1167 | |
1163 | - fname = find_item("info", product); | |
1164 | - if (fname == "") die("cannot find android-info.txt"); | |
1168 | + int64_t sz; | |
1169 | + void* data = load_file(fname.c_str(), &sz); | |
1170 | + if (data == nullptr) die("could not load android-info.txt: %s", strerror(errno)); | |
1165 | 1171 | |
1166 | - int64_t sz; | |
1167 | - void* data = load_file(fname.c_str(), &sz); | |
1168 | - if (data == nullptr) die("could not load android-info.txt: %s", strerror(errno)); | |
1172 | + setup_requirements(reinterpret_cast<char*>(data), sz); | |
1169 | 1173 | |
1170 | - setup_requirements(reinterpret_cast<char*>(data), sz); | |
1171 | - } | |
1172 | 1174 | std::string secondary; |
1173 | - if (flash_secondary) { | |
1175 | + if (!skip_secondary) { | |
1174 | 1176 | if (slot_override != "") { |
1175 | 1177 | secondary = get_other_slot(transport, slot_override); |
1176 | 1178 | } else { |
@@ -1180,16 +1182,16 @@ static void do_flashall(Transport* transport, const std::string& slot_override, | ||
1180 | 1182 | if (supports_AB(transport)) { |
1181 | 1183 | fprintf(stderr, "Warning: Could not determine slot for secondary images. Ignoring.\n"); |
1182 | 1184 | } |
1183 | - flash_secondary = false; | |
1185 | + skip_secondary = true; | |
1184 | 1186 | } |
1185 | 1187 | } |
1186 | 1188 | |
1187 | 1189 | for (size_t i = 0; i < ARRAY_SIZE(images); i++) { |
1188 | 1190 | const char* slot = NULL; |
1189 | 1191 | if (images[i].is_secondary) { |
1190 | - if (flash_secondary) slot = secondary.c_str(); | |
1192 | + if (!skip_secondary) slot = secondary.c_str(); | |
1191 | 1193 | } else { |
1192 | - if (flash_primary) slot = slot_override.c_str(); | |
1194 | + slot = slot_override.c_str(); | |
1193 | 1195 | } |
1194 | 1196 | if (!slot) continue; |
1195 | 1197 | fname = find_item_given_name(images[i].img_name, product); |
@@ -1209,7 +1211,11 @@ static void do_flashall(Transport* transport, const std::string& slot_override, | ||
1209 | 1211 | do_for_partitions(transport, images[i].part_name, slot, flashall, false); |
1210 | 1212 | } |
1211 | 1213 | |
1212 | - if (flash_primary) set_active(transport, slot_override); | |
1214 | + if (slot_override == "all") { | |
1215 | + set_active(transport, "a"); | |
1216 | + } else { | |
1217 | + set_active(transport, slot_override); | |
1218 | + } | |
1213 | 1219 | } |
1214 | 1220 | |
1215 | 1221 | #define skip(n) do { argc -= (n); argv += (n); } while (0) |
@@ -1388,6 +1394,7 @@ int main(int argc, char **argv) | ||
1388 | 1394 | bool wants_reboot = false; |
1389 | 1395 | bool wants_reboot_bootloader = false; |
1390 | 1396 | bool wants_set_active = false; |
1397 | + bool skip_secondary = false; | |
1391 | 1398 | bool erase_first = true; |
1392 | 1399 | bool set_fbe_marker = false; |
1393 | 1400 | void *data; |
@@ -1412,6 +1419,7 @@ int main(int argc, char **argv) | ||
1412 | 1419 | {"slot", required_argument, 0, 0}, |
1413 | 1420 | {"set_active", optional_argument, 0, 'a'}, |
1414 | 1421 | {"set-active", optional_argument, 0, 'a'}, |
1422 | + {"skip-secondary", no_argument, 0, 0}, | |
1415 | 1423 | #if !defined(_WIN32) |
1416 | 1424 | {"wipe-and-use-fbe", no_argument, 0, 0}, |
1417 | 1425 | #endif |
@@ -1496,6 +1504,8 @@ int main(int argc, char **argv) | ||
1496 | 1504 | return 0; |
1497 | 1505 | } else if (strcmp("slot", longopts[longindex].name) == 0) { |
1498 | 1506 | slot_override = std::string(optarg); |
1507 | + } else if (strcmp("skip-secondary", longopts[longindex].name) == 0 ) { | |
1508 | + skip_secondary = true; | |
1499 | 1509 | #if !defined(_WIN32) |
1500 | 1510 | } else if (strcmp("wipe-and-use-fbe", longopts[longindex].name) == 0) { |
1501 | 1511 | wants_wipe = true; |
@@ -1702,26 +1712,22 @@ int main(int argc, char **argv) | ||
1702 | 1712 | } else if(!strcmp(*argv, "flashall")) { |
1703 | 1713 | skip(1); |
1704 | 1714 | if (slot_override == "all") { |
1705 | - fprintf(stderr, "Warning: slot set to 'all'. Secondary slots will not be flashed."); | |
1706 | - do_flashall(transport, slot_override, erase_first, true, false); | |
1715 | + fprintf(stderr, "Warning: slot set to 'all'. Secondary slots will not be flashed.\n"); | |
1716 | + do_flashall(transport, slot_override, erase_first, true); | |
1707 | 1717 | } else { |
1708 | - do_flashall(transport, slot_override, erase_first, true, true); | |
1718 | + do_flashall(transport, slot_override, erase_first, skip_secondary); | |
1709 | 1719 | } |
1710 | 1720 | wants_reboot = true; |
1711 | - } else if(!strcmp(*argv, "flash-primary")) { | |
1712 | - skip(1); | |
1713 | - do_flashall(transport, slot_override, erase_first, true, false); | |
1714 | - wants_reboot = true; | |
1715 | - } else if(!strcmp(*argv, "flash-secondary")) { | |
1716 | - skip(1); | |
1717 | - do_flashall(transport, slot_override, erase_first, false, true); | |
1718 | - wants_reboot = true; | |
1719 | 1721 | } else if(!strcmp(*argv, "update")) { |
1722 | + bool slot_all = (slot_override == "all"); | |
1723 | + if (slot_all) { | |
1724 | + fprintf(stderr, "Warning: slot set to 'all'. Secondary slots will not be flashed.\n"); | |
1725 | + } | |
1720 | 1726 | if (argc > 1) { |
1721 | - do_update(transport, argv[1], slot_override, erase_first); | |
1727 | + do_update(transport, argv[1], slot_override, erase_first, skip_secondary || slot_all); | |
1722 | 1728 | skip(2); |
1723 | 1729 | } else { |
1724 | - do_update(transport, "update.zip", slot_override, erase_first); | |
1730 | + do_update(transport, "update.zip", slot_override, erase_first, skip_secondary || slot_all); | |
1725 | 1731 | skip(1); |
1726 | 1732 | } |
1727 | 1733 | wants_reboot = 1; |