August 31, 2010

mini2440 flash upgrade

How to upgrade mini2440/micro2440 kernel image after the systems boots to Linux:

killall processes
mount -o remount,ro /
cd /dev/shm
flash_erase /dev/mtd1 0 16
nandwrite -a -p /dev/mtd1 /zImage_new

Bootloader

There are two "official" bootloaders, supervivi-128M and viv. supervivi is a little bit less than 256K (0x40000), while vivi is only 3-4K. We have supervivi in NOR flash, and viv in NAND flash.

0x0,00000 - 0x0,40000    bootloader
0x0,48000 - 0x0,60000    bootloader parameters (linux_cmd_line           starts at 0x48000 and ends with the first 0x0)
0x0,60000 - 0x2,60000    2M of kernel space
0x2,60000 - 0x80,00000   close to 126M application image


Tools to read/write/erase flash after system is booted (all in mtd-utils project):

        - flash_erase
        - nandwrite
        - nanddump
        - mtd_debug

echo -n -e "VIVICMDLnoinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0\0000" > /tmp/cmdline
/cmdc/flash_erase /dev/mtd0 0x40000 1
/cmdc/nandwrite -p /dev/mtd0 -s 0x48000 /tmp/cmdline


You can probably use the same nandwrite to update the bootloader itself. I haven't tried that yet.

Export MySQL database to CSV file

SELECT * INTO OUTFILE '/tmp/result.text'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM test_table;

And the results are sent to /tmp/result.text in CSV format.

August 27, 2010

Thunderbird turn off signature in reply emails

This is how to turn off signature in replies in Thunderbird:

1. open about:config by go to menu tools->options->advanced->general->Config Editor

2. type "sig" and look for sig_on_reply as shown below.
3. double click on it to make it false.
4. close the window. the value is saved automatically.
done.

August 17, 2010

Remove blank/empty lines from a file

There are many ways to do it:

  • grep '.' file > newfile
  • awk '/./' file > newfile
But, please make sure your file is in "Unix" format, not "Dos" format (this concerns the line ending character). If it is in "Dos" format, none of the script works. You can convert it using vim and do "set fileformat=unix" then save, or use dos2unix command.

August 14, 2010

Vim embedded command in the file edited

This is called "modeline" in vim. you can file help on that.

http://vim.wikia.com/wiki/Modeline_magic

First, make sure modeline is enabled. Then

The following examples show some alternatives that could be in a C file:

// vim: noai:ts=4:sw=4
-or-
/* vim: noai:ts=4:sw=4
*/
-or-
/* vim: set noai ts=4 sw=4: */
-or-
/* vim: set fdm=expr fde=getline(v\:lnum)=~'{'?'>1'\:'1': */

With "set", the modeline ends at the first colon not following a backslash. Without "set", no text can follow the options, so for example, the following is invalid:

Error E518: Unknown option: */

/* vim: noai:ts=4:sw=4 */

August 10, 2010

Disable ssh server reverse dns lookup

Add/Edit the following lines to your /etc/ssh/sshd_config and restart ssh service

UseDNS no
GSSAPIAuthentication no

To enable remote port forwarding for all the computers on your subnet, add this:

GatewayPorts yes

August 5, 2010

Open source Windows TCP Serial port server

Download the Serproxy zip source code , and compile it using the following Makefile using mingw-32.

#
# File:Windows serproxy makefile
#
# (C)1999 Stefano Busti
#

VERSION = `cat VERSION`

SRCS = \
main.c sio.c sock.c thread.c vlist.c cfglib.c config.c string.c \
pipe.c error.c

OBJS = \
main.o sio.o sock.o thread.o vlist.o cfglib.o config.o string.o \
pipe.c error.c

CC = gcc

ifdef DEBUG
CFLAGS = -Wall -g -D__UNIX__ -DDEBUG
else
CFLAGS = -Wall -O2 -fomit-frame-pointer -D__WIN32__ -DWINTHREADS -DSOCK_WIN -DSIO_WIN32
endif

ifdef USE_EF
#LIBS= -lpthread -lefence
else
#LIBS= -lpthread
endif
LIBS=-lws2_32

# Build the program

serproxy: $(SRCS) $(OBJS)
$(CC) $(CFLAGS) -o serproxy $(OBJS) $(LDFLAGS) $(LIBS)

install: serproxy
cp -f serproxy /usr/local/bin

clean:
rm -f *.o *~

realclean:
rm -f *.o *~ serproxy *.gz *.zip

dep:
makedepend -Y -- $(CFLAGS) -- $(SRCS) 2&>/dev/null

# DO NOT DELETE

main.o: sio.h sock.h pipe.h thread.h vlist.h cfglib.h config.h error.h
sio.o: sio.h
sock.o: sock.h
thread.o: thread.h
vlist.o: vlist.h
cfglib.o: cfglib.h
config.o: config.h cfglib.h string.h
string.o: string.h
pipe.o: pipe.h sio.h sock.h thread.h
error.o: error.h

Cross Compile PHP 5.3.3 to ARM

Updated on 2012/05/08 for Compiling PHP 5.4.2  enabling FPM (fastcgi)

1. ./configure --host=arm-linux --without-pear --disable-simplexml --disable-mbregex --enable-sockets --enable-pdo --with-pdo-sqlite --with-sqlite3 --disable-all

2. vi Makefile, search for "-lcrypt", add "-ldl" to the same line.

3. make -j 12

4. php-cgi is in sapi/cgi.

5. use arm-linux-strip php-cgi to strip out the symbols

Done.

-- To compile PHP 5.4.2 with FPM enabled--


1. First edit the "configure" file to remove checking of ptrace and proc mem file (both should be set to yes, broken_ptrace set to no). If you don't need FPM, no change to configure script is necessary.

My new version of this section looks like this:


  have_broken_ptrace=no
  have_ptrace=yes
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }


rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext


    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ptrace works" >&5
$as_echo_n "checking whether ptrace works... " >&6; }


      { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }


rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
  conftest.$ac_objext conftest.beam conftest.$ac_ext




  if test "$have_ptrace" = "yes"; then


$as_echo "#define HAVE_PTRACE 1" >>confdefs.h


  fi


...



    proc_mem_file="mem"

  if test -n "$proc_mem_file" ; then
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for proc mem file" >&5
$as_echo_n "checking for proc mem file... " >&6; }

    if test "$cross_compiling" = no; then :
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: $proc_mem_file" >&5
$as_echo "$proc_mem_file" >&6; }

rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
  conftest.$ac_objext conftest.beam conftest.$ac_ext
fi

  fi

2. CC=arm-none-linux-gnueabi-gcc ./configure --host=arm-linux --without-pear --disable-simplexml --disable-mbregex --enable-sockets --enable-pdo --with-pdo-sqlite --with-sqlite3 --enable-fpm --disable-all

3. make -j 12
4. php-fpm is at sapi/cgi
5. use arm-linux-strip php-fpm to strip out the symbols

Done.



August 1, 2010

Convert FLV to 3GP

ffmpeg1.exe -i %1 -s 352x288 -acodec libfaac %1.3gp