If you will write driver, try out the hello world module example in the (must have) book "Linux Device Driver 3rd ed.".
In your kernel dir, eg, ~/uClinux-dist,
save the file to linux-2.6.x/drivers/misc/hello.c
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_ALERT "Hello, world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
Add these lines to linux-2.6.x/drivers/misc/Kconfig, before the "endmenu" line.
config HELLO
tristate "example hello module"
help
Enable example hello module.
Add the line to linux-2.6.x/drivers/misc/Makefile
obj-$(CONFIG_HELLO) += hello.oEnable module support using "make menuconfig", then build the hello.ko module.
In kernel selection,
Loadable module support -->
[*] Enable loadable module support
[*] Module unloading
Device Drivers -->
Misc devices --->
<M> example hello moduleIn apps selection,
Busybox -->
[*] insmod
[*] insmod: lsmod
[*] insmod: modprobe
[*] insmod: rmmod
[ ] insmod: Pre 2.1 kernel modules
[ ] insmod: 2.1 - 2.4 kernel modules
[*] insmod: 2.6 and above kernel modules
[ ] insmod: Model version checks
[ ] insmod: Support tainted module checking with new kernels
Then, in ~/uClinux-dist dir, rebuild with,
make user/busybox_clean
make
The modules objects, (eg hello.ko) will be install in romfs/lib/modules tree.
Boot nios2 uClinux, and load module
modprobe hello
There is an example driver in Chinese from Alex.liu,
http://www.icwin.net/ShowArtitle.ASP?art_id=8452&cat_id=52
Build module alone (not recommended for newbie)
You can compile the hello module alone, without building the whole kernel.
In the module dir, ~/uClinux-dist/linux-2.6.x/drivers/misc, compile it with,
make ARCH=nios2nommu CROSS_COMPILE=nios2-linux-uclibc- -C ~/uClinux-dist/linux-2.6.x M=`pwd` modules
nios2-linux-uclibc-strip -R .comment -R .note -g --strip-unneeded hello.koThen you can transfer the module file, hello.ko, to your board with ftp or nfs mount if you have ethernet port, and try out with "insmod hello.ko" and "rmmod hello". Or you may replace the old module at /lib/modules/2.6.17-uc1/kernel/drivers/misc , then you can use "modprobe hello".
You can save the time to rebuild the whole kernel, download and reboot.
Or if you want to build module outside the kernel tree, ie external module, create a Makefile in your module dir, with only one line,
obj-m := hello.oThen build it with the same commands above.
For details, please read,
linux-2.6.x/Documentation/kbuild/modules.txt
linux-2.6.x/Documentation/kbuild/makefiles.txt