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