debugging.rst 2.6 KB

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