Saturday, April 18, 2015

GDB cross compiler

objective
  • compile gdb static for mips /el



pre
  • 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)



termcap
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
(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
(host)$make install


Note
host: compiler prefix


reference
http://tigertop.blogspot.co.il/2011/03/building-gdb-72-for-arm-architecture-on.html




Friday, April 17, 2015

first mips assembly

LAB

objective
  • compile mips assembly with gcc
  • run in emulation


setup
  • 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>

.data
.text
.global main
main:
        .set noreorder
        .cpload t9
        .set reorder
        li a0, 99
        li v0, __NR_exit
        syscall


note: file ext must be capital S

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

run
copy qemu to chroot folder

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


/lib/ld-uClibc.so.0: 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

checking

echo $?
99 # the return value for exit syscall

Thursday, April 9, 2015

tcpdump

https://danielmiessler.com/study/tcpdump/