PDA

View Full Version : Custom Kernel Questions



Quasar8000
15th November 2008, 06:37 PM
I'm trying to build a custom kernel for Fedora. I followed the guide at http://fedoraproject.org/wiki/Docs/CustomKernel and everything went without problems, but there are a couple of issues that are still unclear to me:

1. How do I add extra driver modules to the kernel? Every guide I read suggests using "make install_modules", but I'm not sure what this does. I want to make a kernel and be able to distribute it, not just have it working on my box.
2. I have the driver module I need both in source and compiled, but where do I copy it next to be able to integrate it in the kernel? And how can I modify the config file to reflect that new driver?
3. Can I compile a kernel that's not the same version as the one installed on my system? For instance, can I compile a kernel for F10 on an F9 box?

I guess those are the questions I can think of for the time being, any insight on them would be highly appreciated :-)

Quasar8000
15th November 2008, 10:15 PM
I just found a small how-to (http://www.informit.com/articles/article.aspx?p=29445&seqNum=6) which explains how to add a driver to the kernel. But I still have a problem because the driver I have is bigger than a .c and .h file. I was thinking of using the driver's own Makefile, but I have no idea how to integrate it in the kernel compiler, or maybe there's a way to copy the .o or .ko files and use them without having to recompile the driver again.

jcliburn
16th November 2008, 06:39 PM
You'd be better off just using the vendor makefile, because the method you envision will require you to modify the kernel kconfig and makefile(s) with each new kernel update you download anyway. Drivers must be rebuilt with each new kernel you install.

Answers to your specific questions:

1. To add a driver to your kernel, you have to get kernel source either from kernel.org or from the Fedora kernel source rpms. Generally, the steps for building a kernel from kernel.org are:

make
make modules_install
make install

This builds the kernel, installs modules in the proper directory, and installs the kernel binary in the right place (usually in /boot).

2. If your driver module is prebuilt against your running kernel, you can copy the module to /lib/modules/`uname -r`/drivers/somedir, where somedir is the proper subtree (like 'net', for example, if your driver is a network device driver). You'll need to run depmod -a to resolve module dependencies if you do it this way.

3. Yes, you can run alternate kernels on your Fedora system. [Edit: Removed reference to possible incompatibility between kernel and system libraries.]

stevea
16th November 2008, 07:40 PM
You'd be better off just using the vendor makefile, because the method you envision will require you to modify the kernel kconfig and makefile(s) with each new kernel update you download anyway.

*SOME* vendor drivers are setup to just drop into the source tree, but that's not usually the case. Otherwise I agree. You don't need a kconfig unless you want options for the driver. If the vendor makefiloe includes a "obj-m += ..." there is an excellent chance you can just drop that dir under linux-2.6.*/drivers and live happy.


2. If your driver module is prebuilt against your running kernel, you can copy the module to /lib/modules/`uname -r`/drivers/somedir, where somedir is the proper subtree (like 'net', for example, if your driver is a network device driver). You'll need to run depmod -a to resolve module dependencies if you do it this way.

No - as a convention non-kernel drivers should go into /lib/modules/`uname -r`/extra .
That's the entire reason the extra directory exists.

If you need to build for some other installed distro (not the currently running kernel)
The modify the makefile appropriately to use:

obj-m += drivername.o

all:
make -C /lib/modules/other-rev-of-kernel/build M=$(PWD) modules

or you can point the -C to the source tree (well really yhr binary result) dir.



3. Yes, in most cases you can run alternate kernels on your Fedora system. Sometimes that doesn't work, however, because system libraries (like glib) are incompatible with the new kernel.

Oh PULLEEZE - if you don't know why make things up and mislead ppl ?. The kernel doesn't know anything about the "system libraries". The ONLY interface to the kernel is via the glibc/sbrk and that has been forward&backward compatibly since at least 2003. You can run any 2.6 kernel and most 2.4 kernels with the current libraries. Yes newer features are not supported on on older kernels (duh!), but you just get an appropriate error return. This is NOT "incompatibility".

Quasar8000
16th November 2008, 07:40 PM
Thank you for the info. So once I do the "make modules_install", are the modules inserted in the kernel RPM which I can move to another system? If yes, how do I decide where these modules are inserted in that kernel? And I think you misunderstood my last question, I don't want to run the F10 kernel on F9, I just want to compile it there because F9 is on a faster box, then I'll move it to back to F10. Would that cause any problems?

stevea
16th November 2008, 08:03 PM
make modules_install just creates the .ko file in the kernel and creates the /lib/modules/2.6.... directory containing these (and a few links. The various "make" commands discussed have to do with kernel & module build and install and has nothing to do with RPM files.

Now you are veering outside of my domain of expertise; rpmbuild and the various rpm script & config files are involved in building an rpm.

The only thing you NEED for an install is the "/boot/vmlinuz..." kernel and the /lib/modules/... directory tree.
Ideally you'd include the /boot/config* and the /boot/System.map.

You must build a new /boot/initrd... (see mkinitrd) after the install.
The kernel rpm install runs mkinit which also also updates the grub.conf

Quasar8000
16th November 2008, 08:07 PM
Well, I guess I have a good deal of reading to do :-) Thank you for the help again.

jcliburn
16th November 2008, 08:12 PM
Oh PULLEEZE - if you don't know why make things up and mislead ppl ?

Wow. Good thing you're here to keep us all straight. Thanks.

(Sorry for leaving the "c" off glibc, Quasar.)

stevea
16th November 2008, 09:17 PM
Wow. Good thing you're here to keep us all straight. Thanks.

(Sorry for leaving the "c" off glibc, Quasar.)

YOOHOO you missed the big picture.

THERE IS NO KERNEL/"system libraries" COMPATIBILITY ISSUE, AS YOU CLAIMED !

It's not the spelling that's the problem -- it's that you don't understand the kernel/glibc interface and you told a big fat fib about it which can easily mislead.

Most ppl really don't understand how extremely orthogonal the kernel/userspace design is w/ Linux/Unix. OBVIOUSLY YOU DON'T, so you shouldn't run around misinforming ppl. The fact that you made sweeping statements abt kernel/"system libraries" (plural) interaction make it clear that you not well informed (that's my kinder-gentler term for it).

So STOP spreading baloney !!! There is one library that interfaces to the kernel and no one is likely to build a kernel that won't interface to the current glibc. Read some source or pick up a copy of Yaghmour.

stevea
16th November 2008, 09:33 PM
BTW since you don't understand the unique relation between glibc and the kernel, then you obviously don't understand the importance of this *L*GPL code. So you are missing major clues as to how software reality works.

jcliburn
16th November 2008, 11:24 PM
Well, I guess I have a good deal of reading to do :-) Thank you for the help again.

You may have already come across this link, but in case you haven't...

http://fedoraproject.org/wiki/Docs/CustomKernel

jcliburn
17th November 2008, 03:38 PM
No - as a convention non-kernel drivers should go into /lib/modules/`uname -r`/extra. That's the entire reason the extra directory exists.

That appears to be a distro-added directory, right?

I run kernels pulled from git repositories, and that directory doesn't exist in my module trees, but I do see it in the module tree of the only F9-released kernel installed on my system.

As far as where vendors write their driver modules, the only vendor with whom I've worked closely was a network device manufacturer, and his out-of-tree driver makefile wrote the module directly to /lib/modules/`uname -r`/kernel/drivers/net.[1] If the /lib/modules/.../extra directory is distro-added, then a vendor can't rely on its presence, since the user might not be using a distro-released kernel.

Thanks for pointing it though. I didn't know it existed, because I don't usually run distro-released kernels.

[1] On a related note, I modified and submitted that driver for inclusion in the mainline kernel and have been the kernel maintainer of it for two years now.

Quasar8000
23rd November 2008, 02:12 PM
Ok, I tried compiling a few kernels and I think I have a better understanding of how things work now, but I faced a strange problem: I was trying to add a couple of drivers to the kernel so I got the source codes, put them in a new folder, added a Kconfig and adjusted the Makefiles, and linked them to the parent directory's Kconfig just like the other drivers. After executing "make oldconfig" and "make menuconfig", I could see the new drivers in the menu. But then, when I try to build the kernel, the new folder and included drivers just disappear, I don't get any errors, but I don't get the drivers either. I'm assuming it's not a Makefile error since that would give me a compile error. Any ideas on why any new folders I add seem to get deleted without being compiled?