1 // This file is part of the Doxygen Developer Manual
2 /** @page patchguide Patch Guidelines
4 \attention You can't send patches to the mailing list anymore at all. Nowadays
5 you are expected to send patches to the OpenOCD Gerrit GIT server for a
8 \attention If you already have a Gerrit account and want to try a
9 different sign in method, please first sign in as usually, press your
10 name in the upper-right corner, go to @a Settings, select @a
11 Identities pane, press <em>Link Another Identity</em> button. In case
12 you already have duplicated accounts, ask administrators for manual
15 \attention If you're behind a corporate wall with http only access to the
16 world, you can still use these instructions!
18 @section gerrit Submitting patches to the OpenOCD Gerrit server
20 OpenOCD is to some extent a "self service" open source project, so to
21 contribute, you must follow the standard procedures to have the best
22 possible chance to get your changes accepted.
24 The procedure to create a patch is essentially:
28 - send the changes to the Gerrit server for review
29 - correct the patch and re-send it according to review feedback
31 Your patch (or commit) should be a "good patch": focus it on a single
32 issue, and make it easily reviewable. Don't make
33 it so large that it's hard to review; split large
34 patches into smaller ones (this will also help
35 to track down bugs later). All patches should
36 be "clean", which includes preserving the existing
37 coding style and updating documentation as needed. When adding a new
38 command, the corresponding documentation should be added to
39 @c doc/openocd.texi in the same commit. OpenOCD runs on both Little
40 Endian and Big Endian hosts so the code can't count on specific byte
41 ordering (in other words, must be endian-clean).
43 There are several additional methods of improving the quality of your
46 - Runtime testing with Valgrind Memcheck
48 This helps to spot memory leaks, undefined behaviour due to
49 uninitialized data or wrong indexing, memory corruption, etc.
51 - Clang Static Analyzer
53 Using this tool uncovers many different kinds of bugs in C code,
54 with problematic execution paths fully explained. It is a part of
55 standard Clang installation.
57 To generate a report, run this in the OpenOCD source directory:
59 mkdir build-scanbuild; cd build-scanbuild
60 scan-build ../configure
61 scan-build make CFLAGS="-std=gnu99 -I. -I../../jimtcl"
64 - Runtime testing with sanitizers
66 Both GCC and LLVM/Clang include advanced instrumentation options to
67 detect undefined behaviour and many kinds of memory
68 errors. Available with @c -fsanitize=* command arguments.
72 mkdir build-sanitizers; cd build-sanitizers
73 ../configure CC=clang CFLAGS="-fno-omit-frame-pointer \
74 -fsanitize=address -fsanitize=undefined -ggdb3"
76 export ASAN_OPTIONS=detect_stack_use_after_return=1
77 src/openocd -s ../tcl -f /path/to/openocd.cfg
80 Please consider performing these additional checks where appropriate
81 (especially Clang Static Analyzer for big portions of new code) and
82 mention the results (e.g. "Valgrind-clean, no new Clang analyzer
83 warnings") in the commit message.
85 Say in the commit message if it's a bugfix (describe the bug) or a new
86 feature. Don't expect patches to merge immediately
87 for the next release. Be ready to rework patches
88 in response to feedback.
90 Add yourself to the GPL copyright for non-trivial changes.
92 @section stepbystep Step by step procedure
94 -# Create a Gerrit account at: https://review.openocd.org
95 - On subsequent sign ins, use the full URL prefaced with 'http://'
96 For example: http://user_identifier.open_id_provider.com
97 -# Add a username to your profile.
98 After creating the Gerrit account and signing in, you will need to
99 add a username to your profile. To do this, go to 'Settings', and
100 add a username of your choice.
101 Your username will be required in step 3 and substituted wherever
102 the string 'USERNAME' is found.
103 -# Create an SSH public key following the directions on github:
104 https://help.github.com/articles/generating-ssh-keys . You can skip step 3
105 (adding key to Github account) and 4 (testing) - these are useful only if
106 you actually use Github or want to test whether the new key works fine.
107 -# Add this new SSH key to your Gerrit account:
108 go to 'Settings' > 'SSH Public Keys', paste the contents of
109 ~/.ssh/id_rsa.pub into the text field (if it's not visible click on
110 'Add Key ...' button) and confirm by clicking 'Add' button.
111 -# Clone the git repository, rather than just download the source:
113 git clone git://git.code.sf.net/p/openocd/code openocd
115 or if you have problems with the "git:" protocol, use
116 the slower http protocol:
118 git clone http://git.code.sf.net/p/openocd/code openocd
120 -# Set up Gerrit with your local repository. All this does it
121 to instruct git locally how to send off the changes.
122 -# Add a new remote to git using Gerrit username:
124 git remote add review ssh://USERNAME@review.openocd.org:29418/openocd.git
125 git config remote.review.push HEAD:refs/for/master
129 git remote add review https://USERNAME@review.openocd.org/p/openocd.git
130 git config remote.review.push HEAD:refs/for/master
132 The http password is configured from your gerrit settings - https://review.openocd.org/#/settings/http-password.
133 \note If you want to simplify http access you can also add your http password to the url as follows:
135 git remote add review https://USERNAME:PASSWORD@review.openocd.org/p/openocd.git
137 \note All contributions should be pushed to @c refs/for/master on the
138 Gerrit server, even if you plan to use several local branches for different
139 topics. It is possible because @c for/master is not a traditional Git
141 -# You will need to install this hook, we will look into a better solution:
143 scp -p -P 29418 USERNAME@review.openocd.org:hooks/commit-msg .git/hooks/
147 wget https://review.openocd.org/tools/hooks/commit-msg
148 mv commit-msg .git/hooks
149 chmod +x .git/hooks/commit-msg
151 \note A script exists to simplify the two items above. Execute:
153 tools/initial.sh <username>
155 With @<username@> being your Gerrit username.
156 -# Set up git with your name and email:
158 git config --global user.name "John Smith"
159 git config --global user.email "john@smith.org"
161 -# Work on your patches. Split the work into
162 multiple small patches that can be reviewed and
163 applied separately and safely to the OpenOCD
167 work - edit files using your favorite editor.
168 run "git commit -s -a" to commit all changes.
169 run tools/checkpatch.sh to verify your patch style is ok.
172 \note use "git add ." before commit to add new files.
174 \note check @ref checkpatch for hint about checkpatch script
176 Commit message template, notice the short first line.
177 The field '<c>specify touched area</c>'
178 should identify the main part or subsystem the patch touches.
180 specify touched area: short comment
182 Longer comments over several lines, explaining (where applicable) the
183 reason for the patch and the general idea the solution is based on,
184 any major design decisions, etc. Limit each comment line's length to 75
185 characters; since 75 it's too short for a URL, you can put the URL in a
186 separate line preceded by 'Link: '.
192 flash/nor/atsame5: add SAME59 support
197 flash/nor: flash driver for XYZ123
199 Add new flash driver for internal flash of ...
202 target/cortex_m: fix segmentation fault in cmd 'soft_reset_halt'
204 soft_reset_halt command failed reproducibly under following conditions: ...
205 Test for NULL pointer and return error ...
207 Reported-by: John Reporter <rep9876@gmail.com>
208 Fixes: 123456789abc ("target: the commit where the problem started")
209 BugLink: https://sourceforge.net/p/openocd/tickets/999/
214 See "git log" for more examples.
216 -# Next you need to make sure that your patches
217 are on top of the latest stuff on the server and
218 that there are no conflicts:
220 git pull --rebase origin master
222 -# Send the patches to the Gerrit server for review:
226 -# Forgot something, want to add more? Just make the changes and do:
232 Further reading: http://www.coreboot.org/Git
234 @section checkpatch About checkpatch script
236 OpenOCD source code includes the script checkpatch to let developers to
237 verify their patches before submitting them for review (see @ref gerrit).
239 Every patch for OpenOCD project that is submitted for review on Gerrit
240 is tested by Jenkins. Jenkins will run the checkpatch script to analyze
242 If the script highlights either errors or warnings, Gerrit will add the
243 score "-1" to the patch and maintainers will probably ignore the patch,
244 waiting for the developer to send a fixed version.
246 The script checkpatch verifies the SPDX tag for new files against a very
247 short list of license tags.
248 If the license of your contribution is not listed there, but compatible
249 with OpenOCD license, please alert the maintainers or add the missing
250 license in the first patch of your patch series.
252 The script checkpatch has been originally developed for the Linux kernel
253 source code, thus includes specific tests and checks related to Linux
254 coding style and to Linux code structure. While the script has been
255 adapted for OpenOCD specificities, it still includes some Linux related
256 test. It is then possible that it triggers sometimes some <em>false
259 If you think that the error identified by checkpatch is a false
260 positive, please report it to the openocd-devel mailing list or prepare
261 a patch for fixing checkpatch and send it to Gerrit for review.
263 \attention The procedure below is allowed only for <em>exceptional
264 cases</em>. Do not use it to submit normal patches.
266 There are <em>exceptional cases</em> in which you need to skip some of
267 the tests from checkpatch in order to pass the approval from Gerrit.
269 For example, a patch that modify one line inside a big comment block
270 will not show the beginning or the end of the comment block. This can
271 prevent checkpatch to detect the comment block. Checkpatch can wrongly
272 consider the modified comment line as a code line, triggering a set of
275 Only for <em>exceptional cases</em>, it is allowed to submit patches
276 to Gerrit with the special field 'Checkpatch-ignore:' in the commit
277 message. This field will cause checkpatch to ignore the error types
278 listed in the field, only for the patch itself.
279 The error type is printed by checkpatch on failure.
280 For example the names of Windows APIs mix lower and upper case chars,
281 in violation of OpenOCD coding style, triggering a 'CAMELCASE' error:
283 CHECK:CAMELCASE: Avoid CamelCase: <WSAGetLastError>
284 #96105: FILE: src/helper/log.c:505:
285 + error_code = WSAGetLastError();
287 Adding in the commit message of the patch the line:
289 Checkpatch-ignore: CAMELCASE
291 will force checkpatch to ignore the CAMELCASE error.
293 @section timeline When can I expect my contribution to be committed?
295 The code review is intended to take as long as a week or two to allow
296 maintainers and contributors who work on OpenOCD only in their spare
297 time opportunity to perform a review and raise objections.
299 With Gerrit much of the urgency of getting things committed has been
300 removed as the work in progress is safely stored in Gerrit and
301 available if someone needs to build on your work before it is
302 submitted to the official repository.
304 Another factor that contributes to the desire for longer cool-off
305 times (the time a patch lies around without any further changes or
306 comments), it means that the chances of quality regression on the
307 master branch will be much reduced.
309 If a contributor pushes a patch, it is considered good form if another
310 contributor actually approves and submits that patch.
312 It should be noted that a negative review in Gerrit ("-1" or "-2") may (but does
313 not have to) be disregarded if all conditions listed below are met:
315 - the concerns raised in the review have been addressed (or explained),
316 - reviewer does not re-examine the change in a month,
317 - reviewer does not answer e-mails for another month.
319 @section browsing Browsing Patches
320 All OpenOCD patches can be reviewed <a href="https://review.openocd.org/">here</a>.
322 @section reviewing Reviewing Patches
323 From the main <a href="https://review.openocd.org/#/q/status:open,n,z">Review
324 page</a> select the patch you want to review and click on that patch. On the
325 appearing page select the download method (top right). Apply the
326 patch. After building and testing you can leave a note with the "Reply"
327 button and mark the patch with -1, 0 and +1.
330 This file contains the @ref patchguide page.