domingo, 28 de novembro de 2010

Optware on TP-Link WR1043ND

UPDATE - 2011 04 23 - Acabei por utilizar o OpenWrt em vez do DD-WRT com Optaware. O opkg já vem nativo e o sistema de overlay é muito mais  interessante. A unica vantagem do DD-WRT é a interface gráfica, mas quem se importa....







Pessoal, desculpem-me por este post apenas em Inglês. Devo mandar essa informação para o pessoal do dd-wrt colocar em um Wiki ou algo assim, dai não preciso reescrever.  Se tiverem dúvidas é só comentar que eu esclareço.

I apologize for the Portuguese readers of my blog for posting this in English. I plan to send it to dd-wrt guys, so I don't need to rewrite it. If you have any doubt, please post a comment that I'll be glad to explain.

I just bought a new Wireless router from TP-Link model TP-WR1043ND. It has  4 Gigabit ports, Wireless N which gives up to 300Mpbs an USB port, which open up for a lot of interesting things like using it as a NAS. After installing DD-WRT on it I wanted to use Optware ( a collection of softwares to be installed on /opt that is mounted on a flash drive).

I found that the usual instructions didn't work, because this model has an Atheros (ar71xx) processor and the scripts around are Broadcom oriented. After a lot of research I came up with these instructions. Hope it would be useful for someone. Please, let me know if you use it. Leave a comment. I assume the reader has already installed Optware on a Broadcom device using these instructions: http://www.dd-wrt.com/wiki/index.php/Optware,_the_Right_Way. If not, take a look at it first. There are the basic steps like formatting the USB storage and enabling USB storage in web configuration.

In a pinch, what Optware does is  extend the softwares available on dd-wrt ( and other linux based firmwares too, for instance). You can have, for example, vim, squid, mc, and the coreutils and bash replacing busybox. As the root file system of wireless devices are read-only and very tight in size,  it has to be installed  on a USB drive, MMC card ( check for MMC mod on dd-wrt site) or even the JFFS ( the remaining space of the router's flash mounted on /jffs), even though it offers only a few hundreds of KB. Optware has a utility called opkg, that is very similar to apt-get from Debian and Ubuntu. It can download and install softwares from a repository. What we'll do is to make opkg work and configure some applications to work with /opt instead of usual /.

I assume from now on that you have an ext3 file system of a flash drive mounted on /opt. You have to auto mount it at boot. There's a lot of ways to do it, like using "Commands" from Web configuration page or creating a script like /jffs/etc/config/automount.startup. Check http://www.dd-wrt.com/wiki/index.php/Script_Execution if in doubt.

At first, I tried to install opkg from OpenWRT Backfire packages (http://downloads.openwrt.org/backfire/10.03/ar71xx/packages/) using the native ipkg.

cd /tmp
wget http://downloads.openwrt.org/backfire/10.03/ar71xx/packages/opkg_513-2_ar71xx.ipk
ipkg -d /opt opkg_513-2_ar71xx.ipk

Then I changed the  /opt/etc/opkg.conf to suit the new root:

src/gz packages http://downloads.openwrt.org/backfire/10.03/ar71xx/packages
dest root /opt
dest ram /tmp
lists_dir ext /opt/var/opkg-lists
option overlay_root /overlay


I tried to run, but it didn't work:

cd /opt/bin
./opkg -f /opt/etc/opkg.conf  update
./opkg: can't resolve symbol 'glob64' in lib './opkg'.

Note that I had to use -f to point to the right path of config file. It defaults to /etc/opkg.conf which doesn't exists.


This is because opkg needs some libs not present in dd-wrt. In this post http://www.dd-wrt.com/phpBB2/viewtopic.php?t=67678 Luyi suggests to compile Openwrt yourself and copy the libs to /opt/lib or use the ones he compiled. This is not necessary, because these libs are available on the backfire packages above, you just need to know  which ones and install with ipkg after downloading them.

Then, I installed the libgcc and libc, that are the minimum for opkg to work.


cd  /tmp
wget http://downloads.openwrt.org/backfire/10.03/ar71xx/packages/libgcc_4.3.3+cs-42_ar71xx.ipk
wget http://downloads.openwrt.org/backfire/10.03/ar71xx/packages/libc_0.9.30.1-42_ar71xx.ipk
ipkg  -d /opt/ install libgcc_4.3.3+cs-42_ar71xx.ipk

ipkg  -d /opt/ install libc_0.9.30.1-42_ar71xx.ipk

In order to use these libs you must change the environment variable LD_LIBRARY_PATH . It's already set to /opt/lib by dd-wrt, but you must put it first, so it has priority over /lib or /usr/lib.



export LD_LIBRARY_PATH=/opt/lib:/opt/usr/lib:$LD_LIBRARY_PATH


After this, the opkg works!

opkg -f /opt/etc/opkg.conf update
opkg -f /opt/etc/opkg.conf list

With the last command you can see a list of available packages. Note that if you logoff, you must export the LD_LIBRARY_PATH again. Let' correct it soon, keep reading.
From now on, you can install whatever you want, like vim, for example:


opkg -f /opt/etc/opkg.conf install vim-full

opkg -f /opt/etc/opkg.conf install vim-runtime



One interessating thing is that it automatically download the dependecies, like libncurses.
My recommended packages for initial setup:


coreutils-ls
coreutils-cp
coreutils-rm
coreutils-rmdir
coreutils-mv
procps
file
vim-full
vim-runtime
mc


Problems and solutions


From now on you have opkg working. You can skip these steps or adptapt for your own needs.


If you try vim you'll see that it has no colors and fancy stuff.  This is necessary to tell vim it uses /opt/usr instead of regular /usr. To do this, you can export the VIMRUNTIME env var.
export VIMRUNTIME=/opt/usr/share/vim/vim71


Also, ncurses needs information about terminal. It search by default on /usr/share/terminfo/ by should look at /opt/usr/share/terminfo/
export TERMINFO=/opt/usr/share/terminfo


To solve this at every boot, I created a startup script called /jffs/etc/config/profile.sh that it'll place some entries in the user .profile at boot ( note that you'll loose .profile if you edit it directly because it is rewritten at boot).
This will solve for other problems too. The PATH of /opt/bin and /opt/usr/bin  is set with higher priority over /bin and /usr/bin. That way, if you install an optware package with a command with the same name of the built in, it will be run instead of the default.


We also set some alias to avoid extra typing, like -f of opkg. The file command ( from file package) was corrected to point to magic file.


One important note.
If you install a package and it don't work complaining missing files or paths, you must find a way to point to the right place. My experience tells that environment variables, config files or some alias with a right argument will do the job in 99% of the cases.


#!/bin/sh

if [ -d /opt/bin ]; then

cat <
<EOF >> /tmp/root/.profile

alias opkg='/opt/bin/opkg -f /opt/etc/opkg.conf'
alias ls='ls --color'
alias file='file -m /opt/usr/share/file/magic'
alias df='df -h'

export LD_LIBRARY_PATH=/opt/lib:/opt/usr/lib:$LD_LIBRARY_PATH
export VIMRUNTIME=/opt/usr/share/vim/vim71
export TERMINFO=/opt/usr/share/terminfo
export PATH=/opt/bin:/opt/usr/bin/:$PATH
EOF

fi
 


To make  vim to work nicelly, I use the script /opt/etc/config/vim.startup


#!/bin/sh
VIMRC=/tmp/root/.vimrc
echo "set nocompatible" > $VIMRC
echo "set backspace=indent,eol,start" >> $VIMRC
echo "syntax on" >> $VIMRC


To make opkg to work is not difficult and and even a non skilled linux user can do if it has basic knowledge. I found this method more interesting than using scripts from http://www.dd-wrt.com/wiki/index.php/Optware,_the_Right_Way. It has less features, but I keep control of what I want. if you need what's posted there, just follow the instructions starting from somewhere ahead. You may need to install some packages manually, just figure it out which.

You have doubts I'm pleased to help, just post a comment.
Good luck!

Um comentário:

  1. Amigo, por acaso você não tentou instalar o Pyload ou outro gerenciador de download em um roteador Atheros? Eu tenho tentado sem sucesso fazê-lo funcionar =( .. consegui o Transmission com a sua ajuda (após fazer o optware funcionar). Agora só falta o Pyload para tudo ficar perfeito.

    Agradeceria muito se pudesse ajudar.
    Obrigado =D

    ResponderExcluir

Nota Importante

O conteúdo deste blog foi desenvolvido por mim e não foi copiado de outros locais, embora alguns poucos tópicos tenham sínteses e adaptações de outras fontes, que neste caso, serão referenciadas para se dar o devido crédito.
A reprodução é permitida desde que citada a fonte e para fins não comerciais. É proibido o uso para fins comercias sem a expressa autorização do autor.
Embora o conteúdo aqui apresentado seja testado pelo autor e/ou passado por sua aprovação, não é oferecida nenhuma garantia de que tudo funcionará corretamente ou não irá danificar os sistemas envolvidos, pois o sucesso dependerá do ambiente e/ou conhecimento do leitor.
Ao utilizar este blog, para qualquer fim, o leitor concorda com estes termos e isenta o autor de qualquer responsabilidade, ficando o uso do conhecimento aqui apresentado por sua conta e risco.
Caso discorde destes termos, gentileza fechar esta página imediatamente.

Copyright Jonathan Araújo 2010