summerofcode2014:portingtoandroidemulator

This is an old revision of the document!


Here I will describe the progress of porting FreeBSD to run on top of Android Emulator.

Why?

Because Android Emulator runs on a lot of platforms and is easy to set up. And also to have a unified platform for hacking FreeBSD on ARM.

What's Android Emulator?

It's a fork of Qemu emulator with a new emulated SoC and a board called Goldfish. A somewhat nicer UI is also included.

Currently the source code is at my github repo and I have some unpushed code since writing this page. I plan to push it to the GSoC SVN by the end of the week. Use the android_goldfish_arm_10.0.0 branch at the repository

Android Emulator supports ARMv5 (ARM926E) and ARM1136 cores, but not the coprocessor register instruction for domain control for these SoCs. Since we want to run on a vanilla emulator, let's just rely on the fact that the emulator also supports emulating ARM Cortex-A8 and only build FreeBSD for ARMv7

The latest version of Android Emulator is identical to QEMU in that it loads the kernel binary to 0x10000 (yes, 64K, not 1M) and jumps there. So let's just do what the versatilepb board does - link FreeBSD to 0x100000 (1M) and set up a trampoline. It should theoretically be possible to save some memory by linking to 0x10000 but I assume the kernel initially maps memory by 1M sections and that will fail unless additional patching is done.

Oh well, need to update with a script to build from an external directory

#!/usr/local/bin/bash
export TARGET=arm
export TARGET_ARCH=armv6
export DESTDIR=/root/handhelds/arm
export KERNCONF=GOLDFISH
pushd .
cd /usr/src/
make -j10 buildkernel KERNCONF=GOLDFISH
popd

Apprarently the same way as Versatile PB. Though, maybe this should be done by an LD script in kernel instead.

#!/bin/sh
KERN=/usr/obj/arm.armv6/usr/src/sys/GOLDFISH/kernel.bin
rm ./header
rm ./flash
/usr/bin/printf "\0\0\240\343" > header
/usr/bin/printf "\0\020\240\343" >> header
/usr/bin/printf "\0\040\240\343" >> header
/usr/bin/printf "\0\060\240\343" >> header
/usr/bin/printf "\001\366\240\343" >> header
dd of=flash bs=1M count=4 if=/dev/zero
dd of=flash bs=1 conv=notrunc if=header
dd of=flash bs=64k oseek=15 conv=notrunc if=$KERN

Create an Android Virtual device (install the SDK, run 'android'). Be sure to select an ARMv7A target (basically, installing an SDK for Android 4.X will make ARMv7A the default target). Name your AVD (Android Virtual Device) 'FreeBSD' (though I assume it will work even if you call it 'Windows 8')

Launch it from console specifying the avd name and the kernel file name ('flash' in this case)

emulator -shell-serial stdio -show-kernel -shell -avd FreeBSD  -kernel flash -qemu
  • Check if timer is working fine
  • Working PIC (Interrupt controller)
  • Ethernet driver
  • MMC/SD card driver
  • Framebuffer driver
  • 'pdev' driver (to detect which emulator features are enabled for the virtual device)
  • Prebuilt images for sharing
  • Port FreeBSD a some real phone (if progress is done w/emulator by midterm). I'll be using a Nexus 5 phone with Qualcomm MSM8974 CPU

http://benno.id.au/blog/2007/11/29/android-qemu - Description of the emulated board (Goldfish). Oh, and the up-to-date emulator does not contain the mentioned bugs :)

  • summerofcode2014/portingtoandroidemulator.1400769481.txt.gz
  • Last modified: 2014/05/22 14:38
  • by AlexanderTarasikov