Summer Nights

Let's make the world a better place using digital technologies!

Howto: Building gcc/g++ toolchain for Motorola Coldfire/M68K Processors (II)

In a previous post, I have described how to make a coldfire toolchain using gcc 4.2.3. In this post, we shall see how we can use the latest cvs trunks to build the toolchain based on latest sources.

You should have ample free space (ca. 3GB) on your hard disk and I assume you are root.

  • Become root
    sudo su
  • Install the tools:
    apt-get install gcc g++ build-essential gcc-3.4 automake autoconf gdb bzip2 texinfo patch flex bison subversion cvs
  • Make required folders:
    mkdir /usr/local/coldfire
    mkdir /usr/local/coldfire/source
    cd /usr/local/coldfire/source
  • Get and build binutils:
    mkdir binutils
    cd binutils
    cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src login

    Enter “anoncvs” as password.
    cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src co binutils
    mkdir build_binutils
    cd build_binutils
    ../src/configure --prefix=/usr/local/coldfire --target=m68k-elf --enable-multilib
    make -j2
    make install
    cd ../..
  • Make and install gmp and mpfr libraries:
    cd /usr/src
    wget http://ftp.sunet.se/pub/gnu/gmp/gmp-4.2.2.tar.gz
    tar -xvf gmp-4.2.2.tar.gz
    cd gmp-4.2.2
    ./configure
    make -j 2
    make install
    cd ..

    wget http://www.mpfr.org/mpfr-current/mpfr-2.3.1.tar.bz2
    bzcat mpfr-2.3.1.tar.bz2 | tar -xf -
    cd mpfr-2.3.1
    ./configure
    make -j 2
    make install
    cd ..

  • Update library configuration:
    ldconfig
    depmod -a
  • Download and uncompress latest gcc sources, at the time of writing:
    wget ftp://ftp.mpi-sb.mpg.de/pub/gnu/mirror/gcc.gnu.org/pub/gcc/snapshots/4.3.1-RC-20080523/gcc-4.3.1-RC-20080523.tar.bz2
    bzcat gcc-4.3.1-RC-20080523.tar.bz2 | tar -xf gcc-4.3.1-RC-20080523.tar.bz2
  • Get newlib and link to gcc:
    mkdir newlib
    cd newlib
    cvs -z 9 -d :pserver:anoncvs@sources.redhat.com:/cvs/src co newlib

    Enter "anoncvs" as the password.
    cd ../gcc-4.3.1-RC-20080523
    rm -rf newlib
    ln -s ../newlib/src/newlib newlib
    cd ..
  • ***IMPORTANT: DO NOT COMPILE WITHIN THE SOURCE DIR***
  • Make and install gcc:
    mkdir build_gcc
    cd build_gcc
    PATH="$PATH:/usr/local/coldfire/bin"
    export LD_LIBRARY_PATH=/usr/local/lib

    Configure the toolchain:
    ../gcc-4.3.1-RC-20080523/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=m68k-elf \
    --disable-libmudflap --disable-libssp --disable-libgomp --enable-threads \
    --enable-languages=c,c++ --disable-checking --disable-shared --with-newlib \
    --with-bugurl=http://deneb.homedns.org/things --with-pkgversion=HIRTS-0.1 \
    --disable-nls --prefix=/usr/local/coldfire --enable-poison-system-directories \ --with-build-time-tools=/usr/local/coldfire/bin

    Make and install the toolchain (can take ca. 1 hour on most computers!):
    make -j4
    make install

  • Add the tools to your path:
    emacs /etc/profile
    Add /usr/local/coldfire/bin to the end of PATH
    Press C-x C-s to save, C-x C-c to exit. Enter:
    source /etc/profile
    to load the new path information.
    This will add it to all the users' path except root. If you want to add it to root's path as well, you need to edit .bashrc file in /root folder by adding the following:
    PATH="$PATH:/usr/local/coldfire/bin"
  • Check the toolchain:
    m68k-elf-gcc -v
    Using built-in specs.
    Target: m68k-elf
    .....
  • Compile a simple hello world program:
    cd /tmp
    emacs hello_world_m68k.c

    Enter the following simple program:
    #include <stdio.h>
    int hello_world (int argc, char *argv[])
    {
    int i;
    printf ("Hello World\n");
    return (0);
    }

    Press C-x C-s to save and C-x C-c to exit
    Compile the program:
    m68k-elf-gcc -g -c -mcpu=5282 hello_world_m68k.c

Feedback/comments are welcomed.

Continue Reading

Installing Netgear WG11T Wi-Fi Stick in Ubuntu 7.04, Kernel 2.6.25.4

  • First of all, clear any traces of previous installs, if any:

    sudo su
    apt-get remove ndiswrapper-utils
    cd /usr/src/ndiswrapper
    make uninstall
    make clean
    rm -r /etc/ndiswrapper/
    rm -r /etc/modprobe.d/ndiswrapper
    cd ..
    rm -rf ndiswrapper
  • Get, unzip, make and install new ndiswrapper:
    wget http://garr.dl.sourceforge.net/sourceforge/ndiswrapper/ndiswrapper-1.52.tar.gz
    tar -xzf ndiswrapper-1.52.tar.gz
    cd ndiswrapper-1.52
    make
    make install
  • Install the WG11T drivers:
    Copy the windows xp drivers of WG11T to /usr/src/wlandrivers. Then,
    cd /usr/src/wlandrivers
    ndiswrapper -i athfmwdl.inf
    ndiswrapper -i netwg11t.inf

    Issuing:
    modprobe ndiswrapper
    should make the adapter active, some leds may flash
  • ndiswrapper -m
    will include the module in the auto-load at bootup sequence.
Continue Reading

Installing Xenomai on Ubuntu with Linux Kernel 2.6.25

You should have ~2-3GB free space to make the kernel and must have root privileges.

  • sudo su
    apt-get install subversion
    mkdir /usr/src/xenomai
    cd /usr/src/xenomai
    svn co svn://svn.gna.org/svn/xenomai/trunk xenomai
  • Goto www.kernel.org and download the latest kernel. At the time of writing:
    wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.25.4.tar.bz2
    bzcat linux-2.6.25.4.tar.bz2 | tar -xf -
    ln -s linux-2.6.25.4 linux
  • cd xenomai
    Type:
    ./configure --help
    to see the options and parameters.
    scripts/prepare-kernel.sh --linux=/usr/src/xenomai/linux
  • Configure the Linux kernel
    cd ../linux
    Copy the old configuration file, you may need to change the name depending on your kernel version:
    cp /boot/config-2.6.25.4 .config
    make menuconfig

    I chose the following options. Dis means pressing “n”(for no), and En means pressing “y” (for yes). When you get into Real-time sub-system section, you should closely read the messages on top. It will indicate if some un-recommended/conflicting options are set.

    Dis: Kernel IRQ Balancing
    Dis: APM
    Dis: CPU Freq Scaling
    Dis: CPU Idle PM Support
    Dis: Legacy Power Management
    Dis: HPET Timer
    Dis: ACPI Processor
    Dis: all deprecated from ACPI
    Dis: WMI
    Dis: Power Management Timer Support
    Dis: ACPI Container Driver
    En: Enable Periodic Timing -> RT Subsystem
    En: Scalability -> 0(1) Scheduler
    En: Enable SMI Workaround
    En: Globally Disable SMI
    En: POSIX API all enable
    En: Select support for RTDM file descriptors
    En: Serial Driver -> Any access mode
    Dis: Check for non-fatal errors on AMD Athlon/Duron / Intel Pentium 4
    Dis: check for P4 thermal throttling interrupt.
    Dis: Enable kernel irq balancing
    Dis: Power Management Timer Support
    Dis: APM (Advanced Power Management) BIOS suppor
    Dis: All Interfaces except Native API and POSIX
    Dis: CONFIG_FRAME_POINTER

  • make-kpkg clean
  • Make the new kernel, can take ca. 1 hour:
    CONCURRENCY_LEVEL=2 (on dual core processors)
    make-kpkg --initrd --append-to-version=-rtosx --revision=0.1 kernel_image kernel_headers

    Note:Do not use xeno in --append-to-version option as linux disregards xeno in some of its operations which creates a chaotic situation when finding proper /lib/modules/kernel_version folder.
  • Add modules so that splash screen/console can load at boot
    echo vesafb | tee -a /etc/initramfs-tools/modules
    echo fbcon | tee -a /etc/initramfs-tools/modules
  • Install the newly built kernel and headers:
    dpkg -i linux-image-2.6.25.4-rtosx_0.1_i386.deb
    dpkg -i linux-headers-2.6.25.4-rtosx_0.1_i386.deb
  • Type:
    cat /etc/grub/menu.lst
    to confirm that the new kernel has been properly entered into the list. If not, you may need to add it manually.
  • Boot with the new kernel:
    shutdown -r now
  • Build and install xenomai user-space components:
    cd /usr/src/xenomai
    mkdir build_root && cd build_root
    ../xenomai/configure --enable-x86-sep --enable-smp
    make -j4
    make install
  • Test the new Xenomai RTOS:
    cd /usr/xenomai/bin
    ./xeno-test

    At the end of some tests, you should see the user-space RT latencies. Press Ctrl-C to exit the test.
Continue Reading

Resize, Rename and Compress Images on the Fly

Issue the following command in the folder where *.JPG files are located:
for i in *.JPG; do convert -resize 800x600 -quality 90 $i s_$i; tar --remove-files -rvf pics.tar s_$i; done
The files will be resized, renamed with a prefix of s_ and will be added to the pics.tar.
Issue:
tar -tvf pics.tar
to see the contents of the created archive.
If zip is required, then use:
for i in *.JPG; do convert -resize 800x600 -quality 90 $i s_$i; zip -m pics.zip s_$i; done

Continue Reading

Install Eclipse CDT on Ubuntu

sudo su
cd /usr/src
apt-get install sun-java6-jdk
update-alternatives --config java

Download eclipse cdt from http://www.eclipse.org/
tar -xf eclipse-cpp-europa-winter-linux-gtk.tar.gz
cd eclipse
./eclipse

Create and build a “Hello World” project. Click on project -> new and follow simple instruction.
Build and execute the project. Simple.

Continue Reading

Howto: Build a gcc 4.2.3 based Coldfire Toolchain

You should have ample free space on your disk and I assume you are root.

  • Become root
    sudo su
  • Install the tools:
    apt-get install gcc g++ build-essential gcc-3.4 automake autoconf gdb bzip2 texinfo patch flex bison subversion
  • Make required folders:
    mkdir /usr/local/coldfire
    mkdir /usr/local/coldfire/source
    cd /usr/local/coldfire/source
  • Get and build binutils:
    wget http://ftp.gnu.org/gnu/binutils/binutils-2.17.tar.bz2
    bzcat binutils-2.17.tar.bz2 | tar -xf -
    mkdir build_binutils
    cd build_binutils
    ../binutils-2.17/configure --prefix=/usr/local/coldfire --target=m68k-elf --enable-multilib
    make -j2
    make install
    cd ..
  • Make and install gmp and mpfr libraries:
    cd /usr/src
    wget http://ftp.sunet.se/pub/gnu/gmp/gmp-4.2.2.tar.gz
    tar -xvf gmp-4.2.2.tar.gz
    cd gmp-4.2.2
    ./configure
    make -j 2
    make install
    cd ..

    wget http://www.mpfr.org/mpfr-current/mpfr-2.3.1.tar.bz2
    bzcat mpfr-2.3.1.tar.bz2 | tar -xf -
    cd mpfr-2.3.1
    ./configure
    make -j 2
    make install
    cd ..

  • Update library configuration:
    ldconfig
    depmod -a
  • Download newlib and gcc:
    wget ftp://sources.redhat.com/pub/newlib/newlib-1.16.0.tar.gz
    tar -xzf newlib-1.16.0.tar.gz

    wget ftp://ftp.mpi-sb.mpg.de/pub/gnu/mirror/gcc.gnu.org/pub/gcc/releases/gcc-4.2.3/gcc-4.2.3.tar.bz2
    bzcat gcc-4.2.3.tar.bz2 | tar -xf -

  • ***IMPORTANT: DO NOT COMPILE WITHIN THE SOURCE DIR***
  • mkdir build_gcc
    cd build_gcc
    PATH="$PATH:/usr/local/coldfire/bin"
    export LD_LIBRARY_PATH=/usr/local/lib
  • cp -r /usr/include /usr/local/coldfire/m68k-elf/include
    (to solve ..
    ./tsystem.h:79:19: stdio.h: No such file or directory
    ./tsystem.h:82:23: sys/types.h: No such file or directory
    ./tsystem.h:85:19: errno.h: No such file or directory
    ./tsystem.h:92:20: string.h: No such file or directory
    ./tsystem.h:93:20: stdlib.h: No such file or directory
    ./tsystem.h:94:20: unistd.h: No such file or directory
    ./tsystem.h:100:18: time.h: No such file or directory

    )
  • Configure gcc:
    ../gcc-4.2.3/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=m68k-elf \
    --disable-libmudflap --disable-libssp --disable-libgomp --enable-threads \
    --enable-languages=c --disable-checking --disable-shared --with-newlib\
    --with-bugurl=http://deneb.homedns.org/things --with-pkgversion=HIRTS-0.1 \
    --disable-nls --prefix=/usr/local/coldfire --with-headers=/usr/src/linux/include \
    --enable-poison-system-directories --with-build-time-tools=/usr/local/coldfire/bin
  • Notes:
    1. with-arch=cf would make only coldfire-based binaries, but is not supported in 4.2.3.
    2. c++ does not work as well for some issue with libstdc++
    3. /usr/src/linux should refer to the current linux kernel sources.
    4. make -j4 CFLAGS="-I/usr/local/coldfire/source/newlib-1.16.0/newlib/libc/include does not work because of incompatible headers in newlib/libc
  • Make gcc:
    make -j6
    You may like to time the build using:
    time make -j6 (3m8.346s on my core 2 duo machine)
    make install
    cd ..
  • Make and install newlib
    cd newlib-1.16.0
    ./configure --target=m68k-elf --prefix=/usr/local/coldfire
    make -j6
    make install
    cd .
    .
  • Check the toolchain:
    m68k-elf-gcc -v
    Using built-in specs.
    Target: m68k-elf
    Configured with: ../gcc-4.2.3/configure –build=i686-pc-linux-gnu –host=i686-pc-linux-gnu –target=m68k-elf –disable-libmudflap –disable-libssp –disable-libgomp –enable-threads –disable-libstdcxx-pch -disable-threads –enable-languages=c –disable-checking –with-gnu-as –with-gnu-ld –with-bugurl=http://deneb.homedns.org/things –disable-shared –with-newlib –with-pkgversion=HIRTS-0.1 –disable-nls –prefix=/usr/local/coldfire –with-headers=/usr/src/linux/include –enable-poison-system-directories –with-build-time-tools=/usr/local/coldfire/bin
    Thread model: single
    gcc version 4.2.3
  • Compile s simple hello world program:
    cd /tmp
    emacs hello_world_m68k.c

    Enter the following simple program:
    #include <stdio.h>
    int hello_world (int argc, char *argv[])
    {
    int i;
    printf ("Hello World\n");
    return (0);
    }

    Press C-x C-s to save and C-x C-c to exit
    Compile the program:
    m68k-elf-gcc -g -c hello_world.c

Any feedback or comments are welcomed.

Continue Reading

Compiling and Installing new Linux Kernel on Ubuntu

  • sudo su
    apt-get install build-essential libncurses5-dev linux-kernel-devel
    cd /usr/src
  • Goto www.kernel.org and download the latest kernel. At the time of writing:
    wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.25.4.tar.bz2
  • Unzip the kernel source:
    bzcat linux-2.6.25.4.tar.bz2 | tar -xf -
    Make a symbolic link to linux tree:
    ln -s /usr/src/linux-2.6.25.4 /usr/src/linux
  • Copy the old kernel .config file to the new kernelÅ› folder:
    cp /boot/config-2.6.24-16-generic linux/.config
    cd linux
    make oldconfig
    make menuconfig
  • Make kernel packages using debian tool:
    CONCURRENCY_LEVEL=2 (To compile kernel on dual core processor, optional)
    make-kpkg --initrd --revision=homebrew0.1 kernel_image kernel_headers
    Compile time: 47m55.465s on my Core 2 Duo
  • Add modules so that splash screen/console can load at boot
    echo vesafb | tee -a /etc/initramfs-tools/modules
    echo fbcon | tee -a /etc/initramfs-tools/modules
  • Install the new kernel
    dpkg -i linux-image-2.6.25.4_homebrew0.1_i386.deb
    If you have already installed the same kernel, and are now rebuilding, you should do the following:
    mv /lib/modules/2.6.<KERNEL_VERSION> /lib/modules/2.6.<KERNEL_VERSION>_old
    This would make sure that older modules won’t be loaded after the new installation.
    dpkg -i linux-headers-2.6.25.4_homebrew0.1_i386.deb
  • Reboot the system and select the freshly brewed kernel from the top of the list.
    Caution: If you have ndiswrapper running on your system for wireless connectivity, it will not work after installing the new kernel. Once the new kernel has booted, you may want to follow instructions here to re-install ndiswrapper. I have to investigate further to find out if it is possible to install ndiswrapper for other-than-running kernel.
Continue Reading

Batch Resizing of Images using Adobe Photoshop

In Adobe Photoshop:
File->Scripts->Image Processor

  • Select the source folder where the pictures are located.
  • Select the destination folder where the pictures will be stored after resizing.
  • Click Run to start batch processing.
Continue Reading

Copy files between local and remote systems

#rlogin root@jupiter.domain.com
#rcp file.xyz ~

will copy the file to the home folder of the local user. A . is not appropriate as that would refer to the remote location resulting in a remote duplicate.
rcp abc.tar www.xyz.com:tmp/
would copy the local file to a remote system. You shall be asked for a password during copy operation.

Continue Reading

Building RTEMS (Real-Time Executive for Multiprocessor Systems) for Coldfire using Opensource Tools

It really took me a couple of days to set things straight for a successful build. Here are the steps that I followed. Before starting, make sure you have ca. 1GB free space as the temporary files can easily consume a lot of space. I built everything on andLinux running on a Windows XP host.

  • Create necessary folders:
    mkdir /usr/local/rtems/source
    mkdir /usr/local/rtems/source/tools
    mkdir /usr/local/rtems/rtems-4.8
  • Add the path:
    PATH="$PATH:/usr/local/rtems/rtems-4.8/bin"
  • Install the pre-requisites:
    apt-get install automake gdb bzip2 texinfo autoconf patch
  • Get and build the development tools:
    cd /usr/local/rtems/source/tools
    wget http://www.rtems.com/ftp/pub/rtems/SOURCES/binutils-2.18.tar.bz2
    wget http://www.rtems.com/ftp/pub/rtems/SOURCES/gcc-4.2.2.tar.bz2
    wget http://www.rtems.com/ftp/pub/rtems/SOURCES/newlib-1.15.0.tar.gz

    Unzip the files:
    bzcat binutils-2.18.tar.bz2 | tar xf -
    tar -xvzf newlib-1.15.0.tar.gz
    bzcat gcc-4.2.2.tar.bz2 | tar xf -

    Get and apply the patches:
    wget http://www.rtems.com/ftp/pub/rtems/SOURCES/binutils-2.18-rtems4.8-20071104.diff
    wget http://www.rtems.com/ftp/pub/rtems/SOURCES/newlib-1.15.0-rtems4.8-20071221.diff
    wget http://www.rtems.com/ftp/pub/rtems/SOURCES/gcc-core-4.2.2-rtems4.8-20071127.diff

    cd binutils-2.18
    patch -p1 <../binutils-2.18-rtems4.8-20071104.diff cd ..

    cd newlib-1.15.0
    patch -p1 <../newlib-1.15.0-rtems4.8-20071221.diff cd ..

    cd gcc-4.2.2
    patch -p1 <../gcc-core-4.2.2-rtems4.8-20071127.diff rm -rf newlib ln -s ../newlib-1.15.0/newlib newlib cd ..

    Make and instal necessary libraries

    wget http://ftp.sunet.se/pub/gnu/gmp/gmp-4.2.2.tar.gz
    tar -xvf gmp-4.2.2.tar.gz
    cd gmp-4.2.2
    ./configure
    make
    make install
    cd ..

    wget http://www.mpfr.org/mpfr-current/mpfr-2.3.1.tar.bz2
    bzcat mpfr-2.3.1.tar.bz2 | tar -xf -
    cd mpfr-2.3.1
    ./configure
    make
    make install
    cd ..

    Make a temporary build folder:
    rm -rf build
    mkdir build
    cd build

    ../binutils-2.18/configure -target=m68k-rtems4.8 -prefix=/usr/local/rtems/rtems-4.8
    make -w all install
    ldconfig
    cd ..

    If you want to get the latest version of CVS-head you may use:
    cd /usr/src/rtems-4.9-9MAY08/source
    cvs -d :pserver:anoncvs@www.rtems.com:/usr1/CVS login

    (Press ENTER for password)
    cvs -d :pserver:anoncvs@www.rtems.com:/usr1/CVS -z 9 co -P rtems
    cd rtems
    ./bootstrap
    (This will generate the configure script)
    cd ..
    In this case, however, the instructions given here may not apply exactly as they are.

    Clean the build folder:
    rm -rf build
    mkdir build
    cd build

    Now configure the gcc:
    ../gcc-4.2.2/configure -target=m68k-rtems4.8 \
    -prefix=/usr/local/rtems/rtems-4.8 \
    -with-gnu-as -with-gnu-ld -with-newlib -verbose \
    -with-system-zlib -disable-nls \
    -enable-version-specific-runtime-libs \
    -enable-threads=rtems \
    -enable-languages=c,c++

    make -w all (It can take about an hour and newlib will also be compiled along with)
    make -w install
    cd ..\..
    (pwd: source)

  • Get and build RTEMS-4.8

    wget http://www.rtems.com/ftp/pub/rtems/4.8.0/rtems-4.8.0.tar.bz2
    bzcat rtems-4.8.0.tar.bz2 | tar -xf -

    Make a clean build folder:
    rm -rf build
    mkdir build
    cd build

    Configure the rtems:
    ../rtems-4.8.0/configure -target=m68k-rtems4.8 \
    -prefix=/usr/local/rtems/rtems-4.8 \
    -enable-cxx -disable-tests -enable-networking \
    -enable-posix
    (-enable-docs is broken, results in @include `version.texi': No such file or directory.)

    Make the kernel for a given target:
    make -w RTEMS_BSP="av5282" install

    make RTEMS_BSP="uC5282" does not succeed because of the following gcc-4.2.2 error:
    '../../../../../../rtems-4.8.0/c/src/../../cpukit/shttpd/'`log.c
    ../../../../../../rtems-4.8.0/c/src/../../cpukit/shttpd/log.c: In function '_shttpd_log_access':
    ../../../../../../rtems-4.8.0/c/src/../../cpukit/shttpd/log.c:139: error: insn does not satisfy its constraints:
    (insn 74 158 159 10 ../../../../../../rtems-4.8.0/c/src/../../cpukit/shttpd/log.c:117 (set (mem/c:SI (plus:SI (reg/f:SI 14 %a6)
    (reg:SI 1 %d1)) [57 D.6862+0 S4 A16])
    (mem/s:SI (plus:SI (reg/v/f:SI 10 %a2 [orig:48 c ] [48])
    (const_int 220 [0xdc])) [2 .loc.io.total+0 S4 A16])) 34 {*movsi_cf} (nil)
    (nil))
    ../../../../../../rtems-4.8.0/c/src/../../cpukit/shttpd/log.c:139: internal compiler error: in reload_cse_simplify_operands, at
    postreload.c:392

    Install RTEMS:
    make -w install

  • Build Addon Packages For Command Line Utilities
    wget http://www.rtems.com/ftp/pub/rtems/4.8.0/rtems-addon-packages-4.8.0.tar.bz2

    Set the RTEMS_MAKEFILE_PATH variable to the BSP location:
    PATH="$PATH:/usr/local/rtems/rtems-4.8/bin"
    export RTEMS_MAKEFILE_PATH=/usr/local/rtems/rtems-4.8/m68k-rtems4.8/av5282
    cd /usr/local/rtems/source/rtems-addon-packages-4.8.0

    (If you have more than one targets, this needs to be done for each of them)
    Make the add-on tools
    sh bit

Continue Reading