<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Soul Of Free Loop &#187; QEMU</title>
	<atom:link href="https://zohead.com/archives/tag/qemu/feed/" rel="self" type="application/rss+xml" />
	<link>https://zohead.com</link>
	<description>Uranus Zhou&#039;s Blog</description>
	<lastBuildDate>Sat, 19 Jul 2025 15:42:46 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.8</generator>
	<item>
		<title>龙芯MIPS64 QEMU ioctl的问题</title>
		<link>https://zohead.com/archives/loongson-qemu-ioctl/</link>
		<comments>https://zohead.com/archives/loongson-qemu-ioctl/#comments</comments>
		<pubDate>Wed, 26 Dec 2018 16:59:20 +0000</pubDate>
		<dc:creator><![CDATA[Uranus Zhou]]></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[ioctl]]></category>
		<category><![CDATA[MIPS64]]></category>
		<category><![CDATA[QEMU]]></category>
		<category><![CDATA[龙芯]]></category>

		<guid isPermaLink="false">https://zohead.com/?p=1561</guid>
		<description><![CDATA[龙芯 QEMU 问题 最近搞了一块使用国产龙芯 3A3000 处理器的开源开发板，顺便捣鼓移植我们的服务程序，安装龙芯开源社区的 Loongnix 系统之后测试下来 3A3000 处理器的性能还是基本能用的。龙芯处理器自带的内存控制器也能到 DDR3-1600 了，只是目前还在使用 HT3.0 总线确实拖累系统性能。 我们部署的一些服务目前还依赖几个 x86 系统的闭源程序，无法直接在龙芯 MIPS64 系统下运行，就想到使用 QEMU 的 User-mode emulation 来实现了。 Loongnix 系统中的 qemu-i386 运行比较简单的 x86 程序一般都没有问题，不过我发现 [&#8230;]]]></description>
				<content:encoded><![CDATA[<h2 id="loongson-qemu-issue">龙芯 QEMU 问题</h2>
<p>最近搞了一块使用国产<a href="http://www.loongson.cn/product/cpu/3/3A3000.html" target="_blank">龙芯 3A3000</a> 处理器的开源开发板，顺便捣鼓移植我们的服务程序，安装龙芯开源社区的 <a href="http://www.loongnix.org/" target="_blank">Loongnix</a> 系统之后测试下来 3A3000 处理器的性能还是基本能用的。龙芯处理器自带的内存控制器也能到 DDR3-1600 了，只是目前还在使用 HT3.0 总线确实拖累系统性能。</p>
<p>我们部署的一些服务目前还依赖几个 x86 系统的闭源程序，无法直接在龙芯 MIPS64 系统下运行，就想到使用 QEMU 的 User-mode emulation 来实现了。</p>
<p>Loongnix 系统中的 qemu-i386 运行比较简单的 x86 程序一般都没有问题，不过我发现即使用打了 ioctl patch 的 QEMU 运行其中一个使用了私有 ioctl 调用的 x86 程序仍然会出错，通过开启 qemu-i386 的 strace 可以看到错误信息：</p>
<pre class="brush: bash; title: ; notranslate">
zzm@loongnix:~$ qemu-i386 -strace /lib/i386-linux-gnu/ld-linux.so.2 --library-path /lib/i386-linux-gnu /usr/sbin/test-agent

2459 ioctl(5,-1055634175,-42368,0,0,-42056) = -1 errno=25 (Inappropriate ioctl for device)
2459 ioctl(5,-1055634175,-41488,0,0,-41176) = -1 errno=25 (Inappropriate ioctl for device)
2459 ioctl(5,-1055634175,-44192,0,0,-43880) = -1 errno=25 (Inappropriate ioctl for device)
</pre>
<p>上面的 <code>/usr/sbin/test-agent</code> 就是要模拟运行的 x86 二进制程序，<code>/lib/i386-linux-gnu</code> 是我在龙芯 MIPS64 系统上增加的 x86 程序依赖基础库目录，其中最重要的就是 <code>libc.so.6</code> 和 <code>ld-linux.so.2</code> 库了。</p>
<p>从 strace 数据应该可以发现该 ioctl 已经发到设备，但是 kernel 返回 <code>Inappropriate ioctl</code> 错误，而 <code>-1055634175</code>  则表示 x86 二进制程序发送的是 compat ioctl，此时我才想起来确认下 qemu-i386 程序是否正确：</p>
<pre class="brush: bash; title: ; notranslate">
zzm@loongnix:~$ file `which qemu-i386`
/usr/bin/qemu-i386: ELF 64-bit LSB executable, MIPS, MIPS64 rel2 version 1 (SYSV), dynamically linked (uses shared libs), BuildID[sha1]=39cac8103f052b4ffa161f615159c888024ef4e3, for GNU/Linux 2.6.32, stripped
</pre>
<p>龙芯 Loongnix MIPS64 系统目前兼容几种 ABI：</p>
<ul>
<li>O32：MIPS 32 位处理器使用；</li>
<li>N64：只适用于 MIPS 64 位处理器，使用 64 位指针和 long integers；</li>
<li>N32：只适用于 MIPS 64 位处理器，在保留 MIPS N64 ABI 的几乎所有特性的情况下，使用 32 位指针和 long integers。</li>
</ul>
<p>这个 qemu-i386 使用的是 MIPS64 N64 ABI，而 qemu-i386 实际运行的 x86 二进制程序在龙芯 64 位 kernel 下会发送 compat ioctl，这样最终 qemu-i386 程序调用 compat ioctl 时就显然会有问题，报 <code>Inappropriate ioctl</code> 也就不奇怪了。</p>
<p>解决方法也就很简单了，我只要重新编译出使用 N32 或者 O32 ABI 的 qemu-i386 程序应该就能解决，为了性能考虑可以尽量使用 N32 ABI。</p>
<h2 id="n32-abi-qemu">编译 N32 ABI QEMU</h2>
<p>首先需要在 Loongnix MIPS64 系统下安装编译 QEMU 需要的 N32 版本的开发包，这里我只安装了 QEMU 用户模式需要的开发包：</p>
<pre class="brush: bash; title: ; notranslate">
zzm@loongnix:~$ yum install glibc-devel.mipsn32el glib2-devel.mipsn32el zlib-devel.mipsn32el libffi.mipsn32el pixman-devel.mipsn32el
</pre>
<blockquote>
<p><strong>提示</strong></p>
<p>Loongnix 系统的 N64 相关库文件一般放在 <code>/usr/lib64</code> 目录下，N32 相关库文件在 <code>/usr/lib32</code> 目录下，而 O32 相关库文件则在 <code>/usr/lib</code> 目录下。</p>
</blockquote>
<p>然后进入 QEMU 源代码目录重新 configure，增加特定编译参数指定生成 N32 位的程序：</p>
<pre class="brush: bash; title: ; notranslate">
zzm@loongnix:qemu$ PKG_CONFIG_LIBDIR=/usr/lib32/pkgconfig ./configure --target-list=i386-linux-user --disable-kvm --disable-xen --enable-pie --extra-cflags=-mabi=n32
</pre>
<p>简单说明一下：</p>
<ul>
<li><code>PKG_CONFIG_LIBDIR</code> 环境变量指定使用什么版本的 pkgconfig 查找库及开发包，这里使用 <code>/usr/lib32/pkgconfig</code> N32 版本；</li>
<li><code>--target-list</code> 指定 QEMU 编译目标，这里我们只需要 qemu-i386，因此把 KVM、Xen 等功能也禁用了；</li>
<li><code>--extra-cflags</code> 指定额外编译参数为 <code>-mabi=n32</code>，这样编译和链接时都是 N32 版本了。</li>
</ul>
<p>重新编译安装之后可以看到新的 qemu-i386 使用的就是 N32 ABI 了：</p>
<pre class="brush: bash; title: ; notranslate">
zzm@loongnix:~$ file `which qemu-i386`
/usr/local/bin/qemu-i386: ELF 32-bit LSB executable, MIPS, N32 MIPS64 rel2 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=12e0025c42a9a63b8045c31159950f9b185f8745, stripped
</pre>
<p>最后测试使用新的 qemu-i386 运行依赖 ioctl 的 x86 二进制程序，现在就没有直接报错的问题了。</p>
]]></content:encoded>
			<wfw:commentRss>https://zohead.com/archives/loongson-qemu-ioctl/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>使用Exagear Desktop在ARM Chromebook上运行x86程序</title>
		<link>https://zohead.com/archives/exagear-chromebook/</link>
		<comments>https://zohead.com/archives/exagear-chromebook/#comments</comments>
		<pubDate>Thu, 15 Oct 2015 15:25:51 +0000</pubDate>
		<dc:creator><![CDATA[Uranus Zhou]]></dc:creator>
				<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[技术]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[binfmt_misc]]></category>
		<category><![CDATA[Chromebook]]></category>
		<category><![CDATA[Eltechs]]></category>
		<category><![CDATA[Exagear]]></category>
		<category><![CDATA[QEMU]]></category>

		<guid isPermaLink="false">http://zohead.com/?p=1048</guid>
		<description><![CDATA[关于 Exagear Desktop 有 ARM Chromebook 使用经验的朋友们应该都知道 ARM Chromebook 在可折腾性上要比 x86 的 Chromebook 要差上不少，最主要一个原因就是在 Crouton 下的 ARM Linux 无法运行很多流行的 x86 应用程序。 之前我写过一篇在 Raspberry Pi 上运行 x86 Sopcast 程序的文章，这个主要是使用 QEMU 的用户模式实现在 ARM Linux 上运行 x86 的应用程序，但这种方式的主要问题是 QEMU 的性能比较差。一个比较好的消息是国外的 Eltechs 公司推出的 Exgear Des [&#8230;]]]></description>
				<content:encoded><![CDATA[<h2 id="about-exagear-desktop">关于 Exagear Desktop</h2>
<p>有 ARM Chromebook 使用经验的朋友们应该都知道 ARM Chromebook 在可折腾性上要比 x86 的 Chromebook 要差上不少，最主要一个原因就是在 Crouton 下的 ARM Linux 无法运行很多流行的 x86 应用程序。</p>
<p>之前我写过一篇在 <a href="https://zohead.com/archives/raspberry-pi-sopcast/" target="_blank">Raspberry Pi 上运行 x86 Sopcast</a> 程序的文章，这个主要是使用 QEMU 的用户模式实现在 ARM Linux 上运行 x86 的应用程序，但这种方式的主要问题是 QEMU 的性能比较差。一个比较好的消息是国外的 Eltechs 公司推出的 Exgear Desktop 软件宣称可以在 ARM Linux 上以接近 x86 原生的性能运行 x86 Linux 程序，综合性能是 QEMU 的 5 倍。这样对于我的三星 ARM Chromebook 来说可是相当有用的，因此考虑买一个授权（你没看错，<code>Exagear Desktop</code> 是收费软件，根据设备不同需要 20-30 美元）看看实际效果。</p>
<p>有关 <code>Exagear Desktop</code> 的介绍可以参考 Eltechs 的介绍页面：</p>
<p><a href="http://eltechs.com/product/exagear-desktop/" target="_blank">http://eltechs.com/product/exagear-desktop/</a></p>
<p>花了 30 美元购买 <code>Exagear Desktop</code> 之后 Eltechs 会将软件下载方式及授权文件以邮件方式发过来，通过 Google Drive 下载安装。</p>
<h2 id="install-exagear-desktop">安装 Exagear Desktop</h2>
<p>安装之前可以了解下 <code>Exagear Desktop</code> 的系统概念，运行 ARM Linux 的主机系统被称为 <code>host system</code>，需要运行的 x86 系统被称为 <code>guest system</code>，首先需要先确认所使用的 ARM 设备是否满足要求：</p>
<ul>
<li>ARMv6 或 ARMv7 CPU；</li>
<li>512MB 或更多的内存；</li>
<li>Ubuntu 12.04 14.04 或者 Debian 之类的系统</li>
</ul>
<p>上面的几个要求对于 ARM Chromebook 没有压力了，如果想省事可以直接使用 Crouton 安装 Ubuntu 系统使用。这里我使用 XUbuntu 14.04 armhf 系统测试 <code>Exagear Desktop</code> 的效果。</p>
<p>解压缩 <code>Exagear Desktop</code> 的安装包，可以看到类似这些文件：</p>
<pre class="brush: bash; title: ; notranslate">
chronos@localhost ~ $ ls exagear/
eltechs_exagear_desktop_1.1_guide.pdf  exagear-guest-debian-7-wine2g_3_all.deb  exagear-mem2g_2254-1_armhf.deb
exagear_2254-1_armhf.deb               exagear-guest-ubuntu-1204lts_9_all.deb   install-exagear.sh
exagear-guest-debian-7_3_all.deb       exagear-guest-ubuntu-1404lts_1_all.deb   README
</pre>
<p><code>Exagear Desktop</code> 提供了 Debian 7、Ubuntu 12.04、Ubuntu 14.04 等几种不同的 x86 系统，一般按照 user guide PDF 文件的介绍运行 <code>install-exagear.sh</code> 脚本就可以自动完成安装，中间会提示你安装哪种类型的 x86 guest 系统，选择之后会自动通过网络加载安装 x86 的应用包。</p>
<p>安装完成之后运行 <code>exagear-ls</code> 命令可以查看已经安装的客户机系统，直接运行 <code>exagear</code> 命令就可以进入 x86 客户系统，进行 x86 环境之后可以直接运行或安装 x86 的应用程序。</p>
<h2 id="about-binfmtmisc">关于 binfmt_misc</h2>
<p>Eltechs 建议为了达到无缝运行 x86 程序的效果（特别是能更好的支持运行 需要 SUID 或者 SGID 的 x86 程序），ARM Linux host 系统里最好能支持 <code>binfmt_misc</code>。</p>
<p>不过 Chromebook 上的 Linux kernel 一般没有自带这个，需要自己编译，可以参考我之前写的文章 <a href="https://zohead.com/archives/koding-chromebook/" target="_blank">在Koding云平台上编译Chromebook kernel</a> 自己编译 Chromebook 下的 <code>binfmt_misc</code> 模块。</p>
<p>另外由于 <code>binfmt_misc</code> 没有默认在 Chromebook kernel 中，这样即使加载手工 <code>binfmt_misc</code> 模块之后也是没有 <code>/proc/sys/fs/binfmt_misc</code> 目录的，你需要在 Crouton 等 ARM Linux host 系统中创建 <code>/var/binfmt_misc</code> 目录，这样 <code>Exagear Desktop</code> 服务在启动时才可以自动挂载并启用 <code>binfmt_misc</code> 支持（具体可以参考 <code>/etc/init.d/exagear</code> 服务脚本）。</p>
<p>另外我在 <code>/etc/init.d/exagear</code> 服务脚本里加了一条自动加载 <code>binfmt_misc</code> 模块的处理（Chromebook 的 Crouton 上仍然需要自行编译并安装到系统模块目录中）：</p>
<pre class="brush: bash; title: ; notranslate">
[ -d /sys/module/binfmt_misc ] || modprobe binfmt_misc
</pre>
<h2 id="sum-up">总结</h2>
<p>最后从我最近简单的测试情况来看，<code>Exagear Desktop</code> 对于 x86 程序的兼容性做的还是不错的，平常用的 Sublime Text、Skype 之类的软件可以正常运行，TeamViewer 用起来似乎也无碍，虽然我最想用的 Visual Studio Code 还是运行不了有点遗憾。实际 x86 程序的运行速度也是比较接近 ARM 程序的体验呢。</p>
<p>最后放张 Sublime Text 在我的三星 ARM Chromebook 上的运行效果：</p>
<div style="width: 716px" class="wp-caption alignnone"><a href="http://res.cloudinary.com/digwht2y0/image/upload/v1737371060/exagear-sublime.png" target="_blank"><img alt="Sublime Text on ARM Chromebook" src="http://res.cloudinary.com/digwht2y0/image/upload/v1737371060/exagear-sublime.png" width="706" height="507" /></a><p class="wp-caption-text">Sublime Text on ARM Chromebook</p></div>
<p>祝各位玩的开心～～～</p>
]]></content:encoded>
			<wfw:commentRss>https://zohead.com/archives/exagear-chromebook/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Raspberry Pi上观看Sopcast视频</title>
		<link>https://zohead.com/archives/raspberry-pi-sopcast/</link>
		<comments>https://zohead.com/archives/raspberry-pi-sopcast/#comments</comments>
		<pubDate>Thu, 02 Jan 2014 07:58:03 +0000</pubDate>
		<dc:creator><![CDATA[Uranus Zhou]]></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[XBMC]]></category>
		<category><![CDATA[技术]]></category>
		<category><![CDATA[树莓派]]></category>
		<category><![CDATA[QEMU]]></category>
		<category><![CDATA[Sopcast]]></category>
		<category><![CDATA[sp-sc-auth]]></category>
		<category><![CDATA[XSopcast]]></category>
		<category><![CDATA[插件]]></category>
		<category><![CDATA[虚拟机]]></category>
		<category><![CDATA[视频]]></category>

		<guid isPermaLink="false">http://zohead.com/?p=652</guid>
		<description><![CDATA[本文同步自（最佳显示效果请点击）：https://zohead.com/archives/raspberry-pi-sopcast/ Sopcast 是一种国外比较受欢迎的 P2P 流媒体直播软件，可以运行在 Windows、Linux、Android 等平台，近日想在 Raspberry Pi 树莓派板子上看 Sopcast 直播视频看球赛，经过搜索之后终于找到一种曲线解决的办法。 目前树莓派上的 Android 还基本处于不能用的阶段，Raspberry Pi 由于是 ARM 架构的嵌入式板子，也无法运行 x86 版本的 Sopcast Linux 客户端程序，因此只能另想办法。 这里就要 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>本文同步自（最佳显示效果请点击）：<a href="https://zohead.com/archives/raspberry-pi-sopcast/" target="_blank">https://zohead.com/archives/raspberry-pi-sopcast/</a></p>
<p>Sopcast 是一种国外比较受欢迎的 P2P 流媒体直播软件，可以运行在 Windows、Linux、Android 等平台，近日想在 Raspberry Pi 树莓派板子上看 Sopcast 直播视频看球赛，经过搜索之后终于找到一种曲线解决的办法。</p>
<p>目前树莓派上的 Android 还基本处于不能用的阶段，Raspberry Pi 由于是 ARM 架构的嵌入式板子，也无法运行 x86 版本的 Sopcast Linux 客户端程序，因此只能另想办法。</p>
<p>这里就要用到 QEMU 这个著名的虚拟机的 user mode 用户模式了，而通常使用的虚拟机都是 system mode 系统模式。通过使用 QEMU 的用户模式，可以在当前的系统环境下直接模拟运行其它架构下的程序，因此想到在 Raspberry Pi 当前的 armhf 环境下使用 qemu-i386 在用户模式下运行 x86 架构下的 Sopcast Linux 客户端程序。</p>
<p>有关 QEMU 用户模式的介绍请参考这里：</p>
<p><a href="http://wiki.debian.org/QemuUserEmulation" target="_blank">http://wiki.debian.org/QemuUserEmulation</a></p>
<p>你如果有兴趣的话可以自己下载 QEMU 的源代码并在 Raspberry Pi 下编译，这里为了省事我就直接用网上已经编译好的了，可以从我共享的微云网盘里下载：</p>
<p><a href="http://share.weiyun.com/cfeea0d9b415d625309d1bb420a4150b" target="_blank">http://share.weiyun.com/cfeea0d9b415d625309d1bb420a4150b</a></p>
<p>解压拷贝到 Raspberry Pi 系统中，假设为 <strong>/home/sopcast</strong> 目录中，其中有 sp-sc-auth 这个 x86 系统下的 Sopcast Linux 客户端程序，然后在 /usr/bin 目录下产生一个名为 sp-sc-auth 的脚本文件，内容如下（路径请自行修改）：</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/sh
cd /home/sopcast
exec ./qemu-i386 lib/ld-linux.so.2 --library-path lib ./sp-sc-auth $@
</pre>
<p>此脚本中使用 exec 的目的是方便后面的 Xsopcast XBMC 插件在停止播放节目时可以正常结束掉 sp-sc-auth 进程（保持进程 PID 不变这样 XBMC 系统可以跟踪）。</p>
<p>然后在 Raspberry Pi 系统中运行 sp-sc-auth 命令测试是否可以正常连接 Sopcast 服务器并打开节目，这里以 CCTV-13 频道地址为例：</p>
<p><strong>sp-sc-auth sop://124.232.150.188:3912/9767 9000 9001</strong></p>
<p>稍微片刻，如果连接正常的话就会不断产生数据输出。</p>
<p>下面就是使用的问题了，你如果想在 Raspberry Pi 的 X 界面下使用的话，可以安装 Linux 下的 Sopcast Player 软件来播放，这是一个 X 环境下的 Sopcast 的前端 GUI 界面：</p>
<p><a href="http://code.google.com/p/sopcast-player/" target="_blank">http://code.google.com/p/sopcast-player/</a></p>
<p>如果你是和我一样用的 XBian 之类的 XBMC 多媒体系统，那可以直接安装 XSopcast 这一 XBMC 插件，让这个插件自动来运行 sp-sc-auth 客户端程序，有关此插件的介绍请参考这里：</p>
<p><a href="http://forum.xbmc.org/showthread.php?tid=129996" target="_blank">http://forum.xbmc.org/showthread.php?tid=129996</a></p>
<p>安装好此插件之后，首先安装上面的步骤将 <strong>sp-sc-auth</strong> 脚本放到 /usr/bin 目录下，然后再进入 XBMC 系统的 视频 - 扩展插件 - XSopcast，就可以看到 SopCast 节目列表了，点击一个节目就可以观看了。如果没有做 sp-sc-auth 脚本操作，第一次启动 XSopCast 插件的时候，插件会自动从网络下载 sp-sc-auth 程序，但下载的 Linux 客户端程序是 x86 版本不能运行的。</p>
<p>细心的朋友如果在播放的时候在 Raspberry Pi Linux 后台运行 ps ax 命令就可以看到 qemu-i386 启动的 sp-sc-auth 进程了，停止播放直播视频时此进程就会自动被结束掉。</p>
]]></content:encoded>
			<wfw:commentRss>https://zohead.com/archives/raspberry-pi-sopcast/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
