summaryrefslogtreecommitdiff
path: root/gsi_tool.cpp
diff options
context:
space:
mode:
authorHoward Chen <howardsoc@google.com>2019-08-13 17:00:44 +0800
committerHoward Chen <howardsoc@google.com>2019-10-24 01:19:38 +0800
commit18109b1f1add5187c57b2d90f5953ad592f16fe6 (patch)
tree1b876eb8170a283452a3f918b18448f93d1d0809 /gsi_tool.cpp
parent1d58060fdb7ac0ec38e3ef9e76731d401adf02f6 (diff)
downloadgsid-18109b1f1add5187c57b2d90f5953ad592f16fe6.tar.gz
Make DSU to support multiple partitions
Make gsid to support multiple partitions in a generic way. Bug: 139402092 Test: \ adb shell gsi_tool install -n --gsi-size $(du -b system.raw|cut -f1) -w < system.raw adb shell gsi_tool install -n --gsi-size $(du -b vendor.raw|cut -f1) -p vendor < vendor.raw Change-Id: Iaf5259cc059daa61cf52efab20bf23a433909b7a
Diffstat (limited to 'gsi_tool.cpp')
-rw-r--r--gsi_tool.cpp55
1 files changed, 39 insertions, 16 deletions
diff --git a/gsi_tool.cpp b/gsi_tool.cpp
index e3718c7..fa287d3 100644
--- a/gsi_tool.cpp
+++ b/gsi_tool.cpp
@@ -187,21 +187,23 @@ class ProgressBar {
};
static int Install(sp<IGsiService> gsid, int argc, char** argv) {
+ constexpr const char* kDefaultPartition = "system";
struct option options[] = {
{"install-dir", required_argument, nullptr, 'i'},
{"gsi-size", required_argument, nullptr, 's'},
{"no-reboot", no_argument, nullptr, 'n'},
{"userdata-size", required_argument, nullptr, 'u'},
+ {"partition-name", required_argument, nullptr, 'p'},
{"wipe", no_argument, nullptr, 'w'},
{nullptr, 0, nullptr, 0},
};
- GsiInstallParams params;
- params.gsiSize = 0;
- params.userdataSize = 0;
- params.wipeUserdata = false;
+ long gsiSize = 0;
+ long userdataSize = 0;
+ bool wipeUserdata = false;
bool reboot = true;
-
+ std::string installDir = "";
+ std::string partition = kDefaultPartition;
if (getuid() != 0) {
std::cerr << "must be root to install a GSI" << std::endl;
return EX_NOPERM;
@@ -210,24 +212,26 @@ static int Install(sp<IGsiService> gsid, int argc, char** argv) {
int rv, index;
while ((rv = getopt_long_only(argc, argv, "", options, &index)) != -1) {
switch (rv) {
+ case 'p':
+ partition = optarg;
+ break;
case 's':
- if (!android::base::ParseInt(optarg, &params.gsiSize) || params.gsiSize <= 0) {
+ if (!android::base::ParseInt(optarg, &gsiSize) || gsiSize <= 0) {
std::cerr << "Could not parse image size: " << optarg << std::endl;
return EX_USAGE;
}
break;
case 'u':
- if (!android::base::ParseInt(optarg, &params.userdataSize) ||
- params.userdataSize < 0) {
+ if (!android::base::ParseInt(optarg, &userdataSize) || userdataSize < 0) {
std::cerr << "Could not parse image size: " << optarg << std::endl;
return EX_USAGE;
}
break;
case 'i':
- params.installDir = optarg;
+ installDir = optarg;
break;
case 'w':
- params.wipeUserdata = true;
+ wipeUserdata = true;
break;
case 'n':
reboot = false;
@@ -235,7 +239,7 @@ static int Install(sp<IGsiService> gsid, int argc, char** argv) {
}
}
- if (params.gsiSize <= 0) {
+ if (gsiSize <= 0) {
std::cerr << "Must specify --gsi-size." << std::endl;
return EX_USAGE;
}
@@ -253,23 +257,42 @@ static int Install(sp<IGsiService> gsid, int argc, char** argv) {
std::cerr << "Error duplicating descriptor: " << strerror(errno) << std::endl;
return EX_SOFTWARE;
}
-
// Note: the progress bar needs to be re-started in between each call.
ProgressBar progress(gsid);
progress.Display();
-
int error;
- auto status = gsid->beginGsiInstall(params, &error);
+ if (partition == kDefaultPartition) {
+ GsiInstallParams userdataParams;
+ userdataParams.installDir = installDir;
+ userdataParams.name = "userdata";
+ userdataParams.size = userdataSize;
+ userdataParams.wipe = wipeUserdata;
+ userdataParams.readOnly = false;
+
+ auto status = gsid->beginGsiInstall(userdataParams, &error);
+ if (!status.isOk() || error != IGsiService::INSTALL_OK) {
+ std::cerr << "Could not start live image install: " << ErrorMessage(status, error)
+ << "\n";
+ return EX_SOFTWARE;
+ }
+ }
+ GsiInstallParams systemParams;
+ systemParams.installDir = installDir;
+ systemParams.name = partition;
+ systemParams.size = gsiSize;
+ systemParams.wipe = true;
+ systemParams.readOnly = true;
+
+ auto status = gsid->beginGsiInstall(systemParams, &error);
if (!status.isOk() || error != IGsiService::INSTALL_OK) {
std::cerr << "Could not start live image install: " << ErrorMessage(status, error) << "\n";
return EX_SOFTWARE;
}
-
android::os::ParcelFileDescriptor stream(std::move(input));
bool ok = false;
progress.Display();
- status = gsid->commitGsiChunkFromStream(stream, params.gsiSize, &ok);
+ status = gsid->commitGsiChunkFromStream(stream, systemParams.size, &ok);
if (!ok) {
std::cerr << "Could not commit live image data: " << ErrorMessage(status) << "\n";
return EX_SOFTWARE;