Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Nächste Überarbeitung
Vorhergehende Überarbeitung
software:linux:yocto:sdk [2020-03-25 13:30] – angelegt mlammerichsoftware:linux:yocto:sdk [2023-11-16 16:16] (aktuell) Urs Graf
Zeile 1: Zeile 1:
-====== SDK'======+====== SDK ======
  
-===== Build Natively =====+===== Cross Development SDK =====
  
-This is the simplest but also least useful way to build packages for yocto+The most common way is to cross compile rather than compiling natively
-By default, ther e is no toolchain installed in the image.+Yocto provides an SDK package that can be built for an image to match possible dependencies in the image.
  
-To add the toolchain to an image, append ''tools-sdk'' to ''CORE_IMAGE_INSTALL''.+==== Building the SDK ==== 
 +run this command to generate a cross development SDK:
  
 <code> <code>
-CORE_IMAGE_INSTALL_append  = " tools-sdk"+bitbake <image name> -c populate_sdk 
 +# for example: 
 +bitbake ost-image -c populate_sdk
 </code> </code>
  
-Note that this will significantly increase image size and build time.+This will generate a toolchain with a sysroot containing all header/libraries/... included in the image
 +By default the SDK is in ''build/tmp/deploy/sdk/''.
  
-===== Cross Development SDK =====+=== Changing the SDK HOST CPU Architecture ===
  
-run this command to generate a cross development SDK:+By default, the SDK is built for ''x86_64'' host machines. That means you can use the SDK on x86_64 computers to build software for the target. If you want to use the SDK on another system such as the ARM based Apple Macbooks, the SDK host architecture needs to be specified accordingly. This is achieved through the ''SDKMACHINE'' variable. 
 +To build the SDK for a 64bit ARM host (e.g. ARM based Apple computers), add the following to ''local.conf'': 
 +<code> 
 +SDKMACHINE = "aarch64" 
 +</code> 
 + 
 +==== Installing the SDK ==== 
 +The sdk can be built as described above or can be fetched from [[software:linux:images:start|Linux Images]]. It does do not need to be extracted any further. Building the SDK will generate a few files. The most important one being a ''.sh'' script that is used to install the SDK. 
 +For example, building the SDK yields:
  
 <code> <code>
-bitbake <image name> -c poulate_sdk +poky-glibc-x86_64-ost-image-dev-armv7at2hf-neon-bblue-toolchain-3.0.2.host.manifest 
-# for example: +poky-glibc-x86_64-ost-image-dev-armv7at2hf-neon-bblue-toolchain-3.0.2.sh 
-bitbake ntb-prod-image -c pouplate_sdk+poky-glibc-x86_64-ost-image-dev-armv7at2hf-neon-bblue-toolchain-3.0.2.target.manifest 
 +poky-glibc-x86_64-ost-image-dev-armv7at2hf-neon-bblue-toolchain-3.0.2.testdata.json
 </code> </code>
  
-This will generate a toolchain with a sysroot containing all header/libraries/... included in the image+Note that the file names include information about the image and hardware it was built for. 
-By default the SDK is in ''build/tmp/deploy/sdk/''.+ 
 +Installing the SDK is as simple as executing the shell script (e.g. ''poky-glibc-x86_64-ntb-dev-image-armv7at2hf-neon-bblue-toolchain-3.0.2.sh'') and following the instructions. 
 +An example installation is shown below. 
 + 
 +<code> 
 +./tmp/deploy/sdk/poky-glibc-x86_64-ost-image-dev-armv7at2hf-neon-bblue-toolchain-3.0.2.sh 
 +Poky (Yocto Project Reference Distro) SDK installer version 3.0.2 
 +================================================================= 
 +Enter target directory for SDK (default: /opt/poky/3.0.2): 
 +You are about to install the SDK to "/opt/poky/3.0.2". Proceed [Y/n]? y 
 +Extracting SDK.......................................................................................done 
 +Setting it up...done 
 +SDK has been successfully set up and is ready to be used. 
 +Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g
 + $ . /opt/poky/3.0.2/environment-setup-armv7at2hf-neon-poky-linux-gnueabi 
 + 
 +</code> 
 + 
 +There are two things of note:  
 +The script will ask for a location to install the SDK to in case you do not want to install it to its default location. 
 +Also the last line of output will tell you what script needs to be sourced in order to use the SDK (see below). 
 + 
 +==== Using the SDK ==== 
 + 
 +The SDK includes a script that needs to be sourced in order to use the SDK. 
 +This, among other things, sets up the standard environment variables (such as ''CC'', ''LD'' and ''CFLAGS''). 
 + 
 +The script is located in the SDK install directory and the install script tells you where to find it. 
 + 
 +For the example above, the command is: 
 + 
 +<code> 
 +. /opt/poky/3.0.2/environment-setup-armv7at2hf-neon-poky-linux-gnueabi 
 +</code> 
 + 
 +Note the space between ''.'' and the path. 
 +The script needs to be sourced rather than executed. 
 +Now running any standard build system (eg ''make'') should pick up the cross compile settings and automatically build for the target platform. 
 + 
 + 
 +==== Developing Kernel Modules ==== 
 + 
 +When using [[meta-ost]], the SDK contains the kernel dev sources by default. 
 +However, properly compiling an out of tree module requires some additional steps: 
 + 
 +<code> 
 +. path/to/sdk/environment-setup-aarch64-linux-<arch> 
 +pushd path/to/sdk/sysroot/<arch>/usr/src/kernel 
 +make scripts 
 +make prepare 
 +</code> 
 + 
 +Source: {{ https://stackoverflow.com/questions/60923890/how-to-build-linux-kernel-module-using-yocto-sdk}} 
 + 
 +Note that depending on the location of the installed SDK, ''make scripts'' may encounter permission errors. 
 +This has been observed when installing the SDK in ''/opt''
 +The easiest way to work around this is installing the SDK in a location under the current user's home directory.
  
 === Additional Information === === Additional Information ===
  
 [[ https://www.youtube.com/watch?v=u1rzYRz83kc&t=3119s | Live Coding with Yocto Project #4: SDKs ]] [[ https://www.youtube.com/watch?v=u1rzYRz83kc&t=3119s | Live Coding with Yocto Project #4: SDKs ]]