Documentation: Create Lesson2.md
[coreboot.git] / Documentation / Lesson2.md
blob55d81881ca3f1ae084c956307dcc059292f7c961
1 # coreboot Lesson 2: Submitting a patch to coreboot.org
3 ## Part 1: Setting up an account at coreboot.org
5 If you already have an account, skip to Part 2.
7 Otherwise, go to <https://review.coreboot.org> in your preferred web browser.
8 Select **Register** in the upper right corner.
10 Select the appropriate sign-in. For example, if you have a Google account,
11 select **Google OAuth2** (gerrit-oauth-provider plugin)".**Note:** Your
12 username for the account will be the username of the account you used to
13 sign-in with. (ex. your Google username).
15 ## Part 2a: Set up RSA Private/Public Key
17 If you prefer to use an HTTP password instead, skip to Part 2b.
19 For the most up-to-date instructions on how to set up SSH keys with Gerrit go to
20 <https://gerrit-documentation.storage.googleapis.com/Documentation/2.14.2/user-upload.html#configure_ssh)>
21 and follow the instructions there. Then, skip to Part 3.
23 Additonally, that section of the Web site provides explanation on starting
24 an ssh-agent, which may be particularly helpful for those who anticipate
25 frequently uploading changes.
27 If you instead prefer to have review.coreboot.org specific instructions,
28 follow the steps below. Note that this particular section may have the
29 most up-to-date instructions.
31 If you do not have an RSA key set up on your account already (as is the case
32 with a newly created account), follow the instructions below; otherwise,
33 doing so could overwrite an existing key.
35 In the upper right corner, select your name and click on **Settings**.
36 Select **SSH Public Keys** on the left-hand side.
38 In a terminal, run "ssh-keygen" and confirm the default path ".ssh/id_rsa".
40 Make a passphrase -- remember this phrase. It will be needed whenever you use
41 this RSA Public Key. **Note:** You might want to use a short password, or
42 forego the password altogether as you will be using it very often.
44 Open "id_rsa.pub", copy all contents and paste into the textbox under
45 "Add SSH Public Key" in the https://review.coreboot.org webpage.
47 ## Part 2b: Setting up an HTTP Password
49 Alternatively, instead of using SSH keys, you can use an HTTP password. To do so,
50 after you select your name and click on **Settings** on the left-hand side, rather
51 than selecting **SSH Public Keys**, select **HTTP Password**.
53 Click **Generate Password**. This should fill the "Password" box with a password. Copy
54 the password, and add the following to your $HOME/.netrc file:
56         machine review.coreboot.org login YourUserNameHere password YourPasswordHere
58 where YourUserNameHere is your username, and YourPasswordHere is the password you
59 just generated.
61 ## Part 3: Clone coreboot and configure it for submitting patches
63 Go to the **Projects** tab in the upper left corner and select **List**.
64 From the dropdown menu that appears, select "coreboot".
66 If you are using SSH keys, select **ssh** from the tabs under "Project coreboot"
67 and run the command that appears. This should prompt you for your id_rsa passphrase,
68 if you previously set one.
70 If you are using HTTP, instead, select **http** from the tabs under "Project coreboot"
71 and run the command that appears
73 After it finishes cloning, "cd coreboot" will take you into the local
74 git repository. Run "make gitconfig" to set up the hooks and configurations.
75 For example, you will be asked to run the following commands to set your
76 username and email.
78         git config --global user.name "Your Name"
79         git config --global user.email "Your Email"
81 ## Part 4: Submit a commit
83 An easy first commit to make is fixing existing checkpatch errors and warnings
84 in the source files. To see errors that are already present, build the files in
85 the repository by running 'make lint' in the coreboot directory. Alternatively,
86 if you want to run 'make lint' on a specific directory, run:
88         for file in $(git ls-files | grep src/amd/quadcore); do \
89         util/lint/checkpatch.pl --file $file --terse; done
91 where <filepath> is the filepath of the directory (ex. src/cpu/amd/car).
93 Any changes made to files under the src directory are made locally,
94 and can be submitted for review.
96 Once you finish making your desired changes, use the command line to stage
97 and submit your changes. An alternative and potentially easier way to stage
98 and submit commits is to use git cola, a graphical user interface for git. For
99 instructions on how to do so, skip to Part 4b.
101 ## Part 4a: Using the command line to stage and submit a commit
103 To use the command line to stage a commit, run
105         git add <filename>
107 where `filename` is the name of your file.
109 To commit the change, run
111         git commit -s
113 **Note:** The -s adds a signed-off-by line by the commiter. Your commit should be
114 signed off with your name and email (i.e. **Your Name** **<Your Email>**, based on
115 what you set with git config earlier).
117 Running git commit first checks for any errors and warnings using lint. If
118 there are any, you must go back and fix them before submitting your commit.
119 You can do so by making the necessary changes, and then staging your commit again.
121 When there are no errors or warnings, your default text editor will open.
122 This is where you will write your commit message.
124 The first line of your commit message is your commit summary. This is a brief
125 one-line description of what you changed in the files using the template
126 below:
128 <filepath>: Short description
129 *ex. cpu/amd/pi/00630F01: Fix checkpatch warnings and errors*
130 **Note:** It is good practice to use present tense in your descriptions
131 and do not punctuate your summary.
133 Then hit Enter. The next paragraph should be a more in-depth explanation of the
134 changes you've made to the files. Again, it is good practice to use present
135 tense.
136 *ex.  Fix space prohibited between function name and open parenthesis,
137 line over 80 characters, unnecessary braces for single statement blocks,
138 space required before open brace errors and warnings.*
140 When you have finished writing your commit message, save and exit the text
141 editor. You have finished committing your change. If, after submitting your
142 commit, you wish to make changes to it, running "git commit --amend" allows
143 you to take back your commit and amend it.
145 When you are done with your commit, run 'git push' to push your commit to
146 coreboot.org. **Note:** To submit as a draft, use
147 'git push origin HEAD:refs/drafts/master' Submitting as a draft means that
148 your commit will be on coreboot.org, but is only visible to those you add
149 as reviewers.
151 ## Part 4b: Using git cola to stage and submit a commit
153 If git cola is not installed on your machine, see
154 https://git-cola.github.io/downloads.html for download instructions.
156 After making some edits to src files, rather than run "git add," run
157 'git cola' from the command line. You should see all of the files
158 edited under "Modified".
160 In the textbox labeled "Commit summary" provide a brief one-line
161 description of what you changed in the files according to the template
162 below:
164 <filepath>: Short description
165 *ex. cpu/amd/pi/00630F01: Fix checkpatch warnings and errors*
166 **Note:** It is good practice to use present tense in your descriptions
167 and do not punctuate your short description.
169 In the larger text box labeled 'Extended description...' provide a more
170 in-depth explanation of the changes you've made to the files. Again, it
171 is good practice to use present tense.
172 *ex.  Fix space prohibited between function name and open parenthesis,
173 line over 80 characters, unnecessary braces for single statement blocks,
174 space required before open brace errors and warnings.*
176 Then press Enter two times to move the cursor to below your description.
177 To the left of the text boxes, there is an icon with an downward arrow.
178 Press the arrow and select "Sign Off." Make sure that you are signing off
179 with your name and email (i.e. **Your Name** **<Your Email>**, based on what
180 you set with git config earlier).
182 Now, review each of your changes and mark either individual changes or
183 an entire file as Ready to Commit by marking it as 'Staged'. To do
184 this, select one file from the 'Modified' list. If you only want to
185 submit particular changes from each file, then highlight the red and
186 green lines for your changes, right click and select 'Stage Selected
187 Lines'. Alternatively, if an entire file is ready to be committed, just
188 double click on the file under 'Modified' and it will be marked as
189 Staged.
191 Once the descriptions are done and all the edits you would like to
192 commit have been staged, press 'Commit' on the right of the text
193 boxes.
195 If the commit fails due to persisting errors, a text box will appear
196 showing the errors. You can correct these errors within 'git cola' by
197 right-clicking on the file in which the error occurred and selecting
198 'Launch Diff Tool'. Make necessary corrections, close the Diff Tool and
199 'Stage' the corrected file again. It might be necessary to refresh
200 'git cola' in order for the file to be shown under 'Modified' again.
201 Note: Be sure to add any other changes that haven't already been
202 explained in the extended description.
204 When ready, select 'Commit' again. Once all errors have been satisfied
205 and the commit succeeds, move to the command line and run 'git push'.
206 **Note:** To submit as a draft, use 'git push origin HEAD:refs/drafts/master'
207 Submitting as a draft means that your commit will be on coreboot.org, but is
208 only visible to those you add as reviewers.
210 ## Part 5: Getting your commit reviewed
212 Your commits can now be seen on review.coreboot.org if you select “My”
213 and click on “Changes” and can be reviewed by others. Your code will
214 first be reviewed by build bot (Jenkins), which will either give you a warning
215 or verify a successful build; if so, your commit will receive a +1. Other
216 users may also give your commit +1.  For a commit to be merged, it needs
217 to receive a +2.**Note:** A +1 and a +1 does not make a +2. Only certain users
218 can give a +2.
220 ## Part 6 (optional): bash-git-prompt
222 To help make it easier to understand the state of the git repository
223 without running 'git status' or 'git log', there is a way to make the
224 command line show the status of the repository at every point. This
225 is through bash-git-prompt.
227 Instructions for installing this are found at:
228 https://github.com/magicmonty/bash-git-prompt
229 **Note:** Feel free to search for different versions of git prompt,
230 as this one is specific to bash.
232 Alternatively, follow the instructions below:
233 Run the following two commands in the command line:
235     cd
236     git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt --depth=1
238 **Note:** cd will change your directory to your home directory, so the
239 git clone commmand will be run there.
241 Finally, open the ~/.bashrc file and append the following two lines:
243     GIT_PROMPT_ONLY_IN_REPO=1
244     source ~/.bash-git-prompt/gitprompt.sh
246 Now, whenever you are in a git repository, it will continuously display
247 its state.
249 There also are additional configurations that you can change depending on your
250 preferences. If you wish to do so, look at the "All configs for .bashrc" section
251 on https://github.com/magicmonty/bash-git-prompt. Listed in that section are
252 various lines that you can copy, uncomment and add to your .bashrc file to
253 change the configurations. Example configurations include avoid fetching remote
254 status, and supporting versions of Git older than 1.7.10.