UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Participant igal_kroyter
Participant
5,310 Views
Registered: ‎09-13-2016

Kernel Modules Development in Petalinux 2016.4

Hi,

 

I'm trying to develop a very simple Kernel Module on Petalinux 2016.4. I have read some article's and books on the issue and understand the basic requirement. Though I'm missing an organized scheme that dictates the way it is expected from a developer to develop a driver for Petalinux 2016.4 specifically: like where is the border line between the effort that the developer has to provide and the capabilities that the already available tools provide.

 

Just an example (a very big chance that I do not understand the big picture at this point at all): I do not understand where the insmod function flexibility that the Linux provides vs. the requirement to install the driver in the kernel image as per the UG1144.

 

I'll appreciate, if someone could elaborate on the issue or provide pointers to material that can support on the matter.

 

Thanks,

 

Igal

0 Kudos
14 Replies
Moderator
Moderator
5,304 Views
Registered: ‎12-04-2016

Re: Kernel Modules Development in Petalinux 2016.4

Hi

 

Here are the very simple steps to develop/add the kernel module in petalinux 16.4:

 

  1. In the 2016.4 petalinux project, create the template modules using the following command:
    petalinux-create -t modules -n new-module
  2. Remove the existing source code and Makefiles in the "<2016.4-petalinux-project>/project-spec/meta-user/recipe-module/new-module/new-module" directory and copy your module source code and Makefiles.
  3. Edit the "<2016.4-petalinux-project>/project-spec/meta-user/recipe-modules/new-module/new-module.bb" file as shown below:

 

a) Remove the entire contents of the file and add the following:

SUMMARY = "Example new-module module "

SECTION = "PETALINUX/modules"
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = file://COPYING;md5=12f884d2ae1ff87c09e5b7ccc2c4ca7e
SRC_URI = "file://Makefile \
           file://<MODULENAME>.c \
        "
S = "${WORKDIR}"
 

b)

inherit module
EXTRA_OEMAKE = 'KERNEL_src="${STAGING_KERNEL_DIR}" \
                O=${STAGING_KERNEL_BUILDDIR} \
                '
  1. Replace the <MODULENAME>.c in the "<2016.4-petalinux-project>/project-spec/meta-user/recipe-modules/new-module/new-module.bb" with your source file name.
  2. Edit the "<2016.4-petalinux-project>/project-spec/meta-user/recipe-modules/new-module/new-module/Makefile" file as shown below:

 

Remove the entire contents of the file and then add the following text:

obj-m += <MODULENAME>.o

all:
                make -C $(KERNEL_SRC) M=$(CURDIR)
modules_install:
                make -C $(KERNEL_SRC) M=$(CURDIR) modules_install
clean:
                make -C $(KERNEL_SRC) M=$(CURDIR) clean
 
 
 
 
Best Regards
Shabbir
Xilinx Employee
Xilinx Employee
5,298 Views
Registered: ‎08-01-2008

Re: Kernel Modules Development in Petalinux 2016.4

check this documents
https://www.xilinx.com/support/documentation/sw_manuals/xilinx2016_4/ug1144-petalinux-tools-reference-guide.pdf

refer this ARs for debugging
https://www.xilinx.com/support/answers/66853.html
Thanks and Regards
Balkrishan
--------------------------------------------------------------------------------------------
Please mark the post as an answer "Accept as solution" in case it helped resolve your query.
Give kudos in case a post in case it guided to the solution.
0 Kudos
Participant igal_kroyter
Participant
5,245 Views
Registered: ‎09-13-2016

Re: Kernel Modules Development in Petalinux 2016.4

Balkrishan and Shabbir,

 

thank you both for the reply.

 

I have tried with https://www.xilinx.com/support/answers/66853.html to enable the debugging info within Kernel but failed the petalinux-Config step(log is attached).

 

Any support will be appreciated.

 

Igal

0 Kudos
Moderator
Moderator
5,241 Views
Registered: ‎12-04-2016

Re: Kernel Modules Development in Petalinux 2016.4

Hi Igal

 

Firstly check the RAM size, it must be more than 4GB for petalinux.

Second thing, run the command: petalinux-build -x clean and  petalinux-build -x mrproper

 

After this try again?

 

 

Best Regards

Shabbir

0 Kudos
Participant igal_kroyter
Participant
5,238 Views
Registered: ‎09-13-2016

Re: Kernel Modules Development in Petalinux 2016.4

Shabbir,

the board ZCU-102 that in my possession does not have 4GB. So it means that I cannot add kernel debug info into the image.ub?
This might explain the repeating error.
OK.
So I'd like to copy the mymodule.ko to an SD card and debug it on the target board. Is it the correct approach if yes, where can I get some information on how to do it? If not, what is the correct approach?

thanks,
Igal
0 Kudos
Moderator
Moderator
5,237 Views
Registered: ‎12-04-2016

Re: Kernel Modules Development in Petalinux 2016.4

Hi Igal

 

I mean to say that, since petalinux-build itself is failing for you, the host on which you are running/creating this images must have RAM of more than 4GB.It is nothing to do with target.

 

Sorry, if i have confused you.

 

 

Regards

Shabbir

0 Kudos
Participant igal_kroyter
Participant
5,231 Views
Registered: ‎09-13-2016

Re: Kernel Modules Development in Petalinux 2016.4

Shabbir,
the station where I compile has 16GB.

So why does it continue to fail?

Igal
0 Kudos
Moderator
Moderator
5,228 Views
Registered: ‎12-04-2016

Re: Kernel Modules Development in Petalinux 2016.4

Hi igal

 

If you are having 16GB then thats fine, then just try giving the clean build once, as I suggested above.

 

 

Regards

Shabbir

0 Kudos
Participant igal_kroyter
Participant
5,226 Views
Registered: ‎09-13-2016

Re: Kernel Modules Development in Petalinux 2016.4

Shabbir,

I have tried and it fails.

If it continue to fail can you please support on the second questions regarding the approach to run kernel modules from SD?

Thanks,

Igal
0 Kudos
Participant igal_kroyter
Participant
3,428 Views
Registered: ‎09-13-2016

Re: Kernel Modules Development in Petalinux 2016.4

Shabbir,

 

I understood that in order to run a module I need to install the module into the rootfs.

Though I have faced a few issues:

 

I tried your proposal to prepare a general Makefile and use the *.bb file as the one that summarizes all files (*.c, *.h) in the module. Was that the intention? because when I compile It fails (a log is attached).

It looks like the source files are copied to another directory and compiled there but it is missing files which are in my original directory: /opt/pkg/petalinux/xilinx-zcu102-zu9-es2-rev1.0-2016.4/project-spec/meta-user/recipes-modules/mcdgmodule/mcdgmodule

Temporally, I am using the attached Makefile which is slightly different from your proposal (the file is attached).

 

when I try to compile:

petalinux-build -c rootfs/mcdgmodule it fails and propose to compile petalinux-build -c mymodule which starts the compilation. Why?

 

The compilation takes ~5 minutes every time. Is there a way to a build and not a rebuild?

 

 

Then I noticed that although I compile the module a new image.ub is not generated unless I run petalinux-build which also takes ~10minutes. Is there a way to shorten it?

 

Thanks,

 

Igal

0 Kudos
Participant igal_kroyter
Participant
3,406 Views
Registered: ‎09-13-2016

Re: Kernel Modules Development in Petalinux 2016.4

@shabbirk, hi,

 

could you please reply on my previous post?

 

Thanks,

 

Igal

0 Kudos
Moderator
Moderator
3,392 Views
Registered: ‎12-04-2016

Re: Kernel Modules Development in Petalinux 2016.4

Hi Igal

 

Sorry for late reply. And in petalinux we have a standard way to create modules. PFA petalinux user (Refer:Adding Custom Modules), you can get this.

 

And, petalinux-build -c rootfs/mcdgmodule it fails and propose to compile petalinux-build -c mymodule which starts the compilation. Why?

Yes this is know issue with petalinux 2016.4, you should compile using petalinux-build -c <module_name>, I will check this and update you

 

For the third question, you will find answer in the attached guide itself (Refer: Building User Applications)

 

On Petalinux 2016.4, you can speed up execution by going to petalinux-config--->yocto settings ---> You can see num of threads for parallel compilation, there you can put the 4 or 8 depending on the cores

0 Kudos
Moderator
Moderator
3,391 Views
Registered: ‎12-04-2016

Re: Kernel Modules Development in Petalinux 2016.4

Sorry Please find attached user guide

0 Kudos
Participant igal_kroyter
Participant
3,358 Views
Registered: ‎09-13-2016

Re: Kernel Modules Development in Petalinux 2016.4

@shabbirk, hi,

Q1) I understand that there is a standard way but it does not work on my side. I need to add custom files which are not found. An y suggestions?
Q2) thanks.
Q3) You have directed my to User Application while I am trying to reduce compilation of the whole image.ub with a new User Module. Does it utilize the same procedure (commands)?
Q4) Thanks, it has decreased the compilations time.

Thanks,

Igal
0 Kudos