1.. _contribute_guidelines:
2
3Contribution Guidelines
4#######################
5
6As an open-source project, we welcome and encourage the community to submit
7patches directly to the project.  In our collaborative open source environment,
8standards and methods for submitting changes help reduce the chaos that can result
9from an active development community.
10
11This document explains how to participate in project conversations, log bugs
12and enhancement requests, and submit patches to the project so your patch will
13be accepted quickly in the codebase.
14
15
16Prerequisites
17*************
18
19.. _Zephyr Project website: https://zephyrproject.org
20
21As a contributor, you'll want to be familiar with the Zephyr project, how to
22configure, install, and use it as explained in the `Zephyr Project website`_
23and how to set up your development environment as introduced in the Zephyr
24:ref:`getting_started`.
25
26You should be familiar with common developer tools such as Git and CMake, and
27platforms such as GitHub.
28
29If you haven't already done so, you'll need to create a (free) GitHub account
30on https://github.com and have Git tools available on your development system.
31
32.. note::
33   The Zephyr development workflow supports all 3 major operating systems
34   (Linux, macOS, and Windows) but some of the tools used in the sections below
35   are only available on Linux and macOS. On Windows, instead of running these
36   tools yourself, you will need to rely on the Continuous Integration (CI)
37   service using Github Actions, which runs automatically on GitHub when you submit
38   your Pull Request (PR).  You can see any failure results in the workflow
39   details link near the end of the PR conversation list. See
40   `Continuous Integration`_ for more information
41
42
43.. _licensing_requirements:
44
45Licensing
46*********
47
48Licensing is very important to open source projects. It helps ensure the
49software continues to be available under the terms that the author desired.
50
51.. _Apache 2.0 license:
52   https://github.com/zephyrproject-rtos/zephyr/blob/main/LICENSE
53
54.. _GitHub repo: https://github.com/zephyrproject-rtos/zephyr
55
56Zephyr uses the `Apache 2.0 license`_ (as found in the LICENSE file in
57the project's `GitHub repo`_) to strike a balance between open
58contribution and allowing you to use the software however you would like
59to.  The Apache 2.0 license is a permissive open source license that
60allows you to freely use, modify, distribute and sell your own products
61that include Apache 2.0 licensed software.  (For more information about
62this, check out articles such as `Why choose Apache 2.0 licensing`_ and
63`Top 10 Apache License Questions Answered`_).
64
65.. _Why choose Apache 2.0 licensing:
66   https://www.zephyrproject.org/faqs/#1571346989065-9216c551-f523
67
68.. _Top 10 Apache License Questions Answered:
69   https://www.whitesourcesoftware.com/whitesource-blog/top-10-apache-license-questions-answered/
70
71A license tells you what rights you have as a developer, as provided by the
72copyright holder. It is important that the contributor fully understands the
73licensing rights and agrees to them. Sometimes the copyright holder isn't the
74contributor, such as when the contributor is doing work on behalf of a
75company.
76
77Components using other Licenses
78===============================
79
80There are some imported or reused components of the Zephyr project that
81use other licensing, as described in :ref:`Zephyr_Licensing`.
82
83Importing code into the Zephyr OS from other projects that use a license
84other than the Apache 2.0 license needs to be fully understood in
85context and approved by the Zephyr governing board.
86
87By carefully reviewing potential contributions and also enforcing a
88:ref:`DCO` for contributed code, we can ensure that
89the Zephyr community can develop products with the Zephyr Project
90without concerns over patent or copyright issues.
91
92See :ref:`external-contributions` for more information about
93this contributing and review process for imported components.
94
95.. only:: latex
96
97   .. toctree::
98      :maxdepth: 1
99
100      ../LICENSING.rst
101
102.. _copyrights:
103
104Copyrights Notices
105******************
106
107The Zephyr Project follows the `Community Best Practice`_ for Copyright Notices from the Linux
108Foundation.
109
110We recommend using the following copyright notice:
111
112.. code-block:: C
113
114    Copyright The Zephyr Project Contributors
115
116.. _Community Best Practice:
117   https://www.linuxfoundation.org/blog/copyright-notices-in-open-source-software-projects/
118
119.. _DCO:
120
121Developer Certification of Origin (DCO)
122***************************************
123
124To make a good faith effort to ensure licensing criteria are met, the Zephyr
125project requires the Developer Certificate of Origin (DCO) process to be
126followed.
127
128The DCO is an attestation attached to every contribution made by every
129developer. In the commit message of the contribution, (described more fully
130later in this document), the developer simply adds a ``Signed-off-by``
131statement and thereby agrees to the DCO.
132
133When a developer submits a patch, it is a commitment that the contributor has
134the right to submit the patch per the license.  The DCO agreement is shown
135below and at https://developercertificate.org/.
136
137.. code-block:: none
138
139    Developer's Certificate of Origin 1.1
140
141    By making a contribution to this project, I certify that:
142
143    (a) The contribution was created in whole or in part by me and I
144        have the right to submit it under the open source license
145        indicated in the file; or
146
147    (b) The contribution is based upon previous work that, to the
148        best of my knowledge, is covered under an appropriate open
149        source license and I have the right under that license to
150        submit that work with modifications, whether created in whole
151        or in part by me, under the same open source license (unless
152        I am permitted to submit under a different license), as
153        Indicated in the file; or
154
155    (c) The contribution was provided directly to me by some other
156        person who certified (a), (b) or (c) and I have not modified
157        it.
158
159    (d) I understand and agree that this project and the contribution
160        are public and that a record of the contribution (including
161        all personal information I submit with it, including my
162        sign-off) is maintained indefinitely and may be redistributed
163        consistent with this project or the open source license(s)
164        involved.
165
166DCO Sign-Off
167============
168
169The "sign-off" in the DCO is a "Signed-off-by:" line in each commit's log
170message. The Signed-off-by: line must be in the following format::
171
172   Signed-off-by: Your Name <your.email@example.com>
173
174For your commits, replace:
175
176- ``Your Name`` with your legal name (pseudonyms, hacker handles, and the
177  names of groups are not allowed)
178
179- ``your.email@example.com`` with the real email address you are using to
180  author the commit. Pseudo or anonymized emails such as
181  ``you-id+your-username@users.noreply.github.com`` are not allowed. The
182  email must match the one you use to author the commit (CI will fail if
183  there is no match).
184
185You can automatically add the Signed-off-by: line to your commit body using
186``git commit -s``. Use other commits in the zephyr git history as examples.
187See :ref:`git_setup` for instructions on configuring user and email settings
188in Git.
189
190Additional requirements:
191
192- If you are altering an existing commit created by someone else, you must add
193  your Signed-off-by: line without removing the existing one.
194
195.. _source_tree_v2:
196
197Source Tree Structure
198*********************
199
200To clone the main Zephyr Project repository use the instructions in
201:ref:`get_the_code`.
202
203This section describes the main repository's source tree. In addition to the
204Zephyr kernel itself, you'll also find the sources for technical documentation,
205sample code, supported board configurations, and a collection of subsystem
206tests.  All of these are available for developers to contribute to and enhance.
207
208Understanding the Zephyr source tree can help locate the code
209associated with a particular Zephyr feature.
210
211At the top of the tree, several files are of importance:
212
213:file:`CMakeLists.txt`
214    The top-level file for the CMake build system, containing a lot of the
215    logic required to build Zephyr.
216
217:file:`Kconfig`
218    The top-level Kconfig file, which refers to the file :file:`Kconfig.zephyr`
219    also found in the top-level directory.
220
221    See :ref:`the Kconfig section of the manual <kconfig>` for detailed Kconfig
222    documentation.
223
224:file:`west.yml`
225    The :ref:`west` manifest, listing the external repositories managed by
226    the west command-line tool.
227
228The Zephyr source tree also contains the following top-level
229directories, each of which may have one or more additional levels of
230subdirectories not described here.
231
232:file:`arch`
233    Architecture-specific kernel and system-on-chip (SoC) code.
234    Each supported architecture (for example, x86 and ARM)
235    has its own subdirectory,
236    which contains additional subdirectories for the following areas:
237
238    * architecture-specific kernel source files
239    * architecture-specific kernel include files for private APIs
240
241:file:`soc`
242    SoC related code and configuration files.
243
244:file:`boards`
245    Board related code and configuration files.
246
247:file:`doc`
248    Zephyr technical documentation source files and tools used to
249    generate the https://docs.zephyrproject.org web content.
250
251:file:`drivers`
252    Device driver code.
253
254:file:`dts`
255    :ref:`devicetree <dt-guide>` source files used to describe non-discoverable
256    board-specific hardware details.
257
258:file:`include`
259    Include files for all public APIs, except those defined under :file:`lib`.
260
261:file:`kernel`
262    Architecture-independent kernel code.
263
264:file:`lib`
265    Library code, including the minimal standard C library.
266
267:file:`misc`
268    Miscellaneous code that doesn't belong to any of the other top-level
269    directories.
270
271:file:`samples`
272    Sample applications that demonstrate the use of Zephyr features.
273
274:file:`scripts`
275    Various programs and other files used to build and test Zephyr
276    applications.
277
278:file:`cmake`
279    Additional build scripts needed to build Zephyr.
280
281:file:`subsys`
282    Subsystems of Zephyr, including:
283
284    * USB device stack code
285    * Networking code, including the Bluetooth stack and networking stacks
286    * File system code
287    * Bluetooth host and controller
288
289:file:`tests`
290    Test code and benchmarks for Zephyr features.
291
292:file:`share`
293    Additional architecture independent data. It currently contains Zephyr's CMake
294    package.
295
296Pull Requests and Issues
297************************
298
299.. _Zephyr Project Issues: https://github.com/zephyrproject-rtos/zephyr/issues
300
301.. _open pull requests: https://github.com/zephyrproject-rtos/zephyr/pulls
302
303.. _Zephyr devel mailing list: https://lists.zephyrproject.org/g/devel
304
305.. _Zephyr Discord Server: https://chat.zephyrproject.org
306
307Before starting on a patch, first check in our issues `Zephyr Project Issues`_
308system to see what's been reported on the issue you'd like to address.  Have a
309conversation on the `Zephyr devel mailing list`_ (or the `Zephyr Discord
310Server`_) to see what others think of your issue (and proposed solution).  You
311may find others that have encountered the issue you're finding, or that have
312similar ideas for changes or additions.  Send a message to the `Zephyr devel
313mailing list`_ to introduce and discuss your idea with the development
314community.
315
316It's always a good practice to search for existing or related issues before
317submitting your own. When you submit an issue (bug or feature request), the
318triage team will review and comment on the submission, typically within a few
319business days.
320
321You can find all `open pull requests`_ on GitHub and open `Zephyr Project
322Issues`_ in Github issues.
323
324.. _git_setup:
325
326Git Setup
327*********
328
329We need to know who you are, and how to contact you. To add this
330information to your Git installation, set the Git configuration
331variables ``user.name`` to your full name, and ``user.email`` to your
332email address.
333
334For example, if your name is ``Zephyr Developer`` and your email
335address is ``z.developer@example.com``:
336
337.. code-block:: console
338
339   git config --global user.name "Zephyr Developer"
340   git config --global user.email "z.developer@example.com"
341
342.. note::
343   ``user.name`` must be your full name (first and last at minimum), not a
344   pseudonym or hacker handle. The email address that you use in your Git configuration must match the email
345   address you use to sign your commits. If they don't match, the CI system will
346   fail your pull request.
347
348   If you intend to edit commits using the Github.com UI, ensure that your github profile
349   ``email address`` and profile ``name`` also match those used in your git configuration
350   (``user.name`` & ``user.email``).
351
352Pull Request Guidelines
353***********************
354When opening a new Pull Request, adhere to the following guidelines to ensure
355compliance with Zephyr standards and facilitate the review process.
356
357If in doubt, it's advisable to explore existing Pull Requests within the Zephyr
358repository. Use the search filters and labels to locate PRs related to changes
359similar to the ones you are proposing.
360
361.. _commit-guidelines:
362
363Commit Message Guidelines
364=========================
365
366Changes are submitted as Git commits. Each commit has a *commit
367message* describing the change. Acceptable commit messages look like
368this:
369
370.. code-block:: none
371
372   [area]: [summary of change]
373
374   [Commit message body (must be non-empty)]
375
376   Signed-off-by: [Your Full Name] <[your.email@address]>
377
378You need to change text in square brackets (``[like this]``) above to
379fit your commit.
380
381Here is an example of a good commit message.
382
383.. code-block:: none
384
385   drivers: sensor: abcd1234: fix bus I/O error handling
386
387   The abcd1234 sensor driver is failing to check the flags field in
388   the response packet from the device which signals that an error
389   occurred. This can lead to reading invalid data from the response
390   buffer. Fix it by checking the flag and adding an error path.
391
392   Signed-off-by: Zephyr Developer <z.developer@example.com>
393
394[area]: [summary of change]
395---------------------------
396
397This line is called the commit's *title*. Titles must be:
398
399* one line
400* less than 72 characters long
401* followed by a completely blank line
402
403[area]
404  The ``[area]`` prefix usually identifies the area of code
405  being changed. It can also identify the change's wider
406  context if multiple areas are affected.
407
408  Here are some examples:
409
410  * ``doc: ...`` for documentation changes
411  * ``drivers: foo:`` for ``foo`` driver changes
412  * ``Bluetooth: Shell:`` for changes to the Bluetooth shell
413  * ``net: ethernet:`` for Ethernet-related networking changes
414  * ``dts:`` for treewide devicetree changes
415  * ``style:`` for code style changes
416
417  If you're not sure what to use, try running ``git log FILE``, where
418  ``FILE`` is a file you are changing, and using previous commits that
419  changed the same file as inspiration.
420
421[summary of change]
422  The ``[summary of change]`` part should be a quick description of
423  what you've done. Here are some examples:
424
425  * ``doc: update wiki references to new site``
426  * ``drivers: sensor: sensor_shell: fix channel name collision``
427
428Commit Message Body
429-------------------
430
431.. warning::
432
433   An empty commit message body is not permitted. Even for trivial
434   changes, please include a descriptive commit message body. Your
435   pull request will fail CI checks if you do not.
436
437This part of the commit should explain what your change does, and why
438it's needed. Be specific. A body that says ``"Fixes stuff"`` will be
439rejected. Be sure to include the following as relevant:
440
441* **what** the change does,
442* **why** you chose that approach,
443* **what** assumptions were made, and
444* **how** you know it works -- for example, which tests you ran.
445
446Each line in your commit message should usually be 75 characters or
447less. Use newlines to wrap longer lines. Exceptions include lines
448with long URLs, email addresses, etc.
449
450For examples of accepted commit messages, you can refer to the Zephyr GitHub
451`changelog <https://github.com/zephyrproject-rtos/zephyr/commits/main>`__.
452
453
454Signed-off-by: ...
455------------------
456
457.. tip::
458
459   You should have set your :ref:`git_setup`
460   already. Create your commit with ``git commit -s`` to add the
461   Signed-off-by: line automatically using this information.
462
463For open source licensing reasons, your commit must include a
464Signed-off-by: line that looks like this:
465
466.. code-block:: none
467
468   Signed-off-by: [Your Full Name] <[your.email@address]>
469
470For example, if your full name is ``Zephyr Developer`` and your email
471address is ``z.developer@example.com``:
472
473.. code-block:: none
474
475   Signed-off-by: Zephyr Developer <z.developer@example.com>
476
477This means that you have personally made sure your change complies
478with the :ref:`DCO`. For this reason, you must use your legal name.
479Pseudonyms or "hacker aliases" are not permitted.
480
481Your name and the email address you use must match the name and email
482in the Git commit's ``Author:`` field.
483
484See the :ref:`contributor-expectations` for a more complete discussion of
485contributor and reviewer expectations.
486
487Adding Links
488------------
489
490.. _GitHub references:
491   https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/autolinked-references-and-urls
492
493If your change addresses a specific GitHub issue, include a reference in the
494pull request description using the following format:
495
496.. code-block:: none
497
498   Fixes zephyrproject-rtos/zephyr#[issue number]
499
500For pull requests to the Zephyr project only, the short form can also be used,
501for example:
502
503.. code-block:: none
504
505   Fixes #[issue number]
506
507Replace [issue number] with the relevant GitHub issue number. For example:
508
509.. code-block:: none
510
511   Fixes zephyrproject-rtos/zephyr#1234
512
513This syntax ensures that the issue is automatically closed when the pull
514request is merged. Always specify the full repository path
515(zephyrproject-rtos/zephyr) to avoid ambiguity, especially when working across
516multiple repositories.
517
518The same format can also be used in commit messages.
519
520For linking to additional external resources—such as related issues,
521datasheets, or technical reference manuals—use the ``Link:`` tag:
522
523.. code-block:: none
524
525   Link: https://github.com/zephyrproject-rtos/zephyr/issues/<issue number>
526
527.. _Continuous Integration:
528
529Continuous Integration (CI)
530===========================
531
532The Zephyr Project operates a Continuous Integration (CI) system that runs on
533every Pull Request (PR) in order to verify several aspects of the PR:
534
535* Git commit formatting
536* Coding Style
537* Twister builds for multiple architectures and boards
538* Documentation build to verify any doc changes
539
540CI is run on Github Actions and it uses the same tools described in the
541`CI Tests`_ section.  The CI results must be green indicating "All
542checks have passed" before the Pull Request can be merged.  CI is run when the
543PR is created, and again every time the PR is modified with a commit.
544
545The current status of the CI run can always be found at the bottom of the
546GitHub PR page, below the review status. Depending on the success or failure
547of the run you will see:
548
549* "All checks have passed"
550* "All checks have failed"
551
552In case of failure you can click on the "Details" link presented below the
553failure message in order to navigate to ``Github Actions`` and inspect the
554results.
555Once you click on the link you will be taken to the ``Github actions`` summary
556results page where a table with all the different builds will be shown. To see
557what build or test failed click on the row that contains the failed (i.e.
558non-green) build.
559
560.. _CI Tests:
561
562Running CI Tests Locally
563========================
564
565.. _check_compliance_py:
566
567check_compliance.py
568-------------------
569
570The ``check_compliance.py`` script serves as a valuable tool for assessing code
571compliance with Zephyr's established guidelines and best practices. The script
572acts as wrapper for a suite of tools that performs various checks, including
573linters and formatters.
574
575Developers are encouraged to run the script locally to validate their changes
576before opening a new Pull Request:
577
578.. code-block:: bash
579
580   ./scripts/ci/check_compliance.py -c upstream/main..
581
582.. note::
583   On Windows if the .pl extension has not yet been associated with an
584   application, then the first time a .pl file is run without specifying an
585   interpreter, Windows will ask what application will open Perl files.
586   Set the default app to Strawberry Perl. By default the executable is
587   installed at ``C:\Strawberry\perl\bin\perl.exe``.
588
589twister
590-------
591
592.. note::
593   twister is only fully supported on Linux; on Windows and MacOS the execution
594   of tests is not supported on all target devices.
595
596If you think your change may break some test, you can submit your PR as a draft
597and let the project CI automatically run the :ref:`twister_script` for you.
598
599If a test fails, you can check from the CI run logs how to rerun it locally,
600for example:
601
602.. code-block:: bash
603
604   west twister -p native_sim -s tests/drivers/build_all/sensor/drivers.sensor.generic_test
605
606.. _static_analysis:
607
608Static Code Analysis
609********************
610
611Coverity Scan is a free service for static code analysis of Open Source
612projects. It is based on Coverity's commercial product and is able to analyze
613C, C++ and Java code.
614
615Coverity's static code analysis doesn't run the code. Instead of that it uses
616abstract interpretation to gain information about the code's control flow and
617data flow. It's able to follow all possible code paths that a program may take.
618For example the analyzer understands that malloc() returns a memory that must
619be freed with free() later. It follows all branches and function calls to see
620if all possible combinations free the memory. The analyzer is able to detect
621all sorts of issues like resource leaks (memory, file descriptors), NULL
622dereferencing, use after free, unchecked return values, dead code, buffer
623overflows, integer overflows, uninitialized variables, and many more.
624
625The results are available on the `Coverity Scan
626<https://scan.coverity.com/projects/zephyr>`_ website. In order to access the
627results you have to create an account yourself.  From the Zephyr project page,
628you may select "Add me to project" to be added to the project. New members must
629be approved by an admin.
630
631Static analysis of the Zephyr codebase is conducted on a bi-weekly basis. GitHub
632issues are automatically created for any issues detected by static analysis
633tools. These issues will have the same (or equivalent) priority initially
634defined by the tool.
635
636To ensure accountability and efficient issue resolution, they are assigned to
637the respective maintainer who is responsible for the affected code.
638
639A dedicated team comprising members with expertise in static analysis, code
640quality, and software security ensures the effectiveness of the static
641analysis process and verifies that identified issues are properly
642triaged and resolved in a timely manner.
643
644Workflow
645========
646
647If after analyzing the Coverity report it is concluded that it is a false
648positive please set the classification to either "False positive" or
649"Intentional", the action to "Ignore", owner to your own account and add a
650comment why the issue is considered false positive or intentional.
651
652Update the related Github issue in the zephyr project with the details, and only close
653it after completing the steps above on scan service website. Any issues
654closed without a fix or without ignoring the entry in the scan service will be
655automatically reopened if the issue continues to be present in the code.
656
657.. _Contribution workflow:
658
659Contribution Workflow
660*********************
661
662One general practice we encourage, is to make small,
663controlled changes. This practice simplifies review, makes merging and
664rebasing easier, and keeps the change history clear and clean.
665
666When contributing to the Zephyr Project, it is also important you provide as much
667information as you can about your change, update appropriate documentation,
668and test your changes thoroughly before submitting.
669
670The general GitHub workflow used by Zephyr developers uses a combination of
671command line Git commands and browser interaction with GitHub.  As it is with
672Git, there are multiple ways of getting a task done.  We'll describe a typical
673workflow here:
674
675.. _Create a Fork of Zephyr:
676   https://github.com/zephyrproject-rtos/zephyr#fork-destination-box
677
678#. `Create a Fork of Zephyr`_
679   to your personal account on GitHub. (Click on the fork button in the top
680   right corner of the Zephyr project repo page in GitHub.)
681
682#. On your development computer, change into the :file:`zephyr` folder that was
683   created when you :ref:`obtained the code <get_the_code>`::
684
685     cd zephyrproject/zephyr
686
687   Rename the default remote pointing to the `upstream repository
688   <https://github.com/zephyrproject-rtos/zephyr>`_ from ``origin`` to
689   ``upstream``::
690
691     git remote rename origin upstream
692
693   Let Git know about the fork you just created, naming it ``origin``::
694
695     git remote add origin https://github.com/<your github id>/zephyr
696
697   and verify the remote repos::
698
699     git remote -v
700
701   The output should look similar to::
702
703     origin   https://github.com/<your github id>/zephyr (fetch)
704     origin   https://github.com/<your github id>/zephyr (push)
705     upstream https://github.com/zephyrproject-rtos/zephyr (fetch)
706     upstream https://github.com/zephyrproject-rtos/zephyr (push)
707
708#. Create a topic branch (off of ``main``) for your work (if you're addressing
709   an issue, we suggest including the issue number in the branch name)::
710
711     git checkout main
712     git checkout -b fix_comment_typo
713
714   Some Zephyr subsystems do development work on a separate branch from
715   ``main`` so you may need to indicate this in your checkout::
716
717     git checkout -b fix_out_of_date_patch origin/net
718
719#. Make changes, test locally, change, test, test again, ...  (Check out the
720   prior chapter on `twister`_ as well).
721
722#. When things look good, start the pull request process by adding your changed
723   files::
724
725     git add [file(s) that changed, add -p if you want to be more specific]
726
727   You can see files that are not yet staged using::
728
729     git status
730
731#. Verify changes to be committed look as you expected::
732
733     git diff --cached
734
735#. Commit your changes to your local repo::
736
737     git commit -s
738
739   The ``-s`` option automatically adds your ``Signed-off-by:`` to your commit
740   message.  Your commit will be rejected without this line that indicates your
741   agreement with the :ref:`DCO`.  See the :ref:`commit-guidelines` section for
742   specific guidelines for writing your commit messages.
743
744#. Push your topic branch with your changes to your fork in your personal
745   GitHub account::
746
747     git push origin fix_comment_typo
748
749#. In your web browser, go to your forked repo and click on the
750   ``Compare & pull request`` button for the branch you just worked on and
751   you want to open a pull request with.
752
753#. Review the pull request changes, and verify that you are opening a pull
754   request for the ``main`` branch. The title and message from your commit
755   message should appear as well.
756
757#. A bot will assign one or more suggested reviewers (based on the
758   MAINTAINERS file in the repo). If you are a project member, you can
759   select additional reviewers now too.
760
761#. Click on the submit button and your pull request is sent and awaits
762   review.  Email will be sent as review comments are made, or you can check
763   on your pull request at https://github.com/zephyrproject-rtos/zephyr/pulls.
764
765#. While you're waiting for your pull request to be accepted and merged, you
766   can create another branch to work on another issue. (Be sure to make your
767   new branch off of ``main`` and not the previous branch.)::
768
769     git checkout main
770     git checkout -b fix_another_issue
771
772   and use the same process described above to work on this new topic branch.
773
774#. If reviewers do request changes to your patch, you can interactively rebase
775   commit(s) to fix review issues. In your development repo::
776
777     git rebase -i <offending-commit-id>^
778
779   In the interactive rebase editor, replace ``pick`` with ``edit`` to select
780   a specific commit (if there's more than one in your pull request), or
781   remove the line to delete a commit entirely.  Then edit files to fix the
782   issues in the review.
783
784   As before, inspect and test your changes. When ready, continue the
785   patch submission::
786
787     git add [file(s)]
788     git rebase --continue
789
790   Update commit comment if needed, and continue::
791
792     git push --force origin fix_comment_typo
793
794   By force pushing your update, your original pull request will be updated
795   with your changes so you won't need to resubmit the pull request.
796
797#. After pushing the requested change, check on the PR page if there is a
798   merge conflict. If so, rebase your local branch::
799
800      git fetch --all
801      git rebase --ignore-whitespace upstream/main
802
803   The ``--ignore-whitespace`` option stops ``git apply`` (called by rebase)
804   from changing any whitespace. Resolve the conflicts and push again::
805
806      git push --force origin fix_comment_typo
807
808   .. note:: While amending commits and force pushing is a common review model
809      outside GitHub, and the one recommended by Zephyr, it's not the main
810      model supported by GitHub. Forced pushes can cause unexpected behavior,
811      such as not being able to use "View Changes" buttons except for the last
812      one - GitHub complains it can't find older commits. You're also not
813      always able to compare the latest reviewed version with the latest
814      submitted version. When rewriting history GitHub only guarantees access
815      to the latest version.
816
817#. If the CI run fails, you will need to make changes to your code in order
818   to fix the issues and amend your commits by rebasing as described above.
819   Additional information about the CI system can be found in
820   `Continuous Integration`_.
821
822.. _contribution_tips:
823
824Contribution Tips
825=================
826
827The following is a list of tips to improve and accelerate the review process of
828Pull Requests. If you follow them, chances are your pull request will get the
829attention needed and it will be ready for merge sooner than later:
830
831.. _git-rebase:
832   https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt---keep-base
833
834#. When pushing follow-up changes, use the ``--keep-base`` option of
835   `git-rebase`_
836
837#. On the PR page, check if the change can still be merged with no merge
838   conflicts
839
840#. Make sure title of PR explains what is being fixed or added
841
842#. Make sure your PR has a body with more details about the content of your
843   submission
844
845#. Make sure you reference the issue you are fixing in the body of the PR
846
847#. Watch early CI results immediately after submissions and fix issues as they
848   are discovered
849
850#. Revisit PR after 1-2 hours to see the status of all CI checks, make sure all
851   is green
852
853#. If you get request for changes and submit a change to address them, make
854   sure you click the "Re-request review" button on the GitHub UI to notify
855   those who asked for the changes
856
857Identifying Contribution Origin
858===============================
859
860When adding a new file to the tree, it is important to detail the source of
861origin on the file, provide attributions, and detail the intended usage. In
862cases where the file is an original to Zephyr, the commit message should
863include the following ("Original" is the assumption if no Origin tag is
864present)::
865
866      Origin: Original
867
868In cases where the file is :ref:`imported from an external project
869<external-contributions>`, the commit message shall contain details regarding
870the original project, the location of the project, the SHA-id of the origin
871commit for the file and the intended purpose.
872
873For example, a copy of a locally maintained import::
874
875      Origin: Contiki OS
876      License: BSD 3-Clause
877      URL: https://www.contiki-os.org/
878      commit: 853207acfdc6549b10eb3e44504b1a75ae1ad63a
879      Purpose: Introduction of networking stack.
880
881For example, a copy of an externally maintained import in a module repository::
882
883      Origin: Tiny Crypt
884      License: BSD 3-Clause
885      URL: https://github.com/01org/tinycrypt
886      commit: 08ded7f21529c39e5133688ffb93a9d0c94e5c6e
887      Purpose: Introduction of TinyCrypt
888
889Contributions to External Modules
890**********************************
891
892Follow the guidelines in the :ref:`modules` section for contributing
893:ref:`new modules <submitting_new_modules>` and
894submitting changes to :ref:`existing modules <changes_to_existing_module>`.
895
896.. _treewide-changes:
897
898Treewide Changes
899****************
900
901This section describes contributions that are treewide changes and some
902additional associated requirements that apply to them. These requirements exist
903to try to give such changes increased review and user visibility due to their
904large impact.
905
906Definition and Decision Making
907==============================
908
909A *treewide change* is defined as any change to Zephyr APIs, coding practices,
910or other development requirements that either implies required changes
911throughout the zephyr source code repository or can reasonably be expected to
912do so for a wide class of external Zephyr-based source code.
913
914This definition is informal by necessity. This is because the decision on
915whether any particular change is treewide can be subjective and may depend on
916additional context.
917
918Project maintainers should use good judgement and prioritize the Zephyr
919developer experience when deciding when a proposed change is treewide.
920Protracted disagreements can be resolved by the Zephyr Project's Technical
921Steering Committee (TSC), but please avoid premature escalation to the TSC.
922
923Requirements for Treewide Changes
924=================================
925
926- The zephyr repository must apply the 'treewide' GitHub label to any issues or
927  pull requests that are treewide changes
928
929- The person proposing a treewide change must create an `RFC issue
930  <https://github.com/zephyrproject-rtos/zephyr/issues/new?assignees=&labels=RFC&template=003_rfc-proposal.yml>`_
931  describing the change, its rationale and impact, etc. before any pull
932  requests related to the change can be merged
933
934- The project's `Architecture Working Group (WG)
935  <https://github.com/zephyrproject-rtos/zephyr/wiki/Architecture-Working-Group>`_
936  must include the issue on the agenda and discuss whether the project will
937  accept or reject the change before any pull requests related to the change
938  can be merged (with escalation to the TSC if consensus is not reached at the
939  WG)
940
941- The Architecture WG must specify the procedure for merging any PRs associated
942  with each individual treewide change, including any required approvals for
943  pull requests affecting specific subsystems or extra review time requirements
944
945- The person proposing a treewide change must email
946  devel@lists.zephyrproject.org about the RFC if it is accepted by the
947  Architecture WG before any pull requests related to the change can be merged
948
949Examples
950========
951
952Some example past treewide changes are:
953
954- the deprecation of version 1 of the :ref:`Logging API <logging_api>` in favor
955  of version 2 (see commit `262cc55609
956  <https://github.com/zephyrproject-rtos/zephyr/commit/262cc55609b73ea61b5f999c6c6daaba20bc5240>`_)
957- the removal of support for a legacy :ref:`dt-bindings` syntax
958  (`6bf761fc0a
959  <https://github.com/zephyrproject-rtos/zephyr/commit/6bf761fc0a2811b037abec0c963d60b00c452acb>`_)
960
961Note that adding a new version of a widely used API while maintaining
962support for the old one is not a treewide change. Deprecation and removal of
963such APIs, however, are treewide changes.
964
965Specialized driver requirements
966*******************************
967
968Drivers for standalone devices should use the Zephyr bus APIs (SPI, I2C...)
969whenever possible so that the device can be used with any SoC from any vendor
970implementing a compatible bus.
971
972If it is not technically possible to achieve full performance using the Zephyr
973APIs due to specialized accelerators in a particular SoC family, one could
974extend the support for an external device by providing a specialized path for
975that SoC family. However, the driver must still provide a regular path (via
976Zephyr APIs) for all other SoCs. Every exception must be approved by the
977Architecture WG in order to be validated and potentially to be learned/improved
978from.
979