• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/core


Commit MetaInfo

修訂60d83effb0b17b7a25ea440d2e2c21ae64cffed8 (tree)
時間2017-12-26 19:43:34
作者Chih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

init: add modprobe

We added the modprobe function to init before but it was dropped in
oreo-x86. Originally I planned to replace it by toybox's modprobe.
However, it doesn't work as expected. For example, the audio driver
is not loaded correctly in some Skylake devices.

To fix that, add back the modprobe function to init.

Change Summary

差異

--- a/init/Android.mk
+++ b/init/Android.mk
@@ -94,6 +94,7 @@ LOCAL_REQUIRED_MODULES := \
9494
9595 # Create symlinks.
9696 LOCAL_POST_INSTALL_CMD := $(hide) mkdir -p $(TARGET_ROOT_OUT)/sbin; \
97+ ln -sf ../init $(TARGET_ROOT_OUT)/sbin/modprobe; \
9798 ln -sf ../init $(TARGET_ROOT_OUT)/sbin/ueventd; \
9899 ln -sf ../init $(TARGET_ROOT_OUT)/sbin/watchdogd
99100
--- a/init/devices.cpp
+++ b/init/devices.cpp
@@ -31,6 +31,7 @@
3131 #include <private/android_filesystem_config.h>
3232 #include <selinux/android.h>
3333 #include <selinux/selinux.h>
34+#include <cutils/klog.h>
3435 #include <cutils/probe_module.h>
3536
3637 #include "ueventd.h"
@@ -521,5 +522,40 @@ DeviceHandler::DeviceHandler()
521522 : DeviceHandler(std::vector<Permissions>{}, std::vector<SysfsPermissions>{},
522523 std::vector<Subsystem>{}, false) {}
523524
525+int modprobe_main(int argc, char **argv)
526+{
527+ // We only accept requests from root user (kernel)
528+ if (getuid()) return -EPERM;
529+
530+ // Kernel will launch a user space program specified by
531+ // /proc/sys/kernel/modprobe to load modules.
532+ // No deferred loading in this case.
533+ while (argc > 1 && (!strcmp(argv[1], "-q") || !strcmp(argv[1], "--"))) {
534+ klog_set_level(KLOG_NOTICE_LEVEL);
535+ argc--, argv++;
536+ }
537+
538+ if (argc < 2) {
539+ // it is called without enough arguments
540+ return -EINVAL;
541+ }
542+
543+ std::string options;
544+ if (argc > 2) {
545+ options = argv[2];
546+ for (int i = 3; i < argc; ++i) {
547+ options += ' ';
548+ options += argv[i];
549+ }
550+ }
551+ KLOG_NOTICE("modprobe", "%s %s", argv[1], options.c_str());
552+
553+ Uevent uevent = { .modalias = argv[1] };
554+ DeviceHandler dh;
555+ dh.ReadModulesDescFiles();
556+ dh.OnColdBootDone();
557+ return dh.LoadModule(uevent) || dh.LoadModule(uevent.modalias) ? 0 : -1;
558+}
559+
524560 } // namespace init
525561 } // namespace android
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -995,6 +995,10 @@ static void InstallRebootSignalHandlers() {
995995 }
996996
997997 int main(int argc, char** argv) {
998+ if (!strcmp(basename(argv[0]), "modprobe")) {
999+ return modprobe_main(argc, argv);
1000+ }
1001+
9981002 if (!strcmp(basename(argv[0]), "ueventd")) {
9991003 return ueventd_main(argc, argv);
10001004 }
--- a/init/ueventd.h
+++ b/init/ueventd.h
@@ -21,6 +21,7 @@ namespace android {
2121 namespace init {
2222
2323 int ueventd_main(int argc, char** argv);
24+int modprobe_main(int argc, char **argv);
2425
2526 } // namespace init
2627 } // namespace android