| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung |
| software:linux:yocto:recipes [2022-09-27 08:41] – Urs Graf | software:linux:yocto:recipes [2023-06-13 10:19] (aktuell) – Urs Graf |
|---|
| Another example is libraries being split into ''-dev'' (shared objects), ''-staticdev'' (static libraries), and ''-src'' (source code) packages. | Another example is libraries being split into ''-dev'' (shared objects), ''-staticdev'' (static libraries), and ''-src'' (source code) packages. |
| |
| ===== Life Cycle of a Recipe ===== | ===== Tasks ===== |
| |
| Each recipe undergoes multiple stages while being built: | Each recipe undergoes multiple stages while being built: |
| | package_qa | do_package_qa | perform sanity checks on package | | | package_qa | do_package_qa | perform sanity checks on package | |
| |
| *: it seems ''do_fetch'' and ''do_unpack'' can not be modified/overridden in a recipe. | *: it seems that ''do_fetch'' and ''do_unpack'' can not be modified/overridden in a recipe. More about overriding see below. |
| |
| Each of the listed functions is called when building the package, or can explicitly be invoked using | Each of the listed functions is called when building the package, or can explicitly be invoked using |
| ===== Anatomy of a Recipe ===== | ===== Anatomy of a Recipe ===== |
| |
| In essence, a recipe needs provide 4 things: | In essence, a recipe needs to provide 4 things: |
| |
| * where is source (code) | * where is the source (code) |
| * how to build it | * how to build it |
| * how/where to install it (in the image) | * how/where to install it (in the image) |
| Almost all recipes need some source code or other source from which to build the software. | Almost all recipes need some source code or other source from which to build the software. |
| In bitbake this step is called ''fetch''. | In bitbake this step is called ''fetch''. |
| Sources are specified by setting the ''SRC_URI'' variable and be fetched from a variety of sources. | Sources are specified by setting the ''SRC_URI'' variable and can be fetched from a variety of sources. |
| |
| For example, setting ''SRC_URI'' as shown below will fetch 2 local files ''heloworld.c'' and ''Makefile''. | For example, setting ''SRC_URI'' as shown below will fetch 2 local files ''heloworld.c'' and ''Makefile''. |
| |
| There is a variety of fetchers available for downloading files from the internet or cloning git repositories and more. | There is a variety of fetchers available for downloading files from the internet or cloning git repositories and more. |
| Each has their own requirements and options, which can be found [[ https://www.yoctoproject.org/docs/1.6/bitbake-user-manual/bitbake-user-manual.html#bb-fetchers | here ]]. | Each has their own requirements and options, which can be found [[ https://www.yoctoproject.org/docs/1.6/bitbake-user-manual/bitbake-user-manual.html#bb-fetchers | here]]. |
| |
| <code> | <code> |
| ==== Building and Installation ==== | ==== Building and Installation ==== |
| |
| Building usually constists of 2 steps: configuration and the actual build itself. | Building usually consists of 2 steps: configuration and the actual build itself. bitbake comes with classes to handle standard build systems such as ''cmake'' and ''autotools''. These can be used by inheriting from them. For cmake based projects: |
| | |
| [[ .:bitbake ]] comes with [[ .: classes ]] to handle standard build systems such as ''cmake'' and ''autotools''. | |
| These can be used by inheriting from them. For cmake based projects: | |
| |
| <code> | <code> |
| </code> | </code> |
| |
| For makefile bassed projects, see [[ https://www.yoctoproject.org/docs/latest/mega-manual/mega-manual.html#new-recipe-makefile-based-package | here]]. | For makefile based projects, see [[ https://docs.yoctoproject.org/dev-manual/new-recipe.html?highlight=makefile#building-a-makefile-based-package | Building a Makefile-Based Package]]. |
| |
| ==== Appending a Function ==== | ==== Appending a Function ==== |
| |
| Sometimes it is necessary to perform extra steps for a particular part of the life cycle. | Sometimes it is necessary to perform extra steps for a particular task. This can be achieved by appending custom commands to a function. The syntax for this is |
| This can be achieved by appending custom commands to a function. | |
| The syntax for this is | |
| |
| <code> | <code> |
| |
| ''D'' is the destination direcory, which points to the package's install directory. | ''D'' is the destination direcory, which points to the package's install directory. |
| All destination paths must be relative to it to end up in the right place to be packaged (this is unique to do_install, the other functions should not need to acces ''D''). | All destination paths must be relative to it to end up in the right place to be packaged (this is unique to do_install, the other functions should not need to access ''D''). |
| |
| ===== Creating a Recipe using devtool ===== | ===== Creating a Recipe using devtool ===== |
| |
| [[ .:devtool ]] is a command line utility that comes with [[ .: | yocto ]] that can be used to facilitate development. | [[ .:devtool ]] is a command line utility that comes with [[ .: | yocto ]] that can be used to facilitate development. |
| One of the things it can be used for is semi-automatically creating recipes; using the following command: | One of the things it can be used for is semi-automatically creating recipes using the following command: |
| |
| <code> | <code> |
| |
| Manual creation of recipes may be required when [[ .:devtool | devtool ]] fails to automatically create one. | Manual creation of recipes may be required when [[ .:devtool | devtool ]] fails to automatically create one. |
| |
| ==== <depcrecated> ==== | |
| |
| === Adding a Recipe to the Layer === | === Adding a Recipe to the Layer === |
| |
| As configured above, ''bitbake'' will look for recipes in any sub directory | ''bitbake'' will look for recipes in any sub directory of ''recipes-ost'', **but not in ''recipes-ost'' itself!** Create a folder inside ''recipes-ost'' called ''helloworld'' and inside that create a file called ''helloworld_1_0.bb'' with the following content: |
| of ''recipes-ntb'', **but not in ''recipes-ntb'' itself!** Create a folder inside ''recipes-ntb'' called ''helloworld'' and inside that create a file called ''helloworld_1_0.bb'' with the following content: | |
| |
| <code> | <code> |
| DESCRIPTION = "Example Hello World" | DESCRIPTION = "Example Hello World" |
| SECTION = "ntb" | SECTION = "ost" |
| DEPENDS = "" | DEPENDS = "" |
| |
| </code> | </code> |
| |
| ''bitbake'' is very particular about licenses to ensure no closed source software ends up in a project that only wants open source software. Hence the recipe needs to specify the license used (MIT in this case) and a checksum for the license file to ensure it has not been altered. All this is handled by the ''LIC_FILES_CHKSUM'' field. THe other two interesting fields are ''SRC_URI'' and ''SRC_REV''. ''SRC_URI'' specifies where the source for the application/module/... for this recipe is. In this case ''git:%%//%%'' lets ''bitbake'' know the source lives in a git repository. Note that ''https:%%//%%'' will not work. Also note that ''inherit autotools'' is only necessary because the hello world uses autotools. | ''bitbake'' is very particular about licenses to ensure no closed source software ends up in a project that only wants open source software. Hence the recipe needs to specify the license used (MIT in this case) and a checksum for the license file to ensure it has not been altered. All this is handled by the ''LIC_FILES_CHKSUM'' field. The other two interesting fields are ''SRC_URI'' and ''SRC_REV''. ''SRC_URI'' specifies where the source for the application/module/... for this recipe is. In this case ''git:%%//%%'' lets ''bitbake'' know the source lives in a git repository. Note that ''https:%%//%%'' will not work. Also note that ''inherit autotools'' is only necessary because the hello world uses autotools. |
| |
| To add the new recipe to the build edit ''oe-core/build/conf/local.conf'' and append ''IMAGE_INSTALL_append = " helloworld"'' (make sure to include the space before ''helloworld''). | To add the new recipe to the build edit ''oe-core/build/conf/local.conf'' and append ''IMAGE_INSTALL_append = " helloworld"'' (make sure to include the space before ''helloworld''). |
| ==== Adding a kernel module ==== | ==== Adding a kernel module ==== |
| |
| This part is an extension of the previous and assumes the ''meta-ntb'' layer exists and was added to ''bblayers.conf'' as described above. This part uses the [[ https://github.com/zechenturm/fpga_loader | fpga_loader ]] kernel module to demonstrate how to add an out-of-tree kernel module to yocto. | This part is an extension of the previous and assumes the ''meta-ost'' layer exists and was added to ''bblayers.conf'' as described above. This part uses the [[ https://github.com/zechenturm/fpga_loader | fpga_loader ]] kernel module to demonstrate how to add an out-of-tree kernel module to yocto. |
| |
| Create a new directory ''recipes-kernel'' under ''meta-ntb'' and in that create another folder inside that called ''fpga-loader''. Create a file called ''fpga-loader_1.0.bb'' in ''fpga-loader'' and add the following content: | Create a new directory ''recipes-kernel'' under ''meta-ost'' and in that create another folder inside that called ''fpga-loader''. Create a file called ''fpga-loader_1.0.bb'' in ''fpga-loader'' and add the following content: |
| <code> | <code> |
| DESCRIPTION = "FPGA Loader Kernel Module" | DESCRIPTION = "FPGA Loader Kernel Module" |
| SECTION = "ntb" | SECTION = "ost" |
| DEPENDS = "" | DEPENDS = "" |
| |