blob: c59bf6763bd0236dffd9c2ce15949980be496a2b [file] [log] [blame]
Simon Glassfdd72be2019-09-25 08:55:48 -06001.. SPDX-License-Identifier: GPL-2.0+
2.. sectionauthor:: Simon Glass <sjg@chromium.org>
3
4Debugging driver model
5======================
6
7This document aims to provide help when you cannot work out why driver model is
8not doing what you expect.
9
10
11Useful techniques in general
12----------------------------
13
14Here are some useful debugging features generally.
15
16 - If you are writing a new feature, consider doing it in sandbox instead of
17 on your board. Sandbox has no limits, allows easy debugging (e.g. gdb) and
18 you can write emulators for most common devices.
19 - Put '#define DEBUG' at the top of a file, to activate all the debug() and
20 log_debug() statements in that file.
21 - Where logging is used, change the logging level, e.g. in SPL with
22 CONFIG_SPL_LOG_MAX_LEVEL=7 (which is LOGL_DEBUG) and
23 CONFIG_LOG_DEFAULT_LEVEL=7
24 - Where logging of return values is implemented with log_msg_ret(), set
25 CONFIG_LOG_ERROR_RETURN=y to see exactly where the error is happening
26 - Make sure you have a debug UART enabled - see CONFIG_DEBUG_UART. With this
27 you can get serial output (printf(), etc.) before the serial driver is
28 running.
29 - Use a JTAG emulator to set breakpoints and single-step through code
30
31Not that most of these increase code/data size somewhat when enabled.
32
33
34Failure to locate a device
35--------------------------
36
37Let's say you have uclass_first_device_err() and it is not finding anything.
38
39If it is returning an error, then that gives you a clue. Look up linux/errno.h
40to see errors. Common ones are:
41
42 - -ENOMEM which indicates that memory is short. If it happens in SPL or
43 before relocation in U-Boot, check CONFIG_SPL_SYS_MALLOC_F_LEN and
44 CONFIG_SYS_MALLOC_F_LEN as they may need to be larger. Add '#define DEBUG'
45 at the very top of malloc_simple.c to get an idea of where your memory is
46 going.
47 - -EINVAL which typically indicates that something was missing or wrong in
48 the device tree node. Check that everything is correct and look at the
49 ofdata_to_platdata() method in the driver.
50
51If there is no error, you should check if the device is actually bound. Call
52dm_dump_all() just before you locate the device to make sure it exists.
53
54If it does not exist, check your device tree compatible strings match up with
55what the driver expects (in the struct udevice_id array).
56
57If you are using of-platdata (e.g. CONFIG_SPL_OF_PLATDATA), check that the
58driver name is the same as the first compatible string in the device tree (with
59invalid-variable characters converted to underscore).
60
Fabio Estevam1d6a0c92020-01-29 14:45:33 -030061If you are really stuck, putting '#define LOG_DEBUG' at the top of
62drivers/core/lists.c should show you what is going on.