user7194905
user7194905

Reputation: 217

freebsd kernel module - "make" command: unable to locate the kernel source tree. Set SYSDIR to override

I am newbie in freebsd. I installed freebsd on VMware. I want to write first freebsd kernel module. I find this link: How to write a FreeBSD Kernel Module

But in step3, after make command I get: unable to locate the kernel source tree. Set SYSDIR to override.

What is the output of make command? What should I do now?

Upvotes: 3

Views: 6418

Answers (3)

arved
arved

Reputation: 4576

The FreeBSD handbook describes how to get the Kernel Source with svn.

Update FreeBSD now uses git, so The handbook describes how to sync the source with git

Upvotes: 1

nbari
nbari

Reputation: 26925

Before creating/testing your own module I would suggest to first try to compile a generic kernel, next a custom kernel and only after successfully doing all this, try to start testing your modules. The idea of this is to get familiar with how freebsd build process works and help you implement your modules faster.

This are the basic "fast" steps (skiping mergemaster) for doing a full clean upgrade:

  1. cd /usr/src
  2. svnlite co svn://svn.freebsd.org/base/stable/11 /usr/src
  3. make buildworld (if have multiple cores you can try make -j40 buildworld)
  4. make kernel (or make -j40 kernel)
  5. make installworld (skip the mergemaster -p)
  6. yes | make delete-old
  7. cp -R /etc /etc.old && cd /usr/src && make distribution DESTDIR=/
  8. cd /etc.old && cp group passwd master.passwd /etc && pwd_mkdb /etc/master.passwd
  9. reboot
  10. yes | make delete-old-libs

After doing all this, you can start to customise you builds by either editing the /etc/src.conf file and the /etc/make.conf in where you can define to compile only your module and therefore make the build process faster, below and example of an /etc/make.conf which will only compile zfs and opensolaris modules besides using a custom kernel /usr/src/sys/amd64/conf/TEQUILA :

MODULES_OVERRIDE=zfs opensolaris
KERNCONF=TEQUILA

By doing this you can compile/test much faster, you could indeed only do:

MODULES_OVERRIDE=mymodule

Upvotes: 0

Edward Tomasz Napierala
Edward Tomasz Napierala

Reputation: 1836

Generally speaking, where you want to start is checking out the FreeBSD source. Like this:

svnlite co http://svn.freebsd.org/base/head

This will create the "head" directory. Then: move the directory with your modules' source code into head/sys/dev/. Go do head/sys/modules/, use 'pty' as example (cp -r pty yourmodule), modify head/sys/modules/yourmodule/Makefile (it's self-explanatory, just change the output name and source file names), modify head/sys/modules/Makefile to add "yourmodule" (again, just search for "pty" there, copy, paste, rename). Voila - you've connected your kernel module to the build in the best possible way; you can now use "make buildkernel installkernel", kgdb(8) will know where the sources for your code are, you have INVARIANTS enabled etc.

Upvotes: 1

Related Questions