Compile Linux Kernel Modules
ÎÒÕýÔÚѧϰдlinux device driver for embedded system.
ÎÒÓÐÒ»¸ölinuxǶÈëʽÉ豸£¬Ò²ÓÐÕâ¸öÉ豸µÄlinuxÔ´´úÂë¡£Ò²ÓÐcross compiler tool chain.
µÚÒ»²½£¬¾ÍÊÇдһ¸ö¼òµ¥µÄhelloÄ£¿é£¬È»ºó×°µ½É豸ÖС£ÒÔÑéÖ¤ÎÒÕâ¸ö¿ª·¢»·¾³¡£
ÔÚÍøÉÏËÑË÷ÁËһϣ¬ how to cross compile linux device driver
·¢ÏÖÔÚlinux´úÂë¸ùĿ¼µÄMakefileÖÐÓйØÓÚcross compileµÄÃèÊö
# Cross compiling and selecting different set of gcc/bin-utils
# ---------------------------------------------------------------------------
#
# When performing cross compilation for other architectures ARCH shall be set
# to the target architecture. (See arch/* for the possibilities).
# ARCH can be set during invocation of make:
# make ARCH=ia64
# Another way is to have ARCH set in the environment.
# The default ARCH is the host where make is executed.
# CROSS_COMPILE specify the prefix used for all executables used
# during compilation. Only gcc and related bin-utils executables
# are prefixed with $(CROSS_COMPILE).
# CROSS_COMPILE can be set on the command line
# make CROSS_COMPILE=ia64-linux-
# Alternatively CROSS_COMPILE can be set in the environment.
# Default value for CROSS_COMPILE is not to prefix executables
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
Ö»ÒªÖ¸¶¨ARCHºÍCROSS_COMPILE¾Í¿ÉÒÔÁË¡£
ÔÚÎÒµÄÕâ¸öMakefileÖУ¬ÒѾָ¶¨ÁËARCH=arm£¬CROSS_COMPILE=arm-linux-
ÒòΪÔÚ±àÒëmoduleµÄʱºò£¬Ê¹ÓõÄÊÇÄں˹¹Ôìϵͳ£¬Ò²¾ÍÊÇʹÓõÄÉÏÃæËù˵µÄÕâ¸öÔÚÄÚºËÔ´Âë¸ùĿ¼µÄMakefile¡£ËùÒÔÎҾͲ»ÐèÒªÔÚÎÒµ÷ÓÃmakeµÄÃüÁîÐÐÖÐÖ¸¶¨ARCHºÍCROSS_COMPILEÁË¡£
ÓÃÀ´²âÊÔµÄhelloÄ£¿éµÄÔ´ÂëÀ´×Ô http://www.cyberciti.biz/tips/compiling-linux-kernel-module.html
hello.c
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */
static int __init hello_start(void)
{
printk(KERN_INFO "Loading hello module...\n");
printk(KERN_INFO "Hello world\n");
return 0;
}
static void
Ïà¹ØÎĵµ£º
ÓÉÓÚ fc3 ÄÚºËĬÈÏ fat32 Îļþϵͳ×Ö·û±àÂëÊÇ ascii£¬Èç¹ûÓÅÅ̵ÄÎļþÃû°üº¬ÖÐÎÄ£¬ÄÇôÔÚת»»Ê±»á³öÎÊÌ⣬ӦÓóÌÐò¾Í»áʧȥÏìÓ¦¡£¾ßÌåµÄ±íÏÖÓжàÖÖ£¬±ÈÈç×ÀÃæ¼ÙËÀ£¬¹Ø»úʱÌáʾÎÞ·¨Ð¶ÔØ·ÖÇøµÈµÈ
½â¾öµÄ°ì·¨ÊÇÔÚ¹ÒÔØÊ±£¬¸ù¾ÝÓïÑÔ»·¾³ locale µÄÖµ£¬Ê¹ÓùÒÔØ²ÎÊý¡£Èç¹ûÊÇ UTF- ......
1. I/O Port
¡¡¡¡ºÍÓ²¼þ´ò½»µÀÀë²»¿ªI/O Port£¬ÀϵÄISAÉ豸¾³£ÊÇÕ¼ÓÃʵ¼ÊµÄI/O¶Ë¿Ú£¬ÔÚlinuxÏ£¬²Ù×÷ϵͳûÓжÔI/O¿ÚÆÁ±Î£¬Ò²¾ÍÊÇ˵£¬ÈκÎÇý¶¯³ÌÐò¶¼¿É¶ÔÈÎÒâµÄI/O¿Ú²Ù×÷£¬ÕâÑù¾ÍºÜÈÝÒ×ÒýÆð»ìÂÒ¡£Ã¿¸öÇý¶¯³ÌÐòÓ¦¸Ã×Ô¼º±ÜÃâÎóÓö˿ڡ£
¡¡¡¡ÓÐÁ½¸öÖØÒªµÄkernelº¯Êý¿É ......
brctl addbr br0
ifconfig br0
br0 MAC is 00:00:00:00:00:00
brctl addif br0 eth1 (eth1 is xx:xx:xx:xx:xx:33)
ifconfig br0
br0 MAC is xx:xx:xx:xx:xx:33 same as eth1, auto change
brctl addif br0 eth2 (eth2 is xx:xx:xx:xx:xx:30)
ifconfig br0
br0 MAC is xx:xx:xx:xx:xx:30 sa ......
ÔÚ°²×°ÍêjdkÒԺ󣬾ÍÀ´°²×°MyEclipseÁË¡£
ÓÐһЩ°²×°ÁËjdkÒÔºóûÓÐÉúЧ£¬³öÏֵϹÊÇ1.4°æ±¾µÄ¡£
ËùÒÔ°²×°MyEclipse7.0»òÕßÊÇ6.5¡¢6.6µÄ¶¼»á³ö´í
[root@gupt aaaa]# ll
×ÜÓÃÁ¿ 380
dr-xr-xr-x 6 root root 4096
2009-01-17 configuration
-r--r--r-- 1 root root 7 ......
Ò»ÄêÒ»¶ÈµÄLinux¿ª·¢Õß´ó»áÉÏÖÜÔھɽðɽ¾ÙÐУ¬»áÉÏLinux»ù½ð»áÖ´ÐÐÀíÊÂJim Zemlin±íʾ£¬µÃÒæÓÚÔÆ¼ÆËãÒÔ¼°ÆäËü¿Æ¼¼³±Á÷µÄ³öÏÖ£¬LinuxµÄÊг¡µØÎ»Ê®·ÖÎȹ̣¬È»¶øÒ»Ð©Ö÷ÒªµÄά»¤ÈËÔ±ÒѾÈÕ½¥²ÔÀÏ£¬ºó¼ÌÕßÈ´»¹Ã»ÓгÉÊì¡£
sysfsÄÚºË×Óϵͳά»¤ÕßGrey Kroah-HartmanÖ¸³ö£º“ÉϲãµÄÈËÔ±ÈÔȻà ......