I'm building a kernel module that uses the hrtimer interface. I have the module compiling successfully, and it's got MODULE_LICENSE("GPL") set:
make -C /lib/modules/3.0.0-23-server/build SUBDIRS=/home/projects/net-modeler modules
make[1]: Entering directory `/usr/src/linux-headers-3.0.0-23-server'
CC [M] /home/projects/net-modeler/nm_injector.o
CC [M] /home/projects/net-modeler/nm_scheduler.o
LD [M] /home/projects/net-modeler/net-modeler.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/projects/net-modeler/net-modeler.mod.o
LD [M] /home/projects/net-modeler/net-modeler.ko
make[1]: Leaving directory `/usr/src/linux-headers-3.0.0-23-server'
... but when I try to insmod it, dmesg outputs
[111853.094925] Unknown symbol hrtimer_init (err 0)
[111853.094931] Unknown symbol hrtimer_start (err 0)
[111853.094942] Unknown symbol hrtimer_cancel (err 0)
Those functions are externed inside of <linux/hrtimer.h>, and exported in kernel/hrtimer.c as follows:
/**
* hrtimer_init - initialize a timer to the given clock
* #timer: the timer to be initialized
* #clock_id: the clock to be used
* #mode: timer mode abs/rel
*/
void hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
enum hrtimer_mode mode)
{
debug_init(timer, clock_id, mode);
__hrtimer_init(timer, clock_id, mode);
}
EXPORT_SYMBOL_GPL(hrtimer_init);
cat /proc/kallsyms | grep <func> for the three functions results in:
0000000000000000 T hrtimer_init
0000000000000000 T hrtimer_cancel
0000000000000000 T hrtimer_start
Can anyone help me figure out what's going on? It seems to me that all of the functions are exported and they should be able to be found, but for some reason they're not. Am I doing something stupid?
For anyone else trying to solve this problem, MODULE_LICENSE("GPL") must be in all of the module files, not just the main one.
Without that, the file that actually contained the function calls was restricted from accessing them by EXPORT_SYMBOL_GPL.
Related
! UPDATE on 28 Feb, 2020:
The problem is solved. please refer to :https://develop.openfoam.com/Development/openfoam/issues/1608
Summary
I'm new to OpenFOAM and I'm trying to compile OpenFOAM-v1912 using Icc and IntelMPI, only to find the following confusing error. It seems like an error in codes. But it just makes no sense, because I have successfully compiled it with gcc(v4.8.5) and openmpi(1.10.7), and it worked just fine. I'd be more than delighted to hear any suggestions. Ideas about what the problem might be will also be of great help. THANKS A LOT!
wallBoundedStreamLine/wallBoundedParticleTemplates.C(121): error: no operator "==" matches these operands
Steps to reproduce
I edited OpenFOAM-v1912/etc/bashrc from
...
export WM_COMPILER=Gcc
...
export WM_MPLIB=OPENMPI
...
to
...
export WM_COMPILER=Icc
...
export WM_MPLIB=INTELMPI
...
and I got "ld: cannot find -lmpi" error so I edit OpenFOAM-v1912/wmake/rules/General/Icc/c++
CC = icpc -std=c++11
to
CC = mpiicc -std=c++11
then under directory OpenFOAM-v1912/ , I ran
./Allwmake
What I've tried
Compiling with $WM_LABEL_SIZE=64
But it just seemed irrelevant and it got stuck on building libscotch. Doesn't seem to help at all.
Details of the error from the promts:
wmake reactingEulerFoam/phaseSystems
wmake reactingEulerFoam/interfacialModels
wmake reactingEulerFoam/interfacialCompositionModels
wmake reactingEulerFoam/derivedFvPatchFields
wmake reactingEulerFoam/reactingMultiphaseEulerFoam/multiphaseSystem
wmake reactingEulerFoam/reactingMultiphaseEulerFoam/multiphaseCompressibleTurbulenceModels
wmake reactingEulerFoam/reactingTwoPhaseEulerFoam/twoPhaseSystem
wmake reactingEulerFoam/reactingTwoPhaseEulerFoam/twoPhaseCompressibleTurbulenceModels
wmake field
mpiicc -std=c++11 -fp-trap=common -fp-model precise -DOPENFOAM=1912 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-unknown-pragmas -diag-disable 327,654,1125,1292,2289,2304,11062,11074,11076 -O3 -DNoRepository -ftemplate-depth-100 -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/finiteVolume/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/fileFormats/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/surfMesh/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/meshTools/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/sampling/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/lagrangian/basic/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/lagrangian/distributionModels/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/thermophysicalModels/basic/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/transportModels -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/transportModels/compressible/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/TurbulenceModels/turbulenceModels/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/TurbulenceModels/incompressible/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/TurbulenceModels/compressible/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/transportModels/compressible/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/thermophysicalModels/basic/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/thermophysicalModels/solidThermo/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/thermophysicalModels/chemistryModel/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/thermophysicalModels/reactionThermo/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/thermophysicalModels/specie/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/fvAgglomerationMethods/pairPatchAgglomeration/lnInclude -IlnInclude -I. -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/OpenFOAM/lnInclude -I/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/OSspecific/POSIX/lnInclude -fPIC -c wallBoundedStreamLine/wallBoundedStreamLine.C -o /share/software/OpenFOAM/OpenFOAM-v1912-ICC/build/linux64IccDPInt32Opt/src/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.o
wallBoundedStreamLine/wallBoundedParticleTemplates.C(121): error: no operator "==" matches these operands
operand types are: Foam::cell == const Foam::label
cell() == mesh().faceOwner()[face()]
^
/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/lagrangian/basic/lnInclude/particle.H(70): note: this candidate was rejected because arguments do not match
bool operator==(const particle&, const particle&);
^
/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/OpenFOAM/lnInclude/labelBits.H(123): note: this candidate was rejected because function is not visible
inline friend bool operator==(const labelBits& a, const labelBits& b)
^
/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/OpenFOAM/lnInclude/objectMapI.H(85): note: this candidate was rejected because arguments do not match
inline bool Foam::operator==(const objectMap& a, const objectMap& b)
^
/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/OpenFOAM/lnInclude/triFaceI.H(406): note: this candidate was rejected because arguments do not match
inline bool Foam::operator==(const triFace& a, const triFace& b)
^
(followed by lots of rejected candidates)
instantiation of "bool Foam::wallBoundedStreamLineParticle::move(TrackCloudType &, Foam::wallBoundedStreamLineParticle::trackingData &, Foam::scalar={Foam::doubleScalar={double}}) [with TrackCloudType=Foam::wallBoundedStreamLineParticleCloud]" at line 212 of "/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/lagrangian/basic/lnInclude/Cloud.C"
instantiation of "void Foam::Cloud<ParticleType>::move(TrackCloudType &, ParticleType::trackingData &, Foam::scalar={Foam::doubleScalar={double}}) [with ParticleType=Foam::wallBoundedStreamLineParticle, TrackCloudType=Foam::wallBoundedStreamLineParticleCloud]" at line 275 of "wallBoundedStreamLine/wallBoundedStreamLine.C"
wallBoundedStreamLine/wallBoundedParticleTemplates.C(138): error: no operator "=" matches these operands
operand types are: Foam::cell = Foam::label
cell() = nbrCelli;
^
detected during:
instantiation of "bool Foam::wallBoundedStreamLineParticle::move(TrackCloudType &, Foam::wallBoundedStreamLineParticle::trackingData &, Foam::scalar={Foam::doubleScalar={double}}) [with TrackCloudType=Foam::wallBoundedStreamLineParticleCloud]" at line 212 of "/share/software/OpenFOAM/OpenFOAM-v1912-ICC/src/lagrangian/basic/lnInclude/Cloud.C"
instantiation of "void Foam::Cloud<ParticleType>::move(TrackCloudType &, ParticleType::trackingData &, Foam::scalar={Foam::doubleScalar={double}}) [with ParticleType=Foam::wallBoundedStreamLineParticle, TrackCloudType=Foam::wallBoundedStreamLineParticleCloud]" at line 275 of "wallBoundedStreamLine/wallBoundedStreamLine.C"
compilation aborted for wallBoundedStreamLine/wallBoundedStreamLine.C (code 2)
make: *** [/share/software/OpenFOAM/OpenFOAM-v1912-ICC/build/linux64IccDPInt32Opt/src/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.o] Error 2
Environment information
OpenFOAM: v1912 (codes from https://sourceforge.net/projects/openfoam/files/v1912/OpenFOAM-v1912.tgz)
ThirdParty from https://sourceforge.net/projects/openfoam/files/v1912/ThirdParty-v1912.tgz
Intel suite: parallel_studio_xe_2020_cluster_edition
Intel icc: icc (ICC) 19.1.0.166 20191121
Intel MPI lib: for Linux* OS, Version 2019 Update 6 Build 20191024
OS Kernel: Linux version 3.10.0-1062.el7.x86_64 (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) )
OS: CentOS 7.7.1908
CPU: 72 * Intel(R) Xeon(R) Gold 6240 CPU # 2.60GHz
Solution
The problem is solved! Please refer to https://develop.openfoam.com/Development/openfoam/issues/1608.
I cannot build RTL8192EU driver on Kali Linux 5.2 for TP-Link WN821N. After running make in cd rtl8192eu-linux-driver (downloaded from https://github.com/jeremyb31/rtl8192eu-linux-driver):
# sudo apt update
Hit:1 http://kali.download/kali kali-rolling InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
511 packages can be upgraded. Run 'apt list --upgradable' to see them.
# git clone https://github.com/jeremyb31/rtl8192eu-linux-driver
fatal: destination path 'rtl8192eu-linux-driver' already exists and is not an empty directory.
# cd rtl8192eu-linux-driver
# make
make ARCH=x86_64 CROSS_COMPILE= -C /lib/modules/5.2.0-kali2-amd64/build M=/root/rtl8192eu-linux-driver modules
make[1]: Entering directory '/usr/src/linux-headers-5.2.0-kali2-amd64'
CC [M] /root/rtl8192eu-linux-driver/os_dep/osdep_service.o
In file included from /root/rtl8192eu-linux-driver/include/drv_types.h:35,
from /root/rtl8192eu-linux-driver/os_dep/osdep_service.c:24:
/root/rtl8192eu-linux-driver/include/wifi.h:1019: warning: "IEEE80211_MAX_AMPDU_BUF" redefined
#define IEEE80211_MAX_AMPDU_BUF 0x40
In file included from /root/rtl8192eu-linux-driver/include/osdep_service_linux.h:84,
from /root/rtl8192eu-linux-driver/include/osdep_service.h:45,
from /root/rtl8192eu-linux-driver/include/drv_types.h:32,
from /root/rtl8192eu-linux-driver/os_dep/osdep_service.c:24:
/usr/src/linux-headers-5.2.0-kali2-common/include/linux/ieee80211.h:1441: note: this is the location of the previous definition
#define IEEE80211_MAX_AMPDU_BUF 0x100
/root/rtl8192eu-linux-driver/os_dep/osdep_service.c: In function ‘isFileReadable’:
/root/rtl8192eu-linux-driver/os_dep/osdep_service.c:1970:28: error: implicit declaration of function ‘get_ds’; did you mean ‘get_da’? [-Werror=implicit-function-declaration]
oldfs = get_fs(); set_fs(get_ds());
^~~~~~
get_da
/root/rtl8192eu-linux-driver/os_dep/osdep_service.c:1970:28: error: incompatible type for argument 1 of ‘set_fs’
oldfs = get_fs(); set_fs(get_ds());
^~~~~~~~
In file included from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/uaccess.h:11,
from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/crypto.h:21,
from /usr/src/linux-headers-5.2.0-kali2-common/include/crypto/hash.h:11,
from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/uio.h:10,
from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/socket.h:8,
from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/compat.h:15,
from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/ethtool.h:17,
from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/netdevice.h:37,
from /root/rtl8192eu-linux-driver/include/osdep_service_linux.h:35,
from /root/rtl8192eu-linux-driver/include/osdep_service.h:45,
from /root/rtl8192eu-linux-driver/include/drv_types.h:32,
from /root/rtl8192eu-linux-driver/os_dep/osdep_service.c:24:
/usr/src/linux-headers-5.2.0-kali2-common/arch/x86/include/asm/uaccess.h:29:40: note: expected ‘mm_segment_t’ {aka ‘struct <anonymous>’} but argument is of type ‘int’
static inline void set_fs(mm_segment_t fs)
~~~~~~~~~~~~~^~
/root/rtl8192eu-linux-driver/os_dep/osdep_service.c: In function ‘retriveFromFile’:
/root/rtl8192eu-linux-driver/os_dep/osdep_service.c:1998:29: error: incompatible type for argument 1 of ‘set_fs’
oldfs = get_fs(); set_fs(get_ds());
^~~~~~~~
In file included from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/uaccess.h:11,
from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/crypto.h:21,
from /usr/src/linux-headers-5.2.0-kali2-common/include/crypto/hash.h:11,
from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/uio.h:10,
from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/socket.h:8,
from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/compat.h:15,
from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/ethtool.h:17,
from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/netdevice.h:37,
from /root/rtl8192eu-linux-driver/include/osdep_service_linux.h:35,
from /root/rtl8192eu-linux-driver/include/osdep_service.h:45,
from /root/rtl8192eu-linux-driver/include/drv_types.h:32,
from /root/rtl8192eu-linux-driver/os_dep/osdep_service.c:24:
/usr/src/linux-headers-5.2.0-kali2-common/arch/x86/include/asm/uaccess.h:29:40: note: expected ‘mm_segment_t’ {aka ‘struct <anonymous>’} but argument is of type ‘int’
static inline void set_fs(mm_segment_t fs)
~~~~~~~~~~~~~^~
/root/rtl8192eu-linux-driver/os_dep/osdep_service.c: In function ‘storeToFile’:
/root/rtl8192eu-linux-driver/os_dep/osdep_service.c:2032:29: error: incompatible type for argument 1 of ‘set_fs’
oldfs = get_fs(); set_fs(get_ds());
^~~~~~~~
In file included from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/uaccess.h:11,
from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/crypto.h:21,
from /usr/src/linux-headers-5.2.0-kali2-common/include/crypto/hash.h:11,
from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/uio.h:10,
from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/socket.h:8,
from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/compat.h:15,
from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/ethtool.h:17,
from /usr/src/linux-headers-5.2.0-kali2-common/include/linux/netdevice.h:37,
from /root/rtl8192eu-linux-driver/include/osdep_service_linux.h:35,
from /root/rtl8192eu-linux-driver/include/osdep_service.h:45,
from /root/rtl8192eu-linux-driver/include/drv_types.h:32,
from /root/rtl8192eu-linux-driver/os_dep/osdep_service.c:24:
/usr/src/linux-headers-5.2.0-kali2-common/arch/x86/include/asm/uaccess.h:29:40: note: expected ‘mm_segment_t’ {aka ‘struct <anonymous>’} but argument is of type ‘int’
static inline void set_fs(mm_segment_t fs)
~~~~~~~~~~~~~^~
cc1: some warnings being treated as errors
make[4]: *** [/usr/src/linux-headers-5.2.0-kali2-common/scripts/Makefile.build:284: /root/rtl8192eu-linux-driver/os_dep/osdep_service.o] Error 1
make[3]: *** [/usr/src/linux-headers-5.2.0-kali2-common/Makefile:1610: _module_/root/rtl8192eu-linux-driver] Error 2
make[2]: *** [Makefile:179: sub-make] Error 2
make[1]: *** [Makefile:8: all] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.2.0-kali2-amd64'
make: *** [Makefile:1700: modules] Error 2
How do I fix the compile errors?
go to mange:
download and install the only working drivers. It worked with default drivers for me but with extremely low "power" and dropping/poor connection. Now it works great, just as it should...
I am just a simple/new linux user so I can't offer any further support. But the mentioned site has detailed instructions. I was referred there by multiple other forums.
I wrote a simple kernel module to learn module_param feature of the kernel module. However, if I give the S_IWUGO, S_IRWXUGO or S_IALLUGO permissions for the perm field, I get the follwing compilation error:
[root#localhost param]# make -C $KDIR M=$PWD modules
make: Entering directory `/usr/src/kernels/3.11.10-301.fc20.i686+PAE'
CC [M] /root/ldd/misc/param/param/hello.o
/root/ldd/misc/param/param/hello.c:6:168: error: negative width in bit-field ‘<anonymous>’
module_param(a, int, S_IWUGO);
^
make[1]: *** [/root/ldd/misc/param/param/hello.o] Error 1
make: *** [_module_/root/ldd/misc/param/param] Error 2
make: Leaving directory `/usr/src/kernels/3.11.10-301.fc20.i686+PAE'
Compilation is successful for S_IRUGO or S_IXUGO (permission not containing Write permssion). I suppose I must be doing something wrong because from what I know, wrtie permission is legal. What am I doing wrong here?
The program:
#include<linux/module.h>
#include<linux/stat.h>
int a = 2;
module_param(a, int, S_IXUGO);
int f1(void){
return 0;
}
void f2(void){
}
module_init(f1);
module_exit(f2);
MODULE_AUTHOR("lavya");
MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("experiment with parameters");
Linux does not accept the S_IWOTH permission.
If you follow the macro chain behind module_param, you arrive to __module_param_call which includes:
BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2))
S_IWOTH == 2 so the test fails.
The negative width in bit-field error is merely is an artefact of the implementation of BUILD_BUG_ON_ZERO
Linux probably refuses to make module parameters world-writable for security reasons. You should be able to use narrower permissions such as S_IWUSR | S_IWGRP.
I'm trying to share a global variable between two modules in order to understand how to use the EXPORT_SYMBOL macro correctly, but I keep getting an Invalid paramaters error when I try to insert the second module.
In the first module foo.c:
#include <linux/module.h>
#include <linux/kernel.h>
extern unsigned myvar;
unsigned myvar = 42;
EXPORT_SYMBOL(myvar);
static int __init foo_init(void){
printk(KERN_INFO "HELLO FROM MODULE 1");
return 0;
}
static void __exit foo_exit(void){
printk(KERN_INFO "BYE FROM MODULE 1");
}
module_init(foo_init);
module_exit(foo_exit);
MODULE_LICENSE("GPL");
In the second module bar.c:
#include <linux/module.h>
#include <linux/kernel.h>
extern unsigned myvar;
static int __init bar_init(void){
printk(KERN_INFO "HELLO FROM MODULE 2");
printk(KERN_INFO "myvar: %u", myvar);
return 0;
}
static void __exit bar_exit(void){
printk(KERN_INFO "BYE FROM MODULE 2");
}
module_init(bar_init);
module_exit(bar_exit);
MODULE_LICENSE("GPL");
I compile each module in separate directories with separate Makefiles. Then I insert each module manually:
# insmod foo.ko
# insmod bar.ko
Error: could not insert module bar.ko: Invalid parameters
If I attempt to insert bar.ko first, I receive the expected unknown symbol error:
# insmod bar.ko
Error: could not insert module bar.ko: Unknown symbol in module
Here's the symbol dump:
# nm foo.ko | grep myvar
00000000ec933bae A __crc_myvar
0000000000001118 r __kcrctab_myvar
000000000000057c r __kstrtab_myvar
0000000000000b20 r __ksymtab_myvar
0000000000000180 D myvar
I'm running a Debian system (kernel v3.2.21) with a Xenomai patch applied:
# uname -r
3.2.21-xenomai-2.6.2.1-ipipe
Unfortunately, I don't think CONFIG_KALLSYMS_ALL is enabled, so I can't look in /proc/kallsyms/ to verify that myvar is actually exported.
I decided to poke around the system to try to find the cause of the error:
# dmesg | tail
[11169.107152] HELLO FROM MODULE 1
[11226.101245] bar: no symbol version for myvar
[11226.101254] bar: Unknown symbol myvar (err -22)
Looks like the problem wasn't with exporting the symbol, but rather accounting for the symbol version.
The solution is detailed in Documentation/kbuild/modules.txt and is quite simple: make sure the symbol has an entry in the Module.symvers file.
For example, in my case the two modules where located in /home/vilhelm/foo/ and /home/vilhelm/bar/ respectively. Since I compile each module separately, each directory has its own respective Makefile. First I executed make in the foo directory to generate the Module.symvers file in that directory for the foo module.
# make
Next I modified the Makefile for the bar module by inserting the following line at the top of the Makefile:
KBUILD_EXTRA_SYMBOLS := /home/vilhelm/foo/Module.symvers
Note that this is an absolute path!
Finally I execute make in the bar directory and insert the module manually:
# make
...
# insmod /home/vilhelm/foo/foo.ko
# insmod /home/vilhelm/bar/bar.ko
No errors, so that's a good sign.
And now the moment of truth:
# dmesg | tail
[12675.200451] HELLO FROM MODULE 1
[12715.743320] HELLO FROM MODULE 2
[12715.743328] myvar: 42
Success! :-)
I am writing a kernel module to manipute GPIOs. In initialization, the moduel needs to change the muplex of GPIOs.
[tld.c]
#include <mach-omap2/mux.h>
.
.
.
int open_gpio(void){
int result;
result = gpio_request_array(leds_gpios, ARRAY_SIZE(leds_gpios));
if(result != 0) {
printk("tld: cannot request gpio ports\n");
}
result = gpio_direction_output(LED_LE_PIN, 0);
omap_mux_set_gpio(OMAP_MUX_MODE7, LED_LE_PIN);
if(result != 0) {
printk("tld: cannot change GPIO muplex.\n");
gpio_free_array(leds_gpios, ARRAY_SIZE(leds_gpios));
}
return result;
}
static int tld_init(void) {
.
.
/* open gpio ports */
result = open_gpio();
.
.
}
.
module_init(tld_init);
.
Function omap_mux_set_gpio() is declared in Kernel_Source/arch/arm/mach-omap2/mux.h. So I include it in the source file.
The Makefile is also customized.
[Makefile]
CONFIG_CROSS_COMPILE =
CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)
ARCH ?= arm
SOURCE_DIR ?= /home/me/kerner_source
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
obj-m += tld.o
ccflags-y += -I$(SOURCE_DIR)/arch/arm
all:
make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(SOURCE_DIR) M=$(PWD) modules
clean:
rm *.o *.ko *.mod.*
I can get it compiled but there is warning:
WARNING: "omap_mux_set_gpio" [/home/me/projects/tld.ko] undefined!
When i run insmod, there is error in dmesg:
tld: Unknown symbol omap_mux_set_gpio (err 0)
I have checked the kernel symbol list by runing:
cat /proc/kallsyms | grep omap_mux_set_gpio
An function called omap_mux_set_gpio does exist.
I think the way I include the header file probably is causing the problem. The mux.h belongs to the kernel itself but i treat it like an external one.
What is right way to do it?
Thank you very much.
If a symbol is not marked as EXPORT_SYMBOL or EXPORT_SYMBOL_GPL, then you can not use it in kernel modules. This symbol does not appear to be marked in that way.