Skip to content

Commit dce50c9

Browse files
committed
Add physical partition detection fallback logic to AndroidBuild
Bug: b/472553631
1 parent 75bc014 commit dce50c9

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

base/cvd/cuttlefish/host/commands/assemble_cvd/android_build/BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ cf_cc_library(
129129
],
130130
)
131131

132+
cf_cc_library(
133+
name = "physical_partitions",
134+
srcs = ["physical_partitions.cc"],
135+
hdrs = ["physical_partitions.h"],
136+
deps = [
137+
"//cuttlefish/host/commands/assemble_cvd/android_build",
138+
"//cuttlefish/result",
139+
],
140+
)
141+
132142
cf_cc_library(
133143
name = "super_image",
134144
srcs = ["super_image.cc"],
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//
2+
// Copyright (C) 2025 The Android Open Source Project
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#include "cuttlefish/host/commands/assemble_cvd/android_build/physical_partitions.h"
17+
18+
#include <functional>
19+
#include <memory>
20+
#include <ostream>
21+
#include <set>
22+
23+
#include "cuttlefish/host/commands/assemble_cvd/android_build/android_build.h"
24+
#include "cuttlefish/result/result.h"
25+
26+
namespace cuttlefish {
27+
namespace {
28+
29+
class PhysicalPartitionsImpl : public AndroidBuild {
30+
public:
31+
PhysicalPartitionsImpl(AndroidBuild& build) : build_(build) {}
32+
33+
Result<std::set<std::string, std::less<void>>> PhysicalPartitions() override {
34+
if (auto res = build_.PhysicalPartitions(); res.ok()) {
35+
return *res;
36+
}
37+
38+
std::set<std::string, std::less<void>> partitions =
39+
CF_EXPECT(build_.Images());
40+
for (std::string logical : CF_EXPECT(build_.LogicalPartitions())) {
41+
partitions.erase(logical);
42+
}
43+
44+
if (partitions.count("super_empty")) {
45+
partitions.erase("super_empty");
46+
partitions.insert("super");
47+
}
48+
49+
return partitions;
50+
}
51+
52+
private:
53+
std::ostream& Format(std::ostream& out) const override {
54+
return out << "PhysicalPartitions";
55+
}
56+
57+
AndroidBuild& build_;
58+
};
59+
60+
} // namespace
61+
62+
Result<std::unique_ptr<AndroidBuild>> PhysicalPartitions(AndroidBuild& build) {
63+
auto partitions = std::make_unique<PhysicalPartitionsImpl>(build);
64+
65+
CF_EXPECT(partitions->PhysicalPartitions());
66+
67+
return partitions;
68+
}
69+
70+
} // namespace cuttlefish
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// Copyright (C) 2025 The Android Open Source Project
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#pragma once
17+
18+
#include <memory>
19+
20+
#include "cuttlefish/host/commands/assemble_cvd/android_build/android_build.h"
21+
#include "cuttlefish/result/result.h"
22+
23+
namespace cuttlefish {
24+
25+
/**
26+
* Wrap an `AndroidBuild` with fallback physical partition detection logic.
27+
*
28+
* If the `AndroidBuild` does not already provide GPT entry information, this
29+
* makes a best guess based on known logical partitions and image files.
30+
*
31+
* One use case is the android product directory or `m` case, where the build
32+
* system produces a collection of `.img` files including a `super.img`, but no
33+
* explicit list of physical partitions.
34+
*/
35+
Result<std::unique_ptr<AndroidBuild>> PhysicalPartitions(AndroidBuild&);
36+
37+
} // namespace cuttlefish

0 commit comments

Comments
 (0)