This is an old revision of the document!
Porting FreeBSD to Android Emulator
** Student: astarasikov@FreeBSD.org ** Mentor: gavin@freebsd.org
Project description
Here I will describe the progress of porting FreeBSD to run on top of Android Emulator. Android Emulator runs on a lot of platforms and is easy to set up. It can be therefore used as 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.
Approach to solving the problem
I plan to look into how linux drivers for the Goldfish board are implemented and write the corresponding analogues for the FreeBSD kernel.
Deliverables
Midterm
- Check if timer is working fine
- Working PIC (Interrupt controller)
- 'pdev' driver (to detect which emulator features are enabled for the virtual device)
- Ethernet driver
Final
- MMC/SD card driver
- Framebuffer driver
- 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
Milestones
- 19 May: Started coding, pushed a prototype of a kernel that boots and outputs to UART
- 23 June: Mid-term submission
- 11 August: 'Pencils down' date
- 18 August: hard deadline
The Code
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
Useful Links
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 :)
Caveats
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.
How to compile
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
How to build a qemu-compatible zImage
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
How to run
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