高效阅读嵌入式源码系列二:understand阅读linux、uboot等源码

系列文章目录

高效阅读嵌入式源码系列一:静态分析神器understand软件基本操作
高效阅读嵌入式源码系列二:understand阅读linux、uboot等源码
高效阅读嵌入式源码系列三:understand阅读经keil MDK编译的源码



前言

当使用understand分析linux、uboot这类大型工程时,会因为无关源文件太多导致静态分析时卡死。故,如何精准地导入linux、uboot源码到understand,是值得探索的。


一、Generate_Kernel_Uboot_Project_forIDE是什么?

如何精准地获取源码文件,主要使用tonyho大神的Generate_Kernel_Uboot_Project_forIDE工具。该工具可从以下获取。
github原版
下不动的可从码云下:
码云镜像

在github中tonyho介绍到:
Purpose The linux kernel and u-boot contains lots of files, when we want to broswe the source code, we just want to see the compiled files, and the header files which required. This script will make a filelist to tell us the source files compiled and the header files required. Also, the script would genenate a filelist for the source code broswer IDE/Editor(for now, support Source Insight, Scitools Understand and SlickEdit)。
大意是,linux内核和u-boot中包含了大量的文件,当我们想要浏览源代码时,我们只想看到编译的文件,以及所需的头文件。这个脚本将生成一个文件列表,告诉我们已编译的源文件和所需的头文件。
此外,该脚本将为源代码浏览器IDE/编辑器生成一个文件列表(目前支持source Insight、Scitools Understand和SlickEdit)。

接下来在tonyho大神写的文档基础上,介绍下如何使用这款工具,以及在understand中如何利用生成的FileList_understand.txt。

二、使用步骤

1. 编译源码

如何编译linux内核源码或uboot源码,不是这篇文章的重点,各位可自行查找资料编译好需要分析的源码。

2. 根据编译结果生成对应的依赖文件

进入工具Generate_Kernel_Uboot_Project_forIDE文件夹

cd Generate_kernel_uboot_project_forIDE

按以下格式运行generate命令

./PF_Prj_Gen.sh Path_For_Compiled_Kernel(Uboot)_Directory OutPutProjectFileName

即:

./PF_Prj_Gen.sh 源码路径 输出文件夹

注意,运行PF_Prj_Gen.sh前须给文件赋予权限

chmod 777 PF_Prj_Gen.sh

本示例以linux源码为例,示例中linux源码是在workspace下,Generate_Kernel_Uboot_Project_forIDE-master是在tools下。具体示例与命令如下:
在这里插入图片描述示例中,出现的cannot move ‘sample.vpj’ to …之类的错误,可以忽略,原因是tonyho大神已说了这是针对slickedit软件的:Add slickedit project generation support。
打开FileList_understand.txt可看见linux源码中所必须的文件了,如下:
在这里插入图片描述

3. 对生成的FileList_understand.txt进行处理

一般,是在虚拟机中的linux环境中编译源码与生成FileList_understand.txt文件的,故txt文件中的路径均是linux环境下。而我们一般使用windows环境下的understand阅读源码,故而需要对txt文件进行处理。当然,若是在linux环境下的understand阅读源码,则忽略这一步。
处理方法很简单,查找+替换,便可。具体如下:

  1. 将linux环境下生成的FileList_understand.txt拷贝至windows环境下。
  2. 使用编辑软件打开FileList_understand.txt,这里使用notepad++;
  3. 先查找替换掉 / ,快捷键Ctrl+H打开替换框,将 / 替换为 \。
    在这里插入图片描述
  4. 将linux环境下的绝对路径替换为windows下linux源码的绝对路径。
    在这里插入图片描述
    示例中linux源码在windows下 F:\opensource\linux-4.1.15-openedv-me下,故:
    在这里插入图片描述

4. 将linux源码文件导入到understand中

利用上一步处理后的FileList_understand.txt,将linux源码文件导入至understand中。
方法有二,方法一是在新建understand时利用txt导入文件至工程中,具体见 高效阅读嵌入式源码系列一:静态分析神器understand软件基本操作的 “二、导入项目”这个章节。
下面介绍方法二,在已创建的工程中精准导入所需的文件。

  1. 打开project的配置工程选项
    在这里插入图片描述
  2. 在弹出的配置工程框中,选择files
    在这里插入图片描述
  3. 删除工程中之前导入的文件,如下:
    在这里插入图片描述
  4. 导入FileList_understand.txt,如下:
    在这里插入图片描述
    在这里插入图片描述导入后,结果如下,点击OK开始静态分析。
    在这里插入图片描述
    在这里插入图片描述
    左下角有进度
    在这里插入图片描述

待工程的分析完成后,我们便可愉快的分析源码了。

三、总结

以上,介绍了tonyho大神的Generate_Kernel_Uboot_Project_forIDE工具,以及与understand软件结合使用的情况。
这里需要注意的是,生成的FileList_understand.txt要注意 斜杠 ,linux环境与windows环境不同。

各位看官,肯定也看到了Generate_Kernel_Uboot_Project_forIDE工具生成的FileList_SourceInsight.txt,这是用于source insight软件的,各位可以使用下,这里就不介绍了。

  • 5
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值