How to update .ko file to wp76xx

I have wrote .sdef file and .mdef file to install ko file to wp76xx but it’s have an error:

insmod: can’t insert ‘/legato/systems/current/modules/wfx.ko’: invalid module format

wfx.sdef :
kernelModules:
{
/home/exars/workspace/legatoAF/legato-19.02.0/drivers/wf200/wfx.mdef
}

wfx.mdef:
preBuilt:
{
$LEGATO_ROOT/drivers/wf200/wfx-linux-driver/wfx.ko
}

how can i install .kofile to wp76xx modules

You can use insmod command

Here is an example on running kernel driver module

do you mean insmod command like this?

root@swi-mdm9x28-wp:/lib/modules/3.18.140/extra# insmod /lib/modules/3.18.140/ex
tra/wfx.ko
insmod: can’t insert ‘/lib/modules/3.18.140/extra/wfx.ko’: invalid module format

if yes, it’s same error

Can you try my example and see if the insmod ok or not?

Btw, did you compile with correct toolchain and kernel path?

how to check the toolchain and kernel path that i compile is already correct?

users@IStNX3-15HP038:~/ダウンロード/priority_test/high_priority$ scp high_priority_helloworld.ko root@192.168.2.2:/tmp

root@swi-mdm9x28-wp:/# insmod /tmp/high_priority_helloworld.ko
[28900.086521] high_priority_helloworld: version magic ‘3.18.44 preempt mod_unl’
[28900.101211] high_priority_helloworld: version magic ‘3.18.44 preempt mod_unl’
insmod: can’t insert ‘/tmp/high_priority_helloworld.ko’: invalid module format

is I do in correctly??

How do you compile the .ko ?
You need to modify the makefile with the toolchain path

I can compile your example code but cannot compile mine,why??

root@swi-mdm9x28-wp:/# lsmod
Tainted: G
high_priority_helloworld 1729 0 - Live 0xbf0b1000 (O)
brcmfmac 205451 0 - Live 0xbf150000 (O)

You can port your code to my helloworld driver, then you will know which line makes the problem

BTW, " version magic ‘3.18.44 preempt mod_unl’" means you did not use the correct kernel path and toolchain for compilation

I have got this error but i don’t what is wrong??

/home/exars/workspace/legatoAF/legato-19.02.0/drivers/wf200/wfx-linux-driver/sta.c: In function ‘wfx_set_key’:
/home/exars/workspace/legatoAF/legato-19.02.0/drivers/wf200/wfx-linux-driver/sta.c:869:35: warning: array subscript is below array bounds [-Warray-bounds]
error, forbidden warning: sta.c:869
scripts/Makefile.build:257: recipe for target ‘/home/exars/workspace/legatoAF/legato-19.02.0/drivers/wf200/wfx-linux-driver/sta.o’ failed

sta.c

You can see here

Seems the warning is for idx as a negative value

it still got the error:

Screenshot from 2021-12-28 15-56-48

debug.c
Screenshot from 2021-12-28 15-53-20

also this error:
/home/exars/workspace/legatoAF/legato-19.02.0/drivers/wf200/wfx-linux-driver/debug.c: In function ‘get_symbol’:
/home/exars/workspace/legatoAF/legato-19.02.0/drivers/wf200/wfx-linux-driver/debug.c:62:26: error: invalid use of undefined type ‘struct trace_print_flags’
for (i = 0; symbol_array[i].mask != -1; i++) {

debug.c:
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <linux/version.h>

#if (KERNEL_VERSION(4, 17, 0) > LINUX_VERSION_CODE)
#define DEFINE_SHOW_ATTRIBUTE(__name)
static int __name ## _open(struct inode *inode, struct file *file)
{
return single_open(file, __name ## _show, inode->i_private);
}

static const struct file_operations __name ## _fops = {
.owner = THIS_MODULE,
.open = __name ## _open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
}
#endif

#include “debug.h”
#include “wfx.h”
#include “wsm_tx.h”
#include “sta.h”

#define CREATE_TRACE_POINTS
#include “traces.h”

static const struct trace_print_flags wsm_msg_print_map = {
wsm_msg_list,
};

static const struct trace_print_flags wsm_mib_print_map = {
wsm_mib_list,
};

static const struct trace_print_flags wfx_reg_print_map = {
wfx_reg_list,
};

static const struct trace_print_flags wfx_fw_types_print_map = {
{ 0, “ETF” },
{ 1, “WFM” },
{ 2, “WSM” },
{ 3, “HI test” },
{ 4, “Platform test” },
{ -1, NULL }
};

static const char *get_symbol(unsigned long val,
const struct trace_print_flags *symbol_array)
{
int i;

for (i = 0; symbol_array[i].mask != -1; i++) {
	if (val == symbol_array[i].mask)
		return symbol_array[i].name;
}

return "unknown";

}

const char *get_wsm_name(unsigned long id)
{
return get_symbol(id, wsm_msg_print_map);
}

const char *get_mib_name(unsigned long id)
{
return get_symbol(id, wsm_mib_print_map);
}

const char *get_reg_name(unsigned long id)
{
return get_symbol(id, wfx_reg_print_map);
}

const char *get_fw_type(unsigned long id)
{
return get_symbol(id, wfx_fw_types_print_map);
}

I don’t see anywhere defining the “struct trace_print_flags”.

You should ask the vendor of the driver

Btw, you can try to add the struct manually

https://docs.huihoo.com/doxygen/linux/kernel/3.7/structtrace__print__flags.html

BTW, I can find the definition of “struct trace_print_flags” here inside the toolchain:

/opt/swi/SWI9X07Y_02.28.03.05/sysroots/armv7a-neon-poky-linux-gnueabi/usr/src/kernel/include/linux/ftrace_event.h

Probably you need to include this header file in your driver source.

insmod have an error :

root@swi-mdm9x28-wp:/tmp# insmod wfx.ko
insmod: can’t insert ‘wfx.ko’: unknown symbol in module, or unknown parameter

How about my kernel driver?

yes, it’s worked
root@swi-mdm9x28-wp:/tmp# insmod high_priority_helloworld.ko
[ 1613.612472] gpio-10 (sysfs): _gpiod_direction_output_raw: tried to set a GPIt

my makefile:

does it have any thing wrong
ifeq ($(KERNELRELEASE),)

.NOTPARALLEL:

Makefile for kernel test

export ARCH=arm

#export CROSS_COMPILE=/home/owner/legato/packages/legato.toolchain.2.2.3.SWI9X06Y_02160200-wp77xx-native-x86_64-201806050948/resources/native/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-
export CROSS_COMPILE= /opt/swi/SWI9X07Y_02.37.07.00/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-
PWD := $(shell pwd)
KVERSION := $(shell uname -r)
#KERNEL_DIR = /home/owner/legato/packages/legato.toolchain.2.2.3.SWI9X06Y_02160200-wp77xx-native-x86_64-201806050948/resources/native/sysroots/armv7a-neon-poky-linux-gnueabi/usr/src/kernel/
KERNEL_DIR = /opt/swi/SWI9X07Y_02.37.07.00/sysroots/armv7a-neon-poky-linux-gnueabi/usr/src/kernel/
KDIR ?= /lib/modules/$(shell uname -r)/build
MODULE_NAME = wfx

#obj-m := $(MODULE_NAME).o

all:
make CFLAGS=-O0 -C $(KERNEL_DIR) M=$(PWD) modules

#all: modules

install: modules_install
@# When compiling with stock kernel header on Debian, System.map does
@# not exist. So, Kbuild does not run depmod and our shiny new modules is
@# not seen
@echo “Make sure depmod is up-to-date:”
depmod

#%.o: %.c

$(MAKE) -C $(KDIR) M=$(shell pwd) $@

#modules modules_install clean help:

$(MAKE) -C $(KDIR) M=$(shell pwd) $@

clean:
make -C $(KERNEL_DIR) M=$(PWD) clean
deb-pkg:
dkms mkdeb --source-only .

else

CFLAGS_debug.o = -I$(src)

wfx-y :=
hwio.o
bh.o
fwio.o
data_txrx.o
main.o
queue.o
wsm_tx.o
wsm_rx.o
sta.o
scan.o
debug.o
wfx-$(CONFIG_SPI) += wfx_spi.o
wfx-$(subst m,y,$(CONFIG_MMC)) += wfx_sdio.o

obj-m += wfx.o

endif

does this help?