# Rewriting Drivers



## Unee0x (Jul 6, 2018)

Suppose I want to rewrite a driver that was already written for Linux / Windows. What parts (if any) could I use ? And what parts essentially must change in order to make a whole BSD driver free and clear of any blow back?

thanks in advance


----------



## Crivens (Jul 6, 2018)

You will need:

The book "FreeBSD device drivers".
The book "Design and Implementation ..."
A good memory because c&p is out of question.
Skills in async programming.
Knowledge of the hardware in question.
Errata sheets.
Coffee.
Knowledge of kernel debugging.
Highspeed camera (don't laugh. That one actually came in quite handy!)
More coffee.
If available, logic analyzer with tracer.
A test system with LAN connection and SSD for fast booting (no testing on your development system).
Backups
The list may not be complete, but those items are what I found handy or absolute neccessary.


----------



## Crivens (Jul 6, 2018)

Oh, and depending on the origin of your original driver, you may well need some legal counsel.

What hardware would that be, by the way, if I might ask?


----------



## rigoletto@ (Jul 6, 2018)

If IIRC ralphbsz already give some hints about this subject (porting/license inssues) before, but I may be wrong.


----------



## rigoletto@ (Jul 9, 2018)

Unee0x drivers often born BSD/MIT licensed (by the device manufacturer) and later Linux people manage somehow to stamp a GPLx license on it later. You may want to look for an eventual original code from the manufacturer.


----------



## _martin (Jul 12, 2018)

Don't know, it's just maybe me ... I'd first attempt to write the driver and worry about legal things later ..


----------



## sidetone (Jul 16, 2018)

_martin said:


> Don't know, it's just maybe me ... I'd first attempt to write the driver and worry about legal things later ..


If going that route,  it's better to publish it first as the undisputed author or organization before publicly plugging it into GPL code.

But it's better to sort things out first.


----------



## DriverBuilder (Jul 17, 2018)

Take a look in /usr/src/sys/compat/linuxkpi/common/include/linux , it helps to identify correct alternative for linux functions. 
Ex: gfp.h contains FreeBSD equivalents for gfp_* flags.


----------



## fnoyanisi (Jul 21, 2018)

Join the appropriate mailing list, ask questions.
There most probably are people who have done what you want to achive. For wireless NIC drivers, the list is freebsd-wireless for example.

Even if you port a driver, you may still be bound to the original licensing terms (remember, you are modifying the code to get the driver work in FreeBSD, it is a derivate work not something new). Understanding the licensing constraints, if there is any, is important here.


----------

