Brillo: brillo emulator所使用的network类型

相关的文档请参考:

  1. http://wiki.qemu.org/Documentation/Networking
  2. https://en.wikibooks.org/wiki/QEMU/Networking
  3. https://wiki.debian.org/QEMU
  4. https://wiki.archlinux.org/index.php/QEMU#Networking

qemu默认使用的network backend type为User networking(SLIRP), 它不需要root权限进行设置,但是性能不是太好, ICMP也不能用工作(在emulator中无法使用ping), 同时host和外部的网络也不能直接也访问emulator。所以之前我们在访问emulator中的webservd的时候,要使用adb进行tcp端口的forward.

通过上面相关文档的介绍,我们可以通过添加qemu命令行参数的形式,将我们所需要的tcp端口80和443 forward出来,具体的命令如下(使用256M内存,将emulator中的80端口映射到host 8000, 443端口映射到8001上):

$ brilloemualtor-x86 -m 256 -- -redir tcp:8000::80 -redir tcp:8001::443

这个跟在host中执行adb forward tcp:8000 tcp:80, adb forward tcp:8001 tcp:443 效果是一样的。好处就是不用等emulator运行起来后再做。

编译生成的out/host/linux-x86/bin/brilloemulator-x86是一个shell脚本,可以用文本编译器打开:

echo Starting emulator with ${MEM}MB memory
exec \
${ANDROID_BUILD_TOP}/prebuilts/android-emulator/linux-x86_64/qemu/linux-x86_64/qemu-system-aarch64 \
  -M vexpress-a9 \
  -m ${MEM}M \
  -kernel ${ANDROID_BUILD_TOP}/out/target/product/brilloemulator_arm/kernel \
  -append "console=ttyAMA0 ro root=/dev/sda androidboot.hardware=qemu qemu=1 rootwait noinitrd init=/init androidboot.selinux=enforcing" \
  -nographic \
  -device virtio-scsi-device,id=scsi \
  -device scsi-hd,drive=system \
  -drive file="${ANDROID_BUILD_TOP}/out/target/product/brilloemulator_arm/system.img,if=none,id=system,format=raw" \
  -device scsi-hd,drive=userdata \
  -drive file="${ANDROID_BUILD_TOP}/out/target/product/brilloemulator_arm/userdata.img,if=none,id=userdata,format=raw" \
  -redir tcp:5555::5555 \
  -dtb ${ANDROID_BUILD_TOP}/out/target/product/brilloemulator_arm/kernel-dtb \
  "$@"

发表评论

电子邮件地址不会被公开。 必填项已用*标注