omjavaid created this revision.
omjavaid added a reviewer: labath.
omjavaid added a project: LLDB.
Herald added subscribers: aaron.ballman, danielkiss, kristof.beyls, tschuett.

This patch adds a HowTo document to lldb docs which gives instruction on how to 
setup QEMU environment for modern Arm64 features not released in publicly 
available hardware till date.

More generally this howto can be applied to other architecture types supported 
by QEMU emulator. This may help setup a lldb test environment for all supported 
architecture/platform types.


https://reviews.llvm.org/D82064

Files:
  lldb/docs/lldb-qemu-aarch64-sve-howto.txt

Index: lldb/docs/lldb-qemu-aarch64-sve-howto.txt
===================================================================
--- /dev/null
+++ lldb/docs/lldb-qemu-aarch64-sve-howto.txt
@@ -0,0 +1,219 @@
+################################################################################
+LLDB Testing on AArch64 SVE Linux using QEMU system mode emulation
+################################################################################
+
+QEMU can be used to test LLDB in emulation environment in absence of actual
+hardware. This write up will help setup an QEMU environment for testing LLDB
+patches supporting AArch64 features like SVE, MTE, Pointer Authentication etc.
+
+Ubuntu Bionic/Focal x86_64 host machine was used to test all instruction in this
+document. Please update it according to your host distribution/architecture.
+################################################################################
+# STEP 1
+################################################################################
+# Bash script for creating Debian/Ubuntu Linux RootFS for QEMU system emulation
+# Example usage:
+# To create an img file of size 8 GB containing Ubuntu Bionic arm64 rootFS
+# > bash create-qemu-rootfs.sh bionic-arm64 8G bionic arm64
+################################################################################
+#!/bin/bash
+
+# Prerequisites:
+sudo apt-get install debootstrap qemu-user-static schroot qemu-utils
+
+if [ $# -gt 3 ]; then
+  echo "Your command line contains $# arguments"
+else
+  echo "Invalid or no arguments"
+  echo "Usage example: create-rootfs-qemu.sh focal-arm64 8G focal arm64"
+  echo "focal-arm64 is image name"
+  echo "8G is image size in Gigabytes"
+  echo "focal is distro name"
+  echo "arm64 is rootFS architecture"
+  exit
+fi
+
+RFS_IMG_NAME=$1
+shift
+RFS_IMG_SIZE_GB=$1
+shift
+BOOTSTRAP_DISTRO=$1
+shift
+BOOTSTRAP_ARCH=$1
+
+echo "Root FS image name ... $RFS_IMG_NAME"
+echo "Root FS size in GB ... $RFS_IMG_SIZE_GB"
+echo "Root FS bootstrap distro name ... $BOOTSTRAP_DISTRO"
+echo "Root FS bootstrap distro architecture... $BOOTSTRAP_ARCH"
+
+qemu-img create $RFS_IMG_NAME.img $RFS_IMG_SIZE_GB
+
+mkfs.ext4 $RFS_IMG_NAME.img
+mkdir $RFS_IMG_NAME.dir
+sudo mount -o loop $RFS_IMG_NAME.img $RFS_IMG_NAME.dir
+
+sudo qemu-debootstrap --arch $BOOTSTRAP_ARCH $BOOTSTRAP_DISTRO $RFS_IMG_NAME.dir
+
+sudo chroot $RFS_IMG_NAME.dir locale-gen en_US.UTF-8
+
+sudo chroot $RFS_IMG_NAME.dir sed -i \
+'s/main/main restricted multiverse universe/g' /etc/apt/sources.list
+
+sudo chroot $RFS_IMG_NAME.dir sed -i '$ a\nameserver 8.8.8.8' /etc/resolv.conf
+
+sudo chroot $RFS_IMG_NAME.dir apt update
+sudo chroot $RFS_IMG_NAME.dir apt -y install ssh bash-completion
+sudo chroot $RFS_IMG_NAME.dir adduser --gecos "" $USER
+sudo chroot $RFS_IMG_NAME.dir adduser $USER sudo
+sudo umount $RFS_IMG_NAME.dir
+rmdir $RFS_IMG_NAME.dir
+
+################################################################################
+#  End of STEP 1
+################################################################################
+
+################################################################################
+# STEP 2
+#
+# Build QEMU from source for AArch64 system-mode emulation
+################################################################################
+
+# Install dependencies
+sudo apt-get build-dep qemu
+sudo apt install libsdl2-dev
+
+# Checkout source code
+git clone git://git.qemu.org/qemu.git qemu.git
+
+# Configure and build
+cd qemu.git
+./configure --target-list=aarch64-softmmu
+make
+
+################################################################################
+# STEP 3
+#
+# Cross compile Linux kernel
+################################################################################
+
+# Install dependencies
+sudo apt install gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu
+
+# Checkout source code, select branch and clean up source directory
+git clone  \
+https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git linux.git
+
+cd linux.git
+make mrproper
+
+# kernel_branch=master arch=arm64 config=defconfig
+make O=../linux.build/master/arm64 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \
+defconfig
+
+make O=../linux.build/master/arm64 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
+
+
+################################################################################
+# STEP 4
+#
+# AArch64 SVE System Mode Emulation
+#
+# Bash script given below boots our newly built AArch64 Linux kernel using
+# RootFS img file created in step 1.
+################################################################################
+#!/bin/bash
+
+if [ $# -gt 2 ]; then
+  echo "Your command line contains $# arguments"
+else
+  echo "Invalid or no arguments"
+  echo "Usage example: sudo bash run-qemu-emulation.sh \
+./qemu.git/aarch64-softmmu/qemu-system-aarch64 \
+./linux.build/master/arm64/ ./bionic-arm64.img"
+  echo "First argument is .. qemu-system-aarch64"
+  echo "Second argument is .. Linux kernel build directory"
+  echo "Third argument is .. RootFS image file"
+  exit
+fi
+
+QEMU_AARCH64=$1
+shift
+LINUX_BUILD=$1
+shift
+QEMU_RFS_IMG=$1
+
+echo "QEMU AArch64 system emulation executable ... $QEMU_AARCH64"
+echo "Root FS image name ... $QEMU_RFS_IMG"
+echo "Linux ARM64 build directory ... $LINUX_BUILD"
+
+LINUX_DTBS=$LINUX_BUILD/arch/arm64/boot/dts/
+
+QEMU_MACHINE=virt
+QEMU_CPU=max
+QEMU_CORES=2
+QEMU_MEMORY=2048
+QEMU_GDBSERVER_HOST_PORT=54321
+QEMU_GDBSERVER_VM_PORT=54321
+QEMU_SSH_HOST_PORT=5555
+
+
+$QEMU_AARCH64 \
+-kernel $LINUX_BUILD/arch/arm64/boot/Image \
+-M $QEMU_MACHINE \
+-cpu $QEMU_CPU \
+-machine type=$QEMU_MACHINE \
+-smp $QEMU_CORES \
+-m $QEMU_MEMORY \
+-drive file=$QEMU_RFS_IMG,index=0,media=disk,format=raw \
+-append "root=/dev/vda rw ip=dhcp mem=1024M raid=noautodetect  \
+crashkernel=128M rootwait console=ttyAMA0 devtmpfs.mount=0" \
+-nographic \
+-net nic -net user \
+-nic user,hostfwd=tcp::$QEMU_GDBSERVER_HOST_PORT-:$QEMU_GDBSERVER_VM_PORT,hostfwd=tcp::$QEMU_SSH_HOST_PORT-:22
+
+###############################################################################
+# Your default username will be the one with whom you created RootFS image.
+# Internet access inside your emulation environment run: sudo dhclient enp0s2.
+################################################################################
+# Alternatively setup a tap device on host computer by following this link:
+# https://wiki.qemu.org/Documentation/Networking/NAT
+#
+# Run QEMU emulation using commandline given below:
+
+$QEMU_AARCH64 \
+-kernel $LINUX_BUILD/arch/arm64/boot/Image \
+-M $QEMU_MACHINE \
+-cpu $QEMU_CPU,sve-max-vq=$QEMU_SVE_MAX_VQ \
+-machine type=$QEMU_MACHINE \
+-smp $QEMU_CORES \
+-m $QEMU_MEMORY \
+-drive file=$QEMU_RFS_IMG,index=0,media=disk,format=raw \
+-append "root=/dev/vda rw ip=dhcp mem=1024M raid=noautodetect crashkernel=128M rootwait console=ttyAMA0 devtmpfs.mount=0" \
+-nographic \
+-net tap -net nic
+
+################################################################################
+#  End of STEP 4
+################################################################################
+
+################################################################################
+# STEP 5
+# Running lldb-server in QEMU emulation environment
+################################################################################
+
+# Login emulation environment and install dependencies
+sudo apt install python-dev libedit-dev libncurses5-dev libexpat1-dev
+
+# Setup ssh access between host machine and emulation environment
+# Make sure br0 is enabled on host machine by running:
+ip add
+
+# Find out ip address assigned to eth0 in emulation environment
+ip add
+
+# Verify ssh access
+ssh username@ip-address-of-emulation-environment
+
+# Cross compile LLDB server for AArch64 Linux
+# Transfer LLDB server executable to emulation environment
+scp lldb-server username@ip-address-of-emulation-environment:/home/username
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to