extensible.rst 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. ************************
  3. Using the Extensible SDK
  4. ************************
  5. This chapter describes the extensible SDK and how to install it.
  6. Information covers the pieces of the SDK, how to install it, and
  7. presents a look at using the ``devtool`` functionality. The extensible
  8. SDK makes it easy to add new applications and libraries to an image,
  9. modify the source for an existing component, test changes on the target
  10. hardware, and ease integration into the rest of the
  11. :term:`OpenEmbedded Build System`.
  12. .. note::
  13. For a side-by-side comparison of main features supported for an
  14. extensible SDK as compared to a standard SDK, see the
  15. :ref:`sdk-manual/intro:introduction` section.
  16. In addition to the functionality available through ``devtool``, you can
  17. alternatively make use of the toolchain directly, for example from
  18. Makefile and Autotools. See the
  19. ":ref:`sdk-manual/working-projects:using the sdk toolchain directly`" chapter
  20. for more information.
  21. Why use the Extensible SDK and What is in It?
  22. =============================================
  23. The extensible SDK provides a cross-development toolchain and libraries
  24. tailored to the contents of a specific image. You would use the
  25. Extensible SDK if you want a toolchain experience supplemented with the
  26. powerful set of ``devtool`` commands tailored for the Yocto Project
  27. environment.
  28. The installed extensible SDK consists of several files and directories.
  29. Basically, it contains an SDK environment setup script, some
  30. configuration files, an internal build system, and the ``devtool``
  31. functionality.
  32. Installing the Extensible SDK
  33. =============================
  34. Two ways to install the Extensible SDK
  35. --------------------------------------
  36. Extensible SDK can be installed in two different ways, and both have
  37. their own pros and cons:
  38. #. *Setting up the Extensible SDK environment directly in a Yocto build*. This
  39. avoids having to produce, test, distribute and maintain separate SDK
  40. installer archives, which can get very large. There is only one environment
  41. for the regular Yocto build and the SDK and less code paths where things can
  42. go not according to plan. It's easier to update the SDK: it simply means
  43. updating the Yocto layers with git fetch or layer management tooling. The
  44. SDK extensibility is better than in the second option: just run ``bitbake``
  45. again to add more things to the sysroot, or add layers if even more things
  46. are required.
  47. #. *Setting up the Extensible SDK from a standalone installer*. This has the
  48. benefit of having a single, self-contained archive that includes all the
  49. needed binary artifacts. So nothing needs to be rebuilt, and there is no
  50. need to provide a well-functioning binary artefact cache over the network
  51. for developers with underpowered laptops.
  52. .. _setting_up_ext_sdk_in_build:
  53. Setting up the Extensible SDK environment directly in a Yocto build
  54. -------------------------------------------------------------------
  55. #. Set up all the needed layers and a Yocto :term:`Build Directory`, e.g. a regular Yocto
  56. build where ``bitbake`` can be executed.
  57. #. Run::
  58. $ bitbake meta-ide-support
  59. $ bitbake -c populate_sysroot gtk+3
  60. # or any other target or native item that the application developer would need
  61. $ bitbake build-sysroots -c build_native_sysroot && bitbake build-sysroots -c build_target_sysroot
  62. Setting up the Extensible SDK from a standalone installer
  63. ---------------------------------------------------------
  64. The first thing you need to do is install the SDK on your :term:`Build
  65. Host` by running the ``*.sh`` installation script.
  66. You can download a tarball installer, which includes the pre-built
  67. toolchain, the ``runqemu`` script, the internal build system,
  68. ``devtool``, and support files from the appropriate
  69. :yocto_dl:`toolchain </releases/yocto/yocto-&DISTRO;/toolchain/>` directory within the Index of
  70. Releases. Toolchains are available for several 32-bit and 64-bit
  71. architectures with the ``x86_64`` directories, respectively. The
  72. toolchains the Yocto Project provides are based off the
  73. ``core-image-sato`` and ``core-image-minimal`` images and contain
  74. libraries appropriate for developing against that image.
  75. The names of the tarball installer scripts are such that a string
  76. representing the host system appears first in the filename and then is
  77. immediately followed by a string representing the target architecture.
  78. An extensible SDK has the string "-ext" as part of the name. Following
  79. is the general form::
  80. poky-glibc-host_system-image_type-arch-toolchain-ext-release_version.sh
  81. Where:
  82. host_system is a string representing your development system:
  83. i686 or x86_64.
  84. image_type is the image for which the SDK was built:
  85. core-image-sato or core-image-minimal
  86. arch is a string representing the tuned target architecture:
  87. aarch64, armv5e, core2-64, i586, mips32r2, mips64, ppc7400, or cortexa8hf-neon
  88. release_version is a string representing the release number of the Yocto Project:
  89. &DISTRO;, &DISTRO;+snapshot
  90. For example, the following SDK installer is for a 64-bit
  91. development host system and a i586-tuned target architecture based off
  92. the SDK for ``core-image-sato`` and using the current &DISTRO; snapshot::
  93. poky-glibc-x86_64-core-image-sato-i586-toolchain-ext-&DISTRO;.sh
  94. .. note::
  95. As an alternative to downloading an SDK, you can build the SDK
  96. installer. For information on building the installer, see the
  97. :ref:`sdk-manual/appendix-obtain:building an sdk installer`
  98. section.
  99. The SDK and toolchains are self-contained and by default are installed
  100. into the ``poky_sdk`` folder in your home directory. You can choose to
  101. install the extensible SDK in any location when you run the installer.
  102. However, because files need to be written under that directory during
  103. the normal course of operation, the location you choose for installation
  104. must be writable for whichever users need to use the SDK.
  105. The following command shows how to run the installer given a toolchain
  106. tarball for a 64-bit x86 development host system and a 64-bit x86 target
  107. architecture. The example assumes the SDK installer is located in
  108. ``~/Downloads/`` and has execution rights::
  109. $ ./Downloads/poky-glibc-x86_64-core-image-minimal-core2-64-toolchain-ext-2.5.sh
  110. Poky (Yocto Project Reference Distro) Extensible SDK installer version 2.5
  111. ==========================================================================
  112. Enter target directory for SDK (default: poky_sdk):
  113. You are about to install the SDK to "/home/scottrif/poky_sdk". Proceed [Y/n]? Y
  114. Extracting SDK..............done
  115. Setting it up...
  116. Extracting buildtools...
  117. Preparing build system...
  118. Parsing recipes: 100% |##################################################################| Time: 0:00:52
  119. Initialising tasks: 100% |###############################################################| Time: 0:00:00
  120. Checking sstate mirror object availability: 100% |#######################################| Time: 0:00:00
  121. Loading cache: 100% |####################################################################| Time: 0:00:00
  122. Initialising tasks: 100% |###############################################################| Time: 0:00:00
  123. done
  124. SDK has been successfully set up and is ready to be used.
  125. Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
  126. $ . /home/scottrif/poky_sdk/environment-setup-core2-64-poky-linux
  127. .. note::
  128. If you do not have write permissions for the directory into which you
  129. are installing the SDK, the installer notifies you and exits. For
  130. that case, set up the proper permissions in the directory and run the
  131. installer again.
  132. .. _running_the_ext_sdk_env:
  133. Running the Extensible SDK Environment Setup Script
  134. ===================================================
  135. Once you have the SDK installed, you must run the SDK environment setup
  136. script before you can actually use the SDK.
  137. When using a SDK directly in a Yocto build, you will find the script in
  138. ``tmp/deploy/images/qemux86-64/`` in your :term:`Build Directory`.
  139. When using a standalone SDK installer, this setup script resides in
  140. the directory you chose when you installed the SDK, which is either the
  141. default ``poky_sdk`` directory or the directory you chose during
  142. installation.
  143. Before running the script, be sure it is the one that matches the
  144. architecture for which you are developing. Environment setup scripts
  145. begin with the string "``environment-setup``" and include as part of
  146. their name the tuned target architecture. As an example, the following
  147. commands set the working directory to where the SDK was installed and
  148. then source the environment setup script. In this example, the setup
  149. script is for an IA-based target machine using i586 tuning::
  150. $ cd /home/scottrif/poky_sdk
  151. $ source environment-setup-core2-64-poky-linux
  152. SDK environment now set up; additionally you may now run devtool to perform development tasks.
  153. Run devtool --help for further details.
  154. When using the environment script directly in a Yocto build, it can
  155. be run similarly::
  156. $ source tmp/deploy/images/qemux86-64/environment-setup-core2-64-poky-linux
  157. Running the setup script defines many environment variables needed in order to
  158. use the SDK (e.g. ``PATH``, :term:`CC`, :term:`LD`, and so forth). If you want
  159. to see all the environment variables the script exports, examine the
  160. installation file itself.
  161. .. _using_devtool:
  162. Using ``devtool`` in Your SDK Workflow
  163. ======================================
  164. The cornerstone of the extensible SDK is a command-line tool called
  165. ``devtool``. This tool provides a number of features that help you
  166. build, test and package software within the extensible SDK, and
  167. optionally integrate it into an image built by the OpenEmbedded build
  168. system.
  169. .. note::
  170. The use of ``devtool`` is not limited to the extensible SDK. You can use
  171. ``devtool`` to help you easily develop any project whose build output must be
  172. part of an image built using the build system.
  173. The ``devtool`` command line is organized similarly to
  174. :ref:`overview-manual/development-environment:git` in that it has a number of
  175. sub-commands for each function. You can run ``devtool --help`` to see
  176. all the commands.
  177. .. note::
  178. See the ":doc:`/ref-manual/devtool-reference`"
  179. section in the Yocto Project Reference Manual.
  180. ``devtool`` subcommands provide entry-points into development:
  181. - *devtool add*: Assists in adding new software to be built.
  182. - *devtool modify*: Sets up an environment to enable you to modify
  183. the source of an existing component.
  184. - *devtool ide-sdk*: Generates a configuration for an IDE.
  185. - *devtool upgrade*: Updates an existing recipe so that you can
  186. build it for an updated set of source files.
  187. As with the build system, "recipes" represent software packages within
  188. ``devtool``. When you use ``devtool add``, a recipe is automatically
  189. created. When you use ``devtool modify``, the specified existing recipe
  190. is used in order to determine where to get the source code and how to
  191. patch it. In both cases, an environment is set up so that when you build
  192. the recipe a source tree that is under your control is used in order to
  193. allow you to make changes to the source as desired. By default, new
  194. recipes and the source go into a "workspace" directory under the SDK.
  195. The remainder of this section presents the ``devtool add``,
  196. ``devtool modify``, and ``devtool upgrade`` workflows.
  197. Use ``devtool add`` to Add an Application
  198. -----------------------------------------
  199. The ``devtool add`` command generates a new recipe based on existing
  200. source code. This command takes advantage of the
  201. :ref:`devtool-the-workspace-layer-structure`
  202. layer that many ``devtool`` commands use. The command is flexible enough
  203. to allow you to extract source code into both the workspace or a
  204. separate local Git repository and to use existing code that does not
  205. need to be extracted.
  206. Depending on your particular scenario, the arguments and options you use
  207. with ``devtool add`` form different combinations. The following diagram
  208. shows common development flows you would use with the ``devtool add``
  209. command:
  210. .. image:: figures/sdk-devtool-add-flow.png
  211. :width: 100%
  212. #. *Generating the New Recipe*: The top part of the flow shows three
  213. scenarios by which you could use ``devtool add`` to generate a recipe
  214. based on existing source code.
  215. In a shared development environment, it is typical for other
  216. developers to be responsible for various areas of source code. As a
  217. developer, you are probably interested in using that source code as
  218. part of your development within the Yocto Project. All you need is
  219. access to the code, a recipe, and a controlled area in which to do
  220. your work.
  221. Within the diagram, three possible scenarios feed into the
  222. ``devtool add`` workflow:
  223. - *Left*: The left scenario in the figure represents a common
  224. situation where the source code does not exist locally and needs
  225. to be extracted. In this situation, the source code is extracted
  226. to the default workspace --- you do not want the files in some
  227. specific location outside of the workspace. Thus, everything you
  228. need will be located in the workspace::
  229. $ devtool add recipe fetchuri
  230. With this command, ``devtool`` extracts the upstream
  231. source files into a local Git repository within the ``sources``
  232. folder. The command then creates a recipe named recipe and a
  233. corresponding append file in the workspace. If you do not provide
  234. recipe, the command makes an attempt to determine the recipe name.
  235. - *Middle*: The middle scenario in the figure also represents a
  236. situation where the source code does not exist locally. In this
  237. case, the code is again upstream and needs to be extracted to some
  238. local area --- this time outside of the default workspace.
  239. .. note::
  240. If required, ``devtool`` always creates a Git repository locally
  241. during the extraction.
  242. Furthermore, the first positional argument ``srctree`` in this case
  243. identifies where the ``devtool add`` command will locate the
  244. extracted code outside of the workspace. You need to specify an
  245. empty directory::
  246. $ devtool add recipe srctree fetchuri
  247. In summary, the source code is pulled from fetchuri and extracted into the
  248. location defined by ``srctree`` as a local Git repository.
  249. Within workspace, ``devtool`` creates a recipe named recipe along
  250. with an associated append file.
  251. - *Right*: The right scenario in the figure represents a situation
  252. where the ``srctree`` has been previously prepared outside of the
  253. ``devtool`` workspace.
  254. The following command provides a new recipe name and identifies
  255. the existing source tree location::
  256. $ devtool add recipe srctree
  257. The command examines the source code and creates a recipe named
  258. recipe for the code and places the recipe into the workspace.
  259. Because the extracted source code already exists, ``devtool`` does
  260. not try to relocate the source code into the workspace --- only the
  261. new recipe is placed in the workspace.
  262. Aside from a recipe folder, the command also creates an associated
  263. append folder and places an initial ``*.bbappend`` file within.
  264. #. *Edit the Recipe*: You can use ``devtool edit-recipe`` to open up the
  265. editor as defined by the ``$EDITOR`` environment variable and modify
  266. the file::
  267. $ devtool edit-recipe recipe
  268. From within the editor, you can make modifications to the recipe that
  269. take effect when you build it later.
  270. #. *Build the Recipe or Rebuild the Image*: The next step you take
  271. depends on what you are going to do with the new code.
  272. If you need to eventually move the build output to the target
  273. hardware, use the following ``devtool`` command::
  274. $ devtool build recipe
  275. On the other hand, if you want an image to contain the recipe's
  276. packages from the workspace for immediate deployment onto a device
  277. (e.g. for testing purposes), you can use the ``devtool build-image``
  278. command::
  279. $ devtool build-image image
  280. #. *Deploy the Build Output*: When you use the ``devtool build`` command
  281. to build out your recipe, you probably want to see if the resulting
  282. build output works as expected on the target hardware.
  283. .. note::
  284. This step assumes you have a previously built image that is
  285. already either running in QEMU or is running on actual hardware.
  286. Also, it is assumed that for deployment of the image to the
  287. target, SSH is installed in the image and, if the image is running
  288. on real hardware, you have network access to and from your
  289. development machine.
  290. You can deploy your build output to that target hardware by using the
  291. ``devtool deploy-target`` command::
  292. $ devtool deploy-target recipe target
  293. The target is a live target machine running as an SSH server.
  294. You can, of course, also deploy the image you build to actual
  295. hardware by using the ``devtool build-image`` command. However,
  296. ``devtool`` does not provide a specific command that allows you to
  297. deploy the image to actual hardware.
  298. #. *Finish Your Work With the Recipe*: The ``devtool finish`` command
  299. creates any patches corresponding to commits in the local Git
  300. repository, moves the new recipe to a more permanent layer, and then
  301. resets the recipe so that the recipe is built normally rather than
  302. from the workspace::
  303. $ devtool finish recipe layer
  304. .. note::
  305. Any changes you want to turn into patches must be committed to the
  306. Git repository in the source tree.
  307. As mentioned, the ``devtool finish`` command moves the final recipe
  308. to its permanent layer.
  309. As a final process of the ``devtool finish`` command, the state of
  310. the standard layers and the upstream source is restored so that you
  311. can build the recipe from those areas rather than the workspace.
  312. .. note::
  313. You can use the ``devtool reset`` command to put things back should you
  314. decide you do not want to proceed with your work. If you do use this
  315. command, realize that the source tree is preserved.
  316. Use ``devtool modify`` to Modify the Source of an Existing Component
  317. --------------------------------------------------------------------
  318. The ``devtool modify`` command prepares the way to work on existing code
  319. that already has a local recipe in place that is used to build the
  320. software. The command is flexible enough to allow you to extract code
  321. from an upstream source, specify the existing recipe, and keep track of
  322. and gather any patch files from other developers that are associated
  323. with the code.
  324. Depending on your particular scenario, the arguments and options you use
  325. with ``devtool modify`` form different combinations. The following
  326. diagram shows common development flows for the ``devtool modify``
  327. command:
  328. .. image:: figures/sdk-devtool-modify-flow.png
  329. :width: 100%
  330. #. *Preparing to Modify the Code*: The top part of the flow shows three
  331. scenarios by which you could use ``devtool modify`` to prepare to
  332. work on source files. Each scenario assumes the following:
  333. - The recipe exists locally in a layer external to the ``devtool``
  334. workspace.
  335. - The source files exist either upstream in an un-extracted state or
  336. locally in a previously extracted state.
  337. The typical situation is where another developer has created a layer
  338. for use with the Yocto Project and their recipe already resides in
  339. that layer. Furthermore, their source code is readily available
  340. either upstream or locally.
  341. - *Left*: The left scenario in the figure represents a common
  342. situation where the source code does not exist locally and it
  343. needs to be extracted from an upstream source. In this situation,
  344. the source is extracted into the default ``devtool`` workspace
  345. location. The recipe, in this scenario, is in its own layer
  346. outside the workspace (i.e. ``meta-``\ layername).
  347. The following command identifies the recipe and, by default,
  348. extracts the source files::
  349. $ devtool modify recipe
  350. Once ``devtool`` locates the recipe, ``devtool`` uses the recipe's
  351. :term:`SRC_URI` statements to locate the source code and any local
  352. patch files from other developers.
  353. With this scenario, there is no ``srctree`` argument. Consequently, the
  354. default behavior of the ``devtool modify`` command is to extract
  355. the source files pointed to by the :term:`SRC_URI` statements into a
  356. local Git structure. Furthermore, the location for the extracted
  357. source is the default area within the ``devtool`` workspace. The
  358. result is that the command sets up both the source code and an
  359. append file within the workspace while the recipe remains in its
  360. original location.
  361. Additionally, if you have any non-patch local files (i.e. files
  362. referred to with ``file://`` entries in :term:`SRC_URI` statement
  363. excluding ``*.patch/`` or ``*.diff``), these files are copied to
  364. an ``oe-local-files`` folder under the newly created source tree.
  365. Copying the files here gives you a convenient area from which you
  366. can modify the files. Any changes or additions you make to those
  367. files are incorporated into the build the next time you build the
  368. software just as are other changes you might have made to the
  369. source.
  370. - *Middle*: The middle scenario in the figure represents a situation
  371. where the source code also does not exist locally. In this case,
  372. the code is again upstream and needs to be extracted to some local
  373. area as a Git repository. The recipe, in this scenario, is again
  374. local and in its own layer outside the workspace.
  375. The following command tells ``devtool`` the recipe with which to
  376. work and, in this case, identifies a local area for the extracted
  377. source files that exists outside of the default ``devtool``
  378. workspace::
  379. $ devtool modify recipe srctree
  380. .. note::
  381. You cannot provide a URL for ``srctree`` using the ``devtool`` command.
  382. As with all extractions, the command uses the recipe's :term:`SRC_URI`
  383. statements to locate the source files and any associated patch
  384. files. Non-patch files are copied to an ``oe-local-files`` folder
  385. under the newly created source tree.
  386. Once the files are located, the command by default extracts them
  387. into ``srctree``.
  388. Within workspace, ``devtool`` creates an append file for the
  389. recipe. The recipe remains in its original location but the source
  390. files are extracted to the location you provide with ``srctree``.
  391. - *Right*: The right scenario in the figure represents a situation
  392. where the source tree (``srctree``) already exists locally as a
  393. previously extracted Git structure outside of the ``devtool``
  394. workspace. In this example, the recipe also exists elsewhere
  395. locally in its own layer.
  396. The following command tells ``devtool`` the recipe with which to
  397. work, uses the "-n" option to indicate source does not need to be
  398. extracted, and uses ``srctree`` to point to the previously extracted
  399. source files::
  400. $ devtool modify -n recipe srctree
  401. If an ``oe-local-files`` subdirectory happens to exist and it
  402. contains non-patch files, the files are used. However, if the
  403. subdirectory does not exist and you run the ``devtool finish``
  404. command, any non-patch files that might exist next to the recipe
  405. are removed because it appears to ``devtool`` that you have
  406. deleted those files.
  407. Once the ``devtool modify`` command finishes, it creates only an
  408. append file for the recipe in the ``devtool`` workspace. The
  409. recipe and the source code remain in their original locations.
  410. #. *Edit the Source*: Once you have used the ``devtool modify`` command,
  411. you are free to make changes to the source files. You can use any
  412. editor you like to make and save your source code modifications.
  413. #. *Build the Recipe or Rebuild the Image*: The next step you take
  414. depends on what you are going to do with the new code.
  415. If you need to eventually move the build output to the target
  416. hardware, use the following ``devtool`` command::
  417. $ devtool build recipe
  418. On the other hand, if you want an image to contain the recipe's
  419. packages from the workspace for immediate deployment onto a device
  420. (e.g. for testing purposes), you can use the ``devtool build-image``
  421. command::
  422. $ devtool build-image image
  423. #. *Deploy the Build Output*: When you use the ``devtool build`` command
  424. to build out your recipe, you probably want to see if the resulting
  425. build output works as expected on target hardware.
  426. .. note::
  427. This step assumes you have a previously built image that is
  428. already either running in QEMU or running on actual hardware.
  429. Also, it is assumed that for deployment of the image to the
  430. target, SSH is installed in the image and if the image is running
  431. on real hardware that you have network access to and from your
  432. development machine.
  433. You can deploy your build output to that target hardware by using the
  434. ``devtool deploy-target`` command::
  435. $ devtool deploy-target recipe target
  436. The target is a live target machine running as an SSH server.
  437. You can, of course, use other methods to deploy the image you built
  438. using the ``devtool build-image`` command to actual hardware.
  439. ``devtool`` does not provide a specific command to deploy the image
  440. to actual hardware.
  441. #. *Finish Your Work With the Recipe*: The ``devtool finish`` command
  442. creates any patches corresponding to commits in the local Git
  443. repository, updates the recipe to point to them (or creates a
  444. ``.bbappend`` file to do so, depending on the specified destination
  445. layer), and then resets the recipe so that the recipe is built
  446. normally rather than from the workspace::
  447. $ devtool finish recipe layer
  448. .. note::
  449. Any changes you want to turn into patches must be staged and
  450. committed within the local Git repository before you use the
  451. ``devtool finish`` command.
  452. Because there is no need to move the recipe, ``devtool finish``
  453. either updates the original recipe in the original layer or the
  454. command creates a ``.bbappend`` file in a different layer as provided
  455. by layer. Any work you did in the ``oe-local-files`` directory is
  456. preserved in the original files next to the recipe during the
  457. ``devtool finish`` command.
  458. As a final process of the ``devtool finish`` command, the state of
  459. the standard layers and the upstream source is restored so that you
  460. can build the recipe from those areas rather than from the workspace.
  461. .. note::
  462. You can use the ``devtool reset`` command to put things back should you
  463. decide you do not want to proceed with your work. If you do use this
  464. command, realize that the source tree is preserved.
  465. ``devtool ide-sdk`` configures IDEs for the extensible SDK
  466. ----------------------------------------------------------
  467. ``devtool ide-sdk`` automatically configures IDEs to use the extensible SDK.
  468. To make sure that all parts of the extensible SDK required by the generated
  469. IDE configuration are available, ``devtool ide-sdk`` uses BitBake in the
  470. background to bootstrap the extensible SDK.
  471. The extensible SDK supports two different development modes.
  472. ``devtool ide-sdk`` supports both of them:
  473. #. *Modified mode*:
  474. By default ``devtool ide-sdk`` generates IDE configurations for recipes in
  475. workspaces created by ``devtool modify`` or ``devtool add`` as described in
  476. :ref:`using_devtool`. This mode creates IDE configurations with support for
  477. advanced features, such as deploying the binaries to the remote target
  478. device and performing remote debugging sessions. The generated IDE
  479. configurations use the per recipe sysroots as Bitbake does internally.
  480. In order to use the tool, a few settings are needed. As a starting example,
  481. the following lines of code can be added to the ``local.conf`` file::
  482. # Build the companion debug file system
  483. IMAGE_GEN_DEBUGFS = "1"
  484. # Optimize build time: with devtool ide-sdk the dbg tar is not needed
  485. IMAGE_FSTYPES_DEBUGFS = ""
  486. # Without copying the binaries into roofs-dbg, GDB does not find all source files.
  487. IMAGE_CLASSES += "image-combined-dbg"
  488. # SSH is mandatory, no password simplifies the usage
  489. EXTRA_IMAGE_FEATURES += "\
  490. ssh-server-openssh \
  491. allow-empty-password \
  492. allow-root-login \
  493. empty-root-password \
  494. post-install-logging \
  495. "
  496. # Remote debugging needs gdbserver on the target device
  497. IMAGE_INSTALL:append = " gdbserver"
  498. # Add the recipes which should be modified to the image
  499. # Otherwise some dependencies might be missing.
  500. IMAGE_INSTALL:append = " my-recipe"
  501. Assuming the BitBake environment is set up correctly and a workspace has
  502. been created for the recipe using ``devtool modify my-recipe``, the
  503. following command can create the SDK and the configuration for VSCode in
  504. the recipe workspace::
  505. $ devtool ide-sdk my-recipe core-image-minimal --target root@192.168.7.2
  506. The command requires an image recipe (``core-image-minimal`` for this example)
  507. that is used to create the SDK. This firmware image should also be installed
  508. on the target device. It is possible to pass multiple package recipes.
  509. ``devtool ide-sdk`` tries to create an IDE configuration for all package
  510. recipes.
  511. What this command does exactly depends on the recipe, more precisely on the
  512. build tool used by the recipe. The basic idea is to configure the IDE so
  513. that it calls the build tool exactly as ``bitbake`` does.
  514. For example, a CMake preset is created for a recipe that inherits
  515. :ref:`ref-classes-cmake`. In the case of VSCode, CMake presets are supported
  516. by the CMake Tools plugin. This is an example of how the build
  517. configuration used by ``bitbake`` is exported to an IDE configuration that
  518. gives exactly the same build results.
  519. Support for remote debugging with seamless integration into the IDE is
  520. important for a cross-SDK. ``devtool ide-sdk`` automatically generates the
  521. necessary helper scripts for deploying the compiled artifacts to the target
  522. device as well as the necessary configuration for the debugger and the IDE.
  523. .. note::
  524. To ensure that the debug symbols on the build machine match the binaries
  525. running on the target device, it is essential that the image built by
  526. ``devtool ide-sdk`` is running on the target device.
  527. ``devtool ide-sdk`` aims to support multiple programming languages and
  528. multiple IDEs natively. "Natively" means that the IDE is configured to call
  529. the build tool (e.g. CMake or Meson) directly. This has several advantages.
  530. First of all, it is much faster than ``devtool build``, but it also allows
  531. to use the very good integration of tools like CMake or GDB in VSCode and
  532. other IDEs. However, supporting many programming languages and multiple
  533. IDEs is quite an elaborate and constantly evolving thing. Support for IDEs
  534. is therefore implemented as plugins. Plugins can also be provided by
  535. optional layers.
  536. The default IDE is VSCode. Some hints about using VSCode:
  537. - To work on the source code of a recipe an instance of VSCode is started in
  538. the recipe's workspace. Example::
  539. code build/workspace/sources/my-recipe
  540. - To work with CMake press ``Ctrl + Shift + p``, type ``cmake``. This will
  541. show some possible commands like selecting a CMake preset, compiling or
  542. running CTest.
  543. For recipes inheriting :ref:`ref-classes-cmake-qemu` rather than
  544. :ref:`ref-classes-cmake`, executing cross-compiled unit tests on the host
  545. can be supported transparently with QEMU user-mode.
  546. - To work with Meson press ``Ctrl + Shift + p``, type ``meson``. This will
  547. show some possible commands like compiling or executing the unit tests.
  548. A note on running cross-compiled unit tests on the host: Meson enables
  549. support for QEMU user-mode by default. It is expected that the execution
  550. of the unit tests from the IDE will work easily without any additional
  551. steps, provided that the code is suitable for execution on the host
  552. machine.
  553. - For the deployment to the target device, just press ``Ctrl + Shift + p``,
  554. type ``task``. Select ``install && deploy-target``.
  555. - For remote debugging, switch to the debugging view by pressing the "play"
  556. button with the ``bug icon`` on the left side. This will provide a green
  557. play button with a drop-down list where a debug configuration can be
  558. selected. After selecting one of the generated configurations, press the
  559. "play" button.
  560. Starting a remote debugging session automatically initiates the deployment
  561. to the target device. If this is not desired, the
  562. ``"dependsOn": ["install && deploy-target...]`` parameter of the tasks
  563. with ``"label": "gdbserver start...`` can be removed from the
  564. ``tasks.json`` file.
  565. VSCode supports GDB with many different setups and configurations for many
  566. different use cases. However, most of these setups have some limitations
  567. when it comes to cross-development, support only a few target
  568. architectures or require a high performance target device. Therefore
  569. ``devtool ide-sdk`` supports the classic, generic setup with GDB on the
  570. development host and gdbserver on the target device.
  571. Roughly summarized, this means:
  572. - The binaries are copied via SSH to the remote target device by a script
  573. referred by ``tasks.json``.
  574. - gdbserver is started on the remote target device via SSH by a script
  575. referred by ``tasks.json``.
  576. Changing the parameters that are passed to the debugging executable
  577. requires modifying the generated script. The script is located at
  578. ``oe-scripts/gdbserver_*``. Defining the parameters in the ``args``
  579. field in the ``launch.json`` file does not work.
  580. - VSCode connects to gdbserver as documented in
  581. `Remote debugging or debugging with a local debugger server
  582. <https://code.visualstudio.com/docs/cpp/launch-json-reference#_remote-debugging-or-debugging-with-a-local-debugger-server>`__.
  583. Additionally ``--ide=none`` is supported. With the ``none`` IDE parameter,
  584. some generic configuration files like ``gdbinit`` files and some helper
  585. scripts starting gdbserver remotely on the target device as well as the GDB
  586. client on the host are generated.
  587. Here is a usage example for the ``cmake-example`` recipe from the
  588. ``meta-selftest`` layer which inherits :ref:`ref-classes-cmake-qemu`:
  589. .. code-block:: sh
  590. # Create the SDK
  591. devtool modify cmake-example
  592. devtool ide-sdk cmake-example core-image-minimal -c --debug-build-config --ide=none
  593. # Install the firmware on a target device or start QEMU
  594. runqemu
  595. # From exploring the workspace of cmake-example
  596. cd build/workspace/sources/cmake-example
  597. # Find cmake-native and save the path into a variable
  598. # Note: using just cmake instead of $CMAKE_NATIVE would work in many cases
  599. CMAKE_NATIVE="$(jq -r '.configurePresets[0] | "\(.cmakeExecutable)"' CMakeUserPresets.json)"
  600. # List available CMake presets
  601. "$CMAKE_NATIVE" --list-presets
  602. Available configure presets:
  603. "cmake-example-cortexa57" - cmake-example: cortexa57
  604. # Re-compile the already compiled sources
  605. "$CMAKE_NATIVE" --build --preset cmake-example-cortexa57
  606. ninja: no work to do.
  607. # Do a clean re-build
  608. "$CMAKE_NATIVE" --build --preset cmake-example-cortexa57 --target clean
  609. [1/1] Cleaning all built files...
  610. Cleaning... 8 files.
  611. "$CMAKE_NATIVE" --build --preset cmake-example-cortexa57 --target all
  612. [7/7] Linking CXX executable cmake-example
  613. # Run the cross-compiled unit tests with QEMU user-mode
  614. "$CMAKE_NATIVE" --build --preset cmake-example-cortexa57 --target test
  615. [0/1] Running tests...
  616. Test project .../build/tmp/work/cortexa57-poky-linux/cmake-example/1.0/cmake-example-1.0
  617. Start 1: test-cmake-example
  618. 1/1 Test #1: test-cmake-example ............... Passed 0.03 sec
  619. 100% tests passed, 0 tests failed out of 1
  620. Total Test time (real) = 0.03 sec
  621. # Using CTest directly is possible as well
  622. CTEST_NATIVE="$(dirname "$CMAKE_NATIVE")/ctest"
  623. # List available CMake presets
  624. "$CTEST_NATIVE" --list-presets
  625. Available test presets:
  626. "cmake-example-cortexa57" - cmake-example: cortexa57
  627. # Run the cross-compiled unit tests with QEMU user-mode
  628. "$CTEST_NATIVE" --preset "cmake-example-cortexa57"
  629. Test project ...build/tmp/work/cortexa57-poky-linux/cmake-example/1.0/cmake-example-1.0
  630. Start 1: test-cmake-example
  631. 1/1 Test #1: test-cmake-example ............... Passed 0.03 sec
  632. 100% tests passed, 0 tests failed out of 1
  633. Total Test time (real) = 0.03 sec
  634. # Deploying the new build to the target device (default is QEUM at 192.168.7.2)
  635. oe-scripts/install_and_deploy_cmake-example-cortexa57
  636. # Start a remote debugging session with gdbserver on the target and GDB on the host
  637. oe-scripts/gdbserver_1234_usr-bin-cmake-example_m
  638. oe-scripts/gdb_1234_usr-bin-cmake-example
  639. break main
  640. run
  641. step
  642. stepi
  643. continue
  644. quit
  645. # Stop gdbserver on the target device
  646. oe-scripts/gdbserver_1234_usr-bin-cmake-example_m stop
  647. #. *Shared sysroots mode*
  648. For some recipes and use cases a per-recipe sysroot based SDK is not
  649. suitable. Optionally ``devtool ide-sdk`` configures the IDE to use the
  650. toolchain provided by the extensible SDK as described in
  651. :ref:`running_the_ext_sdk_env`. ``devtool ide-sdk --mode=shared`` is
  652. basically a wrapper for the setup of the extensible SDK as described in
  653. :ref:`setting_up_ext_sdk_in_build`. The IDE gets a configuration to use the
  654. shared sysroots.
  655. Creating a SDK with shared sysroots that contains all the dependencies needed
  656. to work with ``my-recipe`` is possible with the following example command::
  657. $ devtool ide-sdk --mode=shared my-recipe
  658. For VSCode the cross-toolchain is exposed as a CMake kit. CMake kits are
  659. defined in ``~/.local/share/CMakeTools/cmake-tools-kits.json``.
  660. The following example shows how the cross-toolchain can be selected in
  661. VSCode. First of all we need a folder containing a CMake project.
  662. For this example, let's create a CMake project and start VSCode::
  663. mkdir kit-test
  664. echo "project(foo VERSION 1.0)" > kit-test/CMakeLists.txt
  665. code kit-test
  666. If there is a CMake project in the workspace, cross-compilation is supported:
  667. - Press ``Ctrl + Shift + P``, type ``CMake: Scan for Kits``
  668. - Press ``Ctrl + Shift + P``, type ``CMake: Select a Kit``
  669. Finally most of the features provided by CMake and the IDE should be available.
  670. Other IDEs than VSCode are supported as well. However,
  671. ``devtool ide-sdk --mode=shared --ide=none my-recipe`` is currently
  672. just a simple wrapper for the setup of the extensible SDK, as described in
  673. :ref:`setting_up_ext_sdk_in_build`.
  674. Use ``devtool upgrade`` to Create a Version of the Recipe that Supports a Newer Version of the Software
  675. -------------------------------------------------------------------------------------------------------
  676. The ``devtool upgrade`` command upgrades an existing recipe to that of a
  677. more up-to-date version found upstream. Throughout the life of software,
  678. recipes continually undergo version upgrades by their upstream
  679. publishers. You can use the ``devtool upgrade`` workflow to make sure
  680. your recipes you are using for builds are up-to-date with their upstream
  681. counterparts.
  682. .. note::
  683. Several methods exist by which you can upgrade recipes ---
  684. ``devtool upgrade`` happens to be one. You can read about all the methods by
  685. which you can upgrade recipes in the
  686. :ref:`dev-manual/upgrading-recipes:upgrading recipes` section of the Yocto
  687. Project Development Tasks Manual.
  688. The ``devtool upgrade`` command is flexible enough to allow you to specify
  689. source code revision and versioning schemes, extract code into or out of the
  690. ``devtool`` :ref:`devtool-the-workspace-layer-structure`, and work with any
  691. source file forms that the
  692. :ref:`bitbake-user-manual/bitbake-user-manual-fetching:fetchers` support.
  693. The following diagram shows the common development flow used with the
  694. ``devtool upgrade`` command:
  695. .. image:: figures/sdk-devtool-upgrade-flow.png
  696. :width: 100%
  697. #. *Initiate the Upgrade*: The top part of the flow shows the typical
  698. scenario by which you use the ``devtool upgrade`` command. The
  699. following conditions exist:
  700. - The recipe exists in a local layer external to the ``devtool``
  701. workspace.
  702. - The source files for the new release exist in the same location
  703. pointed to by :term:`SRC_URI`
  704. in the recipe (e.g. a tarball with the new version number in the
  705. name, or as a different revision in the upstream Git repository).
  706. A common situation is where third-party software has undergone a
  707. revision so that it has been upgraded. The recipe you have access to
  708. is likely in your own layer. Thus, you need to upgrade the recipe to
  709. use the newer version of the software::
  710. $ devtool upgrade -V version recipe
  711. By default, the ``devtool upgrade`` command extracts source
  712. code into the ``sources`` directory in the
  713. :ref:`devtool-the-workspace-layer-structure`.
  714. If you want the code extracted to any other location, you need to
  715. provide the ``srctree`` positional argument with the command as follows::
  716. $ devtool upgrade -V version recipe srctree
  717. .. note::
  718. In this example, the "-V" option specifies the new version. If you
  719. don't use "-V", the command upgrades the recipe to the latest
  720. version.
  721. If the source files pointed to by the :term:`SRC_URI` statement in the
  722. recipe are in a Git repository, you must provide the "-S" option and
  723. specify a revision for the software.
  724. Once ``devtool`` locates the recipe, it uses the :term:`SRC_URI` variable
  725. to locate the source code and any local patch files from other
  726. developers. The result is that the command sets up the source code,
  727. the new version of the recipe, and an append file all within the
  728. workspace.
  729. Additionally, if you have any non-patch local files (i.e. files
  730. referred to with ``file://`` entries in :term:`SRC_URI` statement
  731. excluding ``*.patch/`` or ``*.diff``), these files are copied to an
  732. ``oe-local-files`` folder under the newly created source tree.
  733. Copying the files here gives you a convenient area from which you can
  734. modify the files. Any changes or additions you make to those files
  735. are incorporated into the build the next time you build the software
  736. just as are other changes you might have made to the source.
  737. #. *Resolve any Conflicts created by the Upgrade*: Conflicts could happen
  738. after upgrading the software to a new version. Conflicts occur
  739. if your recipe specifies some patch files in :term:`SRC_URI` that
  740. conflict with changes made in the new version of the software. For
  741. such cases, you need to resolve the conflicts by editing the source
  742. and following the normal ``git rebase`` conflict resolution process.
  743. Before moving onto the next step, be sure to resolve any such
  744. conflicts created through use of a newer or different version of the
  745. software.
  746. #. *Build the Recipe or Rebuild the Image*: The next step you take
  747. depends on what you are going to do with the new code.
  748. If you need to eventually move the build output to the target
  749. hardware, use the following ``devtool`` command::
  750. $ devtool build recipe
  751. On the other hand, if you want an image to contain the recipe's
  752. packages from the workspace for immediate deployment onto a device
  753. (e.g. for testing purposes), you can use the ``devtool build-image``
  754. command::
  755. $ devtool build-image image
  756. #. *Deploy the Build Output*: When you use the ``devtool build`` command
  757. or ``bitbake`` to build your recipe, you probably want to see if the
  758. resulting build output works as expected on target hardware.
  759. .. note::
  760. This step assumes you have a previously built image that is
  761. already either running in QEMU or running on actual hardware.
  762. Also, it is assumed that for deployment of the image to the
  763. target, SSH is installed in the image and if the image is running
  764. on real hardware that you have network access to and from your
  765. development machine.
  766. You can deploy your build output to that target hardware by using the
  767. ``devtool deploy-target`` command::
  768. $ devtool deploy-target recipe target
  769. The target is a live target machine running as an SSH server.
  770. You can, of course, also deploy the image you build using the
  771. ``devtool build-image`` command to actual hardware. However,
  772. ``devtool`` does not provide a specific command that allows you to do
  773. this.
  774. #. *Finish Your Work With the Recipe*: The ``devtool finish`` command
  775. creates any patches corresponding to commits in the local Git
  776. repository, moves the new recipe to a more permanent layer, and then
  777. resets the recipe so that the recipe is built normally rather than
  778. from the workspace.
  779. Any work you did in the ``oe-local-files`` directory is preserved in
  780. the original files next to the recipe during the ``devtool finish``
  781. command.
  782. If you specify a destination layer that is the same as the original
  783. source, then the old version of the recipe and associated files are
  784. removed prior to adding the new version::
  785. $ devtool finish recipe layer
  786. .. note::
  787. Any changes you want to turn into patches must be committed to the
  788. Git repository in the source tree.
  789. As a final process of the ``devtool finish`` command, the state of
  790. the standard layers and the upstream source is restored so that you
  791. can build the recipe from those areas rather than the workspace.
  792. .. note::
  793. You can use the ``devtool reset`` command to put things back should you
  794. decide you do not want to proceed with your work. If you do use this
  795. command, realize that the source tree is preserved.
  796. A Closer Look at ``devtool add``
  797. ================================
  798. The ``devtool add`` command automatically creates a recipe based on the
  799. source tree you provide with the command. Currently, the command has
  800. support for the following:
  801. - Autotools (``autoconf`` and ``automake``)
  802. - CMake
  803. - Scons
  804. - ``qmake``
  805. - Plain ``Makefile``
  806. - Out-of-tree kernel module
  807. - Binary package (i.e. "-b" option)
  808. - Node.js module
  809. - Python modules that use ``setuptools`` or ``distutils``
  810. Apart from binary packages, the determination of how a source tree
  811. should be treated is automatic based on the files present within that
  812. source tree. For example, if a ``CMakeLists.txt`` file is found, then
  813. the source tree is assumed to be using CMake and is treated accordingly.
  814. .. note::
  815. In most cases, you need to edit the automatically generated recipe in
  816. order to make it build properly. Typically, you would go through
  817. several edit and build cycles until the recipe successfully builds.
  818. Once the recipe builds, you could use possible further iterations to
  819. test the recipe on the target device.
  820. The remainder of this section covers specifics regarding how parts of
  821. the recipe are generated.
  822. Name and Version
  823. ----------------
  824. If you do not specify a name and version on the command line,
  825. ``devtool add`` uses various metadata within the source tree in an
  826. attempt to determine the name and version of the software being built.
  827. Based on what the tool determines, ``devtool`` sets the name of the
  828. created recipe file accordingly.
  829. If ``devtool`` cannot determine the name and version, the command prints
  830. an error. For such cases, you must re-run the command and provide the
  831. name and version, just the name, or just the version as part of the
  832. command line.
  833. Sometimes the name or version determined from the source tree might be
  834. incorrect. For such a case, you must reset the recipe::
  835. $ devtool reset -n recipename
  836. After running the ``devtool reset`` command, you need to
  837. run ``devtool add`` again and provide the name or the version.
  838. Dependency Detection and Mapping
  839. --------------------------------
  840. The ``devtool add`` command attempts to detect build-time dependencies and map
  841. them to other recipes in the system. During this mapping, the command fills in
  842. the names of those recipes as part of the :term:`DEPENDS` variable within the
  843. recipe. If a dependency cannot be mapped, ``devtool`` places a comment
  844. in the recipe indicating such. The inability to map a dependency can
  845. result from naming not being recognized or because the dependency simply
  846. is not available. For cases where the dependency is not available, you
  847. must use the ``devtool add`` command to add an additional recipe that
  848. satisfies the dependency. Once you add that recipe, you need to update
  849. the :term:`DEPENDS` variable in the original recipe to include the new
  850. recipe.
  851. If you need to add runtime dependencies, you can do so by adding the
  852. following to your recipe::
  853. RDEPENDS:${PN} += "dependency1 dependency2 ..."
  854. .. note::
  855. The ``devtool add`` command often cannot distinguish between mandatory and
  856. optional dependencies. Consequently, some of the detected dependencies might
  857. in fact be optional. When in doubt, consult the documentation or the
  858. configure script for the software the recipe is building for further
  859. details. In some cases, you might find you can substitute the
  860. dependency with an option that disables the associated functionality
  861. passed to the configure script.
  862. License Detection
  863. -----------------
  864. The ``devtool add`` command attempts to determine if the software you are
  865. adding is able to be distributed under a common, open-source license. If
  866. so, the command sets the :term:`LICENSE` value accordingly.
  867. You should double-check the value added by the command against the
  868. documentation or source files for the software you are building and, if
  869. necessary, update that :term:`LICENSE` value.
  870. The ``devtool add`` command also sets the :term:`LIC_FILES_CHKSUM`
  871. value to point to all files that appear to be license-related. Realize
  872. that license statements often appear in comments at the top of source
  873. files or within the documentation. In such cases, the command does not
  874. recognize those license statements. Consequently, you might need to
  875. amend the :term:`LIC_FILES_CHKSUM` variable to point to one or more of those
  876. comments if present. Setting :term:`LIC_FILES_CHKSUM` is particularly
  877. important for third-party software. The mechanism attempts to ensure
  878. correct licensing should you upgrade the recipe to a newer upstream
  879. version in future. Any change in licensing is detected and you receive
  880. an error prompting you to check the license text again.
  881. If the ``devtool add`` command cannot determine licensing information,
  882. ``devtool`` sets the :term:`LICENSE` value to "CLOSED" and leaves the
  883. :term:`LIC_FILES_CHKSUM` value unset. This behavior allows you to continue
  884. with development even though the settings are unlikely to be correct in
  885. all cases. You should check the documentation or source files for the
  886. software you are building to determine the actual license.
  887. Adding Makefile-Only Software
  888. -----------------------------
  889. The use of Make by itself is very common in both proprietary and
  890. open-source software. Unfortunately, Makefiles are often not written
  891. with cross-compilation in mind. Thus, ``devtool add`` often cannot do
  892. very much to ensure that these Makefiles build correctly. It is very
  893. common, for example, to explicitly call ``gcc`` instead of using the
  894. :term:`CC` variable. Usually, in a
  895. cross-compilation environment, ``gcc`` is the compiler for the build
  896. host and the cross-compiler is named something similar to
  897. ``arm-poky-linux-gnueabi-gcc`` and might require arguments (e.g. to
  898. point to the associated sysroot for the target machine).
  899. When writing a recipe for Makefile-only software, keep the following in
  900. mind:
  901. - You probably need to patch the Makefile to use variables instead of
  902. hardcoding tools within the toolchain such as ``gcc`` and ``g++``.
  903. - The environment in which Make runs is set up with various standard
  904. variables for compilation (e.g. :term:`CC`, :term:`CXX`, and so forth) in a
  905. similar manner to the environment set up by the SDK's environment
  906. setup script. One easy way to see these variables is to run the
  907. ``devtool build`` command on the recipe and then look in
  908. ``oe-logs/run.do_compile``. Towards the top of this file, there is
  909. a list of environment variables that are set. You can take
  910. advantage of these variables within the Makefile.
  911. - If the Makefile sets a default for a variable using "=", that default
  912. overrides the value set in the environment, which is usually not
  913. desirable. For this case, you can either patch the Makefile so it
  914. sets the default using the "?=" operator, or you can alternatively
  915. force the value on the ``make`` command line. To force the value on
  916. the command line, add the variable setting to
  917. :term:`EXTRA_OEMAKE` or
  918. :term:`PACKAGECONFIG_CONFARGS`
  919. within the recipe. Here is an example using :term:`EXTRA_OEMAKE`::
  920. EXTRA_OEMAKE += "'CC=${CC}' 'CXX=${CXX}'"
  921. In the above example,
  922. single quotes are used around the variable settings as the values are
  923. likely to contain spaces because required default options are passed
  924. to the compiler.
  925. - Hardcoding paths inside Makefiles is often problematic in a
  926. cross-compilation environment. This is particularly true because
  927. those hardcoded paths often point to locations on the build host and
  928. thus will either be read-only or will introduce contamination into
  929. the cross-compilation because they are specific to the build host
  930. rather than the target. Patching the Makefile to use prefix variables
  931. or other path variables is usually the way to handle this situation.
  932. - Sometimes a Makefile runs target-specific commands such as
  933. ``ldconfig``. For such cases, you might be able to apply patches that
  934. remove these commands from the Makefile.
  935. Adding Native Tools
  936. -------------------
  937. Often, you need to build additional tools that run on the :term:`Build Host`
  938. as opposed to the target. You should indicate this requirement by using one of
  939. the following methods when you run ``devtool add``:
  940. - Specify the name of the recipe such that it ends with "-native".
  941. Specifying the name like this produces a recipe that only builds for
  942. the build host.
  943. - Specify the "--also-native" option with the ``devtool add``
  944. command. Specifying this option creates a recipe file that still
  945. builds for the target but also creates a variant with a "-native"
  946. suffix that builds for the build host.
  947. .. note::
  948. If you need to add a tool that is shipped as part of a source tree
  949. that builds code for the target, you can typically accomplish this by
  950. building the native and target parts separately rather than within
  951. the same compilation process. Realize though that with the
  952. "--also-native" option, you can add the tool using just one
  953. recipe file.
  954. Adding Node.js Modules
  955. ----------------------
  956. You can use the ``devtool add`` command two different ways to add
  957. Node.js modules: through ``npm`` or from a repository or local source.
  958. Use the following form to add Node.js modules through ``npm``::
  959. $ devtool add "npm://registry.npmjs.org;name=forever;version=0.15.1"
  960. The name and
  961. version parameters are mandatory. Lockdown and shrinkwrap files are
  962. generated and pointed to by the recipe in order to freeze the version
  963. that is fetched for the dependencies according to the first time. This
  964. also saves checksums that are verified on future fetches. Together,
  965. these behaviors ensure the reproducibility and integrity of the build.
  966. .. note::
  967. - You must use quotes around the URL. ``devtool add`` does not
  968. require the quotes, but the shell considers ";" as a splitter
  969. between multiple commands. Thus, without the quotes,
  970. ``devtool add`` does not receive the other parts, which results in
  971. several "command not found" errors.
  972. - In order to support adding Node.js modules, a ``nodejs`` recipe
  973. must be part of your SDK.
  974. As mentioned earlier, you can also add Node.js modules directly from a
  975. repository or local source tree. To add modules this way, use
  976. ``devtool add`` in the following form::
  977. $ devtool add https://github.com/diversario/node-ssdp
  978. In this example, ``devtool`` fetches the specified Git repository, detects the
  979. code as Node.js code, fetches dependencies using ``npm``, and sets
  980. :term:`SRC_URI` accordingly.
  981. Working With Recipes
  982. ====================
  983. When building a recipe using the ``devtool build`` command, the typical
  984. build progresses as follows:
  985. #. Fetch the source
  986. #. Unpack the source
  987. #. Configure the source
  988. #. Compile the source
  989. #. Install the build output
  990. #. Package the installed output
  991. For recipes in the workspace, fetching and unpacking is disabled as the
  992. source tree has already been prepared and is persistent. Each of these
  993. build steps is defined as a function (task), usually with a "do\_" prefix
  994. (e.g. :ref:`ref-tasks-fetch`,
  995. :ref:`ref-tasks-unpack`, and so
  996. forth). These functions are typically shell scripts but can instead be
  997. written in Python.
  998. If you look at the contents of a recipe, you will see that the recipe
  999. does not include complete instructions for building the software.
  1000. Instead, common functionality is encapsulated in classes inherited with
  1001. the ``inherit`` directive. This technique leaves the recipe to describe
  1002. just the things that are specific to the software being built. There is
  1003. a :ref:`ref-classes-base` class that is implicitly inherited by all recipes
  1004. and provides the functionality that most recipes typically need.
  1005. The remainder of this section presents information useful when working
  1006. with recipes.
  1007. Finding Logs and Work Files
  1008. ---------------------------
  1009. After the first run of the ``devtool build`` command, recipes that were
  1010. previously created using the ``devtool add`` command or whose sources
  1011. were modified using the ``devtool modify`` command contain symbolic
  1012. links created within the source tree:
  1013. - ``oe-logs``: This link points to the directory in which log files and
  1014. run scripts for each build step are created.
  1015. - ``oe-workdir``: This link points to the temporary work area for the
  1016. recipe. The following locations under ``oe-workdir`` are particularly
  1017. useful:
  1018. - ``image/``: Contains all of the files installed during the
  1019. :ref:`ref-tasks-install` stage.
  1020. Within a recipe, this directory is referred to by the expression
  1021. ``${``\ :term:`D`\ ``}``.
  1022. - ``sysroot-destdir/``: Contains a subset of files installed within
  1023. :ref:`ref-tasks-install` that have been put into the shared sysroot. For
  1024. more information, see the
  1025. ":ref:`dev-manual/new-recipe:sharing files between recipes`" section.
  1026. - ``packages-split/``: Contains subdirectories for each package
  1027. produced by the recipe. For more information, see the
  1028. ":ref:`sdk-manual/extensible:packaging`" section.
  1029. You can use these links to get more information on what is happening at
  1030. each build step.
  1031. Setting Configure Arguments
  1032. ---------------------------
  1033. If the software your recipe is building uses GNU autoconf, then a fixed
  1034. set of arguments is passed to it to enable cross-compilation plus any
  1035. extras specified by :term:`EXTRA_OECONF` or :term:`PACKAGECONFIG_CONFARGS`
  1036. set within the recipe. If you wish to pass additional options, add them
  1037. to :term:`EXTRA_OECONF` or :term:`PACKAGECONFIG_CONFARGS`. Other supported build
  1038. tools have similar variables (e.g. :term:`EXTRA_OECMAKE` for CMake,
  1039. :term:`EXTRA_OESCONS` for Scons, and so forth). If you need to pass anything on
  1040. the ``make`` command line, you can use :term:`EXTRA_OEMAKE` or the
  1041. :term:`PACKAGECONFIG_CONFARGS` variables to do so.
  1042. You can use the ``devtool configure-help`` command to help you set the
  1043. arguments listed in the previous paragraph. The command determines the
  1044. exact options being passed, and shows them to you along with any custom
  1045. arguments specified through :term:`EXTRA_OECONF` or
  1046. :term:`PACKAGECONFIG_CONFARGS`. If applicable, the command also shows you
  1047. the output of the configure script's "--help" option as a
  1048. reference.
  1049. Sharing Files Between Recipes
  1050. -----------------------------
  1051. Recipes often need to use files provided by other recipes on the
  1052. :term:`Build Host`. For example,
  1053. an application linking to a common library needs access to the library
  1054. itself and its associated headers. The way this access is accomplished
  1055. within the extensible SDK is through the sysroot. There is one sysroot per
  1056. "machine" for which the SDK is being built. In practical terms, this
  1057. means there is a sysroot for the target machine, and a sysroot for
  1058. the build host.
  1059. Recipes should never write files directly into the sysroot. Instead,
  1060. files should be installed into standard locations during the
  1061. :ref:`ref-tasks-install` task within the ``${``\ :term:`D`\ ``}`` directory. A
  1062. subset of these files automatically goes into the sysroot. The reason
  1063. for this limitation is that almost all files that go into the sysroot
  1064. are cataloged in manifests in order to ensure they can be removed later
  1065. when a recipe is modified or removed. Thus, the sysroot is able to
  1066. remain free from stale files.
  1067. Packaging
  1068. ---------
  1069. Packaging is not always particularly relevant within the extensible SDK.
  1070. However, if you examine how build output gets into the final image on
  1071. the target device, it is important to understand packaging because the
  1072. contents of the image are expressed in terms of packages and not
  1073. recipes.
  1074. During the :ref:`ref-tasks-package` task, files installed during the
  1075. :ref:`ref-tasks-install` task are split into one main package, which is almost
  1076. always named the same as the recipe, and into several other packages. This
  1077. separation exists because not all of those installed files are useful in every
  1078. image. For example, you probably do not need any of the documentation installed
  1079. in a production image. Consequently, for each recipe the documentation
  1080. files are separated into a ``-doc`` package. Recipes that package
  1081. software containing optional modules or plugins might undergo additional
  1082. package splitting as well.
  1083. After building a recipe, you can see where files have gone by looking in
  1084. the ``oe-workdir/packages-split`` directory, which contains a
  1085. subdirectory for each package. Apart from some advanced cases, the
  1086. :term:`PACKAGES` and :term:`FILES` variables controls
  1087. splitting. The :term:`PACKAGES` variable lists all of the packages to be
  1088. produced, while the :term:`FILES` variable specifies which files to include
  1089. in each package by using an override to specify the package. For
  1090. example, ``FILES:${PN}`` specifies the files to go into the main package
  1091. (i.e. the main package has the same name as the recipe and
  1092. ``${``\ :term:`PN`\ ``}`` evaluates to the
  1093. recipe name). The order of the :term:`PACKAGES` value is significant. For
  1094. each installed file, the first package whose :term:`FILES` value matches the
  1095. file is the package into which the file goes. Both the :term:`PACKAGES` and
  1096. :term:`FILES` variables have default values. Consequently, you might find
  1097. you do not even need to set these variables in your recipe unless the
  1098. software the recipe is building installs files into non-standard
  1099. locations.
  1100. Restoring the Target Device to its Original State
  1101. =================================================
  1102. If you use the ``devtool deploy-target`` command to write a recipe's
  1103. build output to the target, and you are working on an existing component
  1104. of the system, then you might find yourself in a situation where you
  1105. need to restore the original files that existed prior to running the
  1106. ``devtool deploy-target`` command. Because the ``devtool deploy-target``
  1107. command backs up any files it overwrites, you can use the
  1108. ``devtool undeploy-target`` command to restore those files and remove
  1109. any other files the recipe deployed. Consider the following example::
  1110. $ devtool undeploy-target lighttpd root@192.168.7.2
  1111. If you have deployed
  1112. multiple applications, you can remove them all using the "-a" option
  1113. thus restoring the target device to its original state::
  1114. $ devtool undeploy-target -a root@192.168.7.2
  1115. Information about files deployed to
  1116. the target as well as any backed up files are stored on the target
  1117. itself. This storage, of course, requires some additional space on the
  1118. target machine.
  1119. .. note::
  1120. The ``devtool deploy-target`` and ``devtool undeploy-target`` commands do
  1121. not currently interact with any package management system on the target
  1122. device (e.g. RPM or OPKG). Consequently, you should not intermingle
  1123. ``devtool deploy-target`` and package manager operations on the target
  1124. device. Doing so could result in a conflicting set of files.
  1125. Installing Additional Items Into the Extensible SDK
  1126. ===================================================
  1127. Out of the box the extensible SDK typically only comes with a small
  1128. number of tools and libraries. A minimal SDK starts mostly empty and is
  1129. populated on-demand. Sometimes you must explicitly install extra items
  1130. into the SDK. If you need these extra items, you can first search for
  1131. the items using the ``devtool search`` command. For example, suppose you
  1132. need to link to libGL but you are not sure which recipe provides libGL.
  1133. You can use the following command to find out::
  1134. $ devtool search libGL mesa
  1135. A free implementation of the OpenGL API
  1136. Once you know the recipe
  1137. (i.e. ``mesa`` in this example), you can install it.
  1138. When using the extensible SDK directly in a Yocto build
  1139. -------------------------------------------------------
  1140. In this scenario, the Yocto build tooling, e.g. ``bitbake``
  1141. is directly accessible to build additional items, and it
  1142. can simply be executed directly::
  1143. $ bitbake curl-native
  1144. # Add newly built native items to native sysroot
  1145. $ bitbake build-sysroots -c build_native_sysroot
  1146. $ bitbake mesa
  1147. # Add newly built target items to target sysroot
  1148. $ bitbake build-sysroots -c build_target_sysroot
  1149. When using a standalone installer for the Extensible SDK
  1150. --------------------------------------------------------
  1151. ::
  1152. $ devtool sdk-install mesa
  1153. By default, the ``devtool sdk-install`` command assumes
  1154. the item is available in pre-built form from your SDK provider. If the
  1155. item is not available and it is acceptable to build the item from
  1156. source, you can add the "-s" option as follows::
  1157. $ devtool sdk-install -s mesa
  1158. It is important to remember that building the item from source
  1159. takes significantly longer than installing the pre-built artifact. Also,
  1160. if there is no recipe for the item you want to add to the SDK, you must
  1161. instead add the item using the ``devtool add`` command.
  1162. Applying Updates to an Installed Extensible SDK
  1163. ===============================================
  1164. If you are working with an installed extensible SDK that gets
  1165. occasionally updated (e.g. a third-party SDK), then you will need to
  1166. manually "pull down" the updates into the installed SDK.
  1167. To update your installed SDK, use ``devtool`` as follows::
  1168. $ devtool sdk-update
  1169. The previous command assumes your SDK provider has set the default update URL
  1170. for you through the :term:`SDK_UPDATE_URL` variable as described in the
  1171. ":ref:`sdk-manual/appendix-customizing:Providing Updates to the Extensible SDK After Installation`"
  1172. section. If the SDK provider has not set that default URL, you need to
  1173. specify it yourself in the command as follows::
  1174. $ devtool sdk-update path_to_update_directory
  1175. .. note::
  1176. The URL needs to point specifically to a published SDK and not to an
  1177. SDK installer that you would download and install.
  1178. Creating a Derivative SDK With Additional Components
  1179. ====================================================
  1180. You might need to produce an SDK that contains your own custom
  1181. libraries. A good example would be if you were a vendor with customers
  1182. that use your SDK to build their own platform-specific software and
  1183. those customers need an SDK that has custom libraries. In such a case,
  1184. you can produce a derivative SDK based on the currently installed SDK
  1185. fairly easily by following these steps:
  1186. #. If necessary, install an extensible SDK that you want to use as a
  1187. base for your derivative SDK.
  1188. #. Source the environment script for the SDK.
  1189. #. Add the extra libraries or other components you want by using the
  1190. ``devtool add`` command.
  1191. #. Run the ``devtool build-sdk`` command.
  1192. The previous steps take the recipes added to the workspace and construct
  1193. a new SDK installer that contains those recipes and the resulting binary
  1194. artifacts. The recipes go into their own separate layer in the
  1195. constructed derivative SDK, which leaves the workspace clean and ready
  1196. for users to add their own recipes.