Help to integrate a custom kernel into a Torizon Core Image

I want to integrate a custom kernel into a Torizon Core Image.
There are the following notes on this:
Deploying the Kernel to an Image
I need help on the first two points.
Without concrete examples, I can’t imagine how this works.
I want to make slight adjustments in the kernel in the torizon-core-docker-apalis-imx8-Tezi_5.7.2+build.20

Best regards
Gerald

Greeting @gerko,

May I ask what kind of modifications/customizations you are doing on the kernel?

It is possible to customize some kernel arguments on the TorizonCore image using our TorizonCore Builder tool.

You will find on the documentation of the TorizonCore Builder tool how to do that:

It is possible to configure aspects of the Linux Kernel of TorizonCore and it’s modules by setting certain custom boot-time arguments (parameters). Learn how to customize kernel arguments on the Kernel Arguments section.

Please let me know if that helps.

Hi @rudhi.tx ,

thank you.
Adding the kernel arguments is then the 2nd step. I know that this is possible and how to achieve it.

The change I want to make is a little deeper in the kernel. I have several reasons for asking this question.

Don’t you have an answer to the question I asked?

Best regards,
gerald

Hello @gerko,

Thanks for your reply.

The change I want to make is a little deeper in the kernel.

In this case, you will need to build TorizonCore from source with Yocto and then customize the kernel. These linked articles should help you with how to do that. Please let me know if that helped.

Hello @rudhi.tx ,

If I follow your hint, I’ll end up here again:

Best regards
Gerald

Hello @gerko,

If I understand you correctly, you could successfully build the custom kernel and now you are struggling with how to deploy it on the target.

After you have built the image with the custom kernel, you should be having a tar file of the image in Toradex Easy Installer format in the output directory. There are multiple ways by which you can deploy this image as they are explained here: Detailed Manual | Toradex Developer Center

Since you are on TorizonCore, you will also benefit from the possibility to deploy the image using our Torizon Core Builder tool. Here is how you would do that using the deploy command: TorizonCore Builder Tool - Commands Manual | Toradex Developer Center.

thats correct.

I did that following this guide: Kernel Compilation

I don’t have a tar file or I don’t know where I can find it.

OK

… have found the result image here workdir … arch/arm64/boot/Image.gz

arch/arm64/boot
├── dts
├── Image
├── Image.gz
├── install.sh
└── Makefile

Hi @rudhi.tx ,

I think I’ve found a way.
I got confused with the manpages and their versions.

Over the past few weeks I’ve jumped back from version 6 to the 5 LTS version.

The solution to my problem should be found here:
Deploy the Kernel

I’ll let you know if I’m successful

… later:

I have to apologize but my Linux knowledge and skills are at the end here.
I can’t get the sample commands customized for the image I want to use.

I have a bad suspicion that I can only update bare Linux Minimal Images this way.
However, my question was… into a Torizon Core Image

Hello @gerko,

The file structure of TorizonCore image is a bit different (since it uses OSTree) from that of our reference BSP images. On the BSP, the kernel binary and device tree(s) are part of the bootfs.tar.xz archive. So you simply need to replace them in the archive (just like in the article that you already found).

This is why we recommend building the image following this article. The advantage of this method is that you will get the image in Toradex Easy Installer format in the output directory - which you can deploy using multiple methods.

In your case since you need to add a custom kernel module, this section would be the most relevant to you. In summary, you will create a custom layer and a recipe to build your custom kernel module. After that, you will build the torizoncore image using the command bitbake torizon-core-docker.

Hi @rudhi.tx ,

I don’t want to create a new kernel module. I just want to change 2 values in an existing module that is being used by another module.
As far as I know, Torizon Core Images are created with Yocto as well as the BSP’s.
Where can I find instructions on how to replace the kernel in a TC image to try exactly these 2 changes in a custom Torizon Core Image?

Hello @gerko,

Thanks for the clarification.
In this case, you should be following the steps described in this article: Building External Kernel Modules With Torizon | Toradex Developer Center

Hello @gerko,

Hope you are doing well.
May I know if you have any updates on this topic?

Hello @rudhi.tx ,

No, your answer is not a solution.
I can only repeat my post:

and:

But I can now ask my question more precisely:
How do I swap the kernel in a TorizonCoreImage?

Best Regards
Gearld

Hello @gerko,

As I already described in my previous reply, the recommended way to replace/swap the kernel on TorizonCore image is to reinstall the new image (the custom image you built with the kernel modifications included) itself. You are following the documentation for our BSP images. In my previous answers, I have added the references to how to build your custom TorizonCore image either by using TorizonCore Builder tool or by building it from Yocto. The right method you should follow depends on what type of modifications/customizations you are trying to make. This is why I would like to know what exact modifications are you trying to make with the kernel module.

I don’t want to create a new kernel module. I just want to change 2 values in an existing module that is being used by another module.

Could you please elaborate a bit more on that? How exactly are you doing that? Please list down your step-by-step procedure.

If you find it difficult to describe, I would like to propose a call with you where we can discuss this in detail. Please let me know if you would be interested to do that.

Hello @rudhi.tx ,

OK. Here is a concrete example:

I want to make changes to the following source files:

change:

#define MAX_RPMSG_NUM_BUFS	(512)
#define MAX_RPMSG_BUF_SIZE	(512)

to

#define MAX_RPMSG_NUM_BUFS	(512/16)    // 32
#define MAX_RPMSG_BUF_SIZE	(512*16)    // 8192

(This should ensure that my data packet, which is guaranteed to be larger than 4096 bytes and smaller than 8192, is NOT fragmented.
A data packet that comes in via the serial interface should be forwarded packed in ASN1 via RPMSG)

I made these changes and:

I built an image according to: ‘Build TorizonCore from Source With Yocto Project/OpenEmbedded | Toradex Developer Center’.

Please also read this post:

Best
Gerald

Hello @gerko,

Thanks for the clarification.

From this answer in your other post, I can see that you’ve been successful in editing the kernel driver source and recompiling the kernel. After you compiled the kernel, if I understand you correctly, you built a reference Linux image in Toradex Easy Installer format. If that’s the case, I must say that you are mixing up the workflow of building reference Linux images with that of TorizonCore images.

What you need to do is the following:
You need to modify an in-tree kernel module and build a custom TorizonCore image with it. In this case, you will have to go with the Yocto workflow. That would be the cleanest way. As I have already mentioned before, you could follow this documentation on how to customize your kernel. As a pre-requisite, you need to build a TorizonCore image from Yocto and then add a custom layer and recipe to add your modifications on top of that. Then you will have to bitbake your custom TorizonCore image which will include the kernel modifications you added.

Modifying an in-tree kernel module is not really a supported use case of TorizonCore Builder. If you want to add an external kernel module or customize some kernel arguments you could do those with the TorizonCore Builder tool. Unfortunately, that’s not what you want to do here.

Hi @rudhi.tx

Sorry for the delay.

That sounds good and doable.
I will try.

Hi @rudhi.tx

lets start again

very simply described:

what is the right thing to do in my case (just changing 2 lines of code )?
Once again:
I don’t want to add any kernel module, no helloWorld program, no devicetree.

Hello @gerko,

Thanks again for the clarification. We are discussing this internally and we will get back to you with more details as soon as possible.