<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[【FAQ】全志R128芯片 如何在FreeRTOS下对代码源文件进行快速预处理？]]></title><description><![CDATA[<h2>1.主题</h2>
<p dir="auto">FreeRTOS_R128_如何对代码源文件进行快速预处理</p>
<h2>2.问题背景</h2>
<p dir="auto">硬件：R128<br />
软件：FreeRTOS</p>
<p dir="auto">客户在日常的开发过程中，会碰到源文件中有许多的宏或许多条件编译的代码，有时候需要快速确认多个宏展开后的内容或快速确认条件编译到底编译的是哪一部分代码。</p>
<p dir="auto">那么如何在现有SDK环境下对代码源文件进行快速的预处理？</p>
<h2>3.问题分析</h2>
<p dir="auto">预处理思路：</p>
<p dir="auto">目前R128的SDK使用了修改后的kbuild构建框架(原始kbuild构建框架来自linux kernel)，kbuild构建框架在编译每个源文件时会同时生成一个.xxx.o.cmd文件，</p>
<p dir="auto">这个文件里包含了编译此源文件时依赖的一些头文件以及编译时使用的编译命令，通过修改编译命令将编译时的-c参数修改为-E参数即可完成对源文件的预处理。</p>
<h2>4.解决办法</h2>
<p dir="auto">可以手动从.xxx.o.cmd文件中拿到编译命令并修改，但这适用于要预处理的文件比较少的情况，且各个源文件的编译命令的修改过程基本相同，</p>
<p dir="auto">因此可以使用shell脚本自动预处理来代替人工手动预处理。<br />
这里提供一个generate_preprocess_file.sh脚本(脚本文件见附件)，脚本使用方法为：</p>
<pre><code>./generate_preprocess_file.sh &lt;source file path&gt;
</code></pre>
<p dir="auto">脚本输出的日志中最后2行会有生成的预处理文件的路径。<br />
注意：脚本中调用了astyle工具将生成的预处理文件进行代码格式化，请在使用前安装astyle工具，否则脚本输出日志的最后一行将会报错。</p>
<p dir="auto">下面具体描述下对各个核心的代码源文件进行自动预处理的步骤。</p>
<p dir="auto"><strong>M33核和C906核代码源文件自动预处理步骤</strong></p>
<ol>
<li>拷贝generate_preprocess_file.sh脚本到lichee/rtos目录，并执行命令chmod +x ./generate_preprocess_file.sh确保脚本文件有可执行权限</li>
<li>执行lunch_rtos选择对应方案的M33核或者C906核</li>
<li>执行./generate_preprocess_file.sh xxx.c命令对某个源文件进行预处理</li>
</ol>
<p dir="auto"><strong>DSP核代码源文件自动预处理步骤</strong></p>
<ol>
<li>拷贝generate_preprocess_file.sh脚本到lichee/dsp目录，并执行命令chmod +x ./generate_preprocess_file.sh确保脚本文件有可执行权限</li>
<li>执行./generate_preprocess_file.sh xxx.c命令对某个源文件进行预处理</li>
</ol>
<p dir="auto"><strong>脚本使用示例</strong></p>
<p dir="auto">下面是对M33核代码源文件arch/arm/armv8m/sun20iw2p1/sun20i.c进行预处理的结果</p>
<p dir="auto"><img src="/assets/uploads/files/1679019224592-1c94af239290409aacc772f135601446.jpg" alt="1c94af239290409aacc772f135601446.jpg" class=" img-responsive img-markdown" width="1901" height="947" /></p>
<p dir="auto">可以看到最终生成的预处理文件有如下2个：</p>
<pre><code>build/r128s2_pro_m33/arch/arm/armv8m/sun20iw2p1/sun20i.i
build/r128s2_pro_m33/arch/arm/armv8m/sun20iw2p1/sun20i.i.orig
</code></pre>
<p dir="auto">其中xxx.i.orig表示最原始的由编译器生成的预处理文件，xxx.i表示进行代码格式化后的预处理文件。</p>
<p dir="auto">用vi打开对应的预处理文件后可以看到代码中的宏以及条件编译已全部展开：</p>
<p dir="auto"><img src="/assets/uploads/files/1679019243527-b325d0988c65490d9a733395facaf756.jpg" alt="b325d0988c65490d9a733395facaf756.jpg" class=" img-responsive img-markdown" width="1237" height="640" /></p>
]]></description><link>https://bbs.aw-ol.com/topic/3128/faq-全志r128芯片-如何在freertos下对代码源文件进行快速预处理</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 19:53:19 GMT</lastBuildDate><atom:link href="https://bbs.aw-ol.com/topic/3128.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 17 Mar 2023 02:15:08 GMT</pubDate><ttl>60</ttl></channel></rss>