Author Topic: [howto] compile your own wireless  (Read 83143 times)

June 24, 2009, 12:47:47 PM
Read 83143 times


  • Newbie

  • Offline
  • *

  • 28
I want to compiled my own wireless module but there isn't a detailed how to in one place for newbie like me. After reading posts from many places I was be able to compiled a workable module . I took some notes and share it here in hope that it will help someone. In this how to I will compile the rt2870sta.ko for my dlink dwa-140. Thanks Zorander, smartP and all other developers.

You need a linux box or a vmware image

1) Setting up compiling environment
followed from this wiki

# create wdtv directory
wdtv@localhost ~ $ mkdir ~/wdtv && cd ~/wdtv

# download WD TV GPL Code
# unzip

wdtv@localhost ~/wdtv $ unzip

# extract GPL.tgz
wdtv@localhost ~/wdtv $ tar zxf GPL.tgz

# extract TVDOCK_GPL_code_package.2008.9.25.tar
wdtv@localhost ~/wdtv $ tar xf TVDOCK_GPL_code_package.2008.9.25.tar

# set compiling environment
wdtv@localhost ~/wdtv $ cd GPL/smp86xx_toolchain_2.8.2.0/
wdtv@localhost ~/wdtv/GPL/smp86xx_toolchain_2.8.2.0 $ pwd -P

# create a mips.env file
wdtv@localhost ~/wdtv/GPL/smp86xx_toolchain_2.8.2.0 $ nano -w mips.env
# with the content
export PATH


# then check
wdtv@localhost ~/wdtv/GPL/smp86xx_toolchain_2.8.2.0 $ cat mips.env
export PATH


wdtv@localhost ~/wdtv/GPL/smp86xx_toolchain_2.8.2.0 $ source mips.env
wdtv@localhost ~/wdtv/GPL/smp86xx_toolchain_2.8.2.0 $ echo -e $PATH"\n"$ARCH"\n"$CROSS_TOOL

2) compile kernel source

# extract kernel source
wdtv@localhost ~/wdtv/GPL/smp86xx_toolchain_2.8.2.0 $ cd ~/wdtv/TVDOCK_GPL_code_package.2008.9.25/
wdtv@localhost ~/wdtv/TVDOCK_GPL_code_package.2008.9.25 $ tar zxf linux_kernel_2.6.15.tar.gz
wdtv@localhost ~/wdtv/TVDOCK_GPL_code_package.2008.9.25 $ cd linux_kernel_2.6.15

# download Zorander's linux-kernel.config
wdtv@localhost ~/wdtv/TVDOCK_GPL_code_package.2008.9.25/linux_kernel_2.6.15 $ cp linux-kernel.config .config
wdtv@localhost ~/wdtv/TVDOCK_GPL_code_package.2008.9.25/linux_kernel_2.6.15 $ make oldconfig
wdtv@localhost ~/wdtv/TVDOCK_GPL_code_package.2008.9.25/linux_kernel_2.6.15 $ make

3) compile wireless module

# get ralink source
wdtv@localhost ~/wdtv/TVDOCK_GPL_code_package.2008.9.25/linux_kernel_2.6.15 $ cd ~/wdtv
wdtv@localhost ~/wdtv $ wget
wdtv@localhost ~/wdtv $ tar zxf 2009_0521_RT2870_Linux_STA_V2.1.2.0.tgz
wdtv@localhost ~/wdtv $ cd 2009_0521_RT2870_Linux_STA_V2.1.2.0

# edit Makefile . My diff:
wdtv@localhost ~/wdtv/2009_0521_RT2870_Linux_STA_V2.1.2.0 $ diff -uNbB Makefile.orig Makefile
--- Makefile.orig       2009-06-23 22:15:38.000000000 -0700
+++ Makefile    2009-06-23 22:20:58.000000000 -0700
@@ -8,9 +8,9 @@

 #PLATFORM: Target platform
@@ -29,8 +29,8 @@

-LINUX_SRC = /root/sigma/smp86xx_kernel_source_2.7.172.0/linux-2.6.15
-CROSS_COMPILE = /root/sigma/smp86xx_toolchain_2.7.172.0/build_mipsel_nofpu/staging_dir/bin/mipsel-linux-
+LINUX_SRC = /home/wdtv/wdtv/TVDOCK_GPL_code_package.2008.9.25/linux_kernel_2.6.15
+CROSS_COMPILE = /home/wdtv/wdtv/GPL/smp86xx_toolchain_2.8.2.0/bin/mipsel-linux-

 ifeq ($(PLATFORM),SIGMA_8622)
@@ -141,7 +141,7 @@
        cp -f os/linux/Makefile.6 $(RT28xx_DIR)/os/linux/Makefile
        make  -C  $(LINUX_SRC) SUBDIRS=$(RT28xx_DIR)/os/linux modules
-       cp -f $(RT28xx_DIR)/os/linux/rt$(CHIPSET)sta.ko /tftpboot
+       #cp -f $(RT28xx_DIR)/os/linux/rt$(CHIPSET)sta.ko /tftpboot


# edit os/linux/
wdtv@localhost ~/wdtv/2009_0521_RT2870_Linux_STA_V2.1.2.0 $ diff -uNbB os/linux/ os/linux/
--- os/linux/     2009-06-23 22:28:40.000000000 -0700
+++ os/linux/  2009-06-23 22:29:00.000000000 -0700
@@ -6,7 +6,7 @@

 # Support Wpa_Supplicant


# edit os/linux/Makefile.6 and include/os/rt_linux.h to load RT2870STA.dat from /etc/ instead of /etc/Wireless/RT2870STA/
wdtv@localhost ~/wdtv/2009_0521_RT2870_Linux_STA_V2.1.2.0 $ diff -uNbB os/linux/Makefile.6.orig os/linux/Makefile.6
--- os/linux/Makefile.6.orig    2009-06-23 22:32:10.000000000 -0700
+++ os/linux/Makefile.6 2009-06-23 22:32:31.000000000 -0700
@@ -1,7 +1,7 @@
 include $(RT28xx_DIR)/os/linux/

-DAT_PATH = /etc/Wireless/RT$(CHIPSET)STA

 obj-m := $(MOD_NAME).o

wdtv@localhost ~/wdtv/2009_0521_RT2870_Linux_STA_V2.1.2.0 $ diff -uNbB include/os/rt_linux.h.orig include/os/rt_linux.h
--- include/os/rt_linux.h.orig  2009-06-23 22:36:56.000000000 -0700
+++ include/os/rt_linux.h       2009-06-23 22:37:46.000000000 -0700
@@ -101,10 +101,10 @@

 #ifdef RTMP_MAC_USB
-#define STA_PROFILE_PATH                       "/etc/Wireless/RT2870STA/RT2870STA.dat"
+#define STA_PROFILE_PATH                       "/etc/RT2870STA.dat"
 #define STA_DRIVER_VERSION                     ""
-#define CARD_INFO_PATH                 "/etc/Wireless/RT2870STA/RT2870STACard.dat"
+#define CARD_INFO_PATH                 "/etc/RT2870STACard.dat"
 #endif // RTMP_MAC_USB //

4) Create app.bin

# move back to wdtv work directory .
wdtv@localhost ~/wdtv/2009_0521_RT2870_Linux_STA_V2.1.2.0 $ cd ~/wdtv

# download smartP's
wdtv@localhost ~/wdtv $ unzip

# create a mount point for the app.bin
wdtv@localhost ~/wdtv $ sudo mkdir -p /mnt/
wdtv@localhost ~/wdtv $ sudo mount -o loop /mnt/
wdtv@localhost ~/wdtv $ ls /mnt/
bin  etc  firmware  lib  modules

# create a directory for your new app.bin and copy SmartP's app.bin over.
wdtv@localhost ~/wdtv $ mkdir wireless-mod-rt2870
wdtv@localhost ~/wdtv $ cp -r /mnt/* wireless-mod-rt2870/

# rt2870 does not need firmware . We can delete them .
wdtv@localhost ~/wdtv $ rm -rf wireless-mod-rt2870/firmware/

# remove other modules we don't need .
wdtv@localhost ~/wdtv $ rm wireless-mod-rt2870/modules/rt*.ko

# and we are left with:
wdtv@localhost ~/wdtv $ ls -R wireless-mod-rt2870/*

hotplug  init.d  mdev.conf





# copy our compiled module over
wdtv@localhost ~/wdtv $ cp ~/wdtv/2009_0521_RT2870_Linux_STA_V2.1.2.0/os/linux/rt2870sta.ko wireless-mod-rt2870/modules/

# check our app.bin size
wdtv@localhost ~/wdtv $ du -sh wireless-mod-rt2870
961K    wireless-mod-rt2870

# create an app.bin file; make filesystem; mount
wdtv@localhost ~/wdtv $ dd if=/dev/zero bs=1024 count=1k
1024+0 records in
1024+0 records out
1048576 bytes (1.0 MB) copied, 0.0155911 s, 67.3 MB/s

wdtv@localhost ~/wdtv $ /sbin/mkfs.ext2
mke2fs 1.41.3 (12-Oct-2008) is not a block special device.
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
128 inodes, 1024 blocks
51 blocks (4.98%) reserved for the super user
First data block=1
Maximum filesystem blocks=1048576
1 block group
8192 blocks per group, 8192 fragments per group
128 inodes per group

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

wdtv@localhost ~/wdtv $ sudo mkdir -p /mnt/
wdtv@localhost ~/wdtv $ sudo mount -o loop /mnt/

# remove lost+found
wdtv@localhost ~/wdtv $ sudo rm -rf /mnt/

# copy content of wireless-mod-rt2870 over.
wdtv@localhost ~/wdtv $ cp -r wireless-mod-rt2870/* /mnt/

# if you get the error No space left on device then you need to create a bigger app.bin file (eg dd if=/dev/zero bs=1024 count=2k)

# umount
wdtv@localhost ~/wdtv $ sudo umount /mnt/

# mount the new app.bin again to check
wdtv@localhost ~/wdtv $ sudo mount -o loop /mnt/
wdtv@localhost ~/wdtv $ ls -R /mnt/*

hotplug  init.d  mdev.conf




rt2870sta.ko  wireless-ext.ko

# unmount the new app.bin
wdtv@localhost ~/wdtv $ sudo umount /mnt/

# your is ready .
« Last Edit: June 26, 2009, 02:22:43 PM by hnadov2k9 »

June 26, 2009, 01:54:30 PM
Reply #1


  • Global Moderator
  • Sr. Member

  • Offline
  • *****

  • 411
this is nice and simple how-to
good job man

June 30, 2009, 09:51:16 AM
Reply #2


  • Newbie

  • Offline
  • *

  • 9
what about rt73 devices?

June 30, 2009, 10:34:48 AM
Reply #3


  • Newbie

  • Offline
  • *

  • 28
what about rt73 devices?

1) get driver source for rt73
2) edit Module/Makefile and Module/rt_config.h to match the diff below.
wdtv@localhost ~/wdtv/2009_0206_RT73_Linux_STA_Drv1.1.0.2/Module $ diff -uNbB Makefile
---        2008-12-18 07:01:34.000000000 -0800
+++ Makefile    2009-06-30 11:23:59.000000000 -0700
@@ -2,7 +2,8 @@
 #      Module Name: Makefile
 #      Abstract: Makefile for rt73 linux driver on kernel series 2.6

 #Enable for wpa_supplicant's spcific driver "driver_ralink.c", default enabled.
@@ -40,6 +41,9 @@
 ifeq ($(PLATFORM),CMPC)
 LINUX_SRC = /home/fonchi/vendor/kernel-default-2.6.21/linux-2.6.21
+ifeq ($(PLATFORM),WDTV)
+LINUX_SRC = /home/wdtv/wdtv/TVDOCK_GPL_code_package.2008.9.25/linux_kernel_2.6.15


wdtv@localhost ~/wdtv/2009_0206_RT73_Linux_STA_Drv1.1.0.2/Module $ diff -uNbB rt_config.h.orig rt_config.h
--- rt_config.h.orig    2009-06-30 11:20:30.000000000 -0700
+++ rt_config.h 2009-06-30 11:24:27.000000000 -0700
@@ -38,9 +38,9 @@
 #ifndef        __RT_CONFIG_H__
 #define        __RT_CONFIG_H__

-#define PROFILE_PATH                "/etc/Wireless/RT73STA/rt73sta.dat"
+#define PROFILE_PATH                "/etc/rt73sta.dat"
 #define NIC_DEVICE_NAME             "RT73STA"
-#define RT2573_IMAGE_FILE_NAME      "/etc/Wireless/RT73STA/rt73.bin"
+#define RT2573_IMAGE_FILE_NAME      "/etc/rt73.bin"
 #define RALINK_PASSPHRASE           "Ralink"
 #define DRIVER_VERSION                         ""

3) At step 4 , create the app.bin , DO NOT delete the "firmware" directory but copy rt73.bin over and overwrite the old one to be sure. the module name for rt73 is rt73.ko .

June 30, 2009, 12:36:39 PM
Reply #4


  • Newbie

  • Offline
  • *

  • 9
awesome, thanks for the fast response. ill try this tomorrow

July 07, 2009, 02:30:52 AM
Reply #5


  • Newbie

  • Offline
  • *

  • 1
couple of questions if I can..

first off I'm a real noob to most things Linux but learning from my mistakes..  (many of them to come I imagine) ..

I thought I'd try this to see if I could at least get all the way through without any dramas..  but I've run into what I think is a problem

here # download Zorander's linux-kernel.config
wdtv@localhost ~/wdtv/TVDOCK_GPL_code_package.2008.9.25/linux_kernel_2.6.15 $ cp linux-kernel.config .config
wdtv@localhost ~/wdtv/TVDOCK_GPL_code_package.2008.9.25/linux_kernel_2.6.15 $ make oldconfig
wdtv@localhost ~/wdtv/TVDOCK_GPL_code_package.2008.9.25/linux_kernel_2.6.15 $ make

after make I get the following which I assume is an error..

/bin/sh: mipsel-linux-gcc: not found
make: mipsel-linux-gcc: Command not found
  CHK     include/linux/version.h
  CC      arch/mips/kernel/asm-offsets.s
/bin/sh: mipsel-linux-gcc: not found
make[1]: *** [arch/mips/kernel/asm-offsets.s] Error 127
make: *** [prepare0] Error 2

any ideas on where I'm going wrong and once I get past this stage any tips on trying to compile for the RTL8187b chipset


July 07, 2009, 06:11:16 AM
Reply #6


  • Newbie

  • Offline
  • *

  • 28
make sure you source the envirement file mips.env and $PATH is point to the correct place PATH=/home/wdtv/wdtv/GPL/smp86xx_toolchain_2.8.2.0/bin:$PATH in my setup)
read the ReadMe file that comes with the driver source for more instruction. And I don't think SmartP's script will work with that chipset . You might want to try to add this module to Zorander or wireless app.bin package.

July 10, 2009, 11:53:39 AM
Reply #7


  • Newbie

  • Offline
  • *

  • 9
thx for the help, everything compiled right but still same known issue with my dlink dwl-g122 with rt73 :-(

July 13, 2009, 01:05:49 PM
Reply #8


  • Jr. Member

  • Offline
  • **

  • 58
Can someone please help me out?

I'm stuck at the "diff -uNbB ....." thing because my drivers are different, too!

Here's the download:

RTL8191SU chipset.

Help please!  :)

July 14, 2009, 10:08:25 AM
Reply #9


  • Newbie

  • Offline
  • *

  • 28
you have to follow the instructions in the readme file to compile this driver. my example is only applied to the driver source for the rt73 chipset .

July 14, 2009, 01:24:39 PM
Reply #10


  • Newbie

  • Offline
  • *

  • 28
these are steps to compile rtl8192su module.
extract driver source. assumed kernel source is located at  "/home/wdtv/wdtv/TVDOCK_GPL_code_package.2008.9.25/linux_kernel_2.6.15" (in my example)
Code: [Select]
sed -i "s|KSRC =.*|KSRC = /home/wdtv/wdtv/TVDOCK_GPL_code_package.2008.9.25/linux_kernel_2.6.15|g;" rtl8192su_linux_2.6.0002.0708.2009/Makefile
sed -i "s|CC =.*|CC = mipsel-linux-gcc|g;" rtl8192su_linux_2.6.0002.0708.2009/HAL/rtl8192u/Makefile
cd rtl8192su_linux_2.6.0002.0708.2009 && make
get Zorander's wireless app.bin; mount it; copy content over to your app.bin directory; modify S20wireless; copy firmware; create cramfs app.bin; umount
Code: [Select]
sudo mount sudo mount -o loop /path/to/mount/point
cp -r /path/to/mount/point/*
echo "insmod \$APATH/modules/r8192s_usb.ko" >>
cp firmware/RTL8192SU/rtl8192sfw.bin
sudo umount /path/to/mount/point/

July 18, 2009, 02:47:02 AM
Reply #11


  • Full Member

  • Offline
  • ***

  • 100
Thanks for the guide,

I have a suggestion. I have downloaded the wdtvtools ready to compile VMware image (I am using it with VirtualBox on windows and it works perfect). (Thanks elmar_weber) :)
This is a debian linux box, ready to compile for the wdtv, so this avoids starting from scratch, and it should be much easier to use for people without a linux box or without a lot of linux knowledge (like me).

I know it's much to ask, but would it be possible to review this guide defining which steps are not necessary with the wdtvtools image, and which ones would need to be modified to work on that?

I think it would be ideal to have the same system for everyone to develop, as it would be much easier to write (and follow) guides and howtos. Also, as the wdtvtools is a sourceforge oss project, anybody can contribute with modifications or improvements if he feels they are needed.

July 21, 2009, 10:49:55 AM
Reply #12


  • Full Member

  • Offline
  • ***

  • 100
Hello again,

I'm trying to obtain the latest drivers I am able for the ralink rt73. As the new drivers from rt2x00 project are for newer kernels, I'm trying to compile the final version of legacy rt73 module from rt2x00 project (it is no longer developed)
I think this is a more updated version than the one from ralink. It seems that it doesn't rely on .dat file for configuration (deprecated), and uses standard tools like iwconfig/iwpriv instead. It can be used a patched wpasupplicant too.

Unfortunately, this is the first module I'm trying to compile, and I need some help.

When I decompress and untar, I find in the README file, the following build instructions:
Build Instructions

    1. Unpack the driver sources and go to the Module directory:
          $ tar -xvzf rt73-cvs-daily.tar.gz
          $ cd ./rt73-cvs-YYYYMMDDHH/Module

    2. Compile the driver sources:
          $ make

    3. Install the driver (as root):
          # make install
Obviously, I suppose that there is something I must do prior to make (Modifying the Module/Makefile and Module/rt_config.h)
The problem is that they seem to be different than the ones in your diff, and I'm not sure if it would work.

Let me ask you a newbie question here. How can I use a diff? From what I have googled, I must use 'patch', but how? Should I have two text files (The original one and the diff) and when I patch I overwrite the original one?

July 22, 2009, 10:07:06 AM
Reply #13


  • Newbie

  • Offline
  • *

  • 28
Let me ask you a newbie question here. How can I use a diff? From what I have googled, I must use 'patch', but how? Should I have two text files (The original one and the diff) and when I patch I overwrite the original one?

the diff in my example is just to give you an idea what have been changed when I ran `diff -ubB original_file modifed_file`

July 22, 2009, 11:27:50 PM
Reply #14


  • Jr. Member

  • Offline
  • **

  • 87
Let me ask you a newbie question here. How can I use a diff? From what I have googled, I must use 'patch', but how? Should I have two text files (The original one and the diff) and when I patch I overwrite the original one?

I have already tried to build this driver. I do not remember any significant changes to the sources to be required. Update the makefie to set your paths to kernel sources and then just try running make right away and look at the output. I was not able to find the location it loads the firmware from. I tried both /etc/firmware and /lib/firmware. Probably you should place the firmware together with the driver.

Please leave a message if you succeed and obtain a stable working driver. By 'stable' I mean work under heavy load for more than a day at least.