github.com/lowRISC/opentitan
. Reference the GitHub issue in your PR description and commit messages (see also Working with Issues, Writing Code). To simplify and speed up code review, we expect larger contributions like new features and major changes to be broken into multiple, smaller PRs wherever possible. For more information refer to Working with PRs.Further information can be found in Getting Started with a Design and in Request for Comments (RFC) Process.
The main license used by OpenTitan is the Apache License, Version 2.0, marked by the following license header in all source files:
// Copyright lowRISC contributors. // Licensed under the Apache License, Version 2.0, see LICENSE for details. // SPDX-License-Identifier: Apache-2.0
Do not attempt to commit code with a non-Apache license without discussing first.
All source code contributions must adhere to project style guides. We use separate style guides for different languages:
If unsure about the style, be consistent with the existing code and do your best to match its style.
For C/C++ code, we recommend to run “git-clang-format” on your changes.
There are many useful guides available on how to write commit messages and why.
The following list contains a set of simple guidelines that we consider most useful.
To indicate acceptance of our Contributor License Agreement (CLA), commits should also include a Signed-off-by line (which can be generated by git commit -s
). See CONTRIBUTING.md for more information.
If code changes, issues or pull requests (PRs) are restricted to a specific area, we recommend adding a tag in square brackets, e.g., “[uart/rtl]”, to the subject line of your commit message, issue or PR. Such tags help to identify areas affected by changes. Tags are particularly helpful when dealing with pull requests (PRs) as they can guide team members for code review and simplify later retrieval of specific PRs through the GitHub web interface.
You can add multiple tags separated by a comma, e.g., “[top, dv]” to indicate that multiple separated areas are affected. In addition, you can add further levels of hierarchy to make the indication more precise such as “[uart/rtl]” instead of just “[uart]”, “[sw/device]” instead of “[sw]”.
We track non-trivial pieces of work via GitHub issues rather than TODO comments in the code. We do not use TODO(name) comments as used in some code bases - if it is important enough to assign someone, it is worth tracking via an issue.
If you as a code reviewer come across TODOs, you should encourage the author to create a GitHub issue to track the work item, which can be referenced using a comment such as // TODO(lowrisc/<project_name>#<issue_number>): <brief description>
. Code authors are encouraged to use TODO rather than FIXME.
We leverage a set of utilities to automatically generate parts of the source code based on configuration files and templates. Examples for auto-generated RTL code include the register interface of the peripheral IP cores (using the register tool reggen), the top level (using topgen) and the main TL-UL crossbar (using tlgen). Auto-generated source files are typically checked into the OpenTitan repository. This allows people to build the system without having to invoke the utilities.
To prevent people from editing auto-generated top-level files, these files both contain a header marking them as such and they live in subfolders called autogen/
. When implementing changes that affect auto-generated files, the configuration or template file must be edited, the auto-generated files need to be regenerated and everything needs to be committed to the repository.
Not all source code included in the OpenTitan repository has been developed as part of the project. OpenTitan also leverages code from other repositories (e.g. Ibex or code from third parties released under compatible open-source licenses. The process of incorporating such code into the OpenTitan repository, which besides creating a copy may also involve the application of patches, is managed through the “vendor” script.
The “vendored” code is usually found in a vendor subdirectory such as hw/vendor
. It should never be modified directly in the OpenTitan repository. Instead, modifications should be discussed and implemented upstream and then be vendored into OpenTitan. However, when dealing with third-party code, please first raise awareness and discuss inside OpenTitan before creating issues and pull requests upstream.
Further information regarding vendor code can be found in the Vendor Tool User Guide
A pull request (PR) should contain all the code changes required to address an issue, or all the code changes leading to the implementation of a new feature or a major change in the design. At the same time, a PR should be as small as possible to simplify and speed up the review process. It may thus make sense to break down larger contributions into multiple, self-contained PRs. This does not hold for bug fixes: A single PR is sufficient to fix a bug.
Independent of how a contribution is structured, each individual commit should be atomic. The code base should remain usable even with only the first commit of a PR, or the first PR of a series of PRs, merged.
Code changes not strictly related to the target feature, major change or issue should go into a separate PR.
In some cases, preparatory code changes may be required before a change is implemented, or a new feature may require changes in a somewhat unrelated part of the code. For example, it may be the case that the register interface of an IP must be updated using the latest version of the register tool, before a new register required for the targeted feature can be added. Such changes, if small, can be in the same PR, but they should be in a separate commit with a reasonable commit message explaining why this change is necessary.
PRs with more, smaller commits instead of a few large commits simplifies debugging in the case of regressions.
For more detailed information on how to submit a pull request, see our GitHub notes.
Committers are the only people in the project that can definitively approve contributions for inclusion.
See the Committers definition and role description for a fuller explanation.
Labels can be useful as they help categorizing, prioritizing and assigning open issues/PRs. When creating a PR, you are welcome to assign labels if you feel comfortable about selecting suitable labels. If no labels are assigned, committers and other team members might do that when browsing through the open PR from time to time. If possible, you should also add a meaningful tag to the subject line of your PR as outlined in subject tags.
For PRs, it does not make sense to assign people. But when creating a PR, you should request a review from committers and team members. Some reviewers may be assigned by default depending on the paths of changed files. To balance the review load, you are welcome to also request a review from other people familiar in the corresponding area. However, you should not request a review from more than 2 to 5 team members, as this increases the review load to unsustainable levels.
Contributors should request reviews from:
However, review requests are not obligations to perform a review. It is understood that reviewers may not be able to review every single PR where a review has been requested by them.
Code review is not design review and doesn't remove the need for discussing implementation options. If you would like to make a large-scale change or discuss multiple implementation options, follow the procedure outlined under How to Contribute Code.
The main purpose of code review is to make sure the code changes appropriately solve the problem the PR intends to address. It is thus vital to provide meaningful commit messages and PR descriptions with references to issues where problems and the proposed solutions are outlined.
Code review is a core part of OpenTitan's focus on high quality implementation. It helps ensure that:
When doing code review, you should check if these guidelines are followed. If some of the points are not met, or if you see potential improvements in the modified areas, bring this up in a comment. The author of the PR will then address or comment on all feedback. It is generally the responsibility of the reviewer who started the discussion to decide whether the feedback has been addressed appropriately. If the author and the reviewer cannot find agreement, another committer or team member should be brought into the discussion.
When reviewing code and giving/discussing feedback, keep in mind that:
See also: reviewing pull requests on GitHub and the [OpenTitan Commit Escalation Guidelines](../../project_governance/committers.md#commit-escalation-guidelines" >}}).
Code review may be an intimidating process, especially if you're new to the open source community. Getting lots of comments on even minor style violations can be disheartening. Know that your contributions are always appreciated - the reality is that in many cases initial code review is the most scrutiny a given piece of code will get. Therefore, it is worth pushing to ensure it meets all coding standards rather than hoping it will be fixed in the future.
Feedback addressed during the review process should go into the corresponding commit in the PR instead of having a single commit containing all changes addressing the feedback. Try to keep a clean, linear history. This means no merge commits and no long series of “fixup” patches. Instead, use rebase to restructure your work as a series of logically ordered, atomic patches (git rebase -i
helps). PRs should not be squashed when merging to keep the individual commits including commit messages making up the PR.
Also see our GitHub notes.
To reduce the risk of accidentally introducing bugs or breaking existing functionality, we leverage continuous integration (CI) checks on every PR in addition to nightly regression tests. Depending on the target area of the PR, these automated CI checks can include checking code format and lint rules, checking commit metadata, building and running simulation environments, generating an FPGA bitstream, compilation and execution of smoke tests on an FPGA emulator. The results of these CI checks can be viewed through the GitHub web interface (check the conversation pane of the PR of interest).
In case the CI checks do not succeed, it is not okay to self-approve the PR or merge it. PRs addressing CI failures themselves may be exempted from this rule. However, such PRs are rare and they must always involve senior project committers.
If the CI checks for a PR succeed and if the PR affects larger parts of the code base, it is best to wait 24 hours before merging. This allows project contributors spread across their many time zones an opportunity to provide feedback.
If the author of the PR has commit access, they should merge it once it has been reviewed and approved. Otherwise, a committer will need to merge it. Normally a committer involved in the review will do this. Note that irrespective of who merges the PR, the original authorship of the commit is preserved.
The master
branch should always be stable. If a PR is merged that causes breakage that is likely to prevent others from making progress (e.g. breaking simulation or CI infrastructure), this failing PR should be reverted unless the required fix is obvious and trivial. We see two primary advantages to a quick-revert policy: