繁体   English   中英

使用 Yocto SDK 调试 Linux Kernel

[英]Debugging Linux Kernel with Yocto SDK

I'm trying to use KGDB to debug the Linux kernel from the generated SDK of my arm Yocto image. 为此,我首先确保将 KGDB 编译为内置模块:

CONFIG_KGDB=y CONFIG_KGDB_SERIAL_CONSOLE=y

此外,在我的 image.bb 中,我安装了 kernel 源:

`TOOLCHAIN_TARGET_TASK += "kernel-devsrc"`

最后,我通过在 Kernel 引导命令中添加kgdboc=ttySTM0,115200 kgdbwait在引导时启动 KGDB。 这会停止引导过程,直到 KGDB 连接到主机端的 GDB。 然后,通过从 Yocto-SDK 启动 arm-ostl-linux-gnueabi-gdb 并设置set serial baud 115200target remote /dev/ttyUSB1 ,我可以恢复和调试剩余的引导例程。

KGDB<->GDB 在启动时通过串行连接工作得很好。 However, my current problem is that not all sources of the Kernel are installed in the SDK, which makes GDB complain with /usr/src/kernel/*/*/*.c: No such file or directory. ,使调试几乎毫无用处。

因此,我通过将cp --parents $(find -type f -name "*.c") $kerneldir/build添加到 openembedded-core/meta/recipes-kernel 的 do_install() function 来强制安装 all.c 源/linux/kernel-devsrc.bb,使用上面提到的TOOLCHAIN_TARGET_TASK += "kernel-devsrc"

This effectively adds all resulting Kernel.c files to the SDK after adding my patches to the kernel sources but it also adds lots of.c that are not even required for my architecture (arm), making the SDK unnecessarily large.

所以,我的问题是:

  • 有没有更好的方法来用 Yocto 做到这一点?
  • 如果没有,我怎样才能只过滤需要的。c 添加到 SDK 中?

提前致谢!

过滤掉不需要的源的一种方法是通过使用以下脚本在元层中创建 kernel-devsrc.bbappend 来扩展开放嵌入式 kernel-devsrc.bb:

do_install_append(){
    bbplain "--------------Including Kernel Sources------------------"
    cd ${S}
    # Find binary files (*.o) as a hint to find relevant sources
    for f in `find ${B} -type f -name "*.o"`; do
        # Extract file name
        file="${f##*/}"
        # Extract only path
        path=${f%/*}
        # Remove global part of the path
        path="${path##@(${B})}"
        # Remove object extension
        file=${file%.o}
        # Copy relevant sources to the SDK
        cp --parents $(find .$path -maxdepth 1 -type f -name ${file}.c -o -name ${file}.S) $kerneldir/build 2>/dev/null || :
    done
}

通过这种方法,我们首先在二进制文件夹中查找已编译的 object 文件,因为这些文件为我们提供了当前 defconfig 正在使用哪些 kernel 组件的信息。 有了这些信息,我们可以找到相应的 kernel.c 和.S 源并将它们安装在 SDK 中。 这避免了复制所有源,在我的情况下,这将 src 文件夹从 ~610MB 减少到 18MB。

已知限制:

有一些 object 文件(在我的情况下为 5)没有同名的相应源,即 .tmp_vmlinux.kallsyms2.o、dtc-parser.tab.o、dtc-lexer.lex.o、.tmp_vmlinux.kallsyms1。 o 和 vmlinux.o。 我们可以使脚本更复杂以捕获那些极端情况,或者使用2>/dev/null ||:忽略它们,如图所示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM