summaryrefslogtreecommitdiffstats
path: root/init
diff options
context:
space:
mode:
authorTom Cherry2018-07-13 17:32:02 -0500
committerTom Cherry2018-07-13 17:34:25 -0500
commit7421fa1aedc975f09d3c8b6b74aca454a5d2490d (patch)
tree7d74d8d760832220edcbb373460382cdce150533 /init
parentbcfc8a2ab035ab085f91b59f7f6f75ee364b3363 (diff)
downloadplatform-system-core-7421fa1aedc975f09d3c8b6b74aca454a5d2490d.tar.gz
platform-system-core-7421fa1aedc975f09d3c8b6b74aca454a5d2490d.tar.xz
platform-system-core-7421fa1aedc975f09d3c8b6b74aca454a5d2490d.zip
ueventd: let scripts provide firmware directories
Since some vendors will have firmware in mount points in /mnt/vendor/..., we extend the ueventd script language to allow specifying the firmware directories. Also, move the existing 4 directories to ueventd.rc as a primary user of this mechanism. Bug: 111337229 Test: boot sailfish; firmwares load Change-Id: I0854b0b786ad761e40d2332312c637610432fce2
Diffstat (limited to 'init')
-rw-r--r--init/devices.h1
-rw-r--r--init/firmware_handler.cpp10
-rw-r--r--init/firmware_handler.h5
-rw-r--r--init/ueventd.cpp52
-rw-r--r--init/ueventd_parser.cpp52
-rw-r--r--init/ueventd_parser.h24
6 files changed, 85 insertions, 59 deletions
diff --git a/init/devices.h b/init/devices.h
index f9035da3d..9224fcd82 100644
--- a/init/devices.h
+++ b/init/devices.h
@@ -106,7 +106,6 @@ class DeviceHandler {
106 DeviceHandler(std::vector<Permissions> dev_permissions, 106 DeviceHandler(std::vector<Permissions> dev_permissions,
107 std::vector<SysfsPermissions> sysfs_permissions, std::vector<Subsystem> subsystems, 107 std::vector<SysfsPermissions> sysfs_permissions, std::vector<Subsystem> subsystems,
108 std::set<std::string> boot_devices, bool skip_restorecon); 108 std::set<std::string> boot_devices, bool skip_restorecon);
109 ~DeviceHandler(){};
110 109
111 void HandleDeviceEvent(const Uevent& uevent); 110 void HandleDeviceEvent(const Uevent& uevent);
112 111
diff --git a/init/firmware_handler.cpp b/init/firmware_handler.cpp
index 8c8d9f2ab..28bda34a2 100644
--- a/init/firmware_handler.cpp
+++ b/init/firmware_handler.cpp
@@ -21,7 +21,6 @@
21#include <sys/wait.h> 21#include <sys/wait.h>
22#include <unistd.h> 22#include <unistd.h>
23 23
24#include <string>
25#include <thread> 24#include <thread>
26 25
27#include <android-base/chrono_utils.h> 26#include <android-base/chrono_utils.h>
@@ -36,6 +35,8 @@ using android::base::WriteFully;
36namespace android { 35namespace android {
37namespace init { 36namespace init {
38 37
38std::vector<std::string> firmware_directories;
39
39static void LoadFirmware(const Uevent& uevent, const std::string& root, int fw_fd, size_t fw_size, 40static void LoadFirmware(const Uevent& uevent, const std::string& root, int fw_fd, size_t fw_size,
40 int loading_fd, int data_fd) { 41 int loading_fd, int data_fd) {
41 // Start transfer. 42 // Start transfer.
@@ -78,12 +79,9 @@ static void ProcessFirmwareEvent(const Uevent& uevent) {
78 return; 79 return;
79 } 80 }
80 81
81 static const char* firmware_dirs[] = {"/etc/firmware/", "/odm/firmware/",
82 "/vendor/firmware/", "/firmware/image/"};
83
84try_loading_again: 82try_loading_again:
85 for (size_t i = 0; i < arraysize(firmware_dirs); i++) { 83 for (const auto& firmware_directory : firmware_directories) {
86 std::string file = firmware_dirs[i] + uevent.firmware; 84 std::string file = firmware_directory + uevent.firmware;
87 unique_fd fw_fd(open(file.c_str(), O_RDONLY | O_CLOEXEC)); 85 unique_fd fw_fd(open(file.c_str(), O_RDONLY | O_CLOEXEC));
88 struct stat sb; 86 struct stat sb;
89 if (fw_fd != -1 && fstat(fw_fd, &sb) != -1) { 87 if (fw_fd != -1 && fstat(fw_fd, &sb) != -1) {
diff --git a/init/firmware_handler.h b/init/firmware_handler.h
index e456ac4e4..6081511b5 100644
--- a/init/firmware_handler.h
+++ b/init/firmware_handler.h
@@ -17,11 +17,16 @@
17#ifndef _INIT_FIRMWARE_HANDLER_H 17#ifndef _INIT_FIRMWARE_HANDLER_H
18#define _INIT_FIRMWARE_HANDLER_H 18#define _INIT_FIRMWARE_HANDLER_H
19 19
20#include <string>
21#include <vector>
22
20#include "uevent.h" 23#include "uevent.h"
21 24
22namespace android { 25namespace android {
23namespace init { 26namespace init {
24 27
28extern std::vector<std::string> firmware_directories;
29
25void HandleFirmwareEvent(const Uevent& uevent); 30void HandleFirmwareEvent(const Uevent& uevent);
26 31
27} // namespace init 32} // namespace init
diff --git a/init/ueventd.cpp b/init/ueventd.cpp
index a284203ba..680944546 100644
--- a/init/ueventd.cpp
+++ b/init/ueventd.cpp
@@ -215,39 +215,6 @@ void ColdBoot::Run() {
215 LOG(INFO) << "Coldboot took " << cold_boot_timer.duration().count() / 1000.0f << " seconds"; 215 LOG(INFO) << "Coldboot took " << cold_boot_timer.duration().count() / 1000.0f << " seconds";
216} 216}
217 217
218DeviceHandler CreateDeviceHandler() {
219 Parser parser;
220
221 std::vector<Subsystem> subsystems;
222 parser.AddSectionParser("subsystem", std::make_unique<SubsystemParser>(&subsystems));
223
224 using namespace std::placeholders;
225 std::vector<SysfsPermissions> sysfs_permissions;
226 std::vector<Permissions> dev_permissions;
227 parser.AddSingleLineParser("/sys/",
228 std::bind(ParsePermissionsLine, _1, &sysfs_permissions, nullptr));
229 parser.AddSingleLineParser("/dev/",
230 std::bind(ParsePermissionsLine, _1, nullptr, &dev_permissions));
231
232 parser.ParseConfig("/ueventd.rc");
233 parser.ParseConfig("/vendor/ueventd.rc");
234 parser.ParseConfig("/odm/ueventd.rc");
235
236 /*
237 * keep the current product name base configuration so
238 * we remain backwards compatible and allow it to override
239 * everything
240 * TODO: cleanup platform ueventd.rc to remove vendor specific
241 * device node entries (b/34968103)
242 */
243 std::string hardware = android::base::GetProperty("ro.hardware", "");
244 parser.ParseConfig("/ueventd." + hardware + ".rc");
245
246 auto boot_devices = fs_mgr_get_boot_devices();
247 return DeviceHandler(std::move(dev_permissions), std::move(sysfs_permissions),
248 std::move(subsystems), std::move(boot_devices), true);
249}
250
251int ueventd_main(int argc, char** argv) { 218int ueventd_main(int argc, char** argv) {
252 /* 219 /*
253 * init sets the umask to 077 for forked processes. We need to 220 * init sets the umask to 077 for forked processes. We need to
@@ -263,9 +230,26 @@ int ueventd_main(int argc, char** argv) {
263 SelinuxSetupKernelLogging(); 230 SelinuxSetupKernelLogging();
264 SelabelInitialize(); 231 SelabelInitialize();
265 232
266 DeviceHandler device_handler = CreateDeviceHandler(); 233 DeviceHandler device_handler;
267 UeventListener uevent_listener; 234 UeventListener uevent_listener;
268 235
236 {
237 // Keep the current product name base configuration so we remain backwards compatible and
238 // allow it to override everything.
239 // TODO: cleanup platform ueventd.rc to remove vendor specific device node entries (b/34968103)
240 auto hardware = android::base::GetProperty("ro.hardware", "");
241
242 auto ueventd_configuration =
243 ParseConfig({"/ueventd.rc", "/vendor/ueventd.rc", "/odm/ueventd.rc", hardware});
244
245 device_handler = DeviceHandler{std::move(ueventd_configuration.dev_permissions),
246 std::move(ueventd_configuration.sysfs_permissions),
247 std::move(ueventd_configuration.subsystems),
248 fs_mgr_get_boot_devices(), true};
249
250 firmware_directories = ueventd_configuration.firmware_directories;
251 }
252
269 if (access(COLDBOOT_DONE, F_OK) != 0) { 253 if (access(COLDBOOT_DONE, F_OK) != 0) {
270 ColdBoot cold_boot(uevent_listener, device_handler); 254 ColdBoot cold_boot(uevent_listener, device_handler);
271 cold_boot.Run(); 255 cold_boot.Run();
diff --git a/init/ueventd_parser.cpp b/init/ueventd_parser.cpp
index f74c87849..c114ec704 100644
--- a/init/ueventd_parser.cpp
+++ b/init/ueventd_parser.cpp
@@ -20,6 +20,7 @@
20#include <pwd.h> 20#include <pwd.h>
21 21
22#include "keyword_map.h" 22#include "keyword_map.h"
23#include "parser.h"
23 24
24namespace android { 25namespace android {
25namespace init { 26namespace init {
@@ -72,6 +73,33 @@ Result<Success> ParsePermissionsLine(std::vector<std::string>&& args,
72 return Success(); 73 return Success();
73} 74}
74 75
76Result<Success> ParseFirmwareDirectoriesLine(std::vector<std::string>&& args,
77 std::vector<std::string>* firmware_directories) {
78 if (args.size() < 2) {
79 return Error() << "firmware_directories must have at least 1 entry";
80 }
81
82 std::move(std::next(args.begin()), args.end(), std::back_inserter(*firmware_directories));
83
84 return Success();
85}
86
87class SubsystemParser : public SectionParser {
88 public:
89 SubsystemParser(std::vector<Subsystem>* subsystems) : subsystems_(subsystems) {}
90 Result<Success> ParseSection(std::vector<std::string>&& args, const std::string& filename,
91 int line) override;
92 Result<Success> ParseLineSection(std::vector<std::string>&& args, int line) override;
93 Result<Success> EndSection() override;
94
95 private:
96 Result<Success> ParseDevName(std::vector<std::string>&& args);
97 Result<Success> ParseDirName(std::vector<std::string>&& args);
98
99 Subsystem subsystem_;
100 std::vector<Subsystem>* subsystems_;
101};
102
75Result<Success> SubsystemParser::ParseSection(std::vector<std::string>&& args, 103Result<Success> SubsystemParser::ParseSection(std::vector<std::string>&& args,
76 const std::string& filename, int line) { 104 const std::string& filename, int line) {
77 if (args.size() != 2) { 105 if (args.size() != 2) {
@@ -138,5 +166,29 @@ Result<Success> SubsystemParser::EndSection() {
138 return Success(); 166 return Success();
139} 167}
140 168
169UeventdConfiguration ParseConfig(const std::vector<std::string>& configs) {
170 Parser parser;
171 UeventdConfiguration ueventd_configuration;
172
173 parser.AddSectionParser("subsystem",
174 std::make_unique<SubsystemParser>(&ueventd_configuration.subsystems));
175
176 using namespace std::placeholders;
177 parser.AddSingleLineParser(
178 "/sys/",
179 std::bind(ParsePermissionsLine, _1, &ueventd_configuration.sysfs_permissions, nullptr));
180 parser.AddSingleLineParser("/dev/", std::bind(ParsePermissionsLine, _1, nullptr,
181 &ueventd_configuration.dev_permissions));
182 parser.AddSingleLineParser("firmware_directories",
183 std::bind(ParseFirmwareDirectoriesLine, _1,
184 &ueventd_configuration.firmware_directories));
185
186 for (const auto& config : configs) {
187 parser.ParseConfig(config);
188 }
189
190 return ueventd_configuration;
191}
192
141} // namespace init 193} // namespace init
142} // namespace android 194} // namespace android
diff --git a/init/ueventd_parser.h b/init/ueventd_parser.h
index 83684f39e..343d58bfd 100644
--- a/init/ueventd_parser.h
+++ b/init/ueventd_parser.h
@@ -21,30 +21,18 @@
21#include <vector> 21#include <vector>
22 22
23#include "devices.h" 23#include "devices.h"
24#include "parser.h"
25 24
26namespace android { 25namespace android {
27namespace init { 26namespace init {
28 27
29class SubsystemParser : public SectionParser { 28struct UeventdConfiguration {
30 public: 29 std::vector<Subsystem> subsystems;
31 SubsystemParser(std::vector<Subsystem>* subsystems) : subsystems_(subsystems) {} 30 std::vector<SysfsPermissions> sysfs_permissions;
32 Result<Success> ParseSection(std::vector<std::string>&& args, const std::string& filename, 31 std::vector<Permissions> dev_permissions;
33 int line) override; 32 std::vector<std::string> firmware_directories;
34 Result<Success> ParseLineSection(std::vector<std::string>&& args, int line) override;
35 Result<Success> EndSection() override;
36
37 private:
38 Result<Success> ParseDevName(std::vector<std::string>&& args);
39 Result<Success> ParseDirName(std::vector<std::string>&& args);
40
41 Subsystem subsystem_;
42 std::vector<Subsystem>* subsystems_;
43}; 33};
44 34
45Result<Success> ParsePermissionsLine(std::vector<std::string>&& args, 35UeventdConfiguration ParseConfig(const std::vector<std::string>& configs);
46 std::vector<SysfsPermissions>* out_sysfs_permissions,
47 std::vector<Permissions>* out_dev_permissions);
48 36
49} // namespace init 37} // namespace init
50} // namespace android 38} // namespace android