summaryrefslogtreecommitdiff
path: root/partition_tools
diff options
context:
space:
mode:
authorRam Muthiah <rammuthiah@google.com>2022-01-30 09:17:22 -0800
committerRam Muthiah <rammuthiah@google.com>2022-02-03 11:51:18 -0800
commitcfd33d62ba061000f0fcbcd1d9d9752e61d423cd (patch)
treeb7588c3dbe2bd3b066bc4c2c7c718be0eafc09ec /partition_tools
parent61a427a01de6c729ef13164c5a7aaa6997a6f652 (diff)
downloadextras-cfd33d62ba061000f0fcbcd1d9d9752e61d423cd.tar.gz
Add replace opt to lpadd make build mixing easier
Needed for both system_dlkm and vendor_dlkm mixing. Bug: 149866755 Bug: 200082547 Test: tested on local super image Change-Id: Id7dea9480b9da4b844de73b35a9dc3a1e7a659d1
Diffstat (limited to 'partition_tools')
-rw-r--r--partition_tools/lpadd.cc23
1 files changed, 20 insertions, 3 deletions
diff --git a/partition_tools/lpadd.cc b/partition_tools/lpadd.cc
index a92de955..7374e774 100644
--- a/partition_tools/lpadd.cc
+++ b/partition_tools/lpadd.cc
@@ -58,12 +58,15 @@ static int usage(const char* program) {
std::cerr << "\n";
std::cerr << "Extra options:\n";
std::cerr << " --readonly The partition should be mapped read-only.\n";
+ std::cerr << " --replace The partition contents should be replaced with\n"
+ << " the input image.\n";
std::cerr << "\n";
return EX_USAGE;
}
enum class OptionCode : int {
kReadonly = 1,
+ kReplace = 2,
// Special options.
kHelp = (int)'h',
@@ -105,7 +108,7 @@ class SuperHelper final {
bool Open();
bool AddPartition(const std::string& partition_name, const std::string& group_name,
- uint32_t attributes, const std::string& image_path);
+ uint32_t attributes, const std::string& image_path, bool replace);
bool Finalize();
private:
@@ -158,12 +161,21 @@ bool SuperHelper::Open() {
}
bool SuperHelper::AddPartition(const std::string& partition_name, const std::string& group_name,
- uint32_t attributes, const std::string& image_path) {
+ uint32_t attributes, const std::string& image_path, bool replace) {
if (!image_path.empty() && was_empty_) {
std::cerr << "Cannot add a partition image to an empty super file.\n";
return false;
}
+ if (replace) {
+ auto partition = builder_->FindPartition(partition_name);
+ if (!partition) {
+ std::cerr << "Could not find partition to replace: " << partition_name << "\n";
+ return false;
+ }
+ builder_->RemovePartition(partition_name);
+ }
+
auto partition = builder_->AddPartition(partition_name, group_name, attributes);
if (!partition) {
std::cerr << "Could not add partition: " << partition_name << "\n";
@@ -422,10 +434,12 @@ static void ErrorLogger(android::base::LogId, android::base::LogSeverity severit
int main(int argc, char* argv[]) {
struct option options[] = {
{"readonly", no_argument, nullptr, (int)OptionCode::kReadonly},
+ {"replace", no_argument, nullptr, (int)OptionCode::kReplace},
{nullptr, 0, nullptr, 0},
};
bool readonly = false;
+ bool replace = false;
int rv, index;
while ((rv = getopt_long(argc, argv, "h", options, &index)) != -1) {
@@ -436,6 +450,9 @@ int main(int argc, char* argv[]) {
case OptionCode::kReadonly:
readonly = true;
break;
+ case OptionCode::kReplace:
+ replace = true;
+ break;
default:
return usage(argv[0]);
}
@@ -471,7 +488,7 @@ int main(int argc, char* argv[]) {
if (readonly) {
attributes |= LP_PARTITION_ATTR_READONLY;
}
- if (!super.AddPartition(partition_name, group_name, attributes, image_path)) {
+ if (!super.AddPartition(partition_name, group_name, attributes, image_path, replace)) {
return EX_SOFTWARE;
}
if (!super.Finalize()) {