+static int import_program_into_env(struct udevice *udev, const char *program)
+{
+ char result[1024];
+ size_t reslen;
+
+ if (run_program(program, udev->dev->subsystem, result, sizeof(result), &reslen, (udev_log_priority >= LOG_INFO)) != 0)
+ return -1;
+ return import_keys_into_env(udev, result, reslen);
+}
+
+static int import_parent_into_env(struct udevice *udev, const char *filter)
+{
+ struct sysfs_device *dev_parent;
+ int rc = -1;
+
+ dev_parent = sysfs_device_get_parent(udev->dev);
+ if (dev_parent != NULL) {
+ struct udevice *udev_parent;
+ struct name_entry *name_loop;
+
+ dbg("found parent '%s', get the node name", dev_parent->devpath);
+ udev_parent = udev_device_init(NULL);
+ if (udev_parent == NULL)
+ return -1;
+ /* import the udev_db of the parent */
+ if (udev_db_get_device(udev_parent, dev_parent->devpath) == 0) {
+ dbg("import stored parent env '%s'", udev_parent->name);
+ list_for_each_entry(name_loop, &udev_parent->env_list, node) {
+ char name[NAME_SIZE];
+ char *pos;
+
+ strlcpy(name, name_loop->name, sizeof(name));
+ pos = strchr(name, '=');
+ if (pos) {
+ pos[0] = '\0';
+ pos++;
+ if (fnmatch(filter, name, 0) == 0) {
+ dbg("import key '%s'", name_loop->name);
+ name_list_add(&udev->env_list, name_loop->name, 0);
+ setenv(name, pos, 1);
+ } else
+ dbg("skip key '%s'", name_loop->name);
+ }
+ }
+ rc = 0;
+ } else
+ dbg("parent not found in database");
+ udev_device_cleanup(udev_parent);
+ }
+
+ return rc;
+}
+
+#define WAIT_LOOP_PER_SECOND 50
+static int wait_for_sysfs(struct udevice *udev, const char *file, int timeout)
+{
+ char devicepath[PATH_SIZE];
+ char filepath[PATH_SIZE];
+ struct stat stats;
+ int loop = timeout * WAIT_LOOP_PER_SECOND;
+
+ strlcpy(devicepath, sysfs_path, sizeof(devicepath));
+ strlcat(devicepath, udev->dev->devpath, sizeof(devicepath));
+ strlcpy(filepath, devicepath, sizeof(filepath));
+ strlcat(filepath, "/", sizeof(filepath));
+ strlcat(filepath, file, sizeof(filepath));
+
+ dbg("will wait %i sec for '%s'", timeout, filepath);
+ while (--loop) {
+ /* lookup file */
+ if (stat(filepath, &stats) == 0) {
+ info("file '%s' appeared after %i loops", filepath, (timeout * WAIT_LOOP_PER_SECOND) - loop-1);
+ return 0;
+ }
+ /* make sure, the device did not disappear in the meantime */
+ if (stat(devicepath, &stats) != 0) {
+ info("device disappeared while waiting for '%s'", filepath);
+ return -2;
+ }
+ info("wait for '%s' for %i mseconds", filepath, 1000 / WAIT_LOOP_PER_SECOND);
+ usleep(1000 * 1000 / WAIT_LOOP_PER_SECOND);
+ }
+ err("waiting for '%s' failed", filepath);
+ return -1;
+}
+
+void udev_rules_apply_format(struct udevice *udev, char *string, size_t maxsize)