Saturday, April 21, 2012

Vim as a Blogger editor

Blogger.vim is a vim plugin for interfacing with Google's Blogger. Below I will use my workspace git repository. To use this plugin we need pretty new ruby >= 1.9.2 and gems nokogiri and net-https-wrapper. Let's install latest possible ruby for Debian, before that make sure you have latest updates:
sudo apt-get update
sudo apt-get upgrade 
sudo apt-get dist-upgrade
And ruby:
sudo apt-get install ruby1.9.3
Before we install gems , we need to resolve some dependencies:
sudo apt-get install libxml2-dev libxslt1-dev
Latest nokogiri 1.5.2 have some issues, so we need to use 1.5.0 which is stable:
sudo gem install nokogiri --version 1.5.0
And the wrapper for https:
sudo gem install net-https-wrapper
Finally also pandoc will be neded to display web pages in vim:
sudo apt-get install pandoc
Right now we are able to run vim with blogger support. First we need to configure vim, add below lines to your $HOME/.vimrc file:
let g:blogger_blogid = 'your_blogid_here'
let g:blogger_email = 'your_email_here' 
let g:blogger_pass = 'your_blogger_password_here'
Run vim and try to list your blogger posts by typing:
:e blogger:list
If list of you see all your posts than it seems that plugin works good. Finally check writing feature. Create file with some text and type:
:w blogger:create
Few things doesn't work as it should. Meybe I will find enough time to fix it. This article was created by using blogger.vim script.

Wednesday, April 18, 2012

Debugging coreboot in qemu environment - part 2


In previous post coreboot was configured and installed. Here we try to establish good debugging environment for it. To create a good emulated environment to debug, research and learn coreboot few tricks are required. First of all we need to know how to run our emulated enviroment (qemu). What I mean by that ?
  • load coreboot image (-bios option),
  • freeze CPU at startup (-S),
  • get appropriate feedback about virtual machine state (-d in_asm,cpu),
  • set up remote gdb server to run qemu step by step (-s).
So finally we get:
qemu -bios src/coreboot/build/coreboot.rom -s -S -d in_asm,cpu -nographic
We don't need graphics so it also could be disable (-nographic). Run above command and prepare debugging environment as described below.
  1. Set up gdb:
    1. load bootblock file in gdb:
      file path/to/coreboot/build/bootblock.elf
    2. use objdump to find out at what address .text, .bss and .data sections are:
      objdump -h src/coreboot/build/coreboot_ram|grep -E "text|bss|\.data"
      my output looks like that:
      0 .text         00010810  00100000  00100000  00001000  2**2
      3 .data         000004d8  001174e8  001174e8  000184e8  2**2
      4 .bss          0000080c  001179c0  001179c0  000189c0  2**3
    3. use above addresses to load symbols from coreboot_ram file in gdb:
      add-symbol-file src/coreboot/build/coreboot_ram 0x00100000 -s .data \
      0x001174e8 -s .bss 0x001179c0
  2. In another terminal or screen window
    vim /tmp/qemu.log
    (use :e to reload qemu.log file after every instruction), in this file we will get information about all registers of virtual machine
  3. target remote :1234
  4. Run next instruction (ni command in gdb) and refresh qemu.log, if you get something like:
    EAX=00000000 EBX=00000000 ECX=00000000 EDX=00000633 
    ESI=00000000 EDI=00000000 EBP=00000000 ESP=00000000
    EIP=0000fff0 EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
    ES =0000 00000000 0000ffff 00009300
    CS =f000 ffff0000 0000ffff 00009b00
    SS =0000 00000000 0000ffff 00009300 
    DS =0000 00000000 0000ffff 00009300
    FS =0000 00000000 0000ffff 00009300
    GS =0000 00000000 0000ffff 00009300
    LDT=0000 00000000 0000ffff 00008200
    TR =0000 00000000 0000ffff 00008b00
    GDT=     00000000 0000ffff
    IDT=     00000000 0000ffff
    CR0=60000010 CR2=00000000 CR3=00000000 CR4=00000000
    DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000
    DR6=ffff0ff0 DR7=00000400
    
  5. it means that your debugging enviroment was set correctly.

Thursday, April 12, 2012

Building ARM toolchain - part 2: gcc and eglibc

Unfortunately after few tries of cross compiling eglibc using different source for instructions I alway end with hard to solve issues. Luckily, in the sources of eglibc I noticed instructions for cross-compiling written long time ago by Jim Blandy(I know i should start here). Lot of thanks to him for it. Below I describe my expierence which I gained during eglibc cross cpomliation for arm-unknown-linux-gnueabi and procedure that I used. Commands below contain some constants that I used in previous works. See this post. Eglibc library and the compiler itself is built with many various parameters this post is not the place to explain their meaning, please RTFM.
  1. Checkout eglibc from svn (as alwyas I try to use a latest sources possible). Version used r17815:
    svn co http://www.eglibc.org/svn/trunk eglibc
  2. Link working ports to GNU/Linux on some machine architectures. They are not maintained in the official glibc source tree so we need to add it in this way:
    ln -s ../ports eglibc/libc/ports/
  3. Create eglibc-headers directory:
    mkdir eglib-headers; cd eglib-headers
  4. Configure eglibc and preliminary objects:
    BUILD_CC=gcc CC=arm-unknown-linux-gnueabi-gcc CXX=arm-unknown-linux-gnueabi-cpp \
    AR=arm-unknown-linux-gnueabi-ar RANLIB=arm-unknown-linux-gnueabi-ranlib \
    ../eglibc/libc/configure --prefix=/usr --with-headers=$TARGET/usr/include \
    --build=x86_64-pc-linux-gnu --host=arm-unknown-linux-gnueabi --disable-profile \
    --without-gd --without-cvs --enable-add-ons
  5. Install eglibc headers:
    make install-headers install_root=$TARGET install-bootstrap-headers=yes
  6. We need few object file to link shared libraries, which will be built and installed by hand:
    mkdir -p $TARGET/usr/lib
    make csu/subdir_lib
    cp csu/crt1.o csu/crti.o csu/crtn.o $TARGET/usr/lib
  7. To produce libgcc_s.so we need libc.so, but only need its dummy version because we'll never use it. It doesn't matter what we will point as a libc.so we use /dev/null as C file.
    arm-unknown-linux-gnueabi-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o \
    $TARGET/usr/lib/libc.so
  8. Get latest gcc sources using git repository mirror. Latest commit while writing this post was 5b9a8c3:
    cd ..
    git clone git://repo.or.cz/official-gcc.git
  9. Now, we can build gcc which can compile eglibc.
    mkdir eglibc-gcc; cd eglibc-gcc
    ../official-gcc/configure --target=arm-unknown-linux-gnueabi \
    --prefix=$TARGET/arm-x-tools --with-sysroot=$TARGET --disable-libssp \
    --disable-libgomp --disable-libmudflap --enable-languages=c \
    --with-gmp=$TARGET/arm-x-tools --with-mpfr=$TARGET/arm-x-tools \
    --with-mpc=$TARGET/arm-x-tools --disable-libquadmath --build=$MACHTYPE \
    --host=$MACHTYPE --with-local-prefix=$TARGET/arm-x-tools --disable-multilib \
    --with-float=soft --with-pkgversion="pietrushnic" --enable-threads=no \
    --enable-target-optspace --disable-nls --enable-c99 --enable-long-long
    make -j4
    make install
  10. Confugure and compile final version of eglibc.
    mkdir eglibc-final
    cd eglibc-final/
    BUILD_CC=gcc CC=arm-unknown-linux-gnueabi-gcc CXX=arm-unknown-linux-gnueabi-cpp \
    AR=arm-unknown-linux-gnueabi-ar RANLIB=arm-unknown-linux-gnueabi-ranlib \
    ../eglibc/libc/configure --prefix=/usr --with-headers=$TARGET/usr/include \
    --build=x86_64-pc-linux-gnu --host=arm-unknown-linux-gnueabi --disable-profile \
    --without-gd --without-cvs --enable-add-ons
    make
    make install install_root=$TARGET
  11. Install libelf library
    wget http://www.mr511.de/software/libelf-0.8.13.tar.gz
    tar zxvf libelf-0.8.13.tar.gz
    cd libelf-0.8.13/
    ./configure  --prefix=$TARGET/arm-x-tools --disable-shared --enable-static
    make;make install
  12. Prepare final version of gcc.
    cd ..
    mkdir final-gcc
    cd final-gcc
    ../official-gcc/configure --target=arm-unknown-linux-gnueabi \
    --prefix=$TARGET/arm-x-tools --with-sysroot=$TARGET --disable-libssp \
    --disable-libgomp --disable-libmudflap --enable-languages=c,c++ 
    --with-gmp=$TARGET/arm-x-tools --with-mpfr=$TARGET/arm-x-tools 
    --with-mpc=$TARGET/arm-x-tools --disable-libquadmath --build=$MACHTYPE \
    --host=$MACHTYPE --with-local-prefix=$TARGET/arm-x-tools --disable-multilib \
    --with-float=soft --with-pkgversion="pietrushnic" --enable-threads=posix \
    --enable-target-optspace --disable-nls --enable-c99 --enable-long-long \
    --enable-__cxa_atexit --enable-symvers=gnu --with-libelf=$TARGET/arm-x-tools \
    --enable-lto
    make
    make install
  13. Few libraries should be copied manualy
    cp -d $TARGET/arm-x-tools/arm-unknown-linux-gnueabi/lib/libgcc_s.so* $TARGET/lib
    cp -d $TARGET/arm-x-tools/arm-unknown-linux-gnueabi/lib/libstdc++.so* $TARGET/lib
  14. Compile and install chrpath - this is useful tool to remove the rpath or runpath setting from binary.
    cd ..
    sudo apt-get install libc6-i386 gcc-multilib
    apt-get source chrpath
    cd chrpath-0.13/
    CFLAGS=-m32 ./configure --prefix=$TARGET/arm-x-tools \
    --program-prefix=arm-unknown-linux-gnueabi-
    make
    make install
  15. Strip debug symbols
    strip --strip-debug $TARGET/arm-x-tools/lib/* \
    $TARGET/arm-x-tools/arm-unknown-linux-gnueabi/lib/* $TARGET/arm-x-tools/libexec/*
    
    strip --strip-unneeded $TARGET/arm-x-tools/bin/* \
    $TARGET/arm-x-tools/arm-unknown-linux-gnueabi/bin/*
    arm-unknown-linux-gnueabi-strip --strip-debug $TARGET/lib/* $TARGET/usr/lib/*
  16. At the end simple test to find out if basic functionality works:
    $ cat > hello.c <<EOF
    > #include <stdio.h>
    > int
    > main (int argc, char **argv)
    > {
    >   puts ("Hello, world!");
    >   return 0;
    > }
    > EOF
    
    Try to cross compile C file:
    $TARGET/arm-x-tools/bin/arm-unknown-linux-gnueabi-gcc -Wall hello.c -o hello
    
    $ cat > c++-hello.cc <<EOF
    > #include <iostream>
    > int
    > main (int argc, char **argv)
    > {
    >   std::cout << "Hello, C++ world!" << std::endl;
    >   return 0;
    > }
    > EOF
    
    Try to cross compile C++ file:
    $TARGET/arm-x-tools/bin/arm-unknown-linux-gnueabi-g++ -Wall c++-hello.cc -o \
    c++-hello
    
    Displays the information contained in the ELF header and in the file's segment headers:
    $TARGET/arm-x-tools/bin/arm-unknown-linux-gnueabi-readelf -hl hello
    $TARGET/arm-x-tools/bin/arm-unknown-linux-gnueabi-readelf -hl c++-hello
    
    Result should look like that:
    ELF Header:
      Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
      Class:                             ELF32
      Data:                              2's complement, little endian
      Version:                           1 (current)
      OS/ABI:                            UNIX - System V
      ABI Version:                       0
      Type:                              EXEC (Executable file)
      Machine:                           ARM
      (...)
      Flags:                             0x5000002, has entry point, Version5 EABI
      (...)
    Program Headers:
      (...)
      INTERP         0x000134 0x00008134 0x00008134 0x00013 0x00013 R   0x1
          [Requesting program interpreter: /lib/ld-linux.so.3]
      LOAD           0x000000 0x00008000 0x00008000 0x004b8 0x004b8 R E 0x8000
      (...)
    
    $TARGET/arm-x-tools/bin/arm-unknown-linux-gnueabi-readelf -d \
    $TARGET/lib/libgcc_s.so.1
    Result should look like that:
      (...)
      Tag        Type                         Name/Value
     0x00000001 (NEEDED)                     Shared library: [libc.so.6]
     0x0000000e (SONAME)                     Library soname: [libgcc_s.so.1]
     0x0000000c (INIT)                       0xcc2c
      (...)
    
I hope you find above manual useful. If you need more detailed descriptions it can be found here. Also don't bother to ask me by comment below.

Friday, April 6, 2012

How to download videos from videos.linux.com

Therefore, I'm leaving for the Easter holidays I wanted to download some lecture on embedded systems, which was presented at the 2012 Embedded Linux Conference. Although I regret I found that I could not find as good quality copy in the network as on the Linux Foundation page. It is unfortunate that linux.com site does not have the possibility of direct downloading video files. But there is a workaround. Follow below tutorial:

  1. Go to page with video. For example:  http://video.linux.com/videos/to-provide-a-long-term-stable-linux-for-industry
  2. Click play on the video and if you using Chrome browser right click on player window and inspect this element. Result should look like that: 


  3. Expand div tag marked in red on screenshot above. If video was start you should see video tag which contain two links to video files mp4 and webm. Screen shot below shows hot it should look like:


These links are only temporary, so if you want to use them do it as soon as possible. The sad part of all is that the organization intended to promote one of the most libertarian solutions in software history does not provide materials for download.