init: refactor: add support for doing early coldboot
We don't want to spend time creating devices that are unncessesary
during early (init first-stage) mount. So, refactor the devices code
tha allows us to call into coldboot and has the
- ability to only create devices that are specified by the caller
- ability to stop coldboot cycle when all devices that the caller is
interested in
- ability to run coldboot for a specific syspath
- ability to run ueventd code unmodified
Test: Tested boot on angler, sailfish
Change-Id: Id8f3492380696760414eadc20d624d300c904f8e
Signed-off-by: Sandeep Patil <sspatil@google.com>
diff --git a/init/devices.h b/init/devices.h
index 8e9ab7d..d1e489b 100644
--- a/init/devices.h
+++ b/init/devices.h
@@ -17,10 +17,36 @@
#ifndef _INIT_DEVICES_H
#define _INIT_DEVICES_H
+#include <functional>
#include <sys/stat.h>
-extern void handle_device_fd();
-extern void device_init(void);
+enum coldboot_action_t {
+ // coldboot continues without creating the device for the uevent
+ COLDBOOT_CONTINUE = 0,
+ // coldboot continues after creating the device for the uevent
+ COLDBOOT_CREATE,
+ // coldboot stops after creating the device for uevent but doesn't
+ // create the COLDBOOT_DONE file
+ COLDBOOT_STOP,
+ // same as COLDBOOT_STOP, but creates the COLDBOOT_DONE file
+ COLDBOOT_FINISH
+};
+
+struct uevent {
+ const char* action;
+ const char* path;
+ const char* subsystem;
+ const char* firmware;
+ const char* partition_name;
+ const char* device_name;
+ int partition_num;
+ int major;
+ int minor;
+};
+
+typedef std::function<coldboot_action_t(struct uevent* uevent)> coldboot_callback;
+extern coldboot_action_t handle_device_fd(coldboot_callback fn = nullptr);
+extern void device_init(const char* path = nullptr, coldboot_callback fn = nullptr);
enum early_device_type { EARLY_BLOCK_DEV, EARLY_CHAR_DEV };