Saturday, March 6, 2010

Fonera 1-wire MicroLAN extension

I wanted to add a 1-wire bus to one of my Foneras. I already flashed it to DD-WRT some time ago, but realized that I can't disable the serial system console or the shell so there's no way to use the serial port for anything else. I searched around and it seemed like Gargoyle might be a better solution. It's a firmware based on OpenWRT. I flashed it, only to realize that the same restriction applies to the system console part. It seems all Fonera firmwares ignore the kernel command string set in RedBoot and just work with a hardcoded one. Which usually contains console=/dev/ttyS0 making the serial port useless.
A post on the Gargoyle forums refers me to setconsole, which isn't included in either version (stable/testing) anymore. I tried with several setconsole compiles of my own only to get an assortment of error messages. Because compiling a whole new firmware is entirely too much of a pain for something as simple as freeing up a serial port i ended up unpacking the kernel image and modifying the hardcoded string with a hex editor. Then repacking, padding, and flashing the modified image to the Fonera. (modify the string to console=/dev/null)
The LZMA SDK from 7zip can be used for the compression.
Make note of the kernel image size before unpacking, and pad with null bytes to that exact size after repack. This is not optional. Flashing will fail otherwise.

This worked, so I proceeded to disable the shell in /etc/inittab making the serial port usable again.
Thanks to the OpenWRT roots the rest was pretty easy on the software side.
the commands
opkg update
opkg install owfs
opkg install owhttpd
gave me all the tools I needed to work with 1-wire.
And ..
opkg install php4-cli
opkg install php4-mod-gd
gave me what I needed to code up web interfaces.

The CLI compile is required because the CGI one is Apache specific. Gargoyle has a small httpd lacking most of Apache's features. The CGI compile will error out however the CLI release can be made to work. There are certain annoyances like a missing $_GET/$_POST and the requirement to send a \n before page content and after headers, but they are not that serious.
( to fix get: parse_str($SERVER["QUERY_STRING"],$_GET) )

On the hardware side I opted to use a DS2480B 1-Wire Line Driver chip. This chip is used in the DS9097U adapters so it's basically the standard in UART to 1-Wire interfacing. I wanted to include fancy things on the board like a software controlled power switch and an activity LED, but in the end I abandoned both. The power switch didn't work out, and the LED was pretty useless due to the low activity on the bus. Because of this the original board is ugly and overkill. It is however extremely simple to hook this chip up. There are no external component requirements. POL VPP and VDD needs to be connected to together. Rest is obvious. (TXD,RXD, 1-w DQ and GNDs to appropriate holes/solderpads on the interface board, then TXD,RXD,GND to Fonera, and DQ and GND to some sort of connector for the 1-Wire bus. You can also get the 5V for the interface board by soldering to the Fonera's PSU connector)
Here's a simplified interface board:


eagle brd here

I opted to use an RJ9 connector simply because I had one on hand, and because it fit right next to the Ethernet's RJ45.


You might want to consider including the Fonera's 5V on your connector. It could become handy if you want to attach non-parasitic devices in the future. I opted not to do so. I will be building a "powered hub" out of a 5way phone-line splitter later.

For testing I used iButtons hooked up as seen below.
RJ11 Blue dot receptor -> Ghetto RJ9<->RJ11 cable -> Fonera


Simple OWFS testing: (connecting and removing iButton)


Success!
Now I have a LAN/WLAN/MicroLAN router :)

29 comments:

  1. Great job. I was also thinking of doing that. Never found the time though. Certainly going to do this to. They did not add it to the owfs site yet.

    ReplyDelete
  2. Can you share the modified kernel?

    ReplyDelete
  3. http://www.mediafire.com/?vv1k4ihgjjm

    Good Luck :)

    ReplyDelete
  4. Congratulation that's a nice project! It wasn't possible to change kernel parameters passed-on to the kernel from redboot pompt?

    Inouk (from fon.com)

    ReplyDelete
  5. Thanks
    Both DD-WRT and Gargoyle seemed to fall back on their hardcoded strings and ignored the one I set in redboot for some reason. I added it to the exec command with -c. I couldn't get it to use anything I set there. I'm pretty sure I double-checked everything. Maybe someone else can get it to work that way, I gave up :)

    ReplyDelete
  6. This is very cool. I did something similar with my Fonera using OpenWRT Kamikaze build. I did not need to alter RedBoot at all to get serial to work, just had to make the small change to /etc/inittab to get serial working.

    ReplyDelete
  7. That works if your build doesn't have system console set to /dev/ttyS0. If you just disable shells in inittab you can use the serial, but if the system console is still set there then kernel messages might disrupt whatever it is you have on serial.

    ReplyDelete
  8. hey how you did this part? modify the string to console=/dev/null

    can you tell me more detailed information? thanks :)

    ReplyDelete
  9. btw i tried your compiled firmware but when it asks for admin password i put: admin
    but it didnt work :S

    ReplyDelete
  10. The default might be "password" but I don't remember anymore. A search on the gargoyle site will prolly turn it up. I haven't compiled anything It's the official release's unmodified rootfs in that archive. My only modification was in the kernel.

    ReplyDelete
  11. do we need to change anything on redbot? password: password :) thanks :)

    ReplyDelete
  12. Since it's booting fine probably not :) No problem

    ReplyDelete
  13. what version of Fonera did you use? i'm trying to make this project with Fonera 2100 with your firmware but it gives no data to serial port (http://www.jbprojects.net/projects/wifirobot/#software) and if you want to see my post on openwrt (https://forum.openwrt.org/viewtopic.php?id=24078) :)

    ReplyDelete
  14. It should work fine with a 2100. Possibly some problem with your serial interface?

    ReplyDelete
  15. nope, i tested it with serial console ( before disable that) and it works :S

    ReplyDelete
  16. I see. Maybe try skipping setserial/stty commands. (If you're using them) Port should be at 9600bps by default or the speed configured in redboot. Don't know. But it should work at one of those speeds. Works fine for me at 9600. Didn't do any testing at other speeds.

    ReplyDelete
  17. it isnt at 9600 by default i think, and my circuit needs that speed

    ReplyDelete
  18. It is for me ;) Try setting 9600 in redboot fconfig.

    ReplyDelete
  19. can you tell me how i do that? :)

    ReplyDelete
  20. Enter redboot
    Enter the fconfig command
    Leave other settings intact (you may need to re-type the boot script, but it'll show the original. Just copy.)
    When it gets to Console baud rate, delete original value and type 9600
    When it asks you if you want to update the config choose yes. You can always choose no if you've made a mistake and retry.
    Type reset or just powercycle the router.

    ReplyDelete
  21. What commands are used to unpack/repack the file properly with the [LZMA SDK from 7zip]? I have tried some ways but after comparing my files with the original files and your file I think I'm doing it wrong. So if you could answer this question I would be pleased, and a bit wiser.

    ReplyDelete
  22. Never mind my last comment. I solved it, I was just being particularly stupid at the time. Anyway, here is a link to the latest(2010-07-02) OpenWrt Backfire version (10.03, r20728) with the same modification as linked above. Still need to disable the shell in /etc/inittab . But after that you are gold. All owfs programs are available as packages in a slightly newer version (2.7p21-1).

    http://www.mediafire.com/?whhytzcqddj
    http://www.mediafire.com/file/whhytzcqddj/backfire_10.03_nosercon.zip

    ReplyDelete
  23. hey there, anyone know how to compile one program to that version of gargoyle? ( openwrt kamikaze 8.09.1)

    ReplyDelete
  24. i have foenra 2100A and i need to install http://www.jbprojects.net/projects/wifi … ipsel.ipk, this is for white russian. it gave me this error when i tried to install it:

    Collected errors:
    * Packages were found, but none compatible with the architectures configured

    i already had it installed with that version but now it doenst accept the package dont know why sad

    i resolved to compile my package and it gaves me the same error :S

    i have gargoyle firmware version installed on my Fonera ( 8.09.1 openwrt)

    don't know what to do :S last month this worked perfectly :S

    ReplyDelete
  25. ciao Victor,

    sure I'm missing something, but if I connect my fonera to the DS2408, it won't boot.
    If I connect that later it boots fine and everything works, but I caanot have that connected to have fonera booting.
    I tried to see if I could get into redboot to see what was going on but it seems not even going into redboot.
    any clue ?
    Thanks very much
    Luca

    ReplyDelete
  26. Not even RedBoot? That's strange..
    Did you try connecting a PC to the serial port to see what's going on (if anything) during the boot process when the 2408 is connected?
    You could also check if changing the Redboot serial console baud rate in fconfig to something else changes anything.

    ReplyDelete
  27. Hi Viktor,

    First of all thanks for the answer.
    I did an error. I supposed that the serial pins on the fonera were having the +5v power pin, while that is +3,3...... and I used that to power the 2480... removed that it works fine.

    Thanks again for your time.
    L

    ReplyDelete