ambarella H2 kernel调试记录

更改kernel config配置,如下:

# make menuconfig_public_linux 
     Kernel hacking  --->  
         [*] Kernel debugging
         Compile-time checks and compiler options  --->
            [*] Compile the kernel with debug info                                  

然后执行 make -j8 编译SDK时可能会报如下错误:

 Build EXT4...
genext2fs: couldn't allocate a block (no free space)

rootfs的空间设置的不够大,需要增加rootfs的大小。

解决办法:

# make menuconfig
 [*] Ambarella File System Configuration  ---> 
     EXT4 File System Configuration  ---> 
       (262144) Ambarella RootFS Size(KB) 

如上所示, 把rootfs大小改为262144KB(256MB)。如果在更改 Ambarella RootFS Size 时发现使用Backspace键不能删除原先的数字,参考:MobaXterm 执行make menuconfig不能删除字符

然后继续 make -j8 编译,编译通过后,使用以下命令查看kernel中是否带有debug信息:

# aarch64-linux-gnu-objdump -h /path_to_vmlinux/vmlinux     //path_to_vmlinx为vmlinux所在的路径 

如果kernel中已经包含了debug信息,应该有如下显示:

18 .data         0005e188  ffffffc0006ef000  ffffffc0006ef000  0067f000  2**12
                  CONTENTS, ALLOC, LOAD, DATA
 19 .bss          00038544  ffffffc00074e000  ffffffc00074e000  006dd188  2**12
                  ALLOC
 20 .comment      0000002d  0000000000000000  0000000000000000  006dd188  2**0
                  CONTENTS, READONLY
 21 .debug_line   00563b60  0000000000000000  0000000000000000  006dd1b5  2**0
                  CONTENTS, READONLY, DEBUGGING
 22 .debug_info   04944153  0000000000000000  0000000000000000  00c40d15  2**0
                  CONTENTS, READONLY, DEBUGGING
 23 .debug_abbrev 00256d9e  0000000000000000  0000000000000000  05584e68  2**0
                  CONTENTS, READONLY, DEBUGGING
 24 .debug_aranges 00014600  0000000000000000  0000000000000000  057dbc10  2**4
                  CONTENTS, READONLY, DEBUGGING
 25 .debug_ranges 00296d30  0000000000000000  0000000000000000  057f0210  2**4
                  CONTENTS, READONLY, DEBUGGING
 26 .debug_frame  0014a808  0000000000000000  0000000000000000  05a86f40  2**3
                  CONTENTS, READONLY, DEBUGGING
 27 .debug_str    0015858f  0000000000000000  0000000000000000  05bd1748  2**0
                  CONTENTS, READONLY, DEBUGGING
 28 .debug_loc    0059046a  0000000000000000  0000000000000000  05d29cd7  2**0

重点在于21~28所示的debug相关信息。

根据内核报错时的Call Trace信息,使用gdb调试crash出现在什么地方(具体到某个函数的某一行),比如说Call Trace信息显示skip_free_areas_node+0xec/0x2fc,意思是skip_free_areas_node函数有0x2fc这么大,Oops发生在这个函数的0xec偏移处:

使用 aarch64-linux-gnu-gdb vmlinux 调试内核,输入 list *(skip_free_areas_node+0xec) ,如下所示,显示错误发生在 ambarella/kernel/linux-4.4/mm/page_alloc.c 的 3708行处。

# aarch64-linux-gnu-gdb  /path_to_vmlinux/vmlinux 
...
Type "apropos word" to search for commands related to "word"...
Reading symbols from  /path_to_vmlinux/vmlinux...done.
(gdb) list *(skip_free_areas_node+0xec)
0xffffffc00011c75c is in show_free_areas (/h2_sdk/ambarella/kernel/linux-4.4/mm/page_alloc.c:3708).
3703    {
3704            unsigned long free_pcp = 0;
3705            int cpu;
3706            struct zone *zone;
3707
3708            for_each_populated_zone(zone) {
3709                    if (skip_free_areas_node(filter, zone_to_nid(zone)))
3710                            continue;
3711
3712                    for_each_online_cpu(cpu)
(gdb) 

如果在执行 aarch64-linux-gnu-gdb vmlinux 时出现如下错误:

aarch64-linux-gnu-gdb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

解决办法见: 

  https://www.cnblogs.com/wanglouxiaozi/p/14987053.html

posted @ 2021-07-08 18:18  闹闹爸爸  阅读(243)  评论(0编辑  收藏  举报