Hello,

I am following a simple helloworld kernel module tutorial. But I am getting below errors:

weiquan@weiquan-PowerEdge-T30:~/src/test/openwrt-km$ make
make -C /home/weiquan/git/openwrt/build_dir/target-aarch64_cortex-a53_glibc/linux-brcm2708_bcm2710/linux-4.9.77 ARCH="arm" CC="/home/weiquan/git/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-5.5.0_glibc/bin/aarch64-openwrt-linux-gcc"  M=/home/weiquan/src/test/openwrt-km modules
make[1]: Entering directory '/home/weiquan/git/openwrt/build_dir/target-aarch64_cortex-a53_glibc/linux-brcm2708_bcm2710/linux-4.9.77'
  CC [M]  /home/weiquan/src/test/openwrt-km/hello.o
aarch64-openwrt-linux-gcc: error: unrecognized argument in option '-mabi=apcs-gnu'
aarch64-openwrt-linux-gcc: note: valid arguments to '-mabi=' are: ilp32 lp64
aarch64-openwrt-linux-gcc: error: unrecognized command line option '-mapcs'
aarch64-openwrt-linux-gcc: error: unrecognized command line option '-mno-sched-prolog'
aarch64-openwrt-linux-gcc: error: unrecognized command line option '-msoft-float'
scripts/Makefile.build:299: recipe for target '/home/weiquan/src/test/openwrt-km/hello.o' failed
make[2]: *** [/home/weiquan/src/test/openwrt-km/hello.o] Error 1
Makefile:1495: recipe for target '_module_/home/weiquan/src/test/openwrt-km' failed
make[1]: *** [_module_/home/weiquan/src/test/openwrt-km] Error 2
make[1]: Leaving directory '/home/weiquan/git/openwrt/build_dir/target-aarch64_cortex-a53_glibc/linux-brcm2708_bcm2710/linux-4.9.77'
Makefile:15: recipe for target 'all' failed
make: *** [all] Error 2

My target platform is bcm2710(raspberry pi 3) and I am choosing glibc as my C library implementation.

I am able to use the aarch64-openwrt-linux-gcc to cross compile simple c program like this:

aarch64-openwrt-linux-gcc -o test.o test.c

But, when I try to build kernel modules, the build is always failing with those "unrecognized argument in option" and "unrecognized command line option" errors. Does anyone ever meet this issue before? Googled around but could not quite understand this issue. I really appreciate if anyone could shed some light on this.

Below is the Makefile

OPENWRT = /home/weiquan/git/openwrt
STAGING_DIR = ${OPENWRT}/staging_dir
TOOLCHAIN_DIR = ${STAGING_DIR}/toolchain-aarch64_cortex-a53_gcc-5.5.0_glibc

KERNEL = ${OPENWRT}/build_dir/target-aarch64_cortex-a53_glibc/linux-brcm2708_bcm2710/linux-4.9.77
LD=${TOOLCHAIN_DIR}/bin/mips-openwrt-linux-uclibc-ld
CROSS_COMPILE="aarch64-openwrt-linux-"
EXTRA_LDSFLAGS="-I${OPENWRT}/build_dir/target-aarch64_cortex-a53_glibc/linux-brcm2708_bcm2710 -include symtab.h"
KBUILD_HAVE_NLS=no
CONFIG_SHELL="/bin/bash" 

obj-m += hello.o

all:
    make -C ${KERNEL} ARCH="arm" CC="${TOOLCHAIN_DIR}/bin/aarch64-openwrt-linux-gcc"  M=$(PWD) modules

clean:
    make -C ${KERNEL} CC="${TOOLCHAIN_DIR}/bin/aarch64-openwrt-linux-gcc"  M=$(PWD) clean

Below is the hello.c

#include <linux/module.h>  /* Needed by all modules */
#include <linux/kernel.h>  /* Needed for KERN_ALERT */

int init_module(void)
{
    printk("<1>Hello world 1.\n");
    
    // A non 0 return means init_module failed; module can't be loaded.    
    return 0;
}

void cleanup_module(void)
{
    printk(KERN_ALERT "Goodbye world 1.\n");
}

Thank you very much!

>>>>>> 2018-02-20 updates <<<<<<

The issue is resolved:
1. first the rspberry pi 3 is arm64 arch, so ARCH="arm64"
2. LD=${TOOLCHAIN_DIR}/bin/mips-openwrt-linux-uclibc-ld should be changed to LD=${TOOLCHAIN_DIR}/bin/aarch64-openwrt-linux-ld
Below is the final correct Make file:

OPENWRT = /home/weiquan/git/openwrt
STAGING_DIR = ${OPENWRT}/staging_dir
TOOLCHAIN_DIR = ${STAGING_DIR}/toolchain-aarch64_cortex-a53_gcc-5.5.0_glibc

KERNEL = ${OPENWRT}/build_dir/target-aarch64_cortex-a53_glibc/linux-brcm2708_bcm2710/linux-4.9.77
LD=${TOOLCHAIN_DIR}/bin/aarch64-openwrt-linux-ld
CROSS_COMPILE="aarch64-openwrt-linux-"
EXTRA_LDSFLAGS="-I${OPENWRT}/build_dir/target-aarch64_cortex-a53_glibc/linux-brcm2708_bcm2710 -include symtab.h"
KBUILD_HAVE_NLS=no
CONFIG_SHELL="/bin/bash"

obj-m += hello.o

all:
    make -C ${KERNEL} ARCH="arm64" CC="${TOOLCHAIN_DIR}/bin/aarch64-openwrt-linux-gcc"  M=$(PWD) modules

clean:
    make -C ${KERNEL} CC="${TOOLCHAIN_DIR}/bin/aarch64-openwrt-linux-gcc"  M=$(PWD) clean

(Last edited by weiquan19 on 21 Feb 2018, 08:52)