]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
dm: blk: Add functions to select a hardware partition
authorSimon Glass <sjg@chromium.org>
Sun, 1 May 2016 19:52:30 +0000 (13:52 -0600)
committerSimon Glass <sjg@chromium.org>
Tue, 17 May 2016 15:54:43 +0000 (09:54 -0600)
The block device uclass does not currently support selecting a particular
hardware partition but this is needed for MMC. Add it so that the blk API
can support MMC properly.

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

index a37239ee504c7ecf53d7a3b0b1b503bcac866564..6ba1026f5818efc61f69182112a79fd60d75fa1a 100644 (file)
@@ -165,6 +165,18 @@ static int get_desc(enum if_type if_type, int devnum, struct blk_desc **descp)
        return found_more ? -ENOENT : -ENODEV;
 }
 
+int blk_select_hwpart_devnum(enum if_type if_type, int devnum, int hwpart)
+{
+       struct udevice *dev;
+       int ret;
+
+       ret = blk_get_device(if_type, devnum, &dev);
+       if (ret)
+               return ret;
+
+       return blk_select_hwpart(dev, hwpart);
+}
+
 int blk_list_part(enum if_type if_type)
 {
        struct blk_desc *desc;
@@ -291,6 +303,23 @@ ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start,
        return blk_dwrite(desc, start, blkcnt, buffer);
 }
 
+int blk_select_hwpart(struct udevice *dev, int hwpart)
+{
+       const struct blk_ops *ops = blk_get_ops(dev);
+
+       if (!ops)
+               return -ENOSYS;
+       if (!ops->select_hwpart)
+               return 0;
+
+       return ops->select_hwpart(dev, hwpart);
+}
+
+int blk_dselect_hwpart(struct blk_desc *desc, int hwpart)
+{
+       return blk_select_hwpart(desc->bdev, hwpart);
+}
+
 int blk_first_device(int if_type, struct udevice **devp)
 {
        struct blk_desc *desc;
index 82b2c1a70686439bd2ca6765620c2b98a3e76886..3fa373e208b932577e7eb6ca6b6851aff9998f9b 100644 (file)
@@ -211,6 +211,25 @@ struct blk_ops {
         */
        unsigned long (*erase)(struct udevice *dev, lbaint_t start,
                               lbaint_t blkcnt);
+
+       /**
+        * select_hwpart() - select a particular hardware partition
+        *
+        * Some devices (e.g. MMC) can support partitioning at the hardware
+        * level. This is quite separate from the normal idea of
+        * software-based partitions. MMC hardware partitions must be
+        * explicitly selected. Once selected only the region of the device
+        * covered by that partition is accessible.
+        *
+        * The MMC standard provides for two boot partitions (numbered 1 and 2),
+        * rpmb (3), and up to 4 addition general-purpose partitions (4-7).
+        *
+        * @desc:       Block device to update
+        * @hwpart:     Hardware partition number to select. 0 means the raw
+        *              device, 1 is the first partition, 2 is the second, etc.
+        * @return 0 if OK, -ve on error
+        */
+       int (*select_hwpart)(struct udevice *dev, int hwpart);
 };
 
 #define blk_get_ops(dev)       ((struct blk_ops *)(dev)->driver->ops)
@@ -329,6 +348,17 @@ int blk_unbind_all(int if_type);
  */
 int blk_find_max_devnum(enum if_type if_type);
 
+/**
+ * blk_select_hwpart() - select a hardware partition
+ *
+ * Select a hardware partition if the device supports it (typically MMC does)
+ *
+ * @dev:       Device to update
+ * @hwpart:    Partition number to select
+ * @return 0 if OK, -ve on error
+ */
+int blk_select_hwpart(struct udevice *dev, int hwpart);
+
 #else
 #include <errno.h>
 /*