index.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. =========================
  3. Yocto Project Quick Build
  4. =========================
  5. Welcome!
  6. ========
  7. This short document steps you through the process for a typical
  8. image build using the Yocto Project. The document also introduces how to
  9. configure a build for specific hardware. You will use Yocto Project to
  10. build a reference embedded OS called Poky.
  11. .. note::
  12. - The examples in this paper assume you are using a native Linux
  13. system running a recent Ubuntu Linux distribution. If the machine
  14. you want to use Yocto Project on to build an image
  15. (:term:`Build Host`) is not
  16. a native Linux system, you can still perform these steps by using
  17. CROss PlatformS (CROPS) and setting up a Poky container. See the
  18. :ref:`dev-manual/start:setting up to use cross platforms (crops)`
  19. section
  20. in the Yocto Project Development Tasks Manual for more
  21. information.
  22. - You may use version 2 of Windows Subsystem For Linux (WSL 2) to set
  23. up a build host using Windows 10 or later, Windows Server 2019 or later.
  24. See the :ref:`dev-manual/start:setting up to use windows subsystem for
  25. linux (wsl 2)` section in the Yocto Project Development Tasks Manual
  26. for more information.
  27. If you want more conceptual or background information on the Yocto
  28. Project, see the :doc:`/overview-manual/index`.
  29. Compatible Linux Distribution
  30. =============================
  31. Make sure your :term:`Build Host` meets the
  32. following requirements:
  33. - At least &MIN_DISK_SPACE; Gbytes of free disk space, though
  34. much more will help to run multiple builds and increase
  35. performance by reusing build artifacts.
  36. - At least &MIN_RAM; Gbytes of RAM, though a modern build host with as
  37. much RAM and as many CPU cores as possible is strongly recommended to
  38. maximize build performance.
  39. - Runs a supported Linux distribution (i.e. recent releases of Fedora,
  40. openSUSE, CentOS, Debian, or Ubuntu). For a list of Linux
  41. distributions that support the Yocto Project, see the
  42. :ref:`ref-manual/system-requirements:supported linux distributions`
  43. section in the Yocto Project Reference Manual. For detailed
  44. information on preparing your build host, see the
  45. :ref:`dev-manual/start:preparing the build host`
  46. section in the Yocto Project Development Tasks Manual.
  47. -
  48. - Git &MIN_GIT_VERSION; or greater
  49. - tar &MIN_TAR_VERSION; or greater
  50. - Python &MIN_PYTHON_VERSION; or greater.
  51. - gcc &MIN_GCC_VERSION; or greater.
  52. - GNU make &MIN_MAKE_VERSION; or greater
  53. If your build host does not meet any of these three listed version
  54. requirements, you can take steps to prepare the system so that you
  55. can still use the Yocto Project. See the
  56. :ref:`ref-manual/system-requirements:required git, tar, python, make and gcc versions`
  57. section in the Yocto Project Reference Manual for information.
  58. Build Host Packages
  59. ===================
  60. You must install essential host packages on your build host. The
  61. following command installs the host packages based on an Ubuntu
  62. distribution:
  63. .. literalinclude:: ../tools/host_packages_scripts/ubuntu_essential.sh
  64. :language: shell
  65. .. note::
  66. For host package requirements on all supported Linux distributions,
  67. see the :ref:`ref-manual/system-requirements:required packages for the build host`
  68. section in the Yocto Project Reference Manual.
  69. Use Git to Clone Poky
  70. =====================
  71. Once you complete the setup instructions for your machine, you need to
  72. get a copy of the Poky repository on your build host. Use the following
  73. commands to clone the Poky repository.
  74. .. code-block:: shell
  75. $ git clone git://git.yoctoproject.org/poky
  76. Cloning into 'poky'...
  77. remote: Counting
  78. objects: 432160, done. remote: Compressing objects: 100%
  79. (102056/102056), done. remote: Total 432160 (delta 323116), reused
  80. 432037 (delta 323000) Receiving objects: 100% (432160/432160), 153.81 MiB | 8.54 MiB/s, done.
  81. Resolving deltas: 100% (323116/323116), done.
  82. Checking connectivity... done.
  83. Go to :yocto_wiki:`Releases wiki page </Releases>`, and choose a release
  84. codename (such as ``&DISTRO_NAME_NO_CAP;``), corresponding to either the
  85. latest stable release or a Long Term Support release.
  86. Then move to the ``poky`` directory and take a look at existing branches:
  87. .. code-block:: shell
  88. $ cd poky
  89. $ git branch -a
  90. .
  91. .
  92. .
  93. remotes/origin/HEAD -> origin/master
  94. remotes/origin/dunfell
  95. remotes/origin/dunfell-next
  96. .
  97. .
  98. .
  99. remotes/origin/gatesgarth
  100. remotes/origin/gatesgarth-next
  101. .
  102. .
  103. .
  104. remotes/origin/master
  105. remotes/origin/master-next
  106. .
  107. .
  108. .
  109. For this example, check out the ``&DISTRO_NAME_NO_CAP;`` branch based on the
  110. ``&DISTRO_NAME;`` release:
  111. .. code-block:: shell
  112. $ git checkout -t origin/&DISTRO_NAME_NO_CAP; -b my-&DISTRO_NAME_NO_CAP;
  113. Branch 'my-&DISTRO_NAME_NO_CAP;' set up to track remote branch '&DISTRO_NAME_NO_CAP;' from 'origin'.
  114. Switched to a new branch 'my-&DISTRO_NAME_NO_CAP;'
  115. The previous Git checkout command creates a local branch named
  116. ``my-&DISTRO_NAME_NO_CAP;``. The files available to you in that branch
  117. exactly match the repository's files in the ``&DISTRO_NAME_NO_CAP;``
  118. release branch.
  119. Note that you can regularly type the following command in the same directory
  120. to keep your local files in sync with the release branch:
  121. .. code-block:: shell
  122. $ git pull
  123. For more options and information about accessing Yocto Project related
  124. repositories, see the
  125. :ref:`dev-manual/start:locating yocto project source files`
  126. section in the Yocto Project Development Tasks Manual.
  127. Building Your Image
  128. ===================
  129. Use the following steps to build your image. The build process creates
  130. an entire Linux distribution, including the toolchain, from source.
  131. .. note::
  132. - If you are working behind a firewall and your build host is not
  133. set up for proxies, you could encounter problems with the build
  134. process when fetching source code (e.g. fetcher failures or Git
  135. failures).
  136. - If you do not know your proxy settings, consult your local network
  137. infrastructure resources and get that information. A good starting
  138. point could also be to check your web browser settings. Finally,
  139. you can find more information on the
  140. ":yocto_wiki:`Working Behind a Network Proxy </Working_Behind_a_Network_Proxy>`"
  141. page of the Yocto Project Wiki.
  142. #. **Initialize the Build Environment:** From within the ``poky``
  143. directory, run the :ref:`ref-manual/structure:``oe-init-build-env```
  144. environment
  145. setup script to define Yocto Project's build environment on your
  146. build host.
  147. .. code-block:: shell
  148. $ cd poky
  149. $ source oe-init-build-env
  150. You had no conf/local.conf file. This configuration file has therefore been
  151. created for you with some default values. You may wish to edit it to, for
  152. example, select a different MACHINE (target hardware). See conf/local.conf
  153. for more information as common configuration options are commented.
  154. You had no conf/bblayers.conf file. This configuration file has therefore
  155. been created for you with some default values. To add additional metadata
  156. layers into your configuration please add entries to conf/bblayers.conf.
  157. The Yocto Project has extensive documentation about OE including a reference
  158. manual which can be found at:
  159. https://docs.yoctoproject.org
  160. For more information about OpenEmbedded see their website:
  161. https://www.openembedded.org/
  162. ### Shell environment set up for builds. ###
  163. You can now run 'bitbake <target>'
  164. Common targets are:
  165. core-image-minimal
  166. core-image-full-cmdline
  167. core-image-sato
  168. core-image-weston
  169. meta-toolchain
  170. meta-ide-support
  171. You can also run generated QEMU images with a command like 'runqemu qemux86-64'
  172. Other commonly useful commands are:
  173. - 'devtool' and 'recipetool' handle common recipe tasks
  174. - 'bitbake-layers' handles common layer tasks
  175. - 'oe-pkgdata-util' handles common target package tasks
  176. Among other things, the script creates the :term:`Build Directory`, which is
  177. ``build`` in this case and is located in the :term:`Source Directory`. After
  178. the script runs, your current working directory is set to the
  179. :term:`Build Directory`. Later, when the build completes, the
  180. :term:`Build Directory` contains all the files created during the build.
  181. #. **Examine Your Local Configuration File:** When you set up the build
  182. environment, a local configuration file named ``local.conf`` becomes
  183. available in a ``conf`` subdirectory of the :term:`Build Directory`. For this
  184. example, the defaults are set to build for a ``qemux86`` target,
  185. which is suitable for emulation. The package manager used is set to
  186. the RPM package manager.
  187. .. tip::
  188. You can significantly speed up your build and guard against fetcher
  189. failures by using :ref:`overview-manual/concepts:shared state cache`
  190. mirrors and enabling :ref:`overview-manual/concepts:hash equivalence`.
  191. This way, you can use pre-built artifacts rather than building them.
  192. This is relevant only when your network and the server that you use
  193. can download these artifacts faster than you would be able to build them.
  194. To use such mirrors, uncomment the below lines in your ``conf/local.conf``
  195. file in the :term:`Build Directory`::
  196. BB_HASHSERVE_UPSTREAM = "wss://hashserv.yoctoproject.org/ws"
  197. SSTATE_MIRRORS ?= "file://.* http://cdn.jsdelivr.net/yocto/sstate/all/PATH;downloadfilename=PATH"
  198. BB_HASHSERVE = "auto"
  199. BB_SIGNATURE_HANDLER = "OEEquivHash"
  200. The hash equivalence server needs the websockets python module version 9.1
  201. or later. Debian GNU/Linux 12 (Bookworm) and later, Fedora, CentOS Stream
  202. 9 and later, and Ubuntu 22.04 (LTS) and later, all have a recent enough
  203. package. Other supported distributions need to get the module some other
  204. place than their package feed, e.g. via ``pip``.
  205. #. **Start the Build:** Continue with the following command to build an OS
  206. image for the target, which is ``core-image-sato`` in this example:
  207. .. code-block:: shell
  208. $ bitbake core-image-sato
  209. For information on using the ``bitbake`` command, see the
  210. :ref:`overview-manual/concepts:bitbake` section in the Yocto Project Overview and
  211. Concepts Manual, or see
  212. :ref:`bitbake-user-manual/bitbake-user-manual-intro:the bitbake command`
  213. in the BitBake User Manual.
  214. #. **Simulate Your Image Using QEMU:** Once this particular image is
  215. built, you can start QEMU, which is a Quick EMUlator that ships with
  216. the Yocto Project:
  217. .. code-block:: shell
  218. $ runqemu qemux86-64
  219. If you want to learn more about running QEMU, see the
  220. :ref:`dev-manual/qemu:using the quick emulator (qemu)` chapter in
  221. the Yocto Project Development Tasks Manual.
  222. #. **Exit QEMU:** Exit QEMU by either clicking on the shutdown icon or by typing
  223. ``Ctrl-C`` in the QEMU transcript window from which you evoked QEMU.
  224. Customizing Your Build for Specific Hardware
  225. ============================================
  226. So far, all you have done is quickly built an image suitable for
  227. emulation only. This section shows you how to customize your build for
  228. specific hardware by adding a hardware layer into the Yocto Project
  229. development environment.
  230. In general, layers are repositories that contain related sets of
  231. instructions and configurations that tell the Yocto Project what to do.
  232. Isolating related metadata into functionally specific layers facilitates
  233. modular development and makes it easier to reuse the layer metadata.
  234. .. note::
  235. By convention, layer names start with the string "meta-".
  236. Follow these steps to add a hardware layer:
  237. #. **Find a Layer:** Many hardware layers are available. The Yocto Project
  238. :yocto_git:`Source Repositories <>` has many hardware layers.
  239. This example adds the
  240. `meta-altera <https://github.com/kraj/meta-altera>`__ hardware layer.
  241. #. **Clone the Layer:** Use Git to make a local copy of the layer on your
  242. machine. You can put the copy in the top level of the copy of the
  243. Poky repository created earlier:
  244. .. code-block:: shell
  245. $ cd poky
  246. $ git clone https://github.com/kraj/meta-altera.git
  247. Cloning into 'meta-altera'...
  248. remote: Counting objects: 25170, done.
  249. remote: Compressing objects: 100% (350/350), done.
  250. remote: Total 25170 (delta 645), reused 719 (delta 538), pack-reused 24219
  251. Receiving objects: 100% (25170/25170), 41.02 MiB | 1.64 MiB/s, done.
  252. Resolving deltas: 100% (13385/13385), done.
  253. Checking connectivity... done.
  254. The hardware layer is now available
  255. next to other layers inside the Poky reference repository on your build
  256. host as ``meta-altera`` and contains all the metadata needed to
  257. support hardware from Altera, which is owned by Intel.
  258. .. note::
  259. It is recommended for layers to have a branch per Yocto Project release.
  260. Please make sure to checkout the layer branch supporting the Yocto Project
  261. release you're using.
  262. #. **Change the Configuration to Build for a Specific Machine:** The
  263. :term:`MACHINE` variable in the
  264. ``local.conf`` file specifies the machine for the build. For this
  265. example, set the :term:`MACHINE` variable to ``cyclone5``. These
  266. configurations are used:
  267. https://github.com/kraj/meta-altera/blob/master/conf/machine/cyclone5.conf.
  268. .. note::
  269. See the "Examine Your Local Configuration File" step earlier for more
  270. information on configuring the build.
  271. #. **Add Your Layer to the Layer Configuration File:** Before you can use
  272. a layer during a build, you must add it to your ``bblayers.conf``
  273. file, which is found in the :term:`Build Directory` ``conf`` directory.
  274. Use the ``bitbake-layers add-layer`` command to add the layer to the
  275. configuration file:
  276. .. code-block:: shell
  277. $ cd poky/build
  278. $ bitbake-layers add-layer ../meta-altera
  279. NOTE: Starting bitbake server...
  280. Parsing recipes: 100% |##################################################################| Time: 0:00:32
  281. Parsing of 918 .bb files complete (0 cached, 918 parsed). 1401 targets,
  282. 123 skipped, 0 masked, 0 errors.
  283. You can find
  284. more information on adding layers in the
  285. :ref:`dev-manual/layers:adding a layer using the \`\`bitbake-layers\`\` script`
  286. section.
  287. Completing these steps has added the ``meta-altera`` layer to your Yocto
  288. Project development environment and configured it to build for the
  289. ``cyclone5`` machine.
  290. .. note::
  291. The previous steps are for demonstration purposes only. If you were
  292. to attempt to build an image for the ``cyclone5`` machine, you should
  293. read the Altera ``README``.
  294. Creating Your Own General Layer
  295. ===============================
  296. Maybe you have an application or specific set of behaviors you need to
  297. isolate. You can create your own general layer using the
  298. ``bitbake-layers create-layer`` command. The tool automates layer
  299. creation by setting up a subdirectory with a ``layer.conf``
  300. configuration file, a ``recipes-example`` subdirectory that contains an
  301. ``example.bb`` recipe, a licensing file, and a ``README``.
  302. The following commands run the tool to create a layer named
  303. ``meta-mylayer`` in the ``poky`` directory:
  304. .. code-block:: shell
  305. $ cd poky
  306. $ bitbake-layers create-layer meta-mylayer
  307. NOTE: Starting bitbake server...
  308. Add your new layer with 'bitbake-layers add-layer meta-mylayer'
  309. For more information
  310. on layers and how to create them, see the
  311. :ref:`dev-manual/layers:creating a general layer using the \`\`bitbake-layers\`\` script`
  312. section in the Yocto Project Development Tasks Manual.
  313. Where To Go Next
  314. ================
  315. Now that you have experienced using the Yocto Project, you might be
  316. asking yourself "What now?". The Yocto Project has many sources of
  317. information including the website, wiki pages, and user manuals:
  318. - **Website:** The :yocto_home:`Yocto Project Website <>` provides
  319. background information, the latest builds, breaking news, full
  320. development documentation, and access to a rich Yocto Project
  321. Development Community into which you can tap.
  322. - **Video Seminar:** The `Introduction to the Yocto Project and BitBake, Part 1
  323. <https://youtu.be/yuE7my3KOpo>`__ and
  324. `Introduction to the Yocto Project and BitBake, Part 2
  325. <https://youtu.be/iZ05TTyzGHk>`__ videos offer a video seminar
  326. introducing you to the most important aspects of developing a
  327. custom embedded Linux distribution with the Yocto Project.
  328. - **Yocto Project Overview and Concepts Manual:** The
  329. :doc:`/overview-manual/index` is a great
  330. place to start to learn about the Yocto Project. This manual
  331. introduces you to the Yocto Project and its development environment.
  332. The manual also provides conceptual information for various aspects
  333. of the Yocto Project.
  334. - **Yocto Project Wiki:** The :yocto_wiki:`Yocto Project Wiki <>`
  335. provides additional information on where to go next when ramping up
  336. with the Yocto Project, release information, project planning, and QA
  337. information.
  338. - **Yocto Project Mailing Lists:** Related mailing lists provide a forum
  339. for discussion, patch submission and announcements. There are several
  340. mailing lists grouped by topic. See the
  341. :ref:`ref-manual/resources:mailing lists`
  342. section in the Yocto Project Reference Manual for a complete list of
  343. Yocto Project mailing lists.
  344. - **Comprehensive List of Links and Other Documentation:** The
  345. :ref:`ref-manual/resources:links and related documentation`
  346. section in the Yocto Project Reference Manual provides a
  347. comprehensive list of all related links and other user documentation.
  348. .. include:: /boilerplate.rst