Debugging linux kernel on IMX6ULL using JTAG

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Debugging linux kernel on IMX6ULL using JTAG

1,112 Views
Almaz
Contributor I

Hello.
Continuation of this thread. Finally got U-boot debuggable using JTAG. Here and here explained how I did it. Now I am trying to get Linux Kernel debuggable too.

Steps passed to achieve that:

1. Started GDB server:

 

 

$ JLinkGDBServer -device MCIMX6Y2 -if JTAG -speed 1000

 

 

it outputs following:

 

 

SEGGER J-Link GDB Server V7.54a Command Line Version

JLinkARM.dll V7.54a (DLL compiled Sep  7 2021 14:25:38)

Command line: -device MCIMX6Y2 -if JTAG -speed 1000
-----GDB Server start settings-----
GDBInit file:                  none
GDB Server Listening port:     2331
SWO raw output listening port: 2332
Terminal I/O port:             2333
Accept remote connection:      yes
Generate logfile:              off
Verify download:               off
Init regs on start:            off
Silent mode:                   off
Single run mode:               off
Target connection timeout:     0 ms
------J-Link related settings------
J-Link Host interface:         USB
J-Link script:                 none
J-Link settings file:          none
------Target related settings------
Target device:                 MCIMX6Y2
Target interface:              JTAG
Target interface speed:        1000kHz
Target endian:                 little

Connecting to J-Link...
J-Link is connected.
Firmware: J-Link ARM V8 compiled Nov 28 2014 13:44:46
Hardware: V8.00
Feature(s): RDI,FlashDL,FlashBP,JFlash,GDB
Checking target voltage...
Target voltage: 3.31 V
Listening on TCP/IP port 2331
Connecting to target...

J-Link found 3 JTAG devices, Total IRLen = 13
JTAG ID: 0x5BA00477 (Cortex-A7)
Connected to target
Waiting for GDB connection...

 

 


2. Started debugging session:

 

 

$ gdb-multiarch vmlinux --nx
(gdb) target remote localhost:2331
Remote debugging using localhost:2331
0x8ff5cfc4 in ?? ()
(gdb) monitor reset
Resetting target
(gdb) monitor halt
(gdb) monitor sleep 200
Sleep 200ms
(gdb) load
Loading section .text, size 0x61c0 lma 0x0
Loading section .rodata, size 0x224 lma 0x61c0
Loading section .piggydata, size 0x278ffc lma 0x63e4
Loading section .got.plt, size 0xc lma 0x27f3e0
Loading section .got, size 0x2c lma 0x27f3ec
Loading section .pad, size 0x8 lma 0x27f418
Start address 0x00000000, load size 2618400
Transfer rate: 70 KB/sec, 15679 bytes/write.

 

 

 While entering this commands GDB server outputs following:

 

 

Connected to 127.0.0.1
Reading all registers
Read 4 bytes @ address 0x8FF5CFC4 (Data = 0xE3130020)
Read 4 bytes @ address 0x8FF5CFC0 (Data = 0xE59230B4)
Read 4 bytes @ address 0x8FF5CFC4 (Data = 0xE3130020)
Read 4 bytes @ address 0x8FF5CFC0 (Data = 0xE59230B4)
Read 2 bytes @ address 0x8FF5CFC4 (Data = 0x0020)
Read 2 bytes @ address 0x8FF5CFC2 (Data = 0xE592)
Read 2 bytes @ address 0x8FF5CFC0 (Data = 0x30B4)
Read 2 bytes @ address 0x8FF5CFC4 (Data = 0x0020)
Read 2 bytes @ address 0x8FF5CFC2 (Data = 0xE592)
Read 2 bytes @ address 0x8FF5CFC0 (Data = 0x30B4)
Read 4 bytes @ address 0x8FF5CFC4 (Data = 0xE3130020)
Read 4 bytes @ address 0x8FF5CFC0 (Data = 0xE59230B4)
Read 4 bytes @ address 0x8FF5CFC4 (Data = 0xE3130020)
Read 4 bytes @ address 0x8FF5CFC0 (Data = 0xE59230B4)
Read 4 bytes @ address 0x8FF5CFC4 (Data = 0xE3130020)
Read 4 bytes @ address 0x8FF5CFC4 (Data = 0xE3130020)
Read 4 bytes @ address 0x8FF5CFC4 (Data = 0xE3130020)
Received monitor command: reset
Resetting target
Received monitor command: halt
Halting target CPU...
...Target halted (PC = 0x8FF5CFC4)
Received monitor command: sleep 200
Sleep 200ms
Downloading 16256 bytes @ address 0x00000000
Downloading 8768 bytes @ address 0x00003F80
Downloading 548 bytes @ address 0x000061C0
Downloading 16140 bytes @ address 0x000063E4
Downloading 16080 bytes @ address 0x0000A2F0
Downloading 16112 bytes @ address 0x0000E1C0
Downloading 16112 bytes @ address 0x000120B0
Downloading 16080 bytes @ address 0x00015FA0
Downloading 16112 bytes @ address 0x00019E70
Downloading 16112 bytes @ address 0x0001DD60
Downloading 16080 bytes @ address 0x00021C50
Downloading 16128 bytes @ address 0x00025B20
Downloading 16112 bytes @ address 0x00029A20
Downloading 16112 bytes @ address 0x0002D910
Downloading 16112 bytes @ address 0x00031800
Downloading 16128 bytes @ address 0x000356F0
Downloading 16112 bytes @ address 0x000395F0
Downloading 16112 bytes @ address 0x0003D4E0
Downloading 16112 bytes @ address 0x000413D0
Downloading 16128 bytes @ address 0x000452C0
Downloading 16096 bytes @ address 0x000491C0
Downloading 16096 bytes @ address 0x0004D0A0
Downloading 16096 bytes @ address 0x00050F80
Downloading 16080 bytes @ address 0x00054E60
Downloading 16096 bytes @ address 0x00058D30
Downloading 16080 bytes @ address 0x0005CC10
Downloading 16096 bytes @ address 0x00060AE0
Downloading 16128 bytes @ address 0x000649C0
Downloading 16096 bytes @ address 0x000688C0
Downloading 16128 bytes @ address 0x0006C7A0
Downloading 16096 bytes @ address 0x000706A0
Downloading 16128 bytes @ address 0x00074580
Downloading 16112 bytes @ address 0x00078480
Downloading 16096 bytes @ address 0x0007C370
Downloading 16112 bytes @ address 0x00080250
Downloading 16096 bytes @ address 0x00084140
Downloading 16096 bytes @ address 0x00088020
Downloading 16112 bytes @ address 0x0008BF00
Downloading 16080 bytes @ address 0x0008FDF0
Downloading 16128 bytes @ address 0x00093CC0
Downloading 16112 bytes @ address 0x00097BC0
Downloading 16096 bytes @ address 0x0009BAB0
Downloading 16096 bytes @ address 0x0009F990
Downloading 16128 bytes @ address 0x000A3870
Downloading 16080 bytes @ address 0x000A7770
Downloading 16080 bytes @ address 0x000AB640
Downloading 16080 bytes @ address 0x000AF510
Downloading 16112 bytes @ address 0x000B33E0
Downloading 16112 bytes @ address 0x000B72D0
Downloading 16096 bytes @ address 0x000BB1C0
Downloading 16112 bytes @ address 0x000BF0A0
Downloading 16128 bytes @ address 0x000C2F90
Downloading 16128 bytes @ address 0x000C6E90
Downloading 16128 bytes @ address 0x000CAD90
Downloading 16096 bytes @ address 0x000CEC90
Downloading 16128 bytes @ address 0x000D2B70
Downloading 16112 bytes @ address 0x000D6A70
Downloading 16128 bytes @ address 0x000DA960
Downloading 16128 bytes @ address 0x000DE860
Downloading 16096 bytes @ address 0x000E2760
Downloading 16112 bytes @ address 0x000E6640
Downloading 16112 bytes @ address 0x000EA530
Downloading 16064 bytes @ address 0x000EE420
Downloading 16096 bytes @ address 0x000F22E0
Downloading 16112 bytes @ address 0x000F61C0
Downloading 16144 bytes @ address 0x000FA0B0
Downloading 16096 bytes @ address 0x000FDFC0
Downloading 16080 bytes @ address 0x00101EA0
Downloading 16096 bytes @ address 0x00105D70
Downloading 16112 bytes @ address 0x00109C50
Downloading 16144 bytes @ address 0x0010DB40
Downloading 16096 bytes @ address 0x00111A50
Downloading 16096 bytes @ address 0x00115930
Downloading 16112 bytes @ address 0x00119810
Downloading 16112 bytes @ address 0x0011D700
Downloading 16112 bytes @ address 0x001215F0
Downloading 16096 bytes @ address 0x001254E0
Downloading 16080 bytes @ address 0x001293C0
Downloading 16096 bytes @ address 0x0012D290
Downloading 16112 bytes @ address 0x00131170
Downloading 16112 bytes @ address 0x00135060
Downloading 16080 bytes @ address 0x00138F50
Downloading 16112 bytes @ address 0x0013CE20
Downloading 16112 bytes @ address 0x00140D10
Downloading 16096 bytes @ address 0x00144C00
Downloading 16112 bytes @ address 0x00148AE0
Downloading 16144 bytes @ address 0x0014C9D0
Downloading 16144 bytes @ address 0x001508E0
Downloading 16112 bytes @ address 0x001547F0
Downloading 16096 bytes @ address 0x001586E0
Downloading 16128 bytes @ address 0x0015C5C0
Downloading 16112 bytes @ address 0x001604C0
Downloading 16112 bytes @ address 0x001643B0
Downloading 16112 bytes @ address 0x001682A0
Downloading 16096 bytes @ address 0x0016C190
Downloading 16128 bytes @ address 0x00170070
Downloading 16096 bytes @ address 0x00173F70
Downloading 16096 bytes @ address 0x00177E50
Downloading 16112 bytes @ address 0x0017BD30
Downloading 16096 bytes @ address 0x0017FC20
Downloading 16096 bytes @ address 0x00183B00
Downloading 16112 bytes @ address 0x001879E0
Downloading 16080 bytes @ address 0x0018B8D0
Downloading 16112 bytes @ address 0x0018F7A0
Downloading 16096 bytes @ address 0x00193690
Downloading 16112 bytes @ address 0x00197570
Downloading 16112 bytes @ address 0x0019B460
Downloading 16112 bytes @ address 0x0019F350
Downloading 16128 bytes @ address 0x001A3240
Downloading 16096 bytes @ address 0x001A7140
Downloading 16112 bytes @ address 0x001AB020
Downloading 16096 bytes @ address 0x001AEF10
Downloading 16144 bytes @ address 0x001B2DF0
Downloading 16112 bytes @ address 0x001B6D00
Downloading 16096 bytes @ address 0x001BABF0
Downloading 16096 bytes @ address 0x001BEAD0
Downloading 16096 bytes @ address 0x001C29B0
Downloading 16096 bytes @ address 0x001C6890
Downloading 16096 bytes @ address 0x001CA770
Downloading 16096 bytes @ address 0x001CE650
Downloading 16112 bytes @ address 0x001D2530
Downloading 16112 bytes @ address 0x001D6420
Downloading 16112 bytes @ address 0x001DA310
Downloading 16144 bytes @ address 0x001DE200
Downloading 16096 bytes @ address 0x001E2110
Downloading 16128 bytes @ address 0x001E5FF0
Downloading 16112 bytes @ address 0x001E9EF0
Downloading 16096 bytes @ address 0x001EDDE0
Downloading 16096 bytes @ address 0x001F1CC0
Downloading 16080 bytes @ address 0x001F5BA0
Downloading 16128 bytes @ address 0x001F9A70
Downloading 16096 bytes @ address 0x001FD970
Downloading 16096 bytes @ address 0x00201850
Downloading 16128 bytes @ address 0x00205730
Downloading 16128 bytes @ address 0x00209630
Downloading 16096 bytes @ address 0x0020D530
Downloading 16144 bytes @ address 0x00211410
Downloading 16112 bytes @ address 0x00215320
Downloading 16112 bytes @ address 0x00219210
Downloading 16144 bytes @ address 0x0021D100
Downloading 16096 bytes @ address 0x00221010
Downloading 16096 bytes @ address 0x00224EF0
Downloading 16080 bytes @ address 0x00228DD0
Downloading 16096 bytes @ address 0x0022CCA0
Downloading 16048 bytes @ address 0x00230B80
Downloading 16112 bytes @ address 0x00234A30
Downloading 16112 bytes @ address 0x00238920
Downloading 16112 bytes @ address 0x0023C810
Downloading 16128 bytes @ address 0x00240700
Downloading 16096 bytes @ address 0x00244600
Downloading 16096 bytes @ address 0x002484E0
Downloading 16112 bytes @ address 0x0024C3C0
Downloading 16096 bytes @ address 0x002502B0
Downloading 16112 bytes @ address 0x00254190
Downloading 16128 bytes @ address 0x00258080
Downloading 16112 bytes @ address 0x0025BF80
Downloading 16080 bytes @ address 0x0025FE70
Downloading 16112 bytes @ address 0x00263D40
Downloading 16128 bytes @ address 0x00267C30
Downloading 16096 bytes @ address 0x0026BB30
Downloading 16112 bytes @ address 0x0026FA10
Downloading 16096 bytes @ address 0x00273900
Downloading 16112 bytes @ address 0x002777E0
Downloading 15632 bytes @ address 0x0027B6D0
Downloading 12 bytes @ address 0x0027F3E0
Downloading 44 bytes @ address 0x0027F3EC
Downloading 8 bytes @ address 0x0027F418
Writing register (PC = 0x       0)
Read 4 bytes @ address 0x00000000 (Data = 0xE1A00000)
Read 4 bytes @ address 0xFFFFFFFC (Data = 0xFF700C12)
Read 4 bytes @ address 0x00000000 (Data = 0xE1A00000)
Read 4 bytes @ address 0xFFFFFFFC (Data = 0xFFB00C12)
Read 2 bytes @ address 0x00000000 (Data = 0x0000)
Read 2 bytes @ address 0xFFFFFFFE (Data = 0x0070)
Read 2 bytes @ address 0xFFFFFFFC (Data = 0x0012)
Read 2 bytes @ address 0x00000000 (Data = 0x0000)
Read 2 bytes @ address 0xFFFFFFFE (Data = 0x0070)

 

 


3. Trying to debug:
Typing in debugger console:

 

 

(gdb) s
Cannot access memory at address 0x0

 

 

 GDB server outputs following:

 

 

Read 4 bytes @ address 0x00000000 (Data = 0xE1A00000)
Read 4 bytes @ address 0xFFFFFFFC (Data = 0xFF700C12)
Read 4 bytes @ address 0x00000000 (Data = 0xE1A00000)
Read 4 bytes @ address 0xFFFFFFFC (Data = 0xFFB00C12)
Read 2 bytes @ address 0x00000000 (Data = 0x0000)
Read 2 bytes @ address 0xFFFFFFFE (Data = 0x0070)
Read 2 bytes @ address 0xFFFFFFFC (Data = 0x0012)
Read 2 bytes @ address 0x00000000 (Data = 0x0000)
Read 2 bytes @ address 0xFFFFFFFE (Data = 0x0070)
Read 2 bytes @ address 0xFFFFFFFC (Data = 0x0012)
Read 4 bytes @ address 0x00000000 (Data = 0xE1A00000)
WARNING: Failed to read memory @ address 0xFFFFFFFC
WARNING: Failed to read memory @ address 0x00000000
WARNING: Failed to read memory @ address 0xFFFFFFFC
WARNING: Failed to read memory @ address 0x00000000
WARNING: Failed to read memory @ address 0x00000000
WARNING: Failed to read memory @ address 0x00000000
WARNING: Failed to read memory @ address 0x00000000

 

 

 

Linux kernel (vmlinux) file compiled using

 

 

CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_KERNEL=y

 

 

 

So probably something obvious missed. Probably access memory address is differs from 0x00? Should I provide it somehow or use another file to load in memory?

Here what I see on Linux kernel normal booting (without using debugger):

 

## Booting kernel from Legacy Image at 82000000 ...
   Image Name:   ARM OpenWrt Linux-4.14.199
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    2626009 Bytes = 2.5 MiB
   Load Address: 80008000
   Entry Point:  80008000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK

 

Labels (2)
0 Kudos
2 Replies

1,094 Views
igorpadykov
NXP Employee
NXP Employee

Hi Almaz

 

explanation of gdb error "Cannot access memory at addres" can be found on web, for example

https://stackoverflow.com/questions/30139356/gdb-cant-access-memory-address-error

Also for gdb may be useful AN4553 Using Open Source Debugging Tools for Linux on i.MX Processors

 

Best regards
igor

0 Kudos

1,066 Views
Almaz
Contributor I

Seems I used wrong vmlinux file.
Now I am facing following:

(gdb) target remote localhost:2331
Remote debugging using localhost:2331
0x8ff5cfc4 in ?? ()
(gdb) monitor reset
Resetting target
(gdb) monitor halt
(gdb) monitor sleep 200
Sleep 200ms
(gdb) load
Loading section .head.text, size 0x26c lma 0x80008000
Loading section .text, size 0x58fda0 lma 0x80100000
Loading section .rodata, size 0x14efe8 lma 0x80690000
Loading section .pci_fixup, size 0x1b50 lma 0x807defe8
Loading section __ksymtab, size 0x7ed0 lma 0x807e0b38
Loading section __ksymtab_gpl, size 0x6ba0 lma 0x807e8a08
Loading section __ksymtab_strings, size 0x2395e lma 0x807ef5a8
Loading section __param, size 0xa78 lma 0x80812f08
Loading section __ex_table, size 0x820 lma 0x80814000
Loading section .notes, size 0x24 lma 0x80814820
Loading section .vectors, size 0x20 lma 0x80900000
Loading section .stubs, size 0x2ac lma 0x80900020
Loading section .init.text, size 0x377e8 lma 0x809002e0
Loading section .exit.text, size 0x4c lma 0x80937ac8
Loading section .init.proc.info, size 0x2a4 lma 0x80937b14
Loading section .init.arch.info, size 0x208 lma 0x80937db8
Loading section .init.tagtable, size 0x38 lma 0x80937fc0
Loading section .init.smpalt, size 0x5b18 lma 0x80937ff8
Loading section .init.pv_table, size 0x1c4 lma 0x8093db10
Loading section .init.data, size 0xd26c lma 0x8093e000
Loading section .data..percpu, size 0x6b4c lma 0x8094c000
Loading section .data, size 0x375e0 lma 0x80a00000
Start address 0x80008000, load size 7983654
--Type <RET> for more, q to quit, c to continue without paging--
Transfer rate: 69 KB/sec, 15777 bytes/write.
(gdb) s
__hyp_stub_install () at arch/arm/kernel/hyp-stub.S:89
89		store_primary_cpu_mode	r4, r5, r6
(gdb) b __enable_mmu
Breakpoint 1 at 0x8010178c: file arch/arm/kernel/head.S, line 453.
(gdb) s
s__hyp_stub_install_secondary () at arch/arm/kernel/hyp-stub.S:96
96		mrs	r4, cpsr
(gdb) s
97		and	r4, r4, #MODE_MASK
(gdb) b __enable_mmu
Breakpoint 1 at 0x8010178c: file arch/arm/kernel/head.S, line 453.
(gdb) c
Continuing.

Breakpoint 1, __enable_mmu () at arch/arm/kernel/head.S:453
453		bic	r0, r0, #CR_A
(gdb) s
467		mov	r5, #DACR_INIT
(gdb) s
468		mcr	p15, 0, r5, c3, c0, 0		@ load domain access register
(gdb) s
469		mcr	p15, 0, r4, c2, c0, 0		@ load page table pointer
(gdb) s

execution stucks on last step. Trying to understand what is wrong with table pointer and where/how should I get it?

0 Kudos