Difference between revisions of "Using devtool to modify recipes in Yocto"
(Created page with "== Creating Using devtool to modify recipes in Yocto == Suppose you have a requirement of customizing an existing sources for a recipe, <code>devtool</code> will be the best...") |
(→Using devtool to modify recipes in Yocto) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | == | + | == Using devtool to modify recipes in Yocto == |
− | Suppose you have a requirement of customizing an existing sources for a recipe, <code>devtool</code> will be the best option to go, as it will do all the steps required to create a patch, bbappend file etc. | + | Suppose you have a requirement of customizing an existing sources for a recipe, <code>devtool</code> will be the best option to go, as it will do all the steps required to create a patch, <code>bbappend</code> file etc. |
+ | <br /> | ||
+ | |||
+ | As part of building a recipe, Yocto/OE creates a <code>tmp/work/<architecture>/<recipe>/<version></code> directory, known as the "work directory". <br /><br /> | ||
+ | This is where all of the work done to build a recipe takes place. <br /><br /> | ||
+ | One of the things you'll find in this directory is the source, usually under a subdirectory named <code><recipename>-<version></code> or "git" (depending on how the fetched source is provided). <br /><br /> | ||
+ | The temptation (and what people used to do in the past) is to simply make changes here and then recompile, but there are several reasons why that's not a good idea: | ||
+ | |||
+ | * It's awkward - you have to use <code>bitbake -c compile -f</code> or <code>bitbake -C compile</code> to force recompilation, since the build system doesn't know that you've made any changes | ||
+ | * You can easily lose your changes if you're not careful e.g. running <code>bitbake -c clean</code> will wipe the directory out | ||
+ | |||
+ | <br /> | ||
+ | |||
+ | Luckily there's a much better method using the <code>devtool</code> command: | ||
+ | |||
+ | # Run <code>devtool modify <recipename></code>. This will fetch the sources for the recipe and unpack them to a workspace/sources/<recipename> directory and initialise it as a git repository if it isn't already one. If you prefer you can specify your own path, or if you already have your own existing source tree you can specify the path along with the -n option to use that instead of unpacking a new one. | ||
+ | # Make the changes you want to make to the source | ||
+ | # Run a build to test your changes - you can just <code>devtool build <recipename></code> or even build an entire image incorporating the changes assuming a package produced by the recipe is part of an image. There's no need to force anything - the build system will detect changes to the source and recompile as necessary. | ||
+ | # If you wish, test your changes on the target. There's a "devtool deploy-target" command which will copy the files installed at do_install over to the target machine assuming it has network access, and any dependencies are already present in the image. | ||
+ | # Repeat from step 2 as needed until you're happy with the results. | ||
+ | # At this point you will almost certainly want to place your changes in the form of a patch to be applied from the metadata - devtool provides help with this as well. Commit your changes using "git commit" (as many or as few commits as you'd like) and then run either: | ||
+ | #* <code>devtool update-recipe <recipename></code> to update the original recipe - usually appropriate if it's your own recipe or you're submitting the changes back to the upstream layer | ||
+ | #* <code>devtool update-recipe -a <layerpath> <recipename></code> to put your changes in the form of a bbappend to be applied by a different layer. This is usually the desired method if your changes are customisations rather than bugfixes. | ||
+ | # If you're finished working on the recipe, run <code>devtool reset <recipename></code>. | ||
+ | |||
+ | <br /> | ||
+ | |||
+ | This is just one of the things that devtool can do - it provides some powerful tools to help you maintain recipes and make changes to source code. | ||
+ | |||
+ | <br /> | ||
+ | |||
+ | ----- | ||
+ | |||
+ | == Using devtool to modify the linux kernel recipes in Yocto == | ||
+ | |||
+ | Modifying the kernel inside Yocto/OE | ||
+ | |||
+ | From your build directory run | ||
+ | |||
+ | devtool modify virtual/kernel | ||
+ | |||
+ | It will create a workspace directory containing the kernel sources in build directory | ||
+ | |||
+ | <br /> | ||
+ | |||
+ | Now discover the package-name (PN) of the virtual/kernel | ||
+ | |||
+ | devtool status | ||
+ | NOTE: Starting bitbake server... | ||
+ | linux-yocto: /home/tux/yocto-bbb-dunfell/poky/build/workspace/sources/linux-yocto | ||
+ | |||
+ | edit manually what you need (.c and .dts) in <code>workspace/sources/linux-yocto/</code> | ||
+ | |||
+ | devtool build linux-yocto | ||
+ | |||
+ | now you have your kernel and DeviceTree in <code>tmp/deploy/images/beaglebone-yocto/</code> | ||
+ | then deploy them on the target board and test them. | ||
+ | |||
+ | <br /> | ||
+ | |||
+ | Once you are satisfied, add this git repository to your fork.<br /> | ||
+ | This will add your patches to the original recipe | ||
+ | |||
+ | git add . | ||
+ | git commit -m "my linux modifications" | ||
+ | devtool update-recipe linux-yocto | ||
+ | |||
+ | |||
+ | == Using devtool to modify the linux kernel configuration == | ||
+ | |||
+ | '''WARNING: the <code>devtool menuconfig</code> option is valid only for recent Yocto releases like '''dunfell''' ''' | ||
+ | |||
+ | Modifying the kernel configuration may be different depending on the original conditions | ||
+ | |||
+ | Consider that when you use <code>devtool modify</code>, it will automatically run the <code>kernel_configme</code> task. | ||
+ | |||
+ | If not already done, run from your build directory | ||
+ | |||
+ | devtool modify virtual/kernel | ||
+ | |||
+ | then modify your configuration | ||
+ | |||
+ | devtool menuconfig linux-yocto | ||
+ | |||
+ | Once you are satisfied run this to generate the <code>defconfig</code> | ||
+ | |||
+ | bitbake -c savedefconfig virtual/kernel | ||
+ | |||
+ | and overwrite the <code>defconfig</code> on the previous one in the original recipe. |
Latest revision as of 16:16, 5 March 2024
Using devtool to modify recipes in Yocto
Suppose you have a requirement of customizing an existing sources for a recipe, devtool
will be the best option to go, as it will do all the steps required to create a patch, bbappend
file etc.
As part of building a recipe, Yocto/OE creates a tmp/work/<architecture>/<recipe>/<version>
directory, known as the "work directory".
This is where all of the work done to build a recipe takes place.
One of the things you'll find in this directory is the source, usually under a subdirectory named <recipename>-<version>
or "git" (depending on how the fetched source is provided).
The temptation (and what people used to do in the past) is to simply make changes here and then recompile, but there are several reasons why that's not a good idea:
- It's awkward - you have to use
bitbake -c compile -f
orbitbake -C compile
to force recompilation, since the build system doesn't know that you've made any changes - You can easily lose your changes if you're not careful e.g. running
bitbake -c clean
will wipe the directory out
Luckily there's a much better method using the devtool
command:
- Run
devtool modify <recipename>
. This will fetch the sources for the recipe and unpack them to a workspace/sources/<recipename> directory and initialise it as a git repository if it isn't already one. If you prefer you can specify your own path, or if you already have your own existing source tree you can specify the path along with the -n option to use that instead of unpacking a new one. - Make the changes you want to make to the source
- Run a build to test your changes - you can just
devtool build <recipename>
or even build an entire image incorporating the changes assuming a package produced by the recipe is part of an image. There's no need to force anything - the build system will detect changes to the source and recompile as necessary. - If you wish, test your changes on the target. There's a "devtool deploy-target" command which will copy the files installed at do_install over to the target machine assuming it has network access, and any dependencies are already present in the image.
- Repeat from step 2 as needed until you're happy with the results.
- At this point you will almost certainly want to place your changes in the form of a patch to be applied from the metadata - devtool provides help with this as well. Commit your changes using "git commit" (as many or as few commits as you'd like) and then run either:
-
devtool update-recipe <recipename>
to update the original recipe - usually appropriate if it's your own recipe or you're submitting the changes back to the upstream layer -
devtool update-recipe -a <layerpath> <recipename>
to put your changes in the form of a bbappend to be applied by a different layer. This is usually the desired method if your changes are customisations rather than bugfixes.
-
- If you're finished working on the recipe, run
devtool reset <recipename>
.
This is just one of the things that devtool can do - it provides some powerful tools to help you maintain recipes and make changes to source code.
Using devtool to modify the linux kernel recipes in Yocto
Modifying the kernel inside Yocto/OE
From your build directory run
devtool modify virtual/kernel
It will create a workspace directory containing the kernel sources in build directory
Now discover the package-name (PN) of the virtual/kernel
devtool status NOTE: Starting bitbake server... linux-yocto: /home/tux/yocto-bbb-dunfell/poky/build/workspace/sources/linux-yocto
edit manually what you need (.c and .dts) in workspace/sources/linux-yocto/
devtool build linux-yocto
now you have your kernel and DeviceTree in tmp/deploy/images/beaglebone-yocto/
then deploy them on the target board and test them.
Once you are satisfied, add this git repository to your fork.
This will add your patches to the original recipe
git add . git commit -m "my linux modifications" devtool update-recipe linux-yocto
Using devtool to modify the linux kernel configuration
WARNING: the devtool menuconfig
option is valid only for recent Yocto releases like dunfell
Modifying the kernel configuration may be different depending on the original conditions
Consider that when you use devtool modify
, it will automatically run the kernel_configme
task.
If not already done, run from your build directory
devtool modify virtual/kernel
then modify your configuration
devtool menuconfig linux-yocto
Once you are satisfied run this to generate the defconfig
bitbake -c savedefconfig virtual/kernel
and overwrite the defconfig
on the previous one in the original recipe.