Saturday, March 18, 2017

vim print

:ha print the whole document to default printer
To print the lines starting from line m to line n:
:m,n ha > or :m,n hardcopy >
Without the > part, the default printer will be used.

Tuesday, August 30, 2016

buildroot qemu ARM

build embedded system for qemu and ARM with buildroot (buildroot-2016.05)

use qemu_arm_versatile_defconfig config file as base config
$make qemu_arm_versatile_defconfig

changed nothing

-M versatilepb 
-kernel output/images/zImage 
-dtb output/images/versatile-pb.dtb 
-drive file=output/images/rootfs.ext2,if=scsi,format=raw 
-append "root=/dev/sda console=ttyAMA0,115200" 
-net nic,model=rtl8139 -net user

can be replace with:

-M Set the emulated machine type
-dtb device tree image
-drive block device option
-append kernel command line /-drive/
-nographic disable graphical output and redirect serial I/Os to console

execution command taken from:

Wednesday, July 22, 2015

nohup vs &


Saturday, May 16, 2015

LKM syscall links

Saturday, May 2, 2015

copy file with ssh without scp

text file

cat /tmp/aaa | ssh user@host "cat - > aaa"
ssh user@host cat < /tmp/aaa ">" aaaa

from remote to local
ssh user@host cat > /tmp/bbb "<" bbb

uuencode - encode a binary file

 -m     Encode  the  output using the MIME Base64

Saturday, April 18, 2015

GDB cross compiler

  • compile gdb static for mips /el

  • create build and source folders
  • download gdb 7.9 and termcap 1.3.1 to source folder
  • create cross compiler with buildroot or crosstool-ng (i used buildroot)

under build folder create sub folder 
(host)$mkdir -p build/termcap/mipsel
(host)$export CC=<path>/buildroot/output/mipsel/host/usr/bin/mipsel-linux-gcc
(host)$./configure --host=mipsel-linux --prefix='/<path>/build/termcap/mipsel/'
(host)$make install

gdb 7.9
(host)set PATH=/to/gcc/folder
(host)$cd to gdb-7.9 folder #don't run process from gdb subfolder see README
(host)$export CC=<path>/buildroot/output/mipsel/host/usr/bin/mipsel-linux-gcc
#set ld flags: static and point to termcap lib folder
(host)$export LDFLAGS="-static -L/<path>/build/termcap/mipsel/lib"
#set include to termcap include folder
(host)$export CFLAGS="-g -O2 -I/<path>/build/termcap/mipsel/include"
(host)$./configure --host=mipsel-linux --prefix='/<path>/build/gdb_mipsel' --disable-werror
(host)$make install

host: compiler prefix


Friday, April 17, 2015

first mips assembly


  • compile mips assembly with gcc
  • run in emulation

  • gcc: aboriginal cross compiler , mipsel
  • emulator: qemu-user-static

sudo apt-get install qemu-user-static

vim exit.S
#include <sys/regdef.h>
#include <asm/unistd.h>

.global main
        .set noreorder
        .cpload t9
        .set reorder
        li a0, 99
        li v0, __NR_exit

note: file ext must be capital S

include cross gcc in path or point run directly
$mipsel-gcc -o exit exit.S

copy qemu to chroot folder

$cp $(which qemu-mipsel-static) .
$sudo chroot . ./qemu-mipsel-static ./exit

/lib/ No such file or directory

we get error because we compile dynamicly and the lib folder not include in chroot folder

we need to bind the lib folder for outside the chroot to chroot location

$mkdir lib
$sudo mount --bind <path/to/cross_compile/lib> lib

$sudo chroot . ./qemu-mipsel-static ./exit


echo $?
99 # the return value for exit syscall