вторник, 11 февраля 2014 г.

U-boot mod for tp-link mobile routers

I have 3 different TP-Link mobile routers. I always wanted to dig into boot-loader, replace factory one with custom boot-loader from developer pepe2k. Github link

What's so special about this boot-loader? It has very nice killer-features like:
  • Embedded micro-http server. It allows firmware upload via browser for system image, boot-loader and radio calibration data named ART
  • UDP network console, allows you access boot-loader's command-line without uart-cable
  • Overclocking
  • Other handy stuff
Nice features, but developer does not offers fresh binary versions of boot-loader. Sad story. But i managed to compile these by myself. All you need to have is some mips-toolchain installed and then compile your own binaries.
I created 32-bit openvz-container(but debootstrap/chroot combination will be ok too) with debian wheezy. After googling for some time i found script for auto install toolchain.
#!/bin/sh
 
#
# Script name: setup_codesourcery.sh
# Version: 2.2 - 2012-07-19
#
# Copyright (C) 2009-2012 Matthias "Maddes" Buecher
#
 
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/gpl-2.0.txt
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
 
 
##
## Script Functions
##
install_toolchain ()
{
BINPATH="${INSTALLPATH}/${VERSION}/bin"
SCRIPTFILE="${SCRIPTPATH}/${SCRIPTPREFIX}${VERSION}.sh"
DLFILE="${VERSION}${SUBVERSION}-${CCPREFIX}-i686-pc-linux-gnu.tar.bz2"
 
echo "Installing ${VERSION}:"
 
# # Download toolchain
[ ! -d "${DLDIR}" ] && mkdir -p "${DLDIR}"
wget -N -P "${DLDIR}" "${DLBASEPATH}/${CCPREFIX}/${DLFILE}"
 
# # Install toolchain (by extracting)
echo 'Extracting...'
[ ! -d "${INSTALLPATH}" ] && mkdir -p "${INSTALLPATH}"
tar -x --bzip2 -f "${DLDIR}"/"${DLFILE}" -C "${INSTALLPATH}"
 
# # Create toolchain environment script
echo "Creating script file ${SCRIPTFILE} ..."
cat >"${SCRIPTFILE}" << __EOF
#!/bin/sh
echo "Type 'exit' to return to non-crosscompile environment"
[ -n "\${CROSS_COMPILE}" ] && { echo "ALREADY in crosscompile environment for \${ARCH} (\${CROSS_COMPILE})"; exit; }
export PATH='${BINPATH}':\${PATH}
export ARCH='${ARCHCODE}'
export CROSS_COMPILE='${CCPREFIX}-'
echo "NOW in crosscompile environment for \${ARCH} (\${CROSS_COMPILE})"
/bin/bash
echo 'Back in non-crosscompile environment'
__EOF
[ ! -x "${SCRIPTFILE}" ] && chmod +x "${SCRIPTFILE}"
 
echo 'Done.'
}
 
 
###
### Install prerequisites
###
 
[ "`whoami`" != "root" ] && {
echo "$0: ABORT!!! Only for root user"
exit 1
}
 
# --> general buildtools & development packages
# wget & bzip2 for downloading and unpacking
# uboot's mkimage & devio for creating uImage
echo 'Installing prerequisites:'
PACKAGES='build-essential linux-libc-dev wget bzip2 uboot-mkimage devio ncurses-dev'
DOINSTALL=0
for PACKAGE in ${PACKAGES}
do
# # special cases
[ "${PACKAGE}" = "ncurses-dev" ] && PACKAGE="libncurses5-dev" ; # package ncurses-dev is virtual on Debian, which can not be found via dpkg
 
dpkg -l | grep -q -F -e "${PACKAGE}"
DOINSTALL=$?
[ "${DOINSTALL}" -ne 0 ] && break
done
[ "${DOINSTALL}" -ne 0 ] && {
apt-get update
apt-get install ${PACKAGES}
}
 
 
###
### Install toolchains
###
 
 
### Mentor Graphics' (ex-CodeSourcery) toolchains
### http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/lite-edition
### (navigation 2012: Products and/or Embedded Software --> Sourcery CodeBench [--> Lean more] [--> Editions] --> Sourcery CodeBench Lite Edition (at the bottom))
### (navigation 2011: Products --> Embedded Software --> Sourcery Tools --> Sourcery CodeBench --> Editions --> Lite Edition Download)
#
### before 2011:
### http://www.codesourcery.com/sgpp/lite_edition.html
### (navigation: Products --> Sourcery G++ --> Editions --> Lite)
#
### Note: the toolchains for the different targets can be installed in parallel
 
## Pathes for toolchains, scripts and downloads
INSTALLPATH='/usr/local/codesourcery'
SCRIPTPATH='/usr/local/bin'
SCRIPTPREFIX='codesourcery-'
DLDIR="/root/work/codesourcery"
#
DLBASEPATH='https://sourcery.mentor.com/public/gnu_toolchain/'
# before 2011: DLBASEPATH='http://www.codesourcery.com/public/gnu_toolchain/'
 
## -> ARM GNU/Linux target
ARCHCODE='arm'
CCPREFIX='arm-none-linux-gnueabi'
## (arm-2011.03-41)
VERSION='arm-2011.03'
SUBVERSION='-41'
install_toolchain
## (arm-2009q3-67)
VERSION='arm-2009q3'
SUBVERSION='-67'
#install_toolchain
## (arm-2009q1-203)
VERSION='arm-2009q1'
SUBVERSION='-203'
#install_toolchain
 
## -> MIPS GNU/Linux target
ARCHCODE='mips'
CCPREFIX='mips-linux-gnu'
## (mips-2011.03-93)
VERSION='mips-2011.03'
SUBVERSION='-93'
install_toolchain
## (mips-4.4-303)
VERSION='mips-4.4'
SUBVERSION='-303'
#install_toolchain
## (mips-4.3-154)
VERSION='mips-4.3'
SUBVERSION='-154'
#install_toolchain

Paste contents from listing above:
# $EDITOR ~/setup_codesourcery.sh
Make script executable:
# chmod +x ~/setup_codesourcery.sh
Execute script, it will install all dependencies automatically. Install additional dependencies for boot-loader compilation - default-jre-headless и git.
# apt-get install default-jre-headless git
Everything is ready, it's compile time! Let's compile loader for 703 model.
# git clone https://github.com/pepe2k/u-boot_mod.git
# cd u-boot_mod
# codesourcery-mips-2011.03.sh
# make tplink_wr703n
If everything's is okay you'll see something like this on your console:
Image Name:   u-boot image
Created:      Tue Feb 11 20:49:16 2014
Image Type:   MIPS Linux Firmware (lzma compressed)
Data Size:    43654 Bytes = 42.63 kB = 0.04 MB
Load Address: 0x80010000
Entry Point:  0x80010000
make[1]: Entering directory `/root/u-boot_mod'
-e
======= Preparing 64KB file filled with 0xFF... =======
64+0 records in
128+0 records out
65536 bytes (66 kB) copied, 0.000749393 s, 87.5 MB/s
-e
======= Copying U-Boot image... =======
114+1 records in
114+1 records out
58458 bytes (58 kB) copied, 0.000249334 s, 234 MB/s
-e
======= U-Boot image ready, size: 65536 bytes =======

make[1]: Leaving directory `/root/u-boot_mod'
Resulted files will be in "bin" directory:
# ls -1 bin/
README
uboot_for_tp-link_tl-mr3020.bin
uboot_for_tp-link_tl-mr3020.md5
uboot_for_tp-link_tl-wr703n.bin
uboot_for_tp-link_tl-wr703n.md5
uboot_for_tp-link_tl-wr720n_v3_CH.bin
uboot_for_tp-link_tl-wr720n_v3_CH.md5
Your freshly compiled boot-loader can be flashed with usb2uart cable using author's instructions
I will left here compiled files, if someone is too lazy to compile them by themselves. Check-sums:
87af702f1b4e241af74ade3b2d5964b0 uboot_for_tp-link_tl-mr3020.bin
cfba9d0299c2cfddcfd21d6b1292617a uboot_for_tp-link_tl-wr703n.bin
b7285673db0d0fa0320e81e37395f0b4 uboot_for_tp-link_tl-wr720n_v3_CH.bin
uboot_for_tp-link_tl-mr3020.bin
uboot_for_tp-link_tl-wr703n.bin
uboot_for_tp-link_tl-wr720n_v3_CH.bin




14 комментариев:

  1. unfortunately it does not work for me ...
    Do you have any idea of the problem?

    make[1]: mips-linux-gnu-gcc: Command not found
    Makefile:219: warning: overriding commands for target `board/ar7240/ap121/libap121.a'
    Makefile:188: warning: ignoring old commands for target `board/ar7240/ap121/libap121.a'
    Makefile:219: warning: overriding commands for target `cpu/mips/libmips.a'
    Makefile:188: warning: ignoring old commands for target `cpu/mips/libmips.a'
    Makefile:219: warning: overriding commands for target `cpu/mips/ar7240/libar7240.a'
    Makefile:188: warning: ignoring old commands for target `cpu/mips/ar7240/libar7240.a'
    ======= Configuring for TP-Link TL-WR703N at: Tue Mar 4 15:56:15 UTC 2014 =======
    make[1]: mips-linux-gnu-gcc: Command not found
    Makefile:219: warning: overriding commands for target `board/ar7240/ap121/libap121.a'
    Makefile:188: warning: ignoring old commands for target `board/ar7240/ap121/libap121.a'
    Makefile:219: warning: overriding commands for target `cpu/mips/libmips.a'
    Makefile:188: warning: ignoring old commands for target `cpu/mips/libmips.a'
    Makefile:219: warning: overriding commands for target `cpu/mips/ar7240/libar7240.a'
    Makefile:188: warning: ignoring old commands for target `cpu/mips/ar7240/libar7240.a'
    make[2]: mips-linux-gnu-gcc: Command not found
    make[2]: mips-linux-gnu-gcc: Command not found
    make[1]: mips-linux-gnu-gcc: Command not found
    make[1]: *** [cpu/mips/start.o] Error 127
    make: *** [tplink_wr703n] Error 2

    ОтветитьУдалить
    Ответы
    1. looks like you didn't executed ~/setup_codesourcery.sh OR don't run codesourcery-mips-2011.03.sh afterwards.

      Удалить
    2. root@test:/# mips-linux-gnu-gcc
      -bash: mips-linux-gnu-gcc: command not found
      root@test:/# codesourcery-mips-2011.03.sh
      Type 'exit' to return to non-crosscompile environment
      NOW in crosscompile environment for mips (mips-linux-gnu-)
      root@test:/# mips-linux-gnu-gcc
      mips-linux-gnu-gcc: no input files

      Удалить
    3. thank you for your help.

      root@eqoe:~/u-boot_mod# mips-linux-gnu-gcc
      mips-linux-gnu-gcc: command not found
      root@eqoe:~/u-boot_mod# codesourcery-mips-2011.03.sh
      Type 'exit' to return to non-crosscompile environment
      NOW in crosscompile environment for mips (mips-linux-gnu-)
      root@eqoe:~/u-boot_mod# mips-linux-gnu-gcc
      bash: /usr/local/codesourcery/mips-2011.03/bin/mips-linux-gnu-gcc: No such file or directory

      it seems that everything is installed, but it can be a path problem?

      printenv : (after codesourcery-mips-2011.03.sh)
      SHELL=/bin/bash
      TERM=xterm
      USER=root
      SUDO_USER=root
      SUDO_UID=0
      USERNAME=root
      PATH=/usr/local/codesourcery/mips-2011.03/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      MAIL=/var/mail/root
      PWD=/root/u-boot_mod
      LANG=en_US.UTF-8
      SHLVL=1
      SUDO_COMMAND=/usr/local/bin/codesourcery-mips-2011.03.sh
      HOME=/root
      LANGUAGE=en_US:en
      LOGNAME=root
      LESSOPEN=| /usr/bin/lesspipe %s
      ARCH=mips
      CROSS_COMPILE=mips-linux-gnu-
      SUDO_GID=0
      LESSCLOSE=/usr/bin/lesspipe %s %s
      _=/usr/bin/printenv



      Удалить
    4. Maybe you somehow managed to install toolchain not right?(maybe i forgot something to describe?)
      Here is mine:

      # codesourcery-mips-2011.03.sh
      Type 'exit' to return to non-crosscompile environment
      NOW in crosscompile environment for mips (mips-linux-gnu-)
      root@test:/# set
      ARCH=mips
      BASH=/bin/bash
      BASHOPTS=checkwinsize:cmdhist:expand_aliases:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
      BASH_ALIASES=()
      BASH_ARGC=()
      BASH_ARGV=()
      BASH_CMDS=()
      BASH_LINENO=()
      BASH_SOURCE=()
      BASH_VERSINFO=([0]="4" [1]="2" [2]="37" [3]="1" [4]="release" [5]="i486-pc-linux-gnu")
      BASH_VERSION='4.2.37(1)-release'
      COLUMNS=160
      CROSS_COMPILE=mips-linux-gnu-
      DIRSTACK=()
      EUID=0
      GROUPS=()
      HISTFILE=/dev/null
      HISTFILESIZE=500
      HISTSIZE=500
      HOME=/root
      HOSTNAME=test
      HOSTTYPE=i486
      IFS=$' \t\n'
      LINES=32
      LOGNAME=root
      MACHTYPE=i486-pc-linux-gnu
      MAILCHECK=60
      OPTERR=1
      OPTIND=1
      OSTYPE=linux-gnu
      PATH=/usr/local/codesourcery/mips-2011.03/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      PIPESTATUS=([0]="1")
      PPID=2878
      PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
      PS2='> '
      PS4='+ '
      PWD=/
      SHELL=/bin/bash
      SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
      SHLVL=2
      TERM=xterm
      UID=0
      USER=root
      _=']'

      # du -sh /usr/local/codesourcery/mips-2011.03/mips-linux-gnu/*
      8.5M /usr/local/codesourcery/mips-2011.03/mips-linux-gnu/bin
      9.5M /usr/local/codesourcery/mips-2011.03/mips-linux-gnu/include
      4.4M /usr/local/codesourcery/mips-2011.03/mips-linux-gnu/lib
      504M /usr/local/codesourcery/mips-2011.03/mips-linux-gnu/libc
      164K /usr/local/codesourcery/mips-2011.03/mips-linux-gnu/share


      # du -sh /usr/local/codesourcery/mips-2011.03/mips-linux-gnu/*
      8.5M /usr/local/codesourcery/mips-2011.03/mips-linux-gnu/bin
      9.5M /usr/local/codesourcery/mips-2011.03/mips-linux-gnu/include
      4.4M /usr/local/codesourcery/mips-2011.03/mips-linux-gnu/lib
      504M /usr/local/codesourcery/mips-2011.03/mips-linux-gnu/libc
      164K /usr/local/codesourcery/mips-2011.03/mips-linux-gnu/share

      Удалить
    5. I think the problem is 32/64 bit. Do you know the correct setup to install CodeSourcery 64 bit?

      root@eqoe:/# uname -a
      Linux eqoe 3.8.0-19-generic #30-Ubuntu SMP Wed May 1 16:35:23 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
      root@eqoe:/# file /usr/local/codesourcery/mips-2011.03/bin/mips-linux-gnu-gcc
      /usr/local/codesourcery/mips-2011.03/bin/mips-linux-gnu-gcc: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.2.5, stripped

      Удалить
    6. you could try populate directory with debootstrap
      # debootstrap --arch=i386 wheezy /path/to/directory/
      , then
      # linux32 chroot /path/to/directory/

      Удалить
    7. And i think there's more simple solution for this:

      root@machine:/var/lib/vz/private/9998/usr/local/codesourcery/mips-2011.03/bin# ./mips-linux-gnu-gcc
      -bash: ./mips-linux-gnu-gcc: No such file or directory

      root@machine:/var/lib/vz/private/9998/usr/local/codesourcery/mips-2011.03/bin# aptitude install libc6-i386
      The following NEW packages will be installed:
      libc6-i386
      0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
      Need to get 4,036 kB of archives. After unpacking 9,224 kB will be used.
      Get: 1 http://mirror.yandex.ru/debian/ wheezy/main libc6-i386 amd64 2.13-38+deb7u1 [4,036 kB]
      Fetched 4,036 kB in 0s (27.0 MB/s)
      Selecting previously unselected package libc6-i386.
      (Reading database ... 134564 files and directories currently installed.)
      Unpacking libc6-i386 (from .../libc6-i386_2.13-38+deb7u1_amd64.deb) ...
      Setting up libc6-i386 (2.13-38+deb7u1) ...

      root@machine:/var/lib/vz/private/9998/usr/local/codesourcery/mips-2011.03/bin# ./mips-linux-gnu-gcc
      mips-linux-gnu-gcc: no input files

      Удалить
  2. I think the problem is very basic. My machine is a server, if you have some time, I can give you access to watch the problem?

    ОтветитьУдалить
    Ответы
    1. I think libc-i386 installation should solve your issue, but if not you can reach me at skypeid hackru.

      Удалить
    2. Yes, you're right.
      Unfortunately, I now have another error.

      root@eqoe:~/u-boot_mod# make tplink_mr3020
      Makefile:219: warning: overriding commands for target `board/ar7240/ap121/libap121.a'
      Makefile:188: warning: ignoring old commands for target `board/ar7240/ap121/libap121.a'
      Makefile:219: warning: overriding commands for target `cpu/mips/libmips.a'
      Makefile:188: warning: ignoring old commands for target `cpu/mips/libmips.a'
      Makefile:219: warning: overriding commands for target `cpu/mips/ar7240/libar7240.a'
      Makefile:188: warning: ignoring old commands for target `cpu/mips/ar7240/libar7240.a'
      ======= Configuring for TP-Link TL-MR3020 at: Fri Mar 7 11:06:09 UTC 2014 =======
      Makefile:219: warning: overriding commands for target `board/ar7240/ap121/libap121.a'
      Makefile:188: warning: ignoring old commands for target `board/ar7240/ap121/libap121.a'
      Makefile:219: warning: overriding commands for target `cpu/mips/libmips.a'
      Makefile:188: warning: ignoring old commands for target `cpu/mips/libmips.a'
      Makefile:219: warning: overriding commands for target `cpu/mips/ar7240/libar7240.a'
      Makefile:188: warning: ignoring old commands for target `cpu/mips/ar7240/libar7240.a'
      r - crc32.o
      r - ctype.o
      r - display_options.o
      r - ldiv.o
      r - string.o
      r - vsprintf.o
      r - LzmaWrapper.o
      r - LzmaDecode.o
      r - main.o
      r - cmd_bootm.o
      r - cmd_boot.o
      r - cmd_flash.o
      r - cmd_mem.o
      r - cmd_custom.o
      r - cmd_net.o
      r - cmd_nvedit.o
      r - command.o
      r - console.o
      r - devices.o
      r - dlmalloc.o
      r - environment.o
      r - env_common.o
      r - env_nowhere.o
      r - exports.o
      r - flash.o
      r - lists.o
      r - env_flash.o
      r - ap121.o
      r - ../common/ar7240_flash.o
      r - ../common/ar7240_s26_phy.o
      r - ../common/lowlevel_init.o
      r - hornet_pll_init.o
      r - cpu.o
      r - cache.o
      r - meminit.o
      r - hornet_serial.o
      r - ag7240.o
      r - hornet_ddr_init.o
      r - board.o
      r - time.o
      r - mips_linux.o
      r - netconsole.o
      r - pci.o
      r - net.o
      r - tftp.o
      r - rarp.o
      r - eth.o
      r - bootp.o
      r - sntp.o
      r - httpd.o
      r - date.o
      r - uip.o
      r - uip_arch.o
      r - uip_arp.o
      r - httpd.o
      r - fs.o
      r - bootstrap_board.o
      r - LzmaDecode.o
      r - string.o
      r - crc32.o
      r - LzmaWrapper.o
      r - time.o
      /root/u-boot_mod/host_util/lzma: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
      make[1]: *** [u-boot.lzimg] Error 127
      make: *** [tplink_mr3020] Error 2

      Удалить
    3. Do you have libstdc installed?
      # dpkg -l | grep libstdc
      If not - install it
      # apt-get install libstdc++6

      Удалить
  3. Affiliates that be part of this affiliate program will be able to|be succesful of|have the ability to} market one of the main online on line casino manufacturers available today. As an affiliate, you'll profit from new players you suggest as long as|so long as} they play and also you actively promote them following the phrases and conditions. When it comes to choosing a on line casino, the payment method is generally a major consideration. Videoslots provides a diverse vary of payment choices, making it simple for most players to choose on} a suitable choice. The deposit methods are VISA and Mastercards, Apple Pay, Cashtocode, MuchBetter, NeoSurf, etc. I can understand that as a reader, your mind might be crammed with a lot excitement to know more about Videoslots on line 카지노사이트 casino games.

    ОтветитьУдалить