SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2011-01-27 01:34:37

iann
#! Die Hard
Registered: 2010-09-10
Posts: 708

Building the Nvidia module into the kernel

Madness I know, but I thought I'd try and compile the nVidia kernel module into the kernel itself instead of loading it at run time.  It worked!  Eventually lol

Inserting the module into the standard kernel build process is simple enough.  Place the source and the kbuild Makefile with the source tree and add an entry to it in the top level Makefile.  I put mine as nvidia/ after net/.  Then it will automatically build and install nvidia.ko whenever you make the kernel.  That's a pretty good idea so you don't have to recompile the driver every time.  Lots of the Makefile is now redundant and you can tidy it up if you like.

Building it into the kernel isn't quite so easy.  Obviously change nvidia-m to nvidia-y in the Makefile.  You can also add a Kconfig entry to configure it if you like.  It doesn't work!  There is a -DMODULE lurking in there which forces certain internal defines and the final LD will fail.  So remove that define and it will all be OK.

Now you have a kernel with the nVidia proprietary bits linked in.  Perfect!  It is surprisingly small, considering it has a 5+MB module added to it.  Must compress very well.  Just one final wrinkle.  When you try to start X, nvidia_drv.so will try to modprobe nvidia.ko and die.  You will have to tweak modprobe.conf or something in modprobe.d so that the modprobe appears to succeed.  I added "install nvidia /bin/true", but an alias to null might also work.

Just remembered something else that might bite you: agpgart should be either built in to the kernel or configured off completely.  If it is built as a module as seems to be standard, then nVidia will compile calls to it but won't find them when it is linked.  I turned AGP off completely in the kernel because nVidias internal AGP works well on my hardware.

Last edited by iann (2011-01-27 11:56:43)

Offline

Be excellent to each other!

#2 2011-01-27 06:10:23

Awebb
The Singularity
Registered: 2009-07-23
Posts: 2,812

Re: Building the Nvidia module into the kernel

Nice work. This is why we love Linux. It starts with "I wonder..." and ends with hard work.

What's the gain of this?


I'm so meta, even this acronym

Offline

#3 2011-01-27 12:01:12

iann
#! Die Hard
Registered: 2010-09-10
Posts: 708

Re: Building the Nvidia module into the kernel

Awebb wrote:

What's the gain of this?

Mostly satisfaction of a job well done smile

It knocks a little time off the boot modprobing a very big file.  On its own just a second or so, but this is something you'd probably only want to do if you were already compiling a custom kernel.  Then you would want to configure in all your standard hardware instead of modprobing dozens of modules at every boot, and you can do it with nvidia.ko also.  My kernel with every module that used to get loaded at boot linked in, plus nvidia.ko, and support for anything I don't have either turned off or pushed out to a module, is slightly smaller than the standard distro kernel.

As I mentioned, anyone with a custom kernel should probably place the nVidia source in the kernel source tree anyway, since nvidia.ko gets blown away every time you do a make.  The tweaks to then link it in to the kernel are very small.  You can do this with almost any third party module, since a module is simple an unlinked object file that gets a tiny wrapper to make it into a .ko file.  Most of them just need the "-m" in the Makefile changed to "-y", but nVidia had to be difficult smile

Last edited by iann (2011-01-27 14:02:05)

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo