How to compile kernel modules...

February 8, 2011 at 07:00:33
Specs: Linux/, armv5tejl
on a system without access to the kernel itself (firmware)?

Precisely: I have a NAS (CH3MNAS) which seems to run some kind of Linux based on kernel I already managed to open it for additional software but some of my desired additional features need kernel support: 1) For NTFS-disks on the USB port I need the kernel to support NTFS natively or at least FUSE for use with e.g. NTFS-3G), 2) for a VPN server I need kernel support of PPP. Neither of these 3 features is activated in the firmware by default (of course - because space is limited on this machine).

No problem I thought, there is support for external kernel modules. The USB disk driver itself is such and it works (but I didn't build this one myself, the downloaded one just luckily fitted my hardware). For the 3 mentioned modules however I didn't manage to find a fitting download. So I tried to build them myself from a kernel source code that matches my kernel version. I compiled the whole thing (didn't know how to compile only the desired modules, because they have many dependencies) with the appropriate switches and tested:

I found the modules "ntfs.ko" and "fuse.ko" and started with "insmod ntfs.ko" => Segmentation fault. The second try bricked my NAS completely and "reset-proof" and therefore I thought I'd better ask someone who knows what he's doing ;-): YOU! Obviously I'm missing something or have misconfigured something (I answered all those menu-config questions not more than inuitively).

Any ideas or suggestions?

best regards

See More: How to compile kernel modules...

February 8, 2011 at 08:29:51
Did you just compile on your Linux machine or did you do a cross-compile for the appropriate architecture? If you don't cross-compile you will be producing x86 code which is no use for your NAS.

Cross-compiling for an embedded device like this can be fairly tricky and, as you have discovered, unless you get it right you tend to brick the device. Google "Cross compile Linux ARM" (substitute the appropriat processor architecture for "ARM") to learn more about cross-compiling.

Report •

February 8, 2011 at 08:48:00
I don't have a Linux machine, therefore I compiled directly on the NAS. I might setup a virtual machine for that, but as far as my understanding was, this should be the safest way, too, shouldn't it? No trouble with mismatching toolchain, or the like. Or did I get something completely wrong?

The "google" you recommend resulted in trillions of results, but I resigned after 10. Without in-deep understanding I would never find what I might need. Can you point me to a (really) relevant page?

Report •

February 8, 2011 at 12:40:08
Ah - I misunderstood. Compiling on the NAS itself is certainly the right thing to do. The only other thing that I can add is that, ideally, your kernel configuration should be exactly that used to produce the original kernel.

I can only suggest that you Google around to see if you can find anyone who has done this sort of thing on your particular machine. I've played around with this on Buffalo NAS servers (which are very well supported in this respect) and I can tell you that it is not easy. Ideally you need some access to the machine other than telnet or ssh; normally this involves modifying the circuit board to enable a serial interface; whether this is possible for your machine I don't know.

Report •

Related Solutions

February 9, 2011 at 00:19:22
That doesn't sound too good :-(. My NAS is quite similar in architecture to the DNS-320, which is also very good supported. Most of the addons I'm using (funplug) were orginally written for the latter. Just kernel modules compiled for that one don't seem to work.

As I said before I managed to find (only!) one kernel module for my NAS on the internet: usbdisk.ko, and of course it was my first idea to contact the person who built it, but as for now I couldn't find him/her.

Please, could you explain, what I might need a serial interface for? My kernel does support loadable modules, which is proven to work (usbdisk.ko!), so why would I want to do things to the machine that go beyond this? I don't want to put a modified kernel on the system, I just want to add 3 kernel modules, and therefore like to know how to compile these correctly.

One update by the way: I found out, that the "funplug" addon offers the following toolchain: gcc 4.1.3, binutils, uclibc 0.9.29-7. I'm not absolutely sure, but I suspect, that this might be different from the toolchain the kernel originally was built with - at least because "funplug" was not natively built for my machine, but for the DNS-320. So:

- Do you agree that a mismatching toolchain could be the reason for my problem?

- If so: How can I find out the toolchain the kernel was originally built with (gcc and the like were stripped off the firmware) - other than googling, because that one failed already?

- I read that for building a modified kernel the "make" config file of the original firmware might be helpful. Do you agree? And if so: Can I regenerate it somehow, if I don't find on the internet (which unfortunately is true so far)?

best regards and thank you for your assistance so far...

Report •

February 9, 2011 at 02:37:13
A serial interface can be useful in the event that a device becomes bricked; it's the only way to see what is going on at boot time and perhaps interrupt the boot process (well, that's not quite true - there is also netconsosle, but this requires a working netconsole for your particular device).

I wouldn't have thought that the version of gcc (although you might want to make sure it's the same major version number - i.e. 3 or 4) or binutils would matter; uclibc might conceivable cause probems. The original "make" configuration would obviously be very useful; failing that you might want to compile the kernel as well as the modules - but that is an almost certain route to bricking the device. I don't know how you can recover that information. Although Linux allows you to embed that information in the kernel itself the chances of that being the case for your device are pretty close to zero.

Your best bet would definitely be to try and find that person who has experience with your device. My Buffalo Linkstation is great because so many people have played with it, even to the extent of producing alternate distributions, but I also have a Linksys NAS and an Emtec media device that I would like to do this sort of thing with. Unfortunately finding information about them is pretty difficult - I can't even telnet or ssh into the Linksys.

I'm afraid that I've not really been a lot of help other than to confirm how difficult your task is. But the best of luck with it; and if you do succeed be sure to write it up somewhere to help other brave souls.

Report •

February 9, 2011 at 03:46:35
Fortunately it's quite hard to brick the device permanently, because latest at power off all temporary stuff is gone. I just did a "dmesg" and that had some valueable info to give:

Linux version (jack@SWTEST1) (gcc version 3.4.4 (release) (CodeSourcery ARM 2005q3-2)) #85 Thu Mar 26 09:48:50 CST 2009

I don't exactly know how to use this "CodeSourcery" toolchain, but we well see.

Furthermore I found a (not quite up-to-date) source code for my NAS on the internet. It's still downloading (over 200MB!), and therefore I don't know what expects me there, but hopefully I'll find a suitable "make" config file somewhere inside.

I'll let (all of) you know of any progress...

Report •

February 15, 2011 at 01:00:43
Solved! The source code offered everything I need: Toolchain and kernel source code including .config file for exactly my system. First the toolchain gave me errors, but only until I found out, that it's intended to run on "i686-pc-linux" (not on the NAS itself!). I was really astaunished how easy it was after all: Download the source from Conceptronics ftp site -> Unpack kernel and toolchain -> Modify $PATH to point to the toolchain -> make menuconfig -> make -> copy the compiled modules -> done.

Hope that helps someone

Report •

February 15, 2011 at 02:05:22
Good stuff. I suspect that finding that .config file was the key.

Report •

March 24, 2011 at 18:13:29
i have the same device as well, and i am facing the same problem. But i am a total newbie, so could you please be so kind to send me the modules to install as i can't/dunno how to compile and stuff. my email is n case you can help, thanks

Report •

Ask Question