Archive for the 'hacks' Category

20
Aug
13

Improved bash directory bookmarking

I’d recently found http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html and decided to give it a try.

It’s simple and quite stable. AND you can change it without much thinking (although in bash this could end up in sadness).

To use, just add to your .bashrc. The ZSH and OSX versions are available in the original blogpost!

I’ve updated it to:

export MARKPATH=$HOME/.marks
test -d $MARKPATH || (
    echo "Creating dir MARKPATH=$MARKPATH ..."
    mkdir $MARKPATH
)
function jump {
    if [[ "$1" != "" ]]; then
        cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
    else
        echo "Usage: $0 <mark>"
    fi
}
function mark {
    mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$1"
}
function unmark {
    if [[ "$1" != "" ]]; then
        rm -i "$MARKPATH/$1"
    else
        echo "Usage: $0 <mark>"
    fi
}
function marks {
    ls -l "$MARKPATH" | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' | grep -v '^$'
}

_completemarks() {
    if [[ $COMP_CWORD -ne 1 ]]; then
        COMPREPLY=()
    else
        local curw=${COMP_WORDS[COMP_CWORD]}
        local wordlist=$(find $MARKPATH -type l -printf "%f\n")
        COMPREPLY=($(compgen -W '${wordlist[@]}' -- "$curw"))
    fi
    return 0
}
complete -F _completemarks jump unmark

Changes:

  • create directory if it does not exist
  • do not accept ‘jump’ and ‘unmark’ without argument
  • do not print empty lines in ‘marks’
  • autocomplete only first argument

TODO:

  • check if directory of mark is available
08
Sep
11

Failed 1005ha battery mod

In the end of 2009 I bought my Asus Eee pc 1005ha netbook. It’s pretty good for what it is designed for. Have no complaints, just that the cpu could be a newer Intel Atom model.(Which would support 64bits OS’ and some virtualization options.)

Having used it heavily for more than a year and not really trying to save my battery life, the same has gone down the drain. From the advertised 8 hours, 6 hours good use to now less than an hour. Time to buy a new one.

I saw some batteries with 7200 mAh at eBay. Almost double the power my original battery had, which was 4800mAh. And they were sold for $40! I ended up buying one.

After receiving the battery I plugged it in my netbook and turned it on with the power supply connected.
Weird. The charging light(orange) flashed but stayed off. The BIOS froze at ‘Checking NVRAM’ for some time, but eventually continued. Ubuntu and Windows XP did not recognize the battery.
First thought: defective.

I browsed to the manufacturers(AGPTEK) website and voila, the battery shown in the site was different than mine! Did not have the logo, the battery text was upside down, and the voltage should be 10.8V instead of the 11.1V my new battery had.

I contacted the seller and, of course, I would have to send the battery back, which would cost the equivalent of $30 for a $40 refund. Of course I didn’t. I ended up loosing the dispute date in eBay, or else I would have disputed the payment.

Meanwhile, I decided to buy one from Amazon. Same price, same manufacturer. Should be safe.

Nope, I was wrong. Exactly the SAME battery arrived. And with the same behavior. Now I had two paperweights which I could not really use to power my netbook.

I gave up and put up a bet, all or nothing. I would replace the cells from the old battery with the ones from one of the new batteries. If it worked, I would have a working battery with huge capacity, or else I would have no working battery at all.

After finally managing to open the cases of the two battery packs, which were by no means designed to be opened ever again, I finally dis-soldered the cells and swapped the 6 pack for the new 9 pack. Put it halfway together and inserted it into the netbook while connected to the power supply.
(I recommend using a drill and CAREFULLY cutting into the edges of the battery that have been sealed, or use a heated knife.)

YAY! The charging light turned on! Thats a good start. I left the netbook charging for a bit. I kept checking the

/proc/acpi/battery/BAT0/state
/proc/acpi/battery/BAT0/info

files for any changes or status indications. Nothing.

I disconnected the power supply to test the battery. And my netbook powered of instantly….
I tried it again and got the same effect. The battery was not giving any juice. CRAP.

I looked it over to check if I had done something wrong or if there was some kind of sensor which had been triggered. Nada.
Oh well, time to put my old cell pack back into the battery.
After re-soldering the contacts and sticking the heat sensor back to one cell I tried it….
The same. No power.

YAY. No working battery. I wrapped both in tape to keep the pieces together and put the away. Had no more patience to keep fiddling with them.

OBS.:
It could be that without charge the circuit looses it’s memory or locks. If someone should try this, keep the circuit charged at all times, connecting the new battery pack in parallel first and then removing the old one.

Since I still had to use my netbook and did want to have a little liberty of mobility, I ended up plugging the second battery pack into it. Would have to find a work around with the BIOS issue.

So I was using the netbook for a time and noticed the charging light was ON. Rebooted, still had the BIOS issue and the charging light was off.

I insisted using the new battery for a time, and it ended up working perfectly after a while. Has a very good duration!
I was very confused about the apparent symbiosis the battery made with my netbook.. seems they take a while to understand each other.

Pictures:

Comparison of the old/original and new/chinese(lol) battery casing.(Obviously the old one has ASUS written on it).

The cells from the original battery.

The cells from the Agptek battery.

Front of the new Agptek battery control circuit. Casing below is from the new battery as well.

Back of the new Agptek battery control circuit. The heatsensor can be seen.

Front of the original battery control circuit connected to the new batteries cells.

Backside of the original battery control circuit

My original battery put back together. Purple wire is a substitution of the sheet/slab which I had to cut.

Sorry if this post seems heavy. Open the images in a new tab and you’ll see why.

Hope this helps someone who had the same problem/idea as I had.

03
Aug
11

Bluetooth TTL module and Murphy

I bought a new Bluetooth Serial TTL module at eBay for a project of mine, which I will probably documenting here.

It is from MDFLY, as can be seen in the pictures below. The model is RF-BT0417CB.

Since at the time I had not yet received my Arduino 2009, a friend of mine suggested I test it with his Bus Pirate v3.5(BP for short).

He had bought one but never really used it, so there were the two of us, trying to get the BP to work. It is accessed through serial through USB, so to talk to it we discovered that screen does emulate serial connections!

screen /dev/ttyUSB0 115200

(BAUD rate does not need to be 115200, could be any other probably, and device may not be /dev/ttyUSB0… check your dmesg)

Obs.: screen is a Linux program, not Windows. Deal with it or install Cygwin. ‘Ctrl+a, k, y’ kills the screen so you can close it if you need to(probably will).

After connecting, screen is black. Hit ENTER to have ‘HiZ>’ appear. Now we need to set the mode that the BP will operate, since it has many available features.

HiZ>m
1. HiZ
2. 1-WIRE
3. UART
4. I2C
5. SPI
6. 2WIRE
7. 3WIRE
8. LCD
9. DIO
x. exit(without change)

(1)>3
Set serial port speed: (bps)
1. 300
2. 1200
3. 2400
4. 4800
5. 9600
6. 19200
7. 38400
8. 57600
9. 115200
10. BRG raw value

(1)>5
Data bits and parity:
1. 8, NONE *default
2. 8, EVEN
3. 8, ODD
4. 9, NONE
(1)>
Stop bits:
1. 1 *default
2. 2
(1)>
Receive polarity:
1. Idle 1 *default
2. Idle 0
(1)>
Select output type:
1. Open drain (H=Hi-Z, L=GND)
2. Normal (H=3.3V, L=GND)
(1)>2
Ready
UART>

Explained:
UART is so the BP can comunicate through serial, 9600 is normally the default speed, most of the rest are default options, and I prefer to use the ‘Normal’ output type because my Bluetooth module is TTL.

You will also need to connect the pins of the BP to the module:

BP -> MODULE
GND->GND
+5V->+5V
MOSI->RX
MISO->TX

Now we need to set the BP to power the module:

UART>W
Power supplies ON

The modules LED should begin to blink. If it stays on steadily it means that the module is connected through Bluetooth to another device. If it is off.. recheck the previous steps.

UART>{
UART LIVE DISPLAY, } TO STOP

This sets the BP to listen to incoming serial data. If there is a stream of data that should not be, it usually means that the TX is not connected properly to the MISO pin or that the module is turned off.

To test the communication with the device, send “AT” to it with:

WRITE: “AT”
UART>
READ: 0x4F
UART>
READ: 0x4B

The AT command should return “OK”(O=0x4F, K=0x4B).
If this doesn’t happen, recheck the TX->MISO connection or the BAUD rate for the module may be wrong. Try setting the BAUD rate to other values by redoing the mode setup.
Note: the ‘b’ command for the BP sets the BAUD rate for the pc side communication, not the module side.

Now comes the ‘problem’. Somewhere I read that the command to set/see the BAUD rate of the device was “AT+BAUD1″. This actually sets the BAUD rate to 1200. Great!. The recommended setting is “AT+BAUD4″, which will set it to 9600.

Second problem. The Bluetooth module is kind of picky when sending a ‘complex’ command. “AT” should work at almost any place, “AT+…” will probably not.
As I showed above, sending “AT” will return “OK” but in hex, not as chars. When using “AT+BAUD4″ or “AT+VERSION”(check the version), the hex numbers representing the string will be shown, and not characters, which is a pain.
Also, when sending and receiving data through other devices, the data will be shown as hex, which normally isn’t very practical.

You can run the BP in Macro mode.

UART>(0)
0.Macro menu
1.Transparent bridge
2. Live monitor
3.Bridge with flow control

2 and 3 can be used on to read. When pressing a key the exit the mode. So pretty useless for normal applications.
The ‘Transparent bridge’ mode connects you ‘directly’ to the module. In this mode you receive the characters normally, not in hex, but everything you write does not appear for you AND every char you send, is sent as you type, not after you press enter. So while “A” and then “T” will work and you will receive “OK” as an answer; “A”, “T”, “+”, and then the command will not work since apparently it takes to long for each char to reach the module, so the command is discarded and you don’t even receive the “OK” for the “AT” part.

12
Jul
11

And there goes my new N1…

A friend of mine was in the US and I ordered a Nexus One through eBay which he brought back. I spent USD$270 on the N1, which is less than I spent on my XT300. (Great…)

First experience was AWESOME. Having a phone with android 2.3.4, faster and smoother experience than the XT300, no more that tiny screen, far better camera(5MP) than the XT300 3MP with flash and autofocus.

Of course, first thing I did was to unlock the bootloader through fastboot and flash the Clockwork recovery mod onto it. The mod even supports the N1′s trackball!

Then cyanogenmod 7.10-RC1-N1.

So, I was using the phone happily but had been noticing that sometimes the touchscreen hick-upped and I had to turn the screen off and on again to fix it. Nothing serious. Until it got worse, that is.

The first, say, 3-5 touches go correctly… then it all goes downhill. Using the Nexus live wallpaper, which lights up when it’s touched, I was able to track down the discrepancy of the touch. The faulty touch gets detected 2-3 cm above the lower screen end, but just height of the position is affected, the horizontal position continues to be acquired correctly.

First I thought it could be the cyanogen mod, so I switched to the 7.0.3 stable version. At first it was less frequent but then it got worse again.

Then I tried the stock, which is 2.2.1(FRG83)
The problem also got better than worsened as before.
After the OTA update to 2.3.4 nothing changed.

I’ve read that using the phone with low brightness helps somewhat.
Powering it on, I can unlock it. I go to a blank screen, and start playing with the nexus’s live wallpaper.
The third click goes to 2-3cm above the lower bar. For a time I the clicks register at the right place. Then the desktop tries to change screens, flickers.
The most annoying problem is that this happens while I try to use the back button, or select something from a menu and it simply registers my click with the wrong height.

Now I’m trying to get someone to fix this.
Since I don’t know if the problem can be fixed simply by replacing the digitizer(capacitive sensor), I won’t do it myself(digitizer could be bought at eBay and youtube shows how to replace).

I didn’t find any seemingly reliable repair shop that should be able to repair the phone.

I emailed my country’s HTC, they told to contact Google. In the htc’s international website it says that they would provide customer service. They say they are not responsible for hardware not sold in my country.Great.

The eBay seller is not able to ship it Brazil(my country, yes). I have no one that is going or coming back from the US to perhaps make the switch for me, and even if I were able to get a replacement phone from the seller, does not mean it would not present the same problem.

I was thinking of sending it back for a refund. Pity I don’t have the box anymore, just the accessories…

All in all, the thing I learned was to never buy a frigging HTC phone again. Having high hopes for the Nexus Prime. It’s not that I don’t like the phone. I find it very comfortable to hold and nice looking. The gray, which I thought would bother me, does not. The trackball is great for navigating in the Clockwork mod recovery.

UPDATE:
As it stands, I will try to send it back to the seller, with all accessories I have. He will send a new phone to a friend of mine in the US. Let’s see if this works out.

09
Jul
11

New addition: Arduino

W00t! My new and only arduino just arrived!

Ordered it from eBay(HK, cough cough) instead of buying it here in Brazil. Obvious choice because it would cost me 62.6 USD instead of the 15 I payed.

I bought the Duemilanove, discovered later I should have bought the UNO, which has the ATmega8U2 instead of the FTDI to communicate via USB. This is better because the ATmega8U2 is programmable, so you could make it act as any USB device instead of just a virtual com.

Getting started is ridiculous, in ubuntu at least. Just download the arduino software available at arduino.cc, extract and run.

Select your board in Tools, and other minor configurations, paste the LED Tutorial(also available at the official site) onto the sketch and upload. There! Your first arduino code running!(Note that the 2009 already comes with a LED connected to the pin 13, no need to connect another)

The interesting thing is, the USB-TTL used to program the arduino can be used to communicate with your code that’s running inside the arduino! When using this feature, the pins 0 and 1 (digital), which are named RX and TX respectively, are/can be used to connect a serial ttl device directly to the computer.

Why is this so nice? I bought a bluetooth TTL module which I plan to connect to the arduino and make it talk to android!

 

Further ramblings:
With the launch of the ADK(Open Accessory Development Kit for android, which is basically an arduino with various sensors) you can now connect it via usb on the android an do all sort of stuff.

With a non-official ADK arduino, you must make use of the USB-Host shield and use the new lib.

First, ADK should be able to be host OR client, depending on the power source. Don’t know if the USB-Host shield supports this and/or the android device must be able to provide power via the usb interface. I should look into it… someday.

Second, the arduino UNO allows for USB device ‘emulation’. Is the USB-Host shield really needed or could the ATmega8U2 be programmed to act as an ADK device/proxy?

 

 

So, a new hope a new turn. I should be posting stuff about the arduino and what I’m trying to do with it in the not that near future.

Some other posts are coming along slowly, when I have the opportunity to write. Must stop procrastinating!

25
Apr
11

More dumping!

Since I got a brand new refurbished not-completely-working version of my very own phone, I started hacking it again.

And dumping it.


Just to remember how the partition table looks:

dev: size erasesize name
mtd0: 00700000 00020000 “boot”
mtd1: 0b400000 00020000 “system”
mtd2: 0dea0000 00020000 “userdata”
mtd3: 00a20000 00020000 “cdrom”
mtd4: 00060000 00020000 “misc”
mtd5: 00580000 00020000 “recovery”
mtd6: 02800000 00020000 “cache”
mtd7: 00060000 00020000 “fota_bbuf”
mtd8: 00060000 00020000 “fota_usd”
mtd9: 000a0000 00020000 “fota_bua”
mtd10: 000a0000 00020000 “fota_ua”
mtd11: 00600000 00020000 “fota_up”
mtd12: 00060000 00020000 “kpanic”


The cdrom partition contains a CD image, with the files:

Autorun.inf
config.ini
MotoHelper_2.0.24_Driver_4.7.1.exe
setup.exe

and the config.ini content is:

[MC]
file=MotoHelper_2.0.24_Driver_4.7.1.exe
version= 02.00.23

[driver]
version=4.7.1


The contents of all the fota* partitions:

fota_bbuf.img:
00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |…………….|
*
00060000

fota_bua.img:
00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |…………….|
*
000a0000

fota_ua.img:
00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |…………….|
*
000a0000

fota_up.img:
00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |…………….|
*
00600000

fota_usd.img:
00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |…………….|
*
00060000


The misc partition:

00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |…………….|
*
00000800 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…………….|
*
00000c40 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |…………….|
*
00001800 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…………….|
*
00020000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |…………….|
*
00060000


kpanic partition content:

00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |…………….|
*
00060000


I dumped the system partition via cat but unyaffs complained it was not valid…

No idea why really… and the tar backup I created previously was good for shit… stuck in bootloop… perhaps this one does it… who knows..

25
Apr
11

My Phone Is Back From Repair!

As some might have noticed, I ended up bricking my phone after I tried to replace a lib with a similar one from a HTC phone, where the adreno renderer was enabled.

Why brick with something to simple? Perhaps I wouldn’t have if I knew somethings I know today, like the superoneclick tool which can give you adb root shell.

My problem was that without the graphical interface working(the new lib did not work at all), the superuser app could not grant super user for my su in adb shell.

I ended up trying to restore my system partition(tar to yaffs2) back to my device, but got stuck in bootloop. GREAT!

Frustrated, I erased everything on my phone(as in boot partition went bye bye). Thus I discovered that the bootloader resided in the boot partition. GREAT²!

Apparently it works similarly to the droids mbmloader scheme. In short, I had only the usb interface to the mbmloader(?) which said ‘MSM7225 Flash’ and I did not have/find any driver to. And so I took it to the technical assistance.

After 20 days I finally got a call that my phone was back, ready for retrieval. Managed to get there in the same day still, was promptly served at the store and got my phone back.

I turned it up, noted that it didn’t ask for my Google account. So I reset it and booted again. I turned up fine. So my problem had been fixed! Finally! The wait had not been in vain.

Upon arriving home, I started setting up my phone again to an usable state, like disabling the APN connectivity which my phone account is not activated for. To login to my Google account and configure the phone I would have to connect to my WiFi network. I configured it and… it did not connect! WHY?

I erased the connection and tried again. No success… I went to advanced settings, and noted the Mac Address: 11:22:33:44:55:66! That is NOT normal, for one, the first byte should be EVEN! 11 is not a valid first byte for a normal devices mac address. And 11:22:33 is not even Motorola’s mac address range. GREAT³!

I checked the /etc/wifi/nvram.txt file which configures the devices mac address, it looks fine…

And so it will come to pass… that I will have to go to the store againCRAP…


Details:
The XT300 came back updated to Baseband version: A306_U3_01.72.0
And version: SESLA_U3_01.72.0

AFAIK, the update is available in motorolas crappy website. Moto Helper/Motorola Software Update.

And z4root does not work anymore. Superoneclick does(tested).

I heard that the new version is faster. Would have to remove phone portal and flashback to confirm :P




The Author

Older Ramblings

Tweets

Linux User Sig

Follow

Get every new post delivered to your Inbox.