searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

通过虚拟串口调试Android虚拟机启动

2023-11-30 05:46:40
15
0

一,宿主侧修改

qemu增加以下启动参数

-chardev socket,id=charserial0,path=./kernel-console,server=on,wait=off,logfile=./serial.log
-serial chardev:charserial0

二,虚机侧修改

2.1 需增加以下内核启动参数

cat /proc/cmdline
... console=ttyS0,115200n8

2.2 Android系统侧修改

userdebug默认已打开console终端功能,如果是user版本需要手动打开。
init.rc

$ cat init.rc
...
service console /system/bin/sh
    class core
    console
    disabled
    user shell
    group shell log readproc
    seclabel u:r:shell:s0
    setenv HOSTNAME console

on init && property:ro.debuggable=1
    start console

三,host侧通过虚拟串口连接虚机

3.1 通过socat工具连接虚拟串口

socat安装

$ sudo apt install socat

socat连接,可以正常通过终端交互。

$ sudo socat unix-connect:./kernel-console stdio
console:/ #

console:/ # dmesg
[    0.000000] Linux version 5.15.111 #2 SMP PREEMPT Wed Nov 29 19:56:34 CST 2023
[    0.000000] Command line: BOOT_IMAGE=/android-2023-11-29/kernel stack_depot_disable=on cgroup_disable=pressure root=/dev/ram0 console=ttyS0,115200n8 console=ttyS0,115200n8 quiet
[    0.000000] KERNEL supported cpus:
[    0.000000] Intel GenuineIntel
[    0.000000] AMD AuthenticAMD
[    0.000000] Hygon HygonGenuine
[    0.000000] Centaur CentaurHauls
[    0.000000] zhaoxin   Shanghai
[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x200: 'Protection Keys User registers'
[    0.000000] x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
[    0.000000] x86/fpu: xstate_offset[9]:  832, xstate_sizes[9]:    8
[    0.000000] x86/fpu: Enabled xstate features 0x207, context size is 840 bytes, using 'compacted' format.
[    0.000000] signal: max sigframe size: 3376
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000007fffff] usable
[    0.000000] BIOS-e820: [mem 0x0000000000800000-0x0000000000807fff] ACPI NVS
[    0.000000] BIOS-e820: [mem 0x0000000000808000-0x000000000080afff] usable

3.2 同时将串口log保存到本地,可以通过命令查看。

$ tail -f serial.log
0条评论
0 / 1000