Principles of ftrace - building of development environment (continuous update...)

Starting from this article, we'll study the Kernel Implementation of ftrace. I'm based on the recent and long-term maintenance version of linux 5.4. However, we don't worry about looking at the code, but first build the development environment. Qemu+arm64

Install the necessary software

sudo apt install libncurses5-dev openssl libssl-dev \
    build-essential pkg-config libc6-dev bison flex libelf-dev \
    zlibc minizip libidn11-dev libidn11 qttools5-dev liblz4-tool \
    gcc-arm-linux-gnueabi  gcc-aarch64-linux-gnu
//Installing qemu
sudo apt install qemu qemu-kvm qemu-system-arm virt-manager

Download code

wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.4.120.tar.gz
wget https://busybox.net/downloads/busybox-1.32.0.tar.bz2

Or you can use acceleration software
axel -n 10 -o ./ https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.4.120.tar.gz
axel -n 10 -o ./  https://busybox.net/downloads/busybox-1.32.0.tar.bz2

Compile kernel

export  ARCH=arm64

export CROSS_COMPILE=aarch64-linux-gnu-

make defconfig

make  Image -j8

Configure and compile busybox

make menuconfig 

make && make install 

At this point, a 'is generated in the busybox directory_ intall 'directory will be used as the directory where we build the root file system, and some contents will be added under the root file system directory.
Add the following directory:

  • etc: it mainly stores some configuration files, such as inittab (the init process will parse this file and see further actions); fstab (mainly including some mounted file systems, such as sys proc) init Rd / RCS (can store some executable scripts for use with inittab)
  • Proc: proc file system mount point
  • Sys: sys file system mount point
  • tmp: tmp file system mount point
  • dev: device file
  • lib: library file directory (if busybox adopts dynamic link library, you need to copy the library file of cross compilation chain here)

mkdir -p /etc/init.d/ proc sys tmp dev lib  dev mnt

a. The following nodes are created statically under the dev Directory:

sudo mknod -m 666 tty1 c 4 1
sudo mknod -m 666 tty2 c 4 2
sudo mknod -m 666 tty3 c 4 3
sudo mknod -m 666 tty4 c 4 4
sudo mknod -m 666 console c 5 1
sudo mknod -m 666 null c 1 3

console and null are required. If not, an error will be reported.
b. The contents of the etc / inittab file are as follows, which can be written with reference to busyboxdir/examples/inittab:

::sysinit:/etc/init.d/rcS
::askfirst:/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/sbin/swapoff -a
::shutdown:/bin/umount -a -r
::restart:/sbin/init
tty2::askfirst:/bin/sh
tty3::askfirst:/bin/sh
tty4::askfirst:/bin/sh

c. The contents of the etc / fstab file are as follows. The main purpose is to indicate some file system mount points:

#device mount-point type option dump fsck order
proc  /proc proc  defaults 0 0
temps /tmp  rpoc  defaults 0 0
none  /tmp  ramfs defaults 0 0
sysfs /sys  sysfs defaults 0 0
mdev  /dev  ramfs defaults 0 0

d. etc/init. The contents of the D / rcS file are as follows. The first item of inittab indicates to execute the script from rcS

mount -a
echo "/sbin/mdev" > /proc/sys/kernel/hotplug
/sbin/mdev -s       # According to / etc / mdev Conf to generate device nodes
mount -a

By the way, modify the permission of rcS:

chmod 777 etc/init.d/rcS

e. lib file copy

 cp /usr/aarch64-linux-gnu/lib/* lib/

f. Package root file system

find . | cpio -o -H newc |gzip > /home/lucky/Project/qemu-aarch64/qemu/rootfs.cpio.gz

gdb operation

Start and test QEMU environment, link QEMU and debug kernel through gdb remote function. It should be noted that since we debug the ARM64 simulation environment, we need to use "gdb multiarch" instead of the gdb tool provided by ubuntu. If the system does not have one, you can install it through the following command:

sudo apt-get install gdb-multiarch

Start parameters

qemu-system-aarch64 \
        -machine virt,virtualization=true,gic-version=3 \
        -nographic \
        -m size=1024M \
        -cpu cortex-a57 \
        -smp 2 \
        -kernel Image \
        -initrd rootfs.cpio.gz \
        -S -gdb tcp::9000 \
        --append "console=ttyAMA0 rdinit=/linuxrc"
-smp Number of nuclei
-m Physical memory size
-kernel Kernel compression image location
-initrd rootfs position
-nographic If you do not use the graphical interface, you may fail because you cannot start the graphical interface
-append cmdline startup parameter
-S Blocked at the entrance CPU
-gdb tcp::xxxx Specifies that the communication channel is local tcp passageway(Because it's on the same machine),Port number is xxxx,If you do not need to specify a port number, you can use-s replace

#Open a new window, start gdb and link
gdb-multiarch vmlinux
(gdb)target remote :9000
(gdb)break start_kernel
(gdb)continue
(gdb)step 

Reference article:

       QEMU builds arm64 Linux debugging environment

        arm64 simulation using qemu

       

Added by smilinjack on Sun, 23 Jan 2022 06:54:09 +0200