07-02-2019 07:14 AM
I'm trying to compile an external kernel module to be used in a petalinux 2018.2 zynq7000 project. Therefore, I need the kernel source files to compile against. I added
RM_WORK_EXCLUDE += "linux-xlnx"
to project-spec/meta-user/conf/petalinuxbsp.conf. After doing so and rebuilding my petalinux project, my kernel source files are stored in build/tmp/work-shared/plnx-zynq7/kernel-source. However, a lot of header files are still missing here. For example, the folder build/tmp/work-shared/plnx-zynq7/kernel-source/arch/arm/include/generated does not exist. How can I tell petalinux/yocto to generate these ARM header files?
07-03-2019 05:20 PM
I think we're at basically exactly the same point, but I may have just gotten somewhere that will help you... (Litterally found your post yesterday when I ran into the same missing file!)
First, I figured out how to get petalinux to build the kernel header files, more on that below, although I don't know it's actually what *you* want. I needed them built into the distrobution it self, so I can use a pre-compiled ubuntu for my rootfs and more easilly be able to install ROS that way (a package with a lot of dependencies I need and am not sure how else to include yet in petalinux). BUT... If you don't need a specific pre-built distro, or want to figure out how to copy the files (and anything it may be linking) to your own rootfs: you can build a rootfs right in petalinux that contains the headers everyone seems to point to when you dig into building your own modules (under, for instance: /lib/modules/4.14.0-xilinx-v2018.3/ ) -- You'd then still have to include the nessisary tools in PetaLinux to have your build system on board (haven't figured that out yet my self) but, you'd have the kernel headers... presumably all of them... and be able to do as you will with them.
To do that option: First, from the info here, you need to add:
IMAGE_INSTALL_append = "kernel-devsrc"
to petalinux-image.bbappend <plnx-proj-root>/project-spec/meta-user/recipes-core/images/
petalinux-config -c rootfs
and select : user packages >> kernel-devsrc
In my case, I didn't run into the error @gicgatv mentioned (must have been fixed?) but, I did have to add python as well for it to build properly.
So, before you leave the config, enable python here: Filesystem Packages >> devel >> python >> python
exit the config, and run
That'll generate a much larger image, but, looks like it *should* be able to then build modules.
Better way (don't need any of that for this!)
petalinux includes a tool to create a module more automatically, and doesn't require you knowing where the linux kernel headers are (magic under the hood I haven't gotten yet)
Thats described in *some* detail under "Building User Modules" in the UG1144 pdf document (google it)... That section seems to have moved arround in differnt versions of the doc, so, find the one for you're petalinux version and just search that section title.
But, in your project, you can add a new module with:
petalinux-create -t modules --name <Your Module Name> --enable
Just fill in your module name (what ever lower case string you want)
It'll then give you a directory, and you can cd there, and inside is a README that's actually pretty good, along with ./files/ which has a working example and Makefile.... Unfortunatly it's using a variable that seems to get set within petalinux durring it's build process, so... still not sure where the kernal source is ACTUALLY comming from if you still need it (other than what you posted, which is obviously missing some stuff)
But you can then build the whole thing with petalinux-build... or just the module (see the readme!)
If you do a full build, the module then appears inside the /images/linux/rootfs.tar.gz file generated in your project, under /lib/modules/*xilinx*/extra
But ug1144 explains where it is if you just want to build the module (in my case, and by defult): <PetaLinux Project>/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/<Your module name>/1.0-r0/deploy-rpms/plnx_zynq7/
In there you'll find some rpm's that contain the built module by it self.
I was then able to pull that and insmod it into my working board.
Hope that helps you or someone! -- This is like the one thing with all of the "flows" I've seen thats not well tutorial'd. -- Documented, sure... if you can find it, but, "no step by step for you! :P". So... Anything more people can leave behind! :)
07-06-2019 01:05 AM
Thank you very much for the lengthy and thorough reply. It indeed got me further. What I want to do is build kernel modules outside the Petalinux 'magic' way, because my source files are outside the petalinux project and I want to build them there. I'm not interested in compiling the kernel modules on the petalinux system itself. A typical makefile to do this would contain something like this:
$(MAKE) -C $(KERNELDIR)/kernel-source M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
Where you tell it where your kernel sources are. I located these sources in my petalinux project, but didnt got this to work at first, so I started to see what petalinux does when you tell it to build a kernel module and from there I figured out the following procedure to make this work. Firts I build a kernel module using the petalinux way, described in UG1144. I just created one from their standard template and build it without any changes. It is not nescecary to enable it. Building it downloads/creates the correct environment for the kernel module build process. After that I manually edited my own external makefile to look like this:
$(MAKE) -C $(KERNELDIR)/kernel-source O=$(KERNELDIR)/kernel-build-artifacts M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
To be honest, I couldn't find what the O= parameter does, but the kernel modules are building fine now. Hope this helps!