diff mbox

[U-Boot,v5,05/41] dm: Improve handling of a missing uclass

Message ID 1440975352-28528-6-git-send-email-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass Aug. 30, 2015, 10:55 p.m. UTC
When a uclass definition is missing, no drivers in that uclass can operate.
This can happen if a board has a strange collection of options (e.g. the
driver is enabled but the uclass is not).

Unfortunately this is very confusing at present. Starting up driver model
results in a -ENOENT error, which is pretty generic. Quite a big of digging
is needed to get to the root cause.

To help with this, change the error to a very strange one with no other
users in U-Boot. Also add a debug message.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/core/device.c | 4 +++-
 drivers/core/uclass.c | 7 ++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

Comments

Simon Glass Sept. 3, 2015, 5:58 p.m. UTC | #1
On 30 August 2015 at 16:55, Simon Glass <sjg@chromium.org> wrote:
> When a uclass definition is missing, no drivers in that uclass can operate.
> This can happen if a board has a strange collection of options (e.g. the
> driver is enabled but the uclass is not).
>
> Unfortunately this is very confusing at present. Starting up driver model
> results in a -ENOENT error, which is pretty generic. Quite a big of digging
> is needed to get to the root cause.
>
> To help with this, change the error to a very strange one with no other
> users in U-Boot. Also add a debug message.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v5: None
> Changes in v4: None
> Changes in v3: None
> Changes in v2: None
>
>  drivers/core/device.c | 4 +++-
>  drivers/core/uclass.c | 7 ++++++-
>  2 files changed, 9 insertions(+), 2 deletions(-)

Applied to u-boot-rockchip.
diff mbox

Patch

diff --git a/drivers/core/device.c b/drivers/core/device.c
index a6cd936..0ccd443 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -39,8 +39,10 @@  int device_bind(struct udevice *parent, const struct driver *drv,
 		return -EINVAL;
 
 	ret = uclass_get(drv->id, &uc);
-	if (ret)
+	if (ret) {
+		debug("Missing uclass for driver %s\n", drv->name);
 		return ret;
+	}
 
 	dev = calloc(1, sizeof(struct udevice));
 	if (!dev)
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index f63ff59..e800c28 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -58,7 +58,12 @@  static int uclass_add(enum uclass_id id, struct uclass **ucp)
 	if (!uc_drv) {
 		debug("Cannot find uclass for id %d: please add the UCLASS_DRIVER() declaration for this UCLASS_... id\n",
 		      id);
-		return -ENOENT;
+		/*
+		 * Use a strange error to make this case easier to find. When
+		 * a uclass is not available it can prevent driver model from
+		 * starting up and this failure is otherwise hard to debug.
+		 */
+		return -EPFNOSUPPORT;
 	}
 	uc = calloc(1, sizeof(*uc));
 	if (!uc)