kernel-dev-examples.xml 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  2. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
  3. [<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] >
  4. <chapter id='kernel-how-to'>
  5. <title>Working with the Yocto Project Kernel</title>
  6. <section id='actions-org'>
  7. <title>Introduction</title>
  8. <para>
  9. This chapter describes how to accomplish tasks involving a kernel's tree structure.
  10. The information is designed to help the developer that wants to modify the Yocto
  11. Project kernel and contribute changes upstream to the Yocto Project.
  12. The information covers the following:
  13. <itemizedlist>
  14. <listitem><para>Tree construction</para></listitem>
  15. <listitem><para>Build strategies</para></listitem>
  16. <listitem><para>Workflow examples</para></listitem>
  17. </itemizedlist>
  18. </para>
  19. </section>
  20. <section id='tree-construction'>
  21. <title>Tree Construction</title>
  22. <para>
  23. This section describes construction of the Yocto Project kernel source repositories
  24. as accomplished by the Yocto Project team to create kernel repositories.
  25. These kernel repositories are found under the heading "Yocto Linux Kernel" at
  26. <ulink url='&YOCTO_GIT_URL;/cgit.cgi'>&YOCTO_GIT_URL;/cgit.cgi</ulink>
  27. and can be shipped as part of a Yocto Project release.
  28. The team creates these repositories by
  29. compiling and executing the set of feature descriptions for every BSP/feature
  30. in the product.
  31. Those feature descriptions list all necessary patches,
  32. configuration, branching, tagging and feature divisions found in a kernel.
  33. Thus, the Yocto Project kernel repository (or tree) is built.
  34. </para>
  35. <para>
  36. The existence of this tree allows you to access and clone a particular
  37. Yocto Project kernel repository and use it to build images based on their configurations
  38. and features.
  39. </para>
  40. <para>
  41. You can find the files used to describe all the valid features and BSPs
  42. in the Yocto Project kernel in any clone of the Yocto Project kernel source repository
  43. Git tree.
  44. For example, the following command clones the Yocto Project baseline kernel that
  45. branched off of <filename>linux.org</filename> version 3.4:
  46. <literallayout class='monospaced'>
  47. $ git clone git://git.yoctoproject.org/linux-yocto-3.4
  48. </literallayout>
  49. For another example of how to set up a local Git repository of the Yocto Project
  50. kernel files, see the
  51. "<ulink url='&YOCTO_DOCS_DEV_URL;#local-kernel-files'>Yocto Project Kernel</ulink>" bulleted
  52. item in the Yocto Project Development Manual.
  53. </para>
  54. <para>
  55. Once you have cloned the kernel Git repository on your local machine, you can
  56. switch to the <filename>meta</filename> branch within the repository.
  57. Here is an example that assumes the local Git repository for the kernel is in
  58. a top-level directory named <filename>linux-yocto-3.4</filename>:
  59. <literallayout class='monospaced'>
  60. $ cd ~/linux-yocto-3.4
  61. $ git checkout -b meta origin/meta
  62. </literallayout>
  63. Once you have checked out and switched to the <filename>meta</filename> branch,
  64. you can see a snapshot of all the kernel configuration and feature descriptions that are
  65. used to build that particular kernel repository.
  66. These descriptions are in the form of <filename>.scc</filename> files.
  67. </para>
  68. <para>
  69. You should realize, however, that browsing your local kernel repository
  70. for feature descriptions and patches is not an effective way to determine what is in a
  71. particular kernel branch.
  72. Instead, you should use Git directly to discover the changes in a branch.
  73. Using Git is an efficient and flexible way to inspect changes to the kernel.
  74. For examples showing how to use Git to inspect kernel commits, see the following sections
  75. in this chapter.
  76. <note>
  77. Ground up reconstruction of the complete kernel tree is an action only taken by the
  78. Yocto Project team during an active development cycle.
  79. When you create a clone of the kernel Git repository, you are simply making it
  80. efficiently available for building and development.
  81. </note>
  82. </para>
  83. <para>
  84. The following steps describe what happens when the Yocto Project Team constructs
  85. the Yocto Project kernel source Git repository (or tree) found at
  86. <ulink url='&YOCTO_GIT_URL;/cgit.cgi'></ulink> given the
  87. introduction of a new top-level kernel feature or BSP.
  88. These are the actions that effectively create the tree
  89. that includes the new feature, patch or BSP:
  90. <orderedlist>
  91. <listitem><para>A top-level kernel feature is passed to the kernel build subsystem.
  92. Normally, this feature is a BSP for a particular kernel type.</para></listitem>
  93. <listitem><para>The file that describes the top-level feature is located by searching
  94. these system directories:
  95. <itemizedlist>
  96. <listitem><para>The in-tree kernel-cache directories, which are located
  97. in <filename>meta/cfg/kernel-cache</filename></para></listitem>
  98. <listitem><para>Areas pointed to by <filename>SRC_URI</filename> statements
  99. found in recipes</para></listitem>
  100. </itemizedlist>
  101. For a typical build, the target of the search is a
  102. feature description in an <filename>.scc</filename> file
  103. whose name follows this format:
  104. <literallayout class='monospaced'>
  105. &lt;bsp_name&gt;-&lt;kernel_type&gt;.scc
  106. </literallayout>
  107. </para></listitem>
  108. <listitem><para>Once located, the feature description is either compiled into a simple script
  109. of actions, or into an existing equivalent script that is already part of the
  110. shipped kernel.</para></listitem>
  111. <listitem><para>Extra features are appended to the top-level feature description.
  112. These features can come from the
  113. <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_FEATURES'><filename>KERNEL_FEATURES</filename></ulink>
  114. variable in recipes.</para></listitem>
  115. <listitem><para>Each extra feature is located, compiled and appended to the script
  116. as described in step three.</para></listitem>
  117. <listitem><para>The script is executed to produce a series of <filename>meta-*</filename>
  118. directories.
  119. These directories are descriptions of all the branches, tags, patches and configurations that
  120. need to be applied to the base Git repository to completely create the
  121. source (build) branch for the new BSP or feature.</para></listitem>
  122. <listitem><para>The base repository is cloned, and the actions
  123. listed in the <filename>meta-*</filename> directories are applied to the
  124. tree.</para></listitem>
  125. <listitem><para>The Git repository is left with the desired branch checked out and any
  126. required branching, patching and tagging has been performed.</para></listitem>
  127. </orderedlist>
  128. </para>
  129. <para>
  130. The kernel tree is now ready for developer consumption to be locally cloned,
  131. configured, and built into a Yocto Project kernel specific to some target hardware.
  132. <note><para>The generated <filename>meta-*</filename> directories add to the kernel
  133. as shipped with the Yocto Project release.
  134. Any add-ons and configuration data are applied to the end of an existing branch.
  135. The full repository generation that is found in the
  136. official Yocto Project kernel repositories at
  137. <ulink url='&YOCTO_GIT_URL;/cgit.cgi'>http://git.yoctoproject.org/cgit.cgi</ulink>
  138. is the combination of all supported boards and configurations.</para>
  139. <para>The technique the Yocto Project team uses is flexible and allows for seamless
  140. blending of an immutable history with additional patches specific to a
  141. deployment.
  142. Any additions to the kernel become an integrated part of the branches.</para>
  143. </note>
  144. </para>
  145. </section>
  146. <section id='build-strategy'>
  147. <title>Build Strategy</title>
  148. <para>
  149. Once a local Git repository of the Yocto Project kernel exists on a development system,
  150. you can consider the compilation phase of kernel development - building a kernel image.
  151. Some prerequisites exist that are validated by the build process before compilation
  152. starts:
  153. </para>
  154. <itemizedlist>
  155. <listitem><para>The
  156. <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> points
  157. to the kernel Git repository.</para></listitem>
  158. <listitem><para>A BSP build branch exists.
  159. This branch has the following form:
  160. <literallayout class='monospaced'>
  161. &lt;kernel_type&gt;/&lt;bsp_name&gt;
  162. </literallayout></para></listitem>
  163. </itemizedlist>
  164. <para>
  165. The OpenEmbedded build system makes sure these conditions exist before attempting compilation.
  166. Other means, however, do exist, such as as bootstrapping a BSP, see
  167. the "<link linkend='workflow-examples'>Workflow Examples</link>".
  168. </para>
  169. <para>
  170. Before building a kernel, the build process verifies the tree
  171. and configures the kernel by processing all of the
  172. configuration "fragments" specified by feature descriptions in the <filename>.scc</filename>
  173. files.
  174. As the features are compiled, associated kernel configuration fragments are noted
  175. and recorded in the <filename>meta-*</filename> series of directories in their compilation order.
  176. The fragments are migrated, pre-processed and passed to the Linux Kernel
  177. Configuration subsystem (<filename>lkc</filename>) as raw input in the form
  178. of a <filename>.config</filename> file.
  179. The <filename>lkc</filename> uses its own internal dependency constraints to do the final
  180. processing of that information and generates the final <filename>.config</filename> file
  181. that is used during compilation.
  182. </para>
  183. <para>
  184. Using the board's architecture and other relevant values from the board's template,
  185. kernel compilation is started and a kernel image is produced.
  186. </para>
  187. <para>
  188. The other thing that you notice once you configure a kernel is that
  189. the build process generates a build tree that is separate from your kernel's local Git
  190. source repository tree.
  191. This build tree has a name that uses the following form, where
  192. <filename>${MACHINE}</filename> is the metadata name of the machine (BSP) and "kernel_type" is one
  193. of the Yocto Project supported kernel types (e.g. "standard"):
  194. <literallayout class='monospaced'>
  195. linux-${MACHINE}-&lt;kernel_type&gt;-build
  196. </literallayout>
  197. </para>
  198. <para>
  199. The existing support in the <filename>kernel.org</filename> tree achieves this
  200. default functionality.
  201. </para>
  202. <para>
  203. This behavior means that all the generated files for a particular machine or BSP are now in
  204. the build tree directory.
  205. The files include the final <filename>.config</filename> file, all the <filename>.o</filename>
  206. files, the <filename>.a</filename> files, and so forth.
  207. Since each machine or BSP has its own separate build directory in its own separate branch
  208. of the Git repository, you can easily switch between different builds.
  209. </para>
  210. </section>
  211. <section id='workflow-examples'>
  212. <title>Workflow Examples</title>
  213. <para>
  214. As previously noted, the Yocto Project kernel has built-in Git integration.
  215. However, these utilities are not the only way to work with the kernel repository.
  216. The Yocto Project has not made changes to Git or to other tools that
  217. would invalidate alternate workflows.
  218. Additionally, the way the kernel repository is constructed results in using
  219. only core Git functionality, thus allowing any number of tools or front ends to use the
  220. resulting tree.
  221. </para>
  222. <para>
  223. This section contains several workflow examples.
  224. Many of the examples use Git commands.
  225. You can find Git documentation at
  226. <ulink url='http://git-scm.com/documentation'></ulink>.
  227. You can find a simple overview of using Git with the Yocto Project in the
  228. "<ulink url='&YOCTO_DOCS_DEV_URL;#git'>Git</ulink>"
  229. section of the Yocto Project Development Manual.
  230. </para>
  231. <section id='change-inspection-kernel-changes-commits'>
  232. <title>Change Inspection: Changes/Commits</title>
  233. <para>
  234. A common question when working with a kernel is:
  235. "What changes have been applied to this tree?"
  236. </para>
  237. <para>
  238. In projects that have a collection of directories that
  239. contain patches to the kernel, it is possible to inspect or "grep" the contents
  240. of the directories to get a general feel for the changes.
  241. This sort of patch inspection is not an efficient way to determine what has been
  242. done to the kernel.
  243. The reason it is inefficient is because there are many optional patches that are
  244. selected based on the kernel type and the feature description.
  245. Additionally, patches could exist in directories that are not included in the search.
  246. </para>
  247. <para>
  248. A more efficient way to determine what has changed in the branch is to use
  249. Git and inspect or search the kernel tree.
  250. This method gives you a full view of not only the source code modifications,
  251. but also provides the reasons for the changes.
  252. </para>
  253. <section id='what-changed-in-a-kernel'>
  254. <title>What Changed in a Kernel?</title>
  255. <para>
  256. Following are a few examples that show how to use Git commands to examine changes.
  257. Because Git repositories in the Yocto Project do not break existing Git
  258. functionality, and because there exists many permutations of these types of
  259. Git commands, many methods exist by which you can discover changes.
  260. <note>
  261. In the following examples, unless you provide a commit range,
  262. <filename>kernel.org</filename> history is blended with Yocto Project
  263. kernel changes.
  264. You can form ranges by using branch names from the kernel tree as the
  265. upper and lower commit markers with the Git commands.
  266. You can see the branch names through the web interface to the
  267. Yocto Project source repositories at
  268. <ulink url='http://git.yoctoproject.org/cgit.cgi'></ulink>.
  269. For example, the branch names for the <filename>linux-yocto-3.4</filename>
  270. kernel repository can be seen at
  271. <ulink url='http://git.yoctoproject.org/cgit.cgi/linux-yocto-3.4/refs/heads'></ulink>.
  272. </note>
  273. To see a full range of the changes, use the
  274. <filename>git whatchanged</filename> command and specify a commit range
  275. for the branch (<filename>&lt;commit&gt;..&lt;commit&gt;</filename>).
  276. </para>
  277. <para>
  278. Here is an example that looks at what has changed in the
  279. <filename>emenlow</filename> branch of the
  280. <filename>linux-yocto-3.4</filename> kernel.
  281. The lower commit range is the commit associated with the
  282. <filename>standard/base</filename> branch, while
  283. the upper commit range is the commit associated with the
  284. <filename>standard/emenlow</filename> branch.
  285. <literallayout class='monospaced'>
  286. $ git whatchanged origin/standard/base..origin/standard/emenlow
  287. </literallayout>
  288. </para>
  289. <para>
  290. To see a summary of changes use the <filename>git log</filename> command.
  291. Here is an example using the same branches:
  292. <literallayout class='monospaced'>
  293. $ git log --oneline origin/standard/base..origin/standard/emenlow
  294. </literallayout>
  295. The <filename>git log</filename> output might be more useful than
  296. the <filename>git whatchanged</filename> as you get
  297. a short, one-line summary of each change and not the entire commit.
  298. </para>
  299. <para>
  300. If you want to see code differences associated with all the changes, use
  301. the <filename>git diff</filename> command.
  302. Here is an example:
  303. <literallayout class='monospaced'>
  304. $ git diff origin/standard/base..origin/standard/emenlow
  305. </literallayout>
  306. </para>
  307. <para>
  308. You can see the commit log messages and the text differences using the
  309. <filename>git show</filename> command:
  310. Here is an example:
  311. <literallayout class='monospaced'>
  312. $ git show origin/standard/base..origin/standard/emenlow
  313. </literallayout>
  314. </para>
  315. <para>
  316. You can create individual patches for each change by using the
  317. <filename>git format-patch</filename> command.
  318. Here is an example that that creates patch files for each commit and
  319. places them in your <filename>Documents</filename> directory:
  320. <literallayout class='monospaced'>
  321. $ git format-patch -o $HOME/Documents origin/standard/base..origin/standard/emenlow
  322. </literallayout>
  323. </para>
  324. </section>
  325. <section id='show-a-particular-feature-or-branch-change'>
  326. <title>Show a Particular Feature or Branch Change</title>
  327. <para>
  328. Developers use tags in the Yocto Project kernel tree to divide changes for significant
  329. features or branches.
  330. Once you know a particular tag, you can use Git commands
  331. to show changes associated with the tag and find the branches that contain
  332. the feature.
  333. <note>
  334. Because BSP branch, <filename>kernel.org</filename>, and feature tags are all
  335. present, there could be many tags.
  336. </note>
  337. The <filename>git show &lt;tag&gt;</filename> command shows changes that are tagged by
  338. a feature.
  339. Here is an example that shows changes tagged by the <filename>systemtap</filename>
  340. feature:
  341. <literallayout class='monospaced'>
  342. $ git show systemtap
  343. </literallayout>
  344. You can use the <filename>git branch --contains &lt;tag&gt;</filename> command
  345. to show the branches that contain a particular feature.
  346. This command shows the branches that contain the <filename>systemtap</filename>
  347. feature:
  348. <literallayout class='monospaced'>
  349. $ git branch --contains systemtap
  350. </literallayout>
  351. </para>
  352. <para>
  353. You can use many other comparisons to isolate BSP and kernel changes.
  354. For example, you can compare against <filename>kernel.org</filename> tags
  355. such as the <filename>v3.4</filename> tag.
  356. </para>
  357. </section>
  358. </section>
  359. <section id='development-saving-kernel-modifications'>
  360. <title>Development: Saving Kernel Modifications</title>
  361. <para>
  362. Another common operation is to build a BSP supplied by the Yocto Project, make some
  363. changes, rebuild, and then test.
  364. Those local changes often need to be exported, shared or otherwise maintained.
  365. </para>
  366. <para>
  367. Since the Yocto Project kernel source tree is backed by Git, this activity is
  368. much easier as compared to with previous releases.
  369. Because Git tracks file modifications, additions and deletions, it is easy
  370. to modify the code and later realize that you need to save the changes.
  371. It is also easy to determine what has changed.
  372. This method also provides many tools to commit, undo and export those modifications.
  373. </para>
  374. <para>
  375. This section and its sub-sections, describe general application of Git's
  376. <filename>push</filename> and <filename>pull</filename> commands, which are used to
  377. get your changes upstream or source your code from an upstream repository.
  378. The Yocto Project provides scripts that help you work in a collaborative development
  379. environment.
  380. For information on these scripts, see the
  381. "<ulink url='&YOCTO_DOCS_DEV_URL;#pushing-a-change-upstream'>Using Scripts to Push a Change
  382. Upstream and Request a Pull</ulink>" and
  383. "<ulink url='&YOCTO_DOCS_DEV_URL;#submitting-a-patch'>Using Email to Submit a Patch</ulink>"
  384. sections in the Yocto Project Development Manual.
  385. </para>
  386. <para>
  387. There are many ways to save kernel modifications.
  388. The technique employed
  389. depends on the destination for the patches:
  390. <itemizedlist>
  391. <listitem><para>Bulk storage</para></listitem>
  392. <listitem><para>Internal sharing either through patches or by using Git</para></listitem>
  393. <listitem><para>External submissions</para></listitem>
  394. <listitem><para>Exporting for integration into another Source Code
  395. Manager (SCM)</para></listitem>
  396. </itemizedlist>
  397. </para>
  398. <para>
  399. Because of the following list of issues, the destination of the patches also influences
  400. the method for gathering them:
  401. <itemizedlist>
  402. <listitem><para>Bisectability</para></listitem>
  403. <listitem><para>Commit headers</para></listitem>
  404. <listitem><para>Division of subsystems for separate submission or review</para></listitem>
  405. </itemizedlist>
  406. </para>
  407. <section id='bulk-export'>
  408. <title>Bulk Export</title>
  409. <para>
  410. This section describes how you can "bulk" export changes that have not
  411. been separated or divided.
  412. This situation works well when you are simply storing patches outside of the kernel
  413. source repository, either permanently or temporarily, and you are not committing
  414. incremental changes during development.
  415. <note>
  416. This technique is not appropriate for full integration of upstream submission
  417. because changes are not properly divided and do not provide an avenue for per-change
  418. commit messages.
  419. Therefore, this example assumes that changes have not been committed incrementally
  420. during development and that you simply must gather and export them.
  421. </note>
  422. <literallayout class='monospaced'>
  423. # bulk export of ALL modifications without separation or division
  424. # of the changes
  425. $ git add .
  426. $ git commit -s -a -m &lt;msg&gt;
  427. or
  428. $ git commit -s -a # and interact with $EDITOR
  429. </literallayout>
  430. </para>
  431. <para>
  432. The previous operations capture all the local changes in the project source
  433. tree in a single Git commit.
  434. And, that commit is also stored in the project's source tree.
  435. </para>
  436. <para>
  437. Once the changes are exported, you can restore them manually using a template
  438. or through integration with the <filename>default_kernel</filename>.
  439. </para>
  440. </section>
  441. <section id='incremental-planned-sharing'>
  442. <title>Incremental/Planned Sharing</title>
  443. <para>
  444. This section describes how to save modifications when you are making incremental
  445. commits or practicing planned sharing.
  446. The examples in this section assume that you have incrementally committed
  447. changes to the tree during development and now need to export them.
  448. The sections that follow
  449. describe how you can export your changes internally through either patches or by
  450. using Git commands.
  451. </para>
  452. <para>
  453. During development, the following commands are of interest.
  454. For full Git documentation, refer to the Git documentation at
  455. <ulink url='http://github.com'></ulink>.
  456. <literallayout class='monospaced'>
  457. # edit a file
  458. $ vi &lt;path&gt;/file
  459. # stage the change
  460. $ git add &lt;path&gt;/file
  461. # commit the change
  462. $ git commit -s
  463. # remove a file
  464. $ git rm &lt;path&gt;/file
  465. # commit the change
  466. $ git commit -s
  467. ... etc.
  468. </literallayout>
  469. </para>
  470. <para>
  471. Distributed development with Git is possible when you use a universally
  472. agreed-upon unique commit identifier (set by the creator of the commit) that maps to a
  473. specific change set with a specific parent.
  474. This identifier is created for you when
  475. you create a commit, and is re-created when you amend, alter or re-apply
  476. a commit.
  477. As an individual in isolation, this is of no interest.
  478. However, if you
  479. intend to share your tree with normal Git <filename>push</filename> and
  480. <filename>pull</filename> operations for
  481. distributed development, you should consider the ramifications of changing a
  482. commit that you have already shared with others.
  483. </para>
  484. <para>
  485. Assuming that the changes have not been pushed upstream, or pulled into
  486. another repository, you can update both the commit content and commit messages
  487. associated with development by using the following commands:
  488. <literallayout class='monospaced'>
  489. $ Git add &lt;path&gt;/file
  490. $ Git commit --amend
  491. $ Git rebase or Git rebase -i
  492. </literallayout>
  493. </para>
  494. <para>
  495. Again, assuming that the changes have not been pushed upstream, and that
  496. no pending works-in-progress exist (use <filename>git status</filename> to check), then
  497. you can revert (undo) commits by using the following commands:
  498. <literallayout class='monospaced'>
  499. # remove the commit, update working tree and remove all
  500. # traces of the change
  501. $ git reset --hard HEAD^
  502. # remove the commit, but leave the files changed and staged for re-commit
  503. $ git reset --soft HEAD^
  504. # remove the commit, leave file change, but not staged for commit
  505. $ git reset --mixed HEAD^
  506. </literallayout>
  507. </para>
  508. <para>
  509. You can create branches, "cherry-pick" changes, or perform any number of Git
  510. operations until the commits are in good order for pushing upstream
  511. or for pull requests.
  512. After a <filename>push</filename> or <filename>pull</filename> command,
  513. commits are normally considered
  514. "permanent" and you should not modify them.
  515. If the commits need to be changed, you can incrementally do so with new commits.
  516. These practices follow standard Git workflow and the <filename>kernel.org</filename> best
  517. practices, which is recommended.
  518. <note>
  519. It is recommended to tag or branch before adding changes to a Yocto Project
  520. BSP or before creating a new one.
  521. The reason for this recommendation is because the branch or tag provides a
  522. reference point to facilitate locating and exporting local changes.
  523. </note>
  524. </para>
  525. <section id='export-internally-via-patches'>
  526. <title>Exporting Changes Internally by Using Patches</title>
  527. <para>
  528. This section describes how you can extract committed changes from a working directory
  529. by exporting them as patches.
  530. Once the changes have been extracted, you can use the patches for upstream submission,
  531. place them in a Yocto Project template for automatic kernel patching,
  532. or apply them in many other common uses.
  533. </para>
  534. <para>
  535. This example shows how to create a directory with sequentially numbered patches.
  536. Once the directory is created, you can apply it to a repository using the
  537. <filename>git am</filename> command to reproduce the original commit and all
  538. the related information such as author, date, commit log, and so forth.
  539. <note>
  540. The new commit identifiers (ID) will be generated upon re-application.
  541. This action reflects that the commit is now applied to an underlying commit
  542. with a different ID.
  543. </note>
  544. <literallayout class='monospaced'>
  545. # &lt;first-commit&gt; can be a tag if one was created before development
  546. # began. It can also be the parent branch if a branch was created
  547. # before development began.
  548. $ git format-patch -o &lt;dir&gt; &lt;first commit&gt;..&lt;last commit&gt;
  549. </literallayout>
  550. </para>
  551. <para>
  552. In other words:
  553. <literallayout class='monospaced'>
  554. # Identify commits of interest.
  555. # If the tree was tagged before development
  556. $ git format-patch -o &lt;save dir&gt; &lt;tag&gt;
  557. # If no tags are available
  558. $ git format-patch -o &lt;save dir&gt; HEAD^ # last commit
  559. $ git format-patch -o &lt;save dir&gt; HEAD^^ # last 2 commits
  560. $ git whatchanged # identify last commit
  561. $ git format-patch -o &lt;save dir&gt; &lt;commit id&gt;
  562. $ git format-patch -o &lt;save dir&gt; &lt;rev-list&gt;
  563. </literallayout>
  564. </para>
  565. </section>
  566. <section id='export-internally-via-git'>
  567. <title>Exporting Changes Internally by Using Git</title>
  568. <para>
  569. This section describes how you can export changes from a working directory
  570. by pushing the changes into a master repository or by making a pull request.
  571. Once you have pushed the changes to the master repository, you can then
  572. pull those same changes into a new kernel build at a later time.
  573. </para>
  574. <para>
  575. Use this command form to push the changes:
  576. <literallayout class='monospaced'>
  577. $ git push ssh://&lt;master_server&gt;/&lt;path_to_repo&gt;
  578. &lt;local_branch&gt;:&lt;remote_branch&gt;
  579. </literallayout>
  580. </para>
  581. <para>
  582. For example, the following command pushes the changes from your local branch
  583. <filename>yocto/standard/common-pc/base</filename> to the remote branch with the same name
  584. in the master repository <filename>//git.mycompany.com/pub/git/kernel-3.4</filename>.
  585. <literallayout class='monospaced'>
  586. $ git push ssh://git.mycompany.com/pub/git/kernel-3.4 \
  587. yocto/standard/common-pc/base:yocto/standard/common-pc/base
  588. </literallayout>
  589. </para>
  590. <para>
  591. A pull request entails using the <filename>git request-pull</filename> command to compose
  592. an email to the
  593. maintainer requesting that a branch be pulled into the master repository, see
  594. <ulink url='http://github.com/guides/pull-requests'></ulink> for an example.
  595. <note>
  596. Other commands such as <filename>git stash</filename> or branching can also be used to save
  597. changes, but are not covered in this document.
  598. </note>
  599. </para>
  600. </section>
  601. </section>
  602. <section id='export-for-external-upstream-submission'>
  603. <title>Exporting Changes for External (Upstream) Submission</title>
  604. <para>
  605. This section describes how to export changes for external upstream submission.
  606. If the patch series is large or the maintainer prefers to pull
  607. changes, you can submit these changes by using a pull request.
  608. However, it is common to send patches as an email series.
  609. This method allows easy review and integration of the changes.
  610. <note>
  611. Before sending patches for review be sure you understand the
  612. community standards for submitting and documenting changes and follow their best practices.
  613. For example, kernel patches should follow standards such as:
  614. <itemizedlist>
  615. <listitem><para>
  616. <ulink url='http://linux.yyz.us/patch-format.html'></ulink></para></listitem>
  617. <listitem><para>Documentation/SubmittingPatches (in any linux
  618. kernel source tree)</para></listitem>
  619. </itemizedlist>
  620. </note>
  621. </para>
  622. <para>
  623. The messages used to commit changes are a large part of these standards.
  624. Consequently, be sure that the headers for each commit have the required information.
  625. For information on how to follow the Yocto Project commit message standards, see the
  626. "<ulink url='&YOCTO_DOCS_DEV_URL;#how-to-submit-a-change'>How to Submit a
  627. Change</ulink>" section in the Yocto Project Development Manual.
  628. </para>
  629. <para>
  630. If the initial commits were not properly documented or do not meet those standards,
  631. you can re-base by using the <filename>git rebase -i</filename> command to
  632. manipulate the commits and
  633. get them into the required format.
  634. Other techniques such as branching and cherry-picking commits are also viable options.
  635. </para>
  636. <para>
  637. Once you complete the commits, you can generate the email that sends the patches
  638. to the maintainer(s) or lists that review and integrate changes.
  639. The command <filename>git send-email</filename> is commonly used to ensure
  640. that patches are properly
  641. formatted for easy application and avoid mailer-induced patch damage.
  642. </para>
  643. <para>
  644. The following is an example of dumping patches for external submission:
  645. <literallayout class='monospaced'>
  646. # dump the last 4 commits
  647. $ git format-patch --thread -n -o ~/rr/ HEAD^^^^
  648. $ git send-email --compose --subject '[RFC 0/N] &lt;patch series summary&gt;' \
  649. --to foo@yoctoproject.org --to bar@yoctoproject.org \
  650. --cc list@yoctoproject.org ~/rr
  651. # the editor is invoked for the 0/N patch, and when complete the entire
  652. # series is sent via email for review
  653. </literallayout>
  654. </para>
  655. </section>
  656. <section id='export-for-import-into-other-scm'>
  657. <title>Exporting Changes for Import into Another SCM</title>
  658. <para>
  659. When you want to export changes for import into another
  660. Source Code Manager (SCM), you can use any of the previously discussed
  661. techniques.
  662. However, if the patches are manually applied to a secondary tree and then
  663. that tree is checked into the SCM, you can lose change information such as
  664. commit logs.
  665. This process is not recommended.
  666. </para>
  667. <para>
  668. Many SCMs can directly import Git commits, or can translate Git patches so that
  669. information is not lost.
  670. Those facilities are SCM-dependent and you should use them whenever possible.
  671. </para>
  672. </section>
  673. </section>
  674. <section id='scm-working-with-the-yocto-project-kernel-in-another-scm'>
  675. <title>Working with the Yocto Project Kernel in Another SCM</title>
  676. <para>
  677. This section describes kernel development in an SCM other than Git,
  678. which is not the same as exporting changes to another SCM described earlier.
  679. For this scenario, you use the OpenEmbedded build system to
  680. develop the kernel in a different SCM.
  681. The following must be true for you to accomplish this:
  682. <itemizedlist>
  683. <listitem><para>The delivered Yocto Project kernel must be exported into the second
  684. SCM.</para></listitem>
  685. <listitem><para>Development must be exported from that secondary SCM into a
  686. format that can be used by the OpenEmbedded build system.</para></listitem>
  687. </itemizedlist>
  688. </para>
  689. <section id='exporting-delivered-kernel-to-scm'>
  690. <title>Exporting the Delivered Kernel to the SCM</title>
  691. <para>
  692. Depending on the SCM, it might be possible to export the entire Yocto Project
  693. kernel Git repository, branches and all, into a new environment.
  694. This method is preferred because it has the most flexibility and potential to maintain
  695. the meta data associated with each commit.
  696. </para>
  697. <para>
  698. When a direct import mechanism is not available, it is still possible to
  699. export a branch (or series of branches) and check them into a new repository.
  700. </para>
  701. <para>
  702. The following commands illustrate some of the steps you could use to
  703. import the <filename>yocto/standard/common-pc/base</filename>
  704. kernel into a secondary SCM:
  705. <literallayout class='monospaced'>
  706. $ git checkout yocto/standard/common-pc/base
  707. $ cd .. ; echo linux/.git &gt; .cvsignore
  708. $ cvs import -m "initial import" linux MY_COMPANY start
  709. </literallayout>
  710. </para>
  711. <para>
  712. You could now relocate the CVS repository and use it in a centralized manner.
  713. </para>
  714. <para>
  715. The following commands illustrate how you can condense and merge two BSPs into a
  716. second SCM:
  717. <literallayout class='monospaced'>
  718. $ git checkout yocto/standard/common-pc/base
  719. $ git merge yocto/standard/common-pc-64/base
  720. # resolve any conflicts and commit them
  721. $ cd .. ; echo linux/.git &gt; .cvsignore
  722. $ cvs import -m "initial import" linux MY_COMPANY start
  723. </literallayout>
  724. </para>
  725. </section>
  726. <section id='importing-changes-for-build'>
  727. <title>Importing Changes for the Build</title>
  728. <para>
  729. Once development has reached a suitable point in the second development
  730. environment, you need to export the changes as patches.
  731. To export them, place the changes in a recipe and
  732. automatically apply them to the kernel during patching.
  733. </para>
  734. </section>
  735. </section>
  736. <section id='bsp-creating'>
  737. <title>Creating a BSP Based on an Existing Similar BSP</title>
  738. <para>
  739. This section overviews the process of creating a BSP based on an
  740. existing similar BSP.
  741. The information is introductory in nature and does not provide step-by-step examples.
  742. For detailed information on how to create a new BSP, see
  743. the "<ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-yocto-bsp-script'>Creating a New BSP Layer Using the yocto-bsp Script</ulink>" section in the
  744. Yocto Project Board Support Package (BSP) Developer's Guide, or see the
  745. <ulink url='&YOCTO_WIKI_URL;/wiki/Transcript:_creating_one_generic_Atom_BSP_from_another'>Transcript:_creating_one_generic_Atom_BSP_from_another</ulink>
  746. wiki page.
  747. </para>
  748. <para>
  749. The basic steps you need to follow are:
  750. <orderedlist>
  751. <listitem><para><emphasis>Make sure you have set up a local Source Directory:</emphasis>
  752. You must create a local
  753. <ulink url='&YOCTO_DOCS_DEV_URL;#source-directory'>Source Directory</ulink>
  754. by either creating a Git repository (recommended) or
  755. extracting a Yocto Project release tarball.</para></listitem>
  756. <listitem><para><emphasis>Choose an existing BSP available with the Yocto Project:</emphasis>
  757. Try to map your board features as closely to the features of a BSP that is
  758. already supported and exists in the Yocto Project.
  759. Starting with something as close as possible to your board makes developing
  760. your BSP easier.
  761. You can find all the BSPs that are supported and ship with the Yocto Project
  762. on the Yocto Project's Download page at
  763. <ulink url='&YOCTO_HOME_URL;/download'></ulink>.</para></listitem>
  764. <listitem><para><emphasis>Be sure you have the Base BSP:</emphasis>
  765. You need to either have a local Git repository of the base BSP set up or
  766. have downloaded and extracted the files from a release BSP tarball.
  767. Either method gives you access to the BSP source files.</para></listitem>
  768. <listitem><para><emphasis>Make a copy of the existing BSP, thus isolating your new
  769. BSP work:</emphasis>
  770. Copying the existing BSP file structure gives you a new area in which to work.</para></listitem>
  771. <listitem><para><emphasis>Make configuration and recipe changes to your new BSP:</emphasis>
  772. Configuration changes involve the files in the BSP's <filename>conf</filename>
  773. directory.
  774. Changes include creating a machine-specific configuration file and editing the
  775. <filename>layer.conf</filename> file.
  776. The configuration changes identify the kernel you will be using.
  777. Recipe changes include removing, modifying, or adding new recipe files that
  778. instruct the build process on what features to include in the image.</para></listitem>
  779. <listitem><para><emphasis>Prepare for the build:</emphasis>
  780. Before you actually initiate the build, you need to set up the build environment
  781. by sourcing the environment initialization script.
  782. After setting up the environment, you need to make some build configuration
  783. changes to the <filename>local.conf</filename> and <filename>bblayers.conf</filename>
  784. files.</para></listitem>
  785. <listitem><para><emphasis>Build the image:</emphasis>
  786. The OpenEmbedded build system uses BitBake to create the image.
  787. You need to decide on the type of image you are going to build (e.g. minimal, base,
  788. core, sato, and so forth) and then start the build using the <filename>bitbake</filename>
  789. command.</para></listitem>
  790. </orderedlist>
  791. </para>
  792. </section>
  793. <section id='tip-dirty-string'>
  794. <title>"-dirty" String</title>
  795. <para>
  796. If kernel images are being built with "-dirty" on the end of the version
  797. string, this simply means that modifications in the source
  798. directory have not been committed.
  799. <literallayout class='monospaced'>
  800. $ git status
  801. </literallayout>
  802. </para>
  803. <para>
  804. You can use the above Git command to report modified, removed, or added files.
  805. You should commit those changes to the tree regardless of whether they will be saved,
  806. exported, or used.
  807. Once you commit the changes you need to rebuild the kernel.
  808. </para>
  809. <para>
  810. To brute force pickup and commit all such pending changes, enter the following:
  811. <literallayout class='monospaced'>
  812. $ git add .
  813. $ git commit -s -a -m "getting rid of -dirty"
  814. </literallayout>
  815. </para>
  816. <para>
  817. Next, rebuild the kernel.
  818. </para>
  819. </section>
  820. </section>
  821. </chapter>
  822. <!--
  823. vim: expandtab tw=80 ts=4
  824. -->