qemu in cross building

31
1 QEMU in Cross Building Tetsuyuki Kobayashi

Upload: tetsuyuki-kobayashi

Post on 20-May-2015

3.242 views

Category:

Documents


4 download

DESCRIPTION

Using QEMU in cross compiling for embedded systems

TRANSCRIPT

Page 1: QEMU in Cross building

1

QEMU in

Cross Building

Tetsuyuki Kobayashi

Page 2: QEMU in Cross building

2

Who am I?

20+ years involved in embedded systems 10 years in real time OS, such as iTRON 10 years in embedded Java Virtual Machine Now Gcc, Linux, QEMU, Android, …

Blogs http://d.hatena.ne.jp/embedded/ (Personal) http://blog.kmckk.com/ (Corporate)

Twitter @tetsu_koba

Page 3: QEMU in Cross building

3

Today's topic

About QEMU Native build vs Cross build Easy but too slow: building on

system emulator Fast but too complex:

Scratchbox Just simple : building on user

mode QEMU

Page 4: QEMU in Cross building

4

Today's topic

About QEMU Native build vs Cross build Easy but too slow: building on

system emulator Fast but too complex:

Scratchbox Just simple : building on user

mode QEMU

Page 5: QEMU in Cross building

5

About QEMU

http://wiki.qemu.org/ QEMU is

a generic and open source machine emulatorand virtualizer.

Page 6: QEMU in Cross building

6

QEMU is used …

As virtualizer, KVM Xen VirtualBox

Host CPU == Target CPU Today I don't focus on this.

Page 7: QEMU in Cross building

7

QEMU is used …

As a system emulator, Host CPU != Target CPU Many open source projects such as:

Android Maemo Symbian ARM port of Open Solaris ...

Page 8: QEMU in Cross building

8

QEMU has …

Virtual disk. Many of virtual devices. Tiny Code Generator (TCG) to execute fast. Port redirector, Virtual network card. Bootloader to boot Linux kernel. gdbserver to connect gdb. …

Page 9: QEMU in Cross building

9

User mode QEMU

Emulate only user mode of linux. Not all system calls implemented,

but enough for building.

Page 10: QEMU in Cross building

10

Today's topic

About QEMU Native build vs Cross build Easy but too slow: building on

system emulator Fast but too complex:

Scratchbox Just simple : building on user

mode QEMU

Page 11: QEMU in Cross building

11

Native build vs Cross build

Native build – compile and run on the same machine.

Cross build – compile and run on the different arch machine. Embedded system does not have enough

CPU and memory for native building.

Page 12: QEMU in Cross building

Configure problem

In many open source project

$ configure$ make$ make install

This suppose to be native build. Configure generate many small programand compile and run to check environment.

This does not work on cross build.

Page 13: QEMU in Cross building

13

Today's topic

About QEMU Native build vs Cross build Easy but too slow: building on

system emulator Fast but too complex:

Scratchbox Just simple : building on user

mode QEMU

Page 14: QEMU in Cross building

Building on system QEMU

Apt-get works. Very easy to install compilers and libraries

Too slow to compile Emulating the whole system including kernel. Cannot take advantage of SMP becase

QEMU runs on single thread.

Page 15: QEMU in Cross building

15

Today's topic

About QEMU Native build vs Cross build Easy but too slow: building on

system emulator Fast but too complex:

Scratchbox Just simple : building on user

mode QEMU

Page 16: QEMU in Cross building

16

ScratchBox

Magical environment for cross building

running ARM executable using user mode QEMU

invoking the cross compiler on native

Page 17: QEMU in Cross building

17

ScratchBox 1

http://www.scratchbox.org/ Maemo project on Nokia mechanism

chroot binfmt_misc scratch-box-aware tool chains

Page 18: QEMU in Cross building

18

ScratchBox 2

http://www.freedesktop.org/wiki/Software/sbox2 Another implementation of scratch box Tool chain agnostic Hosted by Freedesktop.org mechanism

Wrap libc by PRELOAD magic of ld.so Hook system calls Insert QEMU when exec target binary Path name translation by LUA script

Page 19: QEMU in Cross building

19

ScratchBox* is

Pretty fast to compile Very hard to customize and

troubleshooting

Page 20: QEMU in Cross building

20

Today's topic

About QEMU Native build vs Cross build Easy but too slow: building on

system emulator Fast but too complex:

Scratchbox Just simple : building on user

mode QEMU

Page 21: QEMU in Cross building

21

Let's try simpler way

Just use user mode QEMU Use chroot and binfmt_misc Compiler running on QEMU, too

Page 22: QEMU in Cross building

22

binfmt_misc

Mechanism to execute foreign executable. ex) Used in Wine for dos executable. $ cat /proc/sys/fs/binfmt_misc/qemu-arm

enabledinterpreter /usr/bin/qemu-arm-staticflags: OCoffset 0magic 7f454c4601010100000000000000000002002800mask ffffffffffffff00fffffffffffffffffeffffff$

Page 23: QEMU in Cross building

23

Chroot

Make dedicated directory tree Used for public ftp server to make

sand box

Page 24: QEMU in Cross building

24

Static linked QEMU

Nice idea to avoid conflict in chrooted target root file system Dynamically linked QEMU needs so many library

files, which are likey conflict file names to target ones.

Static linked QEMU is stand alone. Just copy one file to target root file system.

I found this idea in rootstock script in Ubuntu

Page 25: QEMU in Cross building

25

Just Try

Make arm root file system by rootstock on Ubuntu 10.04

$ sudo apt-get install rootstock$ mkdir arm-ubuntu$ cd arm-ubuntu/$ sudo rootstock --fqdn arm-lucid --login user --password user

$ mkdir root$ cd root$ sudo tar xvf ../armel-rootfs-201005031740.tgz

It takes more than 10 minutes ...

Page 26: QEMU in Cross building

26

Just Try

$ lsbin dev home lost+found mnt proc sbin srv tmp varboot etc lib media opt root selinux sys usr$ uname -mx86_64

$ sudo chroot . /bin/bash## uname -marmv7l

Page 27: QEMU in Cross building

27

Build time comparison

80min (on system QEMU) 8min (user mode QEMU, make -j4) http://blog.kmckk.com/archives/2342452.html

Not yet try on scratchbox.It would be faster if I could.

Page 28: QEMU in Cross building

28

/proc

ps command fails

Don't worry. Mount /proc

# psCannot find /proc/version - is /proc mounted?

# mount proc /proc -t proc# ps PID TTY TIME CMD15434 ? 00:00:00 bash15440 ? 00:00:00 ps#

Page 29: QEMU in Cross building

29

Networking

Failed to resolve name OK, just add ip address to /etc/hosts# cat /etc/hosts127.0.0.1 localhost ubuntu1004127.0.1.1 arm-lucid91.189.88.36 ports.ubuntu.com

Then apt-get works. So far, it's enough.

Page 30: QEMU in Cross building

30

Distcc http://code.google.com/p/distcc/ Preprocessing and linking locally. Compiling and assembling remotely. Invoke cross compiler remotely. Distcc will enhance build time.

Page 31: QEMU in Cross building

31

Q & A

& Demo

Thank you for listening!Any comments to blogs are welcome.