summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'xml/htdocs/proj/en/base/embedded/handbook/cross-qemu.xml')
-rw-r--r--xml/htdocs/proj/en/base/embedded/handbook/cross-qemu.xml112
1 files changed, 112 insertions, 0 deletions
diff --git a/xml/htdocs/proj/en/base/embedded/handbook/cross-qemu.xml b/xml/htdocs/proj/en/base/embedded/handbook/cross-qemu.xml
new file mode 100644
index 00000000..2fa4a021
--- /dev/null
+++ b/xml/htdocs/proj/en/base/embedded/handbook/cross-qemu.xml
@@ -0,0 +1,112 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!DOCTYPE sections SYSTEM "/dtd/book.dtd">
+<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/proj/en/base/embedded/handbook/cross-qemu.xml,v 1.4 2010/08/30 03:59:07 nightmorph Exp $ -->
+
+<!-- The content of this document is licensed under the CC-BY-SA license -->
+<!-- See http://creativecommons.org/licenses/by-sa/2.5 -->
+
+<sections>
+
+<abstract>
+How To compile with QEMU user.
+</abstract>
+
+<version>0.2</version>
+<date>2010-02-14</date>
+
+<section>
+<title>Usage</title>
+<body>
+
+<p>
+In order to take advantage of qemu-user mode we need to do a few things. First
+we need to merge the main package we are going to need. Note the use of the
+<c>static</c> use flag.
+</p>
+
+<pre caption="Installing qemu-user">
+# <i>USE=static emerge -b1 app-emulation/qemu-user</i>
+</pre>
+
+<p>
+Next we need to build the kernel module <c>binfmt_misc</c>.
+Add this to your kernel <path>.config</path>:
+<c>CONFIG_BINFMT_MISC=m</c> or <c>CONFIG_BINFMT_MISC=y</c>.
+If this module is not built already, then the devel host will require a
+reboot after the kernel update and modules_install.
+</p>
+
+<p>
+Mount the <c>binfmt_misc</c> handler if it's not already, then we need to
+register our format with the kernel via the procfs.
+</p>
+
+<pre caption="binfmt_misc">
+# <i>[ -d /proc/sys/fs/binfmt_misc ] || modprobe binfmt_misc</i>
+# <i>[ -f /proc/sys/fs/binfmt_misc/register ] || mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc</i>
+<comment>(Do not register a handler that matches the host machine)</comment>
+# <i>echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/</i>qemu-wrapper<i>:' > /proc/sys/fs/binfmt_misc/register</i>
+# <i>echo ':armeb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-armeb:' > /proc/sys/fs/binfmt_misc/register</i>
+# <i>echo ':alpha:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-alpha:' > /proc/sys/fs/binfmt_misc/register</i>
+# <i>echo ':mips:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-mips:' > /proc/sys/fs/binfmt_misc/register</i>
+# <i>echo ':mipsel:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-mipsel:' > /proc/sys/fs/binfmt_misc/register</i>
+# <i>echo ':ppc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-ppc:' > /proc/sys/fs/binfmt_misc/register</i>
+# <i>echo ':sh4:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff\xff:/usr/bin/qemu-sh4:' >/proc/sys/fs/binfmt_misc/register</i>
+# <i>echo ':sh4eb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-sh4eb:' >/proc/sys/fs/binfmt_misc/register</i>
+# <i>echo ':sparc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-sparc:' > /proc/sys/fs/binfmt_misc/register</i>
+
+</pre>
+
+<pre caption="Enter/Exit the chroot">
+<comment>(Download your desired stage tarball)</comment>
+# <i>wget http://arch-stageball</i>
+<comment>(Unpack the tarball)</comment>
+# <i>tar -xzvf arch-stageball</i>
+# <i>cd arch-stageball</i>
+<comment>(Install the static qemu-user into the chroot)</comment>
+# <i>ROOT=$PWD/ emerge -K qemu-user</i>
+# <i>mkdir -p usr/portage</i>
+<comment>(Mount the required directories)</comment>
+# <i>mount --bind /usr/portage usr/portage</i>
+# <i>mount --bind /proc proc</i>
+# <i>mount --bind /sys sys</i>
+<comment>(Chroot into the environment)</comment>
+# <i>chroot . /bin/busybox mdev -s</i>
+# <i>chroot . /bin/bash --login</i>
+<comment>(Unmount stuff when not in use)</comment>
+# <i>umount usr/portage</i>
+# <i>umount sys</i>
+# <i>umount proc</i>
+</pre>
+
+<p>
+Sometimes we'll need to pass additional args to QEMU (cpu model), so we'll
+create a wrapper script that'll call QEMU with it.
+</p>
+
+<pre caption="qemu-wrapper">
+#include &lt;stdio.h&gt;
+#include &lt;unistd.h&gt;
+
+int main(int argc, char **argv, char **envp) {
+ char *newargv[argc + 3];
+
+ newargv[0] = argv[0];
+ newargv[1] = "-cpu";
+ newargv[2] = "<i>cortex-a8</i>";
+
+ memcpy(&amp;newargv[3], &amp;argv[1], sizeof(*argv) * (argc - 1));
+ newargv[argc + 2] = NULL;
+ return execve("<i>/usr/bin/qemu-arm</i>", newargv, envp);
+}
+</pre>
+
+<p>
+Compile the wrapper with <c>gcc -static qemu-wrapper.c -o qemu-wrapper</c> and
+copy into the chroot. Notice the first example arm entry in the
+<c>binfmt_misc</c> section uses this method.
+</p>
+
+</body>
+</section>
+</sections>