From 6f0ebcb5260a8e769e0e029596d21c0efabe361b Mon Sep 17 00:00:00 2001 From: Jan Dabros Date: Thu, 19 Oct 2023 11:36:37 +0000 Subject: [PATCH] init: Look for super partition only on a boot device Init code is bailing out as soon as `super` partition was found in the system, ignoring rest of uevents. In case given device contains multiple boot sources, `super` partition as well as all other partitions shall be taken from the same boot source, instead of relying on `which uevent came first`. Bug: 309244873, 349144493 Test: Plug secondary USB boot device to device that supports multiple boot sources. Select boot from USB. Device boots properly. Signed-off-by: Jan Dabros Signed-off-by: Konrad Adamczyk Change-Id: I70eb7d4223258ec273faa523cb67ddab0b7c32a0 --- init/block_dev_initializer.cpp | 6 +++++- init/devices.cpp | 22 ++++++++++++++++++++++ init/devices.h | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/init/block_dev_initializer.cpp b/init/block_dev_initializer.cpp index 8f5215856..cabeb0109 100644 --- a/init/block_dev_initializer.cpp +++ b/init/block_dev_initializer.cpp @@ -98,7 +98,11 @@ ListenerAction BlockDevInitializer::HandleUevent(const Uevent& uevent, LOG(VERBOSE) << __PRETTY_FUNCTION__ << ": found partition: " << name; - devices->erase(iter); + // Remove partition from the list only if it was found on boot device + if (device_handler_->IsBootDevice(uevent)) { + devices->erase(iter); + } + device_handler_->HandleUevent(uevent); return devices->empty() ? ListenerAction::kStop : ListenerAction::kContinue; } diff --git a/init/devices.cpp b/init/devices.cpp index f2bb9d276..6a3a64dd8 100644 --- a/init/devices.cpp +++ b/init/devices.cpp @@ -188,6 +188,28 @@ void SysfsPermissions::SetPermissions(const std::string& path) const { } } +bool DeviceHandler::IsBootDevice(const Uevent& uevent) const { + std::string device; + + if (FindPlatformDevice(uevent.path, &device)) { + // Skip /devices/platform or /devices/ if present + static constexpr std::string_view devices_platform_prefix = "/devices/platform/"; + static constexpr std::string_view devices_prefix = "/devices/"; + + if (StartsWith(device, devices_platform_prefix)) { + device = device.substr(devices_platform_prefix.length()); + } else if (StartsWith(device, devices_prefix)) { + device = device.substr(devices_prefix.length()); + } + } else if (FindPciDevicePrefix(uevent.path, &device)) { + } else if (FindVbdDevicePrefix(uevent.path, &device)) { + } else { + return false; + } + + return boot_devices_.find(device) != boot_devices_.end(); +} + std::string DeviceHandler::GetPartitionNameForDevice(const std::string& query_device) { static const auto partition_map = [] { std::vector> partition_map; diff --git a/init/devices.h b/init/devices.h index 6da123259..4df604d00 100644 --- a/init/devices.h +++ b/init/devices.h @@ -133,6 +133,7 @@ class DeviceHandler : public UeventHandler { // `androidboot.partition_map=vdb,metadata;vdc,userdata` maps `vdb` to `metadata` and `vdc` to // `userdata`. static std::string GetPartitionNameForDevice(const std::string& device); + bool IsBootDevice(const Uevent& uevent) const; private: void ColdbootDone() override;