Failing to insert a custom Kernel module

0

I'm working on a STM32MP1 target with yocto. In general I can compile a helloworld .ko file and load it into the kernel. But when I want to compile following:

#include <linux/platform_device.h>
#include <linux/module.h>
#include <linux/types.h>

static struct platform_device *pdev;

static int __init fake_eth_add(void)
{
    int inst_id = 0;
    pdev = platform_device_alloc("fake-eth", inst_id);
    platform_device_add(pdev);
    pr_info("fake-eth added");
    return 0;
}

static void __exit fake_eth_put(void)
{
    pr_info("fake-fake removed");
    platform_device_put(pdev);
}

module_init(fake_eth_add);
module_exit(fake_eth_put);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("John Madieu <john.madieu@gmail.com>");

I get following errors:

ERROR: modpost: "platform_device_put" [/home/rdm/ethtest/eth-ins.ko] undefined!
ERROR: modpost: "platform_device_add" [/home/rdm/ethtest/eth-ins.ko] undefined!
ERROR: modpost: "platform_device_alloc" [/home/rdm/ethtest/eth-ins.ko] undefined!

I check if the platform_device_alloc Symbol/Function is defined and it does:

root@txmp-1570:/lib/modules/5.7.1/source/kernel# grep -w platform_device_alloc /proc/kallsyms
c0547cfc T platform_device_alloc

Now I have learned that the symbols must be in the Module.symvers File tagged as EXPORT_SYMBOL_GPL. The symbols were not there, so I added them to the Module.symvers file:

0x00000000  platform_device_alloc   vmlinux EXPORT_SYMBOL_GPL   
0x00000000  platform_device_add vmlinux EXPORT_SYMBOL_GPL   
0x00000000  platform_device_put vmlinux EXPORT_SYMBOL_GPL

Now the code compiles! But when I want to load it with insmod, then I get following error:

root@txmp-1570:/home/rdm/ethtest# insmod eth-ins.ko
insmod: ERROR: could not insert module eth-ins.ko: Unknown symbol in module

And the dmseg logs:

[ 2954.658383] eth_ins: Unknown symbol platform_device_put (err -2)
[ 2954.664194] eth_ins: Unknown symbol platform_device_add (err -2)
[ 2954.672737] eth_ins: Unknown symbol platform_device_alloc (err -2)

What am I missing? Why did I have to append the Module.symvers file by myself? Did I miss something regarding setting up the enviromnent for kernel driver development?

linux
linux-kernel
embedded-linux
asked on Stack Overflow Dec 4, 2020 by washman • edited Dec 4, 2020 by washman

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0