blob: 7b8baf233ad7346c946a513ec67535e0a3494114 [file] [log] [blame]
Andrew Geisslerf0343792020-11-18 10:42:21 -06001.. SPDX-License-Identifier: CC-BY-SA-2.0-UK
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002
3=========================
4Yocto Project Quick Build
5=========================
6
7Welcome!
8========
9
10This short document steps you through the process for a typical
11image build using the Yocto Project. The document also introduces how to
12configure a build for specific hardware. You will use Yocto Project to
13build a reference embedded OS called Poky.
14
15.. note::
16
17 - The examples in this paper assume you are using a native Linux
18 system running a recent Ubuntu Linux distribution. If the machine
19 you want to use Yocto Project on to build an image
20 (:term:`Build Host`) is not
21 a native Linux system, you can still perform these steps by using
22 CROss PlatformS (CROPS) and setting up a Poky container. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -060023 :ref:`dev-manual/start:setting up to use cross platforms (crops)`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050024 section
25 in the Yocto Project Development Tasks Manual for more
26 information.
27
Patrick Williams2390b1b2022-11-03 13:47:49 -050028 - You may use version 2 of Windows Subsystem For Linux (WSL 2) to set
29 up a build host using Windows 10 or later, Windows Server 2019 or later.
30 See the :ref:`dev-manual/start:setting up to use windows subsystem for
31 linux (wsl 2)` section in the Yocto Project Development Tasks Manual
32 for more information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050033
34If you want more conceptual or background information on the Yocto
Andrew Geissler09209ee2020-12-13 08:44:15 -060035Project, see the :doc:`/overview-manual/index`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050036
37Compatible Linux Distribution
38=============================
39
40Make sure your :term:`Build Host` meets the
41following requirements:
42
43- 50 Gbytes of free disk space
44
45- Runs a supported Linux distribution (i.e. recent releases of Fedora,
46 openSUSE, CentOS, Debian, or Ubuntu). For a list of Linux
47 distributions that support the Yocto Project, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -060048 :ref:`ref-manual/system-requirements:supported linux distributions`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050049 section in the Yocto Project Reference Manual. For detailed
50 information on preparing your build host, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -060051 :ref:`dev-manual/start:preparing the build host`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050052 section in the Yocto Project Development Tasks Manual.
53
54-
55
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050056 - Git &MIN_GIT_VERSION; or greater
57 - tar &MIN_TAR_VERSION; or greater
58 - Python &MIN_PYTHON_VERSION; or greater.
59 - gcc &MIN_GCC_VERSION; or greater.
Andrew Geissler615f2f12022-07-15 14:00:58 -050060 - GNU make &MIN_MAKE_VERSION; or greater
Andrew Geisslerc9f78652020-09-18 14:11:35 -050061
62If your build host does not meet any of these three listed version
63requirements, you can take steps to prepare the system so that you
64can still use the Yocto Project. See the
Andrew Geissler615f2f12022-07-15 14:00:58 -050065:ref:`ref-manual/system-requirements:required git, tar, python, make and gcc versions`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050066section in the Yocto Project Reference Manual for information.
67
68Build Host Packages
69===================
70
71You must install essential host packages on your build host. The
72following command installs the host packages based on an Ubuntu
Andrew Geisslerfc113ea2023-03-31 09:59:46 -050073distribution::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050074
Andrew Geisslerfc113ea2023-03-31 09:59:46 -050075 $ sudo apt install &UBUNTU_HOST_PACKAGES_ESSENTIAL;
Andrew Geisslerc9f78652020-09-18 14:11:35 -050076
77.. note::
78
79 For host package requirements on all supported Linux distributions,
Andrew Geissler09209ee2020-12-13 08:44:15 -060080 see the :ref:`ref-manual/system-requirements:required packages for the build host`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050081 section in the Yocto Project Reference Manual.
82
83Use Git to Clone Poky
84=====================
85
86Once you complete the setup instructions for your machine, you need to
87get a copy of the Poky repository on your build host. Use the following
88commands to clone the Poky repository.
89
90.. code-block:: shell
91
92 $ git clone git://git.yoctoproject.org/poky
93 Cloning into 'poky'...
94 remote: Counting
95 objects: 432160, done. remote: Compressing objects: 100%
96 (102056/102056), done. remote: Total 432160 (delta 323116), reused
97 432037 (delta 323000) Receiving objects: 100% (432160/432160), 153.81 MiB | 8.54 MiB/s, done.
98 Resolving deltas: 100% (323116/323116), done.
99 Checking connectivity... done.
100
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500101Go to :yocto_wiki:`Releases wiki page </Releases>`, and choose a release
102codename (such as ``&DISTRO_NAME_NO_CAP;``), corresponding to either the
103latest stable release or a Long Term Support release.
104
105Then move to the ``poky`` directory and take a look at existing branches:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500106
107.. code-block:: shell
108
109 $ cd poky
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500110 $ git branch -a
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500111 .
112 .
113 .
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500114 remotes/origin/HEAD -> origin/master
115 remotes/origin/dunfell
116 remotes/origin/dunfell-next
117 .
118 .
119 .
120 remotes/origin/gatesgarth
121 remotes/origin/gatesgarth-next
122 .
123 .
124 .
125 remotes/origin/master
126 remotes/origin/master-next
127 .
128 .
129 .
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500130
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500131
132For this example, check out the ``&DISTRO_NAME_NO_CAP;`` branch based on the
133``&DISTRO_NAME;`` release:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500134
135.. code-block:: shell
136
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500137 $ git checkout -t origin/&DISTRO_NAME_NO_CAP; -b my-&DISTRO_NAME_NO_CAP;
138 Branch 'my-&DISTRO_NAME_NO_CAP;' set up to track remote branch '&DISTRO_NAME_NO_CAP;' from 'origin'.
139 Switched to a new branch 'my-&DISTRO_NAME_NO_CAP;'
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500140
141The previous Git checkout command creates a local branch named
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500142``my-&DISTRO_NAME_NO_CAP;``. The files available to you in that branch
143exactly match the repository's files in the ``&DISTRO_NAME_NO_CAP;``
144release branch.
145
146Note that you can regularly type the following command in the same directory
147to keep your local files in sync with the release branch:
148
149.. code-block:: shell
150
151 $ git pull
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500152
153For more options and information about accessing Yocto Project related
154repositories, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600155:ref:`dev-manual/start:locating yocto project source files`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500156section in the Yocto Project Development Tasks Manual.
157
158Building Your Image
159===================
160
161Use the following steps to build your image. The build process creates
162an entire Linux distribution, including the toolchain, from source.
163
164.. note::
165
166 - If you are working behind a firewall and your build host is not
167 set up for proxies, you could encounter problems with the build
168 process when fetching source code (e.g. fetcher failures or Git
169 failures).
170
171 - If you do not know your proxy settings, consult your local network
172 infrastructure resources and get that information. A good starting
173 point could also be to check your web browser settings. Finally,
174 you can find more information on the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600175 ":yocto_wiki:`Working Behind a Network Proxy </Working_Behind_a_Network_Proxy>`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500176 page of the Yocto Project Wiki.
177
178#. **Initialize the Build Environment:** From within the ``poky``
Andrew Geissler09209ee2020-12-13 08:44:15 -0600179 directory, run the :ref:`ref-manual/structure:\`\`oe-init-build-env\`\``
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500180 environment
181 setup script to define Yocto Project's build environment on your
182 build host.
183
184 .. code-block:: shell
185
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500186 $ cd poky
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500187 $ source oe-init-build-env
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500188 You had no conf/local.conf file. This configuration file has therefore been
189 created for you with some default values. You may wish to edit it to, for
190 example, select a different MACHINE (target hardware). See conf/local.conf
191 for more information as common configuration options are commented.
192
193 You had no conf/bblayers.conf file. This configuration file has therefore
194 been created for you with some default values. To add additional metadata
195 layers into your configuration please add entries to conf/bblayers.conf.
196
197 The Yocto Project has extensive documentation about OE including a reference
198 manual which can be found at:
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500199 https://docs.yoctoproject.org
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500200
201 For more information about OpenEmbedded see their website:
Patrick Williams213cb262021-08-07 19:21:33 -0500202 https://www.openembedded.org/
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500203
204 ### Shell environment set up for builds. ###
205
206 You can now run 'bitbake <target>'
207
208 Common targets are:
209 core-image-minimal
Patrick Williams213cb262021-08-07 19:21:33 -0500210 core-image-full-cmdline
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500211 core-image-sato
Patrick Williams213cb262021-08-07 19:21:33 -0500212 core-image-weston
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500213 meta-toolchain
214 meta-ide-support
215
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500216 You can also run generated QEMU images with a command like 'runqemu qemux86-64'
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500217
Patrick Williams213cb262021-08-07 19:21:33 -0500218 Other commonly useful commands are:
219 - 'devtool' and 'recipetool' handle common recipe tasks
220 - 'bitbake-layers' handles common layer tasks
221 - 'oe-pkgdata-util' handles common target package tasks
222
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500223 Among other things, the script creates the :term:`Build Directory`, which is
224 ``build`` in this case and is located in the :term:`Source Directory`. After
Patrick Williams2390b1b2022-11-03 13:47:49 -0500225 the script runs, your current working directory is set to the
226 :term:`Build Directory`. Later, when the build completes, the
227 :term:`Build Directory` contains all the files created during the build.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500228
229#. **Examine Your Local Configuration File:** When you set up the build
230 environment, a local configuration file named ``local.conf`` becomes
Patrick Williams2390b1b2022-11-03 13:47:49 -0500231 available in a ``conf`` subdirectory of the :term:`Build Directory`. For this
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500232 example, the defaults are set to build for a ``qemux86`` target,
233 which is suitable for emulation. The package manager used is set to
234 the RPM package manager.
235
236 .. tip::
237
238 You can significantly speed up your build and guard against fetcher
Andrew Geissler595f6302022-01-24 19:11:47 +0000239 failures by using :ref:`overview-manual/concepts:shared state cache`
240 mirrors and enabling :ref:`overview-manual/concepts:hash equivalence`.
241 This way, you can use pre-built artifacts rather than building them.
242 This is relevant only when your network and the server that you use
243 can download these artifacts faster than you would be able to build them.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500244
Patrick Williams03907ee2022-05-01 06:28:52 -0500245 To use such mirrors, uncomment the below lines in your ``conf/local.conf``
Andrew Geissler595f6302022-01-24 19:11:47 +0000246 file in the :term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500247
Andrew Geissler595f6302022-01-24 19:11:47 +0000248 BB_SIGNATURE_HANDLER = "OEEquivHash"
249 BB_HASHSERVE = "auto"
Patrick Williamsdb4c27e2022-08-05 08:10:29 -0500250 BB_HASHSERVE_UPSTREAM = "hashserv.yocto.io:8687"
Andrew Geissler615f2f12022-07-15 14:00:58 -0500251 SSTATE_MIRRORS ?= "file://.* https://sstate.yoctoproject.org/all/PATH;downloadfilename=PATH"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500252
253#. **Start the Build:** Continue with the following command to build an OS
254 image for the target, which is ``core-image-sato`` in this example:
255
256 .. code-block:: shell
257
258 $ bitbake core-image-sato
259
260 For information on using the ``bitbake`` command, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600261 :ref:`overview-manual/concepts:bitbake` section in the Yocto Project Overview and
Patrick Williams213cb262021-08-07 19:21:33 -0500262 Concepts Manual, or see
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500263 :ref:`bitbake-user-manual/bitbake-user-manual-intro:the bitbake command`
Patrick Williams213cb262021-08-07 19:21:33 -0500264 in the BitBake User Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500265
266#. **Simulate Your Image Using QEMU:** Once this particular image is
267 built, you can start QEMU, which is a Quick EMUlator that ships with
268 the Yocto Project:
269
270 .. code-block:: shell
271
272 $ runqemu qemux86-64
273
274 If you want to learn more about running QEMU, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -0600275 :ref:`dev-manual/qemu:using the quick emulator (qemu)` chapter in
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500276 the Yocto Project Development Tasks Manual.
277
278#. **Exit QEMU:** Exit QEMU by either clicking on the shutdown icon or by typing
279 ``Ctrl-C`` in the QEMU transcript window from which you evoked QEMU.
280
281Customizing Your Build for Specific Hardware
282============================================
283
284So far, all you have done is quickly built an image suitable for
285emulation only. This section shows you how to customize your build for
286specific hardware by adding a hardware layer into the Yocto Project
287development environment.
288
289In general, layers are repositories that contain related sets of
290instructions and configurations that tell the Yocto Project what to do.
291Isolating related metadata into functionally specific layers facilitates
292modular development and makes it easier to reuse the layer metadata.
293
294.. note::
295
296 By convention, layer names start with the string "meta-".
297
298Follow these steps to add a hardware layer:
299
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700300#. **Find a Layer:** Many hardware layers are available. The Yocto Project
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500301 :yocto_git:`Source Repositories <>` has many hardware layers.
302 This example adds the
303 `meta-altera <https://github.com/kraj/meta-altera>`__ hardware layer.
304
305#. **Clone the Layer:** Use Git to make a local copy of the layer on your
306 machine. You can put the copy in the top level of the copy of the
307 Poky repository created earlier:
308
309 .. code-block:: shell
310
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500311 $ cd poky
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500312 $ git clone https://github.com/kraj/meta-altera.git
313 Cloning into 'meta-altera'...
314 remote: Counting objects: 25170, done.
315 remote: Compressing objects: 100% (350/350), done.
316 remote: Total 25170 (delta 645), reused 719 (delta 538), pack-reused 24219
317 Receiving objects: 100% (25170/25170), 41.02 MiB | 1.64 MiB/s, done.
318 Resolving deltas: 100% (13385/13385), done.
319 Checking connectivity... done.
320
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700321 The hardware layer is now available
322 next to other layers inside the Poky reference repository on your build
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500323 host as ``meta-altera`` and contains all the metadata needed to
324 support hardware from Altera, which is owned by Intel.
325
326 .. note::
327
328 It is recommended for layers to have a branch per Yocto Project release.
329 Please make sure to checkout the layer branch supporting the Yocto Project
330 release you're using.
331
332#. **Change the Configuration to Build for a Specific Machine:** The
333 :term:`MACHINE` variable in the
334 ``local.conf`` file specifies the machine for the build. For this
Andrew Geissler09036742021-06-25 14:25:14 -0500335 example, set the :term:`MACHINE` variable to ``cyclone5``. These
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500336 configurations are used:
337 https://github.com/kraj/meta-altera/blob/master/conf/machine/cyclone5.conf.
338
339 .. note::
340
341 See the "Examine Your Local Configuration File" step earlier for more
342 information on configuring the build.
343
344#. **Add Your Layer to the Layer Configuration File:** Before you can use
345 a layer during a build, you must add it to your ``bblayers.conf``
Patrick Williams2390b1b2022-11-03 13:47:49 -0500346 file, which is found in the :term:`Build Directory` ``conf`` directory.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500347
348 Use the ``bitbake-layers add-layer`` command to add the layer to the
349 configuration file:
350
351 .. code-block:: shell
352
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500353 $ cd poky/build
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500354 $ bitbake-layers add-layer ../meta-altera
355 NOTE: Starting bitbake server...
356 Parsing recipes: 100% |##################################################################| Time: 0:00:32
357 Parsing of 918 .bb files complete (0 cached, 918 parsed). 1401 targets,
358 123 skipped, 0 masked, 0 errors.
359
360 You can find
361 more information on adding layers in the
Andrew Geissler517393d2023-01-13 08:55:19 -0600362 :ref:`dev-manual/layers:adding a layer using the \`\`bitbake-layers\`\` script`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500363 section.
364
365Completing these steps has added the ``meta-altera`` layer to your Yocto
366Project development environment and configured it to build for the
367``cyclone5`` machine.
368
369.. note::
370
371 The previous steps are for demonstration purposes only. If you were
372 to attempt to build an image for the ``cyclone5`` machine, you should
373 read the Altera ``README``.
374
375Creating Your Own General Layer
376===============================
377
378Maybe you have an application or specific set of behaviors you need to
379isolate. You can create your own general layer using the
380``bitbake-layers create-layer`` command. The tool automates layer
381creation by setting up a subdirectory with a ``layer.conf``
382configuration file, a ``recipes-example`` subdirectory that contains an
383``example.bb`` recipe, a licensing file, and a ``README``.
384
385The following commands run the tool to create a layer named
386``meta-mylayer`` in the ``poky`` directory:
387
388.. code-block:: shell
389
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500390 $ cd poky
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500391 $ bitbake-layers create-layer meta-mylayer
392 NOTE: Starting bitbake server...
393 Add your new layer with 'bitbake-layers add-layer meta-mylayer'
394
395For more information
396on layers and how to create them, see the
Andrew Geissler517393d2023-01-13 08:55:19 -0600397:ref:`dev-manual/layers:creating a general layer using the \`\`bitbake-layers\`\` script`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500398section in the Yocto Project Development Tasks Manual.
399
400Where To Go Next
401================
402
403Now that you have experienced using the Yocto Project, you might be
404asking yourself "What now?". The Yocto Project has many sources of
405information including the website, wiki pages, and user manuals:
406
407- **Website:** The :yocto_home:`Yocto Project Website <>` provides
408 background information, the latest builds, breaking news, full
409 development documentation, and access to a rich Yocto Project
410 Development Community into which you can tap.
411
Andrew Geisslerd5838332022-05-27 11:33:10 -0500412- **Video Seminar:** The `Introduction to the Yocto Project and BitBake, Part 1
Andrew Geissler9aee5002022-03-30 16:27:02 +0000413 <https://youtu.be/yuE7my3KOpo>`__ and
Andrew Geisslerd5838332022-05-27 11:33:10 -0500414 `Introduction to the Yocto Project and BitBake, Part 2
Andrew Geissler9aee5002022-03-30 16:27:02 +0000415 <https://youtu.be/iZ05TTyzGHk>`__ videos offer a video seminar
416 introducing you to the most important aspects of developing a
417 custom embedded Linux distribution with the Yocto Project.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500418
419- **Yocto Project Overview and Concepts Manual:** The
Andrew Geissler09209ee2020-12-13 08:44:15 -0600420 :doc:`/overview-manual/index` is a great
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500421 place to start to learn about the Yocto Project. This manual
422 introduces you to the Yocto Project and its development environment.
423 The manual also provides conceptual information for various aspects
424 of the Yocto Project.
425
426- **Yocto Project Wiki:** The :yocto_wiki:`Yocto Project Wiki <>`
427 provides additional information on where to go next when ramping up
428 with the Yocto Project, release information, project planning, and QA
429 information.
430
431- **Yocto Project Mailing Lists:** Related mailing lists provide a forum
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700432 for discussion, patch submission and announcements. There are several
433 mailing lists grouped by topic. See the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500434 :ref:`ref-manual/resources:mailing lists`
435 section in the Yocto Project Reference Manual for a complete list of
436 Yocto Project mailing lists.
437
438- **Comprehensive List of Links and Other Documentation:** The
439 :ref:`ref-manual/resources:links and related documentation`
440 section in the Yocto Project Reference Manual provides a
441 comprehensive list of all related links and other user documentation.
442
443.. include:: /boilerplate.rst