ARM Development Studio setup for debugging linux kernel

1. Download and install ARM Development Studio

From ARM website: https://developer.arm.com/downloads/view/FM000A?sortBy=availableBy, you'll need an ARM account to download it

Or, you can get a cracked 2024.0 version, I won't detail here

2. Build Linux kernel

You'll need a linux-based environment to do it. Use WSL or VM if your host system is Windows.

Get linux 6.9.0 rc5, and apply POE patch to the source code.

export ARCH=arm64 and export CROSS_COMPILE=<your toolchain>

make defconfig, then make menuconfig, enable CONFIG_DEBUG_INFO

Build the kernel. make -j12 Image

Your kernel will be located at arch/arm64/boot/Image.

Build the dtb. make dtbs . Install the dependencies if it tells you to do so.

Your dtb will be located at arch/arm64/boot/dts/arm/foundation-v8-gicv3-psci.dtb

3. Pack the kernel

git clone https://git.kernel.org/pub/scm/linux/kernel/git/mark/boot-wrapper-aarch64.git/

enter boot-wrapper-aarch64 directory

autoreconf -i

./configure --enable-psci --enable-gicv3 --with-kernel-dir=<linux source dir> --with-dtb=<path to dtb> --host=aarch64-linux-gnu --with-cmdline="console=ttyAMA0 root=/dev/vda"

make, then you get linux-system.axf

4. Prepare rootfs

create a 2G image: dd if=/dev/zero of=disk.img bs=1M count=2048

format it mkfs.ext4 disk.img

mount it sudo mount disk.img <mountpoint>

look for an instruction for building an rootfs. recommand: build an debian or ubuntu image, because it's easier to do kselftests

you can test the rootfs with qemu:

qemu-system-aarch64 -m 1G -M virt -drive if=none,file=disk.img,id=hd0 -device virtio-blk-device,drive=hd0 -kernel Image -append "console=ttyAMA0 root=/dev/vda" -nographic -serial mon:stdio

5. Setup ARM DS

New project, create a general project

In debug control window, create a new debug connection

image-20250217210921458

add a model connection, enter a name

in Target selection, choose ARM FVP (Install with ARM DS)->Base_AEMvAx4, finish

right click, open Debug Configuration of the debug connection,create a new configuration under Generic Arm C/C++ Application

image-20250217212743874

in Connection tab, choose Arm FVP (Installed with Arm DS) ->Base_AEMvAx4->Linux Kernel Debug->AEM-A_MPx4 SMP

image-20250217212948150

in connections, enter the following Model parameters:

-C cluster0.NUM_CORES=4 -C cluster0.has_arm_v9-4=1 -C cluster0.has_permission_indirection_s1=2 -C cluster0.has_permission_indirection_s2=2 -C cluster0.has_permission_overlay_s1=2 -C cluster0.has_permission_overlay_s2=2 -C bp.secure_memory=false -C cache_state_modelled=0 -C bp.refcounter.non_arch_start_at_default=1 -C bp.virtioblockdevice.image_path='C:\test.img'

image-20250217213038664

of course, you should adjust your image path to the correct location.

in Files tab, choose the linux-system.axf file

image-20250217214715135

in Debugger tab, add linux source directory and boot-wrapper source directory

image-20250217214813045

apply, and debug

debug the kernel

refer to https://blog.csdn.net/M0XFFF/article/details/127108259