Reputation: 753
I am trying to create a patch file for u-boot file and apply it to u-boot recipe in Yocto for my Avenger96 embedded board. I want to make some changes in the config file of u-boot and create a patch and add it to yocto recipe for u-boot. I am new to creating patches and would like to learn in detail.
The file which needs to be modified is in /build/tmp/work/dh_stm32mp1_dhcor_avenger96-poky-linux-gnueabi/u-boot-stm32mp1-dhsom/2021.01-r0/git/include/configs/stm32mp1.h
. In this file I need to modify somethings like enabling CONFIG_BOOTCOUNT_LIMIT
:
#define CONFIG_BOOTCOUNT_LIMIT
#define CONFIG_BOOTCOUNT_ENV
Is this the right way to enable u-boot variables?
And to add below lines to same file:
“bootlimit=5\0" \
"rootfspart=4\0" \
"bootargs=root=/dev/mmcblk0p${rootfspart} rdinit=/bin/kinit rw single\0" \
"altbootcmd=" \
" echo Rollback to previous RootFs; "
" if test ${rootfspart} = 4; " \
" then setenv rootfspart 5; " \
" else " \
" setenv rootfspart 4; " \
" fi; setenv bootcount 0; saveenv; " \
" bootcmd\0" \
And then create a patch for this and apply this to u-boot recipe which is available in /sources/meta-board-bsp/recipes-bsp/u-boot
. This recipe is cloned from git.
Now I have few questions:
Should I directly edit stm32mp1.h file and add my changes or should I copy the original file to some temp location and then add new changes to copied file and then use git diff --no-index stm32mp1.h.orig stm32mp1.h > 0001-add-altbootcmd-u-boot.patch
. Will this be sufficient to make it work?
To add the patch file I need to copy this created patch file to /sources/meta-board-bsp/recipes-bsp/u-boot/files
and include this in the SRC_URI:append:dh-stm32mp1-dhsom = " \ file://0001-add-altbootcmd-u-boot.patch \ "
of the u-boot recipe /sources/meta-board-bsp/recipes-bsp/u-boot/u-boot_%.bbappend
. Is this the right way?
Before bitbaking my image recipe do I need to apply the patch by running anything particular to that patch or whether patching will happen automatically?
Can I do the same thing from my custom layer instead of using meta-board-bsp? For example, my meta-custom layer structure is
└── recipes-bsp
└── u-boot
├── files
│ ├── 0001-add-altbootcmd-u-boot.patch
└── u-boot_%.bbappend
Will this also works?
Update
I followed the above steps and created a patch file and added it to /sources/meta-board-bsp/recipes-bsp/u-boot/u-boot_%.bbappend
under SRC_URI:append:dh-stm32mp1-dhsom = " \ file://0001-add-altbootcmd-u-boot.patch \ "
. Next I ran the image recipe and it completed without any error. But how can I check whether patch is successfully applied or not? My changes are not reflected in /build/tmp/work/dh_stm32mp1_dhcor_avenger96-poky-linux-gnueabi/u-boot-stm32mp1-dhsom/2021.01-r0/git/include/configs/stm32mp1.h
. I expected it to be updated with new changes.
Can anyone please correct me if I am wrong here and how to make this work?
Your help will be much appreciated.
Thanks in advance.
P.S: I am using Ubuntu 20.04 with Yocto Project as build system. Please let me know if there are any missing info.
Upvotes: 0
Views: 3121
Reputation: 175
I have tried it out yesterday, stm32mp1 using this repo https://github.com/STMicroelectronics/u-boot on their u-boot source code.
I cloned the u-boot repo
Create patch from this repo
git format-patch -1 -o /home/user/<your meta-layer>/ <u-bootbbapend> directory
bitake the U-boot recipe
Validation: Navigate to u-boot WORKDIR
bitbake -e u-boot | grep ^WORKDIR=
something like <Yocto directory>/stm32Yoctominimal/build-mp1/tmp/work/stm32mp1-poky-linux-gnueabi/u-boot-stm32mp/v2020.10-stm32mp-r2-r0
go to the git in the u-boot WORKDIR,check the files git/include/configs/stm32mp1.h, if the patch file apply successfully, the file should have your changes.
bitbake the image after you validate the changes take place.
Attached my POC here
In my POC, I have added a printf, when I boot my image in the board:
U-Boot 2020.10-stm32mp-r2-dirty (Oct 05 2020 - 15:15:32 +0000)
CPU: STM32MP157FAC Rev.Z
Model: STMicroelectronics STM32MP157F-DK2 Discovery Board
Board: stm32mp1 in trusted mode (st,stm32mp157f-dk2)
Stargazer OS U-boot Development Enablement
Upvotes: 1
Reputation: 89
I am surprised nobody mentioned devtool
yet. I encourage you to check these online resources and learn how to use it. It makes the process of making changes to .bb
recipes, adding patches, etc. much simpler.
Quick reference: https://wiki.koansoftware.com/index.php/Using_devtool_to_modify_recipes_in_Yocto Extended version: https://docs.yoctoproject.org/ref-manual/devtool-reference.html
The idea would be to leave the u-boot
package as it comes from upstream and apply any changes you need (u-boot variables, .c/.cpp/.h modifications) through .patch files since they are custom options for your SW layer.
Upvotes: 1