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.

How to build .ko

Hi 

         I'm using Beaglebone with linux. i want to create .ko module for me external device. we developed the XX1405.c and its our own file so its out of linux tree. 

Can any one tell me how to create .ko and how to write make file for build the xx1405.c against arm-eabi- cross compiler in source tree.

Thanks in andvance

  • Hi Sangili,

    Is your question how to write and build a Linux kernel loadable module?

    Someone may give much quicker advice, but my opinion is the following book (downloadable online) is comprehensive and well written.  One notice is this book is behind the latest Linux kernel 3.x but still valuable.  (Written for 2.6.x kernels.)

    Especially, the chapter 2 covers some basic topics for kernel loadable module (.ko).

    Best Regards,
    Atsushi

  • Hi,

    paste the below contents in a Makefile, and run

    'make ARCH=arm CROSS_COMPILE=arm-eabi-' where you Makefile

    and  XX1405.c is present. Please note replace 'path to linux-source'

    this with your linx source path.

    obj-m += xx1405.o

    all:
        make -C <path to linux-source> M=$(PWD) modules

    clean:
        make -C <path to linux-source> M=$(PWD) clean

    Regards,

    --Prabhakar Lad

  • Hi Yokoyama,

                Thanks for your reply, your reply help me in broad manner.

  • Hi Prabhakar

                     Thanks for your reply. I followed your way but its show  make: Nothing to be done for `all'. error

    Actually my xx1405.c & make file is inside the xx1405 folder. path of this folder is  /home/MyPC/TI_ICS/ics/xx1405

    path of my kernel folder is  /home/MyPC/TI_ICS/ics/kernel

    marudham@marudham-desktop:~/TI_ICS/ics$ ls
    abi                     build          dalvik           external        image_BB          kernel        ndk         prebuilt                  sdk                  u-boot
    bionic               xx1405      development              frameworks              image_folder           libcore                   out                  rowboat-kernel              start@me.sh    v8.log
    bootable          cts               device                          hardware                 img                            Makefile                 packages     ROWBOAT_ROOT      system

    $ ls kernel

    arch     crypto         fs       Kbuild      lib          module          REPORTING-BUGS  sound       usr
    block    Documentation  include  Kconfig     MAINTAINERS  Module.symvers  samples         suc         virt
    COPYING  drivers        init     kernal.txt  Makefile     net             scripts         System.map  vmlinux
    CREDITS  firmware       ipc      kernel      mm           README          security        tools       vmlinux.o
            These are the source files for linux
    $ls xx1405

     xx1405.c    makefile

    content of my make file is 

    obj-m := xx1405.o

    all:
         make -C /home/marudham/TI_ICS/ics/kernel M=$(PWD) modules

    clean:
         make -C /home/marudham/TI_ICS/ics/kernel M=$(PWD) clean

    $ make ARCH=arm CROSS_COMPILE=arm-eabi-

    make: Nothing to be done for `all'.

          Can you guess where the mistake was happen.?

  • Hi,

    Are you aware of writing Makefiles?

    'all' is a rule there. After all: hit enter and give a tab and not spaces.

    Regards,

    --Prabhakar Lad

  • Thanks Mr.Prabhakar

                 Now its woking fine. I hitted the enter and TAP after all: but without my knowledge one space is added.