Tiny Core Linux

Tiny Core Extensions => TCE Q&A Forum => Topic started by: Theo404 on October 27, 2009, 03:41:01 AM

Title: Compiling kernel modules --> extensions
Post by: Theo404 on October 27, 2009, 03:41:01 AM
Hi there, many thanks to the devs for tiny core... such a fully featured distro in so little space is quite remarkable.

My issue is with compiling kernel modules in a tc environment (with the goal of creating a tcz from it).

I have the compiletc.tcz extension loaded, I download the linux 2.6.29.1 source and place it on a persistent medium. I then mount to /usr/src/linux and try to compile a module with this:

make /net/mac80211/mac08211.ko

It seems to go well but then exits with MODPOST 0 modules.

When looking in /net/mac80211 there is only a mac80211.o file....

I tried compiling it on another system using the same kernel source and got a .ko file out, however when trying to insmod it on the tc system it fails with 'invalid module type'.

I even tried unloading the module that comes with tc and then insmod-ing it back in while in the correct directory... that failed with the same error....

I'm lost... can anyone give me a clue?
Title: Re: Compiling kernel modules --> extensions
Post by: Juanito on October 27, 2009, 03:55:54 AM
This is probably not all required, but:

load the compiletc "meta-extension"
load the perl5 and bash extensions
download the patched tinycore source and unpack in, say, /usr/src
download the tinycore config and copy to the top level of the unpacked souce as .config
use "make menuconfig" to load the tinycore .config and save
make modules
sudo make modules_install
Title: Re: Compiling kernel modules --> extensions
Post by: Theo404 on October 27, 2009, 04:12:54 AM
Many thanks for the swift reply.

I have perl5 loaded (tried a plain make modules for the hell of it, seems some need it) but did not have any of the bash*.tcz extensions loaded... would this make the difference?

I will try all that you suggested, but may I ask, if this works will it produce *.ko.gz modules in the correct directories (because of the modules_install) which I can fish out and put into a .tcz?

Would be really nice if there was an idiots guide to things like this in the wiki... are you guys open to contributions?
Title: Re: Compiling kernel modules --> extensions
Post by: bmarkus on October 27, 2009, 04:22:27 AM
Would be really nice if there was an idiots guide to things like this in the wiki... are you guys open to contributions?

Wiki is open for anybody, just register.
Title: Re: Compiling kernel modules --> extensions
Post by: Juanito on October 27, 2009, 04:45:49 AM
I have perl5 loaded (tried a plain make modules for the hell of it, seems some need it) but did not have any of the bash*.tcz extensions loaded... would this make the difference?

I will try all that you suggested, but may I ask, if this works will it produce *.ko.gz modules in the correct directories (because of the modules_install) which I can fish out and put into a .tcz?

Certain parts of the kernel/kernel modules build require bash and perl so you'd need both extensions loaded to make sure everything compiles OK.

This will produce a *.ko module in the "correct" directory (I don't think it matters too much where as it's under /lib or /usr/local/lib and you run depmod). Unless there's a make switch that I'm not aware of, you'll need to manually gzip/advdef the *.ko to *.ko.gz.

Once you have the module under /lib, I'd recommend moving it to a comparable path under /usr/local/lib/modules/2.6.29.1-tinycore/kernel/.. so that it becomes PPI compatible before you make your *.tczm extension out of it.
Title: Re: Compiling kernel modules --> extensions
Post by: Theo404 on October 27, 2009, 05:14:47 AM
Again thanks for the reply.

Another question (forgive me)... once I have the relevant module in /usr/local/lib/modules...etc... how best should I go about using mksquashfs to create the tczm?

I made a .tcz to load the firmware for my wireless card by creating a temp dir with the same dir structure as the place it needed to be and using mksquashfs on that, eg - mkdir temp/lib/firmware/b43 coping the relevant files to the deepest dir and then mksquashfs temp packagename.tcz. Would I have to create this structure (eg /temp/usr/local/lib/modules/2.6.29.1-tinycore/kernel/...) and then mksquashfs that?
Title: Re: Compiling kernel modules --> extensions
Post by: Juanito on October 27, 2009, 05:23:46 AM
I'm not at a linux machine at the moment to confirm the shortest way to do this, but whilst being a bit long, this should work:
Code: [Select]
$ sudo tar -czvf mymodule.tcem --numeric-owner /usr/local/lib/path-to-file/module_name.ko.gz
$ mkdir /tmp/pkg
$ cp mymodule.tcem /tmp/pkg
$ cd /tmp/pkg
$ sudo tar xzf mymodule.tcem
$ rm mymodule.tcem
$ cd ..
$ sudo mksquashfs pkg/ mymodule.tczm
note: use the gnu tar extension to do this
Title: Re: Compiling kernel modules --> extensions
Post by: Theo404 on October 27, 2009, 05:41:49 AM
I see, so the tar-ing with --numeric-owner /usr/local/lib/path-to-file/module_name.ko.gz preserves the directory structure, which is created again when you untar it, which you then apply mksquashfs to. Thanks for clearing that up.
Title: Re: Compiling kernel modules --> extensions
Post by: Theo404 on October 27, 2009, 05:44:08 AM
Sorry if this is a dumb question by how do you create tcz's that do more than just put files in the right place?
Title: Re: Compiling kernel modules --> extensions
Post by: bmarkus on October 27, 2009, 05:45:33 AM
Sorry if this is a dumb question by how do you create tcz's that do more than just put files in the right place?

What do you mean do more?
Title: Re: Compiling kernel modules --> extensions
Post by: Juanito on October 27, 2009, 05:45:57 AM
Quote
...preserves the directory structure

..and permissions
Title: Re: Compiling kernel modules --> extensions
Post by: Theo404 on October 27, 2009, 05:52:51 AM
Sorry if this is a dumb question by how do you create tcz's that do more than just put files in the right place?

What do you mean do more?

Well I thought that some extensions did more than just put files in folders. The wireless-2.6.29.1 extension seems to make new modules (if required) load at boot, and at the very least they have to update bash. Or is this all just clever scripts?
Title: Re: Compiling kernel modules --> extensions
Post by: Juanito on October 27, 2009, 05:57:14 AM
Well I thought that some extensions did more than just put files in folders. The wireless-2.6.29.1 extension seems to make new modules (if required) load at boot, and at the very least they have to update bash. Or is this all just clever scripts?

This is a combination of the "m" in tczm which tells tce-load to invoke "depmod" and udev which automagically loads available modules for hardware it knows about.

Edit: and you can include a script /usr/local/tce.installed/extension_name in your tcz that will execute when the extension is loaded
Title: Re: Compiling kernel modules --> extensions
Post by: Theo404 on October 27, 2009, 06:06:47 AM
Edit: and you can include a script /usr/local/tce.installed/extension_name in your tcz that will execute when the extension is loaded

Ok, but tcz extensions just come as one file (excluding .list .dep etc), where is this script contained?

Edit: and if you can add scripts to them... how?
Title: Re: Compiling kernel modules --> extensions
Post by: bmarkus on October 27, 2009, 06:08:52 AM
You may read this WIKI article  Adding Custom Startup Scripts (http://wiki.tinycorelinux.com/tiki-index.php?page=Creating+Extensions#Adding_Custom_Startup_Scripts)
Title: Re: Compiling kernel modules --> extensions
Post by: Theo404 on October 27, 2009, 06:14:44 AM
You may read this WIKI article  Adding Custom Startup Scripts (http://wiki.tinycorelinux.com/tiki-index.php?page=Creating+Extensions#Adding_Custom_Startup_Scripts)

Fair... I'l go away and read some more (rtfm?). Thanks for your help guys  ;D
Title: Re: Compiling kernel modules --> extensions
Post by: Juanito on October 27, 2009, 06:23:09 AM
If you take the previous example, you would have a number of files under /tmp/pkg/usr/local - in the case of your module only one file, but it could be any number of files in any number of folders.

Originally /usr/local/tce.installed/extension_name was used as a flag to indicate that an extension called "extension_name" is already loaded. If your extension contains a script named  /usr/local/tce.installed/extension_name, then it will run when the extension is loaded.

To create the script, first create the folder:
Code: [Select]
$ sudo mkdir /tmp/pkg/usr/local/tce.installed
$ sudo chmod 775 /tmp/pkg/usr/local/tce.installed
$ sudo chown root:staff /tmp/pkg/usr/local/tce.installed

..then use vi, beaver or similar to write a script and save it as /usr/local/tce.installed/extension_name, then make it executable:
Code: [Select]
$ sudo chmod +x /tmp/pkg/usr/local/tce.installed/extension_name
..and use squashfs to make the tcz as before
Title: Re: Compiling kernel modules --> extensions
Post by: Theo404 on October 27, 2009, 06:28:52 AM
If you take the previous example, you would have a number of files under /tmp/pkg/usr/local - in the case of your module only one file, but it could be any number of files in any number of folders.

Originally /usr/local/tce.installed/extension_name was used as a flag to indicate that an extension called "extension_name" is already loaded. If your extension contains a script named  /usr/local/tce.installed/extension_name, then it will run when the extension is loaded.

To create the script, first create the folder:
Code: [Select]
$ sudo mkdir /tmp/pkg/usr/local/tce.installed
$ sudo chmod 775 /tmp/pkg/usr/local/tce.installed
$ sudo chown root:staff /tmp/pkg/usr/local/tce.installed

..then use vi, beaver or similar to write a script and save it as /usr/local/tce.installed/extension_name, then make it executable:
Code: [Select]
$ sudo chmod +x /tmp/pkg/usr/local/tce.installed/extension_name
..and use squashfs to make the tcz as before

This is exactly what I'm saying the wiki needs.... clear concise answers to basic questions about tc...

Many thanks... I'l report back later.
Title: Re: Compiling kernel modules --> extensions
Post by: bmarkus on October 27, 2009, 06:40:47 AM
One more reading : http://forum.tinycorelinux.net/index.php?topic=3038.0
Title: Re: Compiling kernel modules --> extensions
Post by: coreplayer2 on June 25, 2018, 10:31:04 AM
Also, you may use "submitqc.tcz" extension to run a build quality check on your new extension for local use and submission