This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SK-AM62: How to install customized driver.ko file?

Genius 13655 points
Part Number: SK-AM62

Hello Champs,

How to install customized driver.ko file?

Customer cp the driver.ko to the sdcard root: /lib/modules/5.10.168-rt83-gc1a1291911, then executed modprobe command, but it prompted can't find the .ko. What's wrong?


It prompted "bad version" when using depmod before modprobe.

Thanks 
Regards
Shine

  • Hi Shine,

    The driver.ko has to be compiled along with the running kernel on the board, so that they all have the matching version.

  • Hi Bin,

    Thank you very much for your great support.

    Below is the customer's reply.

    How to compile my own driver. c file with the kernel? I have already specified the kernel in the makefile of the compiled driver,

    I can use insmod mount .ko file,but can't use modprobe now.




    Thanks
    Regards
    Shine

  • Hi Shine,

    The simplest way is:

    - copy the driver source code to a kernel driver folder, for example, drivers/misc/;
    - modify the file "Makefile" under that folder, to add the following line at the end (assuming the driver source filename is mytest.c):
        obj-m  += mytest.o
    - build kernel modules, which would build mytest.ko along with other kernel modules.

  • Hi Bin,

    Customer wanted to put the mytest.c to his own mydriver folder. Does it need other configuration except for adding the driver to makefile?

    Thanks
    Regards
    Shine

  • Hi Shine,

    I haven't built out-of-tree kernel drivers for many years, so I cannot tell exactly what is missing. The customer's driver Makefile looks okay to me, but please ask the customer to ensure

    1) the SDK kernel has to be built first, and use "make modules_install" to install all kernel modules to the rootfs

    2) the customer's driver Makefile seems missing "make modules_install" entry to install mytest.ko to rootfs

    3) the SDK kernel Image should be copied to rootfs as well.

  • Hi Bin,

    Thank you very much.

    Customer cp his .ko file which is generated by his makefile to /lib/modules/<uname -a> and using insmod to insert it, it prompted "not found in /lib/modules/uname-a" when executing modprobe. 

    According to your suggestion, he put mytest.c to /driver/misc, using make modules to generate .ko, then using make modules install to install mytest.ko successfully. But it can't be found when using lsmod. It prompted below error message when using /lib/modules/5.10.168-rt83-gc1a1291911/kernel/drivers/misc modprobe command. 



    Thanks
    Regards
    Shine

  • Hi Shine,

    Your description and the console log are confusing. I don't fully understand.

    In general, modprobe command can only load modules which are installed by "make modules_install" command. modprobe command won't be able to find modules which are "cp"ed to the root filesystem.

    The console log shows "depmod mytest.ko" failed, which generally means the running kernel Image is mismatch with the kernel module. When you do 'make modules_install" to install all the built kernel modules to the rootfs, you also have to copy the new kernel Image to the rootfs as well. Basically, the kernel image and modules on the rootfs should come from the same kernel build.

  • Hi Bin,

    Thank you very much. 

    Customer executed below commands. 

    make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- clean

    make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- tisdk_am62xx-evm-rt_defconfig

    make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- Image

    make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- ti/k3-am625-sk.dtb

    make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- modules

    sudo make ARCH=arm64 INSTALL_MOD_PATH=/home/ubuntu/rootfs modules_install

    It prompted below message when executing make moduleinstall,but .ko file is already in rootfs.

    arch/arm64/Makefile:25: ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum

    Migrating the image and dtb to SD rootfs, it still shown bad version when executing depmod. 

    Thanks
    Regards
    Shine

  • Hi Shine,

    two questions:

    1. what arm toolchain is used? how the arm toolchain PATH is specified?

    2. what is the Linux distro on the PC, Ubuntu 18.04 or something else?

  • Hi Bin,

    Thank you very much.

    1. Linux ubuntu 5.4.0-150-generic #167~18.04.1-Ubuntu SMP Wed May 24 00:51:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

    2. Compiler: export PATH=/home/ubuntu/SDK/linux-devkit/sysroots/x86_64-arago-linux/usr/bin:$PATH


    Thanks
    Regards
    Shine

  • Hi Shine,

    sudo make ARCH=arm64 INSTALL_MOD_PATH=/home/ubuntu/rootfs modules_install

    It prompted below message when executing make moduleinstall,but .ko file is already in rootfs.

    arch/arm64/Makefile:25: ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum

    I am not sure what causes this error.

    The SDK top level Makefile supports compiling kernel, Does the customer see the same issue if compiling the kernel using SDK top level Makefile?

  • Hello Bin,

    Thank you very much. 

    Compiling the kernel using SDK top level makefile, after executing make install, it still prompted below error message "arch/arm64/Makefile:25: ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum"

    It can't mount by using modprobe in linux, it prompted bad version when using depmod. It has the same issue when using pci_endpoint_test.ko. 

    Customer is not sure which step cause the issue. 

    The only difference is that it prompted below error when using depmod after makefile in SDK top level. 

    root@am62xx-evm:/lib/modules/5.10.168-rt83-gc1a1291911/kernel/drivers/misc#
    root@am62xx-evm:/lib/modules/5.10.168-rt83-gc1a1291911/kernel/drivers/misc# depmod mytest
    depmod: ERROR: Bad version passed mytest
    root@am62xx-evm:/lib/modules/5.10.168-rt83-gc1a1291911/kernel/drivers/misc# depmod
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/fs/cifs/cifs.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/fs/btrfs/btrfs.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/drivers/net/wireless/intel/iwlwifi/mvm/iwlmvm.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/drivers/net/wireless/marvell/mwifiex/mwifiex.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/sound/core/snd-hwdep.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/sound/core/snd-rawmidi.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/sound/usb/snd-usb-audio.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/sound/usb/snd-usbmidi-lib.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/sound/soc/codecs/snd-soc-pcm3168a.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/sound/soc/codecs/snd-soc-pcm3168a-i2c.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/sound/soc/codecs/snd-soc-tlv320aic31xx.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/sound/soc/codecs/snd-soc-tlv320aic3x.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/sound/soc/codecs/snd-soc-wcd934x.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/sound/soc/codecs/snd-soc-wm8904.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/sound/soc/codecs/snd-soc-wsa881x.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/sound/soc/codecs/snd-soc-simple-amplifier.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/sound/soc/generic/snd-soc-simple-card-utils.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/sound/soc/generic/snd-soc-simple-card.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/sound/soc/generic/snd-soc-audio-graph-card.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/sound/soc/ti/snd-soc-j721e-evm.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/samples/rpmsg/rpmsg_client_sample.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/net/netfilter/nf_conntrack.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/net/xfrm/xfrm_algo.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/net/xfrm/xfrm_user.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/net/xfrm/xfrm_ipcomp.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/net/ipv6/ipv6.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/net/wireless/cfg80211.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/net/bridge/bridge.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/net/bluetooth/bluetooth.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/net/sctp/sctp.ko: Invalid argument
    depmod: ERROR: failed to load symbols from /lib/modules/5.10.168-rt83-gc1a1291911/kernel/net/mac80211/mac80211.ko: Invalid argument
    root@am62xx-evm:/lib/modules/5.10.168-rt83-gc1a1291911/kernel/drivers/misc# modprobe mytest.ko
    modprobe: FATAL: Module mytest.ko not found in directory /lib/modules/5.10.168-rt83-gc1a1291911
    root@am62xx-evm:/lib/modules/5.10.168-rt83-gc1a1291911/kernel/drivers/misc# ls
    eeprom mytest.ko pci_endpoint_test.ko uacce
    root@am62xx-evm:/lib/modules/5.10.168-rt83-gc1a1291911/kernel/drivers/misc# depmod pci_endpoint_test.ko
    depmod: ERROR: Bad version passed pci_endpoint_test.ko

    Besides, customer tried to install the /driver/misc/pci_endpoint_test.ko, but the modprobe is still failed. 

    Thanks
    Regards
    Shine

  • Hi Shine,

    Please use 'history' in the Linux PC terminal to show all the commands used to build and install the kernel, including compiling the custom mytest.ko driver, and attach the log here.

  • Hello Bin,

    Thank you very much. 

    Below are the commands:

    594 history
    595 export PATH=/home/ubuntu/ti-processor-sdk-linux-rt-am62xx-evm-08.06.00.42/linux-devkit/sysroots/x86_64-arago-linux/usr/bin:$PATH
    596 echo $PATH
    597 make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- clean
    598 cp '/home/ubuntu/SDK/board-support/linux-rt-5.10.168+gitAUTOINC+c1a1291911-gc1a1291911/drivers/misc/mytest.c' ./board-support/linux-rt-5.10.168+gitAUTOINC+c1a1291911-gc1a1291911/drivers/misc/
    599 vi ./board-support/linux-rt-5.10.168+gitAUTOINC+c1a1291911-gc1a1291911/drivers/misc/Makefile
    600 make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- tisdk_am62xx-evm-rt_defconfig
    601 cd ./board-support/linux-rt-5.10.168+gitAUTOINC+c1a1291911-gc1a1291911/
    602 make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- tisdk_am62xx-evm-rt_defconfig
    603 make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- Image
    604 make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- modules
    605 make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- modules
    606 sudo umount /media/ubuntu/root
    607 sudo mount /dev/sdb2 /home/ubuntu/rootfs
    608 make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- ti/k3-am625-sk.dtb
    609 sudo rm -f /home/ubuntu/rootfs/boot/*
    610 sudo cp '/home/ubuntu/ti-processor-sdk-linux-rt-am62xx-evm-08.06.00.42/board-support/linux-rt-5.10.168+gitAUTOINC+c1a1291911-gc1a1291911/arch/arm64/boot/Image' /home/ubuntu/rootfs/boot
    611 sudo cp '/home/ubuntu/ti-processor-sdk-linux-rt-am62xx-evm-08.06.00.42/board-support/linux-rt-5.10.168+gitAUTOINC+c1a1291911-gc1a1291911/arch/arm64/boot/dts/ti/k3-am625-sk.dtb' /home/ubuntu/rootfs/boot
    612 sudo make ARCH=arm64 INSTALL_MOD_PATH=/home/ubuntu/rootfs modules_install
    613 sudo umount /home/ubuntu/rootfs
    614 history

    Add below code to driver/misc/makefile:

    obj-m  += mytest.o

    It still prompted bad version

    Attached is the log

    7774.log.txt

    Thanks
    Regards
    Shine

  • Hey Shine,

    Could you attach the output of "modinfo mytest.ko"?

    Regards,

    Randolph

  • Hi Randolph,

    Thank you very much.

    Please see below output.



    Regards
    Shine

  • Shine,

    That seems to be correct. Just to be sure, you aren't playing around with SELinux or anything that would explicitly want extra attributes attached to the file, right?

    Regards,

    Randolph

  • Hi Randolph,

    Thank you very much. 

    Customer only used  tisdk_am62xx-evm-rt_defconfig to make kernel. rootfs and uboot are generated when flashing base.image. He is using insmod to mount mytest.ko and modprobe module, pci_endpoint_test.ko can't mount either. So customer doubted if there is something wrong when compiling. 

    Thanks
    Regards
    Shine

  • Hi Shine,

    I just noticed the customer passes a .ko module file to depmod command. This usage is not correct. Please see the explanation of 'depmod <filenames>' in 'man depmod' command.

    "If filenames are given on the command line, only those modules are examined (which is
    rarely useful unless all modules are listed)."

    Actually since the customer has added driver mytest.c to the kernel tree drivers/misc/ folder,  The specific 'depmod' command on EVM is no longer needed, The module dependencies are already generated when 'make ... modules'.

    Please let me know if the customer still has other issues in loading or using mytest.ko.

  • Hi Bin,

    Thank you very much.
     
    The problem is that it will prompt "not found" when using modprobe  after mounting and installing the mytest.c to /driver/misc. The problem is the same when using msic/pci**.ko. 



    Regards
    Shine

  • Hi Shine,

    Please use command 'modprobe pci_endpoint_test' instead, without '.ko'.

  • Hi Bin,

    Customer's problem has been resolved. 

    Thank you very much for your great help.

    Regards
    Shine