tech_log: November 2009

Wednesday, November 4, 2009

sh4 Linux cross-toolchain (by Code Sourcery)

1) Pre-build sh-linux-gcc toolchain :
Download Sourcery G++ Lite 4.4-45 for SuperH GNU/Linux from :
http://www.codesourcery.com/sgpp/lite/superh/portal/release1041
choose : IA32 GNU/Linux Installer

2) Install toolchain to Linux host :
$ /bin/sh renesas-4.4-45-sh-linux-gnu.bin
Will lounch graphical installer which will install toolchain to :
~/CodeSourcery/

3) Compile hello.c :
$ ~/CodeSourcery/Sourcery_G++_Lite/bin/sh-linux-gnu-gcc -o hello hello.c

This will already search libraries to pre-destined paths :

drasko@Marx:~/sh4_projects$ ~/CodeSourcery/Sourcery_G++_Lite/bin/sh-linux-gnu-gcc -v -o hello hello.c
Using built-in specs.
Target: sh-linux-gnu
Configured with: /scratch/ams/4.4-sh-linux-gnu-lite/src/gcc-4.4/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=sh-linux-gnu --enable-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --with-cpu=sh4a --with-multilib-list=sh4al,!mb/m4al --with-endian=little,big --enable-extra-sgxxlite-multilibs --enable-incomplete-targets --with-gnu-as --with-gnu-ld --with-specs='%{O2:%{!fno-remove-local-statics: -fremove-local-statics}} %{O*:%{O|O0|O1|O2|Os:;:%{!fno-remove-local-statics: -fremove-local-statics}}}' --enable-languages=c,c++ --enable-shared --disable-lto --enable-symvers=gnu --enable-__cxa_atexit --with-pkgversion='Sourcery G++ Lite 4.4-45' --with-bugurl=https://support.codesourcery.com/GNUToolchain/ --disable-nls --prefix=/opt/codesourcery --with-sysroot=/opt/codesourcery/sh-linux-gnu/libc --with-build-sysroot=/scratch/ams/4.4-sh-linux-gnu-lite/install/sh-linux-gnu/libc --with-gmp=/scratch/ams/4.4-sh-linux-gnu-lite/obj/host-libs-4.4-45-sh-linux-gnu-i686-pc-linux-gnu/usr --with-mpfr=/scratch/ams/4.4-sh-linux-gnu-lite/obj/host-libs-4.4-45-sh-linux-gnu-i686-pc-linux-gnu/usr --with-ppl=/scratch/ams/4.4-sh-linux-gnu-lite/obj/host-libs-4.4-45-sh-linux-gnu-i686-pc-linux-gnu/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-cloog=/scratch/ams/4.4-sh-linux-gnu-lite/obj/host-libs-4.4-45-sh-linux-gnu-i686-pc-linux-gnu/usr --disable-libgomp --enable-poison-system-directories --with-build-time-tools=/scratch/ams/4.4-sh-linux-gnu-lite/install/sh-linux-gnu/bin --with-build-time-tools=/scratch/ams/4.4-sh-linux-gnu-lite/install/sh-linux-gnu/bin
Thread model: posix
gcc version 4.4.1 (Sourcery G++ Lite 4.4-45)
COLLECT_GCC_OPTIONS='-v' '-o' 'hello'
 /home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../libexec/gcc/sh-linux-gnu/4.4.1/cc1 -quiet -v -iprefix /home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/sh-linux-gnu/4.4.1/ -isysroot /home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../sh-linux-gnu/libc hello.c -quiet -dumpbase hello.c -auxbase hello -version -o /tmp/ccTmWWcy.s
ignoring nonexistent directory "/home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../sh-linux-gnu/libc/usr/local/include"
ignoring duplicate directory "/home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/../../lib/gcc/sh-linux-gnu/4.4.1/include"
ignoring duplicate directory "/home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/../../lib/gcc/sh-linux-gnu/4.4.1/include-fixed"
ignoring duplicate directory "/home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/../../lib/gcc/sh-linux-gnu/4.4.1/../../../../sh-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/sh-linux-gnu/4.4.1/include
 /home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/sh-linux-gnu/4.4.1/include-fixed
 /home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/sh-linux-gnu/4.4.1/../../../../sh-linux-gnu/include
 /home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../sh-linux-gnu/libc/usr/include
End of search list.
GNU C (Sourcery G++ Lite 4.4-45) version 4.4.1 (sh-linux-gnu)
    compiled by GNU C version 4.3.2, GMP version 4.3.1, MPFR version 2.4.1-p5.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 6d45046fc0139f32061c226770713dae
COLLECT_GCC_OPTIONS='-v' '-o' 'hello'
 /home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/sh-linux-gnu/4.4.1/../../../../sh-linux-gnu/bin/as -v -little -o /tmp/ccGtcr9X.o /tmp/ccTmWWcy.s
GNU assembler version 2.19.51 (sh-linux-gnu) using BFD version (Sourcery G++ Lite 4.4-45) 2.19.51.20090709
COMPILER_PATH=/home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../libexec/gcc/sh-linux-gnu/4.4.1/:/home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../libexec/gcc/:/home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/sh-linux-gnu/4.4.1/../../../../sh-linux-gnu/bin/
LIBRARY_PATH=/home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/sh-linux-gnu/4.4.1/:/home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/:/home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/sh-linux-gnu/4.4.1/../../../../sh-linux-gnu/lib/:/home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../sh-linux-gnu/libc/lib/:/home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../sh-linux-gnu/libc/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'hello'
 /home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../libexec/gcc/sh-linux-gnu/4.4.1/collect2 --sysroot=/home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../sh-linux-gnu/libc --eh-frame-hdr -m shlelf_linux -dynamic-linker /lib/ld-linux.so.2 -o hello /home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../sh-linux-gnu/libc/usr/lib/crt1.o /home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../sh-linux-gnu/libc/usr/lib/crti.o /home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/sh-linux-gnu/4.4.1/crtbegin.o -L/home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/sh-linux-gnu/4.4.1 -L/home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc -L/home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/sh-linux-gnu/4.4.1/../../../../sh-linux-gnu/lib -L/home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../sh-linux-gnu/libc/lib -L/home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../sh-linux-gnu/libc/usr/lib /tmp/ccGtcr9X.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/sh-linux-gnu/4.4.1/crtend.o /home/drasko/CodeSourcery/Sourcery_G++_Lite/bin/../sh-linux-gnu/libc/usr/lib/crtn.o
drasko@Marx:~/sh4_projects$

4) Lounch quemu test :
drasko@Marx:~/sh4_projects$ qemu-sh4 -L ~/CodeSourcery/Sourcery_G++_Lite/sh-linux-gnu/libc/ ./hello
Hello from SH4
drasko@Marx:~/sh4_projects$

Tuesday, November 3, 2009

u-boot in qemu

1) make versatile_config
2) Start u-boot.bin in qemu :
$ qemu-system-arm -M versatileab -nographic -m 256 -kernel u-boot.bin

3) Debugging:
$ qemu-system-arm -M versatileab -nographic -m 256 -kernel u-boot.bin -s -S
$ drasko@Marx:~/qemu-arm/u-boot-2009.03$ arm-linux-gnu-gdb u-boot
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i486-linux-gnu --target=arm-linux-gnu"...
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
[New Thread 1]
0x00000000 in ?? ()
(gdb)



Explanation :

Debugging with the moxie qemu simulator

I’ve finally cracked the gdb+qemu puzzle, so now we can debug code running on the qemu moxie simulator!

The last little gotcha was that the simulated $pc wasn’t being updated after single-stepping. This will get you nowhere fast! But it’s all fixed now, and here’s how it works…

$ qemu-system-moxie -s -S -kernel hello.x

This tells qemu to load our hello world program, hello.x. The “-s” option tells it to wait for a connection from GDB on port 1234. The -S option tells it to freeze on startup, and wait for a “continue” command from the debugger.

Now, in a different terminal, fire up moxie-elf-gdb on hello.x and connect to qemu like so:

(gdb) target remote localhost:1234

GDB and qemu should be talking now, and the debugger will report that the sim is waiting on __start, the entry point to our hello.x ELF file. Put a breakpoint on main, and hit ‘c’ to continue. You should be debugging as usual now. I normally run moxie-elf-gdb within emacs in order to get a nice UI, but invoking it from ddd or Eclipse should work just as well.