Andrew Geissler | f034379 | 2020-11-18 10:42:21 -0600 | [diff] [blame^] | 1 | .. SPDX-License-Identifier: CC-BY-SA-2.0-UK |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2 | |
| 3 | ************************************* |
| 4 | Preparing for Application Development |
| 5 | ************************************* |
| 6 | |
| 7 | In order to develop applications, you need set up your host development |
| 8 | system. Several ways exist that allow you to install cross-development |
| 9 | tools, QEMU, the Eclipse Yocto Plug-in, and other tools. This chapter |
| 10 | describes how to prepare for application development. |
| 11 | |
| 12 | .. _installing-the-adt: |
| 13 | |
| 14 | Installing the ADT and Toolchains |
| 15 | ================================= |
| 16 | |
| 17 | The following list describes installation methods that set up varying |
| 18 | degrees of tool availability on your system. Regardless of the |
| 19 | installation method you choose, you must ``source`` the cross-toolchain |
| 20 | environment setup script, which establishes several key environment |
| 21 | variables, before you use a toolchain. See the "`Setting Up the |
| 22 | Cross-Development |
| 23 | Environment <#setting-up-the-cross-development-environment>`__" section |
| 24 | for more information. |
| 25 | |
| 26 | .. note:: |
| 27 | |
| 28 | Avoid mixing installation methods when installing toolchains for |
| 29 | different architectures. For example, avoid using the ADT Installer |
| 30 | to install some toolchains and then hand-installing cross-development |
| 31 | toolchains by running the toolchain installer for different |
| 32 | architectures. Mixing installation methods can result in situations |
| 33 | where the ADT Installer becomes unreliable and might not install the |
| 34 | toolchain. |
| 35 | |
| 36 | If you must mix installation methods, you might avoid problems by |
| 37 | deleting ``/var/lib/opkg``, thus purging the ``opkg`` package |
| 38 | metadata. |
| 39 | |
| 40 | - *Use the ADT installer script:* This method is the recommended way to |
| 41 | install the ADT because it automates much of the process for you. For |
| 42 | example, you can configure the installation to install the QEMU |
| 43 | emulator and the user-space NFS, specify which root filesystem |
| 44 | profiles to download, and define the target sysroot location. |
| 45 | |
| 46 | - *Use an existing toolchain:* Using this method, you select and |
| 47 | download an architecture-specific toolchain installer and then run |
| 48 | the script to hand-install the toolchain. If you use this method, you |
| 49 | just get the cross-toolchain and QEMU - you do not get any of the |
| 50 | other mentioned benefits had you run the ADT Installer script. |
| 51 | |
| 52 | - *Use the toolchain from within the Build Directory:* If you already |
| 53 | have a :term:`Build Directory`, |
| 54 | you can build the cross-toolchain within the directory. However, like |
| 55 | the previous method mentioned, you only get the cross-toolchain and |
| 56 | QEMU - you do not get any of the other benefits without taking |
| 57 | separate steps. |
| 58 | |
| 59 | Using the ADT Installer |
| 60 | ----------------------- |
| 61 | |
| 62 | To run the ADT Installer, you need to get the ADT Installer tarball, be |
| 63 | sure you have the necessary host development packages that support the |
| 64 | ADT Installer, and then run the ADT Installer Script. |
| 65 | |
| 66 | For a list of the host packages needed to support ADT installation and |
| 67 | use, see the "ADT Installer Extras" lists in the "`Required Packages for |
| 68 | the Host Development |
| 69 | System <&YOCTO_DOCS_REF_URL;#required-packages-for-the-host-development-system>`__" |
| 70 | section of the Yocto Project Reference Manual. |
| 71 | |
| 72 | Getting the ADT Installer Tarball |
| 73 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 74 | |
| 75 | The ADT Installer is contained in the ADT Installer tarball. You can get |
| 76 | the tarball using either of these methods: |
| 77 | |
| 78 | - *Download the Tarball:* You can download the tarball from |
| 79 | ` <&YOCTO_ADTINSTALLER_DL_URL;>`__ into any directory. |
| 80 | |
| 81 | - *Build the Tarball:* You can use |
| 82 | :term:`BitBake` to generate the |
| 83 | tarball inside an existing :term:`Build Directory`. |
| 84 | |
| 85 | If you use BitBake to generate the ADT Installer tarball, you must |
| 86 | ``source`` the environment setup script |
| 87 | (````` <&YOCTO_DOCS_REF_URL;#structure-core-script>`__ or |
| 88 | ```oe-init-build-env-memres`` <&YOCTO_DOCS_REF_URL;#structure-memres-core-script>`__) |
| 89 | located in the Source Directory before running the ``bitbake`` |
| 90 | command that creates the tarball. |
| 91 | |
| 92 | The following example commands establish the |
| 93 | :term:`Source Directory`, check out the |
| 94 | current release branch, set up the build environment while also |
| 95 | creating the default Build Directory, and run the ``bitbake`` command |
| 96 | that results in the tarball |
| 97 | ``poky/build/tmp/deploy/sdk/adt_installer.tar.bz2``: |
| 98 | |
| 99 | .. note:: |
| 100 | |
| 101 | Before using BitBake to build the ADT tarball, be sure to make |
| 102 | sure your |
| 103 | local.conf |
| 104 | file is properly configured. See the " |
| 105 | User Configuration |
| 106 | " section in the Yocto Project Reference Manual for general |
| 107 | configuration information. |
| 108 | |
| 109 | $ cd ~ $ git clone git://git.yoctoproject.org/poky $ cd poky $ git |
| 110 | checkout -b DISTRO_NAME origin/DISTRO_NAME $ source OE_INIT_FILE $ |
| 111 | bitbake adt-installer |
| 112 | |
| 113 | Configuring and Running the ADT Installer Script |
| 114 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 115 | |
| 116 | Before running the ADT Installer script, you need to unpack the tarball. |
| 117 | You can unpack the tarball in any directory you wish. For example, this |
| 118 | command copies the ADT Installer tarball from where it was built into |
| 119 | the home directory and then unpacks the tarball into a top-level |
| 120 | directory named ``adt-installer``: $ cd ~ $ cp |
| 121 | poky/build/tmp/deploy/sdk/adt_installer.tar.bz2 $HOME $ tar -xjf |
| 122 | adt_installer.tar.bz2 Unpacking it creates the directory |
| 123 | ``adt-installer``, which contains the ADT Installer script |
| 124 | (``adt_installer``) and its configuration file (``adt_installer.conf``). |
| 125 | |
| 126 | Before you run the script, however, you should examine the ADT Installer |
| 127 | configuration file and be sure you are going to get what you want. Your |
| 128 | configurations determine which kernel and filesystem image are |
| 129 | downloaded. |
| 130 | |
| 131 | The following list describes the configurations you can define for the |
| 132 | ADT Installer. For configuration values and restrictions, see the |
| 133 | comments in the ``adt-installer.conf`` file: |
| 134 | |
| 135 | - ``YOCTOADT_REPO``: This area includes the IPKG-based packages and the |
| 136 | root filesystem upon which the installation is based. If you want to |
| 137 | set up your own IPKG repository pointed to by ``YOCTOADT_REPO``, you |
| 138 | need to be sure that the directory structure follows the same layout |
| 139 | as the reference directory set up at |
| 140 | http://adtrepo.yoctoproject.org. Also, your repository needs |
| 141 | to be accessible through HTTP. |
| 142 | |
| 143 | - ``YOCTOADT_TARGETS``: The machine target architectures for which you |
| 144 | want to set up cross-development environments. |
| 145 | |
| 146 | - ``YOCTOADT_QEMU``: Indicates whether or not to install the emulator |
| 147 | QEMU. |
| 148 | |
| 149 | - ``YOCTOADT_NFS_UTIL``: Indicates whether or not to install user-mode |
| 150 | NFS. If you plan to use the Eclipse IDE Yocto plug-in against QEMU, |
| 151 | you should install NFS. |
| 152 | |
| 153 | .. note:: |
| 154 | |
| 155 | To boot QEMU images using our userspace NFS server, you need to be |
| 156 | running |
| 157 | portmap |
| 158 | or |
| 159 | rpcbind |
| 160 | . If you are running |
| 161 | rpcbind |
| 162 | , you will also need to add the |
| 163 | -i |
| 164 | option when |
| 165 | rpcbind |
| 166 | starts up. Please make sure you understand the security |
| 167 | implications of doing this. You might also have to modify your |
| 168 | firewall settings to allow NFS booting to work. |
| 169 | |
| 170 | - ``YOCTOADT_ROOTFS_``\ arch: The root filesystem images you want to |
| 171 | download from the ``YOCTOADT_IPKG_REPO`` repository. |
| 172 | |
| 173 | - ``YOCTOADT_TARGET_SYSROOT_IMAGE_``\ arch: The particular root |
| 174 | filesystem used to extract and create the target sysroot. The value |
| 175 | of this variable must have been specified with |
| 176 | ``YOCTOADT_ROOTFS_``\ arch. For example, if you downloaded both |
| 177 | ``minimal`` and ``sato-sdk`` images by setting |
| 178 | ``YOCTOADT_ROOTFS_``\ arch to "minimal sato-sdk", then |
| 179 | ``YOCTOADT_ROOTFS_``\ arch must be set to either "minimal" or |
| 180 | "sato-sdk". |
| 181 | |
| 182 | - ``YOCTOADT_TARGET_SYSROOT_LOC_``\ arch: The location on the |
| 183 | development host where the target sysroot is created. |
| 184 | |
| 185 | After you have configured the ``adt_installer.conf`` file, run the |
| 186 | installer using the following command: $ cd adt-installer $ |
| 187 | ./adt_installer Once the installer begins to run, you are asked to enter |
| 188 | the location for cross-toolchain installation. The default location is |
| 189 | ``/opt/poky/``\ release. After either accepting the default location or |
| 190 | selecting your own location, you are prompted to run the installation |
| 191 | script interactively or in silent mode. If you want to closely monitor |
| 192 | the installation, choose "I" for interactive mode rather than "S" for |
| 193 | silent mode. Follow the prompts from the script to complete the |
| 194 | installation. |
| 195 | |
| 196 | Once the installation completes, the ADT, which includes the |
| 197 | cross-toolchain, is installed in the selected installation directory. |
| 198 | You will notice environment setup files for the cross-toolchain in the |
| 199 | installation directory, and image tarballs in the ``adt-installer`` |
| 200 | directory according to your installer configurations, and the target |
| 201 | sysroot located according to the ``YOCTOADT_TARGET_SYSROOT_LOC_``\ arch |
| 202 | variable also in your configuration file. |
| 203 | |
| 204 | .. _using-an-existing-toolchain-tarball: |
| 205 | |
| 206 | Using a Cross-Toolchain Tarball |
| 207 | ------------------------------- |
| 208 | |
| 209 | If you want to simply install a cross-toolchain by hand, you can do so |
| 210 | by running the toolchain installer. The installer includes the pre-built |
| 211 | cross-toolchain, the ``runqemu`` script, and support files. If you use |
| 212 | this method to install the cross-toolchain, you might still need to |
| 213 | install the target sysroot by installing and extracting it separately. |
| 214 | For information on how to install the sysroot, see the "`Extracting the |
| 215 | Root Filesystem <#extracting-the-root-filesystem>`__" section. |
| 216 | |
| 217 | Follow these steps: |
| 218 | |
| 219 | 1. *Get your toolchain installer using one of the following methods:* |
| 220 | |
| 221 | - Go to ` <&YOCTO_TOOLCHAIN_DL_URL;>`__ and find the folder that |
| 222 | matches your host development system (i.e. ``i686`` for 32-bit |
| 223 | machines or ``x86_64`` for 64-bit machines). |
| 224 | |
| 225 | Go into that folder and download the toolchain installer whose |
| 226 | name includes the appropriate target architecture. The toolchains |
| 227 | provided by the Yocto Project are based off of the |
| 228 | ``core-image-sato`` image and contain libraries appropriate for |
| 229 | developing against that image. For example, if your host |
| 230 | development system is a 64-bit x86 system and you are going to use |
| 231 | your cross-toolchain for a 32-bit x86 target, go into the |
| 232 | ``x86_64`` folder and download the following installer: |
| 233 | poky-glibc-x86_64-core-image-sato-i586-toolchain-DISTRO.sh |
| 234 | |
| 235 | - Build your own toolchain installer. For cases where you cannot use |
| 236 | an installer from the download area, you can build your own as |
| 237 | described in the "`Optionally Building a Toolchain |
| 238 | Installer <#optionally-building-a-toolchain-installer>`__" |
| 239 | section. |
| 240 | |
| 241 | 2. *Once you have the installer, run it to install the toolchain:* |
| 242 | |
| 243 | .. note:: |
| 244 | |
| 245 | You must change the permissions on the toolchain installer script |
| 246 | so that it is executable. |
| 247 | |
| 248 | The following command shows how to run the installer given a |
| 249 | toolchain tarball for a 64-bit x86 development host system and a |
| 250 | 32-bit x86 target architecture. The example assumes the toolchain |
| 251 | installer is located in ``~/Downloads/``. $ |
| 252 | ~/Downloads/poky-glibc-x86_64-core-image-sato-i586-toolchain-DISTRO.sh |
| 253 | The first thing the installer prompts you for is the directory into |
| 254 | which you want to install the toolchain. The default directory used |
| 255 | is ``/opt/poky/DISTRO``. If you do not have write permissions for the |
| 256 | directory into which you are installing the toolchain, the toolchain |
| 257 | installer notifies you and exits. Be sure you have write permissions |
| 258 | in the directory and run the installer again. |
| 259 | |
| 260 | When the script finishes, the cross-toolchain is installed. You will |
| 261 | notice environment setup files for the cross-toolchain in the |
| 262 | installation directory. |
| 263 | |
| 264 | .. _using-the-toolchain-from-within-the-build-tree: |
| 265 | |
| 266 | Using BitBake and the Build Directory |
| 267 | ------------------------------------- |
| 268 | |
| 269 | A final way of making the cross-toolchain available is to use BitBake to |
| 270 | generate the toolchain within an existing :term:`Build Directory`. |
| 271 | This method does |
| 272 | not install the toolchain into the default ``/opt`` directory. As with |
| 273 | the previous method, if you need to install the target sysroot, you must |
| 274 | do that separately as well. |
| 275 | |
| 276 | Follow these steps to generate the toolchain into the Build Directory: |
| 277 | |
| 278 | 1. *Set up the Build Environment:* Source the OpenEmbedded build |
| 279 | environment setup script (i.e. |
| 280 | ````` <&YOCTO_DOCS_REF_URL;#structure-core-script>`__ or |
| 281 | ```oe-init-build-env-memres`` <&YOCTO_DOCS_REF_URL;#structure-memres-core-script>`__) |
| 282 | located in the :term:`Source Directory`. |
| 283 | |
| 284 | 2. *Check your Local Configuration File:* At this point, you should be |
| 285 | sure that the :term:`MACHINE` |
| 286 | variable in the ``local.conf`` file found in the ``conf`` directory |
| 287 | of the Build Directory is set for the target architecture. Comments |
| 288 | within the ``local.conf`` file list the values you can use for the |
| 289 | ``MACHINE`` variable. If you do not change the ``MACHINE`` variable, |
| 290 | the OpenEmbedded build system uses ``qemux86`` as the default target |
| 291 | machine when building the cross-toolchain. |
| 292 | |
| 293 | .. note:: |
| 294 | |
| 295 | You can populate the Build Directory with the cross-toolchains for |
| 296 | more than a single architecture. You just need to edit the |
| 297 | MACHINE |
| 298 | variable in the |
| 299 | local.conf |
| 300 | file and re-run the |
| 301 | bitbake |
| 302 | command. |
| 303 | |
| 304 | 3. *Make Sure Your Layers are Enabled:* Examine the |
| 305 | ``conf/bblayers.conf`` file and make sure that you have enabled all |
| 306 | the compatible layers for your target machine. The OpenEmbedded build |
| 307 | system needs to be aware of each layer you want included when |
| 308 | building images and cross-toolchains. For information on how to |
| 309 | enable a layer, see the "`Enabling Your |
| 310 | Layer <&YOCTO_DOCS_DEV_URL;#enabling-your-layer>`__" section in the |
| 311 | Yocto Project Development Manual. |
| 312 | |
| 313 | 4. *Generate the Cross-Toolchain:* Run ``bitbake meta-ide-support`` to |
| 314 | complete the cross-toolchain generation. Once the ``bitbake`` command |
| 315 | finishes, the cross-toolchain is generated and populated within the |
| 316 | Build Directory. You will notice environment setup files for the |
| 317 | cross-toolchain that contain the string "``environment-setup``" in |
| 318 | the Build Directory's ``tmp`` folder. |
| 319 | |
| 320 | Be aware that when you use this method to install the toolchain, you |
| 321 | still need to separately extract and install the sysroot filesystem. |
| 322 | For information on how to do this, see the "`Extracting the Root |
| 323 | Filesystem <#extracting-the-root-filesystem>`__" section. |
| 324 | |
| 325 | Setting Up the Cross-Development Environment |
| 326 | ============================================ |
| 327 | |
| 328 | Before you can develop using the cross-toolchain, you need to set up the |
| 329 | cross-development environment by sourcing the toolchain's environment |
| 330 | setup script. If you used the ADT Installer or hand-installed |
| 331 | cross-toolchain, then you can find this script in the directory you |
| 332 | chose for installation. For this release, the default installation |
| 333 | directory is ````. If you installed the toolchain in the |
| 334 | :term:`Build Directory`, you can find the |
| 335 | environment setup script for the toolchain in the Build Directory's |
| 336 | ``tmp`` directory. |
| 337 | |
| 338 | Be sure to run the environment setup script that matches the |
| 339 | architecture for which you are developing. Environment setup scripts |
| 340 | begin with the string "``environment-setup``" and include as part of |
| 341 | their name the architecture. For example, the toolchain environment |
| 342 | setup script for a 64-bit IA-based architecture installed in the default |
| 343 | installation directory would be the following: |
| 344 | YOCTO_ADTPATH_DIR/environment-setup-x86_64-poky-linux When you run the |
| 345 | setup script, many environment variables are defined: |
| 346 | :term:`SDKTARGETSYSROOT` - |
| 347 | The path to the sysroot used for cross-compilation |
| 348 | :term:`PKG_CONFIG_PATH` - The |
| 349 | path to the target pkg-config files |
| 350 | :term:`CONFIG_SITE` - A GNU |
| 351 | autoconf site file preconfigured for the target |
| 352 | :term:`CC` - The minimal command and |
| 353 | arguments to run the C compiler |
| 354 | :term:`CXX` - The minimal command and |
| 355 | arguments to run the C++ compiler |
| 356 | :term:`CPP` - The minimal command and |
| 357 | arguments to run the C preprocessor |
| 358 | :term:`AS` - The minimal command and |
| 359 | arguments to run the assembler :term:`LD` |
| 360 | - The minimal command and arguments to run the linker |
| 361 | :term:`GDB` - The minimal command and |
| 362 | arguments to run the GNU Debugger |
| 363 | :term:`STRIP` - The minimal command and |
| 364 | arguments to run 'strip', which strips symbols |
| 365 | :term:`RANLIB` - The minimal command |
| 366 | and arguments to run 'ranlib' |
| 367 | :term:`OBJCOPY` - The minimal command |
| 368 | and arguments to run 'objcopy' |
| 369 | :term:`OBJDUMP` - The minimal command |
| 370 | and arguments to run 'objdump' :term:`AR` |
| 371 | - The minimal command and arguments to run 'ar' |
| 372 | :term:`NM` - The minimal command and |
| 373 | arguments to run 'nm' |
| 374 | :term:`TARGET_PREFIX` - The |
| 375 | toolchain binary prefix for the target tools |
| 376 | :term:`CROSS_COMPILE` - The |
| 377 | toolchain binary prefix for the target tools |
| 378 | :term:`CONFIGURE_FLAGS` - The |
| 379 | minimal arguments for GNU configure |
| 380 | :term:`CFLAGS` - Suggested C flags |
| 381 | :term:`CXXFLAGS` - Suggested C++ |
| 382 | flags :term:`LDFLAGS` - Suggested |
| 383 | linker flags when you use CC to link |
| 384 | :term:`CPPFLAGS` - Suggested |
| 385 | preprocessor flags |
| 386 | |
| 387 | Securing Kernel and Filesystem Images |
| 388 | ===================================== |
| 389 | |
| 390 | You will need to have a kernel and filesystem image to boot using your |
| 391 | hardware or the QEMU emulator. Furthermore, if you plan on booting your |
| 392 | image using NFS or you want to use the root filesystem as the target |
| 393 | sysroot, you need to extract the root filesystem. |
| 394 | |
| 395 | Getting the Images |
| 396 | ------------------ |
| 397 | |
| 398 | To get the kernel and filesystem images, you either have to build them |
| 399 | or download pre-built versions. For an example of how to build these |
| 400 | images, see the "`Buiding |
| 401 | Images <&YOCTO_DOCS_QS_URL;#qs-buiding-images>`__" section of the Yocto |
| 402 | Project Quick Start. For an example of downloading pre-build versions, |
| 403 | see the "`Example Using Pre-Built Binaries and |
| 404 | QEMU <#using-pre-built>`__" section. |
| 405 | |
| 406 | The Yocto Project ships basic kernel and filesystem images for several |
| 407 | architectures (``x86``, ``x86-64``, ``mips``, ``powerpc``, and ``arm``) |
| 408 | that you can use unaltered in the QEMU emulator. These kernel images |
| 409 | reside in the release area - ` <&YOCTO_MACHINES_DL_URL;>`__ and are |
| 410 | ideal for experimentation using Yocto Project. For information on the |
| 411 | image types you can build using the OpenEmbedded build system, see the |
| 412 | ":ref:`ref-manual/ref-images:Images`" chapter in the Yocto |
| 413 | Project Reference Manual. |
| 414 | |
| 415 | If you are planning on developing against your image and you are not |
| 416 | building or using one of the Yocto Project development images (e.g. |
| 417 | ``core-image-*-dev``), you must be sure to include the development |
| 418 | packages as part of your image recipe. |
| 419 | |
| 420 | If you plan on remotely deploying and debugging your application from |
| 421 | within the Eclipse IDE, you must have an image that contains the Yocto |
| 422 | Target Communication Framework (TCF) agent (``tcf-agent``). You can do |
| 423 | this by including the ``eclipse-debug`` image feature. |
| 424 | |
| 425 | .. note:: |
| 426 | |
| 427 | See the " |
| 428 | Image Features |
| 429 | " section in the Yocto Project Reference Manual for information on |
| 430 | image features. |
| 431 | |
| 432 | To include the ``eclipse-debug`` image feature, modify your |
| 433 | ``local.conf`` file in the :term:`Build Directory` |
| 434 | so that the |
| 435 | :term:`EXTRA_IMAGE_FEATURES` |
| 436 | variable includes the "eclipse-debug" feature. After modifying the |
| 437 | configuration file, you can rebuild the image. Once the image is |
| 438 | rebuilt, the ``tcf-agent`` will be included in the image and is launched |
| 439 | automatically after the boot. |
| 440 | |
| 441 | Extracting the Root Filesystem |
| 442 | ------------------------------ |
| 443 | |
| 444 | If you install your toolchain by hand or build it using BitBake and you |
| 445 | need a root filesystem, you need to extract it separately. If you use |
| 446 | the ADT Installer to install the ADT, the root filesystem is |
| 447 | automatically extracted and installed. |
| 448 | |
| 449 | Here are some cases where you need to extract the root filesystem: |
| 450 | |
| 451 | - You want to boot the image using NFS. |
| 452 | |
| 453 | - You want to use the root filesystem as the target sysroot. For |
| 454 | example, the Eclipse IDE environment with the Eclipse Yocto Plug-in |
| 455 | installed allows you to use QEMU to boot under NFS. |
| 456 | |
| 457 | - You want to develop your target application using the root filesystem |
| 458 | as the target sysroot. |
| 459 | |
| 460 | To extract the root filesystem, first ``source`` the cross-development |
| 461 | environment setup script to establish necessary environment variables. |
| 462 | If you built the toolchain in the Build Directory, you will find the |
| 463 | toolchain environment script in the ``tmp`` directory. If you installed |
| 464 | the toolchain by hand, the environment setup script is located in |
| 465 | ``/opt/poky/DISTRO``. |
| 466 | |
| 467 | After sourcing the environment script, use the ``runqemu-extract-sdk`` |
| 468 | command and provide the filesystem image. |
| 469 | |
| 470 | Following is an example. The second command sets up the environment. In |
| 471 | this case, the setup script is located in the ``/opt/poky/DISTRO`` |
| 472 | directory. The third command extracts the root filesystem from a |
| 473 | previously built filesystem that is located in the ``~/Downloads`` |
| 474 | directory. Furthermore, this command extracts the root filesystem into |
| 475 | the ``qemux86-sato`` directory: $ cd ~ $ source |
| 476 | /opt/poky/DISTRO/environment-setup-i586-poky-linux $ runqemu-extract-sdk |
| 477 | \\ ~/Downloads/core-image-sato-sdk-qemux86-2011091411831.rootfs.tar.bz2 |
| 478 | \\ $HOME/qemux86-sato You could now point to the target sysroot at |
| 479 | ``qemux86-sato``. |
| 480 | |
| 481 | Optionally Building a Toolchain Installer |
| 482 | ========================================= |
| 483 | |
| 484 | As an alternative to locating and downloading a toolchain installer, you |
| 485 | can build the toolchain installer if you have a :term:`Build Directory`. |
| 486 | |
| 487 | .. note:: |
| 488 | |
| 489 | Although not the preferred method, it is also possible to use |
| 490 | bitbake meta-toolchain |
| 491 | to build the toolchain installer. If you do use this method, you must |
| 492 | separately install and extract the target sysroot. For information on |
| 493 | how to install the sysroot, see the " |
| 494 | Extracting the Root Filesystem |
| 495 | " section. |
| 496 | |
| 497 | To build the toolchain installer and populate the SDK image, use the |
| 498 | following command: $ bitbake image -c populate_sdk The command results |
| 499 | in a toolchain installer that contains the sysroot that matches your |
| 500 | target root filesystem. |
| 501 | |
| 502 | Another powerful feature is that the toolchain is completely |
| 503 | self-contained. The binaries are linked against their own copy of |
| 504 | ``libc``, which results in no dependencies on the target system. To |
| 505 | achieve this, the pointer to the dynamic loader is configured at install |
| 506 | time since that path cannot be dynamically altered. This is the reason |
| 507 | for a wrapper around the ``populate_sdk`` archive. |
| 508 | |
| 509 | Another feature is that only one set of cross-canadian toolchain |
| 510 | binaries are produced per architecture. This feature takes advantage of |
| 511 | the fact that the target hardware can be passed to ``gcc`` as a set of |
| 512 | compiler options. Those options are set up by the environment script and |
| 513 | contained in variables such as :term:`CC` |
| 514 | and :term:`LD`. This reduces the space |
| 515 | needed for the tools. Understand, however, that a sysroot is still |
| 516 | needed for every target since those binaries are target-specific. |
| 517 | |
| 518 | Remember, before using any BitBake command, you must source the build |
| 519 | environment setup script (i.e. |
| 520 | ````` <&YOCTO_DOCS_REF_URL;#structure-core-script>`__ or |
| 521 | ```oe-init-build-env-memres`` <&YOCTO_DOCS_REF_URL;#structure-memres-core-script>`__) |
| 522 | located in the Source Directory and you must make sure your |
| 523 | ``conf/local.conf`` variables are correct. In particular, you need to be |
| 524 | sure the :term:`MACHINE` variable |
| 525 | matches the architecture for which you are building and that the |
| 526 | :term:`SDKMACHINE` variable is |
| 527 | correctly set if you are building a toolchain designed to run on an |
| 528 | architecture that differs from your current development host machine |
| 529 | (i.e. the build machine). |
| 530 | |
| 531 | When the ``bitbake`` command completes, the toolchain installer will be |
| 532 | in ``tmp/deploy/sdk`` in the Build Directory. |
| 533 | |
| 534 | .. note:: |
| 535 | |
| 536 | By default, this toolchain does not build static binaries. If you |
| 537 | want to use the toolchain to build these types of libraries, you need |
| 538 | to be sure your image has the appropriate static development |
| 539 | libraries. Use the |
| 540 | IMAGE_INSTALL |
| 541 | variable inside your |
| 542 | local.conf |
| 543 | file to install the appropriate library packages. Following is an |
| 544 | example using |
| 545 | glibc |
| 546 | static development libraries: |
| 547 | :: |
| 548 | |
| 549 | IMAGE_INSTALL_append = " glibc-staticdev" |
| 550 | |
| 551 | |
| 552 | Optionally Using an External Toolchain |
| 553 | ====================================== |
| 554 | |
| 555 | You might want to use an external toolchain as part of your development. |
| 556 | If this is the case, the fundamental steps you need to accomplish are as |
| 557 | follows: |
| 558 | |
| 559 | - Understand where the installed toolchain resides. For cases where you |
| 560 | need to build the external toolchain, you would need to take separate |
| 561 | steps to build and install the toolchain. |
| 562 | |
| 563 | - Make sure you add the layer that contains the toolchain to your |
| 564 | ``bblayers.conf`` file through the |
| 565 | :term:`BBLAYERS` variable. |
| 566 | |
| 567 | - Set the |
| 568 | :term:`EXTERNAL_TOOLCHAIN` |
| 569 | variable in your ``local.conf`` file to the location in which you |
| 570 | installed the toolchain. |
| 571 | |
| 572 | A good example of an external toolchain used with the Yocto Project is |
| 573 | Mentor Graphics Sourcery G++ Toolchain. You can see information on how |
| 574 | to use that particular layer in the ``README`` file at |
| 575 | http://github.com/MentorEmbedded/meta-sourcery/. You can find |
| 576 | further information by reading about the |
| 577 | :term:`TCMODE` variable in the Yocto |
| 578 | Project Reference Manual's variable glossary. |
| 579 | |
| 580 | .. _using-pre-built: |
| 581 | |
| 582 | Example Using Pre-Built Binaries and QEMU |
| 583 | ========================================= |
| 584 | |
| 585 | If hardware, libraries and services are stable, you can get started by |
| 586 | using a pre-built binary of the filesystem image, kernel, and toolchain |
| 587 | and run it using the QEMU emulator. This scenario is useful for |
| 588 | developing application software. |
| 589 | |
| 590 | |Using a Pre-Built Image| |
| 591 | |
| 592 | For this scenario, you need to do several things: |
| 593 | |
| 594 | - Install the appropriate stand-alone toolchain tarball. |
| 595 | |
| 596 | - Download the pre-built image that will boot with QEMU. You need to be |
| 597 | sure to get the QEMU image that matches your target machine's |
| 598 | architecture (e.g. x86, ARM, etc.). |
| 599 | |
| 600 | - Download the filesystem image for your target machine's architecture. |
| 601 | |
| 602 | - Set up the environment to emulate the hardware and then start the |
| 603 | QEMU emulator. |
| 604 | |
| 605 | Installing the Toolchain |
| 606 | ------------------------ |
| 607 | |
| 608 | You can download a tarball installer, which includes the pre-built |
| 609 | toolchain, the ``runqemu`` script, and support files from the |
| 610 | appropriate directory under ` <&YOCTO_TOOLCHAIN_DL_URL;>`__. Toolchains |
| 611 | are available for 32-bit and 64-bit x86 development systems from the |
| 612 | ``i686`` and ``x86_64`` directories, respectively. The toolchains the |
| 613 | Yocto Project provides are based off the ``core-image-sato`` image and |
| 614 | contain libraries appropriate for developing against that image. Each |
| 615 | type of development system supports five or more target architectures. |
| 616 | |
| 617 | The names of the tarball installer scripts are such that a string |
| 618 | representing the host system appears first in the filename and then is |
| 619 | immediately followed by a string representing the target architecture. |
| 620 | |
| 621 | :: |
| 622 | |
| 623 | poky-glibc-host_system-image_type-arch-toolchain-release_version.sh |
| 624 | |
| 625 | Where: |
| 626 | host_system is a string representing your development system: |
| 627 | |
| 628 | i686 or x86_64. |
| 629 | |
| 630 | image_type is a string representing the image you wish to |
| 631 | develop a Software Development Toolkit (SDK) for use against. |
| 632 | The Yocto Project builds toolchain installers using the |
| 633 | following BitBake command: |
| 634 | |
| 635 | bitbake core-image-sato -c populate_sdk |
| 636 | |
| 637 | arch is a string representing the tuned target architecture: |
| 638 | |
| 639 | i586, x86_64, powerpc, mips, armv7a or armv5te |
| 640 | |
| 641 | release_version is a string representing the release number of the |
| 642 | Yocto Project: |
| 643 | |
| 644 | DISTRO, DISTRO+snapshot |
| 645 | |
| 646 | |
| 647 | For example, the following toolchain installer is for a 64-bit |
| 648 | development host system and a i586-tuned target architecture based off |
| 649 | the SDK for ``core-image-sato``: |
| 650 | poky-glibc-x86_64-core-image-sato-i586-toolchain-DISTRO.sh |
| 651 | |
| 652 | Toolchains are self-contained and by default are installed into |
| 653 | ``/opt/poky``. However, when you run the toolchain installer, you can |
| 654 | choose an installation directory. |
| 655 | |
| 656 | The following command shows how to run the installer given a toolchain |
| 657 | tarball for a 64-bit x86 development host system and a 32-bit x86 target |
| 658 | architecture. You must change the permissions on the toolchain installer |
| 659 | script so that it is executable. |
| 660 | |
| 661 | The example assumes the toolchain installer is located in |
| 662 | ``~/Downloads/``. |
| 663 | |
| 664 | .. note:: |
| 665 | |
| 666 | If you do not have write permissions for the directory into which you |
| 667 | are installing the toolchain, the toolchain installer notifies you |
| 668 | and exits. Be sure you have write permissions in the directory and |
| 669 | run the installer again. |
| 670 | |
| 671 | $ ~/Downloads/poky-glibc-x86_64-core-image-sato-i586-toolchain-DISTRO.sh |
| 672 | |
| 673 | For more information on how to install tarballs, see the "`Using a |
| 674 | Cross-Toolchain |
| 675 | Tarball <&YOCTO_DOCS_ADT_URL;#using-an-existing-toolchain-tarball>`__" |
| 676 | and "`Using BitBake and the Build |
| 677 | Directory <&YOCTO_DOCS_ADT_URL;#using-the-toolchain-from-within-the-build-tree>`__" |
| 678 | sections in the Yocto Project Application Developer's Guide. |
| 679 | |
| 680 | Downloading the Pre-Built Linux Kernel |
| 681 | -------------------------------------- |
| 682 | |
| 683 | You can download the pre-built Linux kernel suitable for running in the |
| 684 | QEMU emulator from ` <&YOCTO_QEMU_DL_URL;>`__. Be sure to use the kernel |
| 685 | that matches the architecture you want to simulate. Download areas exist |
| 686 | for the five supported machine architectures: ``qemuarm``, ``qemumips``, |
| 687 | ``qemuppc``, ``qemux86``, and ``qemux86-64``. |
| 688 | |
| 689 | Most kernel files have one of the following forms: \*zImage-qemuarch.bin |
| 690 | vmlinux-qemuarch.bin Where: arch is a string representing the target |
| 691 | architecture: x86, x86-64, ppc, mips, or arm. |
| 692 | |
| 693 | You can learn more about downloading a Yocto Project kernel in the |
| 694 | "`Yocto Project Kernel <&YOCTO_DOCS_DEV_URL;#local-kernel-files>`__" |
| 695 | bulleted item in the Yocto Project Development Manual. |
| 696 | |
| 697 | Downloading the Filesystem |
| 698 | -------------------------- |
| 699 | |
| 700 | You can also download the filesystem image suitable for your target |
| 701 | architecture from ` <&YOCTO_QEMU_DL_URL;>`__. Again, be sure to use the |
| 702 | filesystem that matches the architecture you want to simulate. |
| 703 | |
| 704 | The filesystem image has two tarball forms: ``ext3`` and ``tar``. You |
| 705 | must use the ``ext3`` form when booting an image using the QEMU |
| 706 | emulator. The ``tar`` form can be flattened out in your host development |
| 707 | system and used for build purposes with the Yocto Project. |
| 708 | core-image-profile-qemuarch.ext3 core-image-profile-qemuarch.tar.bz2 |
| 709 | Where: profile is the filesystem image's profile: lsb, lsb-dev, lsb-sdk, |
| 710 | lsb-qt3, minimal, minimal-dev, sato, sato-dev, or sato-sdk. For |
| 711 | information on these types of image profiles, see the |
| 712 | ":ref:`ref-manual/ref-images:Images`" chapter in the Yocto |
| 713 | Project Reference Manual. arch is a string representing the target |
| 714 | architecture: x86, x86-64, ppc, mips, or arm. |
| 715 | |
| 716 | Setting Up the Environment and Starting the QEMU Emulator |
| 717 | --------------------------------------------------------- |
| 718 | |
| 719 | Before you start the QEMU emulator, you need to set up the emulation |
| 720 | environment. The following command form sets up the emulation |
| 721 | environment. $ source |
| 722 | YOCTO_ADTPATH_DIR/environment-setup-arch-poky-linux-if Where: arch is a |
| 723 | string representing the target architecture: i586, x86_64, ppc603e, |
| 724 | mips, or armv5te. if is a string representing an embedded application |
| 725 | binary interface. Not all setup scripts include this string. |
| 726 | |
| 727 | Finally, this command form invokes the QEMU emulator $ runqemu qemuarch |
| 728 | kernel-image filesystem-image Where: qemuarch is a string representing |
| 729 | the target architecture: qemux86, qemux86-64, qemuppc, qemumips, or |
| 730 | qemuarm. kernel-image is the architecture-specific kernel image. |
| 731 | filesystem-image is the .ext3 filesystem image. |
| 732 | |
| 733 | Continuing with the example, the following two commands setup the |
| 734 | emulation environment and launch QEMU. This example assumes the root |
| 735 | filesystem (``.ext3`` file) and the pre-built kernel image file both |
| 736 | reside in your home directory. The kernel and filesystem are for a |
| 737 | 32-bit target architecture. $ cd $HOME $ source |
| 738 | YOCTO_ADTPATH_DIR/environment-setup-i586-poky-linux $ runqemu qemux86 |
| 739 | bzImage-qemux86.bin \\ core-image-sato-qemux86.ext3 |
| 740 | |
| 741 | The environment in which QEMU launches varies depending on the |
| 742 | filesystem image and on the target architecture. For example, if you |
| 743 | source the environment for the ARM target architecture and then boot the |
| 744 | minimal QEMU image, the emulator comes up in a new shell in command-line |
| 745 | mode. However, if you boot the SDK image, QEMU comes up with a GUI. |
| 746 | |
| 747 | .. note:: |
| 748 | |
| 749 | Booting the PPC image results in QEMU launching in the same shell in |
| 750 | command-line mode. |
| 751 | |
| 752 | .. |Using a Pre-Built Image| image:: figures/using-a-pre-built-image.png |