system/corennnnn
Revision | d28edb60cd1f1af0b53b52b3377252c07a8fa797 (tree) |
---|---|
Time | 2016-06-29 21:50:46 |
Author | Ed Heyl <edheyl@goog...> |
Commiter | Android (Google) Code Review |
Merge "Revert "Add Fastboot support for flashing secondary images"" into nyc-mr1-dev
@@ -49,7 +49,6 @@ | ||
49 | 49 | |
50 | 50 | #include <android-base/parseint.h> |
51 | 51 | #include <android-base/parsenetaddress.h> |
52 | -#include <android-base/stringprintf.h> | |
53 | 52 | #include <android-base/strings.h> |
54 | 53 | #include <sparse/sparse.h> |
55 | 54 | #include <ziparchive/zip_archive.h> |
@@ -100,40 +99,21 @@ struct fastboot_buffer { | ||
100 | 99 | }; |
101 | 100 | |
102 | 101 | static struct { |
103 | - char img_name[17]; | |
104 | - char sig_name[17]; | |
102 | + char img_name[13]; | |
103 | + char sig_name[13]; | |
105 | 104 | char part_name[9]; |
106 | 105 | bool is_optional; |
107 | - bool is_secondary; | |
108 | 106 | } 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}, | |
116 | 111 | }; |
117 | 112 | |
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) { | |
119 | 114 | 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) { | |
136 | 115 | const char *fn; |
116 | + char path[PATH_MAX + 128]; | |
137 | 117 | |
138 | 118 | if(!strcmp(item,"boot")) { |
139 | 119 | fn = "boot.img"; |
@@ -151,10 +131,24 @@ std::string find_item(const char* item, const char* product) { | ||
151 | 131 | fn = "android-info.txt"; |
152 | 132 | } else { |
153 | 133 | fprintf(stderr,"unknown partition '%s'\n", item); |
154 | - return ""; | |
134 | + return 0; | |
155 | 135 | } |
156 | 136 | |
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); | |
158 | 152 | } |
159 | 153 | |
160 | 154 | static int64_t get_file_size(int fd) { |
@@ -325,11 +319,6 @@ static void usage() { | ||
325 | 319 | " if found -- recovery. If the device\n" |
326 | 320 | " supports slots, the slot that has\n" |
327 | 321 | " 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" | |
333 | 322 | " flash <partition> [ <filename> ] Write a file to a flash partition.\n" |
334 | 323 | " flashing lock Locks the device. Prevents flashing.\n" |
335 | 324 | " flashing unlock Unlocks the device. Allows flashing\n" |
@@ -878,12 +867,8 @@ static std::vector<std::string> get_suffixes(Transport* transport) { | ||
878 | 867 | return suffixes; |
879 | 868 | } |
880 | 869 | |
881 | -static bool supports_AB(Transport* transport) { | |
882 | - return !get_suffixes(transport).empty(); | |
883 | -} | |
884 | - | |
885 | 870 | // 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) { | |
887 | 872 | std::vector<std::string> suffixes = get_suffixes(transport); |
888 | 873 | |
889 | 874 | if (!suffixes.empty()) { |
@@ -896,12 +881,6 @@ static std::string get_other_slot(Transport* transport, const std::string& curre | ||
896 | 881 | return ""; |
897 | 882 | } |
898 | 883 | |
899 | -static std::string get_other_slot(Transport* transport) { | |
900 | - std::string current_slot; | |
901 | - fb_getvar(transport, "current-slot", ¤t_slot); | |
902 | - return get_other_slot(transport, current_slot); | |
903 | -} | |
904 | - | |
905 | 884 | static std::string verify_slot(Transport* transport, const char *slot, bool allow_all) { |
906 | 885 | if (strcmp(slot, "all") == 0) { |
907 | 886 | if (allow_all) { |
@@ -1024,9 +1003,9 @@ static void do_update_signature(ZipArchiveHandle zip, char* fn) { | ||
1024 | 1003 | |
1025 | 1004 | // Sets slot_override as the active slot. If slot_override is blank, |
1026 | 1005 | // 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); | |
1030 | 1009 | } else { |
1031 | 1010 | std::string current_slot; |
1032 | 1011 | if (fb_getvar(transport, "current-slot", ¤t_slot)) { |
@@ -1036,7 +1015,7 @@ static void set_active(Transport* transport, const std::string& slot_override) { | ||
1036 | 1015 | } |
1037 | 1016 | } |
1038 | 1017 | |
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) { | |
1040 | 1019 | queue_info_dump(); |
1041 | 1020 | |
1042 | 1021 | 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 | ||
1057 | 1036 | |
1058 | 1037 | setup_requirements(reinterpret_cast<char*>(data), sz); |
1059 | 1038 | |
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 | - } | |
1075 | 1039 | 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 | - | |
1085 | 1040 | int fd = unzip_to_file(zip, images[i].img_name); |
1086 | 1041 | if (fd == -1) { |
1087 | 1042 | if (images[i].is_optional) { |
@@ -1105,69 +1060,49 @@ static void do_update(Transport* transport, const char* filename, const std::str | ||
1105 | 1060 | * program exits. |
1106 | 1061 | */ |
1107 | 1062 | }; |
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); | |
1109 | 1064 | } |
1110 | 1065 | |
1111 | 1066 | CloseArchive(zip); |
1112 | 1067 | set_active(transport, slot_override); |
1113 | 1068 | } |
1114 | 1069 | |
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; | |
1118 | 1073 | |
1119 | - std::string fs_sig = fn.substr(0, extension_loc) + ".sig"; | |
1074 | + if (strcmp(xtn, ".img")) return; | |
1075 | + | |
1076 | + strcpy(xtn, ".sig"); | |
1120 | 1077 | |
1121 | 1078 | int64_t sz; |
1122 | - void* data = load_file(fs_sig.c_str(), &sz); | |
1079 | + void* data = load_file(fn, &sz); | |
1080 | + strcpy(xtn, ".img"); | |
1123 | 1081 | if (data == nullptr) return; |
1124 | 1082 | fb_queue_download("signature", data, sz); |
1125 | 1083 | fb_queue_command("signature", "installing signature"); |
1126 | 1084 | } |
1127 | 1085 | |
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(); | |
1132 | 1088 | |
1133 | - fb_queue_query_save("product", cur_product, sizeof(cur_product)); | |
1089 | + fb_queue_query_save("product", cur_product, sizeof(cur_product)); | |
1134 | 1090 | |
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"); | |
1137 | 1093 | |
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)); | |
1141 | 1097 | |
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); | |
1158 | 1099 | |
1159 | 1100 | 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); | |
1168 | 1102 | 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; | |
1171 | 1106 | die("could not load %s\n", images[i].img_name); |
1172 | 1107 | } |
1173 | 1108 |
@@ -1178,10 +1113,10 @@ static void do_flashall(Transport* transport, const std::string& slot_override, | ||
1178 | 1113 | } |
1179 | 1114 | flash_buf(partition.c_str(), &buf); |
1180 | 1115 | }; |
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); | |
1182 | 1117 | } |
1183 | 1118 | |
1184 | - if (flash_primary) set_active(transport, slot_override); | |
1119 | + set_active(transport, slot_override); | |
1185 | 1120 | } |
1186 | 1121 | |
1187 | 1122 | #define skip(n) do { argc -= (n); argv += (n); } while (0) |
@@ -1508,8 +1443,10 @@ int main(int argc, char **argv) | ||
1508 | 1443 | return 1; |
1509 | 1444 | } |
1510 | 1445 | |
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); | |
1513 | 1450 | |
1514 | 1451 | if (wants_set_active) { |
1515 | 1452 | if (next_active == "") { |
@@ -1630,7 +1567,7 @@ int main(int argc, char **argv) | ||
1630 | 1567 | fb_queue_command("boot", "booting"); |
1631 | 1568 | } else if(!strcmp(*argv, "flash")) { |
1632 | 1569 | char *pname = argv[1]; |
1633 | - std::string fname; | |
1570 | + char *fname = 0; | |
1634 | 1571 | require(2); |
1635 | 1572 | if (argc > 2) { |
1636 | 1573 | fname = argv[2]; |
@@ -1639,13 +1576,13 @@ int main(int argc, char **argv) | ||
1639 | 1576 | fname = find_item(pname, product); |
1640 | 1577 | skip(2); |
1641 | 1578 | } |
1642 | - if (fname == "") die("cannot determine image filename for '%s'", pname); | |
1579 | + if (fname == 0) die("cannot determine image filename for '%s'", pname); | |
1643 | 1580 | |
1644 | 1581 | auto flash = [&](const std::string &partition) { |
1645 | 1582 | if (erase_first && needs_erase(transport, partition.c_str())) { |
1646 | 1583 | fb_queue_erase(partition.c_str()); |
1647 | 1584 | } |
1648 | - do_flash(transport, partition.c_str(), fname.c_str()); | |
1585 | + do_flash(transport, partition.c_str(), fname); | |
1649 | 1586 | }; |
1650 | 1587 | do_for_partitions(transport, pname, slot_override.c_str(), flash, true); |
1651 | 1588 | } else if(!strcmp(*argv, "flash:raw")) { |
@@ -1670,27 +1607,14 @@ int main(int argc, char **argv) | ||
1670 | 1607 | do_for_partitions(transport, argv[1], slot_override.c_str(), flashraw, true); |
1671 | 1608 | } else if(!strcmp(*argv, "flashall")) { |
1672 | 1609 | 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); | |
1687 | 1611 | wants_reboot = true; |
1688 | 1612 | } else if(!strcmp(*argv, "update")) { |
1689 | 1613 | 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); | |
1691 | 1615 | skip(2); |
1692 | 1616 | } else { |
1693 | - do_update(transport, "update.zip", slot_override, erase_first); | |
1617 | + do_update(transport, "update.zip", slot_override.c_str(), erase_first); | |
1694 | 1618 | skip(1); |
1695 | 1619 | } |
1696 | 1620 | wants_reboot = 1; |