• i.MX 6ULL 驱动开发 二:搭建 KGDB 调试 linux 内核和驱动环境


    一、参考

    Linux 官方资料:Using kgdb, kdb and the kernel debugger internals — The Linux Kernel documentation

    参考博客:使用KGDB调试Linux驱动(以imx6ull开发板为例)_weixin_38832162的博客-CSDN博客_kgdb 调试驱动

    二、概述

    KGDB是 Linux 内核提供的用于调试内核的源码级调试工具,支持断点设置,单步调试等源码调试常用功能,类似于在用户空间用gdb调试应用程序。

    KGDB 从形式上来说类似于 GDB server,你需要两台设备,一台主机,用于运行普通的 GDB 程序,一台被调试设备,需要安装所需调试的内核或者驱动,同时运行 KGDB。KGDB 与主机通过串口或网口进行通信,所以要在内核的启动参数里指定 KGDB 所需使用相关参数。

    三、在 ubuntu 安装串口助手

    1、安装 minicom

    sudo apt-get install minicom
    
    • 1

    2、连接usb设备前查看 ttyusb 设备

    onlylove@ubuntu:~$ ls /dev/tty*
    /dev/tty    /dev/tty18  /dev/tty28  /dev/tty38  /dev/tty48  /dev/tty58      /dev/ttyS0   /dev/ttyS19  /dev/ttyS29
    /dev/tty0   /dev/tty19  /dev/tty29  /dev/tty39  /dev/tty49  /dev/tty59      /dev/ttyS1   /dev/ttyS2   /dev/ttyS3
    /dev/tty1   /dev/tty2   /dev/tty3   /dev/tty4   /dev/tty5   /dev/tty6       /dev/ttyS10  /dev/ttyS20  /dev/ttyS30
    /dev/tty10  /dev/tty20  /dev/tty30  /dev/tty40  /dev/tty50  /dev/tty60      /dev/ttyS11  /dev/ttyS21  /dev/ttyS31
    /dev/tty11  /dev/tty21  /dev/tty31  /dev/tty41  /dev/tty51  /dev/tty61      /dev/ttyS12  /dev/ttyS22  /dev/ttyS4
    /dev/tty12  /dev/tty22  /dev/tty32  /dev/tty42  /dev/tty52  /dev/tty62      /dev/ttyS13  /dev/ttyS23  /dev/ttyS5
    /dev/tty13  /dev/tty23  /dev/tty33  /dev/tty43  /dev/tty53  /dev/tty63      /dev/ttyS14  /dev/ttyS24  /dev/ttyS6
    /dev/tty14  /dev/tty24  /dev/tty34  /dev/tty44  /dev/tty54  /dev/tty7       /dev/ttyS15  /dev/ttyS25  /dev/ttyS7
    /dev/tty15  /dev/tty25  /dev/tty35  /dev/tty45  /dev/tty55  /dev/tty8       /dev/ttyS16  /dev/ttyS26  /dev/ttyS8
    /dev/tty16  /dev/tty26  /dev/tty36  /dev/tty46  /dev/tty56  /dev/tty9       /dev/ttyS17  /dev/ttyS27  /dev/ttyS9
    /dev/tty17  /dev/tty27  /dev/tty37  /dev/tty47  /dev/tty57  /dev/ttyprintk  /dev/ttyS18  /dev/ttyS28
    onlylove@ubuntu:~$
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    3、将开发板串口连接到 VMware 虚拟机中

    4、查看 ttyusb 设备

    onlylove@ubuntu:~$ ls /dev/tty*
    /dev/tty    /dev/tty18  /dev/tty28  /dev/tty38  /dev/tty48  /dev/tty58      /dev/ttyS0   /dev/ttyS19  /dev/ttyS29
    /dev/tty0   /dev/tty19  /dev/tty29  /dev/tty39  /dev/tty49  /dev/tty59      /dev/ttyS1   /dev/ttyS2   /dev/ttyS3
    /dev/tty1   /dev/tty2   /dev/tty3   /dev/tty4   /dev/tty5   /dev/tty6       /dev/ttyS10  /dev/ttyS20  /dev/ttyS30
    /dev/tty10  /dev/tty20  /dev/tty30  /dev/tty40  /dev/tty50  /dev/tty60      /dev/ttyS11  /dev/ttyS21  /dev/ttyS31
    /dev/tty11  /dev/tty21  /dev/tty31  /dev/tty41  /dev/tty51  /dev/tty61      /dev/ttyS12  /dev/ttyS22  /dev/ttyS4
    /dev/tty12  /dev/tty22  /dev/tty32  /dev/tty42  /dev/tty52  /dev/tty62      /dev/ttyS13  /dev/ttyS23  /dev/ttyS5
    /dev/tty13  /dev/tty23  /dev/tty33  /dev/tty43  /dev/tty53  /dev/tty63      /dev/ttyS14  /dev/ttyS24  /dev/ttyS6
    /dev/tty14  /dev/tty24  /dev/tty34  /dev/tty44  /dev/tty54  /dev/tty7       /dev/ttyS15  /dev/ttyS25  /dev/ttyS7
    /dev/tty15  /dev/tty25  /dev/tty35  /dev/tty45  /dev/tty55  /dev/tty8       /dev/ttyS16  /dev/ttyS26  /dev/ttyS8
    /dev/tty16  /dev/tty26  /dev/tty36  /dev/tty46  /dev/tty56  /dev/tty9       /dev/ttyS17  /dev/ttyS27  /dev/ttyS9
    /dev/tty17  /dev/tty27  /dev/tty37  /dev/tty47  /dev/tty57  /dev/ttyprintk  /dev/ttyS18  /dev/ttyS28  /dev/ttyUSB0
    onlylove@ubuntu:~$
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    ttyUSB0:与开发板连接的 USB 设备号。

    5、minicom 使用教程

    minicom 的使用_002237的博客-CSDN博客_minicom使用

    四、调试 Linux 内核

    1、开启 Linux 内核的 KGDB 选项

    linux内核调试环境搭建(VM_Centos+KGDB) - 简书 (jianshu.com)

    2、设置kgdboc参数

    setenv bootargs 'console=ttymxc0,115200 kgdboc=ttymxc0,115200 kgdbwait root=/dev/nfs nfsroot=192.168.6.129:/home/onlylove/my/nfs,proto=tcp,nfsvers=4 rw ip=192.168.6.200:192.168.6.129:192.168.6.2:255.255.255.0::eth0:off'
    saveenv
    
    • 1
    • 2

    kgdboc的启动参数:kgdboc=ttymxc0,115200

    • ttymxc0 是所需使用的串口设备名
    • 115200 代表波特率
    • kgdbwait 是一个启动参数

    3、启动 linux

    U-Boot 2016.03 (Aug 20 2022 - 00:46:14 -0700)                                
                                                                                 
    CPU:   Freescale i.MX6ULL rev1.1 69 MHz (running at 396 MHz)
    CPU:   Industrial temperature grade (-40C to 105C) at 41C
    Reset cause: POR                        
    Board: MX6ULL ALIENTEK EMMC             
    I2C:   ready                            
    DRAM:  512 MiB                          
    MMC:   FSL_SDHC: 0, FSL_SDHC: 1
    unsupported panel ATK-LCD-7-1024x600
    In:    serial
    Out:   serial
    Err:   serial
    switch to partitions #0, OK
    mmc0 is current device
    Net:   FEC1
    Normal Boot
    Hit any key to stop autoboot:  0 
    FEC1 Waiting for PHY auto negotiation to complete.... done
    Using FEC1 device
    TFTP from server 192.168.6.129; our IP address is 192.168.6.20
    Filename 'zImage'.
    Load address: 0x80800000
    Loading: #################################################################
             #################################################################
             #################################################################
             #################################################################
             #################################################################
             #################################################################
             ##############
             2.1 MiB/s
    done
    Bytes transferred = 5916896 (5a48e0 hex)
    Using FEC1 device
    TFTP from server 192.168.6.129; our IP address is 192.168.6.20
    Filename 'imx6ull-alientek-emmc.dtb'.
    Load address: 0x83000000
    Loading: ###
             2.5 MiB/s
    done
    Bytes transferred = 39280 (9970 hex)
    Kernel image @ 0x80800000 [ 0x000000 - 0x5a48e0 ]
    ## Flattened Device Tree blob at 83000000
       Booting using the fdt blob at 0x83000000
       Using Device Tree in place at 83000000, end 8300c96f
    
    Starting kernel ...
    
    Booting Linux on physical CPU 0x0
    Linux version 4.1.15 (onlylove@ubuntu) (gcc version 4.9.4 (Linaro GCC 4.9-2017.01) ) #2 SMP PREEMPT Sat Sep 10 21:40:18 PDT2
    CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d
    CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
    Machine model: Freescale i.MX6 ULL 14x14 EVK Board
    Reserved memory: created CMA memory pool at 0x8c000000, size 320 MiB
    Reserved memory: initialized node linux,cma, compatible id shared-dma-pool
    Memory policy: Data cache writealloc
    PERCPU: Embedded 12 pages/cpu @8bb2f000 s16768 r8192 d24192 u49152
    Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 130048
    Kernel command line: console=ttymxc0,115200 kgdboc=ttymxc0,115200 kgdbwait root=/dev/nfs nfsroot=192.168.6.129:/home/onlylof
    PID hash table entries: 2048 (order: 1, 8192 bytes)
    Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
    Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
    Memory: 180184K/524288K available (7312K kernel code, 334K rwdata, 2528K rodata, 404K init, 457K bss, 16424K reserved, 3276)
    Virtual kernel memory layout:
        vector  : 0xffff0000 - 0xffff1000   (   4 kB)
        fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
        vmalloc : 0xa0800000 - 0xff000000   (1512 MB)
        lowmem  : 0x80000000 - 0xa0000000   ( 512 MB)
        pkmap   : 0x7fe00000 - 0x80000000   (   2 MB)
        modules : 0x7f000000 - 0x7fe00000   (  14 MB)
          .text : 0x80008000 - 0x809a44e0   (9842 kB)
          .init : 0x809a5000 - 0x80a0a000   ( 404 kB)
          .data : 0x80a0a000 - 0x80a5d8a0   ( 335 kB)
           .bss : 0x80a60000 - 0x80ad2444   ( 458 kB)
    SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
    Preemptible hierarchical RCU implementation.
            Additional per-CPU info printed with stalls.
            RCU restricting CPUs from NR_CPUS=4 to nr_cpu_ids=1.
    RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
    NR_IRQS:16 nr_irqs:16 16
    mxc_clocksource_init 3000000
    Switching to timer-based delay loop, resolution 333ns
    sched_clock: 32 bits at 3000kHz, resolution 333ns, wraps every 715827882841ns
    clocksource mxc_timer1: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 637086815595 ns
    Console: colour dummy device 80x30
    Calibrating delay loop (skipped), value calculated using timer frequency.. 6.00 BogoMIPS (lpj=30000)
    pid_max: default: 32768 minimum: 301
    Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
    Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
    CPU: Testing write buffer coherency: ok
    /cpus/cpu@0 missing clock-frequency property
    CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
    Setting up static identity map for 0x80008280 - 0x800082f0
    Brought up 1 CPUs
    SMP: Total of 1 processors activated (6.00 BogoMIPS).
    CPU: All CPU(s) started in SVC mode.
    devtmpfs: initialized
    device-tree: Duplicate name in lcdif@021c8000, renamed to "display#1"
    VFP support v0.3: implementor 41 architecture 2 part 30 variant 7 rev 5
    clocksource jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
    pinctrl core: initialized pinctrl subsystem
    NET: Registered protocol family 16
    DMA: preallocated 256 KiB pool for atomic coherent allocations
    cpuidle: using governor ladder
    cpuidle: using governor menu
    hw-breakpoint: found 5 (+1 reserved) breakpoint and 4 watchpoint registers.
    hw-breakpoint: maximum watchpoint size is 8 bytes.
    imx6ul-pinctrl 20e0000.iomuxc: Invalid fsl,pins property in node /soc/aips-bus@02000000/iomuxc@020e0000/imx6ul-evk/flexcan2p
    imx6ul-pinctrl 20e0000.iomuxc: Invalid fsl,pins property in node /soc/aips-bus@02000000/iomuxc@020e0000/imx6ul-evk/uart2dtep
    imx6ul-pinctrl 20e0000.iomuxc: initialized IMX pinctrl driver
    imx6ul-pinctrl 2290000.iomuxc-snvs: Invalid fsl,pins property in node /soc/aips-bus@02200000/iomuxc-snvs@02290000/imx6ul-evp
    imx6ul-pinctrl 2290000.iomuxc-snvs: initialized IMX pinctrl driver
    mxs-dma 1804000.dma-apbh: initialized
    SCSI subsystem initialized
    usbcore: registered new interface driver usbfs
    usbcore: registered new interface driver hub
    usbcore: registered new device driver usb
    i2c i2c-0: IMX I2C adapter registered
    i2c i2c-0: can't use DMA
    i2c i2c-1: IMX I2C adapter registered
    i2c i2c-1: can't use DMA
    Linux video capture interface: v2.00
    pps_core: LinuxPPS API ver. 1 registered
    pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
    PTP clock support registered
    Advanced Linux Sound Architecture Driver Initialized.
    Switched to clocksource mxc_timer1
    NET: Registered protocol family 2
    TCP established hash table entries: 4096 (order: 2, 16384 bytes)
    TCP bind hash table entries: 4096 (order: 3, 32768 bytes)
    TCP: Hash tables configured (established 4096 bind 4096)
    UDP hash table entries: 256 (order: 1, 8192 bytes)
    UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)
    NET: Registered protocol family 1
    RPC: Registered named UNIX socket transport module.
    RPC: Registered udp transport module.
    RPC: Registered tcp transport module.
    RPC: Registered tcp NFSv4.1 backchannel transport module.
    imx rpmsg driver is registered.
    Bus freq driver module loaded
    futex hash table entries: 256 (order: 2, 16384 bytes)
    VFS: Disk quotas dquot_6.6.0
    VFS: Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
    NFS: Registering the id_resolver key type
    Key type id_resolver registered
    Key type id_legacy registered
    jffs2: version 2.2. (NAND) é 2001-2006 Red Hat, Inc.
    fuse init (API version 7.23)
    io scheduler noop registered
    io scheduler deadline registered
    io scheduler cfq registered (default)
    imx-weim 21b8000.weim: Driver registered.
    backlight supply power not found, using dummy regulator
    21c8000.lcdif supply lcd not found, using dummy regulator
    mxsfb 21c8000.lcdif: failed to find mxc display driver 
    Console: switching to colour frame buffer device 128x37
    mxsfb 21c8000.lcdif: initialized
    imx-sdma 20ec000.sdma: no event needs to be remapped
    imx-sdma 20ec000.sdma: loaded firmware 3.3
    imx-sdma 20ec000.sdma: initialized
    2020000.serial: ttymxc0 at MMIO 0x2020000 (irq = 19, base_baud = 5000000) is a IMX
    console [ttymxc0] enabled
    21ec000.serial: ttymxc2 at MMIO 0x21ec000 (irq = 233, base_baud = 5000000) is a IMX
    KGDB: Registered I/O driver kgdboc
    KGDB: Waiting for connection from remote gdb...
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165

    通过日志可以确定 KGDB 已经启动成功了,正在等待远端 GDB 连接。

    4、调试内核

    1、强行关闭minicom,因为GDB调试中需要使用minicom。

    2、输入如下指令

    arm-linux-gnueabihf-gdb ./vmlinux
    
    • 1

    3、设置串口助手

    set serial baud 115200
    
    • 1

    4、gdb通过minicom连接开发板

    target remote /dev/ttyUSB0
    
    • 1

    5、调试日志

    onlylove@ubuntu:~/my/linux/linux-imx-rel_imx_4.1.15_2.1.0_ga_alientek$ arm-linux-gnueabihf-gdb ./vmlinux
    GNU gdb (Linaro_GDB-2017.01) 7.10.1.20160210-cvs
    Copyright (C) 2015 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-unknown-linux-gnu --target=arm-linux-gnueabihf".
    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...done.
    (gdb) set serial baud 115200
    (gdb) target remote /dev/ttyUSB0
    Remote debugging using /dev/ttyUSB0
    0x8009d45c in arch_kgdb_breakpoint () at ./arch/arm/include/asm/outercache.h:142
    142			outer_cache.sync();
    (gdb)
    (gdb) list
    137	 * buffers are drained.
    138	 */
    139	static inline void outer_sync(void)
    140	{
    141		if (outer_cache.sync)
    142			outer_cache.sync();
    143	}
    144	#else
    145	static inline void outer_sync(void)
    146	{ }
    (gdb)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34

    通过以上日志可以确定,gdb连接开发板成功。

    五、解决日志输出和GDB使用串口冲突问题

    问题:日志输出和KGDB共用串口,因此,在使用KGDB时,需要强行关闭日志输出。

    解决方案:agent-proxy

    1、下载 agent-proxy

    kernel/kgdb/agent-proxy.git - agent-proxy for kgdb

    git clone git://git.kernel.org/pub/scm/utils/kernel/kgdb/agent-proxy.git
    
    • 1
    onlylove@ubuntu:~/my/demo$ pwd
    /home/onlylove/my/demo
    onlylove@ubuntu:~/my/demo$ ls
    onlylove@ubuntu:~/my/demo$ git clone git://git.kernel.org/pub/scm/utils/kernel/kgdb/agent-proxy.git
    Cloning into 'agent-proxy'...
    remote: Enumerating objects: 80, done.
    remote: Counting objects: 100% (80/80), done.
    remote: Compressing objects: 100% (79/79), done.
    remote: Total 80 (delta 46), reused 0 (delta 0), pack-reused 0
    Receiving objects: 100% (80/80), 39.67 KiB | 84.00 KiB/s, done.
    Resolving deltas: 100% (46/46), done.
    onlylove@ubuntu:~/my/demo$ ls
    agent-proxy
    onlylove@ubuntu:~/my/demo$
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    2、编译

    make
    
    • 1
    onlylove@ubuntu:~/my/demo/agent-proxy$ pwd
    /home/onlylove/my/demo/agent-proxy
    onlylove@ubuntu:~/my/demo/agent-proxy$ ls
    agent-proxy.c  agent-proxy.h  agent-proxy-rs232.c  COPYING  Example  kdmx  Makefile  README.TXT
    onlylove@ubuntu:~/my/demo/agent-proxy$ make
    gcc -DAGENT_VER=1.97 -g -Wall -Wno-unused-parameter -Dlinux -c agent-proxy.c -o agent-proxy.o
    gcc -DAGENT_VER=1.97 -g -Wall -Wno-unused-parameter -Dlinux -c agent-proxy-rs232.c -o agent-proxy-rs232.o
    gcc -DAGENT_VER=1.97 -g -Wall -Wno-unused-parameter -Dlinux -o agent-proxy agent-proxy.o agent-proxy-rs232.o 
    onlylove@ubuntu:~/my/demo/agent-proxy$ ls
    agent-proxy    agent-proxy.h  agent-proxy-rs232.c  COPYING  kdmx      README.TXT
    agent-proxy.c  agent-proxy.o  agent-proxy-rs232.o  Example  Makefile
    onlylove@ubuntu:~/my/demo/agent-proxy$
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    3、将 agent-proxy 拷贝到 /bin 目录下

    sudo cp agent-proxy /bin
    
    • 1
    onlylove@ubuntu:~/my/demo/agent-proxy$ ls
    agent-proxy    agent-proxy.h  agent-proxy-rs232.c  COPYING  kdmx      README.TXT
    agent-proxy.c  agent-proxy.o  agent-proxy-rs232.o  Example  Makefile
    onlylove@ubuntu:~/my/demo/agent-proxy$ sudo cp agent-proxy /bin
    onlylove@ubuntu:~/my/demo/agent-proxy$ ls /bin/agent-proxy -l
    -rwxr-xr-x 1 root root 70960 Sep 10 22:29 /bin/agent-proxy
    onlylove@ubuntu:~/my/demo/agent-proxy$
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    4、开启 agent-proxy

    agent-proxy 5550^5551 0 /dev/ttyUSB0,115200
    
    • 1

    agent-proxy 将 ttyUSB0 这个端口复用为两个 telnet端口。

    onlylove@ubuntu:~$ 
    onlylove@ubuntu:~$ agent-proxy 5550^5551 0 /dev/ttyUSB0,115200
    Agent Proxy 1.97 Started with: 5550^5551 0 /dev/ttyUSB0,115200
    Agent Proxy running. pid: 1712
    
    • 1
    • 2
    • 3
    • 4

    注意:以上终端不可以关闭。

    5、使用 agent-proxy 开启日志终端

    telnet localhost 5550
    
    • 1
    onlylove@ubuntu:~$ telnet localhost 5550
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    
    • 1
    • 2
    • 3
    • 4

    6、开启开发板

    onlylove@ubuntu:~$ telnet localhost 5550
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    
    
    U-Boot 2016.03 (Aug 20 2022 - 00:46:14 -0700)
    
    CPU:   Freescale i.MX6ULL rev1.1 69 MHz (running at 396 MHz)
    CPU:   Industrial temperature grade (-40C to 105C) at 48C
    Reset cause: POR
    Board: MX6ULL ALIENTEK EMMC
    I2C:   ready
    DRAM:  512 MiB
    MMC:   FSL_SDHC: 0, FSL_SDHC: 1
    unsupported panel ATK-LCD-7-1024x600
    In:    serial
    Out:   serial
    Err:   serial
    switch to partitions #0, OK
    mmc0 is current device
    Net:   FEC1
    Normal Boot
    Hit any key to stop autoboot:  0 
    FEC1 Waiting for PHY auto negotiation to complete.... done
    Using FEC1 device
    TFTP from server 192.168.6.129; our IP address is 192.168.6.20
    Filename 'zImage'.
    Load address: 0x80800000
    Loading: #################################################################
    	 #################################################################
    	 #################################################################
    	 #################################################################
    	 #################################################################
    	 #################################################################
    	 ##############
    	 2.2 MiB/s
    done
    Bytes transferred = 5916896 (5a48e0 hex)
    Using FEC1 device
    TFTP from server 192.168.6.129; our IP address is 192.168.6.20
    Filename 'imx6ull-alientek-emmc.dtb'.
    Load address: 0x83000000
    Loading: ###
    	 2.5 MiB/s
    done
    Bytes transferred = 39280 (9970 hex)
    Kernel image @ 0x80800000 [ 0x000000 - 0x5a48e0 ]
    ## Flattened Device Tree blob at 83000000
       Booting using the fdt blob at 0x83000000
       Using Device Tree in place at 83000000, end 8300c96f
    
    Starting kernel ...
    
    Booting Linux on physical CPU 0x0
    Linux version 4.1.15 (onlylove@ubuntu) (gcc version 4.9.4 (Linaro GCC 4.9-2017.01) ) #2 SMP PREEMPT Sat Sep 10 21:40:18 PDT 2022
    CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d
    CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
    Machine model: Freescale i.MX6 ULL 14x14 EVK Board
    Reserved memory: created CMA memory pool at 0x8c000000, size 320 MiB
    Reserved memory: initialized node linux,cma, compatible id shared-dma-pool
    Memory policy: Data cache writealloc
    PERCPU: Embedded 12 pages/cpu @8bb2f000 s16768 r8192 d24192 u49152
    Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 130048
    Kernel command line: console=ttymxc0,115200 kgdboc=ttymxc0,115200 kgdbwait root=/dev/nfs nfsroot=192.168.6.129:/home/onlylove/my/nfs,proto=tcp,nfsvers=4 rw ip=192.168.6.200:192.168.6.129:192.168.6.2:255.255.255.0::eth0:off
    PID hash table entries: 2048 (order: 1, 8192 bytes)
    Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
    Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
    Memory: 180184K/524288K available (7312K kernel code, 334K rwdata, 2528K rodata, 404K init, 457K bss, 16424K reserved, 327680K cma-reserved, 0K highmem)
    Virtual kernel memory layout:
        vector  : 0xffff0000 - 0xffff1000   (   4 kB)
        fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
        vmalloc : 0xa0800000 - 0xff000000   (1512 MB)
        lowmem  : 0x80000000 - 0xa0000000   ( 512 MB)
        pkmap   : 0x7fe00000 - 0x80000000   (   2 MB)
        modules : 0x7f000000 - 0x7fe00000   (  14 MB)
          .text : 0x80008000 - 0x809a44e0   (9842 kB)
          .init : 0x809a5000 - 0x80a0a000   ( 404 kB)
          .data : 0x80a0a000 - 0x80a5d8a0   ( 335 kB)
           .bss : 0x80a60000 - 0x80ad2444   ( 458 kB)
    SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
    Preemptible hierarchical RCU implementation.
    	Additional per-CPU info printed with stalls.
    	RCU restricting CPUs from NR_CPUS=4 to nr_cpu_ids=1.
    RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
    NR_IRQS:16 nr_irqs:16 16
    mxc_clocksource_init 3000000
    Switching to timer-based delay loop, resolution 333ns
    sched_clock: 32 bits at 3000kHz, resolution 333ns, wraps every 715827882841ns
    clocksource mxc_timer1: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 637086815595 ns
    Console: colour dummy device 80x30
    Calibrating delay loop (skipped), value calculated using timer frequency.. 6.00 BogoMIPS (lpj=30000)
    pid_max: default: 32768 minimum: 301
    Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
    Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
    CPU: Testing write buffer coherency: ok
    /cpus/cpu@0 missing clock-frequency property
    CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
    Setting up static identity map for 0x80008280 - 0x800082f0
    Brought up 1 CPUs
    SMP: Total of 1 processors activated (6.00 BogoMIPS).
    CPU: All CPU(s) started in SVC mode.
    devtmpfs: initialized
    device-tree: Duplicate name in lcdif@021c8000, renamed to "display#1"
    VFP support v0.3: implementor 41 architecture 2 part 30 variant 7 rev 5
    clocksource jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
    pinctrl core: initialized pinctrl subsystem
    NET: Registered protocol family 16
    DMA: preallocated 256 KiB pool for atomic coherent allocations
    cpuidle: using governor ladder
    cpuidle: using governor menu
    hw-breakpoint: found 5 (+1 reserved) breakpoint and 4 watchpoint registers.
    hw-breakpoint: maximum watchpoint size is 8 bytes.
    imx6ul-pinctrl 20e0000.iomuxc: Invalid fsl,pins property in node /soc/aips-bus@02000000/iomuxc@020e0000/imx6ul-evk/flexcan2grp
    imx6ul-pinctrl 20e0000.iomuxc: Invalid fsl,pins property in node /soc/aips-bus@02000000/iomuxc@020e0000/imx6ul-evk/uart2dtegrp
    imx6ul-pinctrl 20e0000.iomuxc: initialized IMX pinctrl driver
    imx6ul-pinctrl 2290000.iomuxc-snvs: Invalid fsl,pins property in node /soc/aips-bus@02200000/iomuxc-snvs@02290000/imx6ul-evk/lcdifresetgrp
    imx6ul-pinctrl 2290000.iomuxc-snvs: initialized IMX pinctrl driver
    mxs-dma 1804000.dma-apbh: initialized
    SCSI subsystem initialized
    usbcore: registered new interface driver usbfs
    usbcore: registered new interface driver hub
    usbcore: registered new device driver usb
    i2c i2c-0: IMX I2C adapter registered
    i2c i2c-0: can't use DMA
    i2c i2c-1: IMX I2C adapter registered
    i2c i2c-1: can't use DMA
    Linux video capture interface: v2.00
    pps_core: LinuxPPS API ver. 1 registered
    pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
    PTP clock support registered
    Advanced Linux Sound Architecture Driver Initialized.
    Switched to clocksource mxc_timer1
    NET: Registered protocol family 2
    TCP established hash table entries: 4096 (order: 2, 16384 bytes)
    TCP bind hash table entries: 4096 (order: 3, 32768 bytes)
    TCP: Hash tables configured (established 4096 bind 4096)
    UDP hash table entries: 256 (order: 1, 8192 bytes)
    UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)
    NET: Registered protocol family 1
    RPC: Registered named UNIX socket transport module.
    RPC: Registered udp transport module.
    RPC: Registered tcp transport module.
    RPC: Registered tcp NFSv4.1 backchannel transport module.
    imx rpmsg driver is registered.
    Bus freq driver module loaded
    futex hash table entries: 256 (order: 2, 16384 bytes)
    VFS: Disk quotas dquot_6.6.0
    VFS: Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
    NFS: Registering the id_resolver key type
    Key type id_resolver registered
    Key type id_legacy registered
    jffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
    fuse init (API version 7.23)
    io scheduler noop registered
    io scheduler deadline registered
    io scheduler cfq registered (default)
    imx-weim 21b8000.weim: Driver registered.
    backlight supply power not found, using dummy regulator
    21c8000.lcdif supply lcd not found, using dummy regulator
    mxsfb 21c8000.lcdif: failed to find mxc display driver 
    Console: switching to colour frame buffer device 128x37
    mxsfb 21c8000.lcdif: initialized
    imx-sdma 20ec000.sdma: no event needs to be remapped
    imx-sdma 20ec000.sdma: loaded firmware 3.3
    imx-sdma 20ec000.sdma: initialized
    2020000.serial: ttymxc0 at MMIO 0x2020000 (irq = 19, base_baud = 5000000) is a IMX
    console [ttymxc0] enabled
    21ec000.serial: ttymxc2 at MMIO 0x21ec000 (irq = 233, base_baud = 5000000) is a IMX
    KGDB: Registered I/O driver kgdboc
    KGDB: Waiting for connection from remote gdb...
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171

    7、使用 agent-proxy 开启调试终端

    telnet localhost 5551
    
    • 1

    六、调试 Linux 驱动

    1、选择驱动程序

    因为使用正点原子 imx6ull 开发板,因此使用正点原子提供驱动。因为驱动需要设备树支持,因此选择1_chrdevbase驱动程序。

    2、修改 kgdboc 参数

    setenv bootargs 'console=ttymxc0,115200 kgdboc=ttymxc0,115200 root=/dev/nfs nfsroot=192.168.6.129:/home/onlylove/my/nfs,proto=tcp,nfsvers=4 rw ip=192.168.6.200:192.168.6.129:192.168.6.2:255.255.255.0::eth0:off'
    saveenv
    
    • 1
    • 2

    kgdbwait 参数会让 Linux 内核停下来,因此需要删除。

    3、开启 agent-proxy

    agent-proxy 5550^5551 0 /dev/ttyUSB0,115200
    
    • 1

    4、开启日志终端

    telnet localhost 5550
    
    • 1
    U-Boot 2016.03 (Aug 20 2022 - 00:46:14 -0700)
    
    CPU:   Freescale i.MX6ULL rev1.1 69 MHz (running at 396 MHz)
    CPU:   Industrial temperature grade (-40C to 105C) at 52C
    Reset cause: POR
    Board: MX6ULL ALIENTEK EMMC
    I2C:   ready
    DRAM:  512 MiB
    MMC:   FSL_SDHC: 0, FSL_SDHC: 1
    unsupported panel ATK-LCD-7-1024x600
    In:    serial
    Out:   serial
    Err:   serial
    switch to partitions #0, OK
    mmc0 is current device
    Net:   FEC1
    Normal Boot
    Hit any key to stop autoboot:  0 
    FEC1 Waiting for PHY auto negotiation to complete.... done
    Using FEC1 device
    TFTP from server 192.168.6.129; our IP address is 192.168.6.20
    Filename 'zImage'.
    Load address: 0x80800000
    Loading: #################################################################
    	 #################################################################
    	 #################################################################
    	 #################################################################
    	 #################################################################
    	 #################################################################
    	 ##############
    	 2.1 MiB/s
    done
    Bytes transferred = 5916896 (5a48e0 hex)
    Using FEC1 device
    TFTP from server 192.168.6.129; our IP address is 192.168.6.20
    Filename 'imx6ull-alientek-emmc.dtb'.
    Load address: 0x83000000
    Loading: ###
    	 2.2 MiB/s
    done
    Bytes transferred = 39280 (9970 hex)
    Kernel image @ 0x80800000 [ 0x000000 - 0x5a48e0 ]
    ## Flattened Device Tree blob at 83000000
       Booting using the fdt blob at 0x83000000
       Using Device Tree in place at 83000000, end 8300c96f
    
    Starting kernel ...
    
    Booting Linux on physical CPU 0x0
    Linux version 4.1.15 (onlylove@ubuntu) (gcc version 4.9.4 (Linaro GCC 4.9-2017.01) ) #2 SMP PREEMPT Sat Sep 10 21:40:18 PDT 2022
    CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d
    CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
    Machine model: Freescale i.MX6 ULL 14x14 EVK Board
    Reserved memory: created CMA memory pool at 0x8c000000, size 320 MiB
    Reserved memory: initialized node linux,cma, compatible id shared-dma-pool
    Memory policy: Data cache writealloc
    PERCPU: Embedded 12 pages/cpu @8bb2f000 s16768 r8192 d24192 u49152
    Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 130048
    Kernel command line: console=ttymxc0,115200 kgdboc=ttymxc0,115200 root=/dev/nfs nfsroot=192.168.6.129:/home/onlylove/my/nfs,proto=tcp,nfsvers=4 rw ip=192.168.6.200:192.168.6.129:192.168.6.2:255.255.255.0::eth0:off
    PID hash table entries: 2048 (order: 1, 8192 bytes)
    Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
    Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
    Memory: 180184K/524288K available (7312K kernel code, 334K rwdata, 2528K rodata, 404K init, 457K bss, 16424K reserved, 327680K cma-reserved, 0K highmem)
    Virtual kernel memory layout:
        vector  : 0xffff0000 - 0xffff1000   (   4 kB)
        fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
        vmalloc : 0xa0800000 - 0xff000000   (1512 MB)
        lowmem  : 0x80000000 - 0xa0000000   ( 512 MB)
        pkmap   : 0x7fe00000 - 0x80000000   (   2 MB)
        modules : 0x7f000000 - 0x7fe00000   (  14 MB)
          .text : 0x80008000 - 0x809a44e0   (9842 kB)
          .init : 0x809a5000 - 0x80a0a000   ( 404 kB)
          .data : 0x80a0a000 - 0x80a5d8a0   ( 335 kB)
           .bss : 0x80a60000 - 0x80ad2444   ( 458 kB)
    SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
    Preemptible hierarchical RCU implementation.
    	Additional per-CPU info printed with stalls.
    	RCU restricting CPUs from NR_CPUS=4 to nr_cpu_ids=1.
    RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
    NR_IRQS:16 nr_irqs:16 16
    mxc_clocksource_init 3000000
    Switching to timer-based delay loop, resolution 333ns
    sched_clock: 32 bits at 3000kHz, resolution 333ns, wraps every 715827882841ns
    clocksource mxc_timer1: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 637086815595 ns
    Console: colour dummy device 80x30
    Calibrating delay loop (skipped), value calculated using timer frequency.. 6.00 BogoMIPS (lpj=30000)
    pid_max: default: 32768 minimum: 301
    Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
    Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
    CPU: Testing write buffer coherency: ok
    /cpus/cpu@0 missing clock-frequency property
    CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
    Setting up static identity map for 0x80008280 - 0x800082f0
    Brought up 1 CPUs
    SMP: Total of 1 processors activated (6.00 BogoMIPS).
    CPU: All CPU(s) started in SVC mode.
    devtmpfs: initialized
    device-tree: Duplicate name in lcdif@021c8000, renamed to "display#1"
    VFP support v0.3: implementor 41 architecture 2 part 30 variant 7 rev 5
    clocksource jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
    pinctrl core: initialized pinctrl subsystem
    NET: Registered protocol family 16
    DMA: preallocated 256 KiB pool for atomic coherent allocations
    cpuidle: using governor ladder
    cpuidle: using governor menu
    hw-breakpoint: found 5 (+1 reserved) breakpoint and 4 watchpoint registers.
    hw-breakpoint: maximum watchpoint size is 8 bytes.
    imx6ul-pinctrl 20e0000.iomuxc: Invalid fsl,pins property in node /soc/aips-bus@02000000/iomuxc@020e0000/imx6ul-evk/flexcan2grp
    imx6ul-pinctrl 20e0000.iomuxc: Invalid fsl,pins property in node /soc/aips-bus@02000000/iomuxc@020e0000/imx6ul-evk/uart2dtegrp
    imx6ul-pinctrl 20e0000.iomuxc: initialized IMX pinctrl driver
    imx6ul-pinctrl 2290000.iomuxc-snvs: Invalid fsl,pins property in node /soc/aips-bus@02200000/iomuxc-snvs@02290000/imx6ul-evk/lcdifresetgrp
    imx6ul-pinctrl 2290000.iomuxc-snvs: initialized IMX pinctrl driver
    mxs-dma 1804000.dma-apbh: initialized
    SCSI subsystem initialized
    usbcore: registered new interface driver usbfs
    usbcore: registered new interface driver hub
    usbcore: registered new device driver usb
    i2c i2c-0: IMX I2C adapter registered
    i2c i2c-0: can't use DMA
    i2c i2c-1: IMX I2C adapter registered
    i2c i2c-1: can't use DMA
    Linux video capture interface: v2.00
    pps_core: LinuxPPS API ver. 1 registered
    pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
    PTP clock support registered
    Advanced Linux Sound Architecture Driver Initialized.
    Switched to clocksource mxc_timer1
    NET: Registered protocol family 2
    TCP established hash table entries: 4096 (order: 2, 16384 bytes)
    TCP bind hash table entries: 4096 (order: 3, 32768 bytes)
    TCP: Hash tables configured (established 4096 bind 4096)
    UDP hash table entries: 256 (order: 1, 8192 bytes)
    UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)
    NET: Registered protocol family 1
    RPC: Registered named UNIX socket transport module.
    RPC: Registered udp transport module.
    RPC: Registered tcp transport module.
    RPC: Registered tcp NFSv4.1 backchannel transport module.
    imx rpmsg driver is registered.
    Bus freq driver module loaded
    futex hash table entries: 256 (order: 2, 16384 bytes)
    VFS: Disk quotas dquot_6.6.0
    VFS: Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
    NFS: Registering the id_resolver key type
    Key type id_resolver registered
    Key type id_legacy registered
    jffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
    fuse init (API version 7.23)
    io scheduler noop registered
    io scheduler deadline registered
    io scheduler cfq registered (default)
    imx-weim 21b8000.weim: Driver registered.
    backlight supply power not found, using dummy regulator
    21c8000.lcdif supply lcd not found, using dummy regulator
    mxsfb 21c8000.lcdif: failed to find mxc display driver 
    Console: switching to colour frame buffer device 128x37
    mxsfb 21c8000.lcdif: initialized
    imx-sdma 20ec000.sdma: no event needs to be remapped
    imx-sdma 20ec000.sdma: loaded firmware 3.3
    imx-sdma 20ec000.sdma: initialized
    2020000.serial: ttymxc0 at MMIO 0x2020000 (irq = 19, base_baud = 5000000) is a IMX
    console [ttymxc0] enabled
    21ec000.serial: ttymxc2 at MMIO 0x21ec000 (irq = 233, base_baud = 5000000) is a IMX
    KGDB: Registered I/O driver kgdboc
    imx sema4 driver is registered.
    [drm] Initialized drm 1.1.0 20060810
    [drm] Initialized vivante 1.0.0 20120216 on minor 0
    brd: module loaded
    loop: module loaded
    fsl-quadspi 21e0000.qspi: unrecognized JEDEC id bytes: ff, ff, ff
    fsl-quadspi 21e0000.qspi: Freescale QuadSPI probe failed
    spi_imx 2010000.ecspi: probed
    CAN device driver interface
    flexcan 2090000.can: device registered (reg_base=a09e8000, irq=25)
    20b4000.ethernet supply phy not found, using dummy regulator
    pps pps0: new PPS source ptp0
    libphy: fec_enet_mii_bus: probed
    fec 20b4000.ethernet eth0: registered PHC device 0
    2188000.ethernet supply phy not found, using dummy regulator
    pps pps1: new PPS source ptp1
    fec 2188000.ethernet eth1: registered PHC device 1
    PPP generic driver version 2.4.2
    PPP BSD Compression module registered
    PPP Deflate Compression module registered
    PPP MPPE Compression module registered
    NET: Registered protocol family 24
    usbcore: registered new interface driver rtl8187
    usbcore: registered new interface driver rndis_wlan
    usbcore: registered new interface driver r8152
    usbcore: registered new interface driver asix
    usbcore: registered new interface driver ax88179_178a
    usbcore: registered new interface driver cdc_ether
    usbcore: registered new interface driver net1080
    usbcore: registered new interface driver rndis_host
    usbcore: registered new interface driver cdc_subset
    usbcore: registered new interface driver zaurus
    usbcore: registered new interface driver cdc_ncm
    GobiNet: Quectel_WCDMA&LTE_Linux&Android_GobiNet_Driver_V1.3.0
    usbcore: registered new interface driver GobiNet
    ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
    ehci-mxc: Freescale On-Chip EHCI Host driver
    ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
    usbcore: registered new interface driver cdc_acm
    cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
    usbcore: registered new interface driver usb-storage
    usbcore: registered new interface driver usbserial
    usbcore: registered new interface driver option
    usbserial: USB Serial support registered for GSM modem (1-port)
    2184800.usbmisc supply vbus-wakeup not found, using dummy regulator
    2184000.usb supply vbus not found, using dummy regulator
    ci_hdrc ci_hdrc.0: EHCI Host Controller
    ci_hdrc ci_hdrc.0: new USB bus registered, assigned bus number 1
    ci_hdrc ci_hdrc.0: USB 2.0 started, EHCI 1.00
    hub 1-0:1.0: USB hub found
    hub 1-0:1.0: 1 port detected
    2184200.usb supply vbus not found, using dummy regulator
    ci_hdrc ci_hdrc.1: EHCI Host Controller
    ci_hdrc ci_hdrc.1: new USB bus registered, assigned bus number 2
    ci_hdrc ci_hdrc.1: USB 2.0 started, EHCI 1.00
    hub 2-0:1.0: USB hub found
    hub 2-0:1.0: 1 port detected
    mousedev: PS/2 mouse device common for all mice
    input: 20cc000.snvs:snvs-powerkey as /devices/platform/soc/2000000.aips-bus/20cc000.snvs/20cc000.snvs:snvs-powerkey/input/input0
    usbcore: registered new interface driver xpad
    usb 2-1: new high-speed USB device number 2 using ci_hdrc
    input: EP0820M09 as /devices/platform/soc/2100000.aips-bus/21a4000.i2c/i2c-1/1-0038/input/input1
    snvs_rtc 20cc000.snvs:snvs-rtc-lp: rtc core: registered 20cc000.snvs:snvs-r as rtc0
    i2c /dev entries driver
    IR NEC protocol handler initialized
    IR RC5(x/sz) protocol handler initialized
    IR RC6 protocol handler initialized
    IR JVC protocol handler initialized
    IR Sony protocol handler initialized
    IR SANYO protocol handler initialized
    IR Sharp protocol handler initialized
    IR MCE Keyboard/mouse protocol handler initialized
    IR XMP protocol handler initialized
    pxp-v4l2 pxp_v4l2: initialized
    imx2-wdt 20bc000.wdog: use WDOG_B to reboot.
    imx2-wdt 20bc000.wdog: timeout 60 sec (nowayout=0)
    sdhci: Secure Digital Host Controller Interface driver
    sdhci: Copyright(c) Pierre Ossman
    sdhci-pltfm: SDHCI platform and OF driver helper
    /soc/aips-bus@02100000/usdhc@02190000: voltage-ranges unspecified
    sdhci-esdhc-imx 2190000.usdhc: Got CD GPIO
    sdhci-esdhc-imx 2190000.usdhc: No vqmmc regulator found
    hub 2-1:1.0: USB hub found
    hub 2-1:1.0: 4 ports detected
    mmc0: SDHCI controller on 2190000.usdhc [2190000.usdhc] using ADMA
    /soc/aips-bus@02100000/usdhc@02194000: voltage-ranges unspecified
    sdhci-esdhc-imx 2194000.usdhc: No vmmc regulator found
    sdhci-esdhc-imx 2194000.usdhc: No vqmmc regulator found
    mmc0: host does not support reading read-only switch, assuming write-enable
    mmc1: SDHCI controller on 2194000.usdhc [2194000.usdhc] using ADMA
    usbcore: registered new interface driver usbhid
    usbhid: USB HID core driver
    mmc0: new high speed SDHC card at address aaaa
    mmcblk0: mmc0:aaaa SC16G 14.8 GiB 
     mmcblk0: p1
    fsl-asrc 2034000.asrc: driver registered
    imx-wm8960 sound: wm8960-hifi <-> 202c000.sai mapping ok
    imx-wm8960 sound: snd-soc-dummy-dai <-> 2034000.asrc mapping ok
    imx-wm8960 sound: wm8960-hifi <-> 202c000.sai mapping ok
    mmc1: MAN_BKOPS_EN bit is not set
    NET: Registered protocol family 10
    mmc1: new HS200 MMC card at address 0001
    mmcblk1: mmc1:0001 8GTF4R 7.28 GiB 
    sit: IPv6 over IPv4 tunneling driver
    NET: Registered protocol family 17
    can: controller area network core (rev 20120528 abi 9)
    mmcblk1boot0: mmc1:0001 8GTF4R partition 1 4.00 MiB
    mmcblk1boot1: mmc1:0001 8GTF4R partition 2 4.00 MiB
    mmcblk1rpmb: mmc1:0001 8GTF4R partition 3 512 KiB
    NET: Registered protocol family 29
    can: raw protocol (rev 20120528)
     mmcblk1: p1 p2
    can: broadcast manager protocol (rev 20120528 t)
    can: netlink gateway (rev 20130117) max_hops=1
    lib80211: common routines for IEEE802.11 drivers
    Key type dns_resolver registered
    Registering SWP/SWPB emulation handler
    input: gpio-keys as /devices/platform/gpio-keys/input/input2
    snvs_rtc 20cc000.snvs:snvs-rtc-lp: setting system clock to 1970-01-01 03:19:28 UTC (11968)
    fec 20b4000.ethernet eth0: Freescale FEC PHY driver [SMSC LAN8710/LAN8720] (mii_bus:phy_addr=20b4000.ethernet:01, irq=-1)
    IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
    fec 20b4000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
    IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
    IP-Config: Complete:
         device=eth0, hwaddr=b8:ae:1d:01:00:00, ipaddr=192.168.6.200, mask=255.255.255.0, gw=192.168.6.2
         host=192.168.6.200, domain=, nis-domain=(none)
         bootserver=192.168.6.129, rootserver=192.168.6.129, rootpath=
    gpio_dvfs: disabling
    can-3v3: disabling
    ALSA device list:
      #0: wm8960-audio
    VFS: Mounted root (nfs4 filesystem) on device 0:15.
    devtmpfs: mounted
    Freeing unused kernel memory: 404K (809a5000 - 80a0a000)
    ALSA: Restoring mixer setting......
    
    Please press Enter to activate this console. random: nonblocking pool is initialized
    /var/empty must be owned by root and not group or world-writable.
    
    / # 
    / # ls
    bin           home          mnt           share         video
    dev           include       music         sys           中文测试
    drivers       lib           proc          tmp
    etc           linuxrc       root          usr
    gdbtest       minicom.log   sbin          var
    / # 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311

    5、安装 chrdevbase.ko 驱动

    / # ls
    bin            gdbtest        minicom.log    sbin           var
    chrdevbase.ko  home           mnt            share          video
    dev            include        music          sys            中文测试
    drivers        lib            proc           tmp
    etc            linuxrc        root           usr
    / # insmod chrdevbase.ko 
    chrdevbase init!
    / #
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    6、获取 chrdevbase.ko 驱动相关信息

    / # cat /sys/module/chrdevbase/sections/.text 
    0x7f000000
    / #
    
    • 1
    • 2
    • 3

    注意:直接使用chrdevbase.ko文件调试,发现无法设置断点,可能是nokaslr的问题(问题未进行确认)。

    7、触发 KGDB

    echo g > /proc/sysrq-trigger
    
    • 1
    / # echo g > /proc/sysrq-trigger
    sysrq: SysRq : DEBUG
    KGDB: Entering KGDB
    
    • 1
    • 2
    • 3

    8、启动 GDB

    arm-linux-gnueabihf-gdb
    
    • 1
    add-symbol-file chrdevbase.ko 0x7f000000
    
    • 1
    onlylove@ubuntu:~/my/nfs$ ls
    bin            dev      etc      home     lib      minicom.log  music  root  share  tmp  var    中文测试
    chrdevbase.ko  drivers  gdbtest  include  linuxrc  mnt          proc   sbin  sys    usr  video
    onlylove@ubuntu:~/my/nfs$ arm-linux-gnueabihf-gdb
    GNU gdb (Linaro_GDB-2017.01) 7.10.1.20160210-cvs
    Copyright (C) 2015 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-unknown-linux-gnu --target=arm-linux-gnueabihf".
    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".
    (gdb) add-symbol-file chrdevbase.ko 0x7f000000
    add symbol table from file "chrdevbase.ko" at
    	.text_addr = 0x7f000000
    (y or n) y
    Reading symbols from chrdevbase.ko...done.
    (gdb)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    9、开启调试终端

    tar rem localhost:5551
    
    • 1
    onlylove@ubuntu:~/my/nfs$ ls
    bin            dev      etc      home     lib      minicom.log  music  root  share  tmp  var    中文测试
    chrdevbase.ko  drivers  gdbtest  include  linuxrc  mnt          proc   sbin  sys    usr  video
    onlylove@ubuntu:~/my/nfs$ arm-linux-gnueabihf-gdb
    GNU gdb (Linaro_GDB-2017.01) 7.10.1.20160210-cvs
    Copyright (C) 2015 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-unknown-linux-gnu --target=arm-linux-gnueabihf".
    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".
    (gdb) add-symbol-file chrdevbase.ko 0x7f000000
    add symbol table from file "chrdevbase.ko" at
    	.text_addr = 0x7f000000
    (y or n) y
    Reading symbols from chrdevbase.ko...done.
    (gdb) 
    (gdb) tar rem localhost:5551
    Remote debugging using localhost:5551
    0x8009d45c in ?? ()
    (gdb) list
    1	#include 
    2	#include 
    3	#include 
    4	#include 
    5	#include 
    6	#include 
    7	/***************************************************************
    8	Copyright © ALIENTEK Co., Ltd. 1998-2029. All rights reserved.
    9	文件名		: chrdevbase.c
    10	作者	  	: 左忠凯
    (gdb)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39

    七、总结

    通过以上配置,成功搭建 Linux 驱动调试框架。

  • 相关阅读:
    课程:如何高效掌控你的时间
    Spring Boot 3的AOT(GraalVM Native Image)应用开发
    [深入研究4G/5G/6G专题-57]: L3信令控制-6-什么是无线承载DRB Profile
    守护绿色屏障:智能高压森林应急消防泵|恒峰智慧科技
    极简实用PyTorch记录——如何读取图片、改变大小、转化为numpy数组、转化为tensor
    【杂记-浅谈交换机的二层转发和三层转发】
    阿里云OSS前端直传+net core后端签名
    掉电安全文件系统littlefs移植
    前端判断版本号区分接口请求的baseURL
    Python中的——random模块
  • 原文地址:https://blog.csdn.net/OnlyLove_/article/details/126805193