Programming kernel module

Hello everyone,

I am trying to program a kernel module on AML-S905X-CC and I am following the tutorial on
https://blog.sourcerer.io/writing-a-simple-linux-kernel-module-d9dc3762c234
However, I can't successfully compile the hello world program.
I only included three header files <linux/module.h>, <linux/kernel.h> and <linux/init.h> but there are errors caused by redefinition and type not match.
Has anyone met the similar problem before? What could be the reasons that cause this?

Thanksa

Comments

  • The errors and are attatched below to help clarify my problem:

    ./include/linux/timekeeping.h: In function ‘do_settimeofday’:
    ./include/linux/timekeeping.h:57:27: error: passing argument 1 of ‘do_settimeofday64’ from incompatible pointer type [-Werror=incompatible-pointer-types]
    return do_settimeofday64(ts);
    ^~
    ./include/linux/timekeeping.h:20:12: note: expected ‘const struct timespec64 *’ but argument is of type ‘const struct timespec *’
    extern int do_settimeofday64(const struct timespec64 *ts);
    ^~~~~
    ./include/linux/timekeeping.h: In function ‘__getnstimeofday’:
    ./include/linux/timekeeping.h:62:28: error: passing argument 1 of ‘__getnstimeofday64’ from incompatible pointer type [-Werror=incompatible-pointer-types]
    return __getnstimeofday64(ts);
    ^~
    ./include/linux/timekeeping.h:47:12: note: expected ‘struct timespec64 *’ but argument is of type ‘struct timespec *’
    extern int __getnstimeofday64(struct timespec64 *tv);
    ^~~~~~
    ./include/linux/timekeeping.h: In function ‘getnstimeofday’:
    ./include/linux/timekeeping.h:67:19: error: passing argument 1 of ‘getnstimeofday64’ from incompatible pointer type [-Werror=incompatible-pointer-types]
    getnstimeofday64(ts);
    ^~
    ./include/linux/timekeeping.h:48:13: note: expected ‘struct timespec64 *’ but argument is of type ‘struct timespec *’
    extern void getnstimeofday64(struct timespec64 *tv);
    ^~~~
    ./include/linux/timekeeping.h: In function ‘ktime_get_ts’:
    ./include/linux/timekeeping.h:72:17: error: passing argument 1 of ‘ktime_get_ts64’ from incompatible pointer type [-Werror=incompatible-pointer-types]
    ktime_get_ts64(ts);
    ^~
    ./include/linux/timekeeping.h:43:13: note: expected ‘struct timespec64 *’ but argument is of type ‘struct timespec *’
    extern void ktime_get_ts64(struct timespec64 *ts);
    ^~~~~~
    ./include/linux/timekeeping.h: In function ‘ktime_get_real_ts’:
    ./include/linux/timekeeping.h:77:19: error: passing argument 1 of ‘getnstimeofday64’ from incompatible pointer type [-Werror=incompatible-pointer-types]
    getnstimeofday64(ts);
    ^~
    ./include/linux/timekeeping.h:48:13: note: expected ‘struct timespec64 *’ but argument is of type ‘struct timespec *’
    extern void getnstimeofday64(struct timespec64 *tv);
    ^~~~
    ./include/linux/timekeeping.h: In function ‘getrawmonotonic’:
    ./include/linux/timekeeping.h:82:20: error: passing argument 1 of ‘getrawmonotonic64’ from incompatible pointer type [-Werror=incompatible-pointer-types]
    getrawmonotonic64(ts);
    ^~
    ./include/linux/timekeeping.h:42:13: note: expected ‘struct timespec64 *’ but argument is of type ‘struct timespec *’
    extern void getrawmonotonic64(struct timespec64 *ts);
    ^~~~~
    ./include/linux/timekeeping.h: In function ‘get_monotonic_coarse’:
    ./include/linux/timekeeping.h:87:9: error: incompatible types when returning type ‘struct timespec64’ but ‘struct timespec’ was expected
    return get_monotonic_coarse64();
    ^~~~~~~~
    ./include/linux/timekeeping.h: In function ‘getboottime’:
    ./include/linux/timekeeping.h:92:23: error: passing argument 1 of ‘getboottime64’ from incompatible pointer type [-Werror=incompatible-pointer-types]
    return getboottime64(ts);
    ^~
    ./include/linux/timekeeping.h:49:13: note: expected ‘struct timespec64 *’ but argument is of type ‘struct timespec *’
    extern void getboottime64(struct timespec64 *ts);
    ^~~~~
    In file included from ./include/linux/sched.h:27:0,
    from ./arch/arm64/include/asm/compat.h:25,
    from ./arch/arm64/include/asm/stat.h:23,
    from ./include/linux/stat.h:6,
    from ./include/linux/module.h:10,
    from /home/libre/kernel_module_flush/flush/flush.c:2:
    ./include/linux/signal_types.h: At top level:
    ./include/linux/signal_types.h:31:8: error: redefinition of ‘struct sigaction’
    struct sigaction {
    ^~~~~
    In file included from ./include/uapi/linux/signal.h:5:0,
    from ./include/linux/signal_types.h:10,
    from ./include/linux/sched.h:27,
    from ./arch/arm64/include/asm/compat.h:25,
    from ./arch/arm64/include/asm/stat.h:23,
    from ./include/linux/stat.h:6,
    from ./include/linux/module.h:10,
    from /home/libre/kernel_module_flush/flush/flush.c:2:
    ./include/asm/signal.h:115:8: note: originally defined here
    struct sigaction {
    ^~~~~
    In file included from ./include/linux/stat.h:6:0,
    from ./include/linux/module.h:10,
    from /home/libre/kernel_module_flush/flush/flush.c:2:
    ./arch/arm64/include/asm/stat.h:29:8: error: redefinition of ‘struct stat64’
    struct stat64 {
    ^~
    In file included from ./arch/arm64/include/uapi/asm/stat.h:17:0,
    from ./arch/arm64/include/asm/stat.h:19,
    from ./include/linux/stat.h:6,
    from ./include/linux/module.h:10,
    from /home/libre/kernel_module_flush/flush/flush.c:2:
    ./include/asm-generic/stat.h:49:8: note: originally defined here
    struct stat64 {
    ^~

  • Hi,

    I have ran into the same issue with timekeeping.h
    during building and installing the driver for seeed-voicecard

    I found this patch https://patchwork.kernel.org/patch/10016473/
    but didn't try it

    Thanks,
    Vlad

  • @zhurlik said:
    Hi,

    I have ran into the same issue with timekeeping.h
    during building and installing the driver for seeed-voicecard

    I found this patch https://patchwork.kernel.org/patch/10016473/
    but didn't try it

    Thanks,
    Vlad

    Thank you Vlad. I finally solved my problem through recompiling the kernel but probably you provided a more convenient way.

Sign In or Register to comment.