1 | #!/bin/bash
|
---|
2 | # $Id: load.sh 40618 2012-03-25 19:51:16Z vboxsync $
|
---|
3 | ## @file
|
---|
4 | # For development.
|
---|
5 | #
|
---|
6 |
|
---|
7 | #
|
---|
8 | # Copyright (C) 2006-2012 Oracle Corporation
|
---|
9 | #
|
---|
10 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | # available from http://www.virtualbox.org. This file is free software;
|
---|
12 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | # General Public License (GPL) as published by the Free Software
|
---|
14 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | #
|
---|
18 | # The contents of this file may alternatively be used under the terms
|
---|
19 | # of the Common Development and Distribution License Version 1.0
|
---|
20 | # (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
21 | # VirtualBox OSE distribution, in which case the provisions of the
|
---|
22 | # CDDL are applicable instead of those of the GPL.
|
---|
23 | #
|
---|
24 | # You may elect to license modified versions of this file under the
|
---|
25 | # terms and conditions of either the GPL or the CDDL or both.
|
---|
26 | #
|
---|
27 |
|
---|
28 | DRVNAME="vboxdrv"
|
---|
29 | DRIVERS_USING_IT="vboxusbmon vboxusb vboxnet vboxflt vboxbow"
|
---|
30 |
|
---|
31 | DRVFILE=`dirname "$0"`
|
---|
32 | DRVFILE=`cd "$DRVFILE" && pwd`
|
---|
33 | DRVFILE="$DRVFILE/$DRVNAME"
|
---|
34 | if [ ! -f "$DRVFILE" ]; then
|
---|
35 | echo "load.sh: Cannot find $DRVFILE or it's not a file..."
|
---|
36 | exit 1;
|
---|
37 | fi
|
---|
38 | if [ ! -f "$DRVFILE.conf" ]; then
|
---|
39 | echo "load.sh: Cannot find $DRVFILE.conf or it's not a file..."
|
---|
40 | exit 1;
|
---|
41 | fi
|
---|
42 |
|
---|
43 | SUDO=sudo
|
---|
44 | #set -x
|
---|
45 |
|
---|
46 | # Unload driver that may depend on the driver we're going to (re-)load
|
---|
47 | # as well as the driver itself.
|
---|
48 | for drv in $DRIVERS_USING_IT $DRVNAME;
|
---|
49 | do
|
---|
50 | LOADED=`modinfo | grep -w "$drv"`
|
---|
51 | if test -n "$LOADED"; then
|
---|
52 | MODID=`echo "$LOADED" | cut -d ' ' -f 1`
|
---|
53 | $SUDO modunload -i $MODID;
|
---|
54 | LOADED=`modinfo | grep -w "$drv"`;
|
---|
55 | if test -n "$LOADED"; then
|
---|
56 | echo "load.sh: failed to unload $drv";
|
---|
57 | dmesg | tail
|
---|
58 | exit 1;
|
---|
59 | fi
|
---|
60 | fi
|
---|
61 | done
|
---|
62 |
|
---|
63 | #
|
---|
64 | # Reconfigure the driver so it get a major number.
|
---|
65 | #
|
---|
66 | # Note! We have to copy the driver and config files to somewhere the kernel can
|
---|
67 | # find them. It is searched for as drv/${DRVNAME}.conf in
|
---|
68 | # kobj_module_path, which is usually:
|
---|
69 | # /platform/i86pc/kernel /kernel /usr/kernel
|
---|
70 | # To try prevent bad drivers from being loaded on the next boot, we remove
|
---|
71 | # always the files.
|
---|
72 | #
|
---|
73 | MY_RC=1
|
---|
74 | set -e
|
---|
75 | $SUDO rm -f \
|
---|
76 | "/platform/i86pc/kernel/drv/${DRVNAME}.conf" \
|
---|
77 | "/platform/i86pc/kernel/drv/${DRVNAME}" \
|
---|
78 | "/platform/i86pc/kernel/drv/amd64/${DRVNAME}"
|
---|
79 | sync
|
---|
80 | $SUDO cp "${DRVFILE}" /platform/i86pc/kernel/drv/amd64/
|
---|
81 | $SUDO cp "${DRVFILE}.conf" /platform/i86pc/kernel/drv/
|
---|
82 | set +e
|
---|
83 |
|
---|
84 | $SUDO rem_drv $DRVNAME
|
---|
85 | if $SUDO add_drv -v $DRVNAME; then
|
---|
86 | sync
|
---|
87 | if $SUDO modload "/platform/i86pc/kernel/drv/amd64/${DRVNAME}"; then
|
---|
88 | echo "load.sh: successfully loaded the driver"
|
---|
89 | modinfo | grep -w "$DRVNAME"
|
---|
90 | MY_RC=0
|
---|
91 | else
|
---|
92 | dmesg | tail
|
---|
93 | echo "load.sh: modload failed"
|
---|
94 | fi
|
---|
95 | else
|
---|
96 | dmesg | tail
|
---|
97 | echo "load.sh: add_drv failed."
|
---|
98 | fi
|
---|
99 |
|
---|
100 | $SUDO rm -f \
|
---|
101 | "/platform/i86pc/kernel/drv/${DRVNAME}.conf" \
|
---|
102 | "/platform/i86pc/kernel/drv/${DRVNAME}" \
|
---|
103 | "/platform/i86pc/kernel/drv/amd64/${DRVNAME}"
|
---|
104 | sync
|
---|
105 |
|
---|
106 | exit $MY_RC;
|
---|
107 |
|
---|