以模块方式加载驱动

为了调试驱动方便,准备让驱动以模块的方式加载,这样就不用重复地烧写整个系统了。

但是在给uclinux选上以模块方式加载支持后:

  │ │   [*] Enable loadable module support                   │ │

  │ │   [ ]   Set version information on all module symbols  │ │

  │ │   [*]   Kernel module loader                           │ │

编译过程就出错了:

make CFLAGS="-D__KERNEL__ -I/home/work1/uClinux-dist-server/linux-2.4.x/include  -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -fno-common -pipe -fno-builtin -D__linux__ -DNO_MM -mapcs-32  -mtune=arm7tdmi -mshort-load-bytes -msoft-float -gdwarf-2" -C  drivers

make[2]: Entering directory `/home/work1/uClinux-dist-server/linux-2.4.x/drivers'

make -C block

make[3]: Entering directory `/home/work1/uClinux-dist-server/linux-2.4.x/drivers/block'

make all_targets

make[4]: Entering directory `/home/work1/uClinux-dist-server/linux-2.4.x/drivers/block'

make[4]: *** 没有规则可以创建"ll_rw_blk.o"需要的目标"DAC960.c"。 停止。

make[4]: Leaving directory `/home/work1/uClinux-dist-server/linux-2.4.x/drivers/block'

make[3]: *** [first_rule] 错误 2

make[3]: Leaving directory `/home/work1/uClinux-dist-server/linux-2.4.x/drivers/block'

make[2]: *** [_subdir_block] 错误 2

make[2]: Leaving directory `/home/work1/uClinux-dist-server/linux-2.4.x/drivers'

make[1]: *** [_dir_drivers] 错误 2

make[1]: Leaving directory `/home/work1/uClinux-dist-server/linux-2.4.x'

make: *** [linux] 错误 1

打开linux-2.4.x/drivers/block/Makefile,发现Makefile里两处指定的都是大写的DAC960.c,而linux-2.4.x/drivers/block/下的这两个文件名都是小写的。后来看了看linux-2.6.18的内核,发现他们是把dac960.c和dac960.h改成了DAC960.c和DAC960.h。

修改后编译又见异常:

make[4]: Entering directory `/home/work1/uClinux-dist-server/linux-2.4.x/drivers/char'

arm-elf-gcc -D__KERNEL__ -I/home/work1/uClinux-dist-server/linux-2.4.x/include  -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -fno-common -pipe -fno-builtin -D__linux__ -DNO_MM -mapcs-32  -mtune=arm7tdmi -mshort-load-bytes -msoft-float -gdwarf-2  -nostdinc -iwithprefix include -DKBUILD_BASENAME=serial_core_44b0x  -c -o serial_core_44b0x.o serial_core_44b0x.c

serial_core_44b0x.c:2244: parse error before `this_object_must_be_defined_as_export_objs_in_the_Makefile'

serial_core_44b0x.c:2244: warning: type defaults to `int' in declaration of `this_object_must_be_defined_as_export_objs_in_the_Makefile'

serial_core_44b0x.c:2244: warning: data definition has no type or storage class

serial_core_44b0x.c:2245: parse error before `this_object_must_be_defined_as_export_objs_in_the_Makefile'

serial_core_44b0x.c:2245: warning: type defaults to `int' in declaration of `this_object_must_be_defined_as_export_objs_in_the_Makefile'

serial_core_44b0x.c:2245: warning: data definition has no type or storage class

serial_core_44b0x.c:2246: parse error before `this_object_must_be_defined_as_export_objs_in_the_Makefile'

serial_core_44b0x.c:2246: warning: type defaults to `int' in declaration of `this_object_must_be_defined_as_export_objs_in_the_Makefile'

serial_core_44b0x.c:2246: warning: data definition has no type or storage class

serial_core_44b0x.c:2247: parse error before `this_object_must_be_defined_as_export_objs_in_the_Makefile'

serial_core_44b0x.c:2247: warning: type defaults to `int' in declaration of `this_object_must_be_defined_as_export_objs_in_the_Makefile'

serial_core_44b0x.c:2247: warning: data definition has no type or storage class

serial_core_44b0x.c:2248: parse error before `this_object_must_be_defined_as_export_objs_in_the_Makefile'

serial_core_44b0x.c:2248: warning: type defaults to `int' in declaration of `this_object_must_be_defined_as_export_objs_in_the_Makefile'

serial_core_44b0x.c:2248: warning: data definition has no type or storage class

make[4]: *** [serial_core_44b0x.o] 错误 1

make[4]: Leaving directory `/home/work1/uClinux-dist-server/linux-2.4.x/drivers/char'

make[3]: *** [first_rule] 错误 2

make[3]: Leaving directory `/home/work1/uClinux-dist-server/linux-2.4.x/drivers/char'

make[2]: *** [_subdir_char] 错误 2

make[2]: Leaving directory `/home/work1/uClinux-dist-server/linux-2.4.x/drivers'

make[1]: *** [_dir_drivers] 错误 2

make[1]: Leaving directory `/home/work1/uClinux-dist-server/linux-2.4.x'

make: *** [linux] 错误 1

按照提示”this_object_must_be_defined_as_export_objs_in_the_Makefile”检查了一下linux-2.4.x/drivers/char/Makefile,发现是export-objs列表里少了serial_core_44b0x.o,加上后即可编译通过。 

模块的加载和卸除需要用到insmod和rmmod,所以还需要将busybox里的这两个工具选上。之后就可以用“insmod 模块名”和“rmmod 模块名”来加载和卸除模块了。

— EOF —

发表评论

电子邮件地址不会被公开。 必填项已用*标注