Debian12Cuttlefish

Hardware/OS/Software

Hardware:

model name      : 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
# free -m
               total        used        free      shared  buff/cache   available
Mem:           63867        5869       20476         261       38502       57997
Swap:            976           0         976

OS:

root@gfxdebian:~# cat /etc/issue
Debian GNU/Linux 12 \n \l

root@gfxdebian:~# uname -a
Linux gfxdebian 6.1.0-25-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.106-3 (2024-08-26) x86_64 GNU/Linux
root@gfxdebian:~# qemu-system-x86_64 --version
QEMU emulator version 9.0.2 (Debian 1:9.0.2+ds-1~bpo12+1)
Copyright (c) 2003-2024 Fabrice Bellard and the QEMU Project developers

aemu/gfxstream/ffi

Building aemu:

 tar xzvf Code.tar.gz
 cd Code
 apt install -y libvirglrenderer-dev
 cd aemu/
  export CMAKE_INSTALL_PREFIX="/usr"
 export PREFIX="/usr"
  export PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig":"${PREFIX}/lib/x86_64-linux-gnu/pkgconfig"
 rm -rf build
  cmake -DAEMU_COMMON_GEN_PKGCONFIG=ON       -DAEMU_COMMON_BUILD_CONFIG=gfxstream       -DENABLE_VKCEREAL_TESTS=OFF       --install-prefix "${PREFIX}"       -B build
  cmake --build build -j
  cmake --install build --prefix "${CMAKE_INSTALL_PREFIX}"

Build gfxstream:

 cd ../gfxstream/
 ls
 rm -rf build/
  meson setup -Ddefault_library=static --prefix "${PREFIX}" build/
  meson install -C build

Install rustup:

 which rustup
 export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
 export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup
 curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
 unset RUSTUP_UPDATE_ROOT
 unset RUSTUP_DIST_SERVER
  source $HOME/.cargo/env
 source ~/.profile

Building ffi:

 export RUSTFLAGS='-Clink-arg=-L='"${PREFIX}"/lib/x86_64-linux-gnu/
 cd ../crosvm/rutabaga_gfx/ffi/
 make
make prefix="${PREFIX}" install

qemu

Notice the packages:


root@gfxdebian:/home/test/deb# ls
Packages                                                qemu-system-mips-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb            qemu-system-x86_9.0.2+ds-1~bpo12+1_amd64.deb
Packages.gz                                             qemu-system-mips_9.0.2+ds-1~bpo12+1_amd64.deb                   qemu-system-xen-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-block-extra-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb    qemu-system-misc-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb            qemu-system-xen_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-block-extra_9.0.2+ds-1~bpo12+1_amd64.deb           qemu-system-misc_9.0.2+ds-1~bpo12+1_amd64.deb                   qemu-system_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-guest-agent-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb    qemu-system-modules-opengl-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb  qemu-user-binfmt_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-guest-agent_9.0.2+ds-1~bpo12+1_amd64.deb           qemu-system-modules-opengl_9.0.2+ds-1~bpo12+1_amd64.deb         qemu-user-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-system-arm-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb     qemu-system-modules-spice-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb   qemu-user-static-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-system-arm_9.0.2+ds-1~bpo12+1_amd64.deb            qemu-system-modules-spice_9.0.2+ds-1~bpo12+1_amd64.deb          qemu-user-static_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-system-common-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb  qemu-system-ppc-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb             qemu-user_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-system-common_9.0.2+ds-1~bpo12+1_amd64.deb         qemu-system-ppc_9.0.2+ds-1~bpo12+1_amd64.deb                    qemu-utils-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-system-data_9.0.2+ds-1~bpo12+1_all.deb             qemu-system-sparc-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb           qemu-utils_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-system-gui-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb     qemu-system-sparc_9.0.2+ds-1~bpo12+1_amd64.deb                  seabios_1.16.3-2~bpo12+1_all.deb
qemu-system-gui_9.0.2+ds-1~bpo12+1_amd64.deb            qemu-system-x86-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb

root@gfxdebian:/home/test# cat /etc/apt/sources.list
# customization qemu
deb [trusted=yes]       file:///home/test/deb/  ./

Install the package:

# apt install -y seabios
# apt install -y qemu-system

Backup the installed debs via:

mv deb debian_qemu_gfx_deb
 scp -r debian_qemu_gfx_deb/ dash@192.168.1.213:/media/sdb/samba

cuttlefish(qemu+gfxstream)

Create the instance:

 mkdir qemu_gfx
 cd qemu_gfx/
 tar xzvf ../cf-x86/cvd-host_package.tar.gz && unzip ../cf-x86/aosp_cf_x86_64_phone-img-11305814.zip
 HOME=$PWD ./bin/launch_cvd -vm_manager qemu_cli -gpu_mode   gfxstream  -qemu_binary_dir /usr/bin  -enable_gpu_udmabuf -cpus 4 -memory_mb 4096

Connect and verify:


 $ sudo adb connect 192.168.1.60:6520                                                                                                               1
connected to 192.168.1.60:6520
$ sudo adb -s 192.168.1.60:6520 shell
vsoc_x86_64:/ $ getprop | grep boot | grep complete
[dev.bootcomplete]: [1]
[sys.boot_completed]: [1]
[sys.bootstat.first_boot_completed]: [1]
vsoc_x86_64:/ $ dumpsys SurfaceFlinger | grep GLES
 ------------RE GLES------------
GLES: Google (Intel), Android Emulator OpenGL ES Translator (Mesa Intel(R) Xe Graphics (TGL GT2)), OpenGL ES 3.1 (OpenGL ES 3.2 Mesa 22.3.6)

cuttlefish(qemu+drm_virgl)

Create the instance:

 mkdir qemu_virgl
 cd qemu_virgl
 tar xzvf ../cf-x86/cvd-host_package.tar.gz && unzip ../cf-x86/aosp_cf_x86_64_phone-img-11305814.zip
 HOME=$PWD ./bin/launch_cvd -vm_manager qemu_cli -gpu_mode   drm_virgl  -qemu_binary_dir /usr/bin  -enable_gpu_udmabuf -cpus 4 -memory_mb 4096

Connect and verify:

vsoc_x86_64:/ $ getprop  | grep boot | grep com
[dev.bootcomplete]: [1]
[ro.boot.hardware.hwcomposer.display_finder_mode]: [drm]
[ro.boot.hardware.hwcomposer.mode]: [client]
[ro.boot.vendor.apex.com.google.emulated.camera.provider.hal]: [com.google.emulated.camera.provider.hal]
[sys.boot_completed]: [1]
[sys.bootstat.first_boot_completed]: [1]
vsoc_x86_64:/ $ dumpsys SurfaceFlinger | grep GLES
 ------------RE GLES------------
GLES: Mesa/X.org, virgl, OpenGL ES 3.2 Mesa 20.3.4 (git-543897be74)

cuttlefish(crosvm+gfxstream)

Create the instance:

 mkdir crosvm_gfx
 cd crosvm_gfx
 tar xzvf ../cf-x86/cvd-host_package.tar.gz && unzip ../cf-x86/aosp_cf_x86_64_phone-img-11305814.zip
HOME=$PWD ./bin/launch_cvd   -gpu_mode   gfxstream  -cpus 4 -memory_mb  8192

Connect and verify:

vsoc_x86_64:/ $ getprop | grep boot | grep comple
[dev.bootcomplete]: [1]
[sys.boot_completed]: [1]
[sys.bootstat.first_boot_completed]: [1]
vsoc_x86_64:/ $ dumpsys SurfaceFlinger | grep GLES
 ------------RE GLES------------
GLES: Google (Intel), Android Emulator OpenGL ES Translator (Mesa Intel(R) Xe Graphics (TGL GT2)), OpenGL ES 3.1 (OpenGL ES 3.2 Mesa 22.3.6)

cuttlefish(crosvm+virgl)

Create the instance:

 mkdir crosvm_virgl
 cd crosvm_virgl
 tar xzvf ../cf-x86/cvd-host_package.tar.gz && unzip ../cf-x86/aosp_cf_x86_64_phone-img-11305814.zip
$ HOME=$PWD ./bin/launch_cvd   -gpu_mode    drm_virgl -cpus 4 -memory_mb  8192

Connect and verify:

not ok, failed to connect 

RebuildQemuOnDebian

Steps:

$ vim /etc/apt/sources.list
Add:  
 deb http://mirrors.ustc.edu.cn/debian bookworm-backports main contrib non-free non-free-firmware
 deb-src http://mirrors.ustc.edu.cn/debian bookworm-backports main contrib non-free non-free-firmware
$ sudo apt build-dep qemu-system
$ mkdir -p ~/qemu && cd qemu
$ apt source qemu-system
$ cd qemu-9.0.2+ds
$ dpkg-buildpackage -rfakeroot -uc -b

After building, the debs is listed as:

test@buildqemu:~/qemu$ ls
qemu-9.0.2+ds                                           qemu-system-misc-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb
qemu_9.0.2+ds-1~bpo12+1_amd64.buildinfo                 qemu-system-modules-opengl_9.0.2+ds-1~bpo12+1_amd64.deb
qemu_9.0.2+ds-1~bpo12+1_amd64.changes                   qemu-system-modules-opengl-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb
qemu_9.0.2+ds-1~bpo12+1.debian.tar.xz                   qemu-system-modules-spice_9.0.2+ds-1~bpo12+1_amd64.deb
qemu_9.0.2+ds-1~bpo12+1.dsc                             qemu-system-modules-spice-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb
qemu_9.0.2+ds.orig.tar.xz                               qemu-system-ppc_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-block-extra_9.0.2+ds-1~bpo12+1_amd64.deb           qemu-system-ppc-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-block-extra-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb    qemu-system-sparc_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-guest-agent_9.0.2+ds-1~bpo12+1_amd64.deb           qemu-system-sparc-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-guest-agent-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb    qemu-system-x86_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-system_9.0.2+ds-1~bpo12+1_amd64.deb                qemu-system-x86-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-system-arm_9.0.2+ds-1~bpo12+1_amd64.deb            qemu-system-xen_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-system-arm-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb     qemu-system-xen-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-system-common_9.0.2+ds-1~bpo12+1_amd64.deb         qemu-user_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-system-common-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb  qemu-user-binfmt_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-system-data_9.0.2+ds-1~bpo12+1_all.deb             qemu-user-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-system-gui_9.0.2+ds-1~bpo12+1_amd64.deb            qemu-user-static_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-system-gui-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb     qemu-user-static-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-system-mips_9.0.2+ds-1~bpo12+1_amd64.deb           qemu-utils_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-system-mips-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb    qemu-utils-dbgsym_9.0.2+ds-1~bpo12+1_amd64.deb
qemu-system-misc_9.0.2+ds-1~bpo12+1_amd64.deb

BuildQemurutabaga_gfx

Install with debian-12.7.0-amd64-DVD-1.iso. Select gnome/desktop/ssh server.

/images/20240919_084808_x.jpg

/images/20240919_085715_x.jpg

x86 steps

Configure the repository and update/upgrade:

root@debian:~# cat /etc/apt/sources.list
# 默认注释了源码仓库,如有需要可自行取消注释
deb http://mirrors.ustc.edu.cn/debian bookworm main contrib non-free non-free-firmware
# deb-src http://mirrors.ustc.edu.cn/debian bookworm main contrib non-free non-free-firmware
deb http://mirrors.ustc.edu.cn/debian bookworm-updates main contrib non-free non-free-firmware
# deb-src http://mirrors.ustc.edu.cn/debian bookworm-updates main contrib non-free non-free-firmware

# backports 软件源,请按需启用
# deb http://mirrors.ustc.edu.cn/debian bookworm-backports main contrib non-free non-free-firmware
# deb-src http://mirrors.ustc.edu.cn/debian bookworm-backports main contrib non-free non-free-firmware
# apt install -y nethogs vim iptables

Install necessary packages:

 apt install -y ninja-build pkg-config libgbm1 libglib2.0-dev bridge-utils libfdt-dev libpixman-1-dev libssl-dev libsdl1.2-dev libspice-server-dev autoconf libtool xtightvncviewer tightvncserver x11vnc uuid-runtime uuid uml-utilities liblzma-dev libc6-dev libdrm-dev libgbm-dev spice-client-gtk libgtk2.0-dev libusb-1.0-0-dev libepoxy-dev libaio-dev libgtk-3-dev ovmf libsdl2-dev libegl-mesa0
apt install -y {libpulse,libdrm,libglm,libstb,libegl,libgles,libvulkan,vulkan-validationlayers}-dev 
apt install -y libepoxy-dev libgbm-dev cmake curl python3-venv git build-essential meson

Prepare the code structure:

mkdir Code
cd Code
git clone https://gitlab.com/qemu-project/qemu.git

Build libvirglrenderer:

export PREFIX="$(pwd)"/prefix
git clone https://gitlab.freedesktop.org/virgl/virglrenderer.git
cd virglrenderer
meson setup -Dprefix=$PREFIX -Dlibdir=lib build
cd build
ninja install

build aemu (dependencies) Steps:

cd qemu
mkdir -p build/deps/prefix
cd build/deps
export PREFIX="$(pwd)"/prefix
export CMAKE_INSTALL_PREFIX="${PREFIX}"
export PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig":"${PREFIX}/lib/x86_64-linux-gnu/pkgconfig"
git clone https://android.googlesource.com/platform/hardware/google/aemu
cd aemu/
cmake -DAEMU_COMMON_GEN_PKGCONFIG=ON \
      -DAEMU_COMMON_BUILD_CONFIG=gfxstream \
      -DENABLE_VKCEREAL_TESTS=OFF \
      --install-prefix "${PREFIX}" \
      -B build
cmake --build build -j
cmake --install build --prefix "${CMAKE_INSTALL_PREFIX}"

build gfxstream steps:

cd ..
git clone https://android.googlesource.com/platform/hardware/google/gfxstream
cd gfxstream/
meson setup -Ddefault_library=static --prefix "${PREFIX}" build/ 
meson install -C build

rutabaga FFI:

cd ~/Code
git clone https://github.com/google/crosvm
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
#curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/env
source ~/.profile
rustup toolchain list | grep -q 1.68.2-x86_64-unknown-linux-gnu || rustup toolchain install 1.68.2-x86_64-unknown-linux-gnu
cd crosvm
git reset --hard cd04b6198dc89104de7748043585cf38c56cb626
export RUSTFLAGS='-Clink-arg=-L='"${PREFIX}"/lib/x86_64-linux-gnu/
cd rutabaga_gfx/ffi
make
make prefix="${PREFIX}" install

Build qemu:

mkdir -p /opt/local
cd ~/Code/qemu/build
export CFLAGS="-I${PREFIX}/include -L${PREFIX}/lib" # needed for rutabaga_gfx_ffi.h
#../configure --enable-system --enable-tools --enable-vhost-user --enable-slirp --enable-kvm --enable-debug --target-list=x86_64-softmmu --enable-rutabaga-gfx --prefix=/opt/local/
../configure --enable-system --enable-tools --enable-vhost-user --enable-slirp --enable-kvm --enable-debug --target-list=aarch64-softmmu --enable-rutabaga-gfx
make -j$(nproc)
su root

 

cuttlefish build

Steps:

usermod -aG sudo test
cd ~/Code
git clone https://github.com/google/android-cuttlefish
cd android-cuttlefish
tools/buildutils/build_packages.sh
sudo dpkg -i ./cuttlefish-base_*_*64.deb || sudo apt-get install -f
sudo dpkg -i ./cuttlefish-user_*_*64.deb || sudo apt-get install -f
sudo usermod -aG kvm,cvdnetwork,render $USER
mkdir cf
tar xzvf ../cvd-host_package.tar.gz && unzip ../aosp_cf_arm64_only_phone-img-11489887.zip 
sudo reboot

should notice the aarch64 library replacement.

x86 tips

qemu version:

$ /home/test/Code/qemu/build/qemu-system-x86_64 --version
QEMU emulator version 9.1.50 (v9.1.0-384-g2b81c04625)
Copyright (c) 2003-2024 Fabrice Bellard and the QEMU Project developers
test@debian:~/cf$ sudo chmod 777 /usr/bin/qemu-system-x86_64 
test@debian:~/cf$ sudo cat /usr/bin/qemu-system-x86_64 
#!/bin/bash
/home/test/Code/qemu/build/qemu-system-x86_64 $@

Ubuntu2204 issue

When building gfxstream host:

git clone https://android.googlesource.com/platform/hardware/google/gfxstream
cd gfxstream/
meson setup host-build/

Get error:

Run-time dependency dl found: NO (tried pkgconfig and cmake)

host/meson.build:78:2: ERROR: Dependency "dl" not found, tried pkgconfig and cmake

cmake:

 307  sudo apt remove cmake
  308  sudo apt install libssl-dev
  309  cd ..
  310  ls
  311  wget https://cmake.org/files/v3.29/cmake-3.29.2.tar.gz
  312  tar -xzvf cmake-3.29.2.tar.gz
  313  cd cmake-3.29.2
  314  export OPENSSL_ROOT_DIR=/usr/include/openssl
  315  ./bootstrap
  316  make -j$(nproc)
  317  sudo make install
  318  which cmake

cuttlefishRecords

1. crosvm

Default command:

HOME=$PWD ./bin/launch_cvd  -cpus 6 -memory_mb 8192 

Result:

vsoc_arm64_only:/ $ getprop | grep boot | grep com                                            
[dev.bootcomplete]: [1]
[ro.boot.hardware.hwcomposer.display_finder_mode]: [drm]
[ro.boot.vendor.apex.com.google.emulated.camera.provider.hal]: [com.google.emulated.camera.provider.hal]
[sys.boot_completed]: [1]
[sys.bootstat.first_boot_completed]: [1]
vsoc_arm64_only:/ $ dumpsys SurfaceFlinger | grep GLES
 ------------RE GLES------------
GLES: Google Inc. (Google), ANGLE (Google, Vulkan 1.3.0 (SwiftShader Device (LLVM 16.0.0) (0x0000C0DE)), SwiftShader driver-5.0.0), OpenGL ES 3.1.0 (ANGLE 2.1.0 git hash: unknown hash)

(Start under Xorg :0)-gfxstream mode:

$ HOME=$PWD ./bin/launch_cvd -cpus 6 -memory_mb 8192 --gpu_mode=gfxstream

Result:

vsoc_arm64_only:/ $ getprop | grep boot | grep com                                            
[dev.bootcomplete]: [1]
[ro.boot.hardware.hwcomposer.display_finder_mode]: [drm]
[ro.boot.vendor.apex.com.google.emulated.camera.provider.hal]: [com.google.emulated.camera.provider.hal]
[sys.boot_completed]: [1]
[sys.bootstat.first_boot_completed]: [1]
vsoc_arm64_only:/ $ dumpsys SurfaceFlinger | grep GLES
 ------------RE GLES------------
GLES: Google (AMD), Android Emulator OpenGL ES Translator (OLAND (, LLVM 15.0.7, DRM 2.50, 5.15.0-119-generic)), OpenGL ES 3.1 (OpenGL ES 3.2 Mesa 23.2.1-1ubuntu3.1~22.04.2)

$ HOME=$PWD ./bin/launch_cvd -cpus 6 -memory_mb 8192 --gpu_mode=guest_swiftshader:

vsoc_arm64_only:/ $ getprop | grep boot | grep com                                            
[dev.bootcomplete]: [1]
[ro.boot.hardware.hwcomposer.display_finder_mode]: [drm]
[ro.boot.vendor.apex.com.google.emulated.camera.provider.hal]: [com.google.emulated.camera.provider.hal]
[sys.boot_completed]: [1]
[sys.bootstat.first_boot_completed]: [1]
vsoc_arm64_only:/ $ dumpsys SurfaceFlinger | grep GLES
 ------------RE GLES------------
GLES: Google Inc. (Google), ANGLE (Google, Vulkan 1.3.0 (SwiftShader Device (LLVM 16.0.0) (0x0000C0DE)), SwiftShader driver-5.0.0), OpenGL ES 3.1.0 (ANGLE 2.1.0 git hash: unknown hash)

$ HOME=$PWD ./bin/launch_cvd -cpus 6 -memory_mb 8192 --gpu_mode=auto:

vsoc_arm64_only:/ $ getprop | grep boot | grep com                                            
[dev.bootcomplete]: [1]
[ro.boot.hardware.hwcomposer.display_finder_mode]: [drm]
[ro.boot.vendor.apex.com.google.emulated.camera.provider.hal]: [com.google.emulated.camera.provider.hal]
[sys.boot_completed]: [1]
[sys.bootstat.first_boot_completed]: [1]
vsoc_arm64_only:/ $ dumpsys SurfaceFlinger | grep GLES
 ------------RE GLES------------
GLES: Google Inc. (Google), ANGLE (Google, Vulkan 1.3.0 (SwiftShader Device (LLVM 16.0.0) (0x0000C0DE)), SwiftShader driver-5.0.0), OpenGL ES 3.1.0 (ANGLE 2.1.0 git hash: unknown hash)

2. qemu

virgl:

HOME=$PWD ./bin/launch_cvd -vm_manager qemu_cli -gpu_mode  drm_virgl  -enable_gpu_udmabuf -cpus 4 -memory_mb 4096

Result:

vsoc_arm64_only:/ $ getprop | grep boot | grep com                                            
[dev.bootcomplete]: [1]
[ro.boot.hardware.hwcomposer.display_finder_mode]: [drm]
[ro.boot.hardware.hwcomposer.mode]: [client]
[ro.boot.vendor.apex.com.google.emulated.camera.provider.hal]: [com.google.emulated.camera.provider.hal]
[sys.boot_completed]: [1]
[sys.bootstat.first_boot_completed]: [1]
vsoc_arm64_only:/ $ dumpsys SurfaceFlinger | grep GLES
 ------------RE GLES------------
GLES: Mesa/X.org, virgl, OpenGL ES 3.2 Mesa 20.3.4 (git-1aa4951402)

gfxstream:

$ HOME=$PWD ./bin/launch_cvd -vm_manager qemu_cli -gpu_mode   gfxstream  -enable_gpu_udmabuf -cpus 4 -memory_mb 4096

Result:

--gpu_mode=gfxstream was requested but the prerequisites for accelerated rendering were not detected so the device may not function correctly. Please consider switching to --gpu_mode=auto or --gpu_mode=guest_swiftshader.
GPU vhost user auto mode: not yet supported with qemu_cli. Not enabling vhost user gpu.
assemble_cvd failed: 

uefibuildingq35coreboot

安装以下依赖包:

 sudo apt install -y build-essential git vim m4 bison flex zlib1g-dev libncurses5-dev intltool libtool gperf libcap-dev libblkid-dev libmount-dev xsltproc docbook-xsl autopoint libgpgme11-dev libdevmapper-dev libdw-dev libdw1 libssl-dev libevent-dev

创建编译目录:

mkdir Code
mkdir  -p Code/coreboot
cd Code/coreboot
 git clone http://review.coreboot.org/p/coreboot
 cd coreboot/
 git checkout tags/4.6 -b local46
 wget https://fossies.org/linux/misc/old/libelf-0.8.13.tar.gz
mkdir -p util/crossgcc
 mv libelf-0.8.13.tar.gz util/crossgcc/tarballs/
 vim util/crossgcc/buildgcc 
IASL_ARCHIVE="https://downloadmirror.intel.com/774735/acpica-unix2-${IASL_VERSION}.tar.gz"
 make crossgcc CPUS=`nproc`
 make iasl CPUS=`nproc`
 make menuconfig

编译systemd, 注意这里使用了特定版本的systemd:

cd ~/Code
mkdir systemd
cd systemd/
wget https://github.com/systemd/systemd/archive/refs/tags/v229.tar.gz
tar xzvf v229.tar.gz 
mv systemd-229/ systemd
cd systemd/
./autogen.sh
mkdir build
cd build
../configure --prefix=/usr --enable-blkid --disable-seccomp --disable-libcurl --disable-pam --disable-kmod
make -j12
cd ../../../

编译kexec:

mkdir kexec
cd kexec
git clone git://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git
cd kexec-tools
./bootstrap
./configure --prefix=/usr
vim /home/dash/Code/kexec/kexec-tools/kexec/arch/i386/x86-linux-setup.c
      /#include <sys/random.h>
      #include <linux/random.h>
      #include <unistd.h>
      #include <sys/syscall.h>
......
	//if (getrandom(sd->rng_seed, sizeof(sd->rng_seed), GRND_NONBLOCK) !=
	if (syscall(SYS_getrandom,sd->rng_seed, sizeof(sd->rng_seed), GRND_NONBLOCK) !=
make -j`nproc`
cd ../..

编译twin:

mkdir petitboot
cd petitboot/
git clone git://git.kernel.org/pub/scm/linux/kernel/git/geoff/libtwin.git
cd libtwin/
cp README.md README
./autogen.sh  && make -j8 && sudo make install
cd ../../

编译petitboot:

cd petitboot/
wget https://git.raptorengineering.com/git/petitboot/snapshot/petitboot-1.4.3.tar.gz
tar xzvf petitboot-1.4.3.tar.gz 
mv petitboot-1.4.3/ petitboot
cd petitboot/
./bootstrap 
CPPFLAGS="-I../../systemd/systemd/src/libudev/" LDFLAGS="-L../../systemd/systemd/build/.libs/" ./configure --prefix=/usr --enable-static --disable-shared --enable-busybox --with-ncurses --without-twin-x11 --without-twin-fbdev --with-signed-boot
make -j12
cd ../../

编译busybox:

mkdir busybox
cd busybox
git clone git://git.busybox.net/busybox
cd busybox
make defconfig
make menuconfig
LDFLAGS=--static make -j`nproc`
cd ../.. 

make menuconfig时,去掉下面这个选项:

/images/20240913_104714_x.jpg

现在需要编译一个最小化的initramfs, 准备基本的目录架构:

mkdir initramfs
mkdir -p initramfs/{bin,sbin,etc,lib,proc,sys,newroot,usr,usr/bin,usr/sbin,var,var/log,run,run/udev,tmp}
mkdir initramfs/var/log/petitboot
touch initramfs/etc/mdev.conf
cp -Rp /lib/terminfo initramfs/lib/
cp -Rp busybox/busybox/busybox initramfs/bin/
ln -s busybox initramfs/bin/sh

从本机上拷贝核心库:

mkdir -p initramfs/lib/x86_64-linux-gnu
cp -L /lib/x86_64-linux-gnu/libc.so.* initramfs/lib/x86_64-linux-gnu/
cp -L /lib/x86_64-linux-gnu/libm.so.* initramfs/lib/x86_64-linux-gnu/
cp -L /lib/x86_64-linux-gnu/libdl.so.* initramfs/lib/x86_64-linux-gnu/
cp -L /lib/x86_64-linux-gnu/librt.so.* initramfs/lib/x86_64-linux-gnu/
cp -R /lib/x86_64-linux-gnu/libacl.so.* initramfs/lib/x86_64-linux-gnu/
cp -R /lib/x86_64-linux-gnu/libcap.so.* initramfs/lib/x86_64-linux-gnu/
cp -R /lib/x86_64-linux-gnu/libattr.so.* initramfs/lib/x86_64-linux-gnu/
cp -L /lib/x86_64-linux-gnu/libpthread.so.* initramfs/lib/x86_64-linux-gnu/
cp -R /lib/x86_64-linux-gnu/libncurses.so.* initramfs/lib/x86_64-linux-gnu/
cp -R /lib/x86_64-linux-gnu/libtinfo.so.* initramfs/lib/x86_64-linux-gnu/
cp -R /lib/x86_64-linux-gnu/libpcre.so.* initramfs/lib/x86_64-linux-gnu/
cp -L /lib/x86_64-linux-gnu/libresolv.so.* initramfs/lib/x86_64-linux-gnu/
cp -R /lib/x86_64-linux-gnu/libselinux.so.* initramfs/lib/x86_64-linux-gnu/
cp -R /lib/x86_64-linux-gnu/libreadline.so.* initramfs/lib/x86_64-linux-gnu/
cp -R /lib/x86_64-linux-gnu/libgcc_s.so.* initramfs/lib/x86_64-linux-gnu/
cp -R /lib/x86_64-linux-gnu/libblkid.so.* initramfs/lib/x86_64-linux-gnu/
cp -R /lib/x86_64-linux-gnu/libkmod.so.* initramfs/lib/x86_64-linux-gnu/
cp -R /lib/x86_64-linux-gnu/libuuid.so.* initramfs/lib/x86_64-linux-gnu/
cp -R /lib/x86_64-linux-gnu/libusb-0.1.so.* initramfs/lib/x86_64-linux-gnu/
cp -R /lib/x86_64-linux-gnu/libdevmapper.so.* initramfs/lib/x86_64-linux-gnu/
cp -R /lib/x86_64-linux-gnu/libz.so.* initramfs/lib/x86_64-linux-gnu/
cp -R /lib/x86_64-linux-gnu/liblzma.so.* initramfs/lib/x86_64-linux-gnu/
cp -R /lib/x86_64-linux-gnu/libbz2.so.* initramfs/lib/x86_64-linux-gnu/
cp -R /lib/x86_64-linux-gnu/libgpg-error.so.* initramfs/lib/x86_64-linux-gnu/
cp -L /lib/x86_64-linux-gnu/libnss_files.so.* initramfs/lib/x86_64-linux-gnu/

mkdir -p initramfs/lib64/
cp -L /lib64/ld-linux-x86-64.so.* initramfs/lib64/

mkdir -p initramfs/usr/lib/x86_64-linux-gnu/
cp -R /usr/lib/x86_64-linux-gnu/libform.so.* initramfs/usr/lib/x86_64-linux-gnu/
cp -R /usr/lib/x86_64-linux-gnu/libmenu.so.* initramfs/usr/lib/x86_64-linux-gnu/
cp -L /usr/lib/x86_64-linux-gnu/libelf.so.* initramfs/usr/lib/x86_64-linux-gnu/
cp -L /usr/lib/x86_64-linux-gnu/libdw.so.* initramfs/usr/lib/x86_64-linux-gnu/
cp -R /usr/lib/x86_64-linux-gnu/libgpgme.so.* initramfs/usr/lib/x86_64-linux-gnu/
cp -R /usr/lib/x86_64-linux-gnu/libassuan.so.* initramfs/usr/lib/x86_64-linux-gnu/

复制辅助类的二进制文件到新的initramfs中:

cp -Rp /usr/bin/gpg initramfs/usr/bin/

cp systemd/systemd/build/.libs/libudev.so.* initramfs/lib/x86_64-linux-gnu/
cp -Rp systemd/systemd/build/systemd-udevd initramfs/sbin/
cp -Rp systemd/systemd/build/udevadm initramfs/sbin/

mkdir -p initramfs/usr/lib/udev
cp -Rp systemd/systemd/build/*_id initramfs/usr/lib/udev

cp -Rp kexec/kexec-tools/build/sbin/kexec initramfs/sbin/

安装petitboot到新的initramfs中:

cd petitboot/petitboot
make DESTDIR=`realpath ../../initramfs/` install
cd ../..

拷贝udev规则到新的initramfs中:

mkdir -p initramfs/usr/lib/udev/rules.d
cp -Rp systemd/systemd/rules/* initramfs/usr/lib/udev/rules.d/
cp -Rp systemd/systemd/build/rules/* initramfs/usr/lib/udev/rules.d/
rm -f initramfs/usr/lib/udev/rules.d/*-drivers.rules

设置udhcp辅助脚本:

mkdir -p initramfs/usr/share/udhcpc/
cp -Rp busybox/busybox/examples/udhcp/simple.script initramfs/usr/share/udhcpc/simple.script
chmod 755 initramfs/usr/share/udhcpc/simple.script

sed -i '/should be called from udhcpc/d' initramfs/usr/share/udhcpc/simple.script

cat << EOF > initramfs/usr/share/udhcpc/default.script
#!/bin/sh

/usr/share/udhcpc/simple.script "\$@"
/usr/sbin/pb-udhcpc "\$@"
EOF
chmod 755 initramfs/usr/share/udhcpc/default.script

设置nsswitch:

touch initramfs/etc/nsswitch.conf
cat << EOF > initramfs/etc/nsswitch.conf
passwd:		files
group:		files
shadow:		files
hosts:		files
networks:	files
protocols:	files
services:	files
ethers:		files
rpc:		files
netgroup:	files
EOF

添加基本组:

touch initramfs/etc/group
cat << EOF > initramfs/etc/group
root:x:0:
daemon:x:1:
tty:x:5:
disk:x:6:
lp:x:7:
kmem:x:15:
dialout:x:20:
cdrom:x:24:
tape:x:26:
audio:x:29:
video:x:44:
input:x:122:
EOF

创建启动脚本,下面的脚本负责挂载特定目录,启动udev, 最后拉起petitboot, 也可以在此基础上更改为你自己的应用程序:

touch initramfs/init
cat << EOF > initramfs/init
#!/bin/sh

/bin/busybox --install -s

CURRENT_TIMESTAMP=\$(date '+%s')
if [ \$CURRENT_TIMESTAMP -lt `date '+%s'` ]; then
	date -s "@`date '+%s'`"
fi

mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t devtmpfs none /dev

echo 0 > /proc/sys/kernel/printk
clear

systemd-udevd &
udevadm hwdb --update
udevadm trigger

pb-discover &
petitboot-nc

if [ -e /etc/pb-lockdown ]; then
	echo "Failed to launch petitboot, rebooting!"
	echo 1 > /proc/sys/kernel/sysrq
	echo b > /proc/sysrq-trigger
else
	echo "Failed to launch petitboot, dropping to a shell"
	exec sh
fi
EOF
chmod +x initramfs/init

去掉调试符号:

strip initramfs/sbin/*
strip initramfs/usr/sbin/*
strip initramfs/lib/x86_64-linux-gnu/*
strip initramfs/usr/lib/x86_64-linux-gnu/*
strip initramfs/usr/lib/udev/*_id

创建CPIO并压缩镜像:

cd initramfs
find . | cpio -H newc -o > ../initramfs.cpio
cd ..
cat initramfs.cpio | lzma > initramfs.igz

编译内核:

git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
cd linux
git reset --hard 2dcd0af568b0cf583645c8a317dd12e344b1c72a
make menuconfig
make -j`nproc` bzImage

内核配置项中需要调整的部分:

Processor type and features  --->
	[*] kexec file based system call
	[ ]   Verify kernel signature during kexec_file_load() syscall

Device Drivers  --->
	Generic Driver Options  --->
		[ ]   Include in-kernel firmware blobs in kernel binary
	HID support  --->
		{*} HID bus support
		<*>   Generic HID driver
			USB HID support  --->
			<*> USB HID transport layer
	[*] USB support  --->
		<*>     xHCI HCD (USB 3.0) support
		{*}       Generic xHCI driver for a platform device
		<*>     EHCI HCD (USB 2.0) support
		<*>     OHCI HCD (USB 1.1) support
		<*>       OHCI support for PCI-bus USB controllers
		{*}       Generic OHCI driver for a platform device
		<*>     UHCI HCD (most Intel and VIA) support
		<*>     USB Mass Storage support
			<Enable all options in this category as kernel builtins except verbose debug>

Kernel hacking  --->
	Compile-time checks and compiler options  --->
		[ ] Compile the kernel with debug info
	[ ] KGDB: kernel debugger  ----
	[ ] Enable verbose x86 bootup info messages
	[ ] Early printk
		[ ]   Early printk via EHCI debug port
		[ ]   Early printk via the EFI framebuffer

File systems  --->
	-*- Native language support  --->
		
General setup  --->
	Compiler optimization level (Optimize for size)  --->

coreboot下,调整配置:

make menuconfig


General setup  --->
	[ ] Build the ramstage to be relocatable in 32-bit address space.

Mainboard  --->
	ROM chip size (16384 KB (16 MB))  --->
	(0x1000000) Size of CBFS filesystem in ROM

Payload  --->
	Add a payload (A Linux payload)  --->
		(X) A Linux payload
	Linux path and filename
		../../linux/linux/arch/x86_64/boot/bzImage
	Linux initrd
		../../initramfs.igz
	Linux command line
		console=ttyS0,115200n8 console=tty0 panic=60 softlockup_panic=60 nmi_watchdog=1 quiet rw

这里我换成了q35:

/images/20240913_111649_x.jpg

编译, 而后启动:

make -j12
ls build/coreboot.rom -l -h
qemu-system-x86_64 -m 1G -M q35 -serial stdio -bios coreboot/coreboot/build/coreboot.rom

一个开启了ssh/vnc的命令行:

qemu-system-x86_64 -m 1G -M pc -boot d -cdrom ./ubuntu-18.04.6-server-amd64.iso -hda ./zzzz_1604.qcow2 -serial stdio -bios coreboot.rom  -net nic -net user,hostfwd=tcp::2288-:22 -vga std -vnc :7

目前问题: q35启动有问题,i440无法使用光驱,图形无法使用等.