Skip to content

Getting started with MIPS Dartino

gferenc edited this page May 13, 2016 · 55 revisions

What to do first?

Prerequisites

If you have already installed following packages skip this step:

$ sudo dpkg --add-architecture i386
$ sudo apt-get update
$ sudo apt-get install gcc-multilib g++-multilib  <sup>[1](#why_i386)</sup>
$ sudo apt-get install lib32stdc++6

Install depot tools (to get gclient, git cl, and ninja)

Confirm git is installed. git 2.2.1+ recommended.

Fetch depot tools

$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

Add depot_tools to your PATH:

$ export PATH='pwd'/depot_tools:"$PATH"

Build qemu

If you have already built the qemu skip this step.

Install required packages:

$ sudo apt-get install git libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev

Get the source:

$ git clone git://git.qemu-project.org/qemu.git
$ cd qemu
$ ./configure
$ make -j8

Get MIPS cross-compilation toolchain:

Suggest using Codescape SDK 2015.06-05.

$ wget http://codescape-mips-sdk.imgtec.com/components/toolchain/2015.06-05/Codescape.GNU.Tools.Package.2015.06-05.for.MIPS.MTI.Linux.CentOS-5.x86_64.tar.gz

Install and setup binfmt misc to run MIPS little endian binaries:

Install the binfmt misc package on Ubuntu 14.04 with the following command:

$ sudo apt-get install binfmt-support

Write a script (mips32_qemu.sh) to run MIPS32 little endian binaries.Replace the qemu variable with the path to the mipsel-linux-user/qemu-mipsel previously built QEMU binary.

#!/bin/bash

qemu=/path/to/qemu/mipsel-linux-user/qemu-mipsel

exec $qemu $*

Change the access permissions of a script:

$ sudo chmod +x /path/to/mips32_qemu.sh

The script should be able to take a MIPS32 little endian binary and all it's options and run it under QEMU. A simple test is to cross compile "hello world" for MIPS32 little endian. Then, use your script to see that it correctly prints out "hello, world".

Setup binfmt misc to run your script when the kernel detects it's trying to run a MIPS32 little endian binary. Here is the command to setup binfmt for MIPS32 little endian using your MIPS32 little endian script:

$ sudo update-binfmts --install mipsel-qemu /path/to/mips32_qemu.sh --magic '\x7fELF\x01\x01\x01\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' --mask '\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' --credentials yes --package qemu-user-static

Build hello_world.c for MIPS:

$ /path/to/Codescape/SDK/2015.06-05/bin/mips-mti-linux-gnu-gcc -EL -static -o hello hello_world.c

If binfmt is configured correctly, you should be able to run this program:

$ ./hello

Getting the Sources

$ mkdir dartino
$ cd dartino
$ fetch dartino
$ cd sdk

Get MIPS related changes and update your checkout

$ git checkout -b mips-dev
$ git remote add alt https://github.com/petar-jovanovic/sdk.git
$ git fetch --progress --prune alt 
$ git branch --set-upstream-to=alt/mips-dev mips-dev
$ git pull

Set up cross-compilation environment

$ export PATH=/path/to/Codescape/SDK/2015.06-05/bin/:$PATH
$ export LDSO_PATH=/path/to/Codescape/SDK/2015.06-05/sysroot/mipsel-r2-hard/lib/ld.so.1
$ export LD_R_PATH=/path/to/Codescape/SDK/2015.06-05/sysroot/mipsel-r2-hard/lib:/path/to/Codescape/SDK/2015.06-05/sysroot/mipsel-r2-hard/usr/lib:/path/to/Codescape/SDK/2015.06-05/mips-mti-linux-gnu/lib/mipsel-r2-hard/lib

Build Dartino for MIPS (cross-compiling for MIPS)

$ ninja -t clean
$ ninja
$ ninja -C out/DebugXMIPS -t clean
$ ninja -C out/DebugXMIPS

Test Dartino for MIPS

$ tools/test.py --build-before-testing=0 --run-gclient-hooks=0 -axmips

1: Comment.