1Contributor's Guide
2*******************
3
4Getting Started
5===============
6
7-  Make sure you have a Github account and you are logged on to
8   `review.trustedfirmware.org`_.
9
10   Also make sure that you have registered your full name and email address in
11   your `review.trustedfirmware.org`_ profile. Otherwise, the Gerrit server
12   might reject patches you attempt to post for review.
13
14-  If you plan to contribute a major piece of work, it is usually a good idea to
15   start a discussion around it on the `TF-A mailing list`_. This gives everyone
16   visibility of what is coming up, you might learn that somebody else is
17   already working on something similar or the community might be able to
18   provide some early input to help shaping the design of the feature.
19
20   If you intend to include Third Party IP in your contribution, please mention
21   it explicitly in the email thread and ensure that the changes that include
22   Third Party IP are made in a separate patch (or patch series).
23
24-  Clone the Trusted Firmware-A source code on your own machine as described in
25   :ref:`prerequisites_get_source`.
26
27-  Create a local topic branch based on the Trusted Firmware-A ``master``
28   branch.
29
30Making Changes
31==============
32
33-  Ensure commits adhere to the project's :ref:`Commit Style`.
34
35-  Make commits of logical units. See these general `Git guidelines`_ for
36   contributing to a project.
37
38-  Keep the commits on topic. If you need to fix another bug or make another
39   enhancement, please address it on a separate topic branch.
40
41-  Split the patch in manageable units. Small patches are usually easier to
42   review so this will speed up the review process.
43
44-  Avoid long commit series. If you do have a long series, consider whether
45   some commits should be squashed together or addressed in a separate topic.
46
47-  Follow the :ref:`Coding Style` and :ref:`Coding Guidelines`.
48
49   -  Use the checkpatch.pl script provided with the Linux source tree. A
50      Makefile target is provided for convenience, see :ref:`this
51      section<automatic-compliance-checking>` for more details.
52
53-  Where appropriate, please update the documentation.
54
55   -  Consider whether the :ref:`Porting Guide`, :ref:`Firmware Design` document
56      or other in-source documentation needs updating.
57
58   -  If you are submitting new files that you intend to be the code owner for
59      (for example, a new platform port), then also update the
60      :ref:`code owners` file.
61
62   -  For topics with multiple commits, you should make all documentation changes
63      (and nothing else) in the last commit of the series. Otherwise, include
64      the documentation changes within the single commit.
65
66.. _copyright-license-guidance:
67
68-  Ensure that each changed file has the correct copyright and license
69   information. Files that entirely consist of contributions to this project
70   should have a copyright notice and BSD-3-Clause SPDX license identifier of
71   the form as shown in :ref:`license`. Files that contain changes to imported
72   Third Party IP files should retain their original copyright and license
73   notices.
74
75   For significant contributions you may add your own copyright notice in the
76   following format:
77
78   ::
79
80       Portions copyright (c) [XXXX-]YYYY, <OWNER>. All rights reserved.
81
82   where XXXX is the year of first contribution (if different to YYYY) and YYYY
83   is the year of most recent contribution. <OWNER> is your name or your company
84   name.
85
86-  Ensure that each patch in the patch series compiles in all supported
87   configurations. Patches which do not compile will not be merged.
88
89-  Please test your changes. As a minimum, ensure that Linux boots on the
90   Foundation FVP. See :ref:`Arm Fixed Virtual Platforms (FVP)` for more
91   information. For more extensive testing, consider running the `TF-A Tests`_
92   against your patches.
93
94-  Ensure that all CI automated tests pass. Failures should be fixed. They might
95   block a patch, depending on how critical they are.
96
97Submitting Changes
98==================
99
100.. note::
101   Please follow the `How to Contribute Code`_ section of the OpenCI
102   documentation for general instructions on setting up Gerrit and posting
103   patches there. The rest of this section provides details about patch
104   submission rules specifically for the TF-A project.
105
106-  Submit your changes for review using the ``git review`` command.
107
108   This will automatically rebase them onto the upstream ``integration`` branch,
109   as required by TF-A's patch submission process.
110
111-  From the Gerrit web UI, add reviewers for your patch:
112
113   -  At least one code owner for each module modified by the patch. See the
114      list of modules and their :ref:`code owners`.
115
116   -  At least one maintainer. See the list of :ref:`maintainers`.
117
118   -  If some module has no code owner, try to identify a suitable (non-code
119      owner) reviewer. Running ``git blame`` on the module's source code can
120      help, as it shows who has been working the most recently on this area of
121      the code.
122
123      Alternatively, if it is impractical to identify such a reviewer, you might
124      send an email to the `TF-A mailing list`_ to broadcast your review request
125      to the community.
126
127   Note that self-reviewing a patch is prohibited, even if the patch author is
128   the only code owner of a module modified by the patch. Getting a second pair
129   of eyes on the code is essential to keep up with the quality standards the
130   project aspires to.
131
132-  The changes will then undergo further review by the designated people. Any
133   review comments will be made directly on your patch. This may require you to
134   do some rework. For controversial changes, the discussion might be moved to
135   the `TF-A mailing list`_ to involve more of the community.
136
137   Refer to the `Gerrit Uploading Changes documentation`_ for more details.
138
139-  The patch submission rules are the following. For a patch to be approved
140   and merged in the tree, it must get:
141
142   -  One ``Code-Owner-Review+1`` for each of the modules modified by the patch.
143   -  A ``Maintainer-Review+1``.
144
145   In the case where a code owner could not be found for a given module,
146   ``Code-Owner-Review+1`` is substituted by ``Code-Review+1``.
147
148   In addition to these various code review labels, the patch must also get a
149   ``Verified+1``. This is usually set by the Continuous Integration (CI) bot
150   when all automated tests passed on the patch. Sometimes, some of these
151   automated tests may fail for reasons unrelated to the patch. In this case,
152   the maintainers might (after analysis of the failures) override the CI bot
153   score to certify that the patch has been correctly tested.
154
155   In the event where the CI system lacks proper tests for a patch, the patch
156   author or a reviewer might agree to perform additional manual tests
157   in their review and the reviewer incorporates the review of the additional
158   testing in the ``Code-Review+1`` or ``Code-Owner-Review+1`` as applicable to
159   attest that the patch works as expected. Where possible additional tests should
160   be added to the CI system as a follow up task. For example, for a
161   platform-dependent patch where the said platform is not available in the CI
162   system's board farm.
163
164-  When the changes are accepted, the :ref:`maintainers` will integrate them.
165
166   -  Typically, the :ref:`maintainers` will merge the changes into the
167      ``integration`` branch.
168
169   -  If the changes are not based on a sufficiently-recent commit, or if they
170      cannot be automatically rebased, then the :ref:`maintainers` may rebase it
171      on the ``integration`` branch or ask you to do so.
172
173   -  After final integration testing, the changes will make their way into the
174      ``master`` branch. If a problem is found during integration, the
175      :ref:`maintainers` will request your help to solve the issue. They may
176      revert your patches and ask you to resubmit a reworked version of them or
177      they may ask you to provide a fix-up patch.
178
179Add CI Configurations
180=====================
181
182TF-A uses Jenkins for Continuous Integration and testing activities. Various CI
183jobs are deployed to run tests on every patch before being merged. Each of your
184patches go through a series of checks before they get merged on to the master
185branch. Kindly ensure that every time you add new files under your platform,
186they are covered by the following two sections.
187
188Coverity Scan
189-------------
190
191The TF-A project makes use of `Coverity Scan` for static analysis, a service
192offered by Synopsys for open-source projects. This tool is able to find defects
193and vulnerabilities in a code base, such as dereferences of NULL pointers, use
194of uninitialized data, control flow issues and many other things.
195
196The TF-A source code is submitted daily to this service for analysis. Results of
197the latest and previous scans, as well as the complete list of defects it
198detected, are accessible online from
199https://scan.coverity.com/projects/arm-software-arm-trusted-firmware.
200
201The `tf-a-ci-scripts repository`_ contains scripts to run the Coverity Scan
202tools on the integration branch of the TF-A code base and make them available on
203https://scan.coverity.com. These scripts get executed daily by the
204`tf-a-coverity Jenkins job`_.
205
206In order to maintain a high level of coverage, including on newly introduced
207code, it is important to maintain the appropriate TF-A CI scripts. Details of
208when to update these scripts and how to do so follow.
209
210We maintain a build script - ``tf-cov-make`` - which contains the build
211configurations of various platforms in order to cover the entire source code
212being analysed by Coverity.
213
214When you submit your patches for review, and if they contain new source files,
215`TF-A CI static checks job`_ might report that these files are not covered. In
216this case, the job's console output will show the following error message::
217
218   ****** Newly added files detection check for Coverity Scan analysis on patch(es) ******
219
220   Result : FAILURE
221
222   New source files have been identified in your patch..
223   some/dir/file.c
224
225   please ensure to include them for the ``Coverity Scan analysis`` by adding
226   the respective build configurations in the ``tf-cov-make`` build script.
227
228In this section you find the details on how to append your new build
229configurations for Coverity scan analysis illustrated with examples:
230
231#. We maintain a separate repository named `tf-a-ci-scripts repository`_
232   for placing all the test scripts which will be executed by the CI Jobs.
233
234#. In this repository, ``tf-cov-make`` script is located at
235   ``tf-a-ci-scripts/script/tf-coverity/tf-cov-make``
236
237#. Edit the `tf-cov-make`_ script by appending all the possible build
238   configurations with the specific build flags relevant to your platform, so
239   that newly added source files get built and analysed by Coverity.
240
241#. For better understanding follow the below specified examples listed in the
242   ``tf-cov-make`` script.
243
244.. code:: shell
245
246    Example 1:
247    #Intel
248    make PLAT=stratix10 $(common_flags) all
249    make PLAT=agilex $(common_flags) all
250
251-  In the above example there are two different SoCs ``stratix`` and ``agilex``
252   under the Intel platform and the build configurations has been added suitably
253   to include most of their source files.
254
255.. code:: shell
256
257    Example 2:
258    #Hikey
259    make PLAT=hikey $(common_flags) ${TBB_OPTIONS} ENABLE_PMF=1 all
260    make PLAT=hikey960 $(common_flags) ${TBB_OPTIONS} all
261    make PLAT=poplar $(common_flags) all
262
263-  In this case for ``Hikey`` boards additional build flags have been included
264   along with the ``common_flags`` to cover most of the files relevant to it.
265
266-  Similar to this you can still find many other different build configurations
267   of various other platforms listed in the ``tf-cov-make`` script. Kindly refer
268   them and append your build configurations respectively.
269
270Test Build Configurations
271-------------------------
272
273We have CI jobs which run a set of test configurations on every TF-A patch
274before they get merged upstream.
275
276At the bare minimum, TF-A code should build without any errors for every
277supported platform - and every feature of this platform. To make sure this is
278the case, we maintain a set of build tests. ``tf-l1-build-plat`` is the test
279group which holds all build tests for all platforms. So be kind enough to
280verify that your newly added files are covered by such a build test.
281
282If this is not the case, please follow the instructions below to add the
283appropriate files. We will illustrate this with an example for the ``Hikey``
284platform.
285
286-  In the `tf-a-ci-scripts repository`_ we need to add a build configuration file
287   ``hikey-default`` under ``tf_config/`` folder. ``tf_config/hikey-default``
288   must list all the build parameters relevant to it.
289
290.. code:: shell
291
292   # Hikey Build Parameters
293   CROSS_COMPILE=aarch64-none-elf-
294   PLAT=hikey
295
296-  Further another file, ``hikey-default:nil``, needs to be added under
297   ``group/tf-l1-build-plat/`` folder to allow the platform to be built as part
298   of this test group. ``group/tf-l1-build-plat/hikey-default:nil`` file just
299   needs to exist but does not contain anything meaningful, apart from a
300   mandatory copyright notice:
301
302.. code:: shell
303
304   #
305   # Copyright (c) 2019-2022 Arm Limited. All rights reserved.
306   #
307   # SPDX-License-Identifier: BSD-3-Clause
308   #
309
310-  As illustrated above, you need to add similar files supporting your platform.
311
312For a more elaborate explanation of the TF-A CI scripts internals, including how
313to add more complex tests beyond a simple build test, please refer to the `TF-A
314CI scripts overview`_ section of the OpenCI documentation.
315
316Binary Components
317=================
318
319-  Platforms may depend on binary components submitted to the `Trusted Firmware
320   binary repository`_ if they require code that the contributor is unable or
321   unwilling to open-source. This should be used as a rare exception.
322-  All binary components must follow the contribution guidelines (in particular
323   licensing rules) outlined in the `readme.rst <tf-binaries-readme_>`_ file of
324   the binary repository.
325-  Binary components must be restricted to only the specific functionality that
326   cannot be open-sourced and must be linked into a larger open-source platform
327   port. The majority of the platform port must still be implemented in open
328   source. Platform ports that are merely a thin wrapper around a binary
329   component that contains all the actual code will not be accepted.
330-  Only platform port code (i.e. in the ``plat/<vendor>`` directory) may rely on
331   binary components. Generic code must always be fully open-source.
332
333--------------
334
335*Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved.*
336
337.. _review.trustedfirmware.org: https://review.trustedfirmware.org
338.. _Git guidelines: http://git-scm.com/book/ch5-2.html
339.. _Gerrit Uploading Changes documentation: https://review.trustedfirmware.org/Documentation/user-upload.html
340.. _TF-A Tests: https://trustedfirmware-a-tests.readthedocs.io
341.. _Trusted Firmware binary repository: https://review.trustedfirmware.org/admin/repos/tf-binaries
342.. _tf-binaries-readme: https://git.trustedfirmware.org/tf-binaries.git/tree/readme.rst
343.. _TF-A mailing list: https://lists.trustedfirmware.org/mailman3/lists/tf-a.lists.trustedfirmware.org/
344.. _tf-a-ci-scripts repository: https://git.trustedfirmware.org/ci/tf-a-ci-scripts.git/
345.. _tf-cov-make: https://git.trustedfirmware.org/ci/tf-a-ci-scripts.git/tree/script/tf-coverity/tf-cov-make
346.. _How to Contribute Code: https://tf-ci-users-guide.readthedocs.io/en/latest/#how-to-contribute-code
347.. _TF-A CI scripts overview: https://tf-ci-users-guide.readthedocs.io/en/latest/#tf-a-ci-scripts-overview
348.. _tf-a-coverity Jenkins job: https://ci.trustedfirmware.org/job/tf-a-coverity/
349.. _TF-A CI static checks job: https://ci.trustedfirmware.org/job/tf-a-static-checks/
350