summaryrefslogtreecommitdiffstats
path: root/scripts/mk-dd
blob: e4989924aa4c867cf1ca292f99d52957529a9a19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash

# This scripts creates the files for a driver disk from a driver source
# file. The script follows symbolic links and other nasty things, so don't
# trust it overly much.
#
# To run it, install the kernel-source RPM that you want to build the drivers
# for. You will also need the anaconda-runtime package installed. Once these
# are installed, run this script with the source file name for the module and
# the kernel version as it's arguments. For example:
#
#	./mk-dd eepro100.c 2.4.2-0.1.49
#
# might be appropriate for you.
#
# Drivers will be generated for the uniprocessor, smp, BOOT, and enterprise
# kernels. If you don't need all of these, you may remove the extra drivers
# from the modules.cgz file. If you would like to have drivers for other
# kernels on the same driver disk, repeat this process against a different
# kernel, and combine the modules.cgz files (unpack each one in the same
# place, and repack them with something like "find . -type f | cpio -H crc
# -o | gzip -9 > /some/driver/disk/modules.cgz").
#
# When mk-dd completes, the files in /tmp/modules comprise a driver disk.
# Copy these to a dos or ext2 floppy, and you're all set.
#
# Please note that this script is intended as an example to guide you in
# creating driver disks. Another (in many ways, better) solution is available
# at http://people.redhat.com/~dledford. This driver development kit is
# recommended for most uses.

version=$2
srcname=$1

usage () {
    echo "usage: ./mk-dd <source.c> <kernel-version>"
    exit 1
}

if [ ! -x /usr/lib/anaconda-runtime/modlist -o ! -f /usr/lib/anaconda-runtime/loader/module-info ]; then
    echo "You need to have anaconda-runtime installed."
    usage
fi

modversions=$(rpm -ql kernel-source-$version | grep modversions.h)

if [ ! -f "$srcname" ]; then
    echo "$srcname does not exist"
    usage
fi

if [ ! -f "$modversions" ]; then
    echo "$modversions doesn't exist"
    usage
fi

rm -rf /tmp/modules
mkdir /tmp/modules

name=$(echo $srcname | sed 's/\.c$//')
obj=${name}.ko

klist="UP- SMP-smp ENTERPRISE-enterprise BOOT-BOOT"

for kinfo in $klist; do
    n=$(echo $kinfo | cut -d- -f1)
    dir=/tmp/modules/${version}$(echo $kinfo | cut -d- -f2)

    echo -n "Building $n..."

    defines=""
    for k in $klist; do
	flag=$(echo $k | cut -d- -f1)
	if [ $flag = $n ]; then
	    val=1
	else
	    val=0
	fi

	defines="-D__BOOT_KERNEL_${flag}=${val} $defines"
    done

    mkdir $dir

    gcc $defines -I/usr/src/linux-${version}/include -include $modversions -DMODVERSIONS -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c $srcname -o $dir/$obj

    rc=$?
    echo

    if [ "$rc" != 0 ]; then
	exit 1
    fi
done

cd /tmp/modules
find ${version}* -type f | cpio --quiet -H crc -o | gzip -9 > modules.cgz
rm -rf ${version}*
echo "$name driver disk" > rhdd-6.1
grep "$name" /usr/share/hwdata/pcitable > pcitable
touch modules.dep

/usr/lib/anaconda-runtime/modlist -m -f /usr/lib/anaconda-runtime/loader/module-info $name | sed 's/	"/	"Updated /' > modinfo 

echo "Copy the contents of /tmp/modules to a diskette to create a driver disk."