make_device_driver.sh revision 67568
1193323Sed#!/bin/sh 
2193323Sed# This writes a skeleton driver and puts it into the kernel tree for you
3193323Sed#arg1 is lowercase "foo" 
4193323Sed#
5193323Sed# It also creates a directory under /usr/src/lkm to help you create
6193323Sed#loadable kernel modules, though without much use except for development.
7193323Sed#
8193323Sed# Trust me, RUN THIS SCRIPT :)
9193323Sed# $FreeBSD: head/share/examples/drivers/make_device_driver.sh 67568 2000-10-25 15:08:11Z julian $"
10193323Sed#
11193323Sed#-------cut here------------------
12193323Sedif [ "${1}X" = "X" ] 
13204961Srdivackythen
14198090Srdivacky	echo "Hey , how about some help here.. give me a device name!"
15193323Sed	exit 1
16206274Srdivackyfi
17234353SdimUPPER=`echo ${1} |tr "[:lower:]" "[:upper:]"` 
18221345Sdim
19249423SdimHERE=`pwd`
20249423Sdimcd /sys
21249423SdimTOP=`pwd`
22249423Sdim
23198090Srdivackyecho ${TOP}/modules/${1}
24193323Sedecho ${TOP}/i386/conf/files.${UPPER}
25249423Sdimecho ${TOP}/i386/conf/${UPPER}
26249423Sdimecho ${TOP}/dev/${1}
27249423Sdimecho ${TOP}/dev/${1}/${1}.c
28249423Sdimecho ${TOP}/sys/${1}io.h
29249423Sdimecho ${TOP}/modules/${1}
30249423Sdimecho ${TOP}/modules/${1}/Makefile
31204961Srdivacky
32198090Srdivackyrm -rf ${TOP}/dev/${1}
33198090Srdivackyrm -rf ${TOP}/modules/${1}
34204961Srdivackyrm ${TOP}/i386/conf/files.${UPPER}
35207618Srdivackyrm ${TOP}/i386/conf/${UPPER}
36198090Srdivackyrm ${TOP}/sys/${1}io.h
37198090Srdivacky
38202878Srdivackyif [ -d ${TOP}/modules/${1} ]
39249423Sdimthen
40193323Sed	echo "There appears to already be a module called ${1}"
41249423Sdim	exit 1
42249423Sdimelse
43249423Sdim	mkdir ${TOP}/modules/${1}
44249423Sdimfi
45249423Sdim
46249423Sdim#######################################################################
47193323Sed#######################################################################
48193323Sed#
49212904Sdim# Create configuration information needed to create a kernel
50210299Sed# containing this driver.
51207618Srdivacky#
52207618Srdivacky# Not really needed if we are going to do this as a module.
53208599Srdivacky#######################################################################
54221345Sdim# First add the file to a local file list.
55208599Srdivacky#######################################################################
56208599Srdivacky
57249423Sdimcat >${TOP}/i386/conf/files.${UPPER} <<DONE
58249423Sdimi386/isa/${1}.c	 optional ${1} device-driver
59249423SdimDONE
60249423Sdim
61243830Sdim#######################################################################
62243830Sdim# Then create a configuration file for a kernel that contains this driver.
63243830Sdim#######################################################################
64243830Sdimcat >${TOP}/i386/conf/${UPPER} <<DONE
65243830Sdim# Configuration file for kernel type: ${UPPER}
66243830Sdimident	${UPPER}
67243830Sdim# \$FreeBSD: head/share/examples/drivers/make_device_driver.sh 67568 2000-10-25 15:08:11Z julian $"
68234353SdimDONE
69243830Sdim
70243830Sdimgrep -v GENERIC < /sys/i386/conf/GENERIC >>${TOP}/i386/conf/${UPPER}
71243830Sdim
72243830Sdimcat >>${TOP}/i386/conf/${UPPER} <<DONE
73243830Sdimoptions	DDB		# trust me, you'll need this
74243830Sdimdevice ${1} at isa?
75234353SdimDONE
76243830Sdim
77243830Sdimif [ ! -d ${TOP}/dev/${1} ]
78243830Sdimthen
79243830Sdim	mkdir -p ${TOP}/dev/${1}
80243830Sdimfi
81243830Sdim
82243830Sdim
83243830Sdim
84243830Sdim
85249423Sdim
86249423Sdim
87249423Sdim
88249423Sdim
89249423Sdim
90249423Sdim
91249423Sdim
92249423Sdim
93249423Sdim
94207618Srdivacky
95207618Srdivacky
96207618Srdivacky
97207618Srdivacky
98207618Srdivacky
99193323Sedcat >${TOP}/dev/${1}/${1}.c <<DONE
100193323Sed/*
101249423Sdim * Copyright ME
102249423Sdim *
103193323Sed * ${1} driver
104193323Sed * \$FreeBSD: head/share/examples/drivers/make_device_driver.sh 67568 2000-10-25 15:08:11Z julian $
105193323Sed */
106193323Sed
107226633Sdim
108221345Sdim#include <sys/param.h>
109221345Sdim#include <sys/systm.h>
110221345Sdim#include <sys/conf.h>		/* cdevsw stuff */
111221345Sdim#include <sys/kernel.h>		/* SYSINIT stuff */
112221345Sdim#include <sys/uio.h>		/* SYSINIT stuff */
113221345Sdim#include <sys/malloc.h>		/* malloc region definitions */
114221345Sdim#include <sys/module.h>
115221345Sdim#include <sys/bus.h>
116221345Sdim#include <machine/bus.h>
117221345Sdim#include <machine/resource.h>
118249423Sdim#include <sys/rman.h>
119221345Sdim#include <sys/time.h>
120221345Sdim
121249423Sdim#include <isa/isavar.h>
122221345Sdim#include "isa_if.h"
123221345Sdim#include <sys/${1}io.h>		/* ${1} IOCTL definitions */
124221345Sdim
125221345Sdim#define ${UPPER}DEV2SOFTC(dev) ((dev)->si_drv1)
126221345Sdim#define ${UPPER}_INB(port) bus_space_read_1( bt, bh, (port))
127249423Sdim#define ${UPPER}_OUTB(port, val) bus_space_write_1( bt, bh, (port), (val))
128221345Sdim#define SOME_PORT 123
129221345Sdim#define EXPECTED_VALUE 0x42
130249423Sdim
131221345Sdim
132221345Sdim/* Function prototypes (these should all be static) */
133221345Sdimstatic int ${1}_isa_probe (device_t);
134221345Sdimstatic int ${1}_isa_attach (device_t);
135221345Sdimstatic int ${1}_isa_detach (device_t);
136221345Sdim
137221345Sdimstatic d_open_t		${1}open;
138249423Sdimstatic d_close_t	${1}close;
139221345Sdimstatic d_read_t		${1}read;
140221345Sdimstatic d_write_t	${1}write;
141221345Sdimstatic d_ioctl_t	${1}ioctl;
142212904Sdimstatic d_mmap_t		${1}mmap;
143249423Sdimstatic d_poll_t		${1}poll;
144221345Sdimstatic	void		${1}intr(void *arg);
145221345Sdim 
146249423Sdim#define CDEV_MAJOR 20
147221345Sdimstatic struct cdevsw ${1}_cdevsw = {
148221345Sdim	/* open */	${1}open,
149221345Sdim	/* close */	${1}close,
150221345Sdim	/* read */	${1}read,
151221345Sdim	/* write */	${1}write,
152221345Sdim	/* ioctl */	${1}ioctl,
153212904Sdim	/* poll */	${1}poll,
154221345Sdim	/* mmap */	${1}mmap,
155221345Sdim	/* strategy */	nostrategy,	/* not a block type device */
156193323Sed	/* name */	"${1}",
157206274Srdivacky	/* maj */	CDEV_MAJOR,
158193323Sed	/* dump */	nodump,		/* not a block type device */
159206274Srdivacky	/* psize */	nopsize,	/* not a block type device */
160208599Srdivacky	/* flags */	0,
161212904Sdim	/* bmaj */	-1
162249423Sdim};
163249423Sdim 
164249423Sdim/* 
165249423Sdim * device specific Misc defines 
166249423Sdim */
167249423Sdim#define BUFFERSIZE 1024
168249423Sdim#define NUMPORTS 4
169212904Sdim#define MEMSIZE	1024*1024 /* imaginable h/w buffer size */
170223017Sdim
171206274Srdivacky/*
172249423Sdim * One of these per allocated device
173249423Sdim */
174208599Srdivackystruct ${1}_softc {
175234353Sdim	bus_space_tag_t bt;
176243830Sdim	bus_space_handle_t bh;
177243830Sdim	int rid_ioport;
178249423Sdim	int rid_memory;
179243830Sdim	int rid_irq;
180249423Sdim	int rid_drq;
181249423Sdim	struct resource* res_ioport;	/* resource for port range */
182243830Sdim	struct resource* res_memory;	/* resource for mem range */
183249423Sdim	struct resource* res_irq;	/* resource for irq range */
184243830Sdim	struct resource* res_drq;	/* resource for dma channel */
185249423Sdim	device_t device;
186243830Sdim	dev_t dev;
187243830Sdim	void	*intr_cookie;
188249423Sdim	char	buffer[BUFFERSIZE];
189249423Sdim} ;
190243830Sdim
191249423Sdimtypedef	struct ${1}_softc *sc_p;
192243830Sdim
193249423Sdimdevclass_t ${1}_devclass;
194243830Sdim
195249423Sdimstatic struct isa_pnp_id ${1}_ids[] = {
196249423Sdim	{0x12345678, "ABCco Widget"},
197249423Sdim	{0xfedcba98, "shining moon Widget ripoff"},
198249423Sdim	{0}
199249423Sdim};
200210299Sed
201210299Sedstatic device_method_t ${1}_methods[] = {
202249423Sdim	DEVMETHOD(device_probe,		${1}_isa_probe),
203207618Srdivacky	DEVMETHOD(device_attach,	${1}_isa_attach),
204193323Sed	DEVMETHOD(device_detach,	${1}_isa_detach),
205193323Sed	{ 0, 0 }
206193323Sed};
207193323Sed
208249423Sdimstatic driver_t ${1}_isa_driver = {
209249423Sdim	"${1}",
210249423Sdim	${1}_methods,
211234353Sdim	sizeof (struct ${1}_softc)
212234353Sdim};
213234353Sdim
214234353SdimDRIVER_MODULE(${1}, isa, ${1}_isa_driver, ${1}_devclass, 0, 0);
215234353Sdim
216234353Sdim
217234353Sdim/*
218234353Sdim * The ISA code calls this for each device it knows about,
219234353Sdim * whether via the PNP code or via the hints etc.
220249423Sdim */
221249423Sdimstatic int
222234353Sdim${1}_isa_probe (device_t device)
223234353Sdim{
224249423Sdim	int error;
225249423Sdim	sc_p scp = device_get_softc(device);
226249423Sdim	bus_space_handle_t  bh;
227205218Srdivacky	bus_space_tag_t bt;
228205218Srdivacky	struct resource* res_ioport;	/* resource for port range */
229205218Srdivacky	struct resource* res_memory;	/* resource for mem range */
230249423Sdim	struct resource* res_irq;	/* resource for irq range */
231205218Srdivacky	struct resource* res_drq;	/* resource for dma channel */
232205218Srdivacky	int	size = 16; /* SIZE of port range used */
233249423Sdim
234249423Sdim
235249423Sdim	bzero(scp, sizeof(*scp));
236249423Sdim	scp->device = device;
237249423Sdim
238249423Sdim	/*
239249423Sdim	 * Check for a PNP match..
240249423Sdim	 * There are several possible outcomes.
241249423Sdim	 * error == 0		We match a PNP device (possibly several?).
242249423Sdim	 * error == ENXIO,	It is a PNP device but not ours.
243249423Sdim	 * error == ENOENT,	I is not a PNP device.. try heuristic probes.
244249423Sdim	 *    -- logic from if_ed_isa.c, added info from isa/isa_if.m:
245249423Sdim	 */
246249423Sdim	error = ISA_PNP_PROBE(device_get_parent(device), device, ${1}_ids);
247249423Sdim	switch (error) {
248249423Sdim	case 0:
249249423Sdim		/*
250249423Sdim		 * We found a PNP device.
251249423Sdim		 * Fall through into the code that just looks
252249423Sdim		 * for a non PNP device as that should 
253249423Sdim		 * act as a good filter for bad stuff.
254249423Sdim		 */
255193323Sed	case ENOENT:
256193323Sed		/*
257193323Sed		 * Well it didn't show up in the PNP tables
258193323Sed		 * so look directly at known ports (if we have any)
259193323Sed		 * in case we are looking for an old pre-PNP card.
260249423Sdim		 *
261193323Sed		 * The ports etc should come from a 'hints' section
262193323Sed		 * buried somewhere. XXX - still not figured out.
263193323Sed		 * which is read in by code in isa/isahint.c
264193323Sed		 */
265249423Sdim  
266193323Sed        	res_ioport = bus_alloc_resource(device, SYS_RES_IOPORT,
267193323Sed				&scp->rid_ioport, 0ul, ~0ul, size, RF_ACTIVE);
268249423Sdim        	if (res_ioport == NULL) {
269193323Sed			error = ENXIO;
270193323Sed			goto errexit;
271193323Sed        	}
272193323Sed		res_irq = bus_alloc_resource(device, SYS_RES_IRQ,
273193323Sed				&scp->rid_irq, 0ul, ~0ul, 1, RF_SHAREABLE);
274193323Sed        	if (res_irq == NULL) {
275249423Sdim			error = ENXIO;
276249423Sdim			goto errexit;
277249423Sdim        	}
278202375Srdivacky		res_drq = bus_alloc_resource(device, SYS_RES_DRQ,
279202375Srdivacky				&scp->rid_drq, 0ul, ~0ul, 1, RF_ACTIVE);
280202375Srdivacky        	if (res_drq == NULL) {
281202375Srdivacky			error = ENXIO;
282202375Srdivacky			goto errexit;
283202375Srdivacky        	}
284202375Srdivacky        	res_memory = bus_alloc_resource(device, SYS_RES_IOPORT,
285234353Sdim				&scp->rid_memory, 0ul, ~0ul, MSIZE, RF_ACTIVE);
286234353Sdim        	if (res_memory == NULL) {
287234353Sdim			error = ENXIO;
288234353Sdim			goto errexit;
289234353Sdim        	}
290234353Sdim
291234353Sdim                scp->res_ioport = res_ioport;
292234353Sdim                scp->res_memory = res_memory;
293234353Sdim                scp->res_drq = res_drq;
294234353Sdim                scp->res_irq = res_irq;
295234353Sdim		scp->bt = bt = rman_get_bustag(res_ioport);
296234353Sdim		scp->bh = bh = rman_get_bushandle(res_ioport);
297234353Sdim
298234353Sdim		if ( ${UPPER}_INB(SOME_PORT) != EXPECTED_VALUE) {
299234353Sdim			/* 
300234353Sdim			 * It isn't what we expected,
301234353Sdim			 * so release everything and quit looking for it.
302234353Sdim			 */
303234353Sdim			goto errexit;
304234353Sdim		}
305234353Sdim		error = 0;
306234353Sdim		break;
307234353Sdim	case  ENXIO:
308234353Sdim		/* not ours, leave imediatly */
309234353Sdimerrexit:
310234353Sdim		/* cleanup anything we may have assigned. */
311234353Sdim		${1}_isa_detach(device);
312234353Sdim	default:
313234353Sdim		error = ENXIO;
314234353Sdim	}
315234353Sdim	return (error);
316234353Sdim}
317234353Sdim
318234353Sdim/*
319234353Sdim * Called if the probe succeeded.
320234353Sdim * We can be destructive here as we know we have the device.
321249423Sdim */
322234353Sdimstatic int
323234353Sdim${1}_isa_attach (device_t device)
324234353Sdim{
325234353Sdim	int	unit = device_get_unit(device);
326234353Sdim	sc_p scp = device_get_softc(device);
327234353Sdim	device_t parent = device_get_parent(device);
328234353Sdim
329234353Sdim	scp->dev = make_dev(&${1}_cdevsw, 0, 0, 0, 0600, "${1}%d", unit);
330234353Sdim	scp->dev->si_drv1 = scp;
331234353Sdim	/* register the interrupt handler as default */
332234353Sdim	if (scp->res_irq) {
333234353Sdim		/* default to the tty mask for registration */  /* XXX */
334234353Sdim		if (BUS_SETUP_INTR(parent, device, scp->res_irq, INTR_TYPE_TTY,
335234353Sdim				${1}intr, device, &scp->intr_cookie) == 0) {
336234353Sdim			/* do something if successfull */
337234353Sdim		}
338234353Sdim	}
339234353Sdim	return 0;
340234353Sdim}
341234353Sdim
342249423Sdimstatic int
343249423Sdim${1}_isa_detach (device_t device)
344249423Sdim{
345226633Sdim	sc_p scp = device_get_softc(device);
346226633Sdim	device_t parent = device_get_parent(device);
347208599Srdivacky
348210299Sed	if (scp->res_irq != 0) {
349206274Srdivacky		if (BUS_TEARDOWN_INTR(parent, device,
350206274Srdivacky			scp->res_irq, scp->intr_cookie) != 0) {
351212904Sdim				printf("intr teardown failed.. continuing\n");
352243830Sdim		}
353243830Sdim		bus_deactivate_resource(device, SYS_RES_IRQ,
354243830Sdim			scp->rid_irq, scp->res_irq);
355249423Sdim		bus_release_resource(device, SYS_RES_IRQ,
356249423Sdim			scp->rid_irq, scp->res_irq);
357249423Sdim		scp->res_irq = 0;
358243830Sdim	}
359210299Sed	if (scp->res_ioport != 0) {
360249423Sdim		bus_deactivate_resource(device, SYS_RES_IOPORT,
361249423Sdim			scp->rid_ioport, scp->res_ioport);
362221345Sdim		bus_release_resource(device, SYS_RES_IOPORT,
363249423Sdim			scp->rid_ioport, scp->res_ioport);
364249423Sdim		scp->res_ioport = 0;
365210299Sed	}
366243830Sdim	if (scp->res_ioport != 0) {
367243830Sdim		bus_deactivate_resource(device, SYS_RES_MEMORY,
368243830Sdim			scp->rid_memory, scp->res_memory);
369243830Sdim		bus_release_resource(device, SYS_RES_MEMORY,
370243830Sdim			scp->rid_memory, scp->res_memory);
371243830Sdim		scp->res_ioport = 0;
372243830Sdim	}
373243830Sdim	if (scp->res_drq != 0) {
374243830Sdim		bus_deactivate_resource(device, SYS_RES_DRQ,
375243830Sdim			scp->rid_drq, scp->res_drq);
376243830Sdim		bus_release_resource(device, SYS_RES_DRQ,
377243830Sdim			scp->rid_drq, scp->res_drq);
378243830Sdim		scp->res_drq = 0;
379243830Sdim	}
380243830Sdim	if (scp->dev) {
381243830Sdim		destroy_dev(scp->dev);
382243830Sdim	}
383243830Sdim	return (0);
384243830Sdim}
385243830Sdim
386243830Sdimstatic void
387243830Sdim${1}intr(void *arg)
388243830Sdim{
389243830Sdim	/*device_t dev = (device_t)arg;*/
390243830Sdim	/* sc_p scp	= device_get_softc(dev);*/
391243830Sdim
392243830Sdim	/* 
393243830Sdim	 * well we got an interupt, now what?
394243830Sdim	 */
395243830Sdim	return;
396243830Sdim}
397249423Sdim
398249423Sdimstatic int
399243830Sdim${1}ioctl (dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
400243830Sdim{
401243830Sdim	sc_p scp	= ${UPPER}DEV2SOFTC(dev);
402210299Sed	bus_space_handle_t  bh = scp->bh;
403210299Sed	bus_space_tag_t bt = scp->bt;
404249423Sdim
405249423Sdim	switch (cmd) {
406249423Sdim	case DHIOCRESET:
407249423Sdim		/* whatever resets it */
408249423Sdim		${UPPER}_OUTB(SOME_PORT, 0xff) ;
409249423Sdim		break;
410206274Srdivacky	default:
411206274Srdivacky		return ENXIO;
412221345Sdim	}
413203954Srdivacky	return (0);
414234353Sdim}
415234353Sdim/*
416234353Sdim * You also need read, write, open, close routines.
417249423Sdim * This should get you started
418206274Srdivacky */
419199481Srdivackystatic int
420193323Sed${1}open(dev_t dev, int oflags, int devtype, struct proc *p)
421249423Sdim{
422249423Sdim	sc_p scp	= ${UPPER}DEV2SOFTC(dev);
423249423Sdim
424226633Sdim	/* 
425207618Srdivacky	 * Do processing
426207618Srdivacky	 */
427207618Srdivacky	return (0);
428207618Srdivacky}
429226633Sdim
430207618Srdivackystatic int
431207618Srdivacky${1}close(dev_t dev, int fflag, int devtype, struct proc *p)
432207618Srdivacky{
433226633Sdim	sc_p scp	= ${UPPER}DEV2SOFTC(dev);
434207618Srdivacky
435207618Srdivacky	/* 
436212904Sdim	 * Do processing
437207618Srdivacky	 */
438221345Sdim	return (0);
439249423Sdim}
440243830Sdim
441226633Sdimstatic int
442207618Srdivacky${1}read(dev_t dev, struct uio *uio, int ioflag)
443208599Srdivacky{
444208599Srdivacky	sc_p scp	= ${UPPER}DEV2SOFTC(dev);
445207618Srdivacky	int	 toread;
446207618Srdivacky
447207618Srdivacky
448207618Srdivacky	/* 
449207618Srdivacky	 * Do processing
450207618Srdivacky	 * read from buffer
451249423Sdim	 */
452249423Sdim	toread = (min(uio->uio_resid, sizeof(scp->buffer)));
453207618Srdivacky	return(uiomove(scp->buffer, toread, uio));
454208599Srdivacky}
455193323Sed
456204961Srdivackystatic int
457204961Srdivacky${1}write(dev_t dev, struct uio *uio, int ioflag)
458212904Sdim{
459249423Sdim	sc_p scp	= ${UPPER}DEV2SOFTC(dev);
460249423Sdim	int	towrite;
461193323Sed
462199481Srdivacky	/* 
463199481Srdivacky	 * Do processing
464193323Sed	 * write to buffer
465249423Sdim	 */
466249423Sdim	towrite = (min(uio->uio_resid, sizeof(scp->buffer)));
467226633Sdim	return(uiomove(scp->buffer, towrite, uio));
468226633Sdim}
469226633Sdim
470234353Sdimstatic int
471234353Sdim${1}mmap(dev_t dev, vm_offset_t offset, int nprot)
472207618Srdivacky{
473226633Sdim	sc_p scp	= ${UPPER}DEV2SOFTC(dev);
474226633Sdim
475226633Sdim	/* 
476226633Sdim	 * Do processing
477226633Sdim	 */
478226633Sdim#if 0	/* if we had a frame buffer or whatever.. do this */
479243830Sdim	if (offset > FRAMEBUFFERSIZE - PAGE_SIZE) {
480226633Sdim		return (-1);
481226633Sdim	}
482226633Sdim	return i386_btop((FRAMEBASE + offset));
483226633Sdim#else
484249423Sdim	return (-1);
485249423Sdim#endif
486207618Srdivacky}
487210299Sed
488243830Sdimstatic int
489207618Srdivacky${1}poll(dev_t dev, int which, struct proc *p)
490204961Srdivacky{
491204961Srdivacky	sc_p scp	= ${UPPER}DEV2SOFTC(dev);
492204961Srdivacky
493204961Srdivacky	/* 
494207618Srdivacky	 * Do processing
495223017Sdim	 */
496221345Sdim	return (0); /* this is the wrong value I'm sure */
497221345Sdim}
498193323Sed
499226633SdimDONE
500226633Sdim
501226633Sdimcat >${TOP}/sys/${1}io.h <<DONE
502226633Sdim/*
503226633Sdim * Definitions needed to access the ${1} device (ioctls etc)
504249423Sdim * see mtio.h , ioctl.h as examples
505243830Sdim */
506226633Sdim#ifndef SYS_DHIO_H
507226633Sdim#define SYS_DHIO_H
508226633Sdim
509226633Sdim#ifndef KERNEL
510226633Sdim#include <sys/types.h>
511226633Sdim#endif
512226633Sdim#include <sys/ioccom.h>
513226633Sdim
514249423Sdim/*
515249423Sdim * define an ioctl here
516226633Sdim */
517199481Srdivacky#define DHIOCRESET _IO('D', 0) /* reset the ${1} device */
518199481Srdivacky#endif
519199481SrdivackyDONE
520199481Srdivacky
521226633Sdimif [ ! -d ${TOP}/modules/${1} ]
522226633Sdimthen
523226633Sdim	mkdir -p ${TOP}/modules/${1}
524226633Sdimfi
525208599Srdivacky
526208599Srdivackycat >${TOP}/modules/${1}/Makefile <<DONE
527199481Srdivacky#	${UPPER} Loadable Kernel Module
528199481Srdivacky#
529234353Sdim# $FreeBSD: head/share/examples/drivers/make_device_driver.sh 67568 2000-10-25 15:08:11Z julian $
530208599Srdivacky 
531199481Srdivacky.PATH:  \${.CURDIR}/../../dev/${1}
532204961SrdivackyKMOD    = ${1}
533199481SrdivackySRCS    = ${1}.c
534199481SrdivackySRCS    += opt_inet.h device_if.h bus_if.h pci_if.h isa_if.h
535234353Sdim  
536249423Sdim# you may need to do this is your device is an if_xxx driver
537249423Sdimopt_inet.h:
538221345Sdim	echo "#define INET 1" > opt_inet.h
539199481Srdivacky	   
540234353Sdim.include <bsd.kmod.mk>
541234353SdimDONE
542234353Sdim
543249423Sdim(cd ${TOP}/modules/${1}; make depend; make )
544199481Srdivackyexit
545193323Sed
546193323Sedconfig ${UPPER}
547249423Sdimcd ../../compile/${UPPER}
548226633Sdimmake depend
549204961Srdivackymake ${1}.o
550204961Srdivackymake
551212904Sdimexit
552249423Sdim
553249423Sdim#--------------end of script---------------
554249423Sdim#
555249423Sdim#edit to your taste..
556249423Sdim#
557249423Sdim# 
558234353Sdim
559243830Sdim
560221345Sdim
561221345Sdim
562226633Sdim