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
Ïà¹ØÎĵµ£º
ÓÉÓÚ¹¤×÷ÐèÒªÏÖÔÚ¿ªÊ¼´Óͷѧϰlinux£¬ÏÂÃæÏȼǼamlogic openlinux°²×°²½Öè¡££¨Ç°ÌáÊǰ²×°ÁËÐéÄâ»ú£©
Amlogic open linux ±àÒë»·¾³°²×°
Ò»¡¢gcc¹¤¾ßµÄ°²×°
1¡¢´ÓAmlogicÍøÕ¾ÉÏÏÂÔØgcc¹¤¾ß
ÔÚÏÂÃæÏÂÔØIndex of /download/linux/gnutools
gnutools-arc2.2-p4-ubuntu-9.04-2010- ......
ÒªÔÚǶÈëʽLinuxÏÂʹÓö¯Ì¬ÓïÑÔ£¬Ê×ÏÈÒª½â¾öµÄÊÇÓïÑÔ½âÊÍÆ÷»òÖ´ÐÐÒýÇæµÄ½»²æ±àÒëÎÊÌâ¡£
½»²æ±àÒëͨ³£ÓÐÒÔϼ¸ÖÖ;¾¶£º
1. Ö±½Óͨ¹ý½»²æ±àÒ빤¾ß£¬ÊÖ¹¤ÅäÖý»²æ±àÒë¡£½»²æ±àÒ빤¾ß¿ÉÒÔÀûÓÃÕâ¸ö½Å±¾À´×Ô¶¯Éú³É£º
http://kegel.com/crosstool/
´Ë·½·¨µÄºÃ´¦ÊǼò±ã¿ì½Ý£¬Ò»µ©crosstool×öºÃÒÔºó£¬ÐèҪʲô°üÖ±½Ó±àÒë¼´¿É£¬ ......
fg¡¢bg¡¢jobs¡¢&¡¢ctrl + z¶¼ÊǸúϵͳÈÎÎñÓйصģ¬ËäÈ»ÏÖÔÚ»ù±¾Éϲ»ÔõôÐèÒªÓõ½ÕâЩÃüÁµ«Ñ§»áÁËÒ²ÊǺÜʵÓõÄ
Ò»¡£& ×î¾³£±»Óõ½
Õâ¸öÓÃÔÚÒ»¸öÃüÁîµÄ×îºó£¬¿ÉÒÔ°ÑÕâ¸öÃüÁî·Åµ½ºǫִ́ÐÐ
¶þ¡£ctrl + z
¿ÉÒÔ½«Ò»¸öÕýÔÚǰִ̨ÐеÄÃüÁî·Åµ½ºǫ́£¬²¢ÇÒÔÝÍ£
Èý¡£jobs
²é¿´µ±Ç°ÓжàÉÙÔÚºǫ́ÔËÐеÄÃüÁî
ËÄ¡£fg
½ ......
•ËùÓбàÒëµ÷ÊÔÃüÁî¶¼ÔÚui_ref/trunk/bld_xxxÏÂÃæÖ´ÐÐ,¾ßÌåÄĸöbldÒª¸ù¾ÝÄúʹÓõİå×Ó¾ö¶¨;
•Make #±àÒëÈ«²¿,°üÀ¨kernel, busybox, packagesµÈ;
•Make root #±àÒëÎļþϵͳ;
•Make yaffs#°ÑÎļþϵͳ´ò°üÉú³ÉyaffsÎļþϵͳµÄÓ³Ïñrootfs.yaffsimage,²¢±£´æÔÚbuildĿ¼;
•±àÒëÄÚºË
▫Make k. ......
Ò»ÄêÒ»¶ÈµÄLinux¿ª·¢Õß´ó»áÉÏÖÜÔھɽðɽ¾ÙÐУ¬»áÉÏLinux»ù½ð»áÖ´ÐÐÀíÊÂJim Zemlin±íʾ£¬µÃÒæÓÚÔÆ¼ÆËãÒÔ¼°ÆäËü¿Æ¼¼³±Á÷µÄ³öÏÖ£¬LinuxµÄÊг¡µØÎ»Ê®·ÖÎȹ̣¬È»¶øÒ»Ð©Ö÷ÒªµÄά»¤ÈËÔ±ÒѾÈÕ½¥²ÔÀÏ£¬ºó¼ÌÕßÈ´»¹Ã»ÓгÉÊì¡£
sysfsÄÚºË×Óϵͳά»¤ÕßGrey Kroah-HartmanÖ¸³ö£º“ÉϲãµÄÈËÔ±ÈÔȻà ......