Merge "Add skip-secondary flag" into nyc-mr1-dev

This commit is contained in:
TreeHugger Robot 2016-07-16 01:21:21 +00:00 committed by Android (Google) Code Review
commit efa8604a1d

View file

@ -327,9 +327,6 @@ static void usage() {
" been flashed to is set as active.\n" " been flashed to is set as active.\n"
" Secondary images may be flashed to\n" " Secondary images may be flashed to\n"
" an inactive slot.\n" " an inactive slot.\n"
" flash-primary Same as flashall, but do not flash\n"
" secondary images.\n"
" flash-secondary Only flashes the secondary images.\n"
" flash <partition> [ <filename> ] Write a file to a flash partition.\n" " flash <partition> [ <filename> ] Write a file to a flash partition.\n"
" flashing lock Locks the device. Prevents flashing.\n" " flashing lock Locks the device. Prevents flashing.\n"
" flashing unlock Unlocks the device. Allows flashing\n" " flashing unlock Unlocks the device. Allows flashing\n"
@ -404,6 +401,9 @@ static void usage() {
" supported, this sets the current slot\n" " supported, this sets the current slot\n"
" to be active. This will run after all\n" " to be active. This will run after all\n"
" non-reboot commands.\n" " non-reboot commands.\n"
" --skip-secondary Will not flash secondary slots when\n"
" performing a flashall or update. This\n"
" will preserve data on other slots.\n"
#if !defined(_WIN32) #if !defined(_WIN32)
" --wipe-and-use-fbe On devices which support it,\n" " --wipe-and-use-fbe On devices which support it,\n"
" erase userdata and cache, and\n" " erase userdata and cache, and\n"
@ -1064,7 +1064,7 @@ static void set_active(Transport* transport, const std::string& slot_override) {
} }
} }
static void do_update(Transport* transport, const char* filename, const std::string& slot_override, bool erase_first) { static void do_update(Transport* transport, const char* filename, const std::string& slot_override, bool erase_first, bool skip_secondary) {
queue_info_dump(); queue_info_dump();
fb_queue_query_save("product", cur_product, sizeof(cur_product)); 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
setup_requirements(reinterpret_cast<char*>(data), sz); setup_requirements(reinterpret_cast<char*>(data), sz);
std::string secondary; std::string secondary;
bool update_secondary = slot_override != "all"; if (!skip_secondary) {
if (update_secondary) {
if (slot_override != "") { if (slot_override != "") {
secondary = get_other_slot(transport, slot_override); secondary = get_other_slot(transport, slot_override);
} else { } else {
@ -1097,13 +1096,13 @@ static void do_update(Transport* transport, const char* filename, const std::str
if (supports_AB(transport)) { if (supports_AB(transport)) {
fprintf(stderr, "Warning: Could not determine slot for secondary images. Ignoring.\n"); fprintf(stderr, "Warning: Could not determine slot for secondary images. Ignoring.\n");
} }
update_secondary = false; skip_secondary = true;
} }
} }
for (size_t i = 0; i < ARRAY_SIZE(images); ++i) { for (size_t i = 0; i < ARRAY_SIZE(images); ++i) {
const char* slot = slot_override.c_str(); const char* slot = slot_override.c_str();
if (images[i].is_secondary) { if (images[i].is_secondary) {
if (update_secondary) { if (!skip_secondary) {
slot = secondary.c_str(); slot = secondary.c_str();
} else { } else {
continue; continue;
@ -1137,7 +1136,11 @@ static void do_update(Transport* transport, const char* filename, const std::str
} }
CloseArchive(zip); CloseArchive(zip);
set_active(transport, slot_override); if (slot_override == "all") {
set_active(transport, "a");
} else {
set_active(transport, slot_override);
}
} }
static void do_send_signature(const std::string& fn) { static void do_send_signature(const std::string& fn) {
@ -1153,24 +1156,23 @@ static void do_send_signature(const std::string& fn) {
fb_queue_command("signature", "installing signature"); fb_queue_command("signature", "installing signature");
} }
static void do_flashall(Transport* transport, const std::string& slot_override, int erase_first, bool flash_primary, bool flash_secondary) { static void do_flashall(Transport* transport, const std::string& slot_override, int erase_first, bool skip_secondary) {
std::string fname; std::string fname;
if (flash_primary) { queue_info_dump();
queue_info_dump();
fb_queue_query_save("product", cur_product, sizeof(cur_product)); fb_queue_query_save("product", cur_product, sizeof(cur_product));
fname = find_item("info", product); fname = find_item("info", product);
if (fname == "") die("cannot find android-info.txt"); if (fname == "") die("cannot find android-info.txt");
int64_t sz; int64_t sz;
void* data = load_file(fname.c_str(), &sz); void* data = load_file(fname.c_str(), &sz);
if (data == nullptr) die("could not load android-info.txt: %s", strerror(errno)); if (data == nullptr) die("could not load android-info.txt: %s", strerror(errno));
setup_requirements(reinterpret_cast<char*>(data), sz);
setup_requirements(reinterpret_cast<char*>(data), sz);
}
std::string secondary; std::string secondary;
if (flash_secondary) { if (!skip_secondary) {
if (slot_override != "") { if (slot_override != "") {
secondary = get_other_slot(transport, slot_override); secondary = get_other_slot(transport, slot_override);
} else { } else {
@ -1180,16 +1182,16 @@ static void do_flashall(Transport* transport, const std::string& slot_override,
if (supports_AB(transport)) { if (supports_AB(transport)) {
fprintf(stderr, "Warning: Could not determine slot for secondary images. Ignoring.\n"); fprintf(stderr, "Warning: Could not determine slot for secondary images. Ignoring.\n");
} }
flash_secondary = false; skip_secondary = true;
} }
} }
for (size_t i = 0; i < ARRAY_SIZE(images); i++) { for (size_t i = 0; i < ARRAY_SIZE(images); i++) {
const char* slot = NULL; const char* slot = NULL;
if (images[i].is_secondary) { if (images[i].is_secondary) {
if (flash_secondary) slot = secondary.c_str(); if (!skip_secondary) slot = secondary.c_str();
} else { } else {
if (flash_primary) slot = slot_override.c_str(); slot = slot_override.c_str();
} }
if (!slot) continue; if (!slot) continue;
fname = find_item_given_name(images[i].img_name, product); 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,
do_for_partitions(transport, images[i].part_name, slot, flashall, false); do_for_partitions(transport, images[i].part_name, slot, flashall, false);
} }
if (flash_primary) set_active(transport, slot_override); if (slot_override == "all") {
set_active(transport, "a");
} else {
set_active(transport, slot_override);
}
} }
#define skip(n) do { argc -= (n); argv += (n); } while (0) #define skip(n) do { argc -= (n); argv += (n); } while (0)
@ -1388,6 +1394,7 @@ int main(int argc, char **argv)
bool wants_reboot = false; bool wants_reboot = false;
bool wants_reboot_bootloader = false; bool wants_reboot_bootloader = false;
bool wants_set_active = false; bool wants_set_active = false;
bool skip_secondary = false;
bool erase_first = true; bool erase_first = true;
bool set_fbe_marker = false; bool set_fbe_marker = false;
void *data; void *data;
@ -1412,6 +1419,7 @@ int main(int argc, char **argv)
{"slot", required_argument, 0, 0}, {"slot", required_argument, 0, 0},
{"set_active", optional_argument, 0, 'a'}, {"set_active", optional_argument, 0, 'a'},
{"set-active", optional_argument, 0, 'a'}, {"set-active", optional_argument, 0, 'a'},
{"skip-secondary", no_argument, 0, 0},
#if !defined(_WIN32) #if !defined(_WIN32)
{"wipe-and-use-fbe", no_argument, 0, 0}, {"wipe-and-use-fbe", no_argument, 0, 0},
#endif #endif
@ -1496,6 +1504,8 @@ int main(int argc, char **argv)
return 0; return 0;
} else if (strcmp("slot", longopts[longindex].name) == 0) { } else if (strcmp("slot", longopts[longindex].name) == 0) {
slot_override = std::string(optarg); slot_override = std::string(optarg);
} else if (strcmp("skip-secondary", longopts[longindex].name) == 0 ) {
skip_secondary = true;
#if !defined(_WIN32) #if !defined(_WIN32)
} else if (strcmp("wipe-and-use-fbe", longopts[longindex].name) == 0) { } else if (strcmp("wipe-and-use-fbe", longopts[longindex].name) == 0) {
wants_wipe = true; wants_wipe = true;
@ -1702,26 +1712,22 @@ int main(int argc, char **argv)
} else if(!strcmp(*argv, "flashall")) { } else if(!strcmp(*argv, "flashall")) {
skip(1); skip(1);
if (slot_override == "all") { if (slot_override == "all") {
fprintf(stderr, "Warning: slot set to 'all'. Secondary slots will not be flashed."); fprintf(stderr, "Warning: slot set to 'all'. Secondary slots will not be flashed.\n");
do_flashall(transport, slot_override, erase_first, true, false); do_flashall(transport, slot_override, erase_first, true);
} else { } else {
do_flashall(transport, slot_override, erase_first, true, true); do_flashall(transport, slot_override, erase_first, skip_secondary);
} }
wants_reboot = true; wants_reboot = true;
} else if(!strcmp(*argv, "flash-primary")) {
skip(1);
do_flashall(transport, slot_override, erase_first, true, false);
wants_reboot = true;
} else if(!strcmp(*argv, "flash-secondary")) {
skip(1);
do_flashall(transport, slot_override, erase_first, false, true);
wants_reboot = true;
} else if(!strcmp(*argv, "update")) { } else if(!strcmp(*argv, "update")) {
bool slot_all = (slot_override == "all");
if (slot_all) {
fprintf(stderr, "Warning: slot set to 'all'. Secondary slots will not be flashed.\n");
}
if (argc > 1) { if (argc > 1) {
do_update(transport, argv[1], slot_override, erase_first); do_update(transport, argv[1], slot_override, erase_first, skip_secondary || slot_all);
skip(2); skip(2);
} else { } else {
do_update(transport, "update.zip", slot_override, erase_first); do_update(transport, "update.zip", slot_override, erase_first, skip_secondary || slot_all);
skip(1); skip(1);
} }
wants_reboot = 1; wants_reboot = 1;