# Source tree driver question



## Phishfry (Jul 22, 2016)

I am having a hard time figuring out where in the source tree the driver source would belong.

My device is a driver for external GPIO pins to be named sch311x_gpio for a SMSC SCH3114.

I see the following relevant spots:

/usr/src/sys/dev/sms (exists with an LAN driver >my device manufacturer SMSC=SMS)

/usr/src/sys/i386/i386/ (Gonzo's diff patch uses this directory)

/usr/src/sys/dev/gpio(seems to be spot for gpio_if.m, gpiobus.c and system gpio stuff)

Where would the makefile go?

This book seems good for my file creation but I lack knowledge of correct locations.
https://www.freebsd.org/doc/en/books/arch-handbook/pci.html

Next hurdle after that is where to have it included in my kernel? If used dynamically do I have to recompile kernel or just 'make' my driver and
`kldload sch311x_gpio`?
Thanks in Advance


----------



## Phishfry (Jul 22, 2016)

When I make a driver is it automatically a loadable kernel module? Or is the gpio subsystem "the module" and it looks for drivers?

edit:
Nevermind I missed this page:
https://www.freebsd.org/doc/en/books/arch-handbook/driverbasics-kld.html


----------



## Phishfry (Jul 22, 2016)

I suppose I could 'make' my module anywhere that can find the `#include` files and copy the sch311x_gpio.ko to the boot/modules folder by hand and load.

I am wondering about the proper way.

I note the book above uses kldload -v ./skeleton.ko, So does that mean module in root dir? I dunno what ./ does here?


----------



## kpa (Jul 22, 2016)

Because of the way the system make(1) is configured you can build the sources in any directory you want including /root or a subdirectory of it. The magic incantation is the `.include <bsd.kmod.mk>` which includes a whole bunch of rules that do the correct invocations for the build tools.


----------



## Phishfry (Jul 23, 2016)

Made my first module (outside of usbdevs/u3g.c PID fixup) with minimal effort. Time to test it out.
Thanks for everyones help.


----------



## fossette (Jul 23, 2016)

Phishfry said:


> I note the book above uses kldload -v ./skeleton.ko, So does that mean module in root dir? I dunno what ./ does here?



./ is the directory you currently are (in your shell).  It's just a safeguard in case several files with the same name are in your path.  You may use the pwd(1) command any time to find out where you are.

PS: Had it been April 1st, I would have laughed so hard at you.

Dominique.


----------



## Phishfry (Jul 23, 2016)

Yes I have alot of learning to do...
I need a couple more semesters of FreeBSD education.


----------

