All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sysfs, device-tree: aid for debugging device tree boot problems
@ 2014-04-23  1:25 ` Frank Rowand
  0 siblings, 0 replies; 11+ messages in thread
From: Frank Rowand @ 2014-04-23  1:25 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Grant Likely, Rob Herring
  Cc: Rob Herring, Linux Kernel list, devicetree

Create some infrastructure to aid trouble shooting device tree related
boot issues.

Add a %driver_name file to each device tree node sysfs directory which has had
a driver bound to it.  This allows detecting device tree nodes which failed
to be bound to any driver.

Examples of using the %driver_name file (note that /proc/device-tree is a
link to the base of the device tree sysfs tree):


  1) To find list of device tree nodes with no driver:

  # A few false positives may be reported.  For example,
  #   node_full_path of "." is the board.
  #
  # output is: node_full_path compatible_string
  #
  cd /proc/device-tree
  for k in `find . -type d`; do
     if [[ -f ${k}/compatible && ! -f ${k}/%driver_name ]] ; then
        if [[ "`cat ${k}/compatible`" != "simple-bus" ]] ; then
           echo `echo ${k} | sed -e 's|./||'` `cat ${k}/compatible`
        fi
     fi
  done | sort


  2) To find list of device tree nodes with a bound driver:

  # output is:  node_full_path driver_name
  #
  cd /proc/device-tree
  for k in `find . -name %driver_name` ; do
     echo `echo ${k} | sed -e 's|./||' -e 's|/%driver_name$||'` `cat ${k}`
  done | sort


  3) To find list of device tree nodes with a bound driver:

  # output is:  driver_name node_full_path
  #
  cd /proc/device-tree
  for k in `find . -name %driver_name` ; do
     echo `cat ${k}` `echo ${k} | sed -e 's|./||' -e 's|/%driver_name$||'`
  done | sort


Signed-off-by: Frank Rowand <frank.rowand@sonymobile.com>
---

 Documentation/ABI/testing/sysfs-firmware-ofw |   17 +++++++-
 drivers/base/dd.c                            |    5 ++
 drivers/of/base.c                            |   55 +++++++++++++++++++++++++++
 include/linux/of.h                           |    9 ++++
 4 files changed, 85 insertions(+), 1 deletion(-)

Index: b/drivers/base/dd.c
===================================================================
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -25,6 +25,7 @@
 #include <linux/kthread.h>
 #include <linux/wait.h>
 #include <linux/async.h>
+#include <linux/of.h>
 #include <linux/pm_runtime.h>
 #include <linux/pinctrl/devinfo.h>
 
@@ -194,6 +195,8 @@ static void driver_bound(struct device *
 
 	klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices);
 
+	of_notify_driver_bound(dev);
+
 	/*
 	 * Make sure the device is no longer in one of the deferred lists and
 	 * kick off retrying all pending devices
@@ -505,6 +508,8 @@ static void __device_release_driver(stru
 
 		pm_runtime_put_sync(dev);
 
+		of_notify_driver_released(dev);
+
 		if (dev->bus && dev->bus->remove)
 			dev->bus->remove(dev);
 		else if (drv->remove)
Index: b/drivers/of/base.c
===================================================================
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -19,6 +19,7 @@
  */
 #include <linux/ctype.h>
 #include <linux/cpu.h>
+#include <linux/kallsyms.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_graph.h>
@@ -168,7 +169,61 @@ static void of_node_release(struct kobje
 }
 #endif /* CONFIG_OF_DYNAMIC */
 
+static ssize_t driver_show(struct device *dev, struct device_attribute *attr,
+			   char *buf)
+{
+	return scnprintf(buf, PAGE_SIZE, "%s\n", dev->driver->name);
+}
+
+static const struct device_attribute of_driver_attr =
+	__ATTR(%driver_name, S_IRUGO, driver_show, NULL);
+
+void of_notify_driver_bound(struct device *dev)
+{
+	int err;
+
+	if (dev->of_node) {
+		dev->of_node->bound_dev = dev;
+		err = sysfs_create_file(&dev->of_node->kobj, &of_driver_attr.attr);
+	}
+
+}
+
+void of_notify_driver_released(struct device *dev)
+{
+	if (dev->of_node) {
+		sysfs_remove_file(&dev->of_node->kobj, &of_driver_attr.attr);
+		dev->of_node->bound_dev = NULL;
+	}
+}
+
+#define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)
+
+static ssize_t of_node_attr_show(struct kobject *kobj, struct attribute *attr,
+				 char *buf)
+{
+	struct device_attribute *dev_attr = to_dev_attr(attr);
+	struct device_node *np = container_of(kobj, struct device_node, kobj);
+	struct device *dev = np->bound_dev;
+
+	ssize_t ret = -EIO;
+
+	if (dev_attr->show)
+		ret = dev_attr->show(dev, dev_attr, buf);
+	if (ret >= (ssize_t)PAGE_SIZE) {
+		print_symbol("dev_attr_show: %s returned bad count\n",
+			(unsigned long)dev_attr->show);
+	}
+	return ret;
+}
+
+
+static const struct sysfs_ops of_node_sysfs_ops = {
+	.show	= of_node_attr_show,
+};
+
 struct kobj_type of_node_ktype = {
+	.sysfs_ops = &of_node_sysfs_ops,
 	.release = of_node_release,
 };
 
Index: b/include/linux/of.h
===================================================================
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -60,6 +60,7 @@ struct device_node {
 	struct	kobject kobj;
 	unsigned long _flags;
 	void	*data;
+	struct device *bound_dev;
 #if defined(CONFIG_SPARC)
 	const char *path_component_name;
 	unsigned int unique_id;
@@ -347,6 +348,9 @@ const char *of_prop_next_string(struct p
 
 int of_device_is_stdout_path(struct device_node *dn);
 
+void of_notify_driver_bound(struct device *dev);
+void of_notify_driver_released(struct device *dev);
+
 #else /* CONFIG_OF */
 
 static inline const char* of_node_full_name(struct device_node *np)
@@ -571,6 +575,11 @@ static inline const char *of_prop_next_s
 
 #define of_match_ptr(_ptr)	NULL
 #define of_match_node(_matches, _node)	NULL
+
+void of_notify_driver_bound(struct device *dev) { }
+
+void of_notify_driver_released(struct device *dev) { }
+
 #endif /* CONFIG_OF */
 
 #if defined(CONFIG_OF) && defined(CONFIG_NUMA)
Index: b/Documentation/ABI/testing/sysfs-firmware-ofw
===================================================================
--- a/Documentation/ABI/testing/sysfs-firmware-ofw
+++ b/Documentation/ABI/testing/sysfs-firmware-ofw
@@ -25,4 +25,19 @@ Description:
 		directory name is the resolved path component name (node
 		name plus address). Properties are represented as files
 		in the directory. The contents of each file is the exact
-		binary data from the device tree.
+		binary data from the device tree.  Files that are exceptions
+		to this description will be described separately in this file.
+
+What:		/sys/firmware/devicetree/.../%driver_name
+Date:		April 2014
+KernelVersion:  3.15
+Contact:	Frank Rowand <frank.rowand@sonymobile.com>
+Description:
+		This file does not represent a device tree property.  The file
+		will exist only if a driver is bound to the device tree node.
+		Reading from this file returns the name of the driver.
+
+		The apparently bizarre choice of prefixing the file name with
+		"%" is to avoid any possible conflict with a valid device tree
+		property name.  ePAPR version 1.1 does not allow a property
+		name to contain the character "%".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] sysfs, device-tree: aid for debugging device tree boot problems
@ 2014-04-23  1:25 ` Frank Rowand
  0 siblings, 0 replies; 11+ messages in thread
From: Frank Rowand @ 2014-04-23  1:25 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Grant Likely
  Cc: Rob Herring, Linux Kernel list, devicetree

Create some infrastructure to aid trouble shooting device tree related
boot issues.

Add a %driver_name file to each device tree node sysfs directory which has had
a driver bound to it.  This allows detecting device tree nodes which failed
to be bound to any driver.

Examples of using the %driver_name file (note that /proc/device-tree is a
link to the base of the device tree sysfs tree):


  1) To find list of device tree nodes with no driver:

  # A few false positives may be reported.  For example,
  #   node_full_path of "." is the board.
  #
  # output is: node_full_path compatible_string
  #
  cd /proc/device-tree
  for k in `find . -type d`; do
     if [[ -f ${k}/compatible && ! -f ${k}/%driver_name ]] ; then
        if [[ "`cat ${k}/compatible`" != "simple-bus" ]] ; then
           echo `echo ${k} | sed -e 's|./||'` `cat ${k}/compatible`
        fi
     fi
  done | sort


  2) To find list of device tree nodes with a bound driver:

  # output is:  node_full_path driver_name
  #
  cd /proc/device-tree
  for k in `find . -name %driver_name` ; do
     echo `echo ${k} | sed -e 's|./||' -e 's|/%driver_name$||'` `cat ${k}`
  done | sort


  3) To find list of device tree nodes with a bound driver:

  # output is:  driver_name node_full_path
  #
  cd /proc/device-tree
  for k in `find . -name %driver_name` ; do
     echo `cat ${k}` `echo ${k} | sed -e 's|./||' -e 's|/%driver_name$||'`
  done | sort


Signed-off-by: Frank Rowand <frank.rowand@sonymobile.com>
---

 Documentation/ABI/testing/sysfs-firmware-ofw |   17 +++++++-
 drivers/base/dd.c                            |    5 ++
 drivers/of/base.c                            |   55 +++++++++++++++++++++++++++
 include/linux/of.h                           |    9 ++++
 4 files changed, 85 insertions(+), 1 deletion(-)

Index: b/drivers/base/dd.c
===================================================================
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -25,6 +25,7 @@
 #include <linux/kthread.h>
 #include <linux/wait.h>
 #include <linux/async.h>
+#include <linux/of.h>
 #include <linux/pm_runtime.h>
 #include <linux/pinctrl/devinfo.h>
 
@@ -194,6 +195,8 @@ static void driver_bound(struct device *
 
 	klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices);
 
+	of_notify_driver_bound(dev);
+
 	/*
 	 * Make sure the device is no longer in one of the deferred lists and
 	 * kick off retrying all pending devices
@@ -505,6 +508,8 @@ static void __device_release_driver(stru
 
 		pm_runtime_put_sync(dev);
 
+		of_notify_driver_released(dev);
+
 		if (dev->bus && dev->bus->remove)
 			dev->bus->remove(dev);
 		else if (drv->remove)
Index: b/drivers/of/base.c
===================================================================
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -19,6 +19,7 @@
  */
 #include <linux/ctype.h>
 #include <linux/cpu.h>
+#include <linux/kallsyms.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_graph.h>
@@ -168,7 +169,61 @@ static void of_node_release(struct kobje
 }
 #endif /* CONFIG_OF_DYNAMIC */
 
+static ssize_t driver_show(struct device *dev, struct device_attribute *attr,
+			   char *buf)
+{
+	return scnprintf(buf, PAGE_SIZE, "%s\n", dev->driver->name);
+}
+
+static const struct device_attribute of_driver_attr =
+	__ATTR(%driver_name, S_IRUGO, driver_show, NULL);
+
+void of_notify_driver_bound(struct device *dev)
+{
+	int err;
+
+	if (dev->of_node) {
+		dev->of_node->bound_dev = dev;
+		err = sysfs_create_file(&dev->of_node->kobj, &of_driver_attr.attr);
+	}
+
+}
+
+void of_notify_driver_released(struct device *dev)
+{
+	if (dev->of_node) {
+		sysfs_remove_file(&dev->of_node->kobj, &of_driver_attr.attr);
+		dev->of_node->bound_dev = NULL;
+	}
+}
+
+#define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)
+
+static ssize_t of_node_attr_show(struct kobject *kobj, struct attribute *attr,
+				 char *buf)
+{
+	struct device_attribute *dev_attr = to_dev_attr(attr);
+	struct device_node *np = container_of(kobj, struct device_node, kobj);
+	struct device *dev = np->bound_dev;
+
+	ssize_t ret = -EIO;
+
+	if (dev_attr->show)
+		ret = dev_attr->show(dev, dev_attr, buf);
+	if (ret >= (ssize_t)PAGE_SIZE) {
+		print_symbol("dev_attr_show: %s returned bad count\n",
+			(unsigned long)dev_attr->show);
+	}
+	return ret;
+}
+
+
+static const struct sysfs_ops of_node_sysfs_ops = {
+	.show	= of_node_attr_show,
+};
+
 struct kobj_type of_node_ktype = {
+	.sysfs_ops = &of_node_sysfs_ops,
 	.release = of_node_release,
 };
 
Index: b/include/linux/of.h
===================================================================
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -60,6 +60,7 @@ struct device_node {
 	struct	kobject kobj;
 	unsigned long _flags;
 	void	*data;
+	struct device *bound_dev;
 #if defined(CONFIG_SPARC)
 	const char *path_component_name;
 	unsigned int unique_id;
@@ -347,6 +348,9 @@ const char *of_prop_next_string(struct p
 
 int of_device_is_stdout_path(struct device_node *dn);
 
+void of_notify_driver_bound(struct device *dev);
+void of_notify_driver_released(struct device *dev);
+
 #else /* CONFIG_OF */
 
 static inline const char* of_node_full_name(struct device_node *np)
@@ -571,6 +575,11 @@ static inline const char *of_prop_next_s
 
 #define of_match_ptr(_ptr)	NULL
 #define of_match_node(_matches, _node)	NULL
+
+void of_notify_driver_bound(struct device *dev) { }
+
+void of_notify_driver_released(struct device *dev) { }
+
 #endif /* CONFIG_OF */
 
 #if defined(CONFIG_OF) && defined(CONFIG_NUMA)
Index: b/Documentation/ABI/testing/sysfs-firmware-ofw
===================================================================
--- a/Documentation/ABI/testing/sysfs-firmware-ofw
+++ b/Documentation/ABI/testing/sysfs-firmware-ofw
@@ -25,4 +25,19 @@ Description:
 		directory name is the resolved path component name (node
 		name plus address). Properties are represented as files
 		in the directory. The contents of each file is the exact
-		binary data from the device tree.
+		binary data from the device tree.  Files that are exceptions
+		to this description will be described separately in this file.
+
+What:		/sys/firmware/devicetree/.../%driver_name
+Date:		April 2014
+KernelVersion:  3.15
+Contact:	Frank Rowand <frank.rowand@sonymobile.com>
+Description:
+		This file does not represent a device tree property.  The file
+		will exist only if a driver is bound to the device tree node.
+		Reading from this file returns the name of the driver.
+
+		The apparently bizarre choice of prefixing the file name with
+		"%" is to avoid any possible conflict with a valid device tree
+		property name.  ePAPR version 1.1 does not allow a property
+		name to contain the character "%".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] sysfs, device-tree: aid for debugging device tree boot problems
@ 2014-04-23  3:20   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 11+ messages in thread
From: Greg Kroah-Hartman @ 2014-04-23  3:20 UTC (permalink / raw)
  To: Frank Rowand; +Cc: Grant Likely, Rob Herring, Linux Kernel list, devicetree

On Tue, Apr 22, 2014 at 06:25:25PM -0700, Frank Rowand wrote:
> Create some infrastructure to aid trouble shooting device tree related
> boot issues.
> 
> Add a %driver_name file to each device tree node sysfs directory which has had
> a driver bound to it.  This allows detecting device tree nodes which failed
> to be bound to any driver.

Why is this needed, shouldn't there already be a "driver" symlink in
sysfs for these devices when a driver binds to them?  The rest of the
driver model works that way, why is of devices any different?

> Examples of using the %driver_name file (note that /proc/device-tree is a
> link to the base of the device tree sysfs tree):
> 
> 
>   1) To find list of device tree nodes with no driver:
> 
>   # A few false positives may be reported.  For example,
>   #   node_full_path of "." is the board.
>   #
>   # output is: node_full_path compatible_string
>   #
>   cd /proc/device-tree
>   for k in `find . -type d`; do
>      if [[ -f ${k}/compatible && ! -f ${k}/%driver_name ]] ; then
>         if [[ "`cat ${k}/compatible`" != "simple-bus" ]] ; then
>            echo `echo ${k} | sed -e 's|./||'` `cat ${k}/compatible`
>         fi
>      fi
>   done | sort
> 
> 
>   2) To find list of device tree nodes with a bound driver:
> 
>   # output is:  node_full_path driver_name
>   #
>   cd /proc/device-tree
>   for k in `find . -name %driver_name` ; do
>      echo `echo ${k} | sed -e 's|./||' -e 's|/%driver_name$||'` `cat ${k}`
>   done | sort
> 
> 
>   3) To find list of device tree nodes with a bound driver:
> 
>   # output is:  driver_name node_full_path
>   #
>   cd /proc/device-tree
>   for k in `find . -name %driver_name` ; do
>      echo `cat ${k}` `echo ${k} | sed -e 's|./||' -e 's|/%driver_name$||'`
>   done | sort

If we take this patch, these examples should be somewhere in the
documentation to make it easy for others.

> Signed-off-by: Frank Rowand <frank.rowand@sonymobile.com>

Minor nit, your From: line doesn't match this signed-off-by: so
something has to change (or add a new From: line, like SubmittingPatches
decribes how to do.)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] sysfs, device-tree: aid for debugging device tree boot problems
@ 2014-04-23  3:20   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 11+ messages in thread
From: Greg Kroah-Hartman @ 2014-04-23  3:20 UTC (permalink / raw)
  To: Frank Rowand
  Cc: Grant Likely, Rob Herring, Linux Kernel list,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On Tue, Apr 22, 2014 at 06:25:25PM -0700, Frank Rowand wrote:
> Create some infrastructure to aid trouble shooting device tree related
> boot issues.
> 
> Add a %driver_name file to each device tree node sysfs directory which has had
> a driver bound to it.  This allows detecting device tree nodes which failed
> to be bound to any driver.

Why is this needed, shouldn't there already be a "driver" symlink in
sysfs for these devices when a driver binds to them?  The rest of the
driver model works that way, why is of devices any different?

> Examples of using the %driver_name file (note that /proc/device-tree is a
> link to the base of the device tree sysfs tree):
> 
> 
>   1) To find list of device tree nodes with no driver:
> 
>   # A few false positives may be reported.  For example,
>   #   node_full_path of "." is the board.
>   #
>   # output is: node_full_path compatible_string
>   #
>   cd /proc/device-tree
>   for k in `find . -type d`; do
>      if [[ -f ${k}/compatible && ! -f ${k}/%driver_name ]] ; then
>         if [[ "`cat ${k}/compatible`" != "simple-bus" ]] ; then
>            echo `echo ${k} | sed -e 's|./||'` `cat ${k}/compatible`
>         fi
>      fi
>   done | sort
> 
> 
>   2) To find list of device tree nodes with a bound driver:
> 
>   # output is:  node_full_path driver_name
>   #
>   cd /proc/device-tree
>   for k in `find . -name %driver_name` ; do
>      echo `echo ${k} | sed -e 's|./||' -e 's|/%driver_name$||'` `cat ${k}`
>   done | sort
> 
> 
>   3) To find list of device tree nodes with a bound driver:
> 
>   # output is:  driver_name node_full_path
>   #
>   cd /proc/device-tree
>   for k in `find . -name %driver_name` ; do
>      echo `cat ${k}` `echo ${k} | sed -e 's|./||' -e 's|/%driver_name$||'`
>   done | sort

If we take this patch, these examples should be somewhere in the
documentation to make it easy for others.

> Signed-off-by: Frank Rowand <frank.rowand-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>

Minor nit, your From: line doesn't match this signed-off-by: so
something has to change (or add a new From: line, like SubmittingPatches
decribes how to do.)

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] sysfs, device-tree: aid for debugging device tree boot problems
@ 2014-04-23 11:54     ` Grant Likely
  0 siblings, 0 replies; 11+ messages in thread
From: Grant Likely @ 2014-04-23 11:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Frank Rowand
  Cc: Rob Herring, Linux Kernel list, devicetree

On Tue, 22 Apr 2014 20:20:44 -0700, Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote:
> On Tue, Apr 22, 2014 at 06:25:25PM -0700, Frank Rowand wrote:
> > Create some infrastructure to aid trouble shooting device tree related
> > boot issues.
> > 
> > Add a %driver_name file to each device tree node sysfs directory which has had
> > a driver bound to it.  This allows detecting device tree nodes which failed
> > to be bound to any driver.
> 
> Why is this needed, shouldn't there already be a "driver" symlink in
> sysfs for these devices when a driver binds to them?  The rest of the
> driver model works that way, why is of devices any different?
> 

Because it hasn't been added yet! I only just committed the change to
convert device_nodes into kobjects in v3.14. The next step is to add
driver symlinks.

That said, the devicetree node is already exposed in the uevent for a
device. It should already be possible to find all device tree nodes that
don't have a device, or devices without a driver:

To get a list of all nodes:

find /proc/device-tree/ -type d | sed -e 's/\/proc\/device-tree//'

or a little more nuanced, only choosing nodes with a compatible property:

for k in `find /proc/device-tree/ -name compatible`; do
	echo $(dirname $k) | sed -e 's/\/proc\/device-tree//'
done | sort

It can get even more refined than that if need be.

To get a list of all nodes with a device that has been created:

for k in `find devices -name uevent`; do
	grep '^OF_FULLNAME' $k | sed -e 's/OF_FULLNAME=//'
done | sort

To get a list of all nodes with a device that has been bound to a driver:

for k in `find devices -name uevent`; do
	if [[ -d $(dirname $k)/driver ]]; then
		grep '^OF_FULLNAME' $k | sed -e 's/OF_FULLNAME=//'
	fi
done | sort


The suggestions you have below would be the anything in the first list
that isn't in the second or third:

bound=$(for k in `find /sys/devices -name uevent`; do
		if [[ -d $(dirname $k)/driver ]]; then
			grep '^OF_FULLNAME' $k | sed -e 's/OF_FULLNAME=//'
		fi
	done)

nodes=$(for k in `find /proc/device-tree/ -name compatible`; do
		echo $(dirname $k) | sed -e 's/\/proc\/device-tree//'
	done | sort)

for n in $nodes; do
	if ! echo $bound | grep -q "$n"; then
		echo $n $(cat /proc/device-tree/$n/compatible)
	fi
done



> > Examples of using the %driver_name file (note that /proc/device-tree is a
> > link to the base of the device tree sysfs tree):
> > 
> > 
> >   1) To find list of device tree nodes with no driver:
> > 
> >   # A few false positives may be reported.  For example,
> >   #   node_full_path of "." is the board.
> >   #
> >   # output is: node_full_path compatible_string
> >   #
> >   cd /proc/device-tree
> >   for k in `find . -type d`; do
> >      if [[ -f ${k}/compatible && ! -f ${k}/%driver_name ]] ; then
> >         if [[ "`cat ${k}/compatible`" != "simple-bus" ]] ; then
> >            echo `echo ${k} | sed -e 's|./||'` `cat ${k}/compatible`
> >         fi
> >      fi
> >   done | sort
> > 
> > 
> >   2) To find list of device tree nodes with a bound driver:
> > 
> >   # output is:  node_full_path driver_name
> >   #
> >   cd /proc/device-tree
> >   for k in `find . -name %driver_name` ; do
> >      echo `echo ${k} | sed -e 's|./||' -e 's|/%driver_name$||'` `cat ${k}`
> >   done | sort
> > 
> > 
> >   3) To find list of device tree nodes with a bound driver:
> > 
> >   # output is:  driver_name node_full_path
> >   #
> >   cd /proc/device-tree
> >   for k in `find . -name %driver_name` ; do
> >      echo `cat ${k}` `echo ${k} | sed -e 's|./||' -e 's|/%driver_name$||'`
> >   done | sort
> 
> If we take this patch, these examples should be somewhere in the
> documentation to make it easy for others.
> 
> > Signed-off-by: Frank Rowand <frank.rowand@sonymobile.com>
> 
> Minor nit, your From: line doesn't match this signed-off-by: so
> something has to change (or add a new From: line, like SubmittingPatches
> decribes how to do.)
> 
> thanks,
> 
> greg k-h


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] sysfs, device-tree: aid for debugging device tree boot problems
@ 2014-04-23 11:54     ` Grant Likely
  0 siblings, 0 replies; 11+ messages in thread
From: Grant Likely @ 2014-04-23 11:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Frank Rowand
  Cc: Rob Herring, Linux Kernel list, devicetree-u79uwXL29TY76Z2rM5mHXA

On Tue, 22 Apr 2014 20:20:44 -0700, Greg Kroah-Hartman <gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org> wrote:
> On Tue, Apr 22, 2014 at 06:25:25PM -0700, Frank Rowand wrote:
> > Create some infrastructure to aid trouble shooting device tree related
> > boot issues.
> > 
> > Add a %driver_name file to each device tree node sysfs directory which has had
> > a driver bound to it.  This allows detecting device tree nodes which failed
> > to be bound to any driver.
> 
> Why is this needed, shouldn't there already be a "driver" symlink in
> sysfs for these devices when a driver binds to them?  The rest of the
> driver model works that way, why is of devices any different?
> 

Because it hasn't been added yet! I only just committed the change to
convert device_nodes into kobjects in v3.14. The next step is to add
driver symlinks.

That said, the devicetree node is already exposed in the uevent for a
device. It should already be possible to find all device tree nodes that
don't have a device, or devices without a driver:

To get a list of all nodes:

find /proc/device-tree/ -type d | sed -e 's/\/proc\/device-tree//'

or a little more nuanced, only choosing nodes with a compatible property:

for k in `find /proc/device-tree/ -name compatible`; do
	echo $(dirname $k) | sed -e 's/\/proc\/device-tree//'
done | sort

It can get even more refined than that if need be.

To get a list of all nodes with a device that has been created:

for k in `find devices -name uevent`; do
	grep '^OF_FULLNAME' $k | sed -e 's/OF_FULLNAME=//'
done | sort

To get a list of all nodes with a device that has been bound to a driver:

for k in `find devices -name uevent`; do
	if [[ -d $(dirname $k)/driver ]]; then
		grep '^OF_FULLNAME' $k | sed -e 's/OF_FULLNAME=//'
	fi
done | sort


The suggestions you have below would be the anything in the first list
that isn't in the second or third:

bound=$(for k in `find /sys/devices -name uevent`; do
		if [[ -d $(dirname $k)/driver ]]; then
			grep '^OF_FULLNAME' $k | sed -e 's/OF_FULLNAME=//'
		fi
	done)

nodes=$(for k in `find /proc/device-tree/ -name compatible`; do
		echo $(dirname $k) | sed -e 's/\/proc\/device-tree//'
	done | sort)

for n in $nodes; do
	if ! echo $bound | grep -q "$n"; then
		echo $n $(cat /proc/device-tree/$n/compatible)
	fi
done



> > Examples of using the %driver_name file (note that /proc/device-tree is a
> > link to the base of the device tree sysfs tree):
> > 
> > 
> >   1) To find list of device tree nodes with no driver:
> > 
> >   # A few false positives may be reported.  For example,
> >   #   node_full_path of "." is the board.
> >   #
> >   # output is: node_full_path compatible_string
> >   #
> >   cd /proc/device-tree
> >   for k in `find . -type d`; do
> >      if [[ -f ${k}/compatible && ! -f ${k}/%driver_name ]] ; then
> >         if [[ "`cat ${k}/compatible`" != "simple-bus" ]] ; then
> >            echo `echo ${k} | sed -e 's|./||'` `cat ${k}/compatible`
> >         fi
> >      fi
> >   done | sort
> > 
> > 
> >   2) To find list of device tree nodes with a bound driver:
> > 
> >   # output is:  node_full_path driver_name
> >   #
> >   cd /proc/device-tree
> >   for k in `find . -name %driver_name` ; do
> >      echo `echo ${k} | sed -e 's|./||' -e 's|/%driver_name$||'` `cat ${k}`
> >   done | sort
> > 
> > 
> >   3) To find list of device tree nodes with a bound driver:
> > 
> >   # output is:  driver_name node_full_path
> >   #
> >   cd /proc/device-tree
> >   for k in `find . -name %driver_name` ; do
> >      echo `cat ${k}` `echo ${k} | sed -e 's|./||' -e 's|/%driver_name$||'`
> >   done | sort
> 
> If we take this patch, these examples should be somewhere in the
> documentation to make it easy for others.
> 
> > Signed-off-by: Frank Rowand <frank.rowand-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
> 
> Minor nit, your From: line doesn't match this signed-off-by: so
> something has to change (or add a new From: line, like SubmittingPatches
> decribes how to do.)
> 
> thanks,
> 
> greg k-h

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] sysfs, device-tree: aid for debugging device tree boot problems
@ 2014-04-23 22:45     ` Frank Rowand
  0 siblings, 0 replies; 11+ messages in thread
From: Frank Rowand @ 2014-04-23 22:45 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Grant Likely, Rob Herring, Linux Kernel list, devicetree

On 4/22/2014 8:20 PM, Greg Kroah-Hartman wrote:
> On Tue, Apr 22, 2014 at 06:25:25PM -0700, Frank Rowand wrote:
>> Create some infrastructure to aid trouble shooting device tree related
>> boot issues.
>>
>> Add a %driver_name file to each device tree node sysfs directory which has had
>> a driver bound to it.  This allows detecting device tree nodes which failed
>> to be bound to any driver.
> 
> Why is this needed, shouldn't there already be a "driver" symlink in
> sysfs for these devices when a driver binds to them?  The rest of the
> driver model works that way, why is of devices any different?

Yes, the devices do have a "driver" symlink in sysfs.

The problem I had was that I could not deterministically determine the
device name in /sysfs that was associated with a device tree node that
the device was created for.  And I couldn't find a link from the device
tree entries to the device tree node.

Grant's reply to your email provided the solution to my problem; the
device uevents file contains the full device tree path of the associated
device tree node.

Grant's reply removes the need for my patch.

> 
>> Examples of using the %driver_name file (note that /proc/device-tree is a
>> link to the base of the device tree sysfs tree):
>>
>>
>>   1) To find list of device tree nodes with no driver:
>>
>>   # A few false positives may be reported.  For example,
>>   #   node_full_path of "." is the board.
>>   #
>>   # output is: node_full_path compatible_string
>>   #
>>   cd /proc/device-tree
>>   for k in `find . -type d`; do
>>      if [[ -f ${k}/compatible && ! -f ${k}/%driver_name ]] ; then
>>         if [[ "`cat ${k}/compatible`" != "simple-bus" ]] ; then
>>            echo `echo ${k} | sed -e 's|./||'` `cat ${k}/compatible`
>>         fi
>>      fi
>>   done | sort
>>
>>
>>   2) To find list of device tree nodes with a bound driver:
>>
>>   # output is:  node_full_path driver_name
>>   #
>>   cd /proc/device-tree
>>   for k in `find . -name %driver_name` ; do
>>      echo `echo ${k} | sed -e 's|./||' -e 's|/%driver_name$||'` `cat ${k}`
>>   done | sort
>>
>>
>>   3) To find list of device tree nodes with a bound driver:
>>
>>   # output is:  driver_name node_full_path
>>   #
>>   cd /proc/device-tree
>>   for k in `find . -name %driver_name` ; do
>>      echo `cat ${k}` `echo ${k} | sed -e 's|./||' -e 's|/%driver_name$||'`
>>   done | sort
> 
> If we take this patch, these examples should be somewhere in the
> documentation to make it easy for others.

That is a good idea.  I'll package up the equivalent shell code from
Grant's email.  Any suggestions on location?

  scripts/debug/devicetree/
  scripts/devicetree/debug/
  Documentation/devicetree/scripts/

If there is no good location in the kernel tree, then I will put them
either on the devicetree wiki, or the devicetree section of the
elinux wiki.

> 
>> Signed-off-by: Frank Rowand <frank.rowand@sonymobile.com>
> 
> Minor nit, your From: line doesn't match this signed-off-by: so
> something has to change (or add a new From: line, like SubmittingPatches
> decribes how to do.)

Oops, thanks for pointing that out.

> 
> thanks,
> 
> greg k-h

-Frank


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] sysfs, device-tree: aid for debugging device tree boot problems
@ 2014-04-23 22:45     ` Frank Rowand
  0 siblings, 0 replies; 11+ messages in thread
From: Frank Rowand @ 2014-04-23 22:45 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Grant Likely, Rob Herring, Linux Kernel list,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On 4/22/2014 8:20 PM, Greg Kroah-Hartman wrote:
> On Tue, Apr 22, 2014 at 06:25:25PM -0700, Frank Rowand wrote:
>> Create some infrastructure to aid trouble shooting device tree related
>> boot issues.
>>
>> Add a %driver_name file to each device tree node sysfs directory which has had
>> a driver bound to it.  This allows detecting device tree nodes which failed
>> to be bound to any driver.
> 
> Why is this needed, shouldn't there already be a "driver" symlink in
> sysfs for these devices when a driver binds to them?  The rest of the
> driver model works that way, why is of devices any different?

Yes, the devices do have a "driver" symlink in sysfs.

The problem I had was that I could not deterministically determine the
device name in /sysfs that was associated with a device tree node that
the device was created for.  And I couldn't find a link from the device
tree entries to the device tree node.

Grant's reply to your email provided the solution to my problem; the
device uevents file contains the full device tree path of the associated
device tree node.

Grant's reply removes the need for my patch.

> 
>> Examples of using the %driver_name file (note that /proc/device-tree is a
>> link to the base of the device tree sysfs tree):
>>
>>
>>   1) To find list of device tree nodes with no driver:
>>
>>   # A few false positives may be reported.  For example,
>>   #   node_full_path of "." is the board.
>>   #
>>   # output is: node_full_path compatible_string
>>   #
>>   cd /proc/device-tree
>>   for k in `find . -type d`; do
>>      if [[ -f ${k}/compatible && ! -f ${k}/%driver_name ]] ; then
>>         if [[ "`cat ${k}/compatible`" != "simple-bus" ]] ; then
>>            echo `echo ${k} | sed -e 's|./||'` `cat ${k}/compatible`
>>         fi
>>      fi
>>   done | sort
>>
>>
>>   2) To find list of device tree nodes with a bound driver:
>>
>>   # output is:  node_full_path driver_name
>>   #
>>   cd /proc/device-tree
>>   for k in `find . -name %driver_name` ; do
>>      echo `echo ${k} | sed -e 's|./||' -e 's|/%driver_name$||'` `cat ${k}`
>>   done | sort
>>
>>
>>   3) To find list of device tree nodes with a bound driver:
>>
>>   # output is:  driver_name node_full_path
>>   #
>>   cd /proc/device-tree
>>   for k in `find . -name %driver_name` ; do
>>      echo `cat ${k}` `echo ${k} | sed -e 's|./||' -e 's|/%driver_name$||'`
>>   done | sort
> 
> If we take this patch, these examples should be somewhere in the
> documentation to make it easy for others.

That is a good idea.  I'll package up the equivalent shell code from
Grant's email.  Any suggestions on location?

  scripts/debug/devicetree/
  scripts/devicetree/debug/
  Documentation/devicetree/scripts/

If there is no good location in the kernel tree, then I will put them
either on the devicetree wiki, or the devicetree section of the
elinux wiki.

> 
>> Signed-off-by: Frank Rowand <frank.rowand-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
> 
> Minor nit, your From: line doesn't match this signed-off-by: so
> something has to change (or add a new From: line, like SubmittingPatches
> decribes how to do.)

Oops, thanks for pointing that out.

> 
> thanks,
> 
> greg k-h

-Frank

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] sysfs, device-tree: aid for debugging device tree boot problems
  2014-04-23 11:54     ` Grant Likely
  (?)
@ 2014-04-23 22:48     ` Frank Rowand
  2014-04-28 15:09       ` Grant Likely
  -1 siblings, 1 reply; 11+ messages in thread
From: Frank Rowand @ 2014-04-23 22:48 UTC (permalink / raw)
  To: Grant Likely
  Cc: Greg Kroah-Hartman, Rob Herring, Linux Kernel list, devicetree

On 4/23/2014 4:54 AM, Grant Likely wrote:
> On Tue, 22 Apr 2014 20:20:44 -0700, Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote:
>> On Tue, Apr 22, 2014 at 06:25:25PM -0700, Frank Rowand wrote:
>>> Create some infrastructure to aid trouble shooting device tree related
>>> boot issues.
>>>
>>> Add a %driver_name file to each device tree node sysfs directory which has had
>>> a driver bound to it.  This allows detecting device tree nodes which failed
>>> to be bound to any driver.
>>
>> Why is this needed, shouldn't there already be a "driver" symlink in
>> sysfs for these devices when a driver binds to them?  The rest of the
>> driver model works that way, why is of devices any different?
>>
> 
> Because it hasn't been added yet! I only just committed the change to
> convert device_nodes into kobjects in v3.14. The next step is to add
> driver symlinks.

No need to add a "driver" symlink.  The device directories in sysfs already
have a driver symlink.

> 
> That said, the devicetree node is already exposed in the uevent for a
> device. It should already be possible to find all device tree nodes that
> don't have a device, or devices without a driver:
> 
> To get a list of all nodes:
> 
> find /proc/device-tree/ -type d | sed -e 's/\/proc\/device-tree//'
> 
> or a little more nuanced, only choosing nodes with a compatible property:
> 
> for k in `find /proc/device-tree/ -name compatible`; do
> 	echo $(dirname $k) | sed -e 's/\/proc\/device-tree//'
> done | sort
> 
> It can get even more refined than that if need be.
> 
> To get a list of all nodes with a device that has been created:
> 
> for k in `find devices -name uevent`; do
> 	grep '^OF_FULLNAME' $k | sed -e 's/OF_FULLNAME=//'
> done | sort

< snip >

Thanks Grant!  I did not realize that uevent contained that
information.

-Frank


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] sysfs, device-tree: aid for debugging device tree boot problems
  2014-04-23 22:45     ` Frank Rowand
  (?)
@ 2014-04-23 23:45     ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 11+ messages in thread
From: Greg Kroah-Hartman @ 2014-04-23 23:45 UTC (permalink / raw)
  To: Frank Rowand; +Cc: Grant Likely, Rob Herring, Linux Kernel list, devicetree

On Wed, Apr 23, 2014 at 03:45:11PM -0700, Frank Rowand wrote:
> >>   3) To find list of device tree nodes with a bound driver:
> >>
> >>   # output is:  driver_name node_full_path
> >>   #
> >>   cd /proc/device-tree
> >>   for k in `find . -name %driver_name` ; do
> >>      echo `cat ${k}` `echo ${k} | sed -e 's|./||' -e 's|/%driver_name$||'`
> >>   done | sort
> > 
> > If we take this patch, these examples should be somewhere in the
> > documentation to make it easy for others.
> 
> That is a good idea.  I'll package up the equivalent shell code from
> Grant's email.  Any suggestions on location?
> 
>   scripts/debug/devicetree/
>   scripts/devicetree/debug/
>   Documentation/devicetree/scripts/

tools/ is probably the best place for them, or in Documentation/, either
would work.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] sysfs, device-tree: aid for debugging device tree boot problems
  2014-04-23 22:48     ` Frank Rowand
@ 2014-04-28 15:09       ` Grant Likely
  0 siblings, 0 replies; 11+ messages in thread
From: Grant Likely @ 2014-04-28 15:09 UTC (permalink / raw)
  To: Frank Rowand
  Cc: Greg Kroah-Hartman, Rob Herring, Linux Kernel list, devicetree

On Wed, Apr 23, 2014 at 11:48 PM, Frank Rowand <frowand.list@gmail.com> wrote:
> On 4/23/2014 4:54 AM, Grant Likely wrote:
>> On Tue, 22 Apr 2014 20:20:44 -0700, Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote:
>>> On Tue, Apr 22, 2014 at 06:25:25PM -0700, Frank Rowand wrote:
>>>> Create some infrastructure to aid trouble shooting device tree related
>>>> boot issues.
>>>>
>>>> Add a %driver_name file to each device tree node sysfs directory which has had
>>>> a driver bound to it.  This allows detecting device tree nodes which failed
>>>> to be bound to any driver.
>>>
>>> Why is this needed, shouldn't there already be a "driver" symlink in
>>> sysfs for these devices when a driver binds to them?  The rest of the
>>> driver model works that way, why is of devices any different?
>>>
>>
>> Because it hasn't been added yet! I only just committed the change to
>> convert device_nodes into kobjects in v3.14. The next step is to add
>> driver symlinks.
>
> No need to add a "driver" symlink.  The device directories in sysfs already
> have a driver symlink.

Sorry, I meant of_node symlink. That is the bit I've been planning to add.

g.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-04-28 15:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-23  1:25 [PATCH] sysfs, device-tree: aid for debugging device tree boot problems Frank Rowand
2014-04-23  1:25 ` Frank Rowand
2014-04-23  3:20 ` Greg Kroah-Hartman
2014-04-23  3:20   ` Greg Kroah-Hartman
2014-04-23 11:54   ` Grant Likely
2014-04-23 11:54     ` Grant Likely
2014-04-23 22:48     ` Frank Rowand
2014-04-28 15:09       ` Grant Likely
2014-04-23 22:45   ` Frank Rowand
2014-04-23 22:45     ` Frank Rowand
2014-04-23 23:45     ` Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.