All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] doc: Move devicetree control doc to rST
@ 2021-07-25 16:43 Simon Glass
  2021-07-25 16:43 ` [PATCH 2/3] doc: Update devicedocs including how to add tweaks Simon Glass
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Simon Glass @ 2021-07-25 16:43 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Heinrich Schuchardt, Tom Rini, Simon Glass, Bin Meng

Move this to rST format, largely unchanged to start with. Add an index
for this topic, as well as an empty intro.

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

 .../devicetree/control.rst}                   | 50 +++++++++----------
 doc/develop/devicetree/index.rst              | 13 +++++
 doc/develop/devicetree/intro.rst              |  4 ++
 doc/develop/index.rst                         |  1 +
 4 files changed, 43 insertions(+), 25 deletions(-)
 rename doc/{README.fdt-control => develop/devicetree/control.rst} (89%)
 create mode 100644 doc/develop/devicetree/index.rst
 create mode 100644 doc/develop/devicetree/intro.rst

diff --git a/doc/README.fdt-control b/doc/develop/devicetree/control.rst
similarity index 89%
rename from doc/README.fdt-control
rename to doc/develop/devicetree/control.rst
index 424d13fc5b1..1289b6156fe 100644
--- a/doc/README.fdt-control
+++ b/doc/develop/devicetree/control.rst
@@ -1,6 +1,5 @@
-# SPDX-License-Identifier: GPL-2.0+
-#
-# Copyright (c) 2011 The Chromium OS Authors.
+.. SPDX-License-Identifier: GPL-2.0+
+.. sectionauthor:: Copyright 2011 The Chromium OS Authors
 
 Device Tree Control in U-Boot
 =============================
@@ -37,9 +36,7 @@ What is a Flat Device Tree?
 ---------------------------
 
 An fdt can be specified in source format as a text file. To read about
-the fdt syntax, take a look at the specification here:
-
-https://www.power.org/resources/downloads/Power_ePAPR_APPROVED_v1.0.pdf
+the fdt syntax, take a look at the specification (dtspec_).
 
 You also might find this section of the Linux kernel documentation
 useful: (access this in the Linux kernel source code)
@@ -60,18 +57,18 @@ To use this feature you will need to get the device tree compiler. This is
 provided by U-Boot automatically. If you have a system version of dtc
 (typically in the 'device-tree-compiler' package), it is currently not used.
 
-If you want to build your own dtc, it is kept here:
+If you want to build your own dtc, it is kept here::
 
 	git://git.kernel.org/pub/scm/utils/dtc/dtc.git
 
-For example:
+For example::
 
 	$ git clone git://git.kernel.org/pub/scm/utils/dtc/dtc.git
 	$ cd dtc
 	$ make
 	$ sudo make install
 
-Then run the compiler (your version will vary):
+Then run the compiler (your version will vary)::
 
 	$ dtc -v
 	Version: DTC 1.2.0-g2cb4b51f
@@ -105,14 +102,14 @@ Failing that, you could write one from scratch yourself!
 Configuration
 -------------
 
-Use:
+Use::
 
-#define CONFIG_DEFAULT_DEVICE_TREE	"<name>"
+   #define CONFIG_DEFAULT_DEVICE_TREE	"<name>"
 
 to set the filename of the device tree source. Then put your device tree
-file into
+file into::
 
-	board/<vendor>/dts/<name>.dts
+   board/<vendor>/dts/<name>.dts
 
 This should include your CPU or SOC's device tree file, placed in
 arch/<arch>/dts, and then make any adjustments required.
@@ -123,9 +120,9 @@ and development only and is not recommended for production devices.
 
 If CONFIG_OF_SEPARATE is defined, then it will be built and placed in
 a u-boot.dtb file alongside u-boot-nodtb.bin. A common approach is then to
-join the two:
+join the two::
 
-	cat u-boot-nodtb.bin u-boot.dtb >image.bin
+   cat u-boot-nodtb.bin u-boot.dtb >image.bin
 
 and then flash image.bin onto your board. Note that U-Boot creates
 u-boot-dtb.bin which does the above step for you also. Resulting
@@ -144,9 +141,9 @@ specify the file to read.
 You cannot use more than one of these options at the same time.
 
 To use a device tree file that you have compiled yourself, pass
-EXT_DTB=<filename> to 'make', as in:
+EXT_DTB=<filename> to 'make', as in::
 
-	make EXT_DTB=boot/am335x-boneblack-pubkey.dtb
+   make EXT_DTB=boot/am335x-boneblack-pubkey.dtb
 
 Then U-Boot will copy that file to u-boot.dtb, put it in the .img file
 if used, and u-boot-dtb.bin.
@@ -162,16 +159,21 @@ variable will be set to the address of the newly relocated fdt blob.
 It is read-only and cannot be changed. It can optionally be used to
 control the boot process of Linux with bootm/bootz commands.
 
-To use this, put something like this in your board header file:
+To use this, put something like this in your board header file::
 
-#define CONFIG_EXTRA_ENV_SETTINGS	"fdtcontroladdr=10000\0"
+   #define CONFIG_EXTRA_ENV_SETTINGS	"fdtcontroladdr=10000\0"
 
 Build:
 
-After board configuration is done, fdt supported u-boot can be build in two ways:
-1)  build the default dts which is defined from CONFIG_DEFAULT_DEVICE_TREE
+After board configuration is done, fdt supported u-boot can be build in two
+ways:
+
+#  build the default dts which is defined from CONFIG_DEFAULT_DEVICE_TREE::
+
     $ make
-2)  build the user specified dts file
+
+#  build the user specified dts file::
+
     $ make DEVICE_TREE=<dts-file-name>
 
 
@@ -225,6 +227,4 @@ but can use the fdt to specific the UART clock, peripheral address, etc.
 In very broad terms, the CONFIG options in general control *what* driver
 files are pulled in, and the fdt controls *how* those files work.
 
---
-Simon Glass <sjg@chromium.org>
-1-Sep-11
+.. _dtspec: https://www.power.org/resources/downloads/Power_ePAPR_APPROVED_v1.0.pdf
diff --git a/doc/develop/devicetree/index.rst b/doc/develop/devicetree/index.rst
new file mode 100644
index 00000000000..fa5db3eb76e
--- /dev/null
+++ b/doc/develop/devicetree/index.rst
@@ -0,0 +1,13 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Devicetree in U-Boot
+====================
+
+The following holds information on how U-Boot makes use of devicetree for
+build-time and runtime configuration.
+
+.. toctree::
+   :maxdepth: 2
+
+   intro
+   control
diff --git a/doc/develop/devicetree/intro.rst b/doc/develop/devicetree/intro.rst
new file mode 100644
index 00000000000..344851327c7
--- /dev/null
+++ b/doc/develop/devicetree/intro.rst
@@ -0,0 +1,4 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Devicetree Introduction
+=======================
diff --git a/doc/develop/index.rst b/doc/develop/index.rst
index 54e14dd77b5..1b904189945 100644
--- a/doc/develop/index.rst
+++ b/doc/develop/index.rst
@@ -10,6 +10,7 @@ Implementation
    :maxdepth: 1
 
    commands
+   devicetree/index
    driver-model/index
    global_data
    logging
-- 
2.32.0.432.gabb21c7263-goog


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

* [PATCH 2/3] doc: Update devicedocs including how to add tweaks
  2021-07-25 16:43 [PATCH 1/3] doc: Move devicetree control doc to rST Simon Glass
@ 2021-07-25 16:43 ` Simon Glass
  2021-08-01  8:47   ` Heinrich Schuchardt
  2021-07-25 16:44 ` [PATCH 3/3] doc: Add a note about why devicetree is used Simon Glass
  2021-08-01  8:22 ` [PATCH 1/3] doc: Move devicetree control doc to rST Heinrich Schuchardt
  2 siblings, 1 reply; 6+ messages in thread
From: Simon Glass @ 2021-07-25 16:43 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Heinrich Schuchardt, Tom Rini, Simon Glass

This file is about 10 years old and the updates have not covered
everything that has changed, particularly in the last few years. Update
the information and add mention of the u-boot.dtsi files.

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

 doc/develop/devicetree/control.rst | 107 ++++++++++++++++++++---------
 1 file changed, 74 insertions(+), 33 deletions(-)

diff --git a/doc/develop/devicetree/control.rst b/doc/develop/devicetree/control.rst
index 1289b6156fe..ac5f7989cc6 100644
--- a/doc/develop/devicetree/control.rst
+++ b/doc/develop/devicetree/control.rst
@@ -1,26 +1,27 @@
 .. SPDX-License-Identifier: GPL-2.0+
 .. sectionauthor:: Copyright 2011 The Chromium OS Authors
 
-Device Tree Control in U-Boot
-=============================
+Devicetree Control in U-Boot
+============================
 
 This feature provides for run-time configuration of U-Boot via a flat
-device tree (fdt). U-Boot configuration has traditionally been done
-using CONFIG options in the board config file. This feature aims to
-make it possible for a single U-Boot binary to support multiple boards,
-with the exact configuration of each board controlled by a flat device
-tree (fdt). This is the approach recently taken by the ARM Linux kernel
-and has been used by PowerPC for some time.
+device tree (fdt).
+
+This feature aims to make it possible for a single U-Boot binary to support
+multiple boards, with the exact configuration of each board controlled by
+a flat device tree (fdt). This is the approach recently taken by Linux (e.g.
+for PowerPC and ARM).
 
 The fdt is a convenient vehicle for implementing run-time configuration
-for three reasons. Firstly it is easy to use, being a simple text file.
-It is extensible since it consists of nodes and properties in a nice
-hierarchical format.
+for three reasons:
 
-Finally, there is already excellent infrastructure for the fdt: a
-compiler checks the text file and converts it to a compact binary
-format, and a library is already available in U-Boot (libfdt) for
-handling this format.
+- Firstly it is easy to use, being a simple text file
+- It is extensible since it consists of nodes and properties in a nice
+  hierarchical format
+- There is already excellent infrastructure for the fdt: a compiler checks
+  the text file and converts it to a compact binary format, and a library
+  is already available in U-Boot (libfdt) for handling this format\
+- It is fairly efficient to read incrementally
 
 The dts directory contains a Makefile for building the device tree blob
 and embedding it in your U-Boot image. This is useful since it allows
@@ -38,14 +39,8 @@ What is a Flat Device Tree?
 An fdt can be specified in source format as a text file. To read about
 the fdt syntax, take a look at the specification (dtspec_).
 
-You also might find this section of the Linux kernel documentation
-useful: (access this in the Linux kernel source code)
-
-	Documentation/devicetree/booting-without-of.txt
-
-There is also a mailing list:
-
-	http://lists.ozlabs.org/listinfo/devicetree-discuss
+There is also a mailing list (dtlist_) for the compiler and associated
+tools.
 
 In case you are wondering, OF stands for Open Firmware.
 
@@ -82,8 +77,9 @@ Then run the compiler (your version will vary)::
 	*   Bad configuration:	0
 	* Strange test result:	0
 
-You will also find a useful fdtdump utility for decoding a binary file, as
-well as fdtget/fdtput for reading and writing properties in a binary file.
+You will also find a useful `fdtdump` utility for decoding a binary file, as
+well as `fdtget`/`fdtput` for reading and writing properties in a binary file.
+U-Boot adds its own `fdtgrep` for creating subsets of the file.
 
 
 Where do I get an fdt file for my board?
@@ -109,10 +105,11 @@ Use::
 to set the filename of the device tree source. Then put your device tree
 file into::
 
-   board/<vendor>/dts/<name>.dts
+   arch/<arch>/dts/<name>.dts
 
 This should include your CPU or SOC's device tree file, placed in
-arch/<arch>/dts, and then make any adjustments required.
+`arch/<arch>/dts`, and then make any adjustments required using a u-boot-dtsi
+file for your board.
 
 If CONFIG_OF_EMBED is defined, then it will be picked up and built into
 the U-Boot image (including u-boot.bin). This is suitable for debugging
@@ -122,11 +119,10 @@ If CONFIG_OF_SEPARATE is defined, then it will be built and placed in
 a u-boot.dtb file alongside u-boot-nodtb.bin. A common approach is then to
 join the two::
 
-   cat u-boot-nodtb.bin u-boot.dtb >image.bin
+   cat u-boot-nodtb.bin u-boot.dtb >u-boot.bin
 
 and then flash image.bin onto your board. Note that U-Boot creates
-u-boot-dtb.bin which does the above step for you also. Resulting
-u-boot.bin is a copy of u-boot-dtb.bin in this case. If you are using
+u-boot.bin so does the above step for you automatically. If you are using
 CONFIG_SPL_FRAMEWORK, then u-boot.img will be built to include the device
 tree binary.
 
@@ -136,7 +132,8 @@ it and passes it to U-Boot.
 
 If CONFIG_OF_HOSTFILE is defined, then it will be read from a file on
 startup. This is only useful for sandbox. Use the -d flag to U-Boot to
-specify the file to read.
+specify the file to read, -D for the default and -T for the test devicetree,
+used to run sandbox unit tests.
 
 You cannot use more than one of these options at the same time.
 
@@ -177,6 +174,35 @@ ways:
     $ make DEVICE_TREE=<dts-file-name>
 
 
+Adding tweaks for U-Boot
+------------------------
+
+It is strongly recommended that devicetree files in U-Boot be an exact copy of
+those in Linux, so that it is easy to sync them up from time to time.
+
+U-Boot is of course a very different project from Linux, e.g. it operates under
+much more restrictive memory and code-size constraints. Where Linux may use a
+full clock driver with Common Clock Format (CCF) to find the input clock to the
+UART, U-Boot typically wants to output a banner as early as possible before too
+much code has run.
+
+A second different is that U-Boot includes different phases. For SPL,
+constraints are even more extreme and the devicetree is shrunk to remove
+unwanted nodes, or even turned into C code to avoid access overhead.
+
+U-Boot automatically looks for and incluces a file with updates to the standard
+devicetree for your board, searching for them in the same directory as the
+main file, in this order::
+
+   <orig_filename>-u-boot.dtsi
+   <CONFIG_SYS_SOC>-u-boot.dtsi
+   <CONFIG_SYS_CPU>-u-boot.dtsi
+   <CONFIG_SYS_VENDOR>-u-boot.dtsi
+   u-boot.dtsi
+
+Only one of these is selected but of course you can #include another one within
+that file, to create a hierarchy of shared files.
+
 Relocation, SPL and TPL
 -----------------------
 
@@ -201,7 +227,7 @@ If board_fit_config_name_match() relies on DM (DM driver to access an EEPROM
 containing the board ID for example), it possible to start with a generic DTB
 and then switch over to the right DTB after the detection. For this purpose,
 the platform code must call fdtdec_resetup(). Based on the returned flag, the
-platform may have to re-initiliaze the DM subusystem using dm_uninit() and
+platform may have to re-initiliaze the DM subsystem using dm_uninit() and
 dm_init_and_scan().
 
 
@@ -227,4 +253,19 @@ but can use the fdt to specific the UART clock, peripheral address, etc.
 In very broad terms, the CONFIG options in general control *what* driver
 files are pulled in, and the fdt controls *how* those files work.
 
-.. _dtspec: https://www.power.org/resources/downloads/Power_ePAPR_APPROVED_v1.0.pdf
+History
+-------
+
+U-Boot configuration was previous done using CONFIG options in the board
+config file. This eventually got out of hand with nearly 10,000 options.
+
+U-Boot adopted devicetree around the same time as linux and early boards
+used it before linux (e.g. snow). The two projects developed in parallel
+and there are still some differences in the bindings with certain boards.
+While there has beeen dicussion of having a separate repo for devicetree
+files, in practice the kernel's repo has become the place where these are
+stored, with U-Boot taking copies and adding tweaks with u-boot.dtsi files.
+
+
+.. _dtspec: https://www.devicetree.org/specifications/
+.. _dtlist: https://www.spinics.net/lists/devicetree-compiler/
-- 
2.32.0.432.gabb21c7263-goog


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

* [PATCH 3/3] doc: Add a note about why devicetree is used
  2021-07-25 16:43 [PATCH 1/3] doc: Move devicetree control doc to rST Simon Glass
  2021-07-25 16:43 ` [PATCH 2/3] doc: Update devicedocs including how to add tweaks Simon Glass
@ 2021-07-25 16:44 ` Simon Glass
  2021-08-01  8:56   ` Heinrich Schuchardt
  2021-08-01  8:22 ` [PATCH 1/3] doc: Move devicetree control doc to rST Heinrich Schuchardt
  2 siblings, 1 reply; 6+ messages in thread
From: Simon Glass @ 2021-07-25 16:44 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Heinrich Schuchardt, Tom Rini, Simon Glass

This question comes up every now and then with people coming from Linux.
Add some notes about it so we can point to it in the mailing list.

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

 doc/develop/devicetree/control.rst |  2 ++
 doc/develop/devicetree/intro.rst   | 39 ++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/doc/develop/devicetree/control.rst b/doc/develop/devicetree/control.rst
index ac5f7989cc6..f98faee20d1 100644
--- a/doc/develop/devicetree/control.rst
+++ b/doc/develop/devicetree/control.rst
@@ -174,6 +174,8 @@ ways:
     $ make DEVICE_TREE=<dts-file-name>
 
 
+.. _dttweaks:
+
 Adding tweaks for U-Boot
 ------------------------
 
diff --git a/doc/develop/devicetree/intro.rst b/doc/develop/devicetree/intro.rst
index 344851327c7..e03d8e1ae66 100644
--- a/doc/develop/devicetree/intro.rst
+++ b/doc/develop/devicetree/intro.rst
@@ -2,3 +2,42 @@
 
 Devicetree Introduction
 =======================
+
+U-Boot uses devicetree for configuration. This includes the devices used by
+the board, the format of the image created with binman, which UART to use for
+the console, public keys used for secure boot and many other things.
+
+See :doc:`control` for more information.
+
+Why does U-Boot put <thing> in the devicetree?
+----------------------------------------------
+
+This question comes up a lot with people new to U-Boot, particular those coming
+from Linux who are used to quite strict rules about what can go in the
+devicetree.
+
+U-Boot uses the same devicetree as Linux but adds more things necessary for the
+bootloader environment (see :ref:`dttweaks`).
+
+U-Boot does not have a user space to provide policy and configuration. It cannot
+do what Linux does and run programs and look up filesystems to figure out how to
+boot. So configuration / runtime info go in the devicetree in U-Boot.
+
+Of course it is possible to:
+
+- add tables into the rodata
+- append some info to the end of U-Boot in a different format
+- modify the link script to bring in a file with some info in it
+- put things in ACPI tables
+- compile in a UEFI hand-off block structure and put things in there
+
+but *please don't*. In general, devicetree is the sane place to hold U-Boot's
+configuration.
+
+So please...do NOT ask why U-Boot puts <thing> in the devicetree. It is the only
+place it can go. It is a highly suitable data structure for just about anything
+that U-Boot needs to know at runtime.
+
+Note, it is possible to use platdata directly so drivers avoid devicetreee in
+SPL. But of-platdata is the modern way of avoiding devicetree overhead, so
+please use that instead.
-- 
2.32.0.432.gabb21c7263-goog


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

* Re: [PATCH 1/3] doc: Move devicetree control doc to rST
  2021-07-25 16:43 [PATCH 1/3] doc: Move devicetree control doc to rST Simon Glass
  2021-07-25 16:43 ` [PATCH 2/3] doc: Update devicedocs including how to add tweaks Simon Glass
  2021-07-25 16:44 ` [PATCH 3/3] doc: Add a note about why devicetree is used Simon Glass
@ 2021-08-01  8:22 ` Heinrich Schuchardt
  2 siblings, 0 replies; 6+ messages in thread
From: Heinrich Schuchardt @ 2021-08-01  8:22 UTC (permalink / raw)
  To: Simon Glass, U-Boot Mailing List; +Cc: Tom Rini, Bin Meng

On 7/25/21 6:43 PM, Simon Glass wrote:
> Move this to rST format, largely unchanged to start with. Add an index
> for this topic, as well as an empty intro.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>   .../devicetree/control.rst}                   | 50 +++++++++----------
>   doc/develop/devicetree/index.rst              | 13 +++++
>   doc/develop/devicetree/intro.rst              |  4 ++
>   doc/develop/index.rst                         |  1 +
>   4 files changed, 43 insertions(+), 25 deletions(-)
>   rename doc/{README.fdt-control => develop/devicetree/control.rst} (89%)
>   create mode 100644 doc/develop/devicetree/index.rst
>   create mode 100644 doc/develop/devicetree/intro.rst
>
> diff --git a/doc/README.fdt-control b/doc/develop/devicetree/control.rst
> similarity index 89%
> rename from doc/README.fdt-control
> rename to doc/develop/devicetree/control.rst
> index 424d13fc5b1..1289b6156fe 100644


 > diff --git a/doc/develop/devicetree/control.rst
b/doc/develop/devicetree/control.rst
 > new file mode 100644
 > index 0000000000..1289b6156f
 > --- /dev/null
 > +++ b/doc/develop/devicetree/control.rst
 > @@ -0,0 +1,230 @@
 > +.. SPDX-License-Identifier: GPL-2.0+
 > +.. sectionauthor:: Copyright 2011 The Chromium OS Authors
 > +
 > +Device Tree Control in U-Boot
 > +=============================
 > +
 > +This feature provides for run-time configuration of U-Boot via a flat

%s/flat/flattened/

Please, use the terminology of the Devicetree Specification.

 > +device tree (fdt). U-Boot configuration has traditionally been done
 > +using CONFIG options in the board config file. This feature aims to

%s/config/configuration/

Please, avoid slang.

 > +make it possible for a single U-Boot binary to support multiple boards,
 > +with the exact configuration of each board controlled by a flat device

%s/flag/flattened/

 > +tree (fdt). This is the approach recently taken by the ARM Linux kernel

RISC-V too.

 > +and has been used by PowerPC for some time.
 > +
 > +The fdt is a convenient vehicle for implementing run-time configuration
 > +for three reasons. Firstly it is easy to use, being a simple text file.

No. The flattened devicetree is not a text file format. It is a binary
format.

Assume that a reader does not know that these different formats exist.
You need to explain at the beginning of the chapter what a devicetree is
and that it can be converted to a binary format, the flattened divice tree.

 > +It is extensible since it consists of nodes and properties in a nice
 > +hierarchical format.
 > +
 > +Finally, there is already excellent infrastructure for the fdt: a
 > +compiler checks the text file and converts it to a compact binary
 > +format, and a library is already available in U-Boot (libfdt) for
 > +handling this format.
 > +
 > +The dts directory contains a Makefile for building the device tree blob

The arch/<arch>/dts directories contain Makefiles ...

 > +and embedding it in your U-Boot image. This is useful since it allows
%s/your/the/

 > +U-Boot to configure itself according to what it finds there. If you have
 > +a number of similar boards with different peripherals, you can describe
 > +the features of each board in the device tree file, and have a single
 > +generic source base.
 > +
 > +To enable this feature, add CONFIG_OF_CONTROL to your board config file.
 > +
 > +
 > +What is a Flat Device Tree?

%s/Flat/Flattened/

 > +---------------------------
 > +
 > +An fdt can be specified in source format as a text file. To read about
 > +the fdt syntax, take a look at the specification (dtspec_).

Please, provide a URL link to the Devicetree Specification, Release v0.3.

 > +
 > +You also might find this section of the Linux kernel documentation
 > +useful: (access this in the Linux kernel source code)
 > +
 > +	Documentation/devicetree/booting-without-of.txt
 > +
 > +There is also a mailing list:
 > +
 > +	http://lists.ozlabs.org/listinfo/devicetree-discuss
 > +
 > +In case you are wondering, OF stands for Open Firmware.
 > +
 > +
 > +Tools
 > +-----
 > +
 > +To use this feature you will need to get the device tree compiler.

This is
"this feature" does not relate to anything. Better:

To create flattened device trees the device tree compiler is used.

 > +provided by U-Boot automatically. If you have a system version of dtc

What automatism? Better:

U-Boot comes with a copy of the device tree compiler code in /scripts/dtc/.

 > +(typically in the 'device-tree-compiler' package), it is currently
not used.

What is not used? /scripts/dtc/ or the system instance?

 > +
 > +If you want to build your own dtc, it is kept here::
 > +
 > +	git://git.kernel.org/pub/scm/utils/dtc/dtc.git
 > +
 > +For example::
 > +
 > +	$ git clone git://git.kernel.org/pub/scm/utils/dtc/dtc.git
 > +	$ cd dtc
 > +	$ make
 > +	$ sudo make install

Why should we describe this? We have the code in /scripts/dtc/. We
enable CONFIG_DTC as neeeded.

 > +
 > +Then run the compiler (your version will vary)::
 > +
 > +	$ dtc -v
 > +	Version: DTC 1.2.0-g2cb4b51f
 > +	$ make tests
 > +	$ cd tests
 > +	$ ./run_tests.sh
 > +	********** TEST SUMMARY
 > +	*     Total testcases:	1371
 > +	*                PASS:	1371
 > +	*                FAIL:	0
 > +	*   Bad configuration:	0
 > +	* Strange test result:	0
 > +
 > +You will also find a useful fdtdump utility for decoding a binary
file, as

fdtdump is deprecated. Use 'dtc -I dtb -O dts'.

 > +well as fdtget/fdtput for reading and writing properties in a binary
file.
 > +
 > +
 > +Where do I get an fdt file for my board?>
+----------------------------------------
 > +
 > +You may find that the Linux kernel has a suitable file. Look in the
 > +kernel source in arch/<arch>/boot/dts.

There is no fdt file in the kernel source.

 > +
 > +If not you might find other boards with suitable files that you can
 > +modify to your needs. Look in the board directories for files with a
 > +.dts extension.
 > +
 > +Failing that, you could write one from scratch yourself!
 > +
 > +
 > +Configuration
 > +-------------
 > +
 > +Use::
 > +
 > +   #define CONFIG_DEFAULT_DEVICE_TREE	"<name>"
 > +
 > +to set the filename of the device tree source. Then put your device tree
 > +file into::
 > +
 > +   board/<vendor>/dts/<name>.dts
 > +
 > +This should include your CPU or SOC's device tree file, placed in
 > +arch/<arch>/dts, and then make any adjustments required.
 > +
 > +If CONFIG_OF_EMBED is defined, then it will be picked up and built into
 > +the U-Boot image (including u-boot.bin). This is suitable for debugging
 > +and development only and is not recommended for production devices.
 > +
 > +If CONFIG_OF_SEPARATE is defined, then it will be built and placed in
 > +a u-boot.dtb file alongside u-boot-nodtb.bin. A common approach is
then to
 > +join the two::
 > +
 > +   cat u-boot-nodtb.bin u-boot.dtb >image.bin

All these steps will not be taken by a normal user. So this is very
confusing for him.

Please, clearly distinguish between steps a user takes who uses an
existing defconfig file and those taken by a developer.

 > +
 > +and then flash image.bin onto your board. Note that U-Boot creates
 > +u-boot-dtb.bin which does the above step for you also. Resulting
 > +u-boot.bin is a copy of u-boot-dtb.bin in this case. If you are using
 > +CONFIG_SPL_FRAMEWORK, then u-boot.img will be built to include the
device
 > +tree binary.
 > +
 > +If CONFIG_OF_BOARD is defined, a board-specific routine will provide the
 > +device tree at runtime, for example if an earlier bootloader stage
creates
 > +it and passes it to U-Boot.
 > +
 > +If CONFIG_OF_HOSTFILE is defined, then it will be read from a file on
 > +startup. This is only useful for sandbox. Use the -d flag to U-Boot to
 > +specify the file to read.
 > +
 > +You cannot use more than one of these options at the same time.
 > +
 > +To use a device tree file that you have compiled yourself, pass
 > +EXT_DTB=<filename> to 'make', as in::
 > +
 > +   make EXT_DTB=boot/am335x-boneblack-pubkey.dtb
 > +
 > +Then U-Boot will copy that file to u-boot.dtb, put it in the .img file
 > +if used, and u-boot-dtb.bin.
 > +
 > +If you wish to put the fdt at a different address in memory, you can
 > +define the "fdtcontroladdr" environment variable. This is the hex
 > +address of the fdt binary blob, and will override either of the options.
 > +Be aware that this environment variable is checked prior to relocation,
 > +when only the compiled-in environment is available. Therefore it is not
 > +possible to define this variable in the saved SPI/NAND flash
 > +environment, for example (it will be ignored). After relocation, this
 > +variable will be set to the address of the newly relocated fdt blob.
 > +It is read-only and cannot be changed. It can optionally be used to
 > +control the boot process of Linux with bootm/bootz commands.
 > +
 > +To use this, put something like this in your board header file::
 > +
 > +   #define CONFIG_EXTRA_ENV_SETTINGS	"fdtcontroladdr=10000\0"
 > +
 > +Build:
 > +
 > +After board configuration is done, fdt supported u-boot can be build
in two

%s/After/After the/

%s/build/built/

 > +ways:
 > +
 > +#  build the default dts which is defined from
CONFIG_DEFAULT_DEVICE_TREE::
 > +
 > +    $ make
 > +
 > +#  build the user specified dts file::
 > +
 > +    $ make DEVICE_TREE=<dts-file-name>
 > +
 > +
 > +Relocation, SPL and TPL
 > +-----------------------
 > +
 > +U-Boot can be divided into three phases: TPL, SPL and U-Boot proper.> +
 > +The full device tree is available to U-Boot proper, but normally
only a subset
 > +(or none at all) is available to TPL and SPL. See 'Pre-Relocation
Support' and
 > +'SPL Support' in doc/driver-model/design.rst for more details.
 > +
 > +
 > +Using several DTBs in the SPL (CONFIG_SPL_MULTI_DTB)
 > +----------------------------------------------------
 > +In some rare cases it is desirable to let SPL be able to select one
DTB among
 > +many. This usually not very useful as the DTB for the SPL is small
and usually

Quite the contrary. It is very useful to reduce the number of different
images a Linux distribution has to supply.

 > +fits several platforms. However the DTB sometimes include
information that do
 > +work on several platforms (like IO tuning parameters).
 > +In this case it is possible to use CONFIG_SPL_MULTI_DTB. This option
appends to
How does this compare to CONFIG_MULTI_DTB_FIT and CONFIG_SPL_MULTI_DTB_FIT?

 > +the SPL a FIT image containing several DTBs listed in SPL_OF_LIST.
 > +board_fit_config_name_match() is called to select the right DTB.
 > +
 > +If board_fit_config_name_match() relies on DM (DM driver to access
an EEPROM

CONFIG_SPL_MULTI_DTB seems not to be related to
board_fit_config_name_match(). It is CONFIG_$(SPL_)MULTI_DTB_FIT that
enables compiling common_fit.o.

 > +containing the board ID for example), it possible to start with a
generic DTB
 > +and then switch over to the right DTB after the detection. For this
purpose,
 > +the platform code must call fdtdec_resetup(). Based on the returned
flag, the
 > +platform may have to re-initiliaze the DM subusystem using
dm_uninit() and
 > +dm_init_and_scan().
 > +
 > +
 > +Limitations
 > +-----------
 > +
 > +U-Boot is designed to build with a single architecture type and CPU

%s/with/for/

 > +type. So for example it is not possible to build a single ARM binary
 > +which runs on your AT91 and OMAP boards, relying on an fdt to configure
 > +the various features. This is because you must select one of
 > +the CPU families within arch/arm/cpu/arm926ejs (omap or at91) at build
 > +time. Similarly you cannot build for multiple cpu types or
 > +architectures.

%s/you cannot build/U-Boot cannot be built/

It is not the user's fault.

 > +
 > +That said the complexity reduction by using fdt to support variants of
 > +boards which use the same SOC / CPU can be substantial.

This complexity reduction should be described first. The limitations
(e.g. same CPU architecture) second.

Best regards

Heinrich

 > +
 > +It is important to understand that the fdt only selects options
 > +available in the platform / drivers. It cannot add new drivers (yet). So
 > +you must still have the CONFIG option to enable the driver. For example,
 > +you need to define CONFIG_SYS_NS16550 to bring in the NS16550 driver,
 > +but can use the fdt to specific the UART clock, peripheral address, etc.
 > +In very broad terms, the CONFIG options in general control *what* driver
 > +files are pulled in, and the fdt controls *how* those files work.
 > +
 > +.. _dtspec:
https://www.power.org/resources/downloads/Power_ePAPR_APPROVED_v1.0.pdf
 > diff --git a/doc/develop/devicetree/index.rst
b/doc/develop/devicetree/index.rst
 > new file mode 100644
 > index 0000000000..fa5db3eb76
 > --- /dev/null
 > +++ b/doc/develop/devicetree/index.rst
 > @@ -0,0 +1,13 @@
 > +.. SPDX-License-Identifier: GPL-2.0+
 > +
 > +Devicetree in U-Boot
 > +====================
 > +
 > +The following holds information on how U-Boot makes use of
devicetree for
 > +build-time and runtime configuration.
 > +
 > +.. toctree::
 > +   :maxdepth: 2
 > +
 > +   intro
 > +   control
 > diff --git a/doc/develop/devicetree/intro.rst
b/doc/develop/devicetree/intro.rst
 > new file mode 100644
 > index 0000000000..344851327c
 > --- /dev/null
 > +++ b/doc/develop/devicetree/intro.rst
 > @@ -0,0 +1,4 @@
 > +.. SPDX-License-Identifier: GPL-2.0+
 > +
 > +Devicetree Introduction
 > +=======================
 > diff --git a/doc/develop/index.rst b/doc/develop/index.rst
 > index 54e14dd77b..1b90418994 100644
 > --- a/doc/develop/index.rst
 > +++ b/doc/develop/index.rst
 > @@ -10,6 +10,7 @@ Implementation
 >      :maxdepth: 1
 >
 >      commands
 > +   devicetree/index
 >      driver-model/index
 >      global_data
 >      logging
 >


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

* Re: [PATCH 2/3] doc: Update devicedocs including how to add tweaks
  2021-07-25 16:43 ` [PATCH 2/3] doc: Update devicedocs including how to add tweaks Simon Glass
@ 2021-08-01  8:47   ` Heinrich Schuchardt
  0 siblings, 0 replies; 6+ messages in thread
From: Heinrich Schuchardt @ 2021-08-01  8:47 UTC (permalink / raw)
  To: Simon Glass, U-Boot Mailing List; +Cc: Tom Rini

On 7/25/21 6:43 PM, Simon Glass wrote:
> This file is about 10 years old and the updates have not covered
> everything that has changed, particularly in the last few years. Update
> the information and add mention of the u-boot.dtsi files.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>   doc/develop/devicetree/control.rst | 107 ++++++++++++++++++++---------
>   1 file changed, 74 insertions(+), 33 deletions(-)
>
> diff --git a/doc/develop/devicetree/control.rst b/doc/develop/devicetree/control.rst
> index 1289b6156fe..ac5f7989cc6 100644
> --- a/doc/develop/devicetree/control.rst
> +++ b/doc/develop/devicetree/control.rst
> @@ -1,26 +1,27 @@
>   .. SPDX-License-Identifier: GPL-2.0+
>   .. sectionauthor:: Copyright 2011 The Chromium OS Authors
>
> -Device Tree Control in U-Boot
> -=============================
> +Devicetree Control in U-Boot
> +============================
>
>   This feature provides for run-time configuration of U-Boot via a flat

%s/flag/flattened/

> -device tree (fdt). U-Boot configuration has traditionally been done
> -using CONFIG options in the board config file. This feature aims to
> -make it possible for a single U-Boot binary to support multiple boards,
> -with the exact configuration of each board controlled by a flat device
> -tree (fdt). This is the approach recently taken by the ARM Linux kernel
> -and has been used by PowerPC for some time.
> +device tree (fdt).
> +
> +This feature aims to make it possible for a single U-Boot binary to support
> +multiple boards, with the exact configuration of each board controlled by
> +a flat device tree (fdt). This is the approach recently taken by Linux (e.g.

More than a decade ago is not recent in the software world.

> +for PowerPC and ARM).

and RISC-V

>
>   The fdt is a convenient vehicle for implementing run-time configuration
> -for three reasons. Firstly it is easy to use, being a simple text file.
> -It is extensible since it consists of nodes and properties in a nice
> -hierarchical format.
> +for three reasons:
>
> -Finally, there is already excellent infrastructure for the fdt: a
> -compiler checks the text file and converts it to a compact binary
> -format, and a library is already available in U-Boot (libfdt) for
> -handling this format.
> +- Firstly it is easy to use, being a simple text file

Nay. The flattened devicetree is a binary format.

Assume that the reader has no knowledge of devicetrees. Please, describe
that there is a text format compiled to the binary format before
referring to it.

> +- It is extensible since it consists of nodes and properties in a nice
> +  hierarchical format
> +- There is already excellent infrastructure for the fdt: a compiler checks
> +  the text file and converts it to a compact binary format, and a library
> +  is already available in U-Boot (libfdt) for handling this format\
> +- It is fairly efficient to read incrementally
>
>   The dts directory contains a Makefile for building the device tree blob
>   and embedding it in your U-Boot image. This is useful since it allows
> @@ -38,14 +39,8 @@ What is a Flat Device Tree?
>   An fdt can be specified in source format as a text file. To read about
>   the fdt syntax, take a look at the specification (dtspec_).
>
> -You also might find this section of the Linux kernel documentation
> -useful: (access this in the Linux kernel source code)
> -
> -	Documentation/devicetree/booting-without-of.txt
> -
> -There is also a mailing list:
> -
> -	http://lists.ozlabs.org/listinfo/devicetree-discuss
> +There is also a mailing list (dtlist_) for the compiler and associated
> +tools.
>
>   In case you are wondering, OF stands for Open Firmware.

But why would we use OF in symbol CONFIG_OF_CONTROL if we mean devicetree?

>
> @@ -82,8 +77,9 @@ Then run the compiler (your version will vary)::
>   	*   Bad configuration:	0
>   	* Strange test result:	0
>
> -You will also find a useful fdtdump utility for decoding a binary file, as
> -well as fdtget/fdtput for reading and writing properties in a binary file.
> +You will also find a useful `fdtdump` utility for decoding a binary file, as

fdtdump is deprecated. Use 'dtc -I dtb -O dts' instead.

> +well as `fdtget`/`fdtput` for reading and writing properties in a binary file.
> +U-Boot adds its own `fdtgrep` for creating subsets of the file.
>
>
>   Where do I get an fdt file for my board?
> @@ -109,10 +105,11 @@ Use::
>   to set the filename of the device tree source. Then put your device tree
>   file into::
>
> -   board/<vendor>/dts/<name>.dts
> +   arch/<arch>/dts/<name>.dts
>
>   This should include your CPU or SOC's device tree file, placed in
> -arch/<arch>/dts, and then make any adjustments required.
> +`arch/<arch>/dts`, and then make any adjustments required using a u-boot-dtsi
> +file for your board.
>
>   If CONFIG_OF_EMBED is defined, then it will be picked up and built into
>   the U-Boot image (including u-boot.bin). This is suitable for debugging
> @@ -122,11 +119,10 @@ If CONFIG_OF_SEPARATE is defined, then it will be built and placed in
>   a u-boot.dtb file alongside u-boot-nodtb.bin. A common approach is then to
>   join the two::
>
> -   cat u-boot-nodtb.bin u-boot.dtb >image.bin
> +   cat u-boot-nodtb.bin u-boot.dtb >u-boot.bin
>
>   and then flash image.bin onto your board. Note that U-Boot creates
> -u-boot-dtb.bin which does the above step for you also. Resulting
> -u-boot.bin is a copy of u-boot-dtb.bin in this case. If you are using
> +u-boot.bin so does the above step for you automatically. If you are using
>   CONFIG_SPL_FRAMEWORK, then u-boot.img will be built to include the device
>   tree binary.
>
> @@ -136,7 +132,8 @@ it and passes it to U-Boot.
>
>   If CONFIG_OF_HOSTFILE is defined, then it will be read from a file on
>   startup. This is only useful for sandbox. Use the -d flag to U-Boot to
> -specify the file to read.
> +specify the file to read, -D for the default and -T for the test devicetree,
> +used to run sandbox unit tests.
>
>   You cannot use more than one of these options at the same time.
>
> @@ -177,6 +174,35 @@ ways:
>       $ make DEVICE_TREE=<dts-file-name>
>
>
> +Adding tweaks for U-Boot
> +------------------------
> +
> +It is strongly recommended that devicetree files in U-Boot be an exact copy of
> +those in Linux, so that it is easy to sync them up from time to time.
> +
> +U-Boot is of course a very different project from Linux, e.g. it operates under
> +much more restrictive memory and code-size constraints. Where Linux may use a
> +full clock driver with Common Clock Format (CCF) to find the input clock to the
> +UART, U-Boot typically wants to output a banner as early as possible before too
> +much code has run.
> +
> +A second different is that U-Boot includes different phases. For SPL,

%s/different/difference/

> +constraints are even more extreme and the devicetree is shrunk to remove
> +unwanted nodes, or even turned into C code to avoid access overhead.
> +
> +U-Boot automatically looks for and incluces a file with updates to the standard

%s/incluces/includes/

> +devicetree for your board, searching for them in the same directory as the
> +main file, in this order::
> +
> +   <orig_filename>-u-boot.dtsi
> +   <CONFIG_SYS_SOC>-u-boot.dtsi
> +   <CONFIG_SYS_CPU>-u-boot.dtsi
> +   <CONFIG_SYS_VENDOR>-u-boot.dtsi
> +   u-boot.dtsi
> +
> +Only one of these is selected but of course you can #include another one within
> +that file, to create a hierarchy of shared files.
> +
>   Relocation, SPL and TPL
>   -----------------------
>
> @@ -201,7 +227,7 @@ If board_fit_config_name_match() relies on DM (DM driver to access an EEPROM
>   containing the board ID for example), it possible to start with a generic DTB
>   and then switch over to the right DTB after the detection. For this purpose,
>   the platform code must call fdtdec_resetup(). Based on the returned flag, the
> -platform may have to re-initiliaze the DM subusystem using dm_uninit() and
> +platform may have to re-initiliaze the DM subsystem using dm_uninit() and

%s/re-initiliaze/re-initialize/

>   dm_init_and_scan().
>
>
> @@ -227,4 +253,19 @@ but can use the fdt to specific the UART clock, peripheral address, etc.
>   In very broad terms, the CONFIG options in general control *what* driver
>   files are pulled in, and the fdt controls *how* those files work.
>
> -.. _dtspec: https://www.power.org/resources/downloads/Power_ePAPR_APPROVED_v1.0.pdf
> +History
> +-------
> +
> +U-Boot configuration was previous done using CONFIG options in the board
> +config file. This eventually got out of hand with nearly 10,000 options.
> +
> +U-Boot adopted devicetree around the same time as linux and early boards

%s/linux/Linux/ Linux is a proper name.

> +used it before linux (e.g. snow). The two projects developed in parallel

ditto

> +and there are still some differences in the bindings with certain boards.
> +While there has beeen dicussion of having a separate repo for devicetree

%s/dicussion/discussion/

%s/repo/repository/

> +files, in practice the kernel's repo has become the place where these are

%/kernel's repo/the Linux kernel Git repository/

Best regards

Heinrich

> +stored, with U-Boot taking copies and adding tweaks with u-boot.dtsi files.
> +
> +
> +.. _dtspec: https://www.devicetree.org/specifications/
> +.. _dtlist: https://www.spinics.net/lists/devicetree-compiler/
>


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

* Re: [PATCH 3/3] doc: Add a note about why devicetree is used
  2021-07-25 16:44 ` [PATCH 3/3] doc: Add a note about why devicetree is used Simon Glass
@ 2021-08-01  8:56   ` Heinrich Schuchardt
  0 siblings, 0 replies; 6+ messages in thread
From: Heinrich Schuchardt @ 2021-08-01  8:56 UTC (permalink / raw)
  To: Simon Glass, U-Boot Mailing List; +Cc: Tom Rini

On 7/25/21 6:44 PM, Simon Glass wrote:
> This question comes up every now and then with people coming from Linux.
> Add some notes about it so we can point to it in the mailing list.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>   doc/develop/devicetree/control.rst |  2 ++
>   doc/develop/devicetree/intro.rst   | 39 ++++++++++++++++++++++++++++++
>   2 files changed, 41 insertions(+)
>
> diff --git a/doc/develop/devicetree/control.rst b/doc/develop/devicetree/control.rst
> index ac5f7989cc6..f98faee20d1 100644
> --- a/doc/develop/devicetree/control.rst
> +++ b/doc/develop/devicetree/control.rst
> @@ -174,6 +174,8 @@ ways:
>       $ make DEVICE_TREE=<dts-file-name>
>
>
> +.. _dttweaks:
> +
>   Adding tweaks for U-Boot
>   ------------------------
>
> diff --git a/doc/develop/devicetree/intro.rst b/doc/develop/devicetree/intro.rst
> index 344851327c7..e03d8e1ae66 100644
> --- a/doc/develop/devicetree/intro.rst
> +++ b/doc/develop/devicetree/intro.rst
> @@ -2,3 +2,42 @@
>
>   Devicetree Introduction
>   =======================
> +
> +U-Boot uses devicetree for configuration. This includes the devices used by

%s/devicetree/devicetrees/ or 'uses a'

> +the board, the format of the image created with binman, which UART to use for
> +the console, public keys used for secure boot and many other things.
> +
> +See :doc:`control` for more information.
> +
> +Why does U-Boot put <thing> in the devicetree?
> +----------------------------------------------
> +
> +This question comes up a lot with people new to U-Boot, particular those coming
> +from Linux who are used to quite strict rules about what can go in the

%s/in/into/ ?

> +devicetree.
> +
> +U-Boot uses the same devicetree as Linux but adds more things necessary for the
> +bootloader environment (see :ref:`dttweaks`).
> +
> +U-Boot does not have a user space to provide policy and configuration. It cannot
> +do what Linux does and run programs and look up filesystems to figure out how to
> +boot. So configuration / runtime info go in the devicetree in U-Boot.

Do you mean 'configuration and runtime' or 'runtime configuration'?

%s/info go in/information goes into/

> +
> +Of course it is possible to:
> +
> +- add tables into the rodata

%s/rodata/rodata section of the U-Boot binary/

> +- append some info to the end of U-Boot in a different format
> +- modify the link script to bring in a file with some info in it

%s/link/linker/

> +- put things in ACPI tables

%s/in/into/ ?

> +- compile in a UEFI hand-off block structure and put things in there

%s/compile/link/ ?

> +
> +but *please don't*. In general, devicetree is the sane place to hold U-Boot's
> +configuration.
> +
> +So please...do NOT ask why U-Boot puts <thing> in the devicetree. It is the only

%s/So please.../So, please, /

Best regards

Heinrich

> +place it can go. It is a highly suitable data structure for just about anything
> +that U-Boot needs to know at runtime.
> +
> +Note, it is possible to use platdata directly so drivers avoid devicetreee in
> +SPL. But of-platdata is the modern way of avoiding devicetree overhead, so
> +please use that instead.
>


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

end of thread, other threads:[~2021-08-01  8:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-25 16:43 [PATCH 1/3] doc: Move devicetree control doc to rST Simon Glass
2021-07-25 16:43 ` [PATCH 2/3] doc: Update devicedocs including how to add tweaks Simon Glass
2021-08-01  8:47   ` Heinrich Schuchardt
2021-07-25 16:44 ` [PATCH 3/3] doc: Add a note about why devicetree is used Simon Glass
2021-08-01  8:56   ` Heinrich Schuchardt
2021-08-01  8:22 ` [PATCH 1/3] doc: Move devicetree control doc to rST Heinrich Schuchardt

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.