element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Experts, Learning and Guidance
  • Technologies
  • More
Experts, Learning and Guidance
Ask an Expert Forum Calling embedded Linux kernel experts - how do you build a loadable kernel module from the Linux kernel driver repo
  • Blog
  • Forum
  • Documents
  • Leaderboard
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Experts, Learning and Guidance to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 9 replies
  • Subscribers 287 subscribers
  • Views 2136 views
  • Users 0 members are here
  • linux
Related
See a helpful answer?

Be sure to click 'more' and select 'suggest as answer'!

If you're the thread creator, be sure to click 'more' then 'Verify as Answer'!

Calling embedded Linux kernel experts - how do you build a loadable kernel module from the Linux kernel driver repo

BigG
BigG over 2 years ago

I seem to be going around in circles here, to what is probably very straight forward.

This issue is probably not that common with Raspberry Pi's as I've noticed on Raspbian that most optional Linux kernel drivers are included by default.

So what I'm seeing is the following.

First we have the official repo for Linux and as you can see there is a stack of drivers available: https://github.com/torvalds/linux/tree/master/drivers

In fact what I am after is already here.

I'll start with a straightforward example, of what I am talking about.

So, let's take a CAN bus module such as the MCP2510. You can find this driver here: https://github.com/torvalds/linux/tree/master/drivers/net/can/spi/mcp251xfd

But this SPI module is not always included by default on your Single Board Computer.

So, the question I have is what is the simplest way to make a loadable linux kernel module (i.e. a .ko file) for this module.

I'm assuming there has to be well proven method of doing this. Please note that I wish to do so without having to recompile the whole kernel.

I know for starters I need to get the Linux kernel headers for my distro.

I've at least done that.

Any tips greatly appreciated.

  • Sign in to reply
  • Cancel

Top Replies

  • obones
    obones over 2 years ago +3
    Well, the documentation says this: https://tldp.org/LDP/lkmpg/2.6/html/x181.html And then there's the Kernel Newbies community that would be of great help here I believe: https://kernelnewbies.org…
  • Jan Cumps
    Jan Cumps over 2 years ago +2
    The AVNET IIOT Gateway Linux includes the MCP251x drivers. I don't know yet how they add it, but their Linux bespoke part is on github: https://github.com/Avnet/smartedge-iiot-gateway
  • shabaz
    shabaz over 2 years ago +2
    Hi Colin, I wouldn't normally recommend such an outdated tech book, but it's surprisingly just £3.60 on Amazon currently: It is extremely outdated, but (hopefully) some of it still relevant, although…
  • obones
    0 obones over 2 years ago

    Well, the documentation says this:
    https://tldp.org/LDP/lkmpg/2.6/html/x181.html

    And then there's the Kernel Newbies community that would be of great help here I believe: https://kernelnewbies.org/

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • colporteur
    0 colporteur over 2 years ago

    Sorry for going quiet on you BG. I would have chime in with anything useful. I've done  kernel rebuilds in linux (10 years ago) but haven't done lately. Pi kernel I have never attempted.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • BigG
    0 BigG over 2 years ago in reply to obones

    Ha. I knew there were real experts here... Two excellent links. Thanks.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • BigG
    0 BigG over 2 years ago in reply to BigG

    Adding one to the list from the tldp.org website, which I found interesting: https://tldp.org/LDP/lkmpg/2.6/html/x380.html

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Jan Cumps
    0 Jan Cumps over 2 years ago

    The AVNET IIOT Gateway Linux includes the MCP251x drivers. I don't know yet how they add it, but their Linux bespoke part is on github: https://github.com/Avnet/smartedge-iiot-gateway

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • shabaz
    0 shabaz over 2 years ago

    Hi Colin,

    I wouldn't normally recommend such an outdated tech book, but it's surprisingly just £3.60 on Amazon currently:

    image

    It is extremely outdated, but (hopefully) some of it still relevant, although I doubt any of the command lines will work, you will be able to know roughly what to look for.

    There are almost zero books on the topic, so I don't have any more recent book suggestion. It was already outdated when I purchased it too.

    In that old book, it basically states that if the kernel source is in a location /lib/modules/xxxx/build then from wherever your driver source is, there will be a Makefile there, and you'll be able to type something along these lines:

    make -C/lib/modules/xxxx/build M=$PWD modules

    And then to install it, it is the same command but replace modules with modules_install

    The text xxxx is the output of uname -r

    For sure these make commands won't work today, but you can use the links @obones and Jan Cumps  have suggested, to look for the correct current syntax. Makefiles are still used for device drivers.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • shabaz
    0 shabaz over 2 years ago in reply to shabaz

    I just checked another (old) book (not device driver specific), it states a similar-ish Make invocation:

    make -C /kernel/source/location SUBDIRS=$PWD modules 

    and then replace the text modules with modules_install as mentioned before.

    And then run depmod -A to update dependencies information.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Jan Cumps
    0 Jan Cumps over 2 years ago

    idea: maybe we can start a collaborative exercise to:

    1. try to rebuild a raspberry OS 
    2. add a driver
    3. do more fancy things

    and document it along the way ...

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • BigG
    0 BigG over 2 years ago in reply to shabaz

    Yep, looks like we've some reading to do.

    Here's another useful reference: www.kernel.org/.../index.html

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube