]> git.baikalelectronics.ru Git - uboot.git/commitdiff
dm: mmc: Use bootdev_setup_sibling_blk()
authorSimon Glass <sjg@chromium.org>
Tue, 17 Jan 2023 17:47:25 +0000 (10:47 -0700)
committerTom Rini <trini@konsulko.com>
Mon, 23 Jan 2023 23:11:39 +0000 (18:11 -0500)
At present MMC uses the bootdev_setup_for_dev() function to set up the
bootdev. This is because MMC only has one block-device child, so does not
need to worry about naming of the bootdev.

However this inconsistency with other bootdevs that use block devices is a
bit annoying. The only real reason for it is to have a name like
'mmc0.bootdev' instead of 'mmc0.blk.bootdev'.

Update bootdev_setup_sibling_blk() to drop '.blk' from the name where it
appears, thus removing the only reason to use the bootdev_setup_for_dev().
Switch MMC over to the subling function.

Signed-off-by: Simon Glass <sjg@chromium.org>
boot/bootdev-uclass.c
drivers/mmc/mmc-uclass.c
include/bootdev.h

index cffa01824c0ddb4d61676eb39c4d6544a1e54bdb..97f75cba49da1db29481aa734e50f393b34822e8 100644 (file)
@@ -234,13 +234,27 @@ int bootdev_setup_for_dev(struct udevice *parent, const char *drv_name)
        return 0;
 }
 
+static int bootdev_get_suffix_start(struct udevice *dev, const char *suffix)
+{
+       int len, slen;
+
+       len = strlen(dev->name);
+       slen = strlen(suffix);
+       if (len > slen && !strcmp(suffix, dev->name + len - slen))
+               return len - slen;
+
+       return len;
+}
+
 int bootdev_setup_sibling_blk(struct udevice *blk, const char *drv_name)
 {
        struct udevice *parent, *dev;
        char dev_name[50];
-       int ret;
+       int ret, len;
 
-       snprintf(dev_name, sizeof(dev_name), "%s.%s", blk->name, "bootdev");
+       len = bootdev_get_suffix_start(blk, ".blk");
+       snprintf(dev_name, sizeof(dev_name), "%.*s.%s", len, blk->name,
+                "bootdev");
 
        parent = dev_get_parent(blk);
        ret = device_find_child_by_name(parent, dev_name, &dev);
@@ -271,20 +285,22 @@ int bootdev_get_sibling_blk(struct udevice *dev, struct udevice **blkp)
        struct udevice *parent = dev_get_parent(dev);
        struct udevice *blk;
        int ret, len;
-       char *p;
 
        if (device_get_uclass_id(dev) != UCLASS_BOOTDEV)
                return -EINVAL;
 
        /* This should always work if bootdev_setup_sibling_blk() was used */
-       p = strstr(dev->name, ".bootdev");
-       if (!p)
-               return log_msg_ret("str", -EINVAL);
-
-       len = p - dev->name;
+       len = bootdev_get_suffix_start(dev, ".bootdev");
        ret = device_find_child_by_namelen(parent, dev->name, len, &blk);
-       if (ret)
-               return log_msg_ret("find", ret);
+       if (ret) {
+               char dev_name[50];
+
+               snprintf(dev_name, sizeof(dev_name), "%.*s.blk", len,
+                        dev->name);
+               ret = device_find_child_by_name(parent, dev_name, &blk);
+               if (ret)
+                       return log_msg_ret("find", ret);
+       }
        *blkp = blk;
 
        return 0;
@@ -295,13 +311,15 @@ static int bootdev_get_from_blk(struct udevice *blk, struct udevice **bootdevp)
        struct udevice *parent = dev_get_parent(blk);
        struct udevice *bootdev;
        char dev_name[50];
-       int ret;
+       int ret, len;
 
        if (device_get_uclass_id(blk) != UCLASS_BLK)
                return -EINVAL;
 
        /* This should always work if bootdev_setup_sibling_blk() was used */
-       snprintf(dev_name, sizeof(dev_name), "%s.%s", blk->name, "bootdev");
+       len = bootdev_get_suffix_start(blk, ".blk");
+       snprintf(dev_name, sizeof(dev_name), "%.*s.%s", len, blk->name,
+                "bootdev");
        ret = device_find_child_by_name(parent, dev_name, &bootdev);
        if (ret)
                return log_msg_ret("find", ret);
index 759a6b728c8eba5c85f513c123dd5747b3c90545..01d9b0201f2cf90a26361c7c1f3aec4579662279 100644 (file)
@@ -421,7 +421,7 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
        mmc->cfg = cfg;
        mmc->priv = dev;
 
-       ret = bootdev_setup_for_dev(dev, "mmc_bootdev");
+       ret = bootdev_setup_sibling_blk(bdev, "mmc_bootdev");
        if (ret)
                return log_msg_ret("bootdev", ret);
 
index 9fc219839fe0f8d13cec8aded77b5de41df06ca1..d0ca51c6d5e022f024db4e109c68df1a6d22e80e 100644 (file)
@@ -204,7 +204,10 @@ int bootdev_setup_iter_order(struct bootflow_iter *iter, struct udevice **devp);
 
 #if CONFIG_IS_ENABLED(BOOTSTD)
 /**
- * bootdev_setup_for_dev() - Bind a new bootdev device
+ * bootdev_setup_for_dev() - Bind a new bootdev device (deprecated)
+ *
+ * Please use bootdev_setup_sibling_blk() instead since it supports multiple
+ * (child) block devices for each media device.
  *
  * Creates a bootdev device as a child of @parent. This should be called from
  * the driver's bind() method or its uclass' post_bind() method.