Results 1 to 7 of 7
I try to run the scull example:
"make" was all good and i have scull.o scull.ko
root@ubuntu:/home/rafael/examples/scull# ./scull_load
root@ubuntu:/home/rafael/examples/scull# dmesg
...
[17184723.168000] scullsingle registered at fd00008
[17184723.168000] sculluid registered at ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-23-2006 #1Just Joined!
- Join Date
- Feb 2006
- Posts
- 17
O'reilly Device Drivers chapter3 -scull problem
I try to run the scull example:
"make" was all good and i have scull.o scull.ko
root@ubuntu:/home/rafael/examples/scull# ./scull_load
root@ubuntu:/home/rafael/examples/scull# dmesg
...
[17184723.168000] scullsingle registered at fd00008
[17184723.168000] sculluid registered at fd00009
[17184723.168000] scullwuid registered at fd0000a
[17184723.168000] sullpriv registered at fd0000b
root@ubuntu:/home/rafael/examples/scull# ./scull.init start
Loading scull
./scull.o
(loading file ./scull.o)insmod: error inserting './scull.o': -1 Invalid module format
FAILED!
.
root@ubuntu:/home/rafael/examples/scull# dmesg
[17184831.176000] No module found in object
- 02-23-2006 #2Just Joined!
- Join Date
- Jan 2006
- Location
- India
- Posts
- 52
Hi,
Which kernel version is running on your system and which kernel version source code do you have?
If there are any mismatch then we get the error you mentioned.
--rajesh
- 02-23-2006 #3Just Joined!
- Join Date
- Feb 2006
- Posts
- 17
I have linux 2.6.15.4
and this example is from 2001
what can i do to run it?
- 02-24-2006 #4
Hi sirmoreno,
did you insmod scull.o in your script?
You have to insmod scull.ko
Could you post your Makefile and the contents of scull_load and scull.init?
regards
JAN
- 02-26-2006 #5Just Joined!
- Join Date
- Feb 2006
- Posts
- 1
before you start compling the module,you should compile your kernel first.
download the kernel from kernel.org,and uncompress it,then cd into the folder and
run:make gconfig
after you ran the "make gconfig",file ".config" will exist in the folder,then you can compile your module like this:
use your texteditor to create the "Makefile" file,with the contents below:
obj-m += module.o
and then:
make -C ~/kernel/linux-2.6.12/ SUBDIRS=$PWD modules
then,you will get the module.ko
however,you can`t use this module in your current system if there are any difference between sources from which the kernel are made.
so,you should use the same version of kernel as your system,and the module will then work.
so,given that we have launch "make gconfig",run:
make dep
make modules
make
make modules_install install
then you`ll get the kernel you want.
if you want to run multi "make " process you can add -jn after "make",like this
make -j10 modules
at last,edit /boot/grub/menu.lst,change the path of "kernel" and "initrd"
you will find the former has a file associated in "/boot/",such as vmlinuz-2.6.12-10-686,but the initrd should be manully made by yourself.
run "mkinirtd -o /boot/2.6.12.img 2.6.12",
and copy the .img file to /boot,and then change the contents of /boot/grub/menu.lst.
then you can reboot your computer and enjoy your new kernel!
by the way,you must choose the option of "kernel hacking",otherwise you can`t do anything like module programing.
my english isn`t very good,for i`m chinese,so please point out the mistake and misunderstand in my reply
regards~
xuecheng zhang
- 02-26-2006 #6Just Joined!
- Join Date
- Feb 2006
- Posts
- 17
Hi, well i think i'll try to recompile my kernel with hacking options.
the MAKEFILE:
ifeq ($(DEBUG),y)
DEBFLAGS = -O -g -DSCULL_DEBUG # "-O" is needed to expand inlines
else
DEBFLAGS = -O2
endif
CFLAGS += $(DEBFLAGS)
CFLAGS += -I$(LDDINC)
ifneq ($(KERNELRELEASE),)
# call from kernel build system
scull-objs := main.o pipe.o access.o
obj-m := scull.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
endif
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
depend .depend dep:
$(CC) $(CFLAGS) -M *.c > .depend
ifeq (.depend,$(wildcard .depend))
include .depend
endif
the Scull.Init file:
DEVICE="scull"
SECTION="misc"
# The list of filenames and minor numbers: $PREFIX is prefixed to all names
PREFIX="scull"
FILES=" 0 0 1 1 2 2 3 3 priv 16
pipe0 32 pipe1 33 pipe2 34 pipe3 35
single 48 uid 64 wuid 80"
INSMOD=/sbin/insmod; # use /sbin/modprobe if you prefer
function device_specific_post_load () {
true; # fill at will
}
function device_specific_pre_unload () {
true; # fill at will
}
# Everything below this line should work unchanged for any char device.
# Obviously, however, no options on the command line: either in
# /etc/${DEVICE}.conf or /etc/modules.conf (if modprobe is used)
# Optional configuration file: format is
# owner <ownername>
# group <groupname>
# mode <modename>
# options <insmod options>
CFG=/etc/${DEVICE}.conf
# kernel version, used to look for modules
KERNEL=`uname -r`
#FIXME: it looks like there is no misc section. Where should it be?
MODDIR="/lib/modules/${KERNEL}/kernel/drivers/${SECTION}"
if [ ! -d $MODDIR ]; then MODDIR="/lib/modules/${KERNEL}/${SECTION}"; fi
# Root or die
if [ "$(id -u)" != "0" ]
then
echo "You must be root to load or unload kernel modules"
exit 1
fi
# Read configuration file
if [ -r $CFG ]; then
OWNER=`awk "\\$1==\"owner\" {print \\$2}" $CFG`
GROUP=`awk "\\$1==\"group\" {print \\$2}" $CFG`
MODE=`awk "\\$1==\"mode\" {print \\$2}" $CFG`
# The options string may include extra blanks or only blanks
OPTIONS=`sed -n '/^options / s/options //p' $CFG`
fi
# Create device files
function create_files () {
cd /dev
local devlist=""
local file
while true; do
if [ $# -lt 2 ]; then break; fi
file="${DEVICE}$1"
mknod $file c $MAJOR $2
devlist="$devlist $file"
shift 2
done
if [ -n "$OWNER" ]; then chown $OWNER $devlist; fi
if [ -n "$GROUP" ]; then chgrp $GROUP $devlist; fi
if [ -n "$MODE" ]; then chmod $MODE $devlist; fi
}
# Remove device files
function remove_files () {
cd /dev
local devlist=""
local file
while true; do
if [ $# -lt 2 ]; then break; fi
file="${DEVICE}$1"
devlist="$devlist $file"
shift 2
done
rm -f $devlist
}
# Load and create files
function load_device () {
if [ -f $MODDIR/$DEVICE.o ]; then
devpath=$MODDIR/$DEVICE.o
echo
echo $devpath
echo
else if [ -f ./$DEVICE.o ]; then
devpath=./$DEVICE.o
echo
echo $devpath
echo
else
devpath=$DEVICE; # let insmod/modprobe guess
fi; fi
if [ "$devpath" != "$DEVICE" ]; then
echo -n " (loading file $devpath)"
fi
if $INSMOD $devpath $OPTIONS; then
MAJOR=`awk "\\$2==\"$DEVICE\" {print \\$1}" /proc/devices`
remove_files $FILES
create_files $FILES
device_specific_post_load
else
echo " FAILED!"
fi
}
# Unload and remove files
function unload_device () {
device_specific_pre_unload
/sbin/rmmod $DEVICE
remove_files $FILES
}
case "$1" in
start)
echo -n "Loading $DEVICE"
load_device
echo "."
;;
stop)
echo -n "Unloading $DEVICE"
unload_device
echo "."
;;
force-reload|restart)
echo -n "Reloading $DEVICE"
unload_device
load_device
echo "."
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload}"
exit 1
esac
exit 0
The Scull_load file:
module="scull"
device="scull"
mode="664"
# Group: since distributions do it differently, look for wheel or use staff
if grep -q '^staff:' /etc/group; then
group="staff"
else
group="wheel"
fi
# invoke insmod with all arguments we got
# and use a pathname, as insmod doesn't look in . by default
/sbin/insmod ./$module.ko $* || exit 1
# retrieve major number
major=$(awk "\$2==\"$module\" {print \$1}" /proc/devices)
# Remove stale nodes and replace them, then give gid and perms
# Usually the script is shorter, it's scull that has several devices in it.
rm -f /dev/${device}[0-3]
mknod /dev/${device}0 c $major 0
mknod /dev/${device}1 c $major 1
mknod /dev/${device}2 c $major 2
mknod /dev/${device}3 c $major 3
ln -sf ${device}0 /dev/${device}
chgrp $group /dev/${device}[0-3]
chmod $mode /dev/${device}[0-3]
rm -f /dev/${device}pipe[0-3]
mknod /dev/${device}pipe0 c $major 4
mknod /dev/${device}pipe1 c $major 5
mknod /dev/${device}pipe2 c $major 6
mknod /dev/${device}pipe3 c $major 7
ln -sf ${device}pipe0 /dev/${device}pipe
chgrp $group /dev/${device}pipe[0-3]
chmod $mode /dev/${device}pipe[0-3]
rm -f /dev/${device}single
mknod /dev/${device}single c $major 8
chgrp $group /dev/${device}single
chmod $mode /dev/${device}single
rm -f /dev/${device}uid
mknod /dev/${device}uid c $major 9
chgrp $group /dev/${device}uid
chmod $mode /dev/${device}uid
rm -f /dev/${device}wuid
mknod /dev/${device}wuid c $major 10
chgrp $group /dev/${device}wuid
chmod $mode /dev/${device}wuid
rm -f /dev/${device}priv
mknod /dev/${device}priv c $major 11
chgrp $group /dev/${device}priv
chmod $mode /dev/${device}priv
Thank you all
SirMoreno
- 03-01-2006 #7
Hi,
if I read your script correctly, your insmodding the .o file....
Change the following lines in your scull.init script:
toCode:devpath=$MODDIR/$DEVICE.o echo echo $devpath echo else if [ -f ./$DEVICE.o ]; then devpath=./$DEVICE.o
Code:devpath=$MODDIR/$DEVICE.ko echo echo $devpath echo else if [ -f ./$DEVICE.ko ]; then devpath=./$DEVICE.ko



