Informatik und Kram

Da wir lange nicht wußten, wo wir das für die Uni ausgearbeitete Material unterbringen sollten und auch einen schrecklichen Drang hatten der Welt diverse Sachen aufzudrücken...

Fonera-Hacks-English
de-flagge aktiviert en-flagge aktiviert

I know that this article is quite old stuff for some of you folks, but i've been reading alot tutorials, wikis and howtos for the last 4h, and I'd like to collect it all right here. Plus, i will cover topics like writing your own programs and compiling them for the fonera (to control stuff over WLAN).
In this article, I'll show you
  • how to enable SSH access
  • install the kmod-gpio modules
  • load them at boot-up
  • setting up buildroot and compile programs for the fonera
  • General Infos

    This box has a 183Mhz-Processor, 8Mb Flash, 16Mb RAM, 5 GPIO-Pins and a serial interface.
    The OS in use is Open-Wrt, but modded by Fonera ( for example, client mode of the network-interfaces is disabled ). Besides the OS behaves just like a common Linux

    Out of the box

    DONT CONNECT TO THE I-NET! If you do so, the fonera will update itself to the new firmware, and we dont want that! Just leave the Ethernetport open and connect per WLAN to "MyPlace" (wpa-key is on the sticker on the bottom).
    Now you should see the startpage of your fonera. Here you can select "Status" to view which firmware's on your box. You're lucky if you own a box with firmware-versions 0.7.0r4 to 0.7.1r1, cause here you can simply enable ssh-access with a quick html-injection:http://k0k0.k1k2.de/ssh/open-ssh-access-to-fonera.htmKeep in mind to change the mentioned config-files to prevent the box from updating the firmware when connecting to the internet!
    Everyone else (other firmware-versions) should look at http://stefans.datenbruch.de/lafonera/ , there are other methods listed to open ssh.

    SSH

    Now you can connect to your fonera by typing
    ssh root@192.168.10.1
    
    Your default-Password should be "admin".
    Now that we have ssh-access, we can mod the startpage a bit, you find it at /var/www/.
    Have Fun!

    GPIO

    Our Box has four usable gpio-pins (general purpose input output) which we wanna use!
    Kernel-Versions 2.4 look at http://fghhgh.150m.com/, kernel versions 2.6 should have a look athttp://fon.testbox.dk/packages/2.6.21.5/). Get the files ending *.ipkg, these are the packages we can install with ipk. Afterwards copy them to your fonera:
    scp kmod-gpio_2.4.33.4-ar531x-1_mips.ipk root@192.168.10.1:/jffs
    
    Now again, connect via ssh and install them by typing:
    root@OpenWrt:~# ipkg install /jffs/kmod-gpio_2.4.33.4-ar531x-1_mips.ipk
    
    To check if they work correct load them:
    root@OpenWrt:~# insmod /lib/modules/2.4.33.4/proc_gpio.o
    
    and check, wether there's a directory named gpio in /proc.
    Now you can turn off your WLAN-LED (system will switch it on automatically shortly after that, but hey, its only the first test)
    root@OpenWrt:~# echo "0" > /proc/gpio/2_out
    
    If everything works you can set your system to load the module at boot-up. Therefore you create a file called /etc/init.d/S50gpio, whith the following contents:
    #!/bin/sh
    #Copyright (C) 2006 OpenWrt.org
    
    insmod /lib/modules/2.4.33.4/proc_gpio.o
    

    Solder!

    Now, of course, we wanna open the box (remember: if you cant open it, you dont own it :-) ) and actually use the gpio-pins. Therefore we open up the case, there are only two screws, located under the front feet. Just screw them out and take off the hood!
    And now the pin-locations ->Sadly, the gpio-pins have a clearance of 2mm, not the common 2.54mm, so the solder joints are quite closely. Tomorrow I'll get some pin-headers and solder that proper, in the long run it shall control my robot!
    That is the serial interface of the fonera, i marked the pins for you. Always remeber to connect GNDs!
    And here the allocation of the gpio-pins. I soldered every pad on SW1 for measurements and tests, but it turned out that you can only switch four of them (switching pin 3/4 on will reset the box):
    Usable Pins: 1,2,5,6.

    compile your code!

    Since there's no compiler on the fonera, we have to compile our programs on the pc and transfer them to the box. So we have to set up a build-root to cross-compile, to get the progs running on the Fonera. I'll show you how to this both ways, the first is with a original fonera-kernel on your box, the second is with a custom open-wrt-kernel on your box.

    Setup your buildroot (orig. Fonera-Kernels only!)

    Here's the how-to to setup a buildroot (only tested for fonera):
    We will need the following packages for our project:
    gcc, binutils, patch, bzip2, flex, bison, make, gettext, pkg-config, 
    unzip, libz-dev und die libc-header
    
    Now get the fonera-sources by Fonera, create a directory and unpack:
    $> mkdir /wherever/fonera-src/
    $> cd /wherever/fonera-src/
    $> wget http://download.fon.com/firmware/fonera/latest/fonera.tar.bz2
    $> tar jxvf fonera.tar.bz2
    
    Configure with
    $> make V=99 config
    
    I kept all the default-values, but chose the jffs-filesystem-option additionally.
    Now compile it, have a cup of coffee, smoke some, it took 45 minutes for me:
    $> make V=99
    
    It canceled with error 2 caused by some "ftello64", but i still was able to compile programs, which takes us to the next level:

    compile and copy!

    Now we're read. Create the following test-program as test.c:
    /* test.c - Test my buildroot for Fonera */
    #include <stdio.h>
    
    int main(int argc, char *argv[])
    {
        printf("Yeahah, up and running!\n");
    }
    
    Before compiling we have to set the Environmentvariable PATH:
    $> PATH=$PATH:/wherever/fonera-src/staging_dir_mips/bin
    $> export PATH
    $> mips-linux-uclibc-gcc test.c -o test
    
    Now we copy the compiled binary to the fonera:
    $> scp ./test root@192.168.10.1:/tmp/
    
    Finally, login via ssh and start the binary:
    $> ssh root@192.168.10.1
    root@OpenWrt:~# cd /tmp
    root@OpenWrt:~# ./test
    Yeahah, up and running!
    

    --- UPDATE 19.10.2008 ---

    Meanwhile i coded a little server using a c++-program and the buildroot. It's running on the fonera, and the matching client runs on my Laptop. Now i can hit the keys on my Laptop to toggle the GPIO-Pins in realtime:

    Setup buildroot ( for Open-Wrt-Kernels )

    OpenWrt has a lot more functionality than the trimmed Fonera-Kernel. In this section I'll show you how to compile your own openwrt-kernel, setup a buildroot for it and compile programs running with the new kernel.
    I now need I2C at all costs, since we're planning on using the router as server on our robo, hence we'll build a complete new kernel with with i2c-modules. We used the following Tutorials:Buildroot for OpenWrt and for flashing: Open-Wrt on the Fonera:
    First, check out the source to your computer:
    svn co https://svn.openwrt.org/openwrt/branches/8.09/
    
    To build the i2c-tools as package, create a folder named i2c-tools in your packages-folder, and simply put put this makefile there: i2c-tools-makefile.
    Remember to choose i2c-utils when running 'make menuconfig' !
    Now choose the architecture to build for, for the fonera its Atheros AR2315:
    make menuconfig
    
    ...and now start to compile:
    make V=99
    
    Sooo, a few hours later (to be precise, its been 4h). Kernel has successfully been built, the i2c-modules too. You find the new filesystem and kernel at bin/.

    Flash

    ATTENTION!! This only works, if you already _have_ Open-Wrt on your box! This does NOT work with a vanilla Fonera-kernel! There you have to flash via the serial-cable!So, back again, this time i flashed while the box was running ( over ssh ):
    cd /tmp
    scp host:/path/to/openwrt-atheros-vmlinux.lzma .
    scp host:/path/to/openwrt-atheros-root.jffs2-64k .
    
    mtd -e vmlinux.bin.l7 write openwrt-atheros-vmlinux.lzma vmlinux.bin.l7
    mtd -e rootfs write openwrt-atheros-root.jffs2-64k rootfs
    reboot
    

    WiFi Clientmode

    Worked like charm! After the reboot all your network-settings are gone, so here again the steps to put the fonera in client-mode and connect to your local wlan. ( Of course you have to connect serial, ATTENTION, sometimes the fonera won't boot with plugged-on serial-cable. So, disconnect serial, startup, wait 5 secs, plug-on cables, connect with minicom, hit enter, that activates the console!).
  • Now disable firewall ( we dont need this to control our robo!): just rename /etc/init.d/firewall
  • change /etc/config/network:
  • config interface lan
            option ifname   wifi0
            option proto    dhcp
            option netmask  255.255.255.0
    
  • change /etc/config/wireless:
  • config wifi-device  wifi0
            option type     atheros
            option channel  auto
    
    config wifi-iface
            option device   wifi0
            option network  lan
            option mode     sta
            option proto    dhcp
            option ssid     skynet
            option encryption       "wep"
            option key      "s:YOUR_KEY_IN_ASCII"
    
    Now just setup a root-password to login via ssh!

    Kommentare

    Kommentar schreiben