appendix-obtain.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. *****************
  3. Obtaining the SDK
  4. *****************
  5. Locating Pre-Built SDK Installers
  6. =================================
  7. You can use existing, pre-built toolchains by locating and running an
  8. SDK installer script that ships with the Yocto Project. Using this
  9. method, you select and download an architecture-specific SDK installer
  10. and then run the script to hand-install the toolchain.
  11. Follow these steps to locate and hand-install the toolchain:
  12. 1. *Go to the Installers Directory:* Go to
  13. :yocto_dl:`/releases/yocto/yocto-&DISTRO;/toolchain/`
  14. 2. *Open the Folder for Your Build Host:* Open the folder that matches
  15. your :term:`Build Host` (i.e.
  16. ``i686`` for 32-bit machines or ``x86_64`` for 64-bit machines).
  17. 3. *Locate and Download the SDK Installer:* You need to find and
  18. download the installer appropriate for your build host, target
  19. hardware, and image type.
  20. The installer files (``*.sh``) follow this naming convention:
  21. ``poky-glibc-host_system-core-image-type-arch-toolchain[-ext]-release.sh``:
  22. - ``host_system``: string representing your development system: ``i686`` or ``x86_64``
  23. - ``type``: string representing the image: ``sato`` or ``minimal``
  24. - ``arch``: string representing the target architecture such as ``cortexa57-qemuarm64``
  25. - ``release``: version of the Yocto Project.
  26. .. note::
  27. The standard SDK installer does not have the ``-ext`` string as
  28. part of the filename.
  29. The toolchains provided by the Yocto
  30. Project are based off of the ``core-image-sato`` and
  31. ``core-image-minimal`` images and contain libraries appropriate for
  32. developing against those images.
  33. For example, if your build host is a 64-bit x86 system and you need
  34. an extended SDK for a 64-bit core2 QEMU target, go into the ``x86_64``
  35. folder and download the following installer::
  36. poky-glibc-x86_64-core-image-sato-core2-64-qemux86-64-toolchain-&DISTRO;.sh
  37. #. *Run the Installer:* Be sure you have execution privileges and run
  38. the installer. Here is an example from the ``Downloads``
  39. directory::
  40. $ ~/Downloads/poky-glibc-x86_64-core-image-sato-core2-64-qemux86-64-toolchain-&DISTRO;.sh
  41. During execution of the script, you choose the root location for the
  42. toolchain. See the
  43. ":ref:`sdk-manual/appendix-obtain:installed standard sdk directory structure`"
  44. section and the
  45. ":ref:`sdk-manual/appendix-obtain:installed extensible sdk directory structure`"
  46. section for more information.
  47. Building an SDK Installer
  48. =========================
  49. As an alternative to locating and downloading an SDK installer, you can
  50. build the SDK installer. Follow these steps:
  51. 1. *Set Up the Build Environment:* Be sure you are set up to use BitBake
  52. in a shell. See the ":ref:`dev-manual/start:preparing the build host`" section
  53. in the Yocto Project Development Tasks Manual for information on how
  54. to get a build host ready that is either a native Linux machine or a
  55. machine that uses CROPS.
  56. 2. *Clone the ``poky`` Repository:* You need to have a local copy of the
  57. Yocto Project :term:`Source Directory`
  58. (i.e. a local
  59. ``poky`` repository). See the ":ref:`dev-manual/start:cloning the \`\`poky\`\` repository`" and
  60. possibly the ":ref:`dev-manual/start:checking out by branch in poky`" and
  61. ":ref:`dev-manual/start:checking out by tag in poky`" sections
  62. all in the Yocto Project Development Tasks Manual for information on
  63. how to clone the ``poky`` repository and check out the appropriate
  64. branch for your work.
  65. 3. *Initialize the Build Environment:* While in the root directory of
  66. the Source Directory (i.e. ``poky``), run the
  67. :ref:`structure-core-script` environment
  68. setup script to define the OpenEmbedded build environment on your
  69. build host.
  70. ::
  71. $ source oe-init-build-env
  72. Among other things, the script
  73. creates the :term:`Build Directory`,
  74. which is
  75. ``build`` in this case and is located in the Source Directory. After
  76. the script runs, your current working directory is set to the
  77. ``build`` directory.
  78. 4. *Make Sure You Are Building an Installer for the Correct Machine:*
  79. Check to be sure that your
  80. :term:`MACHINE` variable in the
  81. ``local.conf`` file in your Build Directory matches the architecture
  82. for which you are building.
  83. 5. *Make Sure Your SDK Machine is Correctly Set:* If you are building a
  84. toolchain designed to run on an architecture that differs from your
  85. current development host machine (i.e. the build host), be sure that
  86. the :term:`SDKMACHINE` variable
  87. in the ``local.conf`` file in your Build Directory is correctly set.
  88. .. note::
  89. If you are building an SDK installer for the Extensible SDK, the
  90. SDKMACHINE
  91. value must be set for the architecture of the machine you are
  92. using to build the installer. If
  93. SDKMACHINE
  94. is not set appropriately, the build fails and provides an error
  95. message similar to the following::
  96. The extensible SDK can currently only be built for the same architecture as the machine being built on - SDK_ARCH is
  97. set to i686 (likely via setting SDKMACHINE) which is different from the architecture of the build machine (x86_64).
  98. Unable to continue.
  99. 6. *Build the SDK Installer:* To build the SDK installer for a standard
  100. SDK and populate the SDK image, use the following command form. Be
  101. sure to replace ``image`` with an image (e.g. "core-image-sato")::
  102. $ bitbake image -c populate_sdk
  103. You can do the same for the extensible SDK using this command form::
  104. $ bitbake image -c populate_sdk_ext
  105. These commands produce an SDK installer that contains the sysroot
  106. that matches your target root filesystem.
  107. When the ``bitbake`` command completes, the SDK installer will be in
  108. ``tmp/deploy/sdk`` in the Build Directory.
  109. .. note::
  110. - By default, the previous BitBake command does not build static
  111. binaries. If you want to use the toolchain to build these types
  112. of libraries, you need to be sure your SDK has the appropriate
  113. static development libraries. Use the
  114. :term:`TOOLCHAIN_TARGET_TASK`
  115. variable inside your ``local.conf`` file before building the
  116. SDK installer. Doing so ensures that the eventual SDK
  117. installation process installs the appropriate library packages
  118. as part of the SDK. Here is an example using ``libc``
  119. static development libraries: TOOLCHAIN_TARGET_TASK:append = "
  120. libc-staticdev"
  121. #. *Run the Installer:* You can now run the SDK installer from
  122. ``tmp/deploy/sdk`` in the :term:`Build Directory`. Here is an example::
  123. $ cd poky/build/tmp/deploy/sdk
  124. $ ./poky-glibc-x86_64-core-image-sato-core2-64-toolchain-ext-&DISTRO;.sh
  125. During execution of the script, you choose the root location for the
  126. toolchain. See the
  127. ":ref:`sdk-manual/appendix-obtain:installed standard sdk directory structure`"
  128. section and the
  129. ":ref:`sdk-manual/appendix-obtain:installed extensible sdk directory structure`"
  130. section for more information.
  131. Extracting the Root Filesystem
  132. ==============================
  133. After installing the toolchain, for some use cases you might need to
  134. separately extract a root filesystem:
  135. - You want to boot the image using NFS.
  136. - You want to use the root filesystem as the target sysroot.
  137. - You want to develop your target application using the root filesystem
  138. as the target sysroot.
  139. Follow these steps to extract the root filesystem:
  140. 1. *Locate and Download the Tarball for the Pre-Built Root Filesystem
  141. Image File:* You need to find and download the root filesystem image
  142. file that is appropriate for your target system. These files are kept
  143. in machine-specific folders in the
  144. :yocto_dl:`Index of Releases </releases/yocto/yocto-&DISTRO;/machines/>`
  145. in the "machines" directory.
  146. The machine-specific folders of the "machines" directory contain
  147. tarballs (``*.tar.bz2``) for supported machines. These directories
  148. also contain flattened root filesystem image files (``*.ext4``),
  149. which you can use with QEMU directly.
  150. The pre-built root filesystem image files follow the
  151. ``core-image-profile-machine.tar.bz2`` naming convention:
  152. - ``profile``: filesystem image's profile, such as ``minimal``,
  153. ``minimal-dev`` or ``sato``. For information on these types of image
  154. profiles, see the "Images" chapter in the Yocto Project Reference Manual.
  155. - ``machine``: same string as the name of the parent download directory.
  156. The root filesystems
  157. provided by the Yocto Project are based off of the
  158. ``core-image-sato`` and ``core-image-minimal`` images.
  159. For example, if you plan on using a BeagleBone device as your target
  160. hardware and your image is a ``core-image-sato-sdk`` image, you can
  161. download the following file::
  162. core-image-sato-sdk-beaglebone-yocto.tar.bz2
  163. 2. *Initialize the Cross-Development Environment:* You must ``source``
  164. the cross-development environment setup script to establish necessary
  165. environment variables.
  166. This script is located in the top-level directory in which you
  167. installed the toolchain (e.g. ``poky_sdk``).
  168. Here is an example based on the toolchain installed in the
  169. ":ref:`sdk-manual/appendix-obtain:locating pre-built sdk installers`" section::
  170. $ source poky_sdk/environment-setup-core2-64-poky-linux
  171. 3. *Extract the Root Filesystem:* Use the ``runqemu-extract-sdk``
  172. command and provide the root filesystem image.
  173. Here is an example command that extracts the root filesystem
  174. from a previously built root filesystem image that was downloaded
  175. from the :yocto_dl:`Index of Releases </releases/yocto/yocto-&DISTRO;/machines/>`.
  176. This command extracts the root filesystem into the ``core2-64-sato``
  177. directory::
  178. $ runqemu-extract-sdk ~/Downloads/core-image-sato-sdk-beaglebone-yocto.tar.bz2 ~/beaglebone-sato
  179. You could now point to the target sysroot at ``beaglebone-sato``.
  180. Installed Standard SDK Directory Structure
  181. ==========================================
  182. The following figure shows the resulting directory structure after you
  183. install the Standard SDK by running the ``*.sh`` SDK installation
  184. script:
  185. .. image:: figures/sdk-installed-standard-sdk-directory.png
  186. :scale: 80%
  187. :align: center
  188. The installed SDK consists of an environment setup script for the SDK, a
  189. configuration file for the target, a version file for the target, and
  190. the root filesystem (``sysroots``) needed to develop objects for the
  191. target system.
  192. Within the figure, italicized text is used to indicate replaceable
  193. portions of the file or directory name. For example, install_dir/version
  194. is the directory where the SDK is installed. By default, this directory
  195. is ``/opt/poky/``. And, version represents the specific snapshot of the
  196. SDK (e.g. &DISTRO;). Furthermore, target represents the target architecture
  197. (e.g. ``i586``) and host represents the development system's
  198. architecture (e.g. ``x86_64``). Thus, the complete names of the two
  199. directories within the ``sysroots`` could be ``i586-poky-linux`` and
  200. ``x86_64-pokysdk-linux`` for the target and host, respectively.
  201. Installed Extensible SDK Directory Structure
  202. ============================================
  203. The following figure shows the resulting directory structure after you
  204. install the Extensible SDK by running the ``*.sh`` SDK installation
  205. script:
  206. .. image:: figures/sdk-installed-extensible-sdk-directory.png
  207. :scale: 80%
  208. :align: center
  209. The installed directory structure for the extensible SDK is quite
  210. different than the installed structure for the standard SDK. The
  211. extensible SDK does not separate host and target parts in the same
  212. manner as does the standard SDK. The extensible SDK uses an embedded
  213. copy of the OpenEmbedded build system, which has its own sysroots.
  214. Of note in the directory structure are an environment setup script for
  215. the SDK, a configuration file for the target, a version file for the
  216. target, and log files for the OpenEmbedded build system preparation
  217. script run by the installer and BitBake.
  218. Within the figure, italicized text is used to indicate replaceable
  219. portions of the file or directory name. For example, install_dir is the
  220. directory where the SDK is installed, which is ``poky_sdk`` by default,
  221. and target represents the target architecture (e.g. ``i586``).