* [PATCH 1/8] commands: detect: use device_detect_by_name
2015-06-26 7:30 ubi: Make attaching UBI more convenient Sascha Hauer
@ 2015-06-26 7:31 ` Sascha Hauer
2015-06-26 7:31 ` [PATCH 2/8] driver: detect: detect parent devices aswell Sascha Hauer
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2015-06-26 7:31 UTC (permalink / raw)
To: Barebox List
Instead of looking up the device ourselves let device_detect_by_name
do the work.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/detect.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/commands/detect.c b/commands/detect.c
index d8e0afc..1586a6f 100644
--- a/commands/detect.c
+++ b/commands/detect.c
@@ -68,10 +68,7 @@ static int do_detect(int argc, char *argv[])
return COMMAND_ERROR_USAGE;
for (i = optind; i < argc; i++) {
- dev = get_device_by_name(argv[i]);
- if (!dev)
- return -ENODEV;
- ret = device_detect(dev);
+ ret = device_detect_by_name(argv[i]);
if (ret && option_error)
return ret;
}
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/8] driver: detect: detect parent devices aswell
2015-06-26 7:30 ubi: Make attaching UBI more convenient Sascha Hauer
2015-06-26 7:31 ` [PATCH 1/8] commands: detect: use device_detect_by_name Sascha Hauer
@ 2015-06-26 7:31 ` Sascha Hauer
2015-06-26 7:31 ` [PATCH 3/8] blspec: Use device_detect_by_name Sascha Hauer
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2015-06-26 7:31 UTC (permalink / raw)
To: Barebox List
Let device_detect_by_name detect parent devices aswell. We
separate the devname strings by colons and call device_detect()
for each component. This makes it possible for example to
detect nand0.root.ubi.root
With the above detect will be called for nand0, nand0.root, nand0.root.ubi
and nand0.root.ubi.root. The nand0.root detection step will detect the
UBI volume and attach it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/base/driver.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 24cb5bc..338bea1 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -113,14 +113,29 @@ int device_detect(struct device_d *dev)
return dev->detect(dev);
}
-int device_detect_by_name(const char *devname)
+int device_detect_by_name(const char *__devname)
{
- struct device_d *dev = get_device_by_name(devname);
+ char *devname = xstrdup(__devname);
+ char *str = devname;
+ struct device_d *dev;
+ int ret = -ENODEV;
+
+ while (1) {
+ strsep(&str, ".");
+
+ dev = get_device_by_name(devname);
+ if (dev)
+ ret = device_detect(dev);
- if (!dev)
- return -ENODEV;
+ if (!str)
+ break;
+ else
+ *(str - 1) = '.';
+ }
- return device_detect(dev);
+ free(devname);
+
+ return ret;
}
static int match(struct driver_d *drv, struct device_d *dev)
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 3/8] blspec: Use device_detect_by_name
2015-06-26 7:30 ubi: Make attaching UBI more convenient Sascha Hauer
2015-06-26 7:31 ` [PATCH 1/8] commands: detect: use device_detect_by_name Sascha Hauer
2015-06-26 7:31 ` [PATCH 2/8] driver: detect: detect parent devices aswell Sascha Hauer
@ 2015-06-26 7:31 ` Sascha Hauer
2015-06-26 7:31 ` [PATCH 4/8] ubi: Use preditable device names Sascha Hauer
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2015-06-26 7:31 UTC (permalink / raw)
To: Barebox List
device_detect_by_name will automatically separate by colons now,
we no longer have to do this in the blspec code.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/blspec.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/common/blspec.c b/common/blspec.c
index 3506388..2429560 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -575,17 +575,10 @@ int blspec_scan_devicename(struct blspec *blspec, const char *devname)
{
struct device_d *dev;
struct cdev *cdev;
- const char *colon;
pr_debug("%s: %s\n", __func__, devname);
- colon = strchr(devname, '.');
- if (colon) {
- char *name = xstrdup(devname);
- *strchr(name, '.') = 0;
- device_detect_by_name(name);
- free(name);
- }
+ device_detect_by_name(devname);
cdev = cdev_by_name(devname);
if (cdev) {
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 4/8] ubi: Use preditable device names
2015-06-26 7:30 ubi: Make attaching UBI more convenient Sascha Hauer
` (2 preceding siblings ...)
2015-06-26 7:31 ` [PATCH 3/8] blspec: Use device_detect_by_name Sascha Hauer
@ 2015-06-26 7:31 ` Sascha Hauer
2015-06-26 7:31 ` [PATCH 5/8] mtd: detect ubi devices automatically Sascha Hauer
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2015-06-26 7:31 UTC (permalink / raw)
To: Barebox List
Instead of naming all ubi devices and cdev names ubi<num> append
'.ubi' to the original mtd name. This makes ubi device and cdev
names predictable. With this ubi0 becomes nand0.root.ubi. Also
do the same for volume names, so ubi0.root becomes nand0.root.ubi.root.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/ubi/build.c | 7 ++-----
drivers/mtd/ubi/cdev.c | 4 ++--
2 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index b02880e..1074feb 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -155,8 +155,8 @@ static int uif_init(struct ubi_device *ubi, int *ref)
*ref = 0;
sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num);
- sprintf(ubi->dev.name, "ubi");
- ubi->dev.id = DEVICE_ID_DYNAMIC;
+ sprintf(ubi->dev.name, "%s.ubi", ubi->mtd->cdev.name);
+ ubi->dev.id = DEVICE_ID_SINGLE;
ubi->dev.parent = &ubi->mtd->class_dev;
err = register_device(&ubi->dev);
@@ -596,9 +596,6 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
#else
ubi->fm_disabled = 1;
#endif
-
- ubi_msg("attaching mtd%d to ubi%d", mtd->index, ubi_num);
-
err = io_init(ubi, max_beb_per1024);
if (err)
goto out_free;
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 90d5b2d..fe71a8d 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -176,7 +176,7 @@ int ubi_volume_cdev_add(struct ubi_device *ubi, struct ubi_volume *vol)
priv->ubi = ubi;
cdev->ops = &ubi_volume_fops;
- cdev->name = asprintf("ubi%d.%s", ubi->ubi_num, vol->name);
+ cdev->name = asprintf("%s.%s", ubi->cdev.name, vol->name);
cdev->priv = priv;
cdev->size = vol->used_bytes;
cdev->dev = &vol->dev;
@@ -239,7 +239,7 @@ int ubi_cdev_add(struct ubi_device *ubi)
int ret;
cdev->ops = &ubi_fops;
- cdev->name = asprintf("ubi%d", ubi->ubi_num);
+ cdev->name = asprintf("%s.ubi", ubi->mtd->cdev.name);
cdev->priv = ubi;
cdev->size = 0;
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 5/8] mtd: detect ubi devices automatically
2015-06-26 7:30 ubi: Make attaching UBI more convenient Sascha Hauer
` (3 preceding siblings ...)
2015-06-26 7:31 ` [PATCH 4/8] ubi: Use preditable device names Sascha Hauer
@ 2015-06-26 7:31 ` Sascha Hauer
2015-06-26 7:31 ` [PATCH 6/8] ubi: Lower 'already attached' message to debug level Sascha Hauer
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2015-06-26 7:31 UTC (permalink / raw)
To: Barebox List
Hook UBI attachment into the mtd class devices detect function. This
makes it possible to attach ubi devices with 'detect nand0.root'.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/core.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 681dc93..8a07086 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -18,7 +18,9 @@
#include <common.h>
#include <linux/mtd/nand.h>
#include <linux/mtd/mtd.h>
+#include <mtd/ubi-user.h>
#include <cmdlinepart.h>
+#include <filetype.h>
#include <init.h>
#include <xfuncs.h>
#include <driver.h>
@@ -542,6 +544,41 @@ static int of_mtd_fixup(struct device_node *root, void *ctx)
return 0;
}
+static int mtd_detect(struct device_d *dev)
+{
+ struct mtd_info *mtd = container_of(dev, struct mtd_info, class_dev);
+ int bufsize = 512;
+ void *buf;
+ int ret;
+ enum filetype filetype;
+ size_t retlen;
+
+ /*
+ * Do not try to attach an UBI device if this device has partitions
+ * as it's not a good idea to attach UBI on a raw device when the
+ * real UBI only spans the first partition.
+ */
+ if (!list_empty(&mtd->partitions))
+ return -EBUSY;
+
+ buf = xmalloc(bufsize);
+
+ ret = mtd_read(mtd, 0, bufsize, &retlen, buf);
+ if (ret)
+ goto out;
+
+ filetype = file_detect_type(buf, bufsize);
+ if (filetype == filetype_ubi) {
+ ret = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO, 0, 20);
+ if (ret == -EEXIST)
+ ret = 0;
+ }
+out:
+ free(buf);
+
+ return ret;
+}
+
int add_mtd_device(struct mtd_info *mtd, char *devname, int device_id)
{
struct mtddev_hook *hook;
@@ -554,6 +591,9 @@ int add_mtd_device(struct mtd_info *mtd, char *devname, int device_id)
if (mtd->parent)
mtd->class_dev.parent = mtd->parent;
+ if (IS_ENABLED(CONFIG_MTD_UBI))
+ mtd->class_dev.detect = mtd_detect;
+
ret = register_device(&mtd->class_dev);
if (ret)
return ret;
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 6/8] ubi: Lower 'already attached' message to debug level
2015-06-26 7:30 ubi: Make attaching UBI more convenient Sascha Hauer
` (4 preceding siblings ...)
2015-06-26 7:31 ` [PATCH 5/8] mtd: detect ubi devices automatically Sascha Hauer
@ 2015-06-26 7:31 ` Sascha Hauer
2015-06-26 7:31 ` [PATCH 7/8] commands: mount: detect the device to be mounted Sascha Hauer
2015-06-26 7:31 ` [PATCH 8/8] ubi: Update documentation Sascha Hauer
7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2015-06-26 7:31 UTC (permalink / raw)
To: Barebox List
The caller will show a message, no need to do this in UBI. This
is for the case when mtd_detect calls ubi_attach_mtd_dev. mtd_detect
does not know whether this is already attached and it's not an error.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/ubi/build.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 1074feb..7970226 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -518,7 +518,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
for (i = 0; i < UBI_MAX_DEVICES; i++) {
ubi = ubi_devices[i];
if (ubi && mtd == ubi->mtd) {
- ubi_err("mtd%d is already attached to ubi%d",
+ ubi_debug("mtd%d is already attached to ubi%d",
mtd->index, i);
return -EEXIST;
}
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 7/8] commands: mount: detect the device to be mounted
2015-06-26 7:30 ubi: Make attaching UBI more convenient Sascha Hauer
` (5 preceding siblings ...)
2015-06-26 7:31 ` [PATCH 6/8] ubi: Lower 'already attached' message to debug level Sascha Hauer
@ 2015-06-26 7:31 ` Sascha Hauer
2015-06-26 7:31 ` [PATCH 8/8] ubi: Update documentation Sascha Hauer
7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2015-06-26 7:31 UTC (permalink / raw)
To: Barebox List
Before mounting a device try to detect it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/mount.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/commands/mount.c b/commands/mount.c
index 939e9bc..aa769d4 100644
--- a/commands/mount.c
+++ b/commands/mount.c
@@ -79,6 +79,8 @@ static int do_mount(int argc, char *argv[])
if (!strncmp(devstr, "/dev/", 5))
devstr += 5;
+ device_detect_by_name(devstr);
+
cdev = cdev_by_name(devstr);
if (!cdev)
return -ENOENT;
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 8/8] ubi: Update documentation
2015-06-26 7:30 ubi: Make attaching UBI more convenient Sascha Hauer
` (6 preceding siblings ...)
2015-06-26 7:31 ` [PATCH 7/8] commands: mount: detect the device to be mounted Sascha Hauer
@ 2015-06-26 7:31 ` Sascha Hauer
7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2015-06-26 7:31 UTC (permalink / raw)
To: Barebox List
The previous patches changed the UBI naming and made automounting
UBIFS easier. Update the documentation accordingly.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
Documentation/user/ubi.rst | 44 +++++++++++++++-----------------------------
1 file changed, 15 insertions(+), 29 deletions(-)
diff --git a/Documentation/user/ubi.rst b/Documentation/user/ubi.rst
index a187680..c300c0f 100644
--- a/Documentation/user/ubi.rst
+++ b/Documentation/user/ubi.rst
@@ -5,9 +5,6 @@ barebox has both UBI and UBIFS support. For handling UBI barebox has commands si
the Linux commands :ref:`command_ubiformat`, :ref:`command_ubiattach`, :ref:`command_ubidetach`,
:ref:`command_ubimkvol` and :ref:`command_ubirmvol`.
-The following examples assume we work on the first UBI device. Replace ``ubi0`` with
-the appropriate number when you have multiple UBI devices.
-
The first step for preparing a pristine Flash for UBI is to :ref:`command_ubiformat` the
device:
@@ -28,17 +25,17 @@ After a device has been formatted it can be attached with :ref:`command_ubiattac
ubiattach /dev/nand0.root
-This will create the controlling node ``/dev/ubi0`` and also register all volumes present
-on the device as ``/dev/ubi0.<volname>``. When freshly formatted there won't be any volumes
-present. A volume can be created with:
+This will create the controlling node ``/dev/nand0.root.ubi`` and also register all volumes
+present on the device as ``/dev/nand0.root.ubi.<volname>``. When freshly formatted there won't
+be any volumes present. A volume can be created with:
.. code-block:: sh
- ubimkvol /dev/ubi0 root 0
+ ubimkvol /dev/nand0.root.ubi root 0
The first parameter is the controlling node. The second parameter is the name of the volume.
-In this case the volume can be found under ``/dev/ubi.root``. The third parameter contains
-the size. A size of zero means that all available space shall be used.
+In this case the volume can be found under ``/dev/dev/nand0.root.ubi.root``. The third
+parameter contains the size. A size of zero means that all available space shall be used.
The next step is to write a UBIFS image to the volume. The image must be created on a host using
the ``mkfs.ubifs`` command. ``mkfs.ubifs`` requires several arguments for describing the
@@ -46,7 +43,7 @@ flash layout. Values for these arguments can be retrieved from a ``devinfo ubi``
.. code-block:: sh
- barebox@Phytec pcm970:/ devinfo ubi0
+ barebox@Phytec pcm970:/ devinfo nand0.root.ubi
Parameters:
peb_size: 16384
leb_size: 15360
@@ -76,38 +73,27 @@ The UBIFS image can be transferred to the board for example with TFTP:
.. code-block:: sh
- cp /mnt/tftp/root.ubifs /dev/ubi0.root
+ cp /mnt/tftp/root.ubifs /dev/nand0.root.ubi.root
Finally it can be mounted using the :ref:`command_mount` command:
.. code-block:: sh
- mkdir -p /mnt/ubi
- mount -t ubifs /dev/ubi0.root /mnt/ubi
+ mount /dev/nand0.root.ubi.root
+The default mount path when the mount point is skipped is ``/mnt/<devname>``,
+so in this example it will be ``/mnt/nand0.root.ubi.root``.
The second time the UBIFS is mounted the above can be simplified to:
.. code-block:: sh
ubiattach /dev/nand0.root
- mount -t ubifs /dev/ubi0.root /mnt/ubi
+ mount /dev/nand0.root.ubi.root
Mounting the UBIFS can also be made transparent with the automount command.
-With this helper script in ``/env/bin/automount-ubi:``:
-
-.. code-block:: sh
-
- #!/bin/sh
-
- if [ ! -e /dev/ubi0 ]; then
- ubiattach /dev/nand0 || exit 1
- fi
-
- mount -t ubifs /dev/ubi0.root $automount_path
-
-
-The command ``automount -d /mnt/ubi/ '/env/bin/automount-ubi'`` will automatically
-attach the UBI device and mount the UBIFS image to ``/mnt/ubi`` whenever ``/mnt/ubi``
+The command ``automount -d /mnt/nand0.root.ubi.root 'mount nand0.root.ubi.root'``
+will automatically attach the UBI device and mount the UBIFS image to
+``/mnt/nand0.root.ubi.root`` whenever ``/mnt/nand0.root.ubi.root``
is first accessed. The automount command can be added to ``/env/init/automount`` to
execute it during startup.
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread