+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;
+
+ dbg("insert: '%s'\n", path);
+
+ list_for_each_entry(loop_device, device_list, node) {
+ if (strcmp(loop_device->path, path) > 0) {
+ break;
+ }
+ }
+
+ new_device = malloc(sizeof(struct device));
+ if (new_device == NULL) {
+ dbg("error malloc");
+ return -ENOMEM;
+ }
+
+ strlcpy(new_device->path, path, 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", /* people tend to like their memory devices around first... */
+ NULL,
+};
+
+static int add_device(const char *path, const char *subsystem)
+{
+ struct udevice udev;
+ struct sysfs_class_device *class_dev;
+ const char *devpath;
+
+ devpath = &path[strlen(sysfs_path)];
+
+ /* set environment for callouts and dev.d/ */
+ setenv("DEVPATH", devpath, 1);
+ setenv("SUBSYSTEM", subsystem, 1);
+
+ dbg("exec: '%s' (%s)\n", devpath, path);
+
+ class_dev = sysfs_open_class_device_path(path);
+ if (class_dev == NULL) {
+ dbg ("sysfs_open_class_device_path failed");
+ return -ENODEV;
+ }
+
+ udev_init_device(&udev, devpath, subsystem);
+ udev_add_device(&udev, class_dev);
+
+ /* run dev.d/ scripts if we created a node or changed a netif name */
+ if (udev_dev_d && udev.devname[0] != '\0') {
+ setenv("DEVNAME", udev.devname, 1);
+ udev_multiplex_directory(&udev, DEVD_DIR, DEVD_SUFFIX);
+ }
+
+ sysfs_close_class_device(class_dev);
+ udev_cleanup_device(&udev);