Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 77442C00144 for ; Fri, 29 Jul 2022 07:03:14 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CCDE584119; Fri, 29 Jul 2022 09:03:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="aKQ97ASb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4923984196; Fri, 29 Jul 2022 09:03:10 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E781C8401C for ; Fri, 29 Jul 2022 09:03:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1659078185; bh=vHp0YJ1vTCAtWqLSOCuDnmGgi3G43tTrqVHcpgDczVI=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=aKQ97ASbdxlYNAcnpraH398Sv2uO+3668BX+p0EkYM5+3ywNPCyfSpZ1XlWO2+L2n DWJzF9LGBQcyqGj2J3H8KQC/A197ynUA12ukSe3Z2f+L3AMA7scgNOatU0xgAYHaTM 8QuhUZ1TNt39kCpirBNiGvin6SDLLLInx53O2ab0= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.8.186] ([87.49.44.169]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MJmKh-1o1j733r2H-00K8fg; Fri, 29 Jul 2022 09:03:05 +0200 Message-ID: <46ebc7dd-8429-5794-bcaa-5ec2eb2d66fd@gmx.de> Date: Fri, 29 Jul 2022 09:03:00 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.1.0 Subject: Re: [RFCv2] doc: develop: Describe system configuration To: Tom Rini Cc: =?UTF-8?Q?Pali_Roh=c3=a1r?= , Simon Glass , u-boot@lists.denx.de References: <20220728185349.2039431-1-trini@konsulko.com> Content-Language: en-US From: Heinrich Schuchardt In-Reply-To: <20220728185349.2039431-1-trini@konsulko.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:l7AT7ARnP+I3FtEehT6vSMECa1lK/OzuzVWdeiR0wWZvpLSb1hX xgPVW5dtoi3ny7BnGAekjKqR+ObpEZgsk/IF7ccuW6C+sUbY2tRBGTkD+XxKyRu4eDP1Oxb fz6nS4EZgdvAIBshYSEQMDjJXn/KHnsm4OMsax9U6WfHAYBrXDtjmRO6Sh8mX+sOi6ZFClf I6EjK2cQoJD8N4pDrhBOw== X-UI-Out-Filterresults: notjunk:1;V03:K0:IiLrj37k1n4=:/cW/2ibo427pBE/ENUS5qH lhI142+j+9UoiVq8irxPIVSluRwzwe7kzJspKP7Uz7328D3Q0KNFWdQ+drqSGWE0RlgEli/dp G32Ded81HbSAS7qPapAaV6yNlv9eoEY/ZVaD8WstVIRRQwlQj9rURZACODVhUadezinGjbiss PUILRCze/zdTOF7M/Hek8cEyU8AlYxkVPnuX1oceE11mes9qZ5yzpqM2XwVzan7Kvemrs6qkT Ezgiw+EXbjdyGqIpXT4mFQzgzh2beIQh2rXWu+2CYWDdtS9CyYnPir5rJuZZVwbqOLJAVLUTR uEPWF9X+ykpLV+mdhhOJjhtfv+o5D9Wse3J/YLOCQZ2rjfNGi7I3uewKep52KgdbJ7LTHHj2L +YiCH0skXVIqqJz6abmuAauRpDjJ2WBt7Dn7sCnqBy63bixF3Y0thdg8K0DlnNO6c9FtDnQmI HiD3O4sJriEliRFd5DzKFmE+v1OVvdvjhML0dzfTVTwyVXtqUCwrg43yL8eyJi1Wxowli78Q9 Qliu09vIg+LMYct5xKCnj5UvklfMZDM2ShHvGcvK8P/bCs02vyAzQ6nSohZ0ZmNUtSduxLuoO vKuT/LTzIMorblwWfZntmZ4sRSH4G9U7m2qEBTEHu9oeJTgCOoppesiE+Q0kIb7lQXxvWV3AU QSq+V1sBc9FrMB6v0EX7owFlEgkhfPXbn6SxJEak0lnQkR70bU4ZO0TEHXA2xaaNQozuQE/PG VFM77Ky3nutmL4/etctKEeihNVuDyUxzs2ocLnn3E4qvZT5zTQpxaqqe/3dHFcstSqFr5RuZ9 o35/T3MlKBMRCrv4wfWqHrhKEWiUwSJDm8/YghB06rlx5KG7rom7+/O2MhzfauNGhxT922luL e5aqVsVr3dfjuGU+wZ1+Lj25Pa8Keyg6saYXjX5ygnQkxTlbqW2q7np92kXgXy2tCA9xZqABo xMZ77GOWCYXjvvdMZiOvAsL1eRS0eJwlsw+SgI3iwzUjbRCCqlvuSBbelg+eRjUIqgUzfD+PA 3F6Ydo+cgdPsrBI/vbeRg0TupvmVvvzdThOWTRzX0lqdcQNDOa1mrkU+hiMUUQGGjIikCaehq gmTpWocQIBOtxPbYEjX2p469RWNGMF+LXHYHziQBH9bVvhju3qicqDfzQ== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On 7/28/22 20:53, Tom Rini wrote: > Start by describing in general the best practices for how to implement > configuration of some aspect of U-Boot. This generally means finding > the right choices for when something should be static or dynamically > configured and enabled. Then further document when to use CONFIG or CFG > namespaces for static configuration. > > Signed-off-by: Tom Rini > --- > RFCv2: > - Based on Pali's feedback, remove the README section and start a new > section in this document to cover when to use each namespace. Try and > be clear about when to use "hidden" Kconfig options rather than CFG a= s > well. > - Based on Heinrich's feedback, rename this to system_configuration.rst > and include some introductory remarks on when to use some dynamic or > static configuration. Link to the driver model code for dynamic > configuration and then explain the CONFIG vs CFG namespaces for stati= c > configuration. > > RFCv1: > - This is essentially my idea on how to better handle the problem of > CONFIG values that just don't fit in Kconfig because it makes much > more sense to define them statically for a given SoC or calculate the= m > from other values, and so on. One example here would be to revert > c7fad78ec0ee ("Convert CONFIG_SYS_BR0_PRELIM et al to Kconfig") and > re-name these to CFG_SYS_.. instead. Another big example here would b= e > a global search-and-replace of 's/CONFIG_HPS_/CFG_HPS_/g' as that's > all tool-generated. Not all CONFIG_SYS_ options would get this as > boolean choices are well handled in Kconfig, and that may not be clea= r > enough in what I wrote here? > --- > README | 21 ----- > doc/develop/index.rst | 1 + > doc/develop/system_configuration.rst | 121 +++++++++++++++++++++++++++ > 3 files changed, 122 insertions(+), 21 deletions(-) > create mode 100644 doc/develop/system_configuration.rst > > diff --git a/README b/README > index 2c4bde0b3297..623f35907217 100644 > --- a/README > +++ b/README > @@ -166,27 +166,6 @@ Directory Hierarchy: > Software Configuration: > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > -Configuration is usually done using C preprocessor defines; the > -rationale behind that is to avoid dead code whenever possible. > - > -There are two classes of configuration variables: > - > -* Configuration _OPTIONS_: > - These are selectable by the user and have names beginning with > - "CONFIG_". > - > -* Configuration _SETTINGS_: > - These depend on the hardware etc. and should not be meddled with if > - you don't know what you're doing; they have names beginning with > - "CONFIG_SYS_". > - > -Previously, all configuration was done by hand, which involved creating > -symbolic links and editing configuration files manually. More recently, > -U-Boot has added the Kbuild infrastructure used by the Linux kernel, > -allowing you to use the "make menuconfig" command to configure your > -build. > - > - > Selection of Processor Architecture and Board Type: > --------------------------------------------------- > > diff --git a/doc/develop/index.rst b/doc/develop/index.rst > index 73741ceb6a2f..7c41e3f1b6e5 100644 > --- a/doc/develop/index.rst > +++ b/doc/develop/index.rst > @@ -13,6 +13,7 @@ General > designprinciples > process > release_cycle > + system_configuration > > Implementation > -------------- > diff --git a/doc/develop/system_configuration.rst b/doc/develop/system_c= onfiguration.rst > new file mode 100644 > index 000000000000..bb09d1f974d4 > --- /dev/null > +++ b/doc/develop/system_configuration.rst > @@ -0,0 +1,121 @@ > +.. SPDX-License-Identifier: GPL-2.0+ > + > +U-Boot system configuration Thanks Tom for adding this helpful text on configuration. Overall we should even more move the focus from "namespace" to configuration mechanism. See below. %s/U-Boot system/System/ We know that we are talking about U-Boot. > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > + > +There are a number of different aspects to configuring U-Boot to build = and then > +run on a given platform or set of platforms. Broadly speaking, some asp= ects of > +the world can be configured at run time and others must be done at buil= d time. > +In general run time is preferred over build time. But when making these %s/run time/run time configuration/ %s/build time/build time configuration/ > +decision, we also need to consider if we're talking about feature that = could be %s/decision/decisions/ %s/feature/a feature/ > +useful to virtually every platform or something specific to a single ha= rdware > +platform. The resulting image size is also another important considerat= ion. > +Finally, the overall requirements of being able to do run time detectio= n will > +have an impact on if it's possible or not. I guess you mean that run time detection is not always feasible? How about= : "Run time detection depends on the physical hardware and may not always be possible." > + > +When adding new features to U-Boot, be they a new subsystem or SoC supp= ort or > +new platform for an existing supported SoC, the preferred configuration= order > +is: > + > +#. Simple run time. One example here are chip revision checks. Another = is %s/Simple run time\./Run time feature detection./ > + knowing that we've checked GPIOs and are on revision B of a platform= , rather Do you mean: "On some boards the revision may be detected by reading GPIOs."? > + than doing a more expensive device tree check. This allows us to use= a single > + device tree for revision A and B in this case and perform fixups as = needed > + rather than storing two device trees. > + > +#. Making use of our Kconfig infrastructure and the ``CONFIG`` namespac= e. The > + primary method of build time configuration is done via the ``CONFIG`= ` > + namespace and Kconfig infrastructure. This is generally the best fit= for when > + we want to enable or disable some sort of feature, such as the SoC o= r network > + support. > + > +#. Making use of the :doc:`device tree ` to determi= ne at > + run time how to configure a feature that we have enabled via Kconfig= . For > + example, we would use Kconfig to enable an i2c chip driver, but the = device > + tree to know where the i2c chip resides in memory and other details = we need > + in order to configure the bus. > + > +#. Making use of C header files directly and the ``CFG`` namespace. Thi= s is > + useful when for various reasons we cannot get configuration values t= hat we > + need from the device tree so instead have them defined in a header a= nd use > + the prefix ``CFG_`` in their definition. > + > +Dynamic run time configuration methods. > +--------------------------------------- > + > +For more information in general on how to make use of this please start= with the > +:doc:`driver model ` documentation. > + > +Static build time configuration methods > +--------------------------------------- > + > +There are two namespaces used to control the build time configuration o= f The focus on the word 'namespaces' does not provide clarity here. The choice is between: * defining configuration variables via Kconfig * defining configuration variables via headers files The namespace thing is secondary to this choice. > +U-Boot, ``CONFIG`` and ``CFG``. These are used when it is either not po= ssible > +or not practical to make a run time determination about some functional= ity of > +the hardware or a required software feature or similar. Each of these h= as their > +own places where they are better suited than the other for use. > + > +The first of these, ``CONFIG``` is managed in the `Kconfig language > +`_= that is > +most commonly associated with the Linux kernel and the Kconfig files fo= und > +throughout our sources. Adding options to this namespace is the preferr= ed way of > +exposing new configuration options as there are a number of ways for bo= th users > +and system integrators to manage and change these options. Some common = examples > +here are to enable a specific command within U-Boot or even a whole sub= system > +such as NAND flash or network connectivity. > + > +The second of these, ``CFG`` is implemented directly as C preprocessor = values or > +macros, depending on what they are in turn describing. The nature of U-= Boot > +means that while we have some functionality that is very reasonable to = expose to %s/The nature of U-Boot means that while/While/ The removed words do not add clarity. > +the end user to enable or disable we have other places where we need to= describe > +things such as register locations or values, memory map ranges and so o= n. When > +practical, we should be getting these values from the device tree . How= ever, %s/tree \./tree./ > +there are cases where this is either not practical due to when we need = the > +information and may not have a device tree yet or due to legacy reasons= code has > +not been rewritten. > + > +When to use each namespace > +^^^^^^^^^^^^^^^^^^^^^^^^^^ The paragraphs below are not about namespaces but about when to use Kconfig and when to use arch/Soc/board specific constants defined in headers. > + > +While there are some cases where it should be fairly obvious where to u= se each > +namespace, as for example a command would be ``CONFIG`` and a header of= values > +generated by an external tool should be ``CFG`` there will be cases whe= re it's > +less clear and one needs to take care when implementing. In general, > +configuration *options* should be ``CONFIG`` and configuration *setting= s* should > +be ``CFG``. Since it is not always clear however, let us discuss things= to > +keep in mind when adding to either namespace. Why can't we make this is a hard rule: If it is in Kconfig it is CONFIG_. It is is not in Kconfig it is CFG_ Nothing comes to my mind where such a rule cannot be applied. > + > +A thing to keep in mind is that we have a strong preference for using t= he > +``CONFIG`` namespace first. Options expressed this way let us make use = of the The usage of namespace is irritating me here. "We prefer to use Kconfig." Best regards Heinrich > +Kconfig language to express dependencies and abstractions. Consider the= example > +of a SHA256 hardware acceleration engine. This would be a feature of th= e SoC and > +so something to not ask the user if it exists, but we would want to hav= e our > +generic framework for such engines be optionally available and depend o= n knowing > +we have this engine on a given hardware platform. Expressing this shoul= d be done > +as a hidden symbol that is ``select``'ed by the SoC symbol which would = in turn > +be ``select``'ed by the board option, which is user visible. This means= that > +hardware features that are either present or not present should be in t= he > +``CONFIG`` namespace and in a similar manner, features which will alway= s have a > +constant value such as "this SoC always has 4 cores and 4 threads per c= ore" > +should be as well. > + > +This brings us to differentiating between a configuration *setting* ver= sus a > +hardware feature. To build on the previous example, while we may know t= he number > +of cores and threads, it's possible that within a given family of SoCs = the base > +addresses of peripherals has changed, but the register offsets within h= ave not. > +And for practical reasons, we cannot get this information at run time f= rom the > +device tree. This is a case where it is reasonable to instead make use = of the > +``CFG`` namespace and that it is pure C preprocessor macros to define t= hat > +``CFG_SYS_FOO_REG`` is ``(CFG_SYS_FOO_BASE + 0x200)`` and have blocks o= f those > +under ``#if defined(CONFIG_SOC_FOO1) ... #elif defined(CONFIG_SOC_FOO2)= ... > +#endif`` in a system header file. Another example here is register valu= es. Often > +it will make the most sense to construct these from other values and th= en using > +masks and shifts to turn a list of "magic values" in to something that = is easier > +for humans to parse as well. > + > +When it has been determined that the practical solution for where to ha= ve > +something is in the ``CFG`` namespace, the next decision is where to pl= ace these > +settings. It is strongly encouraged to place these in the architecture = header > +files, if they are generic to a given SoC, or under the board directory= if board > +specific. Placing them under the board.h file in the *include/configs/* > +directory should be seen as a last resort.