歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> uclinux-2008R1-RC8(bf561)到VDSP5的移植(61):KBUILD_MODNAME

uclinux-2008R1-RC8(bf561)到VDSP5的移植(61):KBUILD_MODNAME

日期:2017/3/3 16:43:22   编辑:關於Linux

在一些以模塊方式提供的驅動中,使用了module_param這個宏來定義一些參數,這個宏將引起一個語法錯誤:

"../../drivers/net/dm9000.c", line 124: cc0020: error: identifier
"KBUILD_MODNAME" is undefined
module_param(watchdog, int, 0400);

看看module_param的定義:

#define module_param(name, type, perm) /
module_param_named(name, name, type, perm)

繼續找module_param_named的定義:

/* Helper functions: type is byte, short, ushort, int, uint, long,
ulong, charp, bool or invbool, or XXX if you define param_get_XXX,
param_set_XXX and param_check_XXX. */
#define module_param_named(name, value, type, perm) /
param_check_##type(name, &(value)); /
module_param_call(name, param_set_##type, param_get_##type, &value, perm); /
__MODULE_PARM_TYPE(name, #type)

再展開module_param_call:

/* This is the fundamental function for registering boot/module
parameters. perm sets the visibility in sysfs: 000 means it's
not there, read bits mean it's readable, write bits mean it's
writable. */
#define __module_param_call(prefix, name, set, get, arg, perm) /
/* Default value instead of permissions? */ /
static int __param_perm_check_##name __attribute__((unused)) = /
BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2)); /
static char __param_str_##name[] = prefix #name; /
static struct kernel_param const __param_##name /
__attribute_used__ /
__attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) /
= { __param_str_##name, perm, set, get, arg }
#define module_param_call(name, set, get, arg, perm) /
__module_param_call(MODULE_PARAM_PREFIX, name, set, get, arg, perm)

在這裡使用了一個MODULE_PARAM_PREFIX的宏定義:

#define MODULE_PARAM_PREFIX KBUILD_MODNAME "."

錯誤提示中的KBUILD_MODNAME就出現在這裡。

這個宏就是定義了模塊的名稱,是一個字符串,每個不同的驅動模塊都有不同的名稱,因此當在linux下編譯時,將這個名稱寫在了Makefile中,因此在編譯這個模塊文件時,編譯器會自動加上-DKBUILD_MODNAME=”xxx”這樣的定義。

在VDSP下編譯時,也必須為此模塊文件單獨定義一個KBUILD_MODNAME這個的宏。其操作為:

在文件上點右鍵 -> File Options -> Build with -> File specific settings -> Preprocessor -> Proprocessor definitions,添加如下定義:

KBUILD_MODNAME=/"dm9000/"

注意一定要加上反斜槓。否則將出錯。

Copyright © Linux教程網 All Rights Reserved