How to insert dependent modules into Kernel? - linux

I have a Parrot AR.Drone 2.0 running Ubuntu and I want to connect it to the single board computer using cable. There are no Ethernet ports on the drone so I decided to use USB-Ethernet adapter (D-Link DUB-E100).
After entering uname -a in the terminal I get the following line:
Linux uclibc 2.6.32.9-g980dab2 #1 PREEMPT Mon Oct 6 11:50:23 CEST 2013 armv7l GNU/Linux
I followed this article and instead of module for wifi I used module for USB-Ethernet adapter.
This how I edited Makefile:
TARGET = dub_e100
OBJS = dub_e100.o
MDIR = drivers/net/usb
KDIR = /home/artemii/Downloads/linux
EXTRA_CFLAGS = -DEXPORT_SYMTAB
PWD = $(shell pwd)
DEST = /home/artemii/Downloads/linux/$(MDIR)
obj-m := $(TARGET).o
default:
make -C $(KDIR) SUBDIRS=$(PWD) modules
$(TARGET).o: $(OBJS)
$(LD) $(LD_RFLAG) -r -o $# $(OBJS)
install:
su -c "cp -v $(TARGET).ko $(DEST) && /sbin/depmod -a"
clean:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) clean
.PHONY: modules clean
-include $(KDIR)/Rules.make
After that I compiled the kernel with following lines:
make
export ARCH=arm
export CROSS_COMPILE=arm-none-linux-gnueabi-
make
Leter on I transfer generated 'dub_e100.ko' file into drone and ran the following command line:
insmod dube100.ko
Terminal threw an error insmod: can't insert 'dub_e100.ko': unknown symbol in module, or unknown parameter.
Checking dmesg | tail gives:
usb 1-1:1.0: uevent
dub_e100: Unknown symbol mii_ethtool_sset
dub_e100: Unknown symbol mii_link_ok
dub_e100: Unknown symbol mii_nway_restart
dub_e100: Unknown symbol generic_mii_ioctl
dub_e100: Unknown symbol mii_ethtool_gset
I assume that adapter's module depends on mii module, so I generated mii.ko file with following makefile:
TARGET = dub_e100
OBJS = dub_e100.o
MDIR = drivers/net/usb
KDIR = /home/artemii/Downloads/linux
EXTRA_CFLAGS = -DEXPORT_SYMTAB
PWD = $(shell pwd)
DEST = /home/artemii/Downloads/linux/$(MDIR)
obj-m := $(TARGET).o
obj-m += mii.o
default:
make -C $(KDIR) SUBDIRS=$(PWD) modules
$(TARGET).o: $(OBJS)
$(LD) $(LD_RFLAG) -r -o $# $(OBJS)
install:
su -c "cp -v $(TARGET).ko $(DEST) && /sbin/depmod -a"
clean:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) clean
.PHONY: modules clean
-include $(KDIR)/Rules.make
After that I consiquately run mii.ko and dube100.ko on the drone. All the modules visible in lsmod. But after inserting the adapter to the drone it crushes and reboots. After reboot this modules dessapiar from lsmod.
Is there something I am doing wrong? I might generated or ran modules improperly.

insmod does not handle module dependencies. It's manual page says:
insmod is a trivial program to insert a module into the kernel. Most users will want to use modprobe(8) instead, which is more clever and can handle module dependencies.
Note that you may have to run depmod before the modprobe automatic dependency loading works as intended.

Related

Raspberry PI: make command not working with below makefile

Makefile:
module=usb-it950x
EXTRA_CFLAGS = -DEXPORT_SYMTAB
CURRENT = $(shell uname -r)
KDIR = /lib/modules/$(CURRENT)/build
PWD = $(shell pwd)
MACHINE = $(shell uname -m)
KDIR26 := /lib/modules/$(CURRENT)/kernel/drivers/media
DEST = /lib/modules/$(CURRENT)/kernel/$(MDIR)
LMDIR26 := /lib/firmware
usb-it950x-objs := \
it950x-core.o it950x-drv.o iocontrol.o \
tuner.o cmd.o IT9133.o ADF4351.o \
IT9507.o Omega.o eagleTuner.o \
standard.o usb2impl.o modulatorUser.o user.o
obj-m += usb-it950x.o
default:
#(cp api/*.* ./; cp src/*.* ./)
make -s -C $(KDIR) SUBDIRS=$(PWD) modules
Also, I can compile the makefile at ubuntu.
But, I am trying compile abobe makefile at raspberry pi.
Error Log:
make -C /lib/modules/4.14.98-v7+/build SUBDIRS=/home/pi/it950x_driver modules
make[1]: *** /lib/modules/4.14.98-v7+/build: No such file or directory. Stop.
Makefile:20: recipe for target 'default' failed
make: *** [default] Error 2
How I can compile this makefile at raspberry pi(raspbian)?
You do not have a Makefile at /lib/modules/4.14.98-v7+/build on your pi. (your initial recipe for default runs, but then calls make with a -C that points to a directory with no makefile, and your error message comes from that).
Try doing an ls /lib/modules/, and see what directories it has in there. Note that this web page implies that you have to install the kernel headers onto a pi board manually...

How to build a linux kernel module against with a prebuilt kernel output directory?

My customer send me the prebuilt kernel output directory(They can not release the kernel source tree to us). This output directory is as below(under /home/michael/Clients/android_p_Hzh/kernel/kernel/):
arch
block
build-in.o
certs
...
.config
Makefile
Module.symvers
source (symbol link to a local source tree in my customer's file system)
Is it possible to build my external module against with this directory?
/home/michael/Source/Linux/br_driver is my driver's directory. I have tried to build my driver under this directory as below make command:
make CROSS_COMPILE=x86_64-poky-linux- -C
/home/michael/Clients/android_p_Hzh/kernel/kernel/ M=pwd $1
It fails with below output:
*** No rule to make target '/home/michael/Source/Linux/br_driver/common.o' needed by ...
The Makefile under br_driver is like below:
brt-objs := $(BRTOFILES)
obj-$(DRIVER_TYPE) += brt.o
all:
#echo "$(MAKE) --no-print-directory -C $(KDIR) SUBDIRS=$(CURDIR) modules"
#$(MAKE) --no-print-directory -C $(KDIR) SUBDIRS=$(CURDIR) modules
clean:
rm -rf *.o *.ko *.mod.c *~ .*.cmd *.o.cmd .*.o.cmd \
Module.symvers modules.order .tmp_versions modules.builtin
install:
#$(MAKE) --no-print-directory -C $(KDIR) \
SUBDIRS=$(CURDIR) modules_install
I have resolved this problem. The only things I need is the .config and Modules.symvers. The key operation is make oldconfig and modules_prepare.

Unable to load kernel module 'elan_i2c_core.ko'

I'm trying to load a custom made(sort of) module to get my touchpad to work. I downloaded "elan_i2c_core.c" and "elan_i2c.h" from github. Put them together on a folder made a "Makefile"(on the same folder) like:
ifneq ($(KERNELRELEASE),)
obj-m := elan_i2c_core.o
else
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
$(MAKE) -C $(KDIR) M=$(PWD) modules
install:
$(MAKE) -C $(KDIR) M=$(PWD) modules_install
%:
$(MAKE) -C $(KDIR) M=$(PWD) $#
endif
When I ran sudo make it returned .ko files along with some other files but, returned some warnings too:
WARNING: "elan_i2c_ops" [/home/name/Templates/elan/elan_i2c_core.ko] undefined!
WARNING: "elan_smbus_ops" [/home/name/Templates/elan/elan_i2c_core.ko] undefined!
I tried
insmod elan_i2c_core.ko`
which returned:
insmod: ERROR: could not insert module elan_i2c_core.ko: Unknown symbol in module
The output of
depmod elan_i2c_core.ko`
was
insmod: ERROR: could not insert module elan_i2c_core.ko: Unknown symbol in module
How do I fix it? Do I have to recompile the whole kernel from scratch or am I doing something wrong?
Additional information:
Kernel version- 4.18.0-10-generic
OS- Ubuntu 18.10

How to provide include directory path in kernel module Makefile

I was learning kernel interrupt using a small demo kernel module
which use these two header include
asm/exception.h
asm/mach/irq.h
My Makefile is
ifeq (${KERNELRELEASE},)
KERNEL_SOURCE := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
make -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules
clean:
make -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
else
obj-m := irq_demo.o
endif
The error I am getting
irq_demo.c:9:27: fatal error: asm/exception.h: No such file or directory
#include <asm/exception.h>
I found asm/exception.h in my system in /usr/src/linux-headers-3.16.0-30-generic/arch/arm/include/
[1]But how to include this path in Makefile
[2]Is /usr/src/linux-headers-3.16.0-30-generic/include/asm-generic/ linked with arch/arm/include/asm/ ? if yes , than How ?
First try
adding ARCH=arm after make
i.e.
make ARCH=arm -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules
============================= OR =============================
Can you try adding line before make
CARGS = -I /lib/modules/$(shell uname -r)/arch/arm/include/
make $(CARGS) -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules

Makefile for kernel kecho command issue

This a makefile for compiling the kernel module.
# Makefile – makefile of our first driver
#
# if KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq (${KERNELRELEASE},)
obj-m = first-driver.o
# Otherwise we were called directly from the command line.
# Invoke the kernel build system.
else
KERNEL_SOURCE := /lib/modules/2.6.32-504.8.1.el6.x86_64/build
PWD := $(shell pwd)
default:
${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules
#echo kernel first-driver is ready
#$(kecho) 'Kernel: $# is ready'
clean:
${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
endif
.PHONY : install remove
install :
sudo insmod first-driver.ko
remove :
sudo rmmod first-driver
Here I have used echo and kecho as per kernel makefile documantation but it giving the following error:
make -C /lib/modules/2.6.32-504.8.1.el6.x86_64/build SUBDIRS=/home/betatest/Device-Driver-Test modules
make[1]: Entering directory '/usr/src/kernels/2.6.32-504.8.1.el6.x86_64'
Building modules, stage 2.
MODPOST 1 modules
make[1]: Leaving directory '/usr/src/kernels/2.6.32-504.8.1.el6.x86_64'
kernel first-driver is ready
make: Kernel: default is ready: Command not found
Makefile:16: recipe for target 'default' failed
make: *** [default] Error 127
I am using GNU make version 4.1 and gcc version 4.4.7 where am I going wrong. Thanks.....
What is kecho variable's is assigned to? in the line #$(kecho) 'Kernel: $# is ready' kecho's value is null so the make considers only #$(kecho) 'Kernel: $# is ready' as a rule.
Did you forget to assign kecho to something at the beginning of the file? Like
kecho='echo'

Resources