@@ -82,6 +82,7 @@ class FirstStageMount {
82
82
// The factory method to create either FirstStageMountVBootV1 or FirstStageMountVBootV2
83
83
// based on device tree configurations.
84
84
static std::unique_ptr<FirstStageMount> Create ();
85
+ bool DoCreateDevices (); // Creates devices and logical partitions from storage devices
85
86
bool DoFirstStageMount (); // Mounts fstab entries read from device tree.
86
87
bool InitDevices ();
87
88
@@ -244,15 +245,35 @@ std::unique_ptr<FirstStageMount> FirstStageMount::Create() {
244
245
}
245
246
}
246
247
248
+ bool FirstStageMount::DoCreateDevices () {
249
+ if (!InitDevices ()) return false ;
250
+
251
+ // Mount /metadata before creating logical partitions, since we need to
252
+ // know whether a snapshot merge is in progress.
253
+ auto metadata_partition = std::find_if (fstab_.begin (), fstab_.end (), [](const auto & entry) {
254
+ return entry.mount_point == " /metadata" ;
255
+ });
256
+ if (metadata_partition != fstab_.end ()) {
257
+ if (MountPartition (metadata_partition, true /* erase_same_mounts */ )) {
258
+ // Copies DSU AVB keys from the ramdisk to /metadata.
259
+ // Must be done before the following TrySwitchSystemAsRoot().
260
+ // Otherwise, ramdisk will be inaccessible after switching root.
261
+ CopyDsuAvbKeys ();
262
+ }
263
+ }
264
+
265
+ if (!CreateLogicalPartitions ()) return false ;
266
+
267
+ return true ;
268
+ }
269
+
247
270
bool FirstStageMount::DoFirstStageMount () {
248
271
if (!IsDmLinearEnabled () && fstab_.empty ()) {
249
272
// Nothing to mount.
250
273
LOG (INFO) << " First stage mount skipped (missing/incompatible/empty fstab in device tree)" ;
251
274
return true ;
252
275
}
253
276
254
- if (!InitDevices ()) return false ;
255
-
256
277
if (!MountPartitions ()) return false ;
257
278
258
279
return true ;
@@ -505,22 +526,6 @@ bool FirstStageMount::TrySwitchSystemAsRoot() {
505
526
}
506
527
507
528
bool FirstStageMount::MountPartitions () {
508
- // Mount /metadata before creating logical partitions, since we need to
509
- // know whether a snapshot merge is in progress.
510
- auto metadata_partition = std::find_if (fstab_.begin (), fstab_.end (), [](const auto & entry) {
511
- return entry.mount_point == " /metadata" ;
512
- });
513
- if (metadata_partition != fstab_.end ()) {
514
- if (MountPartition (metadata_partition, true /* erase_same_mounts */ )) {
515
- // Copies DSU AVB keys from the ramdisk to /metadata.
516
- // Must be done before the following TrySwitchSystemAsRoot().
517
- // Otherwise, ramdisk will be inaccessible after switching root.
518
- CopyDsuAvbKeys ();
519
- }
520
- }
521
-
522
- if (!CreateLogicalPartitions ()) return false ;
523
-
524
529
if (!TrySwitchSystemAsRoot ()) return false ;
525
530
526
531
if (!SkipMountingPartitions (&fstab_)) return false ;
@@ -829,8 +834,18 @@ bool FirstStageMountVBootV2::InitAvbHandle() {
829
834
830
835
// Public functions
831
836
// ----------------
837
+ // Creates devices and logical partitions from storage devices
838
+ bool DoCreateDevices () {
839
+ std::unique_ptr<FirstStageMount> handle = FirstStageMount::Create ();
840
+ if (!handle) {
841
+ LOG (ERROR) << " Failed to create FirstStageMount" ;
842
+ return false ;
843
+ }
844
+ return handle->DoCreateDevices ();
845
+ }
846
+
832
847
// Mounts partitions specified by fstab in device tree.
833
- bool DoFirstStageMount () {
848
+ bool DoFirstStageMount (bool create_devices ) {
834
849
// Skips first stage mount if we're in recovery mode.
835
850
if (IsRecoveryMode ()) {
836
851
LOG (INFO) << " First stage mount skipped (recovery mode)" ;
@@ -842,6 +857,11 @@ bool DoFirstStageMount() {
842
857
LOG (ERROR) << " Failed to create FirstStageMount" ;
843
858
return false ;
844
859
}
860
+
861
+ if (create_devices) {
862
+ if (!handle->DoCreateDevices ()) return false ;
863
+ }
864
+
845
865
return handle->DoFirstStageMount ();
846
866
}
847
867
0 commit comments