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.

Loadable Kernel Module (LKM) for am335x

Hi,

[1]
I am working with AM335x. I want to write a simple Loadable Kernel Module (LKM)
and load it into the Linux OS running on the target board.

[2]
I managed to build a LKM on my host Linux System /*Ubuntu 2.6.35-32-generic, 64 bits*/
with a makefile as in Appendix 1. I am able to load and unload the resulting lkm.ko file
(with insmod & rmmod).

[3]
Now I'm trying to create a the same for my embedded am335x board with Linux
using http://processors.wiki.ti.com/index.php/AMSDK_Linux_User's_Guide page.
The closest instrouction I found there is:
make ARCH=arm CROSS_COMPILE=arm-arago-linux-gnueabi- modules

I tried to create corresponding makefile to build a LKM but have not managed to do so.

[4]
Does anybody know how can I build LKM for am335x?

Thanks,
Yan

=======================================================
Appendix 1:
obj-m += lkm.o
all:
sudo make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
sudo make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

  • I think you have it almost right. To compile a LKM outside of the kernel:

    make ARCH=arm CROSS_COMPILE=arm-arago-linux-gnueabi- -C $KERNELDIR M=$PWD modules

    where KERNELDIR is your cross-compiled kernel directory. There has to be two files in the PWD. Your "lkm.c" source file and a file named "Makefile" with one line in it:

    obj-m += lkm.o

    To avoid all that typing. I believe the usual way to use a a 2 pass makefile. The first pass sets up the second pass. Something like this.

    ifeq ($(KERNELRELEASE),)

    PWD:= $(shell pwd)
    ARCH=arm
    CROSS_COMPILE=arm-arago-linux-gnueabi-
    KERNELDIR=PATH_TO_CROSS_COMPILED_LINUX_DIRECTORY

    lkm.ko:    lkm.c
        $(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(PWD) modules

    clean:
        rm lkm.ko

    else

    obj-m += lkm.o

    #endif

    The variables ARCH, CROSS_COMPILE and KERNELDIR could be defined outside the makefile in the shell enviroment. You'll have to add more files the "clean'. There are quite a few files produced.

    I think you have to cross-compile the kernel first. I've heard of others say you don't have to.

  • Hi, Norman,

    Thank you for your prompt reply,
    [1]
    As per your advice I tried to compile the LKM with the makefile (Appendix 1).
    [2]
    However, I got n error message <<arm-arago-linux-gnueabi-gcc: Command not found>> (Appendix 2)
    [3]
    I checked that the arm-arago-linux-gnueabi-gcc exists under the KERNELDIR
    (/usr/local/ti-sdk-am335x-evm/linux-devkit/bin) (Appendix 3)
    [4]
    One more point: I am able to use the arm-arago-linux-gnueabi-gcc from other places,
    e.g. I can compile a helloword application in CCS (Appendix 4)

    [5]

    Do you have any idea what iss wrong with my Makefile?

    Thanks,
    Yan

    =======================================================
    Appendix 1:

    # If KERNELRELEASE is defined, we've been invoked from the
    # kernel build system and can use its language.
    ifneq ($(KERNELRELEASE),)
    obj-m := hello_lkm.o

    # Otherwise we were called directly from the command
    # line; invoke the kernel build system.
    else
    KERNELDIR = /usr/local/ti-sdk-am335x-evm/board-support/linux-3.2-psp04.06.00.07.sdk
    PWD = $(shell pwd)
    ARCH = arm
    CROSS_COMPILE=arm-arago-linux-gnueabi-
    default:
    $(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(PWD) modules

    endif

    =======================================================
    Appendix 2:

    yantsitrin@ubuntu:~/workspace_ccs_v5_1/b_hello_LKM$ make
    make ARCH=arm CROSS_COMPILE=arm-arago-linux-gnueabi- -C /usr/local/ti-sdk-am335x-evm/board-support/linux-3.2-psp04.06.00.07.sdk M=/home/yantsitrin/workspace_ccs_v5_1/b_hello_LKM modules
    make[1]: arm-arago-linux-gnueabi-gcc: Command not found
    make[1]: Entering directory `/usr/local/ti-sdk-am335x-evm/board-support/linux-3.2-psp04.06.00.07.sdk'
    CC [M] /home/yantsitrin/workspace_ccs_v5_1/b_hello_LKM/hello_lkm.o
    /bin/sh: arm-arago-linux-gnueabi-gcc: not found
    make[2]: *** [/home/yantsitrin/workspace_ccs_v5_1/b_hello_LKM/hello_lkm.o] Error 127
    make[1]: *** [_module_/home/yantsitrin/workspace_ccs_v5_1/b_hello_LKM] Error 2
    make[1]: Leaving directory `/usr/local/ti-sdk-am335x-evm/board-support/linux-3.2-psp04.06.00.07.sdk'
    make: *** [default] Error 2


    =======================================================
    Appendix 3:
    yantsitrin@ubuntu:/usr/local/ti-sdk-am335x-evm/linux-devkit/bin$ ls -al | grep arm-arago-linux-gnueabi-gcc
    -rwxr-xr-x 1 120 nogroup 731051 2011-09-28 19:56 arm-arago-linux-gnueabi-gcc
    -rwxr-xr-x 1 120 nogroup 17353 2011-09-28 19:56 arm-arago-linux-gnueabi-gccbug

    =======================================================
    Appendix 4:
    Building target: helloworld
    Invoking: Cross GCC Linker
    arm-arago-linux-gnueabi-gcc -o "helloworld" ./helloworld.o -lpthread -lrt
    Finished building target: helloworld

  • Hi, Norman, 

    I resolved the problem just by adding to the CROSS_COMPILE the full path to the arm-arago-linux-gnueabi-

    Thus, the resulting Makefile is as follows:

    ====================================================================

    ifneq ($(KERNELRELEASE),)
    obj-m := hello_lkm.o
    else
    KERNELDIR = /usr/local/ti-sdk-am335x-evm/board-support/linux-3.2-psp04.06.00.07.sdk
    PWD = $(shell pwd)
    ARCH = arm
    CROSS_COMPILE=/usr/local/ti-sdk-am335x-evm/linux-devkit/bin/arm-arago-linux-gnueabi-
    default:
    $(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(PWD) modules

    endif

    ====================================================================

    Thank you for your cooperation,

    Yan

  • It looks like your cross-compiler is not in the search path. Use the "which arm-arago-linux-gnueabi-gcc" to see if the program is in your search path. You can either specify the entire path in Makefile:

    CROSS_COMPILE=/usr/local/ti-sdk-am335x-evm/linux-devkit/bin/arm-arago-linux-gnueabi-

    or by adding that directory to your search path:

    export PATH=/usr/local/ti-sdk-am335x-evm/linux-devkit/bin:$PATH

    You do the export just once each time you start a shell terminal window that you are doing compiling.

    I don't know how helloworld is finding the the cross-compiler. Whatever script or makefile you are using to build must be defining the path.

    EDIT: Replied the same time that you found the solution. Good news.

  • I'll check whether adding this directory to PATH resolves the problem.


    Thank you again,

    Yan

  • Hi Yan Tsitrin,

    I am a  true beginner with LMK in AM335x (My target board) and I would like to load one simple module in it.

    I have been following your Makefile example, specifically my Makefile has this form:

    =======================================================================================

    ifneq ($(KERNELRELEASE),)
    obj-m := hello.o

    else
    ARCH=arm
    CROSS_COMPILE=/home/sst/sitara/linux-devkit/bin/arm-arago-linux-gnueabi-
    LINUXKERNEL_INSTALL_DIR=/home/sst/sitara/board-support/linux-3.2.0-psp04.06.00.08.sdk
    all:
     $(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(LINUXKERNEL_INSTALL_DIR) M=$(PWD) modules
    endif

    ======================================================================================= 

    When I execute the makefile I find the following error:

    WARNING: Symbol version dump /home/sst/sitara/board-support/linux-3.2.0-psp04.06.00.08.sdk/Module.symvers
               is missing; modules will have no dependencies and modversions.

      CC [M]  /home/sst/sitara/example_module_AM335x/hello.o
    In file included from include/linux/gfp.h:4:0,
                     from include/linux/kmod.h:22,
                     from include/linux/module.h:13,
                     from /home/sst/sitara/example_module_AM335x/hello.c:4:
    include/linux/mmzone.h:18:30: fatal error: generated/bounds.h: No such file or directory
    compilation terminated.

    ================================================================================

    The complet message from the makefile is:

    make ARCH=arm CROSS_COMPILE=/home/sst/sitara/linux-devkit/bin/arm-arago-linux-gnueabi- -C /home/sst/sitara/board-support/linux-3.2.0-psp04.06.00.08.sdk M=/home/sst/sitara/example_module_AM335x modules
    make[1]: Betrete Verzeichnis '/home/sst/sitara/board-support/linux-3.2.0-psp04.06.00.08.sdk'

      WARNING: Symbol version dump /home/sst/sitara/board-support/linux-3.2.0-psp04.06.00.08.sdk/Module.symvers
               is missing; modules will have no dependencies and modversions.

      CC [M]  /home/sst/sitara/example_module_AM335x/hello.o
    In file included from include/linux/gfp.h:4:0,
                     from include/linux/kmod.h:22,
                     from include/linux/module.h:13,
                     from /home/sst/sitara/example_module_AM335x/hello.c:4:
    include/linux/mmzone.h:18:30: fatal error: generated/bounds.h: No such file or directory
    compilation terminated.
    make[2]: *** [/home/sst/sitara/example_module_AM335x/hello.o] Fehler 1
    make[1]: *** [_module_/home/sst/sitara/example_module_AM335x] Fehler 2
    make[1]: Verlasse Verzeichnis '/home/sst/sitara/board-support/linux-3.2.0-psp04.06.00.08.sdk'
    make: *** [all] Fehler 2

    ========================================================================================

    I consider that the problem would be in the build directory because the makefile does not find the Moduel.symvers. But it is the same that the example shows (my sdk files are in the /home/sst/sitara).

    I managed to load the Module on my Host for this reason I supposed that the Module is Okay.

    Thanks for your attention.

    Breixo

  • Hi Community,

    I have been looking for the mistake and I have already found it. It was only that I had to generate a booteable kernel Image one more time. The process:

    In the file /board-support/linux-3.2.0-psp04.06.00.08.sdk:

    make ARCH=arm CROSS_COMPILE=arm-arago-gnueabi- uImage.

    The resulting Image is in the file arch/arm/boot with the name uImage. You may see for more information (http://processors.wiki.ti.com/index.php/AMSDK_Linux_User%27s_Guide).

    Then I managed to create the hello module without problems.

     

  • I check the link you provided after I read your post. Do you mean that the kernel must be updated after the new module? From the link, I think that a changed kernel configuration (from one of two methods: menu configure, xconfigure) because of the new module. But I do not see the configuration of the kernel from your procedures. Could you clarify my questions?

    Thanks,