Compiling device drivers

Is there a easy way to compile drivers from the command line?

I can compile C programs okay from the terminal, can I do the same for device drivers.

Yes, just use jam and check the Haiku sources for inspiration.

I am trying to understand how to use jam to compile individual .c files but the documentation is not that clear worse if I go to https://www.haiku-os.org/guides/building/jam/ it only talks about compiling the entire source code so I tried the links at the bottom of the page only to find none of the links want to be rendered as HTML files, instead I only get raw HTML text.

The general JAM websites are not a lot better. What happened to giving simple examples now-a-days? Everything seem to be written to need an expert to explain what is going on.

On the other hand I just maybe too dumb … I really think it could possible I am smart enough to understand what is written,

Paladin can generate you a driver template.
Or you can use makefile-engine.

2 Likes

If you want to build drivers that are part of Haiku, you just run jam with the target name. For example “jam -q intel_extreme” to build the intel_extreme driver.

If you want to work on your own driver, using the makefile engine may be a simpler choice. The template should have examples on how to use it to build a driver.

3 Likes

If you give a look at makefile-engine content, which is indeed the simpler way to build a driver outside Haiku’s jam-based setup, you will see the specific settings for building a driver by tracking what is done when TYPE variable value is DRIVER:

Compiler flags:
-D_KERNEL_MODE=1 -fno-pic

Linker flags:
-nostdlib /boot/system/develop/lib/KERNEL /boot/system/develop/lib/haiku_version_glue.o

Which should be easy enough to port to another build system if you have too (CMake, SCons, etc.)

Did you manage to compile your driver?
And can you explain how you proceeded , I’ll try well with BSD binaries

1 Like

I just finish my backups and install the latest haiku - so I cam going to start trying to compile driver now.

Sorry for taking so long to answer.

Well, I started work on compiling my old programs to for 32-bit Haiku to the new 64-bit Haiku versions.

I got my CLI programs to compile alright but still had problems compiling the driver from the Terminal. So I tried using Paladin as my IDE to get the job done.

CLI compiled okay. Tracker-Addons also compile okay. But still problem compiling drivers so I looked at the PLD files created by Paladin, there is a problem is how it creates files for drivers! I think I know what the fix is and plan to test out my ideas this weekend. But how do I get the authour to add the fixes to gis program if I get it working?

I just downloaded the source code, but since I don’t know how to use GIT if I find the code that need changing how do I sent the changes to the authour?

Okay, I have found DarkWyrm’s Haiku Sitem can I make suggestions there?

Palladin is deprecated and not developed anymore, afaik.
Palladin hosted at Haikuarchives, so your options:

  • Learn git, create a PR
  • Use the web Interface, create a PR
  • Create a diff, create an issue at Paladin site on Github, attach your diff.
  • create a diff, ask somebody on IRC to make a PR for you

Darkwyrm is not active anymore.

Hi Earl,

Have a look at this blog post Contributing via pull requests.

It shows the simplest way to create a pull request with git.
Knowing the basics of git are a usefull skill to learn. And once you take the initial plunge, things get easier as you learn step-by-step, i.e. mistake-by-mistake. :slight_smile:

Thanks you for the help.

If I use -fno-pic it do not link properly add recommends I use -fPIC.it compiles.

But is I put the drivers in the bin directory and link it to the dev directory the syslog shows the drive is loaded then fails with “bad data”.
/

What I use to compile is:

mkdir -p objects.x86_64-cc5-release;

mkdepend -I./ -I. -p .c:objects.x86_64-cc5-release/%n.o -m -f “objects.x86_64-cc5-release/xxxx.d” xxxx.c

cc -c xxxx.c -iquote./ -iquote./ -iquote. -isystem/boot/develop/headers/be -isystem/boot/develop/headers/cpp -isystem/boot/develop/headers/posix -isystem/boot/home/config/include -D_KERNEL_MODE=1 -fPIC -O0 -o “objects.x86_64-cc5-release/xxxx.o”

cc -o “objects.x86_64-cc5-release/xxxx” objects.x86_64-cc5-release/xxxx.o -nostdlib /boot/system/develop/lib/KERNEL /boot/system/develop/lib/haiku_version_glue.o -L./ /boot/system/lib/libroot.so /boot/system/lib/libbe.so /boot/system/lib/libsupc++.so

xres -o objects.x86_64-cc5-release/xxxx

mimeset -f “objects.x86_64-cc5-release/xxxx”

The driver I compiled is zero.c but I replaces all the text zero in the source code with xxxx and renamed the file to xxxx.c

However, when I place the file and it’s like in the dev and bin directories I get:

KERN: loaded driver /boot/system/add-ons/kernel/drivers/dev/zero
KERN: Could not load kernel add-on “/boot/system/non-packaged/add-ons/kernel/drivers/dev/xxxx”: Bad data
KERN: Could not load kernel add-on “/boot/home/config/non-packaged/add-ons/kernel/drivers/dev/xxxx”: Bad data

I don’t know where the statement “Bad data” is coming from.

The word like should be link.

I don’t think you can use those libraries in kernel mode. They probably try to access user mode things, which don’t exist in kernel mode, thus loading the driver fails.

Clearly those additionnals userland libs after -L won’t and can’t be loaded by kernel modules manager, hence the Bad data error. And it also why linking with those can’t works with -fno-pic option, which is really required for kernel drivers and modules.