1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-13 14:40:22 +00:00

Fix ndisgen(8) for amd64

- file(1) does not recognize UTF-16 encoded .INF file:

	netbc564.inf: MPEG ADTS, layer I, v1,  96 kBits, 32 kHz, Stereo

Use egrep(1) to match two strings, i. e., `Signature' and `Class=Net'.

- Fix linking failure.  Generate a temporary Makefile to emluate
official kernel module build process.

- Some minor typo/style fixes.

Reviewed by:	obrien
This commit is contained in:
Jung-uk Kim 2005-07-22 05:49:41 +00:00
parent a3d1edc2b2
commit 4b77209bcc
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=148279

View File

@ -57,6 +57,7 @@ echo " 4] Exit"
echo ""
echo -n " Enter your selection here and press return: "
read KEYPRESS
return
}
@ -78,8 +79,9 @@ echo " you have installed. At this time, the i386 and amd64 architectures"
echo " are both supported. Note that you cannot use a Windows/i386 driver"
echo " with FreeBSD/amd64: you must obtain a Windows/amd64 driver."
echo ""
echo -n " Press any key to continue... "
echo -n " Press return to continue... "
read KEYPRESS
return
}
help2() {
@ -102,8 +104,9 @@ echo ""
echo " If you don't have a driver CD, you should be able to find a driver"
echo " kit on the card or computer vendor's web site."
echo ""
echo -n " Press any key to continue... "
echo -n " Press return to continue... "
read KEYPRESS
return
}
help3 () {
@ -113,7 +116,7 @@ echo ""
echo " In most cases, you will need only two files: a .INF file and a .SYS"
echo " file. The .INF file is a text file used by the Windows(r) installer to"
echo " perform the driver installation. It contains information that tells"
echo " the intaller what devices the driver supports and what registry keys"
echo " the installer what devices the driver supports and what registry keys"
echo " should be created to control driver configuration. The .SYS file"
echo " is the actual driver executable code in Windows(r) Portable Executable"
echo " (PE) format. Note that sometimes the .INF file is supplied in unicode"
@ -126,8 +129,9 @@ echo " extension, though they can be named almost anything. You will need"
echo " these additional files to make your device work with the NDIS"
echo " compatibility system as well."
echo ""
echo -n " Press any key to continue... "
echo -n " Press return to continue... "
read KEYPRESS
return
}
help4 () {
@ -150,8 +154,9 @@ echo " static kernel image for those who want/need a fully linked kernel"
echo " image (possibly for embedded bootstrap purposes, or just plain old"
echo " experimentation)."
echo ""
echo -n " Press any key to continue... "
echo -n " Press return to continue... "
read KEYPRESS
return
}
help5 () {
@ -174,8 +179,9 @@ echo " If you have installed the X Window system or some sort of desktop"
echo " environment, then iconv(1) should already be present. If not, you"
echo " will need to install the libiconv package or port."
echo ""
echo -n " Press any key to continue... "
echo -n " Press return to continue... "
read KEYPRESS
return
}
infconv () {
@ -189,37 +195,39 @@ echo " Please type in the path to your .INF file now."
echo ""
echo -n " > "
read INFPATH
if [ $INFPATH ] && [ -e $INFPATH ];
then
INFTYPE=`${FILE} ${INFPATH}`
if [ ${INFPATH} ] && [ -e ${INFPATH} ]; then
INFTYPE=`${EGREP} -i -c "^Signature|^.S.i.g.n.a.t.u.r.e" ${INFPATH}`
if [ ${INFTYPE} -le 0 ]; then
echo ""
echo " I don't recognize this file format. It may not be a valid .INF file."
echo ""
echo -n " Press enter to try again, or ^C to quit. "
read KEYPRESS
INFPATH=""
return
fi
case ${INFTYPE} in
*ASCII*)
INFTYPE=`${EGREP} -i -c "^Class.*=.*Net" ${INFPATH}`
if [ ${INFTYPE} -gt 0 ]; then
echo ""
echo " This .INF file appears to be ASCII."
echo ""
echo -n " Press any key to continue... "
echo -n " Press return to continue... "
read KEYPRESS
;;
*text*)
echo ""
echo " This .INF file appears to be ASCII."
echo ""
echo -n " Press any key to continue... "
read KEYPRESS
;;
*nicode*)
return
fi
INFTYPE=`${EGREP} -i -c "^.C.l.a.s.s.*=.*N.e.t" ${INFPATH}`
if [ ${INFTYPE} -gt 0 ]; then
echo ""
echo " This .INF file appears to be Unicode."
if [ -e $ICONVPATH ];
then
if [ -e ${ICONVPATH} ]; then
echo " Trying to convert to ASCII..."
${RM} -f /tmp/ascii.inf
${ICONVPATH} -f utf-16 -t utf-8 ${INFPATH} > /tmp/ascii.inf
INFPATH=/tmp/ascii.inf
${ICONVPATH} -f utf-16 -t utf-8 ${INFPATH} > ${INFFILE}
INFPATH=${INFFILE}
echo " Done."
echo ""
echo -n " Press any key to continue... "
echo -n " Press return to continue... "
read KEYPRESS
else
echo " The iconv(1) utility does not appear to be installed."
@ -228,24 +236,24 @@ then
echo ""
exit
fi
;;
*)
echo ""
echo " I don't recognize this file format. It may not be a valid .INF file."
echo ""
echo -n " Press enter to try again, or ^C to quit. "
read KEYPRESS
INFPATH=""
;;
esac
return
fi
echo ""
echo " I don't recognize this file format. It may not be a valid .INF file."
echo ""
echo -n " Press enter to try again, or ^C to quit. "
read KEYPRESS
INFPATH=""
else
echo ""
echo " The file '$INFPATH' was not found."
echo " The file '${INFPATH}' was not found."
echo ""
echo -n " Press enter to try again, or ^C to quit. "
read KEYPRESS
INFPATH=""
fi
return
}
sysconv() {
@ -264,8 +272,7 @@ echo " Please type in the path to the Windows(r) driver .SYS file now."
echo ""
echo -n " > "
read SYSPATH
if [ $SYSPATH ] && [ -e $SYSPATH ];
then
if [ ${SYSPATH} ] && [ -e ${SYSPATH} ]; then
SYSTYPE=`${FILE} ${SYSPATH}`
case ${SYSTYPE} in
@ -273,9 +280,9 @@ then
echo ""
echo " This .SYS file appears to be in Windows(r) PE format."
echo ""
echo -n " Press any key to continue... "
echo -n " Press return to continue... "
read KEYPRESS
SYSBASE=`basename ${SYSPATH} | ${TR} '.' '_'`
SYSBASE=`${BASENAME} ${SYSPATH} | ${TR} '.' '_'`
;;
*)
echo ""
@ -289,12 +296,13 @@ then
esac
else
echo ""
echo " The file '$SYSPATH' was not found."
echo " The file '${SYSPATH}' was not found."
echo ""
echo -n " Press enter to try again, or ^C to quit. "
read KEYPRESS
SYSPATH=""
fi
return
}
ndiscvt() {
@ -322,6 +330,7 @@ else
echo -n " Press enter to continue... "
read KEYPRESS
fi
return
}
firmcvt() {
@ -337,10 +346,10 @@ echo ""
echo -n " > "
read FIRMPATH
if [ $FIRMPATH ] && [ $FIRMPATH != "" ]; then
if [ ! -e $FIRMPATH ]; then
if [ ${FIRMPATH} ]; then
if [ ! -e ${FIRMPATH} ]; then
echo ""
echo " The file '$FIRMPATH' was not found"
echo " The file '${FIRMPATH}' was not found"
echo ""
echo -n " Press enter to try again, or ^C to quit. "
read KEYPRESS
@ -353,7 +362,7 @@ echo ""
echo ""
echo " Conversion was successful."
echo ""
FRMBASE=`basename ${FIRMPATH}`
FRMBASE=`${BASENAME} ${FIRMPATH}`
FRMBASE="${FRMBASE}.o"
FRMLIST="${FRMLIST} ${FRMBASE}"
fi
@ -368,13 +377,14 @@ header
echo ""
echo " List of files converted firmware files:"
echo ""
for i in $FRMLIST
for i in ${FRMLIST}
do
echo " "$i
done
echo ""
echo -n " Press enter to continue... "
read KEYPRESS
return
}
drvgen () {
@ -390,57 +400,81 @@ echo " Press enter to compile the stub module and generate the driver"
echo -n " module now: "
read KEYPRESS
echo ""
touch bus_if.h
touch device_if.h
echo -n " Compiling stub... "
if ! ${CC} -D_KERNEL -DDRV_DATA_START=${SYSBASE}_drv_data_start -DDRV_NAME=${SYSBASE} -DDRV_DATA_END=${SYSBASE}_drv_data_end -I. ${STUBFILE} -c -o windrv_stub.o; then
echo "compilation failed. Exiting."
echo -n " Generating Makefile... "
echo ".PATH: ${PWD} ${STUBPATH}" > ${MAKEFILE}
echo "KMOD= ${SYSBASE}" >> ${MAKEFILE}
echo "SRCS+= ${STUBFILE} ${DNAME}.h bus_if.h device_if.h" >> ${MAKEFILE}
echo "OBJS+=${FRMLIST} ${DNAME}.o" >> ${MAKEFILE}
echo "CFLAGS+= \\" >> ${MAKEFILE}
echo " -DDRV_DATA_START=${SYSBASE}_drv_data_start \\" >> ${MAKEFILE}
echo " -DDRV_NAME=${SYSBASE} \\" >> ${MAKEFILE}
echo " -DDRV_DATA_END=${SYSBASE}_drv_data_end" >> ${MAKEFILE}
echo "CLEANFILES+= \\" >> ${MAKEFILE}
echo " ${INFFILE} \\" >> ${MAKEFILE}
echo " ${DNAME}.h \\" >> ${MAKEFILE}
echo " ${DNAME}.o" >> ${MAKEFILE}
echo ".include <bsd.kmod.mk>" >> ${MAKEFILE}
if [ -f ${MAKEFILE} ]; then
echo "done."
else
echo "generating Makefile failed. Exiting."
echo ""
exit
else
echo "done."
fi
echo -n " Linking loadable kernel module... "
if ! ${LD} -Bshareable -d -warn-common -o ${SYSBASE}.ko windrv_stub.o ${FRMLIST} ${DNAME}.o; then
echo "linking failed. Exiting."
echo -n " Building kernel module... "
echo "" > bus_if.h
echo "" > device_if.h
if ! ${MAKE} -f ${MAKEFILE} depend > /dev/null; then
echo "build failed. Exiting."
echo ""
exit
else
echo "done."
fi
echo -n " Linking static kernel module... "
if ! ${LD} -r -d -warn-common -o ${SYSBASE}.o windrv_stub.o ${FRMLIST} ${DNAME}.o; then
echo "linking failed. Exiting."
if ! ${MAKE} -f ${MAKEFILE} all > /dev/null; then
echo "build failed. Exiting."
echo ""
exit
else
echo "done."
if [ -f ${SYSBASE}.ko ]; then
${MV} ${SYSBASE}.ko ${SYSBASE}.kmod
echo "done."
else
echo "build failed. Exiting."
echo ""
exit
fi
fi
echo -n " Cleaning up... "
${RM} -f bus_if.h device_if.h windrv_stub.o
${RM} -f ${DNAME}.h ${DNAME}.o
echo "done."
if ! ${MAKE} -f ${MAKEFILE} clean cleandepend > /dev/null; then
echo "cleanup failed. Exiting."
echo ""
exit
else
echo "done."
fi
${RM} ${MAKEFILE}
${MV} ${SYSBASE}.kmod ${SYSBASE}.ko
echo ""
echo " The file $SYSBASE.ko has been successfully generated."
echo " The file ${SYSBASE}.ko has been successfully generated."
echo " You can kldload this module to get started."
echo ""
echo -n " Press any key to exit. "
echo -n " Press return to exit. "
read KEYPRESS
echo ""
echo ""
return
}
convert_driver () {
while : ; do
infconv
if [ $INFPATH ] && [ $INFPATH != "" ]; then
if [ ${INFPATH} ]; then
break
fi
done
while : ; do
sysconv
if [ $SYSPATH ] && [ $SYSPATH != "" ]; then
if [ ${SYSPATH} ]; then
break
fi
done
@ -448,18 +482,27 @@ convert_driver () {
ndiscvt
firmcvt
drvgen
return
}
ICONVPATH=/usr/local/bin/iconv
NDISCVT=/usr/sbin/ndiscvt
STUBFILE=/usr/share/misc/windrv_stub.c
STUBPATH=/usr/share/misc
STUBFILE=windrv_stub.c
DNAME=windrv
OBJCOPY=/usr/bin/objcopy
CC=/usr/bin/cc
LD=/usr/bin/ld
CP=/bin/cp
MV=/bin/mv
RM=/bin/rm
TR=/usr/bin/tr
FILE=/usr/bin/file
EGREP=/usr/bin/egrep
MAKE=/usr/bin/make
BASENAME=/usr/bin/basename
TOUCH=/usr/bin/touch
MKTEMP=/usr/bin/mktemp
MAKEFILE=`${MKTEMP} /tmp/Makefile.XXXXXX`
INFFILE=`${MKTEMP} /tmp/ascii_inf.XXXXXX`
INFPATH=""
FRMLIST=""
@ -498,3 +541,4 @@ while : ; do
;;
esac
done
exit