martes, 24 de abril de 2012

La Fonera definitive cable

One of my old mobile phones (a Grundig) had a usb cable which has been around for a long time without much use, some time ago when plugging it into Linux I realised that it seemed like a standard usb to serial adaptor.

Bus 003 Device 002: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port

[54027.595634] USB Serial support registered for pl2303
[54027.595855] pl2303 3-1:1.0: pl2303 converter detected
[54027.607264] usb 3-1: pl2303 converter now attached to ttyUSB0

So I analyzed it and found that it seemed like a 3.3V serial adaptor, so I had to start using it to access routers, mobiles, ... having also a broken Fonera power supply around (one of this typical Fonera problems where the power supply outputs the correct voltage but not enough intensity) I thought... if I put all this together I'll have a USB cable capable of powering La Fonera and also accessing it's serial port all in one and using just one USB slot.

And so... here is what I think is the definitive Fonera cable:

Recovering my fonera's filesystem files after f*cking it

Once upon a time I was cleaning up the jffs2 filesystem of my OpenWrt Backfire 10.03.1 based Fonera by removing "unused" packages and I thought... what is this hotplug2 package doing here, the fonera doesn't have anything hotplugable, so I can safely remove it... WRONG!

Never remove your hotplug2 package from your OpenWrt router, it won't complain, but once you reboot... at least on a Fonera with Backfire you are f*cked!

Hotplug2 is so needed that today, after finishing my definitive cable for La Fonera (I'll write about this later) when I saw it booting on the serial console, I watched my Fonera say on boot...

VFS: Mounted root (jffs2 filesystem) readonly on device 31:1.
Freeing unused kernel memory: 136k freed
Please be patient, while OpenWrt loads ...
Kernel panic - not syncing: Attempted to kill init!

and that was before getting to failsafe mode or anything, so... how could I gain access to the files I had inside if it was not booting?

It seems I went through the hard way, cause it resulted on a long way, that's why I'm writing it here...

I had access to the console and it has redboot on it (/me doesn't know anything about redboot), so I stopped redboot (I did this on the serial console but I have just realised that this can be done over telnet as well) and typed help, and then looking at my previous notes on how to flash OpenWrt I tried to enable capture on minicom (if you do this on telnet try to pipe it to tee) and dump the contents of the jffs2 filesystem using:

RedBoot> baudrate -b 115200
Baud rate will be changed to 115200 - update your settings
Baud rate changed to 115200 - continue (y/n)? y
Update RedBoot non-volatile configuration - continue (y/n)? n
RedBoot> fis list
Name FLASH addr Mem addr Length Entry point
RedBoot 0xA8000000 0xA8000000 0x00030000 0x00000000
rootfs 0xA8030000 0xA8030000 0x006D0000 0x00000000
vmlinux.bin.l7 0xA8700000 0x80041000 0x000E0000 0x80041000
FIS directory 0xA87E0000 0xA87E0000 0x0000F000 0x00000000
RedBoot config 0xA87EF000 0xA87EF000 0x00001000 0x00000000
RedBoot> fis load -b 0x80041000 rootfs
** Warning - checksum failure. stored: 0x136086ec, computed: 0x5571b53b
RedBoot> dump -b 0x80041000 -l 0x006D0000
80041000: 19 85 20 03 00 00 00 0C F0 60 DC 98 19 85 E0 01 |.. ......`......|
...

So, after some minutes I had all this hexa dump of the memory on my HD. Deavid kindly contributed this 90 secs python script to extract the hexa into binary (many thanks to him):

#! /usr/bin/python

from binascii import unhexlify
import sys

for line in sys.stdin:
colon = line.find(":")
end = line.find("|")
if colon < 0 or end <0:
sys.stderr.write(line)
else:
newline = line[colon+1:end].replace(" ","")
sys.stdout.write(unhexlify(newline))

And I had my jffs2 filesystem dumped on a file, yeah, so I thought I could simple mount -o loop it but... nope, jffs2 isn't that easy. Looking on the net I found that I should:

modprobe mtdram total_size=24576 erase_size=128
modprobe mtdblock
dd if=jffs2.img of=/dev/mtdblock0
mount -t jffs2 /dev/mtdblock0 /mnt

But that resulted on a mount: /dev/mtdblock0: can't read superblock error.

At that time I thought it could be an endianness problem, as I also wasn't able to mount an OpenWrt original jffs2 filesystem. So... a little more search on the net confirmed this and showed that:

apt-get install mtd-utils
jffs2dump -b -c -e dest_file.little src_file.big

should fix it, and so it did, after doing that and copying the new data converted from big endian to little endian to the mtdblock0 I was able to mount it and finally access all that I had on my Fonera.

That's it!

viernes, 24 de febrero de 2012

livebox2 reset internet connection

Being with Orange for some years means that I used to have a livebox 1 and now have a livebox 2. With the new one however it seems that from time to time my connection is stuck, if you look at the web page everything seems fine, but packets don't get passed the livebox, resetting the Internet connection is the quickest way to solve this. Here is a script to reset the connection from the command line:
wget --post-data="page=home&authaction=login&authlogin=admin&authpasswd=YOURPASSWORD" http://192.168.0.1/index.cgi -O - 2>/dev/null|(URL=$(sed -n 's|.*index.cgi?page=internet\(&sessionid[^"]*\)".*|http://192.168.0.1/index.cgi?page=internet\&action=reset\1|p');wget "$URL" -O - >/dev/null 2>&1)
One warning, here we have the password on the command line, you can use --post-file instead of --post-data to be safer, but anyway, please note that we are sending the password in the clear without any ciphering, while the livebox web page sends it as a hash, so it should be somewhat safer if they do things right.

viernes, 27 de enero de 2012

Pepephone vuelve a ofrecer la del pulpo

Pues eso, que los de Pepephone vuelven a ofrecer la tarifa del pulpo (que es la que tengo yo), ahora se paga el primer minuto a 0 y va aumentando de precio hasta los 4.9¢/minuto de máximo, eso sí, siempre con establecimiento de 15¢, si a alguien le interesa podéis pillarla en la web promocional del pulpo pepe

domingo, 1 de enero de 2012

Feliz 2012

Como algunos de mis amigos parecen leer este blog he pensado que estaba bien felicitar el año por este medio, y además se me ha ocurrido utilizar unas fotos que a algunos les traerán recuerdos de los good old times...


en esa foto se puede observar parte del hardware con que fueron tomadas las fotos: una capturadora de video y una cámara VHS, por aquel entonces no crecían las cámaras digitales por todos lados :-) He fechado esto en el año 1998, a ver si alguien me lo puede confirmar, es en la Taboada's Party y estábamos pasando mucho frío, digo... preparando la Arroutada de ese mismo año. Una de las atracciones de la party (al menos para los linuxeros) fue:


un PC (Pentium 166 a 200) que llevaba 12 tarjetas de red, 4 PCI y 8 ISA configuradas en modo bridge (haciendo switching) y que sería el "core" de la red de la Arroutada de ese año, esta es una vista del equipo:


Y aquí tenéis un detalle del expansor de bus que habíamos utilizado para poder meter 5 tarjetas ISA más en la máquina:


La verdad, todavía conservo esta cacharrería por aquí, algún año de estos en una Dudes o algo así me gustaría intentar volverla a poner a funcionar :-)
Mientras tanto... unas imágenes más del engendro, una del interior con las 12 tarjetas numeradas:


Una de la parte trasera con todas las tarjetas con sus BNCs conectados en la que me veo yo con las pintas de aquella época y sin dormir :-)


Y una última en la que se el interior sin los papelotes de numeración de las tarjetas:


Que tiempos aquellos :'-)
Nada más, feliz año a todos y que sigamos pudiendo disfrutar de la informática como siempre lo hemos hecho.

miércoles, 21 de diciembre de 2011

Camiseta de GPUL para Artai

Últimamente a mi mujer se le da por coser, y se le ocurrió hacerle unas camisetas a Artai reciclando camisetas nuestras, esta salió de una antigua camiseta de GPUL mía :-)


Por cierto, también se le ha dado por hacer un blog sobre lo que anda cosiendo, está empezando, se llama Agulla e fio para quien pueda interesar.

viernes, 25 de noviembre de 2011

Executing with a key/button (how to hibernate without the propper button) + ACPI bug workaround

Some time ago I found a problem with one of my desktops when remapping the acpi power button events to hibernate instead of power off the machine, the machine was sending two events on each button press which sadly meant that Linux would hibernate again when powering the machine on :-(
The solution I had to apply to this was to protect my hibernate acpi support script with a lock that avoids the double pm-hibernate call. This ended up being like something like this: if lockfile -r0 /etc/acpi/powerbtn.lock
then
...
pm-hibernate
( sleep 2 ; rm -f /etc/acpi/powerbtn.lock ) &
fi

Anyway, while I was waiting for the ACPI guys not to answer me I was exploring some things which are the ones I wanted to write down here.

First: The good old typical linux low level mapping with setkeycodes, in this case if you want to map scroll lock (0x46) to the sleep key (142) you'll do setkeycodes 46 142 You can use showkey -s to see the scancodes and look for key codes at /usr/include/linux/input.h and /usr/share/acpi-support/key-constants

Second: If you happen to have around a webcam with a button you can try to do something with it, if you are lucky enough that button may be mapped to the "XF86WebCam" key, this happened to me on a Logitech Quickcam 5500 (046d:09a1). It is easy on icewm to map this key writing on .icewm/keys something like this that execs your favourite command:key "XF86WebCam" favourite_command As usual the typical tools like xev, configs like ~/.Xmodmap and infos like /usr/share/X11/XKeysymDB apply here.
There is something you must be aware of, the webcam button may not work if the camera device is not opened, in this case you can launch on background on your startup sequence a little perl script like this one which sleeps forever once it opens the video device: perl -e "open(FILE, '/dev/v4l/by-id/usb-046d_09a1_76A5BF10-video-index0') || die 'Cannot open the device\n';sleep;" &
Third: There are some programs like esekeyd and triggerhappy that can map your events (like the ones from the webcam) to keys and things like that, esekeyd has some limitations I comment here and triggerhappy is supposed to be a bit more powerfull, but I don't know if triggerhappy can work without the perl script I commented earlier, esekeyd right now can't. The config for esekeyd on my machine was to set on /etc/defaults/esekeyd this: DAEMON_OPTS="/etc/esekeyd.conf /dev/input/by-id/usb-046d_09a1_76A5BF10-event-if00" and then I used acpi_fakekey from the acpi-fakekey package to fake the sleep key (142, see first comment on where to get the codes) when the camera button is pressed by setting on esekeyd.conf this: CAMERA(press): acpi_fakekey 142
Fourth: Userspace typically can't just signal hibernate but there I discovered the upower package that allows you to signal hibernate from userspace using a dbus signal and works great, with that my second example ended up with this sh oneliner (that locks my desktop and then sends the hibernate event wich acpi processes) on .icewm/keys: key "XF86WebCam" sh -c "xscreensaver-command -lock && dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Hibernate"