+struct device {
+ struct list_head node;
+ char path[PATH_SIZE];
+ char subsys[NAME_SIZE];
+};
+
+/* sort files in lexical order */
+static int device_list_insert(const char *path, char *subsystem, struct list_head *device_list)
+{
+ struct device *loop_device;
+ struct device *new_device;
+ const char *devpath = &path[strlen(sysfs_path)];
+
+ dbg("insert: '%s'\n", devpath);
+
+ list_for_each_entry(loop_device, device_list, node) {
+ if (strcmp(loop_device->path, devpath) > 0) {
+ break;
+ }
+ }
+
+ new_device = malloc(sizeof(struct device));
+ if (new_device == NULL) {
+ dbg("error malloc");
+ return -ENOMEM;
+ }
+
+ strlcpy(new_device->path, devpath, sizeof(new_device->path));
+ strlcpy(new_device->subsys, subsystem, sizeof(new_device->subsys));
+ list_add_tail(&new_device->node, &loop_device->node);
+ dbg("add '%s' from subsys '%s'", new_device->path, new_device->subsys);
+ return 0;
+}
+
+/* list of devices that we should run last due to any one of a number of reasons */
+static char *last_list[] = {
+ "/block/dm", /* on here because dm wants to have the block devices around before it */
+ NULL,
+};
+
+/* list of devices that we should run first due to any one of a number of reasons */
+static char *first_list[] = {
+ "/class/mem",
+ "/class/tty",
+ NULL,
+};
+
+static int add_device(const char *devpath, const char *subsystem)
+{
+ struct udevice udev;
+ struct sysfs_class_device *class_dev;
+ char path[PATH_SIZE];
+
+ /* clear and set environment for next event */
+ clearenv();
+ setenv("ACTION", "add", 1);
+ setenv("DEVPATH", devpath, 1);
+ setenv("SUBSYSTEM", subsystem, 1);
+ setenv("UDEV_START", "1", 1);
+ if (udev_log_str)
+ setenv("UDEV_LOG", udev_log_str, 1);
+ if (udev_run_str)
+ setenv("UDEV_RUN", udev_run_str, 1);
+ dbg("add '%s'", devpath);