Welcome! Log In Create A New Profile

Advanced

Building kernel module for 4.17.2 kernel

Posted by ayosher 
Building kernel module for 4.17.2 kernel
July 03, 2018 09:11AM
Folks,

I am trying to build cryptodev module.
I found that trying to build almost any kernel module fails.
I believe something wrong with kernel sources. I installed linux-headers-4.17.2-kirkwood-tld-1_1.0_armel.deb with dpkg, looks like that is not enough.
m-a prepare worked fine, but building module fails, probably due to wrongly installed kernel sources...

root@pogoplug:/home/cryptodev/cryptodev-linux# make V=1
make -C /lib/modules/4.17.2-kirkwood-tld-1/build M=/home/cryptodev/cryptodev-linux modules
make[1]: Entering directory '/usr/src/linux-headers-4.17.2-kirkwood-tld-1'
test -e include/generated/autoconf.h -a -e include/config/auto.conf || (                \
echo >&2;                                                       \
echo >&2 "  ERROR: Kernel configuration is invalid.";           \
echo >&2 "         include/generated/autoconf.h or include/config/auto.conf are missing.";\
echo >&2 "         Run 'make oldconfig && make prepare' on kernel src to fix it.";      \
echo >&2 ;                                                      \
/bin/false)
mkdir -p /home/cryptodev/cryptodev-linux/.tmp_versions ; rm -f /home/cryptodev/cryptodev-linux/.tmp_versions/*
make -f ./scripts/Makefile.build obj=/home/cryptodev/cryptodev-linux
(cat /dev/null;   echo kernel//home/cryptodev/cryptodev-linux/cryptodev.ko;) > /home/cryptodev/cryptodev-linux/modules.order
  gcc -Wp,-MD,/home/cryptodev/cryptodev-linux/.ioctl.o.d  -nostdinc -isystem /usr/lib/gcc/arm-linux-gnueabi/6/include -I./arch/arm/include -I./arch/arm/include/generated  -I./include -I./arch/arm/include/uapi -I./arch/arm/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -mlittle-endian -DCONFIG_CC_STACKPROTECTOR -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-PIE -DCC_HAVE_ASM_GOTO -fno-dwarf2-cfi-asm -fno-ipa-sra -mabi=aapcs-linux -mno-thumb-interwork -mfpu=vfp -funwind-tables -marm -Wa,-mno-warn-deprecated -D__LINUX_ARM_ARCH__=5 -march=armv5te -mtune=xscale -msoft-float -Uarm -fno-delete-null-pointer-checks -Wno-frame-address -Os -Wno-maybe-uninitialized --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fstack-protector-strong -Wno-unused-but-set-variable -Wno-unused-const-variable -fomit-frame-pointer -fno-var-tracking-assignments -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fno-merge-all-constants -fmerge-constants -fno-stack-check -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -I/home/cryptodev/cryptodev-linux  -DMODULE  -DKBUILD_BASENAME='"ioctl"' -DKBUILD_MODNAME='"cryptodev"' -c -o /home/cryptodev/cryptodev-linux/.tmp_ioctl.o /home/cryptodev/cryptodev-linux/ioctl.c
In file included from ./include/linux/netfilter.h:8:0,
                 from ./include/linux/netfilter/nf_conntrack_tuple_common.h:6,
                 from ./include/linux/netfilter/nf_conntrack_dccp.h:29,
                 from ./include/net/netns/conntrack.h:11,
                 from ./include/net/net_namespace.h:27,
                 from ./include/linux/netdevice.h:42,
                 from ./include/linux/rtnetlink.h:7,
                 from /home/cryptodev/cryptodev-linux/ioctl.c:47:
./include/linux/if.h:28:54: fatal error: sys/socket.h: No such file or directory
 #include <sys/socket.h>   /* for struct sockaddr.  */
                                                      ^
compilation terminated.
scripts/Makefile.build:312: recipe for target '/home/cryptodev/cryptodev-linux/ioctl.o' failed
make[2]: *** [/home/cryptodev/cryptodev-linux/ioctl.o] Error 1
Makefile:1571: recipe for target '_module_/home/cryptodev/cryptodev-linux' failed
make[1]: *** [_module_/home/cryptodev/cryptodev-linux] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.17.2-kirkwood-tld-1'
Makefile:27: recipe for target 'build' failed
make: *** [build] Error 2

Can somebody advice what to do in such situation?

ayosher
Re: Building kernel module for 4.17.2 kernel
July 03, 2018 02:22PM
Re: Building kernel module for 4.17.2 kernel
July 03, 2018 03:21PM
bodhi,

The (1) I found myself:
root@pogoplug:~# ls -la  /lib/modules/$(uname -r)/build
lrwxrwxrwx 1 root root 44 Jul  3 01:06 /lib/modules/4.17.2-kirkwood-tld-1/build -> /usr/src/linux-headers-4.17.2-kirkwood-tld-1
root@pogoplug:~#

However (2) "make cryptodev worked fine" is not true for me.

On my VirtualBox debian it works OK (while it has kernel 4.9):
root@debian-ayosher:/home# mkdir cryptodev
root@debian-ayosher:/home# cd cryptodev
root@debian-ayosher:/home/cryptodev# git clone https://github.com/cryptodev-linux/cryptodev-linux
Cloning into 'cryptodev-linux'...
remote: Counting objects: 4298, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4298 (delta 0), reused 1 (delta 0), pack-reused 4295
Receiving objects: 100% (4298/4298), 1.92 MiB | 1.02 MiB/s, done.
Resolving deltas: 100% (2405/2405), done.
root@debian-ayosher:/home/cryptodev# cd cryptodev-linux
root@debian-ayosher:/home/cryptodev/cryptodev-linux# make
make -C /lib/modules/4.9.0-6-amd64/build M=/home/cryptodev/cryptodev-linux modules
make[1]: Entering directory '/usr/src/linux-headers-4.9.0-6-amd64'
  CC [M]  /home/cryptodev/cryptodev-linux/ioctl.o
  CC [M]  /home/cryptodev/cryptodev-linux/main.o
  CC [M]  /home/cryptodev/cryptodev-linux/cryptlib.o
  CC [M]  /home/cryptodev/cryptodev-linux/authenc.o
  CC [M]  /home/cryptodev/cryptodev-linux/zc.o
  CC [M]  /home/cryptodev/cryptodev-linux/util.o
  LD [M]  /home/cryptodev/cryptodev-linux/cryptodev.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/cryptodev/cryptodev-linux/cryptodev.mod.o
  LD [M]  /home/cryptodev/cryptodev-linux/cryptodev.ko
make[1]: Leaving directory '/usr/src/linux-headers-4.9.0-6-amd64'
root@debian-ayosher:/home/cryptodev/cryptodev-linux#

So something maybe wrong with specific kernel version (4.17) or specific ARM port.
cryptodev.org claims support for kernel 4.17

Please help
ayosher
Re: Building kernel module for 4.17.2 kernel
July 03, 2018 06:30PM
ayosher Wrote:
-------------------------------------------------------
> bodhi,
>
> The (1) I found myself:
>
> root@pogoplug:~# ls -la  /lib/modules/$(uname
> -r)/build
> lrwxrwxrwx 1 root root 44 Jul  3 01:06
> /lib/modules/4.17.2-kirkwood-tld-1/build ->
> /usr/src/linux-headers-4.17.2-kirkwood-tld-1
> root@pogoplug:~#
>
>
> However (2) "make cryptodev worked fine" is not
> true for me.
>
> On my VirtualBox debian it works OK (while it has
> kernel 4.9):
>
> root@debian-ayosher:/home# mkdir cryptodev
> root@debian-ayosher:/home# cd cryptodev
> root@debian-ayosher:/home/cryptodev# git clone
> https://github.com/cryptodev-linux/cryptodev-linux
> Cloning into 'cryptodev-linux'...
> remote: Counting objects: 4298, done.
> remote: Compressing objects: 100% (3/3), done.
> remote: Total 4298 (delta 0), reused 1 (delta 0),
> pack-reused 4295
> Receiving objects: 100% (4298/4298), 1.92 MiB |
> 1.02 MiB/s, done.
> Resolving deltas: 100% (2405/2405), done.
> root@debian-ayosher:/home/cryptodev# cd
> cryptodev-linux
> root@debian-ayosher:/home/cryptodev/cryptodev-linux#
> make
> make -C /lib/modules/4.9.0-6-amd64/build
> M=/home/cryptodev/cryptodev-linux modules
> make[1]: Entering directory
> '/usr/src/linux-headers-4.9.0-6-amd64'
>   CC [M]  /home/cryptodev/cryptodev-linux/ioctl.o
>   CC [M]  /home/cryptodev/cryptodev-linux/main.o
>   CC [M] 
> /home/cryptodev/cryptodev-linux/cryptlib.o
>   CC [M] 
> /home/cryptodev/cryptodev-linux/authenc.o
>   CC [M]  /home/cryptodev/cryptodev-linux/zc.o
>   CC [M]  /home/cryptodev/cryptodev-linux/util.o
>   LD [M] 
> /home/cryptodev/cryptodev-linux/cryptodev.o
>   Building modules, stage 2.
>   MODPOST 1 modules
>   CC     
> /home/cryptodev/cryptodev-linux/cryptodev.mod.o
>   LD [M] 
> /home/cryptodev/cryptodev-linux/cryptodev.ko
> make[1]: Leaving directory
> '/usr/src/linux-headers-4.9.0-6-amd64'
> root@debian-ayosher:/home/cryptodev/cryptodev-linux#
> 
>
>
> So something maybe wrong with specific kernel
> version (4.17) or specific ARM port.
> cryptodev.org claims support for kernel 4.17
>
> Please help
> ayosher

I have not played with this cryptodev for a while. Can you try to build some other module to see if it behaves the same way?

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Building kernel module for 4.17.2 kernel
July 04, 2018 11:24AM
bodhi,

I did build example "Hello World!" module from here. It builds OK. However, if I am trying to include linux/if.h (let assume I want to build module related to the networking), it fails to build.

root@pogoplug:~/src/lkm_example# make
make -C /lib/modules/4.17.2-kirkwood-tld-1/build M=/root/src/lkm_example modules
make[1]: Entering directory '/usr/src/linux-headers-4.17.2-kirkwood-tld-1'
  CC [M]  /root/src/lkm_example/lkm_example.o
In file included from /root/src/lkm_example/lkm_example.c:6:0:
./include/linux/if.h:28:54: fatal error: sys/socket.h: No such file or directory
 #include <sys/socket.h>   /* for struct sockaddr.  */
                                                      ^
compilation terminated.
scripts/Makefile.build:318: recipe for target '/root/src/lkm_example/lkm_example.o' failed
make[2]: *** [/root/src/lkm_example/lkm_example.o] Error 1
Makefile:1571: recipe for target '_module_/root/src/lkm_example' failed
make[1]: *** [_module_/root/src/lkm_example] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.17.2-kirkwood-tld-1'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2

Here is my code:
root@pogoplug:~/src/lkm_example# cat lkm_example.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <linux/if.h>

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Robert W. Oliver II");
MODULE_DESCRIPTION("A simple example Linux module.");
MODULE_VERSION("0.01");

#define DEVICE_NAME "lkm_example"
#define EXAMPLE_MSG "Hello, World!\n"
#define MSG_BUFFER_LEN 15

/* Prototypes for device functions */
static int device_open(struct inode *, struct file *);
static int device_release(struct inode *, struct file *);
static ssize_t device_read(struct file *, char *, size_t, loff_t *);
static ssize_t device_write(struct file *, const char *, size_t, loff_t *);

static int major_num;
static int device_open_count = 0;
static char msg_buffer[MSG_BUFFER_LEN];
static char *msg_ptr;

/* This structure points to all of the device functions */
static struct file_operations file_ops = {
 .read = device_read,
 .write = device_write,
 .open = device_open,
 .release = device_release
};

/* When a process reads from our device, this gets called. */
static ssize_t device_read(struct file *flip, char *buffer, size_t len, loff_t *offset) {
 int bytes_read = 0;
 /* If we’re at the end, loop back to the beginning */
 if (*msg_ptr == 0) {
 msg_ptr = msg_buffer;
 }
 /* Put data in the buffer */
 while (len && *msg_ptr) {
 /* Buffer is in user data, not kernel, so you can’t just reference
 * with a pointer. The function put_user handles this for us */
 put_user(*(msg_ptr++), buffer++);
 len--;
 bytes_read++;
 }
 return bytes_read;
}

/* Called when a process tries to write to our device */
static ssize_t device_write(struct file *flip, const char *buffer, size_t len, loff_t *offset) {
 /* This is a read-only device */
 printk(KERN_ALERT "This operation is not supported.\n");
 return -EINVAL;
}

/* Called when a process opens our device */
static int device_open(struct inode *inode, struct file *file) {
 /* If device is open, return busy */
 if (device_open_count) {
 return -EBUSY;
 }
 device_open_count++;
 try_module_get(THIS_MODULE);
 return 0;
}

/* Called when a process closes our device */
static int device_release(struct inode *inode, struct file *file) {
 /* Decrement the open counter and usage count. Without this, the module would not unload. */
 device_open_count--;
 module_put(THIS_MODULE);
 return 0;
}

static int __init lkm_example_init(void) {
 /* Fill buffer with our message */
 strncpy(msg_buffer, EXAMPLE_MSG, MSG_BUFFER_LEN);
 /* Set the msg_ptr to the buffer */
 msg_ptr = msg_buffer;
 /* Try to register character device */
 major_num = register_chrdev(0, "lkm_example", &file_ops);
 if (major_num < 0) {
 printk(KERN_ALERT "Could not register device: %d\n", major_num);
 return major_num;
 } else {
 printk(KERN_INFO "lkm_example module loaded with device major number %d\n", major_num);
 return 0;
 }
}

static void __exit lkm_example_exit(void) {
 /* Remember - we have to clean up after ourselves. Unregister the character device. */
 unregister_chrdev(major_num, DEVICE_NAME);
 printk(KERN_INFO "Goodbye, World!\n");
}

/* Register module functions */
module_init(lkm_example_init);
module_exit(lkm_example_exit);

And here is my makefile:
root@pogoplug:~/src/lkm_example# cat Makefile
obj-m += lkm_example.o

all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

test:
        # We put a — in front of the rmmod command to tell make to ignore
        # an error in case the module isn’t loaded.
        -rmmod lkm_example
        # Clear the kernel log without echo
        dmesg -C
        # Insert the module
        insmod lkm_example.ko
        # Display the kernel log
        dmesg
Re: Building kernel module for 4.17.2 kernel
July 04, 2018 05:50PM
ayosher,

I won't be able to get to my boxes today, and perhaps in a couple days.

Anybody who has tried to compile module and can chime in?

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Building kernel module for 4.17.2 kernel
December 18, 2018 03:04PM
Hi both,
I'm seeing the same errors as Ayosher trying to build cryptodev (using your 4.14 kernel) on my box (NSA320S).
I'll check it with the Debian Marvell kernel (Buster has a 4.18 image) when I get a chance over the next couple of weeks.
Re: Building kernel module for 4.17.2 kernel
December 18, 2018 05:03PM
OK, so the module compiles against the headers from the standard Debian distro (4.18-marvell). Obviously it won't work with our kernels though, so I can't test it just yet.
So there's definitely something with the headers from our our kernels that is causing these compile errors...
Re: Building kernel module for 4.17.2 kernel
December 18, 2018 08:12PM
Micky Wicky,

> OK, so the module compiles against the headers
> from the standard Debian distro (4.18-marvell).
> Obviously it won't work with our kernels though,
> so I can't test it just yet.
> So there's definitely something with the headers
> from our our kernels that is causing these compile
> errors...

Thanks for the report. I'll look into it when I have some free time.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Author:

Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: