How do I compile a module?


Results 1 to 8 of 8

Thread: How do I compile a module?

  1. #1
    Join Date
    May 2006
    Posts
    4

    How do I compile a module?

    Hi all, my first post here...

    I'm trying to compile the usb-serial module, but getting lots of errors. Specifically, I'm running 2.6.13-15-default on Suse 10, and downloaded the source code for 2.6.13 from www.kernel.org. Files/dir-tree was extracted to /usr/src/. From there, if I compile the usb-serial.c module without changing anything, I get a long list of errors that starts by telling me there are missing header files such as autoconf.h and linkage.h, so I guess these are responsible for many of the other errors. I've searched the filesystem, and these files do not exist. Is there something else I need to get other than the kernel source files? Or any other clues that could indicate what else is wrong?

    BTW, I am trying to do this, and following the compilation instructions here .

    Thanks,
    -Neil.

  2. #2
    Join Date
    May 2003
    Location
    New Jersey
    Posts
    1,258
    Well, first thing to keep in mind is this:
    WARNING

    THIS PATCH HAS ONLY BEEN TESTED ON KERNEL 2.4.20.

    In theory it should work with any 2.4.x kernel. The change is small enough that it should be easily ported to the 2.6 kernel series.
    That's from the website you are using above. Just be sure that it may not work with your kernel in that case.

    Aside from that, from what you describe, you're probably missing a lot of the development software from your SuSE installation. What you need to do is install a lot of the software development tools for SuSE (autoconfig for example) and then try again. Also, you should try and give us more detailed information about what's going wrong (exact error messages straight from the terminal and such).

    If you can get back to us with some more particular information, I'm sure we can help you out more.
    The Swain

    dswain

  3. #3
    Join Date
    May 2006
    Posts
    4
    Let's go a different route... last night I found a directory under my Suse installation called usr/src/packages/SOURCES. In there was a readme about building the kernel, and it said something about modules being built as well. After some reading, I untarred the sources in there (which should be the exact version I need since it came with the installation), then did ...
    > make oldconfig
    > make

    Hours later, it was done, and there was a file called 'vmlinux' (which I assume is the kernel), and along with a bunch of other new files, there was a new "usbserial.ko", which should be the module. So I copied that (just the usbserial module, not the kernel) into /lib/modules/2.6.13-15-default/kernel/drivers/usb/serial/ to replace the original one in there. Now though, it won't install the module (using 'modprobe'). I get...

    FATAL: Error inserting usbserial (/lib/modules/2.6.13-15-default/kernel/drivers/usb/serial/usbserial.ko): Invalid module format

    So the 'make' commands apparently know what/where all the missing header files are, so that is no longer an issue. But I'm not sure how to get around the invalid format error now.

    Thanks,
    -Neil.

  4. #4
    Join Date
    May 2003
    Location
    New Jersey
    Posts
    1,258
    When you do the make commands for building the new kernel, you need to do a few other things. What you did was rebuild the actual kernel, so you need to make sure you build the modules also. Try this:

    Code:
    make
    make modules
    make modules_install
    This may help make it work.
    The Swain

    dswain

  5. #5
    Join Date
    May 2006
    Posts
    4
    I'll try the 'make modules', but can I skip the 'make modules_install' and manually place that file under /lib/modules/..... ? Reason is that I can backup that one usbserial module just in case, and won't have to mess with the rest of the modules, for fear of breaking something else. Or does 'make modules_install' do anything fancy?

  6. #6
    Join Date
    Apr 2001
    Location
    SF Bay Area, CA
    Posts
    14,947
    modules_install will remove all your current modules, so do not use it! Just backup and replace your current usbserial.ko file.

    Also, with 2.6 kernels, "make modules" is no longer necessary either. All you have to do is "make *config" (config, oldconfig, menuconfig, xconfig, or gconfig, depending on how you like to configure your kernel -- this creates many of the headers that you said were missing before; make SURE you use the EXACT same configuration as your current kernel if you plan on only replacing one module!), then "make", then "make modules_install", then copy bzImage to whatever you want to call the kernel. That's for a full kernel compile-and-install; to just replace a module, you only need to make *config and make, then copy the module's .ko file.

    But then you have to make sure to run /sbin/depmod -ae to make sure the dependency information is up to date. (That's the last thing that modules_install does.)

  7. #7
    Join Date
    May 2006
    Posts
    4
    Quote Originally Posted by bwkaz
    ... make SURE you use the EXACT same configuration as your current kernel if you plan on only replacing one module!), ...
    How do I know exactly what that configuration is? I'm using whatever configuration came with the Suse 10 installation, and have not changed it otherwise. But where is that specified? Perhaps in a file somewhere? When I built this last night, I used " make oldconfig" since the readme indicated something to this effect, but is this exactly the existing config?

    ... to just replace a module, you only need to make *config and make, then copy the module's .ko file.
    Right, that's exactly what I did yesterday, when I got the invalid format error.

    But then you have to make sure to run /sbin/depmod -ae to make sure the dependency information is up to date. (That's the last thing that modules_install does.)
    Okay, I'll look into this. For my own sanity, would doing this by itself (without changing the kernel or any other modules) cause any harm to the existing installation? I'm asking so I know I have a way to put things back to the existing state in case of problems.

    Thanks,
    -Neil.

  8. #8
    Join Date
    Apr 2001
    Location
    SF Bay Area, CA
    Posts
    14,947
    Quote Originally Posted by Linux Dude
    How do I know exactly what that configuration is?
    If your distro is smart, it's in /proc/config or /proc/config.gz.

    If your distro isn't smart, then there may be a config-<version> in /boot somewhere, but there's nothing forcing that to be the same as your running kernel's configuration. It is convention, but it's not forced like /proc/config and /proc/config.gz are. (The config files under /proc are put there by the kernel itself, and the kernel knows how it was configured.)

    But where is that specified?
    At SuSE. When they built the kernel, the process generated a file named .config that they should be including in their kernel-source packages. When you run make <whatever>config, it'll load the current configuration from the .config file in the root of the kernel tree. So if you're building SuSE's kernel source package, and they put the configuration in that package, then it should be picked up.

    The kernel itself also has an option to expose its configuration in /proc; that's where /proc/config and /proc/config.gz come from.

    Most distros also copy .config to /boot/config-<version>, but this is not universal or required.

    When I built this last night, I used " make oldconfig" since the readme indicated something to this effect, but is this exactly the existing config?
    "oldconfig" just pulls the existing settings out of the .config file in the kernel top-level directory, then asks you questions about any settings that have been added since your .config file was generated. (If the versions match, then you won't be asked anything.)

    (The .config file is the source of all the settings, but it's not sufficient to just change .config; you have to also run make <something>config to get the settings to take effect.)

    Right, that's exactly what I did yesterday, when I got the invalid format error.
    The only source of the "invalid module format" error that I've ever seen is using the wrong modprobe executable. If you use modprobe from module-init-tools, you shouldn't get this error. (That's the modprobe in /sbin.)

    For my own sanity, would doing this by itself (without changing the kernel or any other modules) cause any harm to the existing installation?
    No, it shouldn't. All it does is figure out whether each of the modules can be loaded, and if so, what other modules each one depends on (if any). Then it writes this dependency information to a file that modprobe uses to auto-load dependent modules.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •