Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Jul 2005 11:53:46 -0400
From:      Jung-uk Kim <jkim@niksun.com>
To:        freebsd-amd64@freebsd.org, Kelly Black <kjblack@gmail.com>
Subject:   Re: Using ndisgen to create loadable module w/ broadcom on Compaq R3000z
Message-ID:  <200507201153.49441.jkim@niksun.com>
In-Reply-To: <1b1b33f1050720061764ca7eeb@mail.gmail.com>
References:  <1b1b33f1050720061764ca7eeb@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--Boundary-00=_NOn3CW+BGOXcV6d
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On Wednesday 20 July 2005 09:17 am, Kelly Black wrote:
> Hello,
>
> I have a compaq R300z (okay, I'm sorry already!)  running
> freebsd-amd64 current. I recently tried to use ndisulator for the
> built in broadcom wireless and used the 64 bit windows drivers to
> try to generate a loadable module for the wireless device. I have
> had some trouble generating the loadable module, though. I last
> updated world and the kernel on Monday.
>
> I've tried searching the freebsd-amd64 and freebsd-current lists,
> and I've tried to search using google. So far I can't find anything
> to help. Has anyone managed to get this beast working?  Any help
> would be appreciated. I will paste an overview of what I've tried
> below:
>
> Here is the device info:
> root@localhost# pciconf -lvvv
> none3@pci2:2:0: class=0x028000 card=0x12f4103c chip=0x432014e4
> rev=0x03 hdr=0x00 vendor   = 'Broadcom Corporation'
>     device   = 'BCM4306 802.11b/g Wireless LAN Controller'
>
> Copies of the driver files that I am using can be found at
> http://blackk.union.edu/~black/freebsd/BCMWL564.SYS
> http://blackk.union.edu/~black/freebsd/netbc564.inf.ascii
> This is a 64 bit driver, and the inf file was converted to ascii
> using iconv.
>
> Here is the message I get when I use ndisgen:
> Compiling stub... done.
> Linking loadable kernel module... /usr/bin/ld: windrv_stub.o:
> relocation R_X86_64_32S can not be used when making a shared
> object; recompile with -fPIC windrv_stub.o: could not read symbols:
> Bad value linking failed. Exiting.
>
> I read through the ndisgen script to try to figure out what it was
> doing. I then did this (I added -fPIC):
>
> /usr/bin/cc -D_KERNEL -DDRV_DATA_START=BCMWL564_SYS_drv_data_start
> -DDRV_NAME=BC MWL564_SYS -DDRV_DATA_END=BCMWL564_SYS_drv_data_end
> -I. /usr/share/misc/windrv_stub.c -data -symbolic  -c -o
> windrv_stub.o -fPIC
>
> /usr/bin/ld -Bshareable -d -warn-common -o BCMWL564_SYS.ko
> windrv_stub.o windrv.o
>
> /usr/bin/ld -r -d -warn-common -o BCMWL564_SYS.o windrv_stub.o
> windrv.o
>
> (The files windrv_stub.o and others were created when ndisgen
> called ndiscvt so I just left them alone.)
>
> When I do this the file compiles and links with no error messages.
> It creates a file called BCMWL564_SYS.ko. When I try to load the
> file using kldload I get these messages:
>
> kldload: can't load /tmp/broadcom/BCMWL564_SYS.ko: Exec format
> error
>
> and from the console window:
>
> kldload: Unsupported file type
> kldload: unexpected relocation type 7
> link_elf: symbol windrv_load undefined
>
> Any ideas?

Try the attached patch.  I have been using this for months without a 
problem. ;-)  In fact, I sent it to Bill but he didn't reply.

Cheers,

Jung-uk Kim

> Sincerely,
> Kel

--Boundary-00=_NOn3CW+BGOXcV6d
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="ndisgen.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="ndisgen.diff"

Index: usr.sbin/ndiscvt/ndisgen.sh
===================================================================
RCS file: /home/ncvs/src/usr.sbin/ndiscvt/ndisgen.sh,v
retrieving revision 1.1
diff -u -r1.1 ndisgen.sh
--- usr.sbin/ndiscvt/ndisgen.sh	24 Apr 2005 20:21:22 -0000	1.1
+++ usr.sbin/ndiscvt/ndisgen.sh	20 Jul 2005 15:49:53 -0000
@@ -57,6 +57,7 @@
 echo ""
 echo -n "	Enter your selection here and press return: "
 read KEYPRESS
+return
 }
 
 
@@ -78,8 +79,9 @@
 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 "	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 "	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 "	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 "	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 "	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 ""
 echo -n "	> "
 read INFPATH
-if [ $INFPATH ] && [ -e $INFPATH ]; 
-then 
-	INFTYPE=`${FILE} ${INFPATH}`
-
-	case ${INFTYPE} in
-	*ASCII*)
+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 "	This .INF file appears to be ASCII."
+		echo "	I don't recognize this file format. It may not be a valid .INF file."
 		echo ""
-		echo -n "	Press any key to continue... "
+		echo -n "	Press enter to try again, or ^C to quit. "
 		read KEYPRESS
-		;;
-	*text*)
+		INFPATH=""
+		return
+	fi
+
+	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
-		;;
-	*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 @@
 			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 ""
 echo -n "	> "
 read SYSPATH
-if [ $SYSPATH ] && [ -e $SYSPATH ];
-then
+if [ ${SYSPATH} ] && [ -e ${SYSPATH} ]; then
 	SYSTYPE=`${FILE} ${SYSPATH}`
 
 	case ${SYSTYPE} in
@@ -273,9 +280,9 @@
 		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 @@
 	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 @@
 	echo -n "	Press enter to continue... "
 	read KEYPRESS
 fi
+return
 }
 
 firmcvt() {
@@ -337,10 +346,10 @@
 		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 "	Conversion was successful."
 				echo ""
-				FRMBASE=`basename ${FIRMPATH}`
+				FRMBASE=`${BASENAME} ${FIRMPATH}`
 				FRMBASE="${FRMBASE}.o"
 				FRMLIST="${FRMLIST} ${FRMBASE}"
 			fi
@@ -368,13 +377,14 @@
 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,82 @@
 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 "NO_MAN="							>> ${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
+fi
+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	"	Linking static kernel module... "
-if ! ${LD} -r  -d -warn-common -o ${SYSBASE}.o windrv_stub.o ${FRMLIST} ${DNAME}.o; then
-	echo "linking failed. Exiting."
+echo -n "	Cleaning up... "
+if ! ${MAKE} -f ${MAKEFILE} clean cleandepend > /dev/null; then
+	echo "cleanup failed. Exiting."
 	echo ""
 	exit
 else
 	echo "done."
 fi
-echo -n "	Cleaning up... "
-${RM} -f bus_if.h device_if.h windrv_stub.o
-${RM} -f ${DNAME}.h ${DNAME}.o
-echo "done."
+${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 +483,27 @@
 	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 +542,4 @@
 		;;
 	esac
 done
+exit

--Boundary-00=_NOn3CW+BGOXcV6d--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200507201153.49441.jkim>