LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Have a trouble with compiling simple dirver. (https://www.linuxquestions.org/questions/programming-9/have-a-trouble-with-compiling-simple-dirver-695958/)

sulacco 01-10-2009 05:04 PM

Quote:

Originally Posted by map250r (Post 3403110)
If I google linux/types.h:198: error: expected, I get several results.
http://lkml.indiana.edu/hypermail/li...10.1/1854.html

What I searched for is part of the first line with an error.

Assuming the link I provided helps, the problem is that you compiled in the same directory that the source is in. You're allowed to, but I think it's frowned upon. What I do is to use O=../build2.6.28 as one of the args for make each time. (do mkdir ../build2.6.28 first though!)

I feel you are very close at it. Can you explain more. How do I know if
i compiled in the same directory that sources are?
I feel something wrong with symlink too. That is the major part of
errors in compilation of my driver.
Though you link didn't help, cause `make mrproper` dont work.
there are no such option in makefile mrproper i think

bgeddy 01-11-2009 08:48 AM

Ok - this is very odd. I have an even simpler Makefile which will require some command line arguments to make. You should change directory to the directory of hello.c and create a file called, for example, hello.sh. Then make it executable with
Code:

chmod +x hello.sh
Then run it with
Code:

./hello.sh
Be aware that if you already have a subdirectory temp/ off the hello.c directory then it will be erased. This will create a new directory temp/ off the hello.c directory, create a Makefile and run it. It should produce a module hello.ko which should be listed at the end of the make run. Here is the hello.sh to create :

Code:

#!/bin/bash
rm -rf temp/
mkdir temp
cp hello.c temp/
cd temp
cat > Makefile << EOF
obj-m := hello.o

EOF
make -C /lib/modules/$(uname -r)/build  M=$(pwd) modules
ls -al hello*
exit 0


jiml8 01-11-2009 02:16 PM

Quote:

Originally Posted by sulacco (Post 3403900)
2bgeddy

if I run only:
Code:

make
here what I've got for answer:
Code:

make: Nothing to be done for `default'.

Delete all .o files in the directory, then run make again. The makefile you have been given is correct and is what you want to use for a kernel driver. There is no problem compiling into the same directory. The message basically was just telling you that make thinks your executable is up to date.

bgeddy 01-11-2009 04:53 PM

Quote:

Delete all .o files in the directory, then run make again.
I have already told the OP to do this - here was my message :
Quote:

Just to be sure all is well try this :

Quote:
rm hello.{mod.*,o,ko}
make
I hope he/she hasn't been ignoring my advice as this would explain the confusion.

sulacco 01-12-2009 09:24 PM

Quote:

Originally Posted by bgeddy (Post 3404903)
I have already told the OP to do this - here was my message :


I hope he/she hasn't been ignoring my advice as this would explain the confusion.

tnx. I'm not ignoring just there so many details while trying to compile in linux world...

sulacco 01-12-2009 09:35 PM

there are no files .o, mod.*, *.ko and still when I try to send command
`make` there is answer:
make: Nothing to be done for `default'.

sulacco 01-12-2009 11:01 PM

Quote:

Originally Posted by bgeddy (Post 3404471)
Ok - this is very odd. I have an even simpler Makefile which will require some command line arguments to make. You should change directory to the directory of hello.c and create a file called, for example, hello.sh. Then make it executable with
Code:

chmod +x hello.sh
Then run it with
Code:

./hello.sh
Be aware that if you already have a subdirectory temp/ off the hello.c directory then it will be erased. This will create a new directory temp/ off the hello.c directory, create a Makefile and run it. It should produce a module hello.ko which should be listed at the end of the make run. Here is the hello.sh to create :

Code:

#!/bin/bash
rm -rf temp/
mkdir temp
cp hello.c temp/
cd temp
cat > Makefile << EOF
obj-m := hello.o

EOF
make -C /lib/modules/$(uname -r)/build  M=$(pwd) modules
ls -al hello*
exit 0


UNBELIEVABLE!!! This is your last advice is REAL GOLDEN!!.
Thank you very much it worked now! It compiled and created bunch of
files with .ko, .o and so on!!!

sulacco 01-13-2009 10:11 PM

2bgeddy
can you explain pleas what it does?

Code:

#!/bin/bash
rm -rf temp/
mkdir temp
cp hello.c temp/
cd temp
cat > Makefile << EOF
obj-m := hello.o

EOF
make -C /lib/modules/$(uname -r)/build  M=$(pwd) modules
ls -al hello*
exit 0

next commands escape my understanding:
Code:

cat > Makefile << EOF
obj-m := hello.o
EOF
make -C /lib/modules/$(uname -r)/build  M=$(pwd) modules

Those four lines, I just don't get it.

bgeddy 01-14-2009 07:54 AM

Quote:

cat > Makefile << EOF
obj-m := hello.o
EOF
This is what's known as a "here document". It creates a file called "Makefile" with one line "obj-m: hello.o"
Quote:

make -C /lib/modules/$(uname -r)/build M=$(pwd) modules
This runs make with the target "modules" for the module in the current directory "$(pwd)" and the kernel source at "/lib/modules/$(uname -r)/build". Make changes directory to this before running the make.

sulacco 01-15-2009 02:06 PM

I'm very sorry, but driver again refused to compile!!!

Code:

CC [M]  /home/ushka/temp/hello.o
In file included from /usr/src/linux-2.6.28/arch/x86/include/asm/processor.h:19,
                from include/linux/prefetch.h:15,
                from include/linux/list.h:7,
                from include/linux/module.h:10,
                from /home/ushka/temp/hello.c:4:
/usr/src/linux-2.6.28/arch/x86/include/asm/page.h: In function ‘native_pte_flags’:
/usr/src/linux-2.6.28/arch/x86/include/asm/page.h:152: error: ‘phys_addr_t’ undeclared (first use in this function)
/usr/src/linux-2.6.28/arch/x86/include/asm/page.h:152: error: (Each undeclared identifier is reported only once
/usr/src/linux-2.6.28/arch/x86/include/asm/page.h:152: error: for each function it appears in.)
make[1]: *** [/home/ushka/temp/hello.o] Error 1
make: *** [_module_/home/ushka/temp] Error 2
make: Leaving directory `/usr/src/linux-2.6.28'
-rw-r--r-- 1 root root 916 2009-01-15 17:57 hello.c


sulacco 01-15-2009 03:44 PM

Interesting thing when I have tried to compile kernel: linux-2.6.28 with make utility
the same error in page.h was up. Funny thing linux!!!

bgeddy 01-16-2009 09:48 AM

Quote:

Interesting thing when I have tried to compile kernel: linux-2.6.28 with make utility
the same error in page.h was up. Funny thing linux!!!
Do you mean you haven't been able to successfully compile a kernel ? If this is the case then you really should have mentioned it earlier.

Installing and building a kernel source tree is the FIRST THING you should do when wanting to compile you own modules ! If the build process for the kernel fails then you will have problems with your modules.

Quote:

While trying to compile a this simple piece of software I have went through many difficulties such as compiling and installing kernel and
learned much things but still have errors. I learned that some headers needed to be installed, but there so many Linux clones and everyone of them use different schedules to do this.
I took this to mean that you had successfully built a kernel from source. It would seem not.

You must concentrate on successfully building a kernel first eliminating any build errors before continuing. I just wish you would have made this clear at the outset.

Actually this is getting highly confusing as :-
Quote:

UNBELIEVABLE!!! This is your last advice is REAL GOLDEN!!.
Thank you very much it worked now! It compiled and created bunch of
files with .ko, .o and so on!!!
reads like the device driver build worked. Are you saying it worked and now doesn't or it never worked at all ? If the process resulted in a .ko (module) file then it worked. This latest post implies that it didn't.

Before continuing I suggest you study The Linux Kernel in a Nutshell and Linx Device Drivers third edition and in future please give out relevant information at the outset - it would save a lot of time all round.


All times are GMT -5. The time now is 01:11 AM.