diff options
-rw-r--r-- | documentation/kernel-dev/kernel-dev-common.xml | 577 |
1 files changed, 565 insertions, 12 deletions
diff --git a/documentation/kernel-dev/kernel-dev-common.xml b/documentation/kernel-dev/kernel-dev-common.xml index de119c3e87..3af52eb352 100644 --- a/documentation/kernel-dev/kernel-dev-common.xml +++ b/documentation/kernel-dev/kernel-dev-common.xml | |||
@@ -3,20 +3,391 @@ | |||
3 | [<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] > | 3 | [<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] > |
4 | 4 | ||
5 | <chapter id='kernel-dev-common'> | 5 | <chapter id='kernel-dev-common'> |
6 | |||
7 | <title>Common Tasks</title> | 6 | <title>Common Tasks</title> |
8 | 7 | ||
9 | <para> | 8 | <para> |
10 | This chapter presents several common tasks you perform when you | 9 | This chapter presents several common tasks you perform when you |
11 | work with the Yocto Project Linux kernel. | 10 | work with the Yocto Project Linux kernel. |
12 | These tasks include preparing a layer, modifying an existing recipe, | 11 | These tasks include preparing your host development system for |
13 | iterative development, working with your own sources, and incorporating | 12 | kernel development, preparing a layer, modifying an existing recipe, |
14 | out-of-tree modules. | 13 | patching the kernel, iterative development, working with your own sources, |
15 | <note> | 14 | and incorporating out-of-tree modules. |
16 | The examples presented in this chapter work with the Yocto Project | 15 | <note> |
17 | 1.2.2 Release and forward. | 16 | The examples presented in this chapter work with the Yocto Project |
18 | </note> | 17 | 2.4 Release and forward. |
19 | </para> | 18 | </note> |
19 | </para> | ||
20 | |||
21 | <section id='preparing-the-build-host-to-work-on-the-kernel'> | ||
22 | <title>Preparing the Build Host to Work on the Kernel</title> | ||
23 | |||
24 | <para> | ||
25 | Before you can do any kernel development, you need to be | ||
26 | sure your build host is set up to use the Yocto Project. | ||
27 | For information on how to get set up, see the | ||
28 | "<ulink url='&YOCTO_DOCS_DEV_URL;#setting-up-the-development-host-to-use-the-yocto-project'>Setting Up to Use the Yocto Project</ulink>" | ||
29 | section in the Yocto Project Development Manual. | ||
30 | Part of preparing the system is creating a local Git | ||
31 | repository of the | ||
32 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> | ||
33 | (<filename>poky</filename>) on your system. | ||
34 | Follow the steps in the | ||
35 | "<ulink url='&YOCTO_DOCS_DEV_URL;#cloning-the-poky-repository'>Cloning the <filename>poky</filename> Repository</ulink>" | ||
36 | section in the Yocto Project Development Manual to set up your | ||
37 | Source Directory. | ||
38 | <note> | ||
39 | Be sure you check out the appropriate development branch or | ||
40 | by tag to get the version of Yocto Project you want. | ||
41 | See the | ||
42 | "<ulink url='&YOCTO_DOCS_DEV_URL;#checking-out-by-branch-in-poky'>Checking Out by Branch in Poky</ulink>" | ||
43 | and | ||
44 | "<ulink url='&YOCTO_DOCS_DEV_URL;#checkout-out-by-tag-in-poky'>Checking Out by Tag in Poky</ulink>" | ||
45 | sections in the Yocto Project Development Manual for more | ||
46 | information. | ||
47 | </note> | ||
48 | </para> | ||
49 | |||
50 | <para> | ||
51 | Kernel development is best accomplished using | ||
52 | <ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'><filename>devtool</filename></ulink> | ||
53 | and not through traditional kernel workflow methods. | ||
54 | The remainder of this section provides information for both | ||
55 | scenarios. | ||
56 | </para> | ||
57 | |||
58 | <section id='getting-ready-to-develop-using-devtool'> | ||
59 | <title>Getting Ready to Develop using <filename>devtool</filename></title> | ||
60 | |||
61 | <para> | ||
62 | Follow these steps to prepare to update the kernel image using | ||
63 | <filename>devtool</filename>. | ||
64 | Completing this procedure leaves you with a clean kernel image | ||
65 | and ready to make modifications as described in the | ||
66 | "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>" | ||
67 | section: | ||
68 | <orderedlist> | ||
69 | <listitem><para> | ||
70 | <emphasis>Initialize the BitBake Environment:</emphasis> | ||
71 | Before building an extensible SDK, you need to | ||
72 | initialize the BitBake build environment by sourcing a | ||
73 | build environment script | ||
74 | (i.e. <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink> | ||
75 | or | ||
76 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>): | ||
77 | <literallayout class='monospaced'> | ||
78 | $ cd ~/poky | ||
79 | $ source oe-init-build-env | ||
80 | </literallayout> | ||
81 | <note> | ||
82 | The previous commands assume the | ||
83 | <ulink url='&YOCTO_DOCS_REF_URL;#source-repositories'>Source Repositories</ulink> | ||
84 | (i.e. <filename>poky</filename>) have been cloned | ||
85 | using Git and the local repository is named | ||
86 | "poky". | ||
87 | </note> | ||
88 | </para></listitem> | ||
89 | <listitem><para> | ||
90 | <emphasis>Prepare Your <filename>local.conf</filename> File:</emphasis> | ||
91 | By default, the | ||
92 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> | ||
93 | variable is set to "qemux86", which is fine if you are | ||
94 | building for the QEMU emulator in 32-bit mode. | ||
95 | However, if you are not, you need to set the | ||
96 | <filename>MACHINE</filename> variable appropriately in | ||
97 | your <filename>conf/local.conf</filename> file found in | ||
98 | the | ||
99 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink> | ||
100 | (i.e. <filename>~/poky/build</filename> in this | ||
101 | example).</para> | ||
102 | |||
103 | <para>Also, since you are preparing to work on the | ||
104 | kernel image, you need to set the | ||
105 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS</filename></ulink> | ||
106 | variable to include kernel modules.</para> | ||
107 | |||
108 | <para>This example uses the default "qemux86" for the | ||
109 | <filename>MACHINE</filename> variable but needs to | ||
110 | add the "kernel-modules": | ||
111 | <literallayout class='monospaced'> | ||
112 | MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "kernel-modules" | ||
113 | </literallayout> | ||
114 | </para></listitem> | ||
115 | <listitem><para> | ||
116 | <emphasis>Create a Layer for Patches:</emphasis> | ||
117 | You need to create a layer to hold patches created | ||
118 | for the kernel image. | ||
119 | You can use the <filename>yocto-layer</filename> command | ||
120 | as follows: | ||
121 | <literallayout class='monospaced'> | ||
122 | $ cd ~/poky | ||
123 | $ yocto-layer create my-kernel -o ../meta-my-kernel | ||
124 | Please enter the layer priority you'd like to use for the layer: [default: 6] | ||
125 | Would you like to have an example recipe created? (y/n) [default: n] | ||
126 | Would you like to have an example bbappend file created? (y/n) [default: n] | ||
127 | |||
128 | New layer created in ../meta-my-kernel. | ||
129 | |||
130 | Don't forget to add it to your BBLAYERS (for details see ../meta-my-kernel/README). | ||
131 | </literallayout> | ||
132 | </para></listitem> | ||
133 | <listitem><para> | ||
134 | <emphasis>Inform the BitBake Build Environment About | ||
135 | Your Layer:</emphasis> | ||
136 | As directed when you created your layer, you need to | ||
137 | add the layer to the | ||
138 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink> | ||
139 | variable in the <filename>bblayers.conf</filename> file | ||
140 | as follows: | ||
141 | <literallayout class='monospaced'> | ||
142 | $ cd ~/poky/build | ||
143 | $ bitbake-layers add-layer ../../meta-my-kernel | ||
144 | </literallayout> | ||
145 | </para></listitem> | ||
146 | <listitem><para> | ||
147 | <emphasis>Build the Extensible SDK:</emphasis> | ||
148 | Use BitBake to build the extensible SDK specifically for | ||
149 | the Minnowboard: | ||
150 | <literallayout class='monospaced'> | ||
151 | $ cd ~/poky/build | ||
152 | $ bitbake core-image-minimal -c populate_sdk_ext | ||
153 | </literallayout> | ||
154 | Once the build finishes, you can find the SDK installer | ||
155 | file (i.e. <filename>*.sh</filename> file) in the | ||
156 | following directory: | ||
157 | <literallayout class='monospaced'> | ||
158 | ~/poky/build/tmp/deploy/sdk | ||
159 | </literallayout> | ||
160 | For this example, the installer file is named | ||
161 | <filename>poky-glibc-x86_64-core-image-minimal-i586-toolchain-ext-&DISTRO;.sh</filename> | ||
162 | </para></listitem> | ||
163 | <listitem><para> | ||
164 | <emphasis>Install the Extensible SDK:</emphasis> | ||
165 | Use the following command to install the SDK. | ||
166 | For this example, install the SDK in the default | ||
167 | <filename>~/poky_sdk</filename> directory: | ||
168 | <literallayout class='monospaced'> | ||
169 | $ cd ~/poky/build/tmp/deploy/sdk | ||
170 | $ ./poky-glibc-x86_64-core-image-minimal-i586-toolchain-ext-&DISTRO;.sh | ||
171 | Poky (Yocto Project Reference Distro) Extensible SDK installer version &DISTRO; | ||
172 | ============================================================================ | ||
173 | Enter target directory for SDK (default: ~/poky_sdk): | ||
174 | You are about to install the SDK to "/home/scottrif/poky_sdk". Proceed[Y/n]? Y | ||
175 | Extracting SDK......................................done | ||
176 | Setting it up... | ||
177 | Extracting buildtools... | ||
178 | Preparing build system... | ||
179 | Parsing recipes: 100% |#################################################################| Time: 0:00:52 | ||
180 | Initializing tasks: 100% |############## ###############################################| Time: 0:00:04 | ||
181 | Checking sstate mirror object availability: 100% |######################################| Time: 0:00:00 | ||
182 | Parsing recipes: 100% |#################################################################| Time: 0:00:33 | ||
183 | Initializing tasks: 100% |##############################################################| Time: 0:00:00 | ||
184 | done | ||
185 | SDK has been successfully set up and is ready to be used. | ||
186 | Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g. | ||
187 | $ . /home/scottrif/poky_sdk/environment-setup-i586-poky-linux | ||
188 | </literallayout> | ||
189 | </para></listitem> | ||
190 | <listitem><para id='setting-up-the-esdk-terminal'> | ||
191 | <emphasis>Set Up a New Terminal to Work With the | ||
192 | Extensible SDK:</emphasis> | ||
193 | You must set up a new terminal to work with the SDK. | ||
194 | You cannot use the same BitBake shell used to build the | ||
195 | installer.</para> | ||
196 | |||
197 | <para>After opening a new shell, run the SDK environment | ||
198 | setup script as directed by the output from installing | ||
199 | the SDK: | ||
200 | <literallayout class='monospaced'> | ||
201 | $ source ~/poky_sdk/environment-setup-i586-poky-linux | ||
202 | "SDK environment now set up; additionally you may now run devtool to perform development tasks. | ||
203 | Run devtool --help for further details. | ||
204 | </literallayout> | ||
205 | <note> | ||
206 | If you get a warning about attempting to use the | ||
207 | extensible SDK in an environment set up to run | ||
208 | BitBake, you did not use a new shell. | ||
209 | </note> | ||
210 | </para></listitem> | ||
211 | <listitem><para> | ||
212 | <emphasis>Build the Clean Image:</emphasis> | ||
213 | The final step in preparing to work on the kernel is to | ||
214 | build an initial image using | ||
215 | <filename>devtool</filename> in the new terminal you | ||
216 | just set up and initialized for SDK work: | ||
217 | <literallayout class='monospaced'> | ||
218 | $ devtool build-image | ||
219 | Parsing recipes: 100% |##########################################| Time: 0:00:05 | ||
220 | Parsing of 830 .bb files complete (0 cached, 830 parsed). 1299 targets, 47 skipped, 0 masked, 0 errors. | ||
221 | WARNING: No packages to add, building image core-image-minimal unmodified | ||
222 | Loading cache: 100% |############################################| Time: 0:00:00 | ||
223 | Loaded 1299 entries from dependency cache. | ||
224 | NOTE: Resolving any missing task queue dependencies | ||
225 | Initializing tasks: 100% |#######################################| Time: 0:00:07 | ||
226 | Checking sstate mirror object availability: 100% |###############| Time: 0:00:00 | ||
227 | NOTE: Executing SetScene Tasks | ||
228 | NOTE: Executing RunQueue Tasks | ||
229 | NOTE: Tasks Summary: Attempted 2866 tasks of which 2604 didn't need to be rerun and all succeeded. | ||
230 | NOTE: Successfully built core-image-minimal. You can find output files in /home/scottrif/poky_sdk/tmp/deploy/images/qemux86 | ||
231 | </literallayout> | ||
232 | If you were building for actual hardware and not for | ||
233 | emulation, you could flash the image to a USB stick | ||
234 | on <filename>/dev/sdd</filename> and boot your device. | ||
235 | For an example that uses a Minnowboard, see the | ||
236 | <ulink url='https://wiki.yoctoproject.org/wiki/TipsAndTricks/KernelDevelopmentWithEsdk'>TipsAndTricks/KernelDevelopmentWithEsdk</ulink> | ||
237 | Wiki page. | ||
238 | </para></listitem> | ||
239 | </orderedlist> | ||
240 | </para> | ||
241 | |||
242 | <para> | ||
243 | At this point you have set up to start making modifications to | ||
244 | the kernel by using the extensible SDK. | ||
245 | For a continued example, see the | ||
246 | "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>" | ||
247 | section. | ||
248 | </para> | ||
249 | </section> | ||
250 | |||
251 | <section id='getting-ready-for-traditional-kernel-development'> | ||
252 | <title>Getting Ready for Traditional Kernel Development</title> | ||
253 | |||
254 | <para> | ||
255 | Getting ready for traditional kernel development using the Yocto | ||
256 | Project involves many of the same steps as described in the | ||
257 | previous section. | ||
258 | However, you need to establish a local copy of the kernel source | ||
259 | since you will be editing these files. | ||
260 | </para> | ||
261 | |||
262 | <para> | ||
263 | Follow these steps to prepare to update the kernel image using | ||
264 | traditional kernel development flow with the Yocto Project. | ||
265 | Completing this procedure leaves you ready to make modifications | ||
266 | to the kernel source as described in the | ||
267 | "<link linkend='using-traditional-kernel-development-to-patch-the-kernel'>Using Traditional Kernel Development to Patch the Kernel</link>" | ||
268 | section: | ||
269 | <orderedlist> | ||
270 | <listitem><para> | ||
271 | <emphasis>Initialize the BitBake Environment:</emphasis> | ||
272 | Before you can do anything using BitBake, you need to | ||
273 | initialize the BitBake build environment by sourcing a | ||
274 | build environment script | ||
275 | (i.e. <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink> | ||
276 | or | ||
277 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>): | ||
278 | <literallayout class='monospaced'> | ||
279 | $ cd ~/poky | ||
280 | $ source oe-init-build-env | ||
281 | </literallayout> | ||
282 | <note> | ||
283 | The previous commands assume the | ||
284 | <ulink url='&YOCTO_DOCS_REF_URL;#source-repositories'>Source Repositories</ulink> | ||
285 | (i.e. <filename>poky</filename>) have been cloned | ||
286 | using Git and the local repository is named | ||
287 | "poky". | ||
288 | </note> | ||
289 | </para></listitem> | ||
290 | <listitem><para> | ||
291 | <emphasis>Prepare Your <filename>local.conf</filename> | ||
292 | File:</emphasis> | ||
293 | By default, the | ||
294 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> | ||
295 | variable is set to "qemux86", which is fine if you are | ||
296 | building for the QEMU emulator in 32-bit mode. | ||
297 | However, if you are not, you need to set the | ||
298 | <filename>MACHINE</filename> variable appropriately in | ||
299 | your <filename>conf/local.conf</filename> file found | ||
300 | in the | ||
301 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink> | ||
302 | (i.e. <filename>~/poky/build</filename> in this | ||
303 | example).</para> | ||
304 | |||
305 | <para>Also, since you are preparing to work on the | ||
306 | kernel image, you need to set the | ||
307 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS</filename></ulink> | ||
308 | variable to include kernel modules.</para> | ||
309 | |||
310 | <para>This example uses the default "qemux86" for the | ||
311 | <filename>MACHINE</filename> variable but needs to | ||
312 | add the "kernel-modules": | ||
313 | <literallayout class='monospaced'> | ||
314 | MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "kernel-modules" | ||
315 | </literallayout> | ||
316 | </para></listitem> | ||
317 | <listitem><para> | ||
318 | <emphasis>Create a Layer for Patches:</emphasis> | ||
319 | You need to create a layer to hold patches created | ||
320 | for the kernel image. | ||
321 | You can use the <filename>yocto-layer</filename> command | ||
322 | as follows: | ||
323 | <literallayout class='monospaced'> | ||
324 | $ cd ~/poky | ||
325 | $ yocto-layer create my-kernel -o ../meta-my-kernel | ||
326 | Please enter the layer priority you'd like to use for the layer: [default: 6] | ||
327 | Would you like to have an example recipe created? (y/n) [default: n] | ||
328 | Would you like to have an example bbappend file created? (y/n) [default: n] | ||
329 | |||
330 | New layer created in ../meta-my-kernel. | ||
331 | |||
332 | Don't forget to add it to your BBLAYERS (for details see ../meta-my-kernel/README). | ||
333 | </literallayout> | ||
334 | </para></listitem> | ||
335 | <listitem><para> | ||
336 | <emphasis>Inform the BitBake Build Environment About | ||
337 | Your Layer:</emphasis> | ||
338 | As directed when you created your layer, you need to add | ||
339 | the layer to the | ||
340 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink> | ||
341 | variable in the <filename>bblayers.conf</filename> file | ||
342 | as follows: | ||
343 | <literallayout class='monospaced'> | ||
344 | $ cd ~/poky/build | ||
345 | $ bitbake-layers add-layer ../../meta-my-kernel | ||
346 | </literallayout> | ||
347 | </para></listitem> | ||
348 | <listitem><para> | ||
349 | <emphasis>Create a Local Copy of the Kernel Git | ||
350 | Repository:</emphasis> | ||
351 | You can find Git repositories of supported Yocto Project | ||
352 | kernels organized under "Yocto Linux Kernel" in the | ||
353 | Yocto Project Source Repositories at | ||
354 | <ulink url='&YOCTO_GIT_URL;/cgit.cgi'></ulink>. | ||
355 | </para> | ||
356 | |||
357 | <para> | ||
358 | For simplicity, it is recommended that you create your | ||
359 | copy of the kernel Git repository outside of the | ||
360 | <ulink url='&YOCTO_DOCS_REF_URL;source-directory'>Source Directory</ulink>, | ||
361 | which is usually named <filename>poky</filename>. | ||
362 | </para> | ||
363 | |||
364 | <para> | ||
365 | The following command shows how to create a local copy | ||
366 | of the <filename>linux-yocto-4.9</filename> kernel: | ||
367 | <literallayout class='monospaced'> | ||
368 | $ git clone git://git.yoctoproject.org/linux-yocto-4.9 linux-yocto-4.9.git | ||
369 | Cloning into 'linux-yocto-4.9.git'... | ||
370 | remote: Counting objects: 5094108, done. | ||
371 | remote: Compressing objects: 100% (765113/765113), done. | ||
372 | remote: Total 5094108 (delta 4294009), reused 5088388 (delta 4288312) | ||
373 | Receiving objects: 100% (5094108/5094108), 1.02 GiB | 7.82 MiB/s, done. | ||
374 | Resolving deltas: 100% (4294009/4294009), done. | ||
375 | Checking connectivity... done. | ||
376 | Checking out files: 100% (56233/56233), done. | ||
377 | </literallayout> | ||
378 | </para></listitem> | ||
379 | </orderedlist> | ||
380 | </para> | ||
381 | |||
382 | <para> | ||
383 | At this point you have set up to start making modifications to | ||
384 | the kernel using traditional kernel development steps. | ||
385 | For a continued example, see the | ||
386 | "<link linkend='using-traditional-kernel-development-to-patch-the-kernel'>Using Traditional Kernel Development to Patch the Kernel</link>" | ||
387 | section. | ||
388 | </para> | ||
389 | </section> | ||
390 | </section> | ||
20 | 391 | ||
21 | <section id='creating-and-preparing-a-layer'> | 392 | <section id='creating-and-preparing-a-layer'> |
22 | <title>Creating and Preparing a Layer</title> | 393 | <title>Creating and Preparing a Layer</title> |
@@ -824,6 +1195,188 @@ NOTE: This stuff is how it would have been if a *.wic file was created | |||
824 | </orderedlist> | 1195 | </orderedlist> |
825 | </section> | 1196 | </section> |
826 | 1197 | ||
1198 | <section id="using-traditional-kernel-development-to-patch-the-kernel"> | ||
1199 | <title>Using Traditional Kernel Development to Patch the Kernel</title> | ||
1200 | |||
1201 | <para> | ||
1202 | The steps in this procedure show you how you can patch the | ||
1203 | kernel using traditional kernel development (i.e. not using | ||
1204 | <filename>devtool</filename> and the extensible SDK as | ||
1205 | described in the | ||
1206 | "<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>" | ||
1207 | section). | ||
1208 | <note> | ||
1209 | Before attempting this procedure, be sure you have performed | ||
1210 | the steps to get ready for updating the kernel as described | ||
1211 | in the | ||
1212 | "<link linkend='getting-ready-for-traditional-kernel-development'>Getting Ready for Traditional Kernel Development</link>" | ||
1213 | section. | ||
1214 | </note> | ||
1215 | </para> | ||
1216 | |||
1217 | <para> | ||
1218 | Patching the kernel involves changing or adding configurations | ||
1219 | to an existing kernel, changing or adding recipes to the kernel | ||
1220 | that are needed to support specific hardware features, or even | ||
1221 | altering the source code itself. | ||
1222 | <note> | ||
1223 | You can also use the <filename>yocto-kernel</filename> script | ||
1224 | found in the | ||
1225 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> | ||
1226 | under <filename>scripts</filename> to manage kernel patches | ||
1227 | and configuration. | ||
1228 | See the "<ulink url='&YOCTO_DOCS_BSP_URL;#managing-kernel-patches-and-config-items-with-yocto-kernel'>Managing kernel Patches and Config Items with yocto-kernel</ulink>" | ||
1229 | section in the Yocto Project Board Support Packages (BSP) | ||
1230 | Developer's Guide for more information. | ||
1231 | </note> | ||
1232 | </para> | ||
1233 | |||
1234 | <para> | ||
1235 | This example creates a simple patch by adding some QEMU emulator | ||
1236 | console output at boot time through <filename>printk</filename> | ||
1237 | statements in the kernel's <filename>calibrate.c</filename> source | ||
1238 | code file. | ||
1239 | Applying the patch and booting the modified image causes the added | ||
1240 | messages to appear on the emulator's console. | ||
1241 | <note> | ||
1242 | The example is a continuation of the setup procedure found in | ||
1243 | the | ||
1244 | "<link linkend='getting-ready-for-traditional-kernel-development'>Getting Ready for Traditional Kernel Development</link>" | ||
1245 | Section. | ||
1246 | </note> | ||
1247 | </para> | ||
1248 | |||
1249 | <para> | ||
1250 | Also, for more information on patching the kernel, see the | ||
1251 | "<link linkend='applying-patches'>Applying Patches</link>" | ||
1252 | section. | ||
1253 | <orderedlist> | ||
1254 | <listitem><para> | ||
1255 | <emphasis>Know What Branch is Checked Out In Your Local | ||
1256 | Kernel Git Repository:</emphasis> | ||
1257 | Prior to this step, you should have used Git to create a | ||
1258 | local copy of the repository for your kernel. | ||
1259 | Assuming you created the repository as directed in the | ||
1260 | "<link linkend='getting-ready-for-traditional-kernel-development'>Getting Ready for Traditional Kernel Development</link>" | ||
1261 | section, use the following commands to check out the | ||
1262 | <filename>standard/base</filename> branch of the | ||
1263 | Linux Yocto 4.9 kernel: | ||
1264 | <literallayout class='monospaced'> | ||
1265 | $ cd ~/linux-yocto-4.9 | ||
1266 | $ git checkout -b standard/base origin/standard/base | ||
1267 | </literallayout> | ||
1268 | </para></listitem> | ||
1269 | <listitem><para> | ||
1270 | <emphasis>Edit the Source Files</emphasis> | ||
1271 | Follow these steps to make some simple changes to the source | ||
1272 | files: | ||
1273 | <orderedlist> | ||
1274 | <listitem><para> | ||
1275 | <emphasis>Change the working directory</emphasis>: | ||
1276 | You need to locate the source files in the | ||
1277 | local copy of the kernel Git repository: | ||
1278 | Change to where the kernel source code is before making | ||
1279 | your edits to the <filename>calibrate.c</filename> file: | ||
1280 | <literallayout class='monospaced'> | ||
1281 | $ cd ~/linux-yocto-4.9/init | ||
1282 | </literallayout> | ||
1283 | </para></listitem> | ||
1284 | <listitem><para> | ||
1285 | <emphasis>Edit the source file</emphasis>: | ||
1286 | Edit the <filename>calibrate.c</filename> file to have | ||
1287 | the following changes: | ||
1288 | <literallayout class='monospaced'> | ||
1289 | void calibrate_delay(void) | ||
1290 | { | ||
1291 | unsigned long lpj; | ||
1292 | static bool printed; | ||
1293 | int this_cpu = smp_processor_id(); | ||
1294 | |||
1295 | printk("*************************************\n"); | ||
1296 | printk("* *\n"); | ||
1297 | printk("* HELLO YOCTO KERNEL *\n"); | ||
1298 | printk("* *\n"); | ||
1299 | printk("*************************************\n"); | ||
1300 | |||
1301 | if (per_cpu(cpu_loops_per_jiffy, this_cpu)) { | ||
1302 | . | ||
1303 | . | ||
1304 | . | ||
1305 | </literallayout> | ||
1306 | </para></listitem> | ||
1307 | </orderedlist> | ||
1308 | </para></listitem> | ||
1309 | <listitem><para> | ||
1310 | <emphasis>Stage and Commit Your Changes:</emphasis> | ||
1311 | Use standard Git commands to stage and commit the changes | ||
1312 | you just made: | ||
1313 | <literallayout class='monospaced'> | ||
1314 | $ git add calibrate.c | ||
1315 | $ git commit -m "calibrate.c - Added some printk statements" | ||
1316 | </literallayout> | ||
1317 | If you do not stage and commit your changes, the OpenEmbedded | ||
1318 | Build System will not pick up the changes. | ||
1319 | </para></listitem> | ||
1320 | <listitem><para> | ||
1321 | <emphasis>Update Your <filename>local.conf</filename> File to Point to Your Source Files:</emphasis> | ||
1322 | In addition to your <filename>local.conf</filename> file | ||
1323 | specifying to use "kernel-modules" and the "qemux86" machine, | ||
1324 | it must also point to the updated kernel source files. | ||
1325 | Add the following commands to your | ||
1326 | <filename>local.conf</filename>: | ||
1327 | <literallayout class='monospaced'> | ||
1328 | $ cd ~/poky/build/conf | ||
1329 | <replaceable>Add the following:</replaceable> | ||
1330 | |||
1331 | SRC_URI_pn-linux-yocto = "git:///$HOME/linux-yocto-4.9;protocol=file;name=machine;branch=standard/base; \ | ||
1332 | git:///home/scottrif/yocto-kernel-cache;protocol=file;type=kmeta;name=meta;branch=yocto-4.9;destsuffix=${KMETA}" | ||
1333 | SRCREV_meta_qemux86 = "${AUTOREV}" | ||
1334 | SRCREV_machine_qemux86 = "${AUTOREV}" | ||
1335 | </literallayout> | ||
1336 | You must be sure to specify the correct branch and machine | ||
1337 | types. | ||
1338 | For this example, the branch is | ||
1339 | <filename>standard/base</filename> and the machine is | ||
1340 | "qemux86". | ||
1341 | </para></listitem> | ||
1342 | <listitem><para> | ||
1343 | <emphasis>Build the Image:</emphasis> | ||
1344 | With the source modified, staged, and committed, and | ||
1345 | the <filename>local.conf</filename> file pointing to | ||
1346 | the kernel files, you can now use BitBake to build the | ||
1347 | image: | ||
1348 | <literallayout class='monospaced'> | ||
1349 | $ cd ~/poky/build | ||
1350 | $ bitbake core-image-minimal | ||
1351 | </literallayout> | ||
1352 | </para></listitem> | ||
1353 | <listitem><para> | ||
1354 | <emphasis>Boot the image</emphasis>: | ||
1355 | Boot the modified image in the QEMU emulator | ||
1356 | using this command. | ||
1357 | When prompted to login to the QEMU console, use "root" | ||
1358 | with no password: | ||
1359 | <literallayout class='monospaced'> | ||
1360 | $ runqemu qemux86 | ||
1361 | </literallayout> | ||
1362 | </para></listitem> | ||
1363 | <listitem><para> | ||
1364 | <emphasis>Look for Your Changes:</emphasis> | ||
1365 | As QEMU booted, you might have seen your changes rapidly | ||
1366 | scroll by. | ||
1367 | If not, use these commands to see your changes: | ||
1368 | <literallayout class='monospaced'> | ||
1369 | # dmesg | less | ||
1370 | </literallayout> | ||
1371 | You should see the results of your | ||
1372 | <filename>printk</filename> statements | ||
1373 | as part of the output when you scroll down the | ||
1374 | console window. | ||
1375 | </para></listitem> | ||
1376 | </orderedlist> | ||
1377 | </para> | ||
1378 | </section> | ||
1379 | |||
827 | <section id='using-an-iterative-development-process'> | 1380 | <section id='using-an-iterative-development-process'> |
828 | <title>Using an Iterative Development Process</title> | 1381 | <title>Using an Iterative Development Process</title> |
829 | 1382 | ||