From d2e74db475e095bc0386f89b042dc7e7474b797a Mon Sep 17 00:00:00 2001 From: Amit Pundir Date: Wed, 29 Jun 2016 19:00:00 +0530 Subject: [PATCH] init: select usb gadget controller at run time Right now we set sys.usb.controller property in init.$platform.usb.rc to enable ConfigFS gadgets. Let system detect and set UDC driver name from /sys/class/udc instead. Change-Id: I99ad49d24dc53b543c5573e209bf00d6c2d91dd4 Signed-off-by: Amit Pundir --- init/init.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/init/init.cpp b/init/init.cpp index fe2aee4eb..fc3e80f57 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -444,6 +444,22 @@ static void selinux_initialize(bool in_kernel_domain) { } } +// Set the UDC controller for the ConfigFS USB Gadgets. +// Read the UDC controller in use from "/sys/class/udc". +// In case of multiple UDC controllers select the first one. +static void set_usb_controller() { + std::unique_ptrdir(opendir("/sys/class/udc"), closedir); + if (!dir) return; + + dirent* dp; + while ((dp = readdir(dir.get())) != nullptr) { + if (dp->d_name[0] == '.') continue; + + property_set("sys.usb.controller", dp->d_name); + break; + } +} + int main(int argc, char** argv) { if (!strcmp(basename(argv[0]), "ueventd")) { return ueventd_main(argc, argv); @@ -536,6 +552,7 @@ int main(int argc, char** argv) { property_load_boot_defaults(); export_oem_lock_status(); start_property_service(); + set_usb_controller(); const BuiltinFunctionMap function_map; Action::set_function_map(&function_map);