diff options
author | Elliott Hughes <enh@google.com> | 2018-04-10 14:22:13 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2018-04-10 14:24:02 -0700 |
commit | 6ebec932d65f0f716cad784e825051f18acb5165 (patch) | |
tree | 3b50ed1bcea6e3bcf67af1966ef68bc8e291020c /fastboot/fastboot.cpp | |
parent | 20d21598033bb682a54ec1eca2568e030ad92e46 (diff) |
Add fastboot_test.cpp and test --os-version/--os-patch-level parsing.
Also switch all remaining headers over to #pragma once, and actually
use FB_COMMAND_SZ.
Bug: http://b/77340848
Test: ran tests
Change-Id: I27107d054c206e66c39208099e36a55df604e08f
Diffstat (limited to 'fastboot/fastboot.cpp')
-rw-r--r-- | fastboot/fastboot.cpp | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp index 42f4fbb4b..5666fa1e9 100644 --- a/fastboot/fastboot.cpp +++ b/fastboot/fastboot.cpp @@ -1475,24 +1475,9 @@ int FastBoot::Main(int argc, char* argv[]) { } else if (name == "kernel-offset") { g_boot_img_hdr.kernel_addr = strtoul(optarg, 0, 16); } else if (name == "os-patch-level") { - unsigned year, month, day; - if (sscanf(optarg, "%u-%u-%u", &year, &month, &day) != 3) { - syntax_error("OS patch level should be YYYY-MM-DD: %s", optarg); - } - if (year < 2000 || year >= 2128) syntax_error("year out of range: %d", year); - if (month < 1 || month > 12) syntax_error("month out of range: %d", month); - g_boot_img_hdr.SetOsPatchLevel(year, month); + ParseOsPatchLevel(&g_boot_img_hdr, optarg); } else if (name == "os-version") { - unsigned major = 0, minor = 0, patch = 0; - std::vector<std::string> versions = android::base::Split(optarg, "."); - if (versions.size() < 1 || versions.size() > 3 || - (versions.size() >= 1 && !android::base::ParseUint(versions[0], &major)) || - (versions.size() >= 2 && !android::base::ParseUint(versions[1], &minor)) || - (versions.size() == 3 && !android::base::ParseUint(versions[2], &patch)) || - (major > 0x7f || minor > 0x7f || patch > 0x7f)) { - syntax_error("bad OS version: %s", optarg); - } - g_boot_img_hdr.SetOsVersion(major, minor, patch); + ParseOsVersion(&g_boot_img_hdr, optarg); } else if (name == "page-size") { g_boot_img_hdr.page_size = strtoul(optarg, nullptr, 0); if (g_boot_img_hdr.page_size == 0) die("invalid page size"); @@ -1801,3 +1786,26 @@ int FastBoot::Main(int argc, char* argv[]) { fprintf(stderr, "Finished. Total time: %.3fs\n", (now() - start)); return status; } + +void FastBoot::ParseOsPatchLevel(boot_img_hdr_v1* hdr, const char* arg) { + unsigned year, month, day; + if (sscanf(arg, "%u-%u-%u", &year, &month, &day) != 3) { + syntax_error("OS patch level should be YYYY-MM-DD: %s", arg); + } + if (year < 2000 || year >= 2128) syntax_error("year out of range: %d", year); + if (month < 1 || month > 12) syntax_error("month out of range: %d", month); + hdr->SetOsPatchLevel(year, month); +} + +void FastBoot::ParseOsVersion(boot_img_hdr_v1* hdr, const char* arg) { + unsigned major = 0, minor = 0, patch = 0; + std::vector<std::string> versions = android::base::Split(arg, "."); + if (versions.size() < 1 || versions.size() > 3 || + (versions.size() >= 1 && !android::base::ParseUint(versions[0], &major)) || + (versions.size() >= 2 && !android::base::ParseUint(versions[1], &minor)) || + (versions.size() == 3 && !android::base::ParseUint(versions[2], &patch)) || + (major > 0x7f || minor > 0x7f || patch > 0x7f)) { + syntax_error("bad OS version: %s", arg); + } + hdr->SetOsVersion(major, minor, patch); +} |