Merge "Clean up the partition name mapping in fastboot."
This commit is contained in:
commit
bdbcdf3a16
1 changed files with 35 additions and 60 deletions
|
|
@ -75,7 +75,6 @@ using android::base::unique_fd;
|
||||||
char cur_product[FB_RESPONSE_SZ + 1];
|
char cur_product[FB_RESPONSE_SZ + 1];
|
||||||
|
|
||||||
static const char* serial = nullptr;
|
static const char* serial = nullptr;
|
||||||
static const char* product = nullptr;
|
|
||||||
static const char* cmdline = nullptr;
|
static const char* cmdline = nullptr;
|
||||||
static unsigned short vendor_id = 0;
|
static unsigned short vendor_id = 0;
|
||||||
static int long_listing = 0;
|
static int long_listing = 0;
|
||||||
|
|
@ -108,66 +107,46 @@ struct fastboot_buffer {
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
char img_name[17];
|
const char* nickname;
|
||||||
char sig_name[17];
|
const char* img_name;
|
||||||
char part_name[9];
|
const char* sig_name;
|
||||||
|
const char* part_name;
|
||||||
bool is_optional;
|
bool is_optional;
|
||||||
bool is_secondary;
|
bool is_secondary;
|
||||||
} images[] = {
|
} images[] = {
|
||||||
{"boot.img", "boot.sig", "boot", false, false},
|
// clang-format off
|
||||||
{"boot_other.img", "boot.sig", "boot", true, true},
|
{ "boot", "boot.img", "boot.sig", "boot", false, false },
|
||||||
{"recovery.img", "recovery.sig", "recovery", true, false},
|
{ nullptr, "boot_other.img", "boot.sig", "boot", true, true },
|
||||||
{"system.img", "system.sig", "system", false, false},
|
{ "dtbo", "dtbo.img", "dtbo.sig", "dtbo", true, false },
|
||||||
{"system_other.img", "system.sig", "system", true, true},
|
{ "recovery", "recovery.img", "recovery.sig", "recovery", true, false },
|
||||||
{"vendor.img", "vendor.sig", "vendor", true, false},
|
{ "system", "system.img", "system.sig", "system", false, false },
|
||||||
{"vendor_other.img", "vendor.sig", "vendor", true, true},
|
{ nullptr, "system_other.img", "system.sig", "system", true, true },
|
||||||
{"vbmeta.img", "vbmeta.sig", "vbmeta", true, false},
|
{ "vbmeta", "vbmeta.img", "vbmeta.sig", "vbmeta", true, false },
|
||||||
{"dtbo.img", "dtbo.sig", "dtbo", true, false},
|
{ "vendor", "vendor.img", "vendor.sig", "vendor", true, false },
|
||||||
|
{ nullptr, "vendor_other.img", "vendor.sig", "vendor", true, true },
|
||||||
|
// clang-format on
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::string find_item_given_name(const char* img_name, const char* product) {
|
static std::string find_item_given_name(const char* img_name) {
|
||||||
if(product) {
|
char* dir = getenv("ANDROID_PRODUCT_OUT");
|
||||||
std::string path = android::base::GetExecutablePath();
|
|
||||||
path.erase(path.find_last_of('/'));
|
|
||||||
return android::base::StringPrintf("%s/../../../target/product/%s/%s",
|
|
||||||
path.c_str(), product, img_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *dir = getenv("ANDROID_PRODUCT_OUT");
|
|
||||||
if (dir == nullptr || dir[0] == '\0') {
|
if (dir == nullptr || dir[0] == '\0') {
|
||||||
die("neither -p product specified nor ANDROID_PRODUCT_OUT set");
|
die("ANDROID_PRODUCT_OUT not set");
|
||||||
}
|
}
|
||||||
|
|
||||||
return android::base::StringPrintf("%s/%s", dir, img_name);
|
return android::base::StringPrintf("%s/%s", dir, img_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string find_item(const char* item, const char* product) {
|
std::string find_item(const char* item) {
|
||||||
const char *fn;
|
for (size_t i = 0; i < arraysize(images); ++i) {
|
||||||
|
if (images[i].nickname && !strcmp(images[i].nickname, item)) {
|
||||||
if (!strcmp(item,"boot")) {
|
return find_item_given_name(images[i].img_name);
|
||||||
fn = "boot.img";
|
}
|
||||||
} else if(!strcmp(item,"recovery")) {
|
|
||||||
fn = "recovery.img";
|
|
||||||
} else if(!strcmp(item,"system")) {
|
|
||||||
fn = "system.img";
|
|
||||||
} else if(!strcmp(item,"vendor")) {
|
|
||||||
fn = "vendor.img";
|
|
||||||
} else if(!strcmp(item,"vbmeta")) {
|
|
||||||
fn = "vbmeta.img";
|
|
||||||
} else if(!strcmp(item,"dtbo")) {
|
|
||||||
fn = "dtbo.img";
|
|
||||||
} else if(!strcmp(item,"userdata")) {
|
|
||||||
fn = "userdata.img";
|
|
||||||
} else if(!strcmp(item,"cache")) {
|
|
||||||
fn = "cache.img";
|
|
||||||
} else if(!strcmp(item,"info")) {
|
|
||||||
fn = "android-info.txt";
|
|
||||||
} else {
|
|
||||||
fprintf(stderr,"unknown partition '%s'\n", item);
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return find_item_given_name(fn, product);
|
if (!strcmp(item, "userdata")) return find_item_given_name("userdata.img");
|
||||||
|
if (!strcmp(item, "cache")) return find_item_given_name("cache.img");
|
||||||
|
|
||||||
|
fprintf(stderr, "unknown partition '%s'\n", item);
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t get_file_size(int fd) {
|
static int64_t get_file_size(int fd) {
|
||||||
|
|
@ -391,7 +370,6 @@ static void usage() {
|
||||||
" For ethernet, provide an address in the\n"
|
" For ethernet, provide an address in the\n"
|
||||||
" form <protocol>:<hostname>[:port] where\n"
|
" form <protocol>:<hostname>[:port] where\n"
|
||||||
" <protocol> is either tcp or udp.\n"
|
" <protocol> is either tcp or udp.\n"
|
||||||
" -p <product> Specify product name.\n"
|
|
||||||
" -c <cmdline> Override kernel commandline.\n"
|
" -c <cmdline> Override kernel commandline.\n"
|
||||||
" -i <vendor id> Specify a custom USB vendor id.\n"
|
" -i <vendor id> Specify a custom USB vendor id.\n"
|
||||||
" -b, --base <base_addr> Specify a custom kernel base\n"
|
" -b, --base <base_addr> Specify a custom kernel base\n"
|
||||||
|
|
@ -627,7 +605,7 @@ static void delete_fbemarker_tmpdir(const std::string& dir) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int unzip_to_file(ZipArchiveHandle zip, char* entry_name) {
|
static int unzip_to_file(ZipArchiveHandle zip, const char* entry_name) {
|
||||||
unique_fd fd(make_temporary_fd());
|
unique_fd fd(make_temporary_fd());
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
fprintf(stderr, "failed to create temporary file for '%s': %s\n",
|
fprintf(stderr, "failed to create temporary file for '%s': %s\n",
|
||||||
|
|
@ -1081,9 +1059,9 @@ static void do_flash(Transport* transport, const char* pname, const char* fname)
|
||||||
flash_buf(pname, &buf);
|
flash_buf(pname, &buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_update_signature(ZipArchiveHandle zip, char* fn) {
|
static void do_update_signature(ZipArchiveHandle zip, const char* filename) {
|
||||||
int64_t sz;
|
int64_t sz;
|
||||||
void* data = unzip_file(zip, fn, &sz);
|
void* data = unzip_file(zip, filename, &sz);
|
||||||
if (data == nullptr) return;
|
if (data == nullptr) return;
|
||||||
fb_queue_download("signature", data, sz);
|
fb_queue_download("signature", data, sz);
|
||||||
fb_queue_command("signature", "installing signature");
|
fb_queue_command("signature", "installing signature");
|
||||||
|
|
@ -1210,7 +1188,7 @@ static void do_flashall(Transport* transport, const std::string& slot_override,
|
||||||
|
|
||||||
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_given_name("android-info.txt");
|
||||||
if (fname.empty()) die("cannot find android-info.txt");
|
if (fname.empty()) die("cannot find android-info.txt");
|
||||||
|
|
||||||
int64_t sz;
|
int64_t sz;
|
||||||
|
|
@ -1242,7 +1220,7 @@ static void do_flashall(Transport* transport, const std::string& slot_override,
|
||||||
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);
|
||||||
fastboot_buffer buf;
|
fastboot_buffer buf;
|
||||||
if (!load_buf(transport, fname.c_str(), &buf)) {
|
if (!load_buf(transport, fname.c_str(), &buf)) {
|
||||||
if (images[i].is_optional) continue;
|
if (images[i].is_optional) continue;
|
||||||
|
|
@ -1509,7 +1487,7 @@ int main(int argc, char **argv)
|
||||||
serial = getenv("ANDROID_SERIAL");
|
serial = getenv("ANDROID_SERIAL");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
int c = getopt_long(argc, argv, "wub:k:n:r:t:s:S:lp:c:i:m:ha::", longopts, &longindex);
|
int c = getopt_long(argc, argv, "wub:k:n:r:t:s:S:lc:i:m:ha::", longopts, &longindex);
|
||||||
if (c < 0) {
|
if (c < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1549,9 +1527,6 @@ int main(int argc, char **argv)
|
||||||
page_size = (unsigned)strtoul(optarg, nullptr, 0);
|
page_size = (unsigned)strtoul(optarg, nullptr, 0);
|
||||||
if (!page_size) die("invalid page size");
|
if (!page_size) die("invalid page size");
|
||||||
break;
|
break;
|
||||||
case 'p':
|
|
||||||
product = optarg;
|
|
||||||
break;
|
|
||||||
case 'r':
|
case 'r':
|
||||||
ramdisk_offset = strtoul(optarg, 0, 16);
|
ramdisk_offset = strtoul(optarg, 0, 16);
|
||||||
break;
|
break;
|
||||||
|
|
@ -1764,7 +1739,7 @@ int main(int argc, char **argv)
|
||||||
fname = argv[2];
|
fname = argv[2];
|
||||||
skip(3);
|
skip(3);
|
||||||
} else {
|
} else {
|
||||||
fname = find_item(pname, product);
|
fname = find_item(pname);
|
||||||
skip(2);
|
skip(2);
|
||||||
}
|
}
|
||||||
if (fname.empty()) die("cannot determine image filename for '%s'", pname);
|
if (fname.empty()) die("cannot determine image filename for '%s'", pname);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue