So far U-Boot uses a 'flat' device tree, which means that it is decoded
on the fly as needed. This uses the libfdt library and avoids needing
extra memory for additional tables.

For some time there has been discussion about moving U-Boot to use a
'live' tree, where the device tree is decoded at start-up into a set of
hierarchical structures with pointers.

The advantages are:

- It is somewhat faster to access (in particular scanning and looking for a
    parent)
- It permits the device tree to be changed at run-time (this is not
    recommended at present since devices store the offset of their device
    tree node and updating the tree may invalidate that). This could be
    useful for overlays, for example.
- It allows nodes to be referenced by a single pointer, instead of the
    current device tree pointer plus offset

The disadvantages are:

- It requires more memory
- It takes (a little) time to build the live tree
- It adds more complexity under the hood, including an additional
    abstraction layer

This series is an attempt to introduce a useful live tree feature into
U-Boot. There are many options and trade-offs. This series is the
culmination of quite a bit of thought and experimentation.

The approach used in this series is:

- Before relocation the flat tree is used, to avoid extra memory usage
and time. In general, there is not much access before relocation since
most drivers are not started up. So there is little benefit in having a
live tree

- After relocation the live tree is built. At this point the CPU should be
running quickly and there is plenty of memory. All available devices will
be bound so the overhead of building the live tree may be outweighed by
its greater efficiency.

As a simplification, this series supports only one tree or the other. When
the live tree is active, the flat tree cannot be used. That makes it easy
to know the current state and avoids confusion over mixing offset and node
pointers.

Some drivers will need to be used both before and after relocation. This
means that they must support both the flat and the live tree. To support
this, the concept of a node 'reference' is defined. A reference can hold
either a node offset (for the flat tree) or a node pointer (for the live
tree). This allows drivers to access values from the tree regardless of
which tree is in use.

In addition, since most device tree access happens in the context of a
device (struct udevice), a new 'dev_read' layer is provided to read device
tree configuration associated with a device. This encapsulates the details
of exactly how this information is read.

I have taken the view that code compatibility with Linux is desirable. So
the of_access.c file brings in code from Linux with very little
modification. As new access methods are needed we should be able to bring
in more code and avoid writing it ourselves in U-Boot.

Conversion of drivers and subsystems to support the live tree (as well as
flat tree) is fairly easy. A patch is included to add support to the GPIO
uclass, and the cros_ec device is converted over to provide a driver
example.

Once I have comments on this series I will update it to build for all
boards, to pass current tests and to tidy up the code. I will also add
tests for the live tree and finish conversion for sandbox. So for now I am
just looking for high-level comments, rather than a detailed code review.


Simon Glass (22):
  dm: core: Set return value first in lists_bind_fdt()
  dm: core: atmel: Dont export dm_scan_fdt_node()
  Update WARN_ON() to return a value
  dm: Add livetree definitions
  dm: Add livetree access functions
  dm: Add a function to create a 'live' device tree
  dm: Build a live tree after relocation
  dm: Add support for device tree references
  dm: Add a place to put extra device-tree reading functions
  dm: core: Add device-based functions to access DT properties
  dm: core: Allow binding a device from a live tree
  dm: core: Add a method to find a driver for a livetree node
  dm: core: Scan the live tree when setting up driver model
  dm: core: Add a way to find a device by its live-tree node
  dm: core: Add a way to find a device by node reference
  dm: gpio: Refactor to prepare for live tree support
  dm: gpio: Add live tree support
  dm: gpio: Drop blank line in gpio_xlate_offs_flags() comment
  dm: gpio: sandbox: Use dm_read...() functions to access DT
  cros_ec: Fix debug() statement in ec_command_inptr()
  cros_ec: Convert to support live tree
  sandbox: Move to use live tree

 common/board_r.c                  |  12 ++
 configs/sandbox_defconfig         |   1 +
 drivers/core/Makefile             |   1 +
 drivers/core/device.c             |  27 +++-
 drivers/core/lists.c              |  80 +++++++++-
 drivers/core/of_dev.c             |  55 +++++++
 drivers/core/of_extra.c           |  37 +++++
 drivers/core/of_ref.c             | 218 +++++++++++++++++++++++++
 drivers/core/root.c               |  61 ++++++-
 drivers/core/uclass.c             |  78 +++++++++
 drivers/gpio/atmel_pio4.c         |   3 +-
 drivers/gpio/gpio-uclass.c        | 100 ++++++++----
 drivers/gpio/sandbox.c            |  10 +-
 drivers/misc/cros_ec.c            |  36 ++---
 drivers/misc/cros_ec_sandbox.c    |   2 +-
 dts/Kconfig                       |  11 ++
 include/asm-generic/global_data.h |   3 +
 include/asm-generic/gpio.h        |   7 +-
 include/cros_ec.h                 |   8 +-
 include/dm/device-internal.h      |   6 +
 include/dm/device.h               |  19 ++-
 include/dm/lists.h                |   5 +
 include/dm/of.h                   |  53 ++++++
 include/dm/of_access.h            | 164 +++++++++++++++++++
 include/dm/of_dev.h               |  68 ++++++++
 include/dm/of_extra.h             |  46 ++++++
 include/dm/of_ref.h               | 306 +++++++++++++++++++++++++++++++++++
 include/dm/root.h                 |  16 --
 include/dm/uclass-internal.h      |  22 +++
 include/dm/uclass.h               |  23 +++
 include/fdtdec.h                  |  34 ----
 include/linux/compat.h            |   8 +-
 include/livetree.h                |  24 +++
 lib/Makefile                      |   1 +
 lib/fdtdec.c                      |  32 ----
 lib/livetree.c                    | 320 +++++++++++++++++++++++++++++++++++++
 lib/of_access.c                   | 328 ++++++++++++++++++++++++++++++++++++++
 37 files changed, 2066 insertions(+), 159 deletions(-)
 create mode 100644 drivers/core/of_dev.c
 create mode 100644 drivers/core/of_extra.c
 create mode 100644 drivers/core/of_ref.c
 create mode 100644 include/dm/of.h
 create mode 100644 include/dm/of_access.h
 create mode 100644 include/dm/of_dev.h
 create mode 100644 include/dm/of_extra.h
 create mode 100644 include/dm/of_ref.h
 create mode 100644 include/livetree.h
 create mode 100644 lib/livetree.c
 create mode 100644 lib/of_access.c

-- 
2.11.0.483.g087da7b7c-goog

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to