* cannot compile kernel module - headers missing
@ 2015-02-23 15:02 Jens Rapp
2015-02-23 15:08 ` Bruce Ashfield
0 siblings, 1 reply; 2+ messages in thread
From: Jens Rapp @ 2015-02-23 15:02 UTC (permalink / raw)
To: yocto
hi,
i have a simple hello world kernel module and i cannot compile it. linux
headers are missing
i tried to set -I $(OECORE_TARGET_SYSROOT)usr/src/kernel/include/
but there seems to be much more missing..
is there any way to do this easier?
here's what i have:
module.c
-------------
#include <linux/module.h>
#include <linux/spi.h>
#include <linux/gpio.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
/**
* initialisiert das Kernel - Modul
*/
int init_module(void) {
printk(KERN_DEBUG "Hallo Kernel!\n");
return 0;
}
void cleanup_module (void) {
printk (KERN_DEBUG "Ciao!\n");
}
and my Makefile
----------------------
# file Makefile
# copyright Copyright (c) 2012 Toradex AG
# [Software License Agreement]
# author $Author$
# version $Rev$
# date $Date$
# brief a simple makefile to (cross) compile.
# uses the openembedded provided sysroot and toolchain
# target linux on Colibri T20 / Colibri T30
# caveats -
##############################################################################
# Setup your project settings
##############################################################################
# Set the input source files, the binary name and used libraries to link
SRCS = module.c
PROG := module
LIBS =
CONF_LIBS =
C_FLAGS = -D__KERNEL__ -D__SMP__ -DMODULE -DMODVERSIONS
# Set flags to the compiler and linker
CFLAGS += -O2 -g -Wall `$(PKG-CONFIG) --cflags $(CONF_LIBS)`
$(ARCH_CFLAGS) $(C_FLAGS)
LDFLAGS += `$(PKG-CONFIG) --libs $(CONF_LIBS)`
##############################################################################
# Setup your build environment
##############################################################################
# Set the path to the oe built sysroot and
# Set the prefix for the cross compiler
OECORE_NATIVE_SYSROOT ?=
$(HOME)/oe-core/build/out-eglibc/sysroots/x86_64-linux/
OECORE_TARGET_SYSROOT ?=
$(HOME)/oe-core/build/out-eglibc/sysroots/apalis-imx6/
CROSS_COMPILE ?=
$(OECORE_NATIVE_SYSROOT)usr/bin/armv7at2hf-vfp-neon-angstrom-linux-gnueabi/arm-angstrom-linux-gnueabi-
##############################################################################
# The rest of the Makefile usually needs no change
##############################################################################
# Set differencies between native and cross compilation
ifneq ($(strip $(CROSS_COMPILE)),)
LDFLAGS += -L$(OECORE_TARGET_SYSROOT)usr/lib
-Wl,-rpath-link,$(OECORE_TARGET_SYSROOT)usr/lib
-L$(OECORE_TARGET_SYSROOT)lib -Wl,-rpath-link,$(OECORE_TARGET_SYSROOT)lib
ARCH_CFLAGS = -march=armv7-a -fno-tree-vectorize -mthumb-interwork
-mfloat-abi=hard -mtune=cortex-a9
BIN_POSTFIX =
PKG-CONFIG = export PKG_CONFIG_SYSROOT_DIR=$(OECORE_TARGET_SYSROOT); \
export
PKG_CONFIG_PATH=$(OECORE_TARGET_SYSROOT)/usr/lib/pkgconfig/; \
$(OECORE_NATIVE_SYSROOT)usr/bin/pkg-config
else
# Native compile
PKG-CONFIG = pkg-config
ARCH_CFLAGS =
# Append .x86 to the object files and binaries, so that native and cross
builds can live side by side
BIN_POSTFIX = .x86
endif
# Toolchain binaries
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)gcc
STRIP = $(CROSS_COMPILE)strip
RM = rm -f
# Sets the output filename and object files
PROG := $(PROG)$(BIN_POSTFIX)
OBJS = $(SRCS:.c=$(BIN_POSTFIX).o)
DEPS = $(OBJS:.o=.o.d)
# pull in dependency info for *existing* .o files
-include $(DEPS)
all: $(PROG)
$(PROG): $(OBJS) Makefile
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS)
#$(STRIP) $@
%$(BIN_POSTFIX).o: %.c
$(CC) -c $(CFLAGS) -o $@ $<
$(CC) -MM $(CFLAGS) $< > $@.d
clean:
$(RM) $(OBJS) $(PROG) $(DEPS)
.PHONY: all clean
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: cannot compile kernel module - headers missing
2015-02-23 15:02 cannot compile kernel module - headers missing Jens Rapp
@ 2015-02-23 15:08 ` Bruce Ashfield
0 siblings, 0 replies; 2+ messages in thread
From: Bruce Ashfield @ 2015-02-23 15:08 UTC (permalink / raw)
To: Jens Rapp, yocto
On 2015-02-23 10:02 AM, Jens Rapp wrote:
> hi,
>
> i have a simple hello world kernel module and i cannot compile it. linux
> headers are missing
> i tried to set -I $(OECORE_TARGET_SYSROOT)usr/src/kernel/include/
> but there seems to be much more missing..
What release are you using ? The kernel sources recently changed
in master (for the 1.8 release), so that could be catching you
in transition.
>
> is there any way to do this easier?
We have an example in meta-skeleton for a hello world module.
(meta-skeleton/recipes-kernel/hello-mod/). Have a look there and
it may answer most (if not all) questions.
Bruce
>
> here's what i have:
>
> module.c
> -------------
> #include <linux/module.h>
> #include <linux/spi.h>
> #include <linux/gpio.h>
> #include <linux/interrupt.h>
>
> #include <linux/kernel.h>
>
> /**
> * initialisiert das Kernel - Modul
> */
> int init_module(void) {
> printk(KERN_DEBUG "Hallo Kernel!\n");
> return 0;
> }
>
> void cleanup_module (void) {
> printk (KERN_DEBUG "Ciao!\n");
> }
>
>
> and my Makefile
> ----------------------
> # file Makefile
> # copyright Copyright (c) 2012 Toradex AG
> # [Software License Agreement]
> # author $Author$
> # version $Rev$
> # date $Date$
> # brief a simple makefile to (cross) compile.
> # uses the openembedded provided sysroot and toolchain
> # target linux on Colibri T20 / Colibri T30
> # caveats -
>
> ##############################################################################
>
> # Setup your project settings
> ##############################################################################
>
>
> # Set the input source files, the binary name and used libraries to link
> SRCS = module.c
> PROG := module
> LIBS =
> CONF_LIBS =
> C_FLAGS = -D__KERNEL__ -D__SMP__ -DMODULE -DMODVERSIONS
> # Set flags to the compiler and linker
> CFLAGS += -O2 -g -Wall `$(PKG-CONFIG) --cflags $(CONF_LIBS)`
> $(ARCH_CFLAGS) $(C_FLAGS)
> LDFLAGS += `$(PKG-CONFIG) --libs $(CONF_LIBS)`
>
> ##############################################################################
>
> # Setup your build environment
> ##############################################################################
>
>
> # Set the path to the oe built sysroot and
> # Set the prefix for the cross compiler
> OECORE_NATIVE_SYSROOT ?=
> $(HOME)/oe-core/build/out-eglibc/sysroots/x86_64-linux/
> OECORE_TARGET_SYSROOT ?=
> $(HOME)/oe-core/build/out-eglibc/sysroots/apalis-imx6/
> CROSS_COMPILE ?=
> $(OECORE_NATIVE_SYSROOT)usr/bin/armv7at2hf-vfp-neon-angstrom-linux-gnueabi/arm-angstrom-linux-gnueabi-
>
>
> ##############################################################################
>
> # The rest of the Makefile usually needs no change
> ##############################################################################
>
>
> # Set differencies between native and cross compilation
> ifneq ($(strip $(CROSS_COMPILE)),)
> LDFLAGS += -L$(OECORE_TARGET_SYSROOT)usr/lib
> -Wl,-rpath-link,$(OECORE_TARGET_SYSROOT)usr/lib
> -L$(OECORE_TARGET_SYSROOT)lib -Wl,-rpath-link,$(OECORE_TARGET_SYSROOT)lib
> ARCH_CFLAGS = -march=armv7-a -fno-tree-vectorize -mthumb-interwork
> -mfloat-abi=hard -mtune=cortex-a9
> BIN_POSTFIX =
> PKG-CONFIG = export PKG_CONFIG_SYSROOT_DIR=$(OECORE_TARGET_SYSROOT); \
> export
> PKG_CONFIG_PATH=$(OECORE_TARGET_SYSROOT)/usr/lib/pkgconfig/; \
> $(OECORE_NATIVE_SYSROOT)usr/bin/pkg-config
> else
> # Native compile
> PKG-CONFIG = pkg-config
> ARCH_CFLAGS =
> # Append .x86 to the object files and binaries, so that native and cross
> builds can live side by side
> BIN_POSTFIX = .x86
> endif
>
> # Toolchain binaries
> CC = $(CROSS_COMPILE)gcc
> LD = $(CROSS_COMPILE)gcc
> STRIP = $(CROSS_COMPILE)strip
> RM = rm -f
>
> # Sets the output filename and object files
> PROG := $(PROG)$(BIN_POSTFIX)
> OBJS = $(SRCS:.c=$(BIN_POSTFIX).o)
> DEPS = $(OBJS:.o=.o.d)
>
> # pull in dependency info for *existing* .o files
> -include $(DEPS)
>
> all: $(PROG)
>
> $(PROG): $(OBJS) Makefile
> $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS)
> #$(STRIP) $@
>
> %$(BIN_POSTFIX).o: %.c
> $(CC) -c $(CFLAGS) -o $@ $<
> $(CC) -MM $(CFLAGS) $< > $@.d
>
> clean:
> $(RM) $(OBJS) $(PROG) $(DEPS)
>
> .PHONY: all clean
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-02-23 15:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-23 15:02 cannot compile kernel module - headers missing Jens Rapp
2015-02-23 15:08 ` Bruce Ashfield
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.