|
| 1 | +Contribution guidelines |
| 2 | +======================= |
| 3 | + |
| 4 | +This page serves the purpose of providing pointers and a brief introduction to |
| 5 | +contributing to the Linux Kernel, using the tools available as well as wrappers |
| 6 | +maintained by Analog Devices Inc. |
| 7 | + |
| 8 | +.. tip:: |
| 9 | + |
| 10 | + When using :git-linux:`/`, the :doc:`ci` system automates most checks inside |
| 11 | + a container (:git-linux:`ci:container`). See :ref:`interactive-run` for |
| 12 | + interactive usage. |
| 13 | + |
| 14 | +Code checkers |
| 15 | +------------- |
| 16 | + |
| 17 | +There are many checkers to catch issues before submitting changes to the Kernel |
| 18 | +mailing lists. :git-linux:`ci:ci/build.sh` combines all of the checkers so that |
| 19 | +they can be run with one command using a standard configuration. The checkers |
| 20 | +supported by build.sh are as follows. |
| 21 | + |
| 22 | +Checkpatch |
| 23 | +~~~~~~~~~~ |
| 24 | + |
| 25 | +:external+upstream:doc:`dev-tools/checkpatch` |
| 26 | +(:git-linux:`scripts/checkpatch.pl`) is a perl script which checks for trivial |
| 27 | +style violations in patches and optionally corrects them. Checkpatch can also |
| 28 | +be run on file contexts and without the kernel tree. |
| 29 | + |
| 30 | +It is the bare-minimum tool before submitting any patch series. |
| 31 | + |
| 32 | +Usage: |
| 33 | + |
| 34 | +.. code:: bash |
| 35 | +
|
| 36 | + ./scripts/checkpatch.pl [OPTION]... [FILE]... |
| 37 | +
|
| 38 | +.. important:: |
| 39 | + |
| 40 | + You must always adjust the style to match the guidelines of the |
| 41 | + :ref:`subsystem` you are collaborating to. |
| 42 | + |
| 43 | +To run it as a low-budget `lsp server <https://en.wikipedia.org/wiki/Language_Server_Protocol>`__, do: |
| 44 | + |
| 45 | +.. code:: bash |
| 46 | +
|
| 47 | + while true; do \ |
| 48 | + scripts/checkpatch.pl --color=always drivers/power/supply/max77928_charger.c \ |
| 49 | + --strict \ |
| 50 | + --ignore FILE_PATH_CHANGES \ |
| 51 | + --ignore LONG_LINE \ |
| 52 | + --ignore LONG_LINE_STRING \ |
| 53 | + --ignore LONG_LINE_COMMENT \ |
| 54 | + --ignore PARENTHESIS_ALIGNMENT \ |
| 55 | + --ignore CAMELCASE \ |
| 56 | + --ignore UNDOCUMENTED_DT_STRING \ |
| 57 | + --strict \ > /tmp/output ; clear ; cat /tmp/output ; \ |
| 58 | + done |
| 59 | +
|
| 60 | +Sparse and smatch |
| 61 | +~~~~~~~~~~~~~~~~~ |
| 62 | + |
| 63 | +:external+upstream:doc:`dev-tools/sparse` is a semantic checker for C programs; |
| 64 | +it can be used to find a number of potential problems with kernel code. |
| 65 | +Usage: |
| 66 | + |
| 67 | +.. shell:: |
| 68 | + |
| 69 | + ~/linux |
| 70 | + $make C=1 |
| 71 | + |
| 72 | +And `Smatch <https://smatch.sourceforge.net/>`__ is a static analysis tool for |
| 73 | +C mostly for the linux kernel. |
| 74 | +Usage: |
| 75 | + |
| 76 | +.. shell:: |
| 77 | + |
| 78 | + ~/linux |
| 79 | + $make C=1 CHECK="smatch -p=kernel" |
| 80 | + |
| 81 | +Further reading: `Finding locking bugs with Smatch <https://lwn.net/Articles/1023646/>`__ |
| 82 | + |
| 83 | +GCC fanalyzer |
| 84 | +~~~~~~~~~~~~~ |
| 85 | + |
| 86 | +GCC's |
| 87 | +`-fanalyzer <https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html#index-analyzer>`__ |
| 88 | +enables an static analysis of program flow which looks for "interesting" |
| 89 | +interprocedural paths through the code, and issues warnings for problems found |
| 90 | +on them. |
| 91 | + |
| 92 | +Since it is a flag, it must be appended to the compile command, either to the |
| 93 | +`KCFLAGS`: |
| 94 | + |
| 95 | +.. shell:: |
| 96 | + |
| 97 | + ~/linux |
| 98 | + $make KCFLAGS=" -fanalyzer" |
| 99 | + |
| 100 | +To analyze a single file, generate compile commands with |
| 101 | +`./scripts/clang-tools/gen_compile_commands.py`, extract the compile command |
| 102 | +for the ``.c`` file and append ``-fanalyzer``. |
| 103 | + |
| 104 | +Clang static analyzer |
| 105 | +~~~~~~~~~~~~~~~~~~~~~ |
| 106 | + |
| 107 | +`Clang static analyzer <https://clang-analyzer.llvm.org/>`__ is a source code |
| 108 | +analysis tool that finds bugs in C, C++, and Objective-C programs. |
| 109 | + |
| 110 | +Since it is a flag, it must be appended to the compile command, either to the |
| 111 | +`KCFLAGS`: |
| 112 | + |
| 113 | +.. shell:: |
| 114 | + |
| 115 | + ~/linux |
| 116 | + $make LLVM=1 KCFLAGS=" --analyze -Xanalyzer" |
| 117 | + |
| 118 | +To analyze a single file, generate compile commands with |
| 119 | +`./scripts/clang-tools/gen_compile_commands.py`, extract the compile command |
| 120 | +for the ``.c`` file and append ``--analyze -Xanalyzer``. |
| 121 | + |
| 122 | +Devicetree |
| 123 | +---------- |
| 124 | + |
| 125 | +The "Open Firmware Device Tree", or simply |
| 126 | +:external+upstream:doc:`Devicetree <devicetree/usage-model>` (DT), is a data |
| 127 | +structure and language for describing hardware. More specifically, it is a |
| 128 | +description of hardware that is readable by an operating system so that the |
| 129 | +operating system doesn’t need to hard code details of the machine. |
| 130 | + |
| 131 | +Even though some devicetrees are provided with the Linux Kernel, in general, |
| 132 | +a custom devicetree will need to be written to describe a specific board or |
| 133 | +device, using the protopytes provided by the |
| 134 | +:git-linux:`Documentation/devicetree/bindings/**/*.yaml <Documentation/devicetree/bindings>` files. |
| 135 | + |
| 136 | +When submitting dt-bindings, you must check: |
| 137 | + |
| 138 | +.. shell:: |
| 139 | + |
| 140 | + ~/linux |
| 141 | + $make dt_binding_chec CONFIG_DTC=y DT_CHECKER_FLAGS=-m DT_SCHEMA_FILES="./path/to/.yaml" |
| 142 | + |
| 143 | +For warnings and erros and resolve accordingly. |
| 144 | + |
| 145 | +.. _b4: |
| 146 | + |
| 147 | +B4 |
| 148 | +-- |
| 149 | + |
| 150 | +:external+b4:doc:`B4 <index>` is a tool created to make it easier for project |
| 151 | +developers and maintainers to use a distributed development workflow that |
| 152 | +relies on patches and distribution lists for code contributions and review. |
| 153 | + |
| 154 | +Take some time to try it out, and understand how it simplies many tasks. |
| 155 | +B4 tools is not currently leveraged by continuous integration, and you |
| 156 | +must run it locally. |
| 157 | + |
| 158 | +The section that you will most interested in is the |
| 159 | +:external+b4:doc:`contributor/overview`, where the contributor workflow is |
| 160 | +extensively detailed, as well as the tools to ease it, such as |
| 161 | +:external+b4:doc:`b4 prep <contributor/prep>`, |
| 162 | +:external+b4:doc:`b4 send <contributor/send>`, and |
| 163 | +:external+b4:doc:`b4 trailers <contributor/trailers>`. |
| 164 | + |
| 165 | +.. _subsystem: |
| 166 | + |
| 167 | +Subsytems |
| 168 | +--------- |
| 169 | + |
| 170 | +The Linux kernel is organized into subsystems—logical divisions around |
| 171 | +functionality such as core APIs (memory, scheduling, locking, timers), driver |
| 172 | +interfaces (networking, storage, input, etc.), and various device-oriented |
| 173 | +modules (IIO, USB, SPI, etc.). Each subsystem encapsulates its own APIs, |
| 174 | +conventions, and lifecycle, helping maintain modularity and clarity. For an |
| 175 | +up-to-date map of these subsystems and their interfaces, see |
| 176 | +:external+upstream:doc:`subsystem-apis`. |
| 177 | + |
| 178 | +IIO Subsytem |
| 179 | +~~~~~~~~~~~~ |
| 180 | + |
| 181 | +The :external+upstream:doc:`Industrial I/O subsystem <driver-api/iio/intro>` is |
| 182 | +intended to provide support for devices that in some senses are analog to |
| 183 | +digital or digital to analog converters (ADCs, DACs). Devices that fall into |
| 184 | +this category are: ADCs, accelerometers, gyros, IMUs, capacitance to digital |
| 185 | +converters, pressure sensors, light and proximity sensors, temperature sensors, |
| 186 | +magnetometers, DACs, DDS (Direct Digital Synthesis), variable/programmable gain |
| 187 | +amplifiers (VGA, PGA). These devices typically would be connected via SPI or |
| 188 | +I2C. |
| 189 | + |
| 190 | +The overall aim is to fill the gap between the somewhat similar hwmon and input |
| 191 | +subsystems. Hwmon is very much directed at low sample rate sensors used in |
| 192 | +applications such as fan speed control and temperature measurement. |
| 193 | + |
| 194 | +To continuous capture data based on a trigger source, |
| 195 | +:external+upstream:doc:`iio/iio_devbuf` are used. |
0 commit comments