zoukankan      html  css  js  c++  java
  • Ubuntu下qemu环境搭建vexpress开发平台

    在查找资料过程中,发现自己搭建虚拟的arm环境的话,有一个比较好的软件就是qemu了,当然还有其他的,大家各投所好就好。

    接下来说一下qemu环境搭建过程。

    其实搭建很简单,作为小白,我还是捣鼓了两三天才真正的安装成功,正在尝试着怎么使用。

    上篇已经讲了安装Ubuntu系统后root密码的设置,这里就要用到root密码进行软件安装了。

    可以在命令行模式下先进行update,输入:sudo apt-get update

    在保证电脑联网的情况下,Ubuntu会自动进行文件更新,这个操作并不会更新整个文件系统,

    他只是同步le  /etc/apt/sources.list 和 /etc/apt/sources.list.d 中列出的源的索引,这样才能获取到最新的软件包。

    并且只有在更新了资源列表后才能使用apt-get install进行成功安装(我当时就是没有update就去安装程序,失败了好多次,各种欲哭无泪,

    另:一定要保证自己的网络环境良好,更新的文件都不大但是我想你不会想看着电脑以100B的速度去下载6000K+的文件的555555)

    在update完成之后就可以进行qemu的安装了,输入指令:sudo apt-get install qemu(如果失败并提示你需要尝试修复什么文件的话用sudo apt-get -f install qemu代替)

    在连着输入两个表示同意的‘y’之后等着系统自己安装就好了。

    安装完毕,输入qemu并联系按几下table,就会显示当前qemu支持的架构(还是内核?不是很清楚这个概念)

    qemu安装到此结束。

    ========================================和上方震惊体标题后脑残的内容划清界限,下面搭建Vexpress的qemu环境==========================================================================

    1. 安装qemu,参考上方脑残内容,安装完毕后查看qemu版本可出现如下内容表示安装成功

    sly@ubuntu:~/develop$ qemu-arm --version
    qemu-arm version 2.11.1(Debian 1:2.11+dfsg-1ubuntu7.19)
    Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers

    PS: 交叉编译工具链也需要安装  sudo apt-get install gcc-arm-linux-gnueabi

    2. 编译Linux内核

    生成vexpress开发板子的config文件:

    sly@ubuntu:~/develop/linux-5.3.7$ make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm vexpress_defconfig
    #
    # configuration written to .config
    #

    修改Makfile如下两个变量值

    ARCH ?= arm
    CROSS_COMPILE ?= arm-linux-gnueabi-

    编译:

    sly@ubuntu:~/develop/linux-5.3.7$ make 
    sly@ubuntu:~/develop/linux-5.3.7$ make modules
    sly@ubuntu:~/develop/linux-5.3.7$ make dtbs

    生成的内核镱像位于arch/arm/boot/zImage, qemu启动时须要使用该镜像。

    sly@ubuntu:~/develop/linux-5.3.7$ make
    scripts/kconfig/conf  --syncconfig Kconfig
      CALL    scripts/checksyscalls.sh
      CALL    scripts/atomic/check-atomics.sh
      CHK     include/generated/compile.h
      GZIP    kernel/config_data.gz
      CC      kernel/configs.o
      AR      kernel/built-in.a
      GEN     .version
      CHK     include/generated/compile.h
      UPD     include/generated/compile.h
      CC      init/version.o
      AR      init/built-in.a
      LD      vmlinux.o
      MODPOST vmlinux.o
      MODINFO modules.builtin.modinfo-
      KSYM    .tmp_kallsyms1.o
      KSYM    .tmp_kallsyms2.o
      LD      vmlinux
      SORTEX  vmlinux
      SYSMAP  System.map
      OBJCOPY arch/arm/boot/Image
      Kernel: arch/arm/boot/Image is ready
      GZIP    arch/arm/boot/compressed/piggy_data
      AS      arch/arm/boot/compressed/piggy.o
      LD      arch/arm/boot/compressed/vmlinux
      OBJCOPY arch/arm/boot/zImage
      Kernel: arch/arm/boot/zImage is ready
      Building modules, stage 2.
      MODPOST 1 modules

    3. 測试qemu和内核是否能执行成功

    qemu已经安装好了。内核也编译成功了,到这里最好是測试一下,编译出来的内核是否OK,或者qemu对vexpress单板支持是否够友好。

    执行命令:qemu-system-arm -M vexpress-a9 -m 512m -kernel /home/sly/develop/linux-5.3.7/arch/arm/boot/zImage -dtb linux-5.3.7/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -nographic -append "console=ttyAMA0

    sly@ubuntu:~/develop$ qemu-system-arm -M vexpress-a9 -m 512m -kernel /home/sly/develop/linux-5.3.7/arch/arm/boot/zImage -dtb linux-5.3.7/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -nographic -append "console=ttyAMA0"
    pulseaudio: set_sink_input_volume() failed
    pulseaudio: Reason: Invalid argument
    pulseaudio: set_sink_input_mute() failed
    pulseaudio: Reason: Invalid argument
    Booting Linux on physical CPU 0x0
    Linux version 5.3.7 (sly@ubuntu) (gcc version 7.4.0 (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1)) #4 SMP Mon Dec 9 08:31:07 PST 2019
    --省略甚多log----------

    Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
    CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.3.7 #4
    Hardware name: ARM-Versatile Express
    [<80110808>] (unwind_backtrace) from [<8010c680>] (show_stack+0x10/0x14)
    [<8010c680>] (show_stack) from [<8074c7cc>] (dump_stack+0x88/0x9c)
    [<8074c7cc>] (dump_stack) from [<80120e64>] (panic+0x110/0x310)
    [<80120e64>] (panic) from [<80a01640>] (mount_block_root+0x1e8/0x2d4)
    [<80a01640>] (mount_block_root) from [<80a01870>] (mount_root+0x144/0x160)
    [<80a01870>] (mount_root) from [<80a019dc>] (prepare_namespace+0x150/0x198)
    [<80a019dc>] (prepare_namespace) from [<80763874>] (kernel_init+0x8/0x114)
    [<80763874>] (kernel_init) from [<801010e8>] (ret_from_fork+0x14/0x2c)
    Exception stack(0x9e4a1fb0 to 0x9e4a1ff8)
    1fa0: 00000000 00000000 00000000 00000000
    1fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    1fe0: 00000000 00000000 00000000 00000000 00000013 00000000
    ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) ]---

    假设看到内核启动过程中的打印,说明前的搭建是成功的。

    这里简介下qemu命令的參数:

    -M vexpress-a9 模拟vexpress-a9单板,你能够使用-M ?參数来获取该qemu版本号支持的全部单板
    
    -m 512M 单板执行物理内存512M
    
    -kernel /home/ivan/kernel_git/linux/arch/arm/boot/zImage  告诉qemu单板执行内核镜像路径
    
    -nographic 不使用图形化界面,仅仅使用串口
    
    -append "console=ttyAMA0" 内核启动參数。这里告诉内核vexpress单板执行。串口设备是哪个tty。从生成的.config文件CONFIG_CONSOLE宏找到

    4. 利用busybox构建最小文件系统(下载地址:https://busybox.net/

      不加载文件系统穷的那个qemu会产生上面贴的log中的panic信息,下面先制作一个可用的最小文件系统。

    a. 编译busybox

      a1. 下载源文件后进行配置

    sly@ubuntu:~/develop$ cd busybox-1.24.2/
    sly@ubuntu:~/develop/busybox-1.24.2$ export ARCH=arm
    sly@ubuntu:~/develop/busybox-1.24.2$ export CROSS_COMPILE=arm-linux-gnueabi-
    sly@ubuntu:~/develop/busybox-1.24.2$ make menuconfig

      a2.menuconfig配置成静态

       Busybox Settings  --->
        Build Options  --->
           [*] Build BusyBox as a static binary (no shared libs) 

      a3. 开始编译, 编译完成后会在busybox目录下生成一个_install的目录,该目录是编译好的文件系统需要使用的一些命令集合。

    sly@ubuntu:~/develop/busybox-1.24.2$ make defconfig
    sly@ubuntu:~/develop/busybox-1.24.2$ make CROSS_COMPILE=arm-linux-gnueabi-
    sly@ubuntu:~/develop/busybox-1.24.2$ make install CROSS_COMPILE=arm-linux-gnueabi-

      生成的_install目录包含如下内容

    sly@ubuntu:~/develop/busybox-1.24.2/_install$ ll
    total 20
    drwxrwxr-x  5 sly sly 4096 Dec  9 08:14 ./
    drwxr-xr-x 36 sly sly 4096 Dec  9 21:08 ../
    drwxrwxr-x  2 sly sly 4096 Dec  9 08:14 bin/
    lrwxrwxrwx  1 sly sly   11 Dec  9 08:14 linuxrc -> bin/busybox*
    drwxrwxr-x  2 sly sly 4096 Dec  9 08:14 sbin/
    drwxrwxr-x  4 sly sly 4096 Oct 30 22:18 usr/

    b. 制作根文件系统

      b1. 新建一个根文件系统的文件夹

    sly@ubuntu:~/develop$ mkdir rootfs
    sly@ubuntu:~/develop$ cd rootfs/

      b2. 拷贝install目录的命令集到文件夹中

    sly@ubuntu:~/develop/rootfs$ cp -rf ../busybox-1.24.2/_install/* .
    sly@ubuntu:~/develop/rootfs$ ls
    bin  dev  lib  linuxrc  sbin  usr

      b3. 新建lib目录,从工具链中拷贝执行库到lib文件夹下

    sly@ubuntu:~/develop/rootfs$ mkdir lib
    sly@ubuntu:~/develop/rootfs$ cp -p /usr/arm-linux-gnueabi/lib/* ./lib

      b4. 创建设备文件, 创建4个串口设备,和控制台

    sly@ubuntu:~/develop/rootfs$ sudo mknod dev/tty1 c 4 1
    sly@ubuntu:~/develop/rootfs$ sudo mknod dev/tty2 c 4 2
    sly@ubuntu:~/develop/rootfs$ sudo mknod dev/tty3 c 4 3
    sly@ubuntu:~/develop/rootfs$ sudo mknod dev/tty4 c 4 4
    sly@ubuntu:~/develop/rootfs$sudo mknod -m 666 console c 5 1

      b5.  制作SD根文件系统镜像, 生成虚拟sd卡并格式化为ext格式:

    dd if=/dev/zero of=rootfs.ext3 bs=1M count=32

    mkfs.ext3 rootfs.ext3
    sly@ubuntu:~/develop$ dd if=/dev/zero of=rootfs.ext3 bs=1M count=32
    32+0 records in
    32+0 records out
    33554432 bytes (34 MB, 32 MiB) copied, 0.0941612 s, 356 MB/s
    sly@ubuntu:~/develop$ mkfs.ext3 rootfs.ext3
    mke2fs 1.44.1 (24-Mar-2018)
    Discarding device blocks: done                            
    Creating filesystem with 32768 1k blocks and 8192 inodes
    Filesystem UUID: fe2c8081-588f-4e0c-b0c7-09489d0fded5
    Superblock backups stored on blocks: 
            8193, 24577
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (4096 blocks): done
    Writing superblocks and filesystem accounting information: done

    sly@ubuntu:~/develop$ ls
    busybox-1.24.2 linux-5.3.7 linux-5.3.7.tar rootfs rootfs.ext3 tmpfs

      b6. 将虚拟sd卡挂载到/tmpfs,拷贝rootfs的所有文件到sd,卸载sd(块设备不能直接读写)

    sudo mkdir tmpfs

    sudo mount -t ext3 rootfs.ext3 tmpfs/ -o loop
    sudo cp -r rootfs/*  tmpfs/
    sudo umount tmpfs

    sly@ubuntu:~/develop$ sudo mount -t ext3 rootfs.ext3 tmpfs/ -o loop
    sly@ubuntu:~/develop$ sudo cp -r rootfs/* tmpfs/
    sly@ubuntu:~/develop$ ls tmpfs/
    bin dev lib linuxrc lost+found sbin usr
    sly@ubuntu:~/develop$ sudo umount tmpfs
    sly@ubuntu:~/develop$ ls tmpfs/
    sly@ubuntu:~/develop$

     5. 启动内核,挂载rootfs

     qemu-system-arm -M vexpress-a9 -m 512m -kernel /home/sly/develop/linux-5.3.7/arch/arm/boot/zImage -dtb linux-5.3.7/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -nographic -append "root=/dev/mmcblk0 console=ttyAMA0"  -sd rootfs.ext3

    sly@ubuntu:~/develop$  qemu-system-arm -M vexpress-a9 -m 512m -kernel /home/sly/develop/linux-5.3.7/arch/arm/boot/zImage -dtb linux-5.3.7/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -nographic -append "root=/dev/mmcblk0 console=ttyAMA0"  -sd rootfs.ext3
    WARNING: Image format was not specified for 'rootfs.ext3' and probing guessed raw.
             Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
             Specify the 'raw' format explicitly to remove the restrictions.
    pulseaudio: set_sink_input_volume() failed
    pulseaudio: Reason: Invalid argument
    pulseaudio: set_sink_input_mute() failed
    pulseaudio: Reason: Invalid argument
    Booting Linux on physical CPU 0x0
    Linux version 5.3.7 (sly@ubuntu) (gcc version 7.4.0 (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1)) #4 SMP Mon Dec 9 08:31:07 PST 2019=====================================================......=========================================================================
    ALSA device list:
      #0: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 24
    input: ImExPS/2 Generic Explorer Mouse as /devices/platform/smb@4000000/smb@4000000:motherboard/smb@4000000:motherboard:iofpga@7,00000000/10007000.kmi/serio1/input/input2
    Error: Driver 'vexpress-muxfpga' is already registered, aborting...
    drm-clcd-pl111 10020000.clcd: initializing Versatile Express PL111
    drm-clcd-pl111 10020000.clcd: DVI muxed to daughterboard 1 (core tile) CLCD
    EXT4-fs (mmcblk0): mounting ext3 file system using the ext4 subsystem
    random: fast init done
    EXT4-fs (mmcblk0): mounted filesystem with ordered data mode. Opts: (null)
    VFS: Mounted root (ext3 filesystem) readonly on device 179:0.
    Freeing unused kernel memory: 1024K
    Run /sbin/init as init process
    random: crng init done
    can't run '/etc/init.d/rcS': No such file or directory
    
    Please press Enter to activate this console. 
    / # 

     / # ls
      bin dev lib linuxrc lost+found sbin usr

     6. 编写简单的模块进行加载

    文件目录结构如下

    sly@ubuntu:~/develop/module/first$ ls
    first.c  Makefile

    编写源文件

    #include <linux/module.h>
    #include <linux/kernel.h>
    
    int init_hello_module(void)
    {
        printk("init hello_moudle
    ");
        return 0;
    }
    
    void exit_hello_module(void)
    {
        printk("exit hello_module
    ");
    }
    
    module_init(init_hello_module);
    module_exit(exit_hello_module);
    
    MODULE_LICENSE("GPL");

    makefile文件

    KERN_DIR=../../linux-5.3.7
      
    all:
            make -C $(KERN_DIR) M=`pwd` modules 
    
    clean:
            make -C $(KERN_DIR) M=`pwd` modules clean
            rm -rf modules.order
    
    obj-m   += first.o

    执行编译,编译出ko文件

    sly@ubuntu:~/develop/module/first$ make
    make -C ../../linux-5.3.7 M=`pwd` modules 
    make[1]: Entering directory '/home/sly/develop/linux-5.3.7'
      CC [M]  /home/sly/develop/module/first/first.o
      Building modules, stage 2.
      MODPOST 1 modules
      CC      /home/sly/develop/module/first/first.mod.o
      LD [M]  /home/sly/develop/module/first/first.ko
    make[1]: Leaving directory '/home/sly/develop/linux-5.3.7'
    sly@ubuntu:~/develop/module/first$ ls
    first.c  first.ko  first.mod  first.mod.c  first.mod.o  first.o  Makefile  modules.order  Module.symvers
    rootfs根文件系统下面创建一个modules目录用来存放ko文件
    拷贝rootfs的内容到rootfs.ext3虚拟SD中

    mount -t ext3 rootfs.ext3 /mnt/ -o loop
    cp -r rootfs/* /mnt
    umount /mnt

    启动开发板,加载KO
    / # ls
    bin         lib         lost+found  sbin
    dev         linuxrc     modules     usr
    / # cd te
    -/bin/sh: cd: can't cd to te
    / # cd modules/
    /modules # ls
    first.ko
    /modules # insmod first.ko 
    first: loading out-of-tree module taints kernel.
    init hello_moudle
    /modules # rmmod first.ko 
    rmmod: can't change directory to '/lib/modules': No such file or directory
    /lib # lsmod
    lsmod: can't open '/proc/modules': No such file or directory

     7. 继续完善文件系统

     a. 创建etc及inittable文件,语句含义参考: https://blog.csdn.net/u014089899/article/details/80622607

    sly@ubuntu:~/develop/rootfs$ mkdir etc
    sly@ubuntu:~/develop/rootfs$ cd etc/
    sly@ubuntu:~/develop/rootfs/etc$ sudo vi inittab

    inittab内容如下

    ::sysinit:/etc/init.d/rcS
    #::respawn:-/bin/sh
    #tty2::askfirst:-/bin/sh
    #::ctrlaltdel:/bin/umount -a -r
    
    console::askfirst:-/bin/sh
    ::ctrlaltdel:/sbin/reboot
    ::shutdown:/bin/umount -a -r

    创建fstab,相应文件夹需要自行创建好  含义参考:https://blog.csdn.net/xyajia/article/details/79165655

    sly@ubuntu:~/develop/rootfs/etc$ sudo vi fstab
    # /etc/fstab: static file system information.
    # 
    # Use 'blkid' to print the universally unique identifier for a
    # device; this may be used with UUID= as a more robust way to name devices
    # that works even if disks are added and removed. See fstab(5).
    #
    # <file system> <mount point>   <type>  <options>       <dump>  <pass>
    # / was on /dev/sda1 during installation
    proc            /proc           proc    defaults                0       0
    tmpfs           /tmp            tmpfs   defaults                0       0
    sysfs           /sys            sysfs   defaults                0       0
    tmpfs           /dev            tmpfs   defaults                0       0
    var             /dev            tmpfs   defaults                0       0
    ramfs           /dev            ramfs   defaults                0       0

    创建init.d/rcS

    sly@ubuntu:~/develop/rootfs/etc$ sudo mkdir init.d
    sly@ubuntu:~/develop/rootfs/etc$ cd init.d/
    sly@ubuntu:~/develop/rootfs/etc/init.d$ sudo vi rcS
    
    #! /bin/sh
    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    LD_LIBRARY_PATH=/lib
    export PATH LD_LIBRARY_PATH
    
    mount -a
    mkdir -p /dev/pts
    mount -t devpts devpts /dev/pts
    mdev -s
    mkdir -p /var/lock
    echo "----------------------------------------"
    
    echo " welcome debugging on A9 vexpress board"
    
    echo "----------------------------------------"
    sly@ubuntu:~/develop/rootfs/etc/init.d$ sudo chmod 777 rcS

    用最新的rootfs覆盖rootfs.ext3虚拟SD卡,启动开发板验证,效果如下:(出错部分不知道问什么挂在到mnt后在mnt中没有可执行权限,添加下可执行权限就行

    Error: Driver 'vexpress-muxfpga' is already registered, aborting...
    drm-clcd-pl111 10020000.clcd: initializing Versatile Express PL111
    drm-clcd-pl111 10020000.clcd: DVI muxed to daughterboard 1 (core tile) CLCD
    input: AT Raw Set 2 keyboard as /devices/platform/smb@4000000/smb@4000000:motherboard/smb@4000000:motherboard:iofpga@7,00000000/10006000.kmi/serio0/input/input0
    mmc0: new SD card at address 4567
    Error: Driver 'vexpress-muxfpga' is already registered, aborting...
    drm-clcd-pl111 10020000.clcd: initializing Versatile Express PL111
    drm-clcd-pl111 10020000.clcd: DVI muxed to daughterboard 1 (core tile) CLCD
    mmcblk0: mmc0:4567 QEMU! 32.0 MiB 
    Error: Driver 'vexpress-muxfpga' is already registered, aborting...
    drm-clcd-pl111 10020000.clcd: initializing Versatile Express PL111
    drm-clcd-pl111 10020000.clcd: DVI muxed to daughterboard 1 (core tile) CLCD
    Error: Driver 'vexpress-muxfpga' is already registered, aborting...
    drm-clcd-pl111 10020000.clcd: initializing Versatile Express PL111
    drm-clcd-pl111 10020000.clcd: DVI muxed to daughterboard 1 (core tile) CLCD
    rtc-pl031 10017000.rtc: setting system clock to 2019-12-24T05:46:23 UTC (1577166383)
    ALSA device list:
      #0: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 24
    input: ImExPS/2 Generic Explorer Mouse as /devices/platform/smb@4000000/smb@4000000:motherboard/smb@4000000:motherboard:iofpga@7,00000000/10007000.kmi/serio1/input/input2
    Error: Driver 'vexpress-muxfpga' is already registered, aborting...
    drm-clcd-pl111 10020000.clcd: initializing Versatile Express PL111
    drm-clcd-pl111 10020000.clcd: DVI muxed to daughterboard 1 (core tile) CLCD
    EXT4-fs (mmcblk0): mounting ext3 file system using the ext4 subsystem
    random: fast init done
    EXT4-fs (mmcblk0): mounted filesystem with ordered data mode. Opts: (null)
    VFS: Mounted root (ext3 filesystem) readonly on device 179:0.
    Freeing unused kernel memory: 1024K
    Run /sbin/init as init process
    random: crng init done
    can't run '/etc/init.d/rcS': Permission denied
    
    Please press Enter to activate this console. 
    

    / # ls
    bin etc linuxrc proc sys usr
    dev lib modules sbin tmp var

     进行insmod和rmmod操作,发现还需要创建几个文件夹,根据提示在lib下创建lib/modules和lib/modules/5.3.7,就此告一段落

    /modules # ls
    first.ko  hello
    /modules # cat hello 
    hello
    /modules # vi hello 
    /modules # 

    8.gdb远程调试内核

     8.1.准备gdb

      linux环境安装gcc后默认是不安装配到gdb的,我们调试的远端设备是arm的所以需要安装交叉编译的gdb,我们之前使用的交叉编译工具链是这个 arm-linux-gnueabi-gcc, 所以我们安装对应的gdb。这里下载的是目前较新的8.3版本

      下载地址: http://ftp.gnu.org/gnu/gdb/

      安装方法,建议在源码目录外新建一个文件夹进行编译,目录结构如下

    sly@ubuntu:~/develop$ ls
    build_gdb  busybox-1.24.2  gdb-8.3  linux-5.3.7  linux-5.3.7.tar  module  rootfs  rootfs.ext3  start.sh  stop.sh  tmp

      按照上面的交叉编译工具链进行安装对应的gdb

    sly@ubuntu:~/develop/build_gdb$ ../gdb-8.3/configure --target=arm-linux-gnueabi
    sly@ubuntu:~/develop/build_gdb$ make
    sly@ubuntu:~/develop/build_gdb$ sudo make install

      第一个坑:gdb需要环境上安装了textinfo,否则install的时候会失败,安装方法: sudo apt-get install texinfo

      第二个坑:gdb运行remote调试时需要安装expat, 安装方法: sudo apt-get install expat

      第三个坑:只安装expat不管用,需要安装dev的开发lib,安装方法: sudo apt-get install libexpat1-dev

      第二和第三个坑填上后修改下第一步的configure的传入参数如下,带expat编译gdb,之后make再make install就可以了

    sly@ubuntu:~/develop/build_gdb$ ../gdb-8.3/configure --target=arm-linux-gnueabi --with-expat

      gdb默认安装路径: /usr/local/bin/arm-linux-gnueabi-gdb

      安装完成后查看一下

    sly@ubuntu:~/develop/build_gdb$ arm-linux-gnueabi-gdb -v   
    GNU gdb (GDB) 8.3
    Copyright (C) 2019 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.

    8.2 gdb连接qemu的虚拟环境

      qemu的参数需要加上-s以便于gdb可以通过1234端口对内核进行连接,新的启动参数如下

    qemu-system-arm -M vexpress-a9 -m 512m -kernel /home/sly/develop/linux-5.3.7/arch/arm/boot/zImage -dtb linux-5.3.7/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -nographic -append "root=/dev/mmcblk0 console=ttyAMA0"  -sd rootfs.ext3 -s

       之后另起一个控制台,启动gdb进行连接

    sly@ubuntu:~/develop/linux-5.3.7$ arm-linux-gnueabi-gdb vmlinux
    GNU gdb (GDB) 8.3
    Copyright (C) 2019 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    Type "show copying" and "show warranty" for details.
    This GDB was configured as "--host=x86_64-pc-linux-gnu --target=arm-linux-gnueabi".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
        <http://www.gnu.org/software/gdb/documentation/>.
    
    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from vmlinux...
    (gdb) target remote localhost:1234
    Remote debugging using localhost:1234
    cpu_v7_do_idle () at arch/arm/mm/proc-v7.S:78
    78              ret     lr
    (gdb) 

    大功告成!!

  • 相关阅读:
    Java基础知识三点
    《计算机网络》读书笔记
    Shell编程初步
    《现代操作系统》读书笔记
    《数据库系统概论》读书笔记
    《数据结构》读书笔记
    Linux使用笔记
    【Thinking in Java】读书笔记
    算法题摘录六
    算法题摘录五
  • 原文地址:https://www.cnblogs.com/edver/p/6001786.html
Copyright © 2011-2022 走看看