WDTV 1 Forum Groups > Homebrew / Custom Firmware

[howto] compile your own wireless

(1/11) > >>

hnadov2k9:
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_GPL_Code.zip
wdtv@localhost ~/wdtv $ unzip WDTV_GPL_Code.zip

# 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
/home/wdtv/wdtv/GPL/smp86xx_toolchain_2.8.2.0

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

ARCH=mips
CROSS_TOOL=mipsel-linux-
export ARCH CROSS_TOOL
# then check
wdtv@localhost ~/wdtv/GPL/smp86xx_toolchain_2.8.2.0 $ cat mips.env
PATH=/home/wdtv/wdtv/GPL/smp86xx_toolchain_2.8.2.0/bin:$PATH
export PATH

ARCH=mips
CROSS_TOOL=mipsel-linux-
export ARCH CROSS_TOOL
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
/home/wdtv/wdtv/GPL/smp86xx_toolchain_2.8.2.0/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.3.2:/usr/kde/3.5/bin:/usr/games/bin
mips
mipsel-linux-

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 http://www.ralinktech.com.tw/data/drivers/2009_0521_RT2870_Linux_STA_V2.1.2.0.tgz
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 @@
 RTMP_SRC_DIR = $(RT28xx_DIR)/RT$(CHIPSET)

 #PLATFORM: Target platform
-PLATFORM = PC
+#PLATFORM = PC
 #PLATFORM = 5VT
-#PLATFORM = SIGMA
+PLATFORM = SIGMA
 #PLATFORM = SIGMA_8622
 #PLATFORM = INIC
 #PLATFORM = STAR
@@ -29,8 +29,8 @@
 endif

 ifeq ($(PLATFORM),SIGMA)
-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-
 endif

 ifeq ($(PLATFORM),SIGMA_8622)
@@ -141,7 +141,7 @@
 else
        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
 endif

 clean:

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

 #ifdef WPA_SUPPLICANT_SUPPORT
 # Support Wpa_Supplicant
-HAS_WPA_SUPPLICANT=n
+HAS_WPA_SUPPLICANT=y
 #endif // WPA_SUPPLICANT_SUPPORT //

 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT

# 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/config.mk

 MOD_NAME = rt$(CHIPSET)sta
-DAT_PATH = /etc/Wireless/RT$(CHIPSET)STA
+DAT_PATH = /etc/RT$(CHIPSET)STA
 DAT_FILE_NAME = RT$(CHIPSET)STA.dat

 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 CONFIG_STA_SUPPORT

 #ifdef RTMP_MAC_USB
-#define STA_PROFILE_PATH                       "/etc/Wireless/RT2870STA/RT2870STA.dat"
+#define STA_PROFILE_PATH                       "/etc/RT2870STA.dat"
 #define STA_DRIVER_VERSION                     "2.1.2.0"
 #ifdef MULTIPLE_CARD_SUPPORT
-#define CARD_INFO_PATH                 "/etc/Wireless/RT2870STA/RT2870STACard.dat"
+#define CARD_INFO_PATH                 "/etc/RT2870STACard.dat"
 #endif // MULTIPLE_CARD_SUPPORT //
 #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 wireless-mod-rt.app.bin
wdtv@localhost ~/wdtv $ unzip wireless-mod-rt.app.bin-1.1.zip

# create a mount point for the app.bin
wdtv@localhost ~/wdtv $ sudo mkdir -p /mnt/orig.app.bin
wdtv@localhost ~/wdtv $ sudo mount -o loop wireless-mod-rt.app.bin /mnt/orig.app.bin
wdtv@localhost ~/wdtv $ ls /mnt/orig.app.bin/
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/orig.app.bin/* 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/*
bin:
iwconfig

wireless-mod-rt2870/etc:
hotplug  init.d  mdev.conf

wireless-mod-rt2870/etc/hotplug:
wlan-rt.agent

wireless-mod-rt2870/etc/init.d:
S20wlanmodules

wireless-mod-rt2870/lib:
libiw.so.28

wireless-mod-rt2870/modules:
wireless-ext.ko

# 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 of=wireless-mod-rt2870.app.bin 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 wireless-mod-rt2870.app.bin
mke2fs 1.41.3 (12-Oct-2008)
wireless-mod-rt2870.app.bin 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/new.app.bin
wdtv@localhost ~/wdtv $ sudo mount -o loop wireless-mod-rt2870.app.bin /mnt/new.app.bin/

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

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

# 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 of=wireless-mod-rt2870.app.bin bs=1024 count=2k)

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

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

/mnt/new.app.bin/etc:
hotplug  init.d  mdev.conf

/mnt/new.app.bin/etc/hotplug:
wlan-rt.agent

/mnt/new.app.bin/etc/init.d:
S20wlanmodules

/mnt/new.app.bin/lib:
libiw.so.28

/mnt/new.app.bin/modules:
rt2870sta.ko  wireless-ext.ko

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

# your wireless-mod-rt2870.app.bin is ready .

3dxr:
this is nice and simple how-to
good job man

nabster:
what about rt73 devices?

hnadov2k9:

--- Quote from: nabster on June 30, 2009, 09:51:16 AM ---what about rt73 devices?

--- End quote ---

1) get driver source for rt73 http://www.ralinktech.com.tw/data/drivers/2009_0206_RT73_Linux_STA_Drv1.1.0.2.tar.bz2
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.org Makefile
--- Makefile.org        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
 ######################################################################
-PLATFORM=PC
+PLATFORM=WDTV
+#PLATFORM=PC
 #PLATFORM=CMPC

 #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
 endif
+ifeq ($(PLATFORM),WDTV)
+LINUX_SRC = /home/wdtv/wdtv/TVDOCK_GPL_code_package.2008.9.25/linux_kernel_2.6.15
+endif

 EXTRA_CFLAGS += -I$(LINUX_SRC)/include

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                         "1.1.0.0"


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 .

nabster:
awesome, thanks for the fast response. ill try this tomorrow

Navigation

[0] Message Index

[#] Next page

Go to full version