Tag Archive : tools

/ tools

Installing QEMU from Source

December 11, 2015 | Article | 1 Comment

Edit: I had update the article to build from latest package and testing.

You might notice that I had written an article before about building QEMU from source. That one is QEMU KVM (Kernel Virtual Machine).  As per version version 1.3 QEMU-KVM is merged to upstream QEMU project therefore the QEMU-KVM is no longer maintained. It’s been done long time ago, actually.

QEMU is a generic and open source machine emulator and virtualizer.

When used as a machine emulator, QEMU can run OSes and programs made for one machine (e.g. an ARM board) on a different machine. By using dynamic translation, it achieves very good performance.

In this article we will discuss about installing QEMU and use following requirement:

  1. Slackware64 14.0, although any version is OK
  2. latest qemu source code

There are two options for us: building the stable release or building the development code.

Obtain the Source Code

Between the stable release source code and development code, which one is suitable for us?If you want to download the latest stable release, you can obtain it from qemu official site here.

At the time of writing this article, the latest stable version is 2.5.0 (per March 20th 2016). You can download it by direct link here. http://wiki.qemu-project.org/download/qemu-2.5.0.tar.bz2

Once you have done downloading, uncompress it with:

mv qemu-2.5.0.tar.bz2 /usr/src
tar -jxvf qemu-2.5.0.tar.bz2
cd qemu-2.5.0

If you want to download the development code. You can clone the git repository by:

cd /usr/src
git clone git://git.qemu-project.org/qemu.git
cd qemu

For any option we choose, we should have qemu source code now.

Compilation

At this point we are inside the source directory. Qemu support many features. We can list the feature by

./configure --help

For now, we just want a working Qemu with debug enable and install it to /usr. First, create a directory build. This directory will be used for all building process we do.

mkdir build
cd build

Next we do usual chant:

../configure --enable-debug  --prefix=/usr --enable-modules
make -j4

If you want to know my build, here it is:

../configure --enable-debug --prefix=/usr --enable-modules --enable-libusb \
--enable-usb-redir --enable-spice --enable-smartcard

If you like, you can go to next section for testing. If not, you can install QEMU by

make install

Congratulation, you had installed Qemu.

Testing

Testing BIOS

To test if default settings works.

x86_64-softmmu/qemu-system-x86_64 -L pc-bios

Testing KVM

To test if KVM is working

x86_64-softmmu/qemu-system-x86_64 -cpu host --enable-kvm -L pc-bios

To test with Linux image

wget http://wiki.qemu.org/download/linux-0.2.img.bz2
bunzip2 linux-0.2.img.bz2
x86_64-softmmu/qemu-system-x86_64 -cpu host --enable-kvm -display gtk linux-0.2.img

Building GCC MinGW Toolchain Cross Compiler

December 11, 2015 | Article | No Comments

Windows, up until today, is still popular Operating System and have large market. This Microsoft’s product is designed for end-user and reducing complexity of Operating System. Even when some other OS such as Linux and Mac OS starts invading, this Operating System is still major and fanatically used by some people in the world.

In this article we will about how to build GCC Win32 and Win64 Toolchain for Win32 and Win64 architecture, which is a cross compiler to build Win32 and Win64 program.

Requirement set for this article:

    1. GCC (Native platform)
    2. Binutils (Native platform)
    3. Bison
    4. Flex
    5. gperf

CoreutilsMake (>= 3.8.1)

  1. SVN & CVS client

Also the test is done on Slackware64 current, though it is optional. You can use other Linux distribution which suit you.

While the previous list is requirement on your host system (your system which will build the cross compiler), we have another list. Some of the component mentioned below will be taken out from their respective repository.

  1. MinGW-w64 (SVN repository)
  2. GCC 4.9.2
  3. Binutils 2.24
  4. GDB 7.8.1
  5. GMP 6.0.0
  6. MPFR 3.1.2
  7. MPC 1.0.2

The Target

There are two architecture: Win32 and Win64. You are free to choose what MinGW system you will build. However, in this article, we will build MinGW Cross Compiler for Windows 64-bit. If you read other cross compiler article, we need a target alias (or simply target) which is the target of the toolchain.

Preparation

We will need some disk space (~2GB should be enough). We also need root access to install it on “system-wide”.

We will create a working directory. We will refer it as $MINGWGCC, so $MINGWGCC/src should really be something like ~/MINGWGCC/src (the ~ means your home directory). So go ahead and create following directory structure:

# set aliases
export MINGWGCC=~/
export PREFIX=/usr/local
export BUILD=$(gcc -dumpmachine)
export TARGET=x86_64-w64-mingw32

export BINUTILS_BUILD=${MINGWGCC}/build/binutils-build
export GCC_BUILD=${MINGWGCC}/build/gcc-build
export GDB_BUILD=${MINGWGCC}/build/gdb-build
export MINGW_BUILD=${MINGWGCC}/build/mingw-build
export MINGW_H_BUILD=${MINGWGCC}/build/mingw-h-build

export BINUTILS_SRC=${MINGWGCC}/src/binutils-2.24
export GCC_SRC=${MINGWGCC}/src/gcc-4.9.2
export GDB_SRC=${MINGWGCC}/src/gdb-7.8.1
export MINGW_SRC=${MINGWGCC}/src/mingw/
export MINGW_HEADERS=${MINGW_SRC}/mingw-w64-headers

# make base dir, original archives dir (orig), source code dir (src), 
# and working / building dir (build) 
mkdir ${MINGWGCC}{,/{orig,src,build}}

# Make build directory for each component
mkdir ${MINGWGCC}/build/{binutils,gcc,gdb,mingw{,-h}}-build

Acquiring the Materials

A cross compiler for Win32 and Win64 are provided by MinGW-w64 project. Download latest packages of GCC, GDB, binutils, and MinGW-w64 source code. You can download it using wget or alternatively download via browser and move it to $MINGWGCC/orig.

cd ${MINGWGCC}/orig

wget ftp://ftp.gnu.org/pub/gnu/gcc/gcc-4.9.2/gcc-4.9.2.tar.bz2
wget ftp://ftp.gnu.org/pub/gnu/gdb/gdb-7.8.1.tar.xz
wget ftp://ftp.gnu.org/gnu/binutils/binutils-2.24.tar.bz2

wget ftp://ftp.gnu.org/pub/gnu/gmp/gmp-6.0.0a.tar.xz
wget ftp://ftp.gnu.org/pub/gnu/mpc/mpc-1.0.2.tar.gz
wget ftp://ftp.gnu.org/pub/gnu/mpfr/mpfr-3.1.2.tar.gz

Then, extract them to src directory.

cd ${MINGWGCC}/src

tar -jxf ${MINGWGCC}/orig/gcc-4.9.2.tar.bz2
tar -Jxf ${MINGWGCC}/orig/gdb-7.8.1.tar.xz
tar -jxf ${MINGWGCC}/orig/binutils-2.24.tar.bz2

Next, the MinGW and GCC codes.

cd ${MINGWGCC}/src
svn co 'https://svn.code.sf.net/p/mingw-w64/code/trunk' mingw

Next we need to download some prerequisites, especially GMP (GNU Multiple Precision), MPC (Multiple-Precision Complex), and MPFR (Multiple-Precision Floating Point Reliably) which is used for computation. The prerequisites can be downloaded by invoking following command:

The MPFR, GMP, and MPC is not the latest version, but at least we can build GCC. Suppose your working directory at /home/xathrya/ARMGCC, to obtain MPDR, GMP, and MPC invoke following command:

cd ${GCC_SRC}
./contrib/download_prerequisites

However, the version of GMP, MPC, and MPFR is not the latest version. We can switch to the latest version by download the latest version and create symbolic link to it.

cd ${GCC_SRC}

rm {gmp,mpc,mpfr}

tar -Jxf ${MINGWGCC}/orig/gmp-6.0.0a.tar.xz
tar -zxf ${MINGWGCC}/orig/mpc-1.0.2.tar.gz
tar -zxf ${MINGWGCC}/orig/mpfr-3.1.2.tar.gz

ln -s gmp-6.0.0 gmp
ln -s mpc-1.0.2 mpc
ln -s mpfr-3.1.2 mpfr

Building the Toolchains

Building stage is pretty simple. Honestly speaking, the tricky part is about how GCC and built concept and ordering them in correct order.

Binutils

First, built binutils. This will provide lots of useful tools in building MinGW libraries and binaries (like objdump, ld, ranlib, etc). Invoke following commands:

cd ${BINUTILS_BUILD}
${BINUTILS_SRC}/configure \
   --target=${TARGET} \
   --enable-targets=x86_64-w64-mingw32,i686-w64-mingw32 \
   --prefix=${PREFIX} \
   --disable-nls
make -j4 all
make install
make clean

MinGW Headers

MinGW headers is set of headers used to build MinGW application. It is different beast with Linux GCC headers, although we use the same vendor compiler.

cd ${MINGW_H_BUILD}
${MINGW_HEADERS}/configure \
    --build=${BUILD} \
    --host=${TARGET} \
    --prefix=${PREFIX}/${TARGET}
make install

For v3 and later trunk, we have to append ${TARGET} to our prefix. If not, your native GCC will be contaminated. Please note it.

This will install MinGW headers into ${PREFIX}/${TARGET}/include/ or in our case it would be /usr/local/x86_64-w64-mingw32/include/.

MinGW Directories and Symlinks

We should end up with a ${PREFIX}/${TARGET}/ directory. Manually create lib/ directory and create symbolic link as lib64/

GCC also requires the ${TARGET} directory to be mirrored as a directory ‘mingw’ in the same root (it’s ${PREFIX} directory). Therefore, we need to make a soft link there.

n -s ${PREFIX}/${TARGET} ${PREFIX}/mingw
mkdir -p ${PREFIX}/${TARGET}/lib{,32}
ln -s ${PREFIX}/${TARGET}/lib ${PREFIX}/${TARGET}/lib64

GCC Core

Next we will build the GCC. But please note that we are only intereset on C and C++ so we will ignore other language. To built GCC, do this:

cd ${GCC_BUILD}
${GCC_SRC}/configure \
   --build=${BUILD} \
   --target=${TARGET} \
   --enable-targets=all \
   --prefix=${PREFIX} \
   --enable-interwork \
   --enable-multilib \
   --enable-languages="c,c++" \
   --enable-shared \
   --enable-fully-dynamic-string \
   --with-system-zlib \
   --disable-nls
make -j4 all-gcc install-gcc
make clean

C RunTime (CRT) Library

 Next we will build the C runtime library or the MinGW itself. In the short: building libs required. The static and dynamic lib built with GCC core we have built.

cd ${MINGW_BUILD}
${MINGW_SRC}/configure \
    --host=${TARGET} \
    --prefix=${PREFIX}/${TARGET} \
    --enable-multilib \
    --enable-shared \
    --enable-lib32
make -j4 all
make install

For v3 and later trunk, we have to append ${TARGET} to our prefix. If not, your native GCC will be contaminated. Please note it.

Make sure you have following directories in the ${PREFIX}:

# ${PREFIX} => /usr/local
# ${TARGET} => x86_64-w64-mingw32

${PREFIX}/${TARGET}
${PREFIX}/${TARGET}/include
${PREFIX}/${TARGET}/lib
${PREFIX}/${TARGET}/lib32
${PREFIX}/${TARGET}/lib64 [link to lib]
${PREFIX}/mingw [link to ${TARGET}]
${PREFIX}/mingw/include
${PREFIX}/mingw/lib
${PREFIX}/mingw/lib32
${PREFIX}/mingw/lib64 [link to lib]

GCC (again)

Now that we have our runtime libraries, go back and ginish the GCC build:

cd ${GCC_BUILD}
make -j4
make install

GDB

Optionally you can build GDB. To do so, invoke following:

cd ${GDB_BUILD}
${GDB_SRC}/configure \
   --target=${TARGET} \
   --prefix=${PREFIX} \
   --enable-interwork \
   --enable-multilib
make -j4 all 
make install

And that’s it. You should have them now.

Testing

The toolchain can be tested with the minimal code here, save as demo.c:

int main()
{
   return 0;
}

void exit(int code)
{
   while(1);
}

Invoke following command to compile:

x86_64-w64-mingw32-gcc demo.c -o demo.exe

In this article we will about how to build GCC ARM Toolchain, which is a cross compiler to build ARM program. The built GCC can be used to compile application into ARM’s machine codes. The toolchain then reside on /usr/local path.

For this article, I use:

  1. Slackware64 14.0
  2. GCC 4.9.2
  3. GDB 7.8.1
  4. Binutils 2.24
  5. Newlib 2.1
  6. GMP 6.0.0
  7. MPFR 3.1.2
  8. MPC 1.0.2

Deciding the Target

In ARM, there is a naming convention which explain what toolchain will do. The target alias, or target, is the target of the toolchain. It’s more than just an architecture. The tools on this toolchain will have some profix, such as: arm-none-eabi-gcc, arm-linux-eabi-gcc, etc.

This distinguish one toolchain from native host compiler and have different purpose for each name.

Basically, “arm-none-eabi” is consist of three part:

  1. architecture / processor name. Which is ARM architecture (ARM, Thumb, Thumb-2, etc)
  2. something about OS/libraries. This part is varies. Some have none and other has linux, etc. The ‘none’ means that the toolchains are not targetting specific operating system (aka ‘bare-metal’). ‘unknown’ is the same as ‘none’ while ‘linux’ designed to be used to build programs with glibc under a Linux environment, usually for built for embedded linux ARM devices.
  3. ABIs. This part describes how binary files (libraries, etc) are stored (the actual file formats), and calling conventions, register usage, etc. Some common are gnuabi, eabi, etc.

In this article, we will build arm-none-eabi to make bare metal arm compiler.

Preparation

We will need some disk space (~2GB should be enough). We also need root access to install it on “system-wide”.

Slackware64 14.0 is optional. You can use any linux distribution you like.

We will create a working directory. We will refer it as $ARMGCC, so $ARMGCC/src should really be something like ~/ARMGCC/src (the ~ means your home directory). So go ahead and create following directory structure:

# set aliases
export ARMGCC=~/ARMGCC
export TARGET=arm-none-eabi
export PREFIX=/usr/local

export BINUTILS_BUILD=${ARMGCC}/build/binutils-build
export GCC_BUILD=${ARMGCC}/build/gcc-build
export GDB_BUILD=${ARMGCC}/build/gdb-build

export BINUTILS_SRC=${ARMGCC}/src/binutils-2.24
export GCC_SRC=${ARMGCC}/src/gcc-4.9.2
export GDB_SRC=${ARMGCC}/src/gdb-7.8.1
export NEWLIB_SRC=${ARMGCC}/src/newlib-2.1.0

# make base dir, original archives dir (orig), source code dir (src), 
# and working / building dir (build) 
mkdir ${ARMGCC}{,/{orig,src,build}}

# Make build directory for each component
mkdir ${ARMGCC}/build/{binutils,gcc,gdb}-build

Acquiring the Materials

Download latest packages of GCC, GDB, binutils, and Newlib.You can download it using wget or alternatively download via browser and move it to $ARMGCC/orig. The version we will use is GCC 4.9.0, GDB 7.7, binutils 2.24, and newlib 2.1.0.

cd ${ARMGCC}/orig
wget ftp://ftp.gnu.org/pub/gnu/gcc/gcc-4.9.2/gcc-4.9.2.tar.bz2
wget ftp://ftp.gnu.org/pub/gnu/gdb/gdb-7.8.1.tar.xz
wget ftp://ftp.gnu.org/gnu/binutils/binutils-2.24.tar.bz2
wget ftp://sources.redhat.com/pub/newlib/newlib-2.1.0.tar.gz

wget ftp://ftp.gnu.org/pub/gnu/gmp/gmp-6.0.0a.tar.xz
wget ftp://ftp.gnu.org/pub/gnu/mpc/mpc-1.0.2.tar.gz
wget ftp://ftp.gnu.org/pub/gnu/mpfr/mpfr-3.1.2.tar.gz

Then, extract them to src directory.

cd ${ARMGCC}/src

tar -jxf ${ARMGCC}/orig/gcc-4.9.2.tar.bz2
tar -Jxf ${ARMGCC}/orig/gdb-7.8.1.tar.xz
tar -jxf ${ARMGCC}/orig/binutils-2.24.tar.bz2
tar -zxf ${ARMGCC}/orig/newlib-2.1.0.tar.gz

Next we need to download some prerequisites, especially GMP (GNU Multiple Precision), MPC (Multiple-Precision Complex), and MPFR (Multiple-Precision Floating Point Reliably) which is used for computation. The prerequisites can be downloaded by invoking following command:

The MPFR, GMP, and MPC is not the latest version, but at least we can build GCC. Suppose your working directory at /home/xathrya/ARMGCC, to obtain MPDR, GMP, and MPC invoke following command:

cd ${GCC_SRC}
./contrib/download_prerequisites

However, the version of GMP, MPC, MPFR, PPL, CLOOG, and ISL is not the latest version. We can switch to the latest version by download the latest version and create symbolic link to it.

cd ${GCC_SRC}

rm {gmp,mpc,mpfr}

tar -Jxf ${ARMGCC}/orig/gmp-6.0.0a.tar.xz
tar -zxf ${ARMGCC}/orig/mpc-1.0.2.tar.gz
tar -zxf ${ARMGCC}/orig/mpfr-3.1.2.tar.gz

ln -s gmp-6.0.0 gmp
ln -s mpc-1.0.2 mpc
ln -s mpfr-3.1.2 mpfr

Building the Toolchains

Building stage is pretty simple. Honestly speaking, the tricky part is about how GCC and built concept and ordering them in correct order.

Binutils

First, built binutils. This will provide lots of useful tools in building ARM libraries and binaries (like objdump, ld, ranlib, etc). Invoke following commands:

cd ${BINUTILS_BUILD}
${BINUTILS_SRC}/configure \
   --target=${TARGET} \
   --prefix=${PREFIX} \
   --enable-interwork \
   --enable-multilib \
   --with-gnu-as \
   --with-gnu-ld \
   --disable-werror \
   --disable-nls
make configure-host
make -j4 all
make install
make clean

You will notice a few configure options that are really critical for getting things to work properly.

  • –target=arm-none-eabi Says we want a compiler to generate binaries for the arm-none-eabi platform.
  • –enable-interwork This allows for assembling Thumb and ARM code mixed into the same binaries (for those chips that support that)
  • –enable-multilib Multilib allows the use of libraries that are compiled multiple times for different targets/build types
  • –enable-shared – enable the creation of the shared libraries.

GCC

Next we will build the GCC. But please note that we are only intereset on C and C++ so we will ignore other language. To built GCC, do this:

cd ${GCC_BUILD}
${GCC_SRC}/configure \
   --target=${TARGET} \
   --prefix=${PREFIX} \
   --enable-interwork \
   --enable-multilib \
   --enable-languages="c,c++" \
   --with-newlib \
   --without-headers \
   --disable-shared \
   --with-system-zlib \
   --with-gnu-as \
   --with-gnu-ld \
   --disable-nls \
   --enable-c99 \
   --enable-long-long \
   --enable-__cxa_atexit
make -j4 all-gcc install-gcc
make clean

Now, the important points are:

  • –enable-languages=”c,c++” – means build C and C++ only.
  • –with-newlib – use Newlib instead of the standard C libraries.
  • –with-headers – this adds a header inlude path during build time and will allow the build to find the newlib header files
  • –enable-__cxa_atexit – allows use of __cxa_atexit, rather than atexit, to register C++ destructors for local statics and global objects and is essential for fully standards-compliant handling of destructors. It also affects the C++ ABI and therefore results in C++ shared libraries and C++ programs that are interoperable with other Linux distributions.
  • –enable-c99 – enable C99 support for C programs.
  • –enable-long-long – enables long long support in the compiler.

Newlib

Now build our newlib

cd ${NEWLIB_BUILD}
${NEWLIB_SRC}/configure \
  --target=${TARGET} \
  --prefix=${PREFIX} \
  --enable-interwork \
  --enable-multilib \
  --with-gnu-as \
  --with-gnu-ld \
  --disable-nls \
  --enable-target-optspace \
  --enable-newlib-reent-small \
  --enable-newlib-io-c99-formats \
  --enable-newlib-io-long-long \
  --disable-newlib-multithread \
  --disable-newlib-supplied-syscalls \
  CFLAGS_FOR_TARGET="
make -j4 all
make install
make clean

GCC (again)

Now that we have our runtime libraries, go back and ginish the GCC build:

cd ${GCC_BUILD}
make all-install

GDB

Optionally you can build GDB. To do so, invoke following:

cd ${GDB_BUILD}
${GDB_SRC}/configure \
   --target=${TARGET} \
   --prefix=${PREFIX} \
   --enable-interwork \
   --enable-multilib
make -j4 all 
make install

And that’s it. You should have them now.

Testing

The toolchain can be tested with the minimal code here:

int main()
{
   return 0;
}

void exit(int code)
{
   while(1);
}

Building GCC AVR Toolchain Cross Compiler

December 11, 2015 | Article, Labs | No Comments

In this article we will about how to build GCC AVR Toolchain, which is a cross compiler to build AVR program. The built GCC can be used to compile application into AVR’s machine codes. The toolchain then reside on /usr/local path.

For this article, I use:

  1. Slackware64 14.0
  2. GCC 4.9.0
  3. GDB 7.7
  4. Binutils 2.24
  5. AVR-libc 1.8
  6. GMP 6.0.0
  7. MPFR 3.1.2
  8. MPC 1.0.2

Preparation

We will need some disk space (~2GB should be enough). We also need root access to install it on “system-wide”.

Slackware64 14.0 is optional. You can use any linux distribution you like.

We will create a working directory. We will refer it as $AVRGCC, so $AVRGCC/src should really be something like ~/AVRGCC/src (the ~ means your home directory). So go ahead and create following directory structure:

# set aliases
export AVRGCC=~/AVRGCC
export TARGET=avr
export PREFIX=/usr/local

export BINUTILS_BUILD=${AVRGCC}/build/binutils-build
export GCC_BUILD=${AVRGCC}/build/gcc-build
export GDB_BUILD=${AVRGCC}/build/gdb-build

export BINUTILS_SRC=${AVRGCC}/src/binutils-2.24
export GCC_SRC=${AVRGCC}/src/gcc-4.9.0
export GDB_SRC=${AVRGCC}/src/gdb-7.7
export AVRLIBC_SRC=${AVRGCC}/src/avr-libc-1.8.0

# make base dir, original archives dir (orig), source code dir (src), 
# and working / building dir (build) 
mkdir ${AVRGCC}{,/{orig,src,build}}

# Make build directory for each component
mkdir ${AVRGCC}/build/{binutils,gcc,gdb}-build

Acquiring the Materials

Download latest packages of GCC, GDB, binutils, and Newlib.You can download it using wget or alternatively download via browser and move it to $AVRGCC/orig. The version we will use is GCC 4.9.0, GDB 7.7, binutils 2.24, and newlib 2.1.0.

cd ${AVRGCC}/orig
wget ftp://ftp.gnu.org/pub/gnu/gcc/gcc-4.9.0/gcc-4.9.0.tar.bz2
wget ftp://ftp.gnu.org/pub/gnu/gdb/gdb-7.7.tar.bz2
wget ftp://ftp.gnu.org/gnu/binutils/binutils-2.24.tar.bz2
wget ftp://ftp.twaren.net/Unix/NonGNU//avr-libc/avr-libc-1.8.0.tar.bz2

wget ftp://ftp.gnu.org/pub/gnu/gmp/gmp-6.0.0a.tar.xz
wget ftp://ftp.gnu.org/pub/gnu/mpc/mpc-1.0.2.tar.gz
wget ftp://ftp.gnu.org/pub/gnu/mpfr/mpfr-3.1.2.tar.gz

Then, extract them to src directory.

cd ${AVRGCC}/src

tar -jxf ${AVRGCC}/orig/gcc-4.9.0.tar.bz2
tar -jxf ${AVRGCC}/orig/gdb-7.7.tar.bz2
tar -jxf ${AVRGCC}/orig/binutils-2.24.tar.bz2
tar -jxf ${AVRGCC}/orig/avr-libc-1.8.0.tar.bz2

Next we need to download some prerequisites, especially GMP (GNU Multiple Precision), MPC (Multiple-Precision Complex), and MPFR (Multiple-Precision Floating Point Reliably) which is used for computation. The prerequisites can be downloaded by invoking following command:

The MPFR, GMP, and MPC is not the latest version, but at least we can build GCC. Suppose your working directory at /home/xathrya/AVRGCC, to obtain MPDR, GMP, and MPC invoke following command:

cd ${GCC_SRC}
./contrib/download_prerequisites

However, the version of GMP, MPC, MPFR are not the latest version. We can switch to the latest version by link it to our downloaded one.

cd ${GCC_SRC}

rm {gmp,mpc,mpfr}

tar -Jxf ${AVRGCC}/orig/gmp-6.0.0a.tar.xz
tar -zxf ${AVRGCC}/orig/mpc-1.0.2.tar.gz
tar -zxf ${AVRGCC}/orig/mpfr-3.1.2.tar.gz

ln -s gmp-6.0.0 gmp
ln -s mpc-1.0.2 mpc
ln -s mpfr-3.1.2 mpfr

Building the Toolchains

Building stage is pretty simple. Honestly speaking, the tricky part is about how GCC and built concept and ordering them in correct order.

Binutils

First, built binutils. This will provide lots of useful tools in building ARM libraries and binaries (like objdump, ld, ranlib, etc). Invoke following commands:

cd ${BINUTILS_BUILD}
${BINUTILS_SRC}/configure --target=${TARGET} --prefix=${PREFIX} \
    --enable-interwork --enable-multilib --enable-shared 
make configure-host
make -j4 all
make install

You will notice a few configure options that are really critical for getting things to work properly.

  • –target=avr Says we want a compiler to generate binaries for the avr platform.
  • –enable-multilib Multilib allows the use of libraries that are compiled multiple times for different targets/build types
  • –enable-shared – enable the creation of the shared libraries.

GCC

Next we will build the GCC. But please note that we are only intereset on C and C++ so we will ignore other language. To built GCC, do this:

cd ${GCC_BUILD}
${GCC_SRC}/configure --target=${TARGET} --prefix=${PREFIX} --enable-interwork \
   --enable-multilib --enable-languages="c,c++" --with-dwarf2 --disable-libssp \
   --enable-c99 --enable-long-long --enable-__cxa_atexit --enable-shared
make -j4 all-gcc 
make -j4 all-target-libgcc

make install-gcc install-target-libgcc

Now, the important points are:

  • –enable-languages=”c,c++” – means build C and C++ only.
  • –with-headers – this adds a header inlude path during build time and will allow the build to find the newlib header files
  • –enable-__cxa_atexit – allows use of __cxa_atexit, rather than atexit, to register C++ destructors for local statics and global objects and is essential for fully standards-compliant handling of destructors. It also affects the C++ ABI and therefore results in C++ shared libraries and C++ programs that are interoperable with other Linux distributions.
  • –enable-c99 – enable C99 support for C programs.
  • –enable-long-long – enables long long support in the compiler.

avr-libc

Now build our avr-libc

cd ${AVRLIBC_SRC}
./configure --host=avr --build=`./config.guess` --prefix=${PREFIX}
make
make install

GDB

Optionally you can build GDB. To do so, invoke following:

cd ${GDB_BUILD}
${GDB_SRC}/configure --target=${TARGET} --prefix=${PREFIX} \
  --enable-interwork --enable-multilib
make -j4 all 
make install

And that’s it. You should have them now.

Testing

The toolchain can be tested with the minimal code here:

int main()
{
   return 0;
}

Introduction to NPM (Node Package Manager)

December 9, 2015 | Article | 1 Comment

NPM (Node Package Manager) or simply npm is a simple application to install node programs. NPM also support a feature which will indicate dependencies and package starting file.

In this article, we will discuss about how to use npm, from a basic command to a rather advance one.

Getting Help

npm has a lot of feature, therefore let’s start by knowing how to get a help. NPM has a lot of help documentation about all of its command. Getting a help is as simple as typing this command on your terminal:

npm help

If you have a problem with any of npm command/feature, you can append –help on the command, leading to a documentation specific to that command. For example, both are valid command:

npm help install
npm install --help

Filtering Packages

npm ls [filter]

NPM can see the list of all packages and their version (npm ls with no filter), or filter by a tag (npm filter tag). For examples:

Installed Package

npm ls installed

This will list all installed package.

Stable Package

npm ls stable

This will list all stable package available (installed or not).

Search by Content

npm ls name

This way, we can have all packages that have “name” inside its name or tags.

Search by Version

npm ls @1.0

This is used to query packages specified by its version.

Install a Package

NPM is used to install,update, and remove a package. That’s what a package managers do.

When we want to install something, we can use following command and let NPM install the latest version of it to our machine. Here we will have “pkg_name” installed on our system.

npm install pkg_name

You can also install from a tarball, a folder, or an url to a tarball. If you run npm install without arguments, it tries to install the current folder. For example, we will install express:

npm install express

Or we can also install a specific version of a package by:

npm install [email protected]

We can also install the latest of a package within a version range we specify. For instance:

npm install [email protected]">=0.1.0"

More filters can be used to select a specific packages.

Update Packages

npm update [pkg_name]

The update command does a few things:

  1. Search the registry for new versions of all the packages installed (if pkg_name is omitted) or specific packages.
  2. If there’s a newer version, then install it
  3. Point dependent packages at the new version, if it satisfies their dependency
  4. Remove old versions, if no other package names them as a dependency.

Basically, update behaves a lot like a “standard” package manager’s update command, except that it also checks to make sure that the new version isn’t going to break anything before it points stuff at it.

Remove Packages

This command will uninstall a package. If the version are omitted, then all the found version are removed.

npm rm pkg_name[@version] [pkg_name2[@version]]

Read Package Information

To view all of a package information, we can do like this:

npm view pkg_name[@version]

Typical digital images or photos have a rich set of metadata embedded in them. Metadata is automatically written by capture device such as digital cameras, or it can be manually added by photographers or photo editing software to show various properties. Similarly, a pdf document also have its own set of metadata associated with them to identify author, title, date, etc.

There are various tools that allow us to edit metadata in digital photos or pdf documents and ExifTool is one of it. ExifTool is a platform-independent Perl library plus a command-line application for reading, writing and editing meta information in a wide variety of files. ExifTool supports many different metadata formats including EXIF, GPS, IPTC, XMP, JFIF, GeoTIFF, ICC Profile, Photoshop IRB, FlashPix, AFCP and ID3, as well as the maker notes of many digital cameras by Canon, Casio, FLIR, FujiFilm, GE, HP, JVC/Victor, Kodak, Leaf, Minolta/Konica-Minolta, Nikon, Olympus/Epson, Panasonic/Leica, Pentax/Asahi, Phase One, Reconyx, Ricoh, Samsung, Sanyo, Sigma/Foveon and Sony.

In this article, we will discuss about how to view or edit metadata in pdf documents or digital pictures from command line using ExifTool. All of experiments have been done on Slackware64 14.0.

Supported Metadata

Below is the list of file types and metadata currently supported by ExifTool (“r” = read, “w” = write, “c” = create)

Supported file types

------------+-------------+-------------+-------------+------------
3FR   r     | DVB   r     | M4A/V r     | PBM   r/w   | RWL   r/w
3G2   r     | DYLIB r     | MEF   r/w   | PDF   r/w   | RWZ   r
3GP   r     | EIP   r     | MIE   r/w/c | PEF   r/w   | RM    r
ACR   r     | EPS   r/w   | MIFF  r     | PFA   r     | SO    r
AFM   r     | ERF   r/w   | MKA   r     | PFB   r     | SR2   r/w
AI    r/w   | EXE   r     | MKS   r     | PFM   r     | SRF   r
AIFF  r     | EXIF  r/w/c | MKV   r     | PGF   r     | SRW   r/w
APE   r     | F4A/V r     | MNG   r/w   | PGM   r/w   | SVG   r
ARW   r/w   | FLA   r     | MOS   r/w   | PICT  r     | SWF   r
ASF   r     | FLAC  r     | MOV   r     | PMP   r     | THM   r/w
AVI   r     | FLV   r     | MP3   r     | PNG   r/w   | TIFF  r/w
BMP   r     | FPX   r     | MP4   r     | PPM   r/w   | TTC   r
BTF   r     | GIF   r/w   | MPC   r     | PPT   r     | TTF   r
COS   r     | GZ    r     | MPG   r     | PPTX  r     | VRD   r/w/c
CR2   r/w   | HDP   r/w   | MPO   r/w   | PS    r/w   | VSD   r
CRW   r/w   | HTML  r     | MQV   r     | PSB   r/w   | WAV   r
CS1   r/w   | ICC   r/w/c | MRW   r/w   | PSD   r/w   | WDP   r/w
DCM   r     | IIQ   r/w   | MXF   r     | PSP   r     | WEBP  r
DCP   r/w   | IND   r/w   | NEF   r/w   | QTIF  r     | WEBM  r
DCR   r     | ITC   r     | NRW   r/w   | RA    r     | WMA   r
DFONT r     | JNG   r/w   | NUMBERS r   | RAF   r/w   | WMV   r
DIVX  r     | JP2   r/w   | ODP   r     | RAM   r     | X3F   r/w
DJVU  r     | JPEG  r/w   | ODS   r     | RAR   r     | XCF   r
DLL   r     | K25   r     | ODT   r     | RAW   r/w   | XLS   r
DNG   r/w   | KDC   r     | OGG   r     | RIFF  r     | XLSX  r
DOC   r     | KEY   r     | ORF   r/w   | RSRC  r     | XMP   r/w/c
DOCX  r     | LNK   r     | OTF   r     | RTF   r     | ZIP   r
DV    r     | M2TS  r     | PAGES r     | RW2   r/w   |

Supported metadata standards and types

----------------------+----------------------+---------------------
EXIF           r/w/c  |  CIFF           r/w  |  Ricoh RMETA    r
GPS            r/w/c  |  AFCP           r/w  |  Picture Info   r
IPTC           r/w/c  |  Kodak Meta     r/w  |  Adobe APP14    r
XMP            r/w/c  |  FotoStation    r/w  |  MPF            r
MakerNotes     r/w/c  |  PhotoMechanic  r/w  |  Stim           r
Photoshop IRB  r/w/c  |  JPEG 2000      r    |  APE            r
ICC Profile    r/w/c  |  DICOM          r    |  Vorbis         r
MIE            r/w/c  |  Flash          r    |  SPIFF          r
JFIF           r/w/c  |  FlashPix       r    |  DjVu           r
Ducky APP12    r/w/c  |  QuickTime      r    |  M2TS           r
PDF            r/w/c  |  Matroska       r    |  PE/COFF        r
PNG            r/w/c  |  GeoTIFF        r    |  AVCHD          r
Canon VRD      r/w/c  |  PrintIM        r    |  ZIP            r
Nikon Capture  r/w/c  |  ID3            r    |  (and more)

Installation

As stated before, ExifTool is using Perl. ExifTool requires Perl 5.004 or later. No other library or software is required.

Package Manager Way

To install ExifTool on Ubuntu, Debian or Linux Mint you can use following command:

sudo apt-get install libimage-exiftool-perl

To install ExifTool on CentOS or RHEL, first you need to set up EPEL repository, and then run the following:

sudo yum install perl-Image-ExifTool

Generic Way

Installing ExifTool from source is really simple.

Download the source code, the latest version is 9.37

wget http://www.sno.phy.queensu.ca/~phil/exiftool/Image-ExifTool-9.37.tar.gz

Extract and go to the source code’s root directory:

tar -xzvf Image-ExifTool-9.37.tar.gz
cd Image-ExifTool-9.37

next, invoke following commands to test and install:

perl Makefile.PL
make test
sudo make install

Windows Way

In Windows, there is a choice of two different versions of ExifTool to install. If you don’t already have Perl, it is easier to install the stand-alone ExifTool executable, but note that the stand-alone version doesn’t include the HTML documentation or some other files of the full distribution.

The stand-alone executable can be downloaded from ExifTool home page: exiftool-9.37.zip. After download it, extract “exiftool(-k).exe”. Rename and move it as to C:\Windows\exiftool.exe.

You can now run exiftool by typing “exiftool” at the command prompt.

Usage Example

View all metadata in a picture

exiftool input.jpg

Change title and author information of a pdf document

exiftool -Title=”A title by Satria” -Author=”Satria Ady Pradana” input.pdf

Modify tags of multiple image in a batch

exiftool -artist=”Satria Ady Pradana” -copyright=”2013 Satria Ady Pradana” a.jpg b.jpg c.jpg

Modify artist name for all media files located in a target directory

exiftool -artist=”Satria Ady Pradana” ./folder

Show all Metadata information in an Image

This will include duplicate and unknown tags, sorted by group.

exiftool -a -u -g2 input.jpg

Show all metadata fields which contains the word “Date”

exiftool -”*Date*” input.png

Extract GPS coordinate information from a photo

exiftool -gpslatitude -gpslongitude input.jpg

Show GPS coordinate information contained in a picture in tabular format

exiftool -filename -gpslatitude -gpslongitude -T input.jpg

 

Installing wxHexEditor

December 9, 2015 | Article | No Comments

A hex editor is a “special purpose” editor. It is different from a regular text ediro in that the hex editor displays the raw binary content of a given file, without applying any text encoding or typesetting. A hex editor is mainly used in forensic or low level editing situation. It can be use for example: repairing disk image and partition, reverse engineering binary code, patching emulator ROM files, analyzing malware, etc.

One of good HEX editor available for Linux is wxHexEditor, which will be discussed here.

wxHexEditor is using wxWidgets libraries, therefore it can be compiled on top of various platform supported by wxWidgets.

In this article we will limit ourself to some operating system: Windows, Mac, and Linux.

There is also a specific article for installing wxHexEditor for Slackware, which can be used as a guide for installing wxHexEditor from source code.

The latest version of wxHexEditor is 0.22, which will be used in this article.

wxHexEditor Features

wxHexEditor offers a number of powerful features.

  • 64-bit file descriptors supporting files or devices of up to 2^64 bytes.
  • Extremely fast with handling large files by not copying the whole files to RAM.
  • Can handle multiple byte insertions or deletions without creating a temp file.
  • Low memory footprint (e.g., 25 MB memory for opening multi GB files).
  • Disassembly support for x86, x86-64, MMX, SSE, SSE2, SSE3, AMD-V, Intel VT-x.
  • Support for process memory editing.
  • Can handle XOR-based obfuscation.
  • Multiple views to show multiple files.
  • Support for multiple encodings (e.g., UTF8/16/32, Shift JIS, GBK, EUC, etc).

Dependencies

To compile wxHexEditor, we need wxWidgets library with version 2.8.11 or higher.

You can follow this article to install wxWidgets if you don’t have it yet.

Windows Installation

wxHexEditor offers a binary installer which compiled using MinGW. You can download it here.

Once the download finished, you will have a new zip archive name wxHexEditor-v0.22a-Win32.zip.

Mac OS Installation

Mac OSX users can download precompiled static binary for MacIntel. You can download the installer here.

Linux Installation

Debian Way

To install wxHexEditor on Debian and it’s derivation, you can install via GetDeb Apps repositories. Here are the commands you need to invoke to install wxHexEditor:

wget -q -O – http://archive.getdeb.net/getdeb-archive.key | sudo apt-key add -
sudo sh -c ‘echo “deb http://archive.getdeb.net/ubuntu $(lsb_release -cs)-getdeb apps” >> /etc/apt/sources.list.d/getdeb.list’
sudo apt-get update
sudo apt-get install wxhexeditor

Alternatively, you can build wxHexEditor from source:

sudo apt-get install debhelper libdisasm-dev libmhash-dev libwxbase2.8-dev libwxgtk2.8-dev wx-common wx2.8-headers
svn checkout svn://svn.code.sf.net/p/wxhexeditor/code/trunk wxHexEditor
cd wxHexEditor
make OPTFLAGS=”-fopenmp”

RPM Package Way

If you are using CentOS or RHEL, you need to enable Repoforge repository first.

To install wxHexEditor, you can build it from source, as follows:

sudo yum install libtool gcc-c++ wxGTK-devel
svn checkout svn://svn.code.sf.net/p/wxhexeditor/code/trunk wxHexEditor
cd wxHexEditor
make OPTFLAGS=”-fopenmp”

Troubleshoot

If you encounter following problems:

/lib/libgbm.so.1: undefined reference to `wayland_buffer_is_drm'

then you need to updating mesa-libgbm package.

Installing wxHexEditor for Slackware64

December 9, 2015 | Article | No Comments

A hex editor is a “special purpose” editor. It is different from a regular text ediro in that the hex editor displays the raw binary content of a given file, without applying any text encoding or typesetting. A hex editor is mainly used in forensic or low level editing situation. It can be use for example: repairing disk image and partition, reverse engineering binary code, patching emulator ROM files, analyzing malware, etc.

One of good HEX editor available for Linux is wxHexEditor, which will be discussed here.

In this article, I use following:

  1. Slackware64 14.0
  2. wxHexEditor – source code.

There is also an article for installing wxHexEditor in several operating system.

wxHexEditor Features

wxHexEditor offers a number of powerful features.

  • 64-bit file descriptors supporting files or devices of up to 2^64 bytes.
  • Extremely fast with handling large files by not copying the whole files to RAM.
  • Can handle multiple byte insertions or deletions without creating a temp file.
  • Low memory footprint (e.g., 25 MB memory for opening multi GB files).
  • Disassembly support for x86, x86-64, MMX, SSE, SSE2, SSE3, AMD-V, Intel VT-x.
  • Support for process memory editing.
  • Can handle XOR-based obfuscation.
  • Multiple views to show multiple files.
  • Support for multiple encodings (e.g., UTF8/16/32, Shift JIS, GBK, EUC, etc).

Installation

Dependencies

To compile wxHexEditor, we need wxWidgets library with version 2.8.11 or higher.

You can follow this article to install wxWidgets if you don’t have it yet.

You also need wxPython to do so.

Obtain the Materials

Source code for wxHexEditor is hosted at sourceforge with latest version is 0.22 Beta. You can download the source code here.

Next, extract it and you will have a directory of the source code. Change to that directory, the rest of compilation will be assumed that we are here.

Compilation

Invoke these series of commands to build wxHexEditor (using root privileges to install):

make OPTFLAGS="-fopenmp"
su -c "make install"

Other Installation Methods

Slackbuilds

A slackbuild script has been provided here. However, the version supported there is 0.20.

You can download the source code and slackbuild script and do slackbuild on your system.

Install from RPM Package

Installing from RPM package means you need to convert the corresponding .rpm package to Slackware compatible. This package is actually used for Red Hat and it’s derivative distributions.

First you need to obtain the package.

For example, I obtain one package from pkgs.org which is wxHexEditor-0.22-2.1.x86_64.rpm

Then do conversion by rpm2tgz tool:

rpm2tgz wxhexeditor-0.22-2.1.x86_64.rpm

And then install it by:

su -c "upgradepkg --install-new wxhexeditor-0.22-2.1.x86_64.tgz"

Install from Deb Package

Installing from Deb package means you need to convert the corresponding .deb package to Slackware compatible. This package is actually used for Debian and it’s derivative distributions.

First you need to obtain the package.

For example, I obtain one package from pkgs.org which is wxHexEditor-0.22-repack-1_amd64.deb

Then do conversion by deb2tgz tool:

deb2tgz wxhexeditor_0.22+repack-1_amd64.deb

And then install it by:

su -c "upgradepkg --install-new wxhexeditor_0.22+repack-1_amd64.tgz"

Arch Linux Pacage Manager Command List

December 9, 2015 | Article | No Comments

Here is the list of useful commands for pacman. Pacman is a package manager for Arch Linux.

Whether you use x86, amd64, or ARM architecture, the command should remain same.

Update Package List

The repository is consists of many package. To update the package list, we do:

pacman -Syy

Upgrade Packages

This will update all packages on the system.

pacman -Suy

Perform Full Upgrade

This is necessary if some libraries are missing to recompile system properly.

pacman -Syyu

Install New Package

Install specific package.

pacman -S $PACKAGE

where $PACKAGE is the package name you want to install. For example: xorg-server

Install package groups

pacman -Sg $PACKAGEGROUP

where $PACKAGE is the package group. For example: gnome.

Remove Package

Remove package, normally.

pacman -R $PACKAGE

where $PACKAGE is the package name you want to remove. This will remove a single package and leaving all of its dependencies installed.

If you want to remove a package and its dependencies which are note required by any other package, do following:

pacman -Rs $PACKAGE

If you want to remove a package, its dependencies, and all of the dependent (packages depend on it)

pacman -Rsc $PACKAGE

Search for Package

Will search the package database on given keyword

pacman -Ss $KEYWORD

where $KEYWORD is the keyword, can be parts of package name, description, etc.

List of Package Installed

List of packages

pacman -Q

List the package installed with given keyword

pacman -Q | grep $KEYWORD

List the packages installed as dependencies but not used anymore.

pacman -Qdt

List the packages installed, and not needed by other packages (not bein depended on)

pacman -Qet

List of files installed with package (content of package)

pacman -Ql $PACKAGE

ARM Development Studio 5 is one of the development studio used for cross compiling and developing application for ARM processor. ARM DS-5 is developed by the very expert one on ARM architecture and enable engineers to develop robust and highly optimized embedded software for ARM application processors. The DS-5 toolchain comprises tools such as the best-in-class ARM C/C++ Compiler, powerful Linux/Android/RTOS-aware debugger, ARM Streamline system-wide performance analyzer, and realtime system model simulators. All conveniently packaged in a user friendly integrated development environment (IDE) based on the Eclipse.

In this article we will discuss about how to install ARM Development Studio 5 Community Edition on various operating system.

This article is written based on following:

  1. Slackware64 14.0
  2. Windows 8
  3. JDK 1.7

If you don’t want create a cross compile toolchain by yourselves, this method is suitable for you.

Requirements

ARM Development Studio 5 requires Java, JRE or JDK. You need this package to run the IDE (Integrated Development Environment), which is a modified Eclipse.

Obtain Materials

Download the ARM DS-5 by visiting this page. There are four types of installer:

  1. Windows 32-bit
  2. Windows 64-bit
  3. Linux 32-bit
  4. Linux 64-bit

Make sure you download the appropriate package for your system.

Installation

I assume you have downloaded the package specific to your platform. Follow the section which suit your platform:

Windows

Aside from the target architecture you download, you should have a zip file with .zip extension. You shall have following items:

  1. Guide e-book (ds-5_license_management_guide.pdf)
  2. ARM logo (armlogo.png)
  3. change log (changes.html)
  4. readme (readme.html)
  5. actual installation file (install_<yourplatform>.exe)

Extract the package and do the installation by running the file.

Linux

Aside from the Linux target version for the package you download, you should have a tar ball package with .tgz extension. Inside you will have following:

  1. Guide e-book (ds-5_license_management_guide.pdf)
  2. ARM logo (armlogo.png)
  3. change log (changes.html)
  4. readme (readme.html)
  5. actual installation file (install_<yourplatform>.sh)

We will refer the installation file as install.sh.

Extract the packages to any directory and make sure you are currently accessing the top directory of the package content.

Change to root account or account with root privilege.

Do installation by executing the install.sh

./install.sh

You will be asked some questions. The questions are straightforward, nothing tricky here. Install it to any location you want. For example, I choose /usr/local.

Once installed, you will have ARM Development Studio installed on /usr/local/DS-5 if you choose /usr/local. You then will be asked to add /usr/local/DS-5/bin to your PATH. Do this by editing your shell startup script (ex: .bashrc).

To start IDE, you can run /usr/local/DS-5/bin/eclipse.

You can also invoke toolchain without running the Eclipse IDE.

License and Activation Code

To use DS-5, it is recommended to activate it. As we have DS-5 Community Edition we can use it freely after activation successful.

When we start ARM Development Studio 5, we can navigate to “Help” menu. If this is your first time using DS-5, then a popup dialog will automatically ask you if you wish to open the license manager.

DS5-0

Click “Add License” and a new dialog will appear. You will be asked to enter your Activation Code. Use the license displayed on this page.

DS5-1

Next, we will be asked by Wizard to select the Host ID to lock our license to.

DS5-2

Next, we need to enter or create ARM account. If you don’t have one, you can create it now on here or following the link given in the dialog box.

DS5-3

Once complete, the license manager can be closed and our DS-5 is licensed now.

Social media & sharing icons powered by UltimatelySocial