【RT-Thread】将BSP工程从RT-Thread源码中独立出来开发(2)

上一篇:【RT-Thread】将BSP工程从RT-Thread源码中独立出来开发(1)

接上回

上一篇文章中介绍了如何制作一个可以独立编译的BSP,构建CMake工程和编译都是正常的,但在使用 menuconfig 进行配置时依然需要进一步配置。

由于 menuconfig 使用的 Kconfig 配置也存在递归寻找其他 Kconfig 文件的机制,因此,我们直接使用时,出现了以下错误:

$ menuconfig
Kconfig:5: warning: BSP_ROOT has 'option env="BSP_DIR"', but the environment variable BSP_DIR is not set
Kconfig:5: warning: Kconfiglib expands environment variables in strings directly, meaning you do not need 'option env=...' "bounce" symbols. For compatibility with the C tools, rename BSP_DIR to BSP_ROOT (so that the symbol name matches the environment variable name).
Kconfig:10: warning: Kconfiglib expands environment variables in strings directly, meaning you do not need 'option env=...' "bounce" symbols. For compatibility with the C tools, rename RTT_DIR to RTT_ROOT (so that the symbol name matches the environment variable name).
Kconfig:15: warning: Kconfiglib expands environment variables in strings directly, meaning you do not need 'option env=...' "bounce" symbols. For compatibility with the C tools, rename PKGS_DIR to PKGS_ROOT (so that the symbol name matches the environment variable name).
warning: RT_VBUS_USING_TESTS (defined at D:\00_Workspace\01_software_proj\embed_proj\rt-thread/components/vbus/Kconfig:22) has leading or trailing whitespace in its prompt
warning: RT_VBUS_GUEST_VIRQ (defined at D:\00_Workspace\01_software_proj\embed_proj\rt-thread/components/vbus/Kconfig:36) defined with more than one help text -- only the last one will be used
warning: PKG_USING_RGPOWER (defined at D:\03_Tools\env-windows\tools\bin\..\..\packages/packages/peripherals/RgPower/Kconfig:2) has leading or trailing whitespace in its prompt
menuconfig: Kconfig:20: '../libraries/Kconfig' not found (in 'source "../libraries/Kconfig"'). Check that environment variables are set correctly (e.g. $srctree, which is unset or blank). Also note that unset environment variables expand to the empty string.

前面所显示的警告主要有两部分:

  • 第一部分主要是来自于某些环境变量未定义 but the environment variable BSP_DIR is not set,因此在使用它们的时候会报找不到的警告,由于配置中都定义了找不到环境变量则使用默认值,警告也提示我们可以直接赋值为默认值,因此这里我们先不关注这些警告;
  • 第二部分来自于RTT官方的配置中可能存在某些额外的空白字符has leading or trailing whitespace,或者重复定义了help字符串等defined with more than one help text -- only the last one will be used,这里暂时也先不关注;

我们需要关注的是最后一个错误的提示,这个错误显示 'menuconfig: Kconfig:20: '../libraries/Kconfig' not found (in 'source "../libraries/Kconfig"').,因此我们需要修改某些路径,帮助 Kconfig 找到需要的脚本

分析出错误的Kconfig文件

根据日志提示,出错误的Kconfig文件为跟目录下的Kconfig文件的第20行,我们观察Kconfig中出错误的部分,第20行为 source "../libraries/Kconfig",由于更换成了独立的bsp,这种相对路径肯定会失效的。

Kconfig中,可以使用系统环境变量,方法就是如下的 option env=RTT_ROOT

mainmenu "RT-Thread Configuration"

config BSP_DIR
    string
    option env="BSP_ROOT"
    default "."

config RTT_DIR
    string
    option env="RTT_ROOT"
    default "../../.."

config PKGS_DIR
    string
    option env="PKGS_ROOT"
    default "packages"

source "$RTT_DIR/Kconfig"
source "$PKGS_DIR/Kconfig"
source "../libraries/Kconfig"
source "board/Kconfig"

由于在上篇中,我们已经建立了环境变量 RTT_ROOT,我们可以使用 $(info, $(RTT_DIR)) 在Kconfig中打印一下试试:

mainmenu "RT-Thread Configuration"

config BSP_DIR
    string
    option env="BSP_ROOT"
    default "."

config RTT_DIR
    string
    option env="RTT_ROOT"
    default "../../.."

config PKGS_DIR
    string
    option env="PKGS_ROOT"
    default "packages"

$(info, $(RTT_DIR))

source "$RTT_DIR/Kconfig"
source "$PKGS_DIR/Kconfig"
source "../libraries/Kconfig"
source "board/Kconfig"
.....
Kconfig:18:  D:\00_Workspace\01_software_proj\embed_proj\rt-thread
.....
menuconfig: Kconfig:22: '../libraries/Kconfig' not found (in 'source "../libraries/Kconfig"'). Check that environment variables are set correctly (e.g. $srctree, which is unset or blank). Also note that unset environment variables expand to the empty string.

去除警告信息,可见打印出RTT_DIR为D:\00_Workspace\01_software_proj\embed_proj\rt-thread,这与我设定的环境变量一致。因此,将这里也改成 "$RTT_DIR/bsp/stm32/libraries/Kconfig",由于RTT_DIR 和RTT_ROOT是一样的,因此这里也可以使用 RTT_ROOT。

修改完后,重新使用 menuconfig,输出日志如下,library路径下的Kconfig已经可以找到,在 board 下的 Kconfig 第306行找不到 '../libraries/HAL_Drivers/Kconfig'

menuconfig: board/Kconfig:306: '../libraries/HAL_Drivers/Kconfig' not found (in 'source "../libraries/HAL_Drivers/Kconfig"'). Check that environment variables are set correctly (e.g. $srctree, which is unset or blank). Also note that unset environment variables expand to the empty string.

修改第306行如下,再次执行 menuconfig 就可以正常启动:

修改前:
source "../libraries/HAL_Drivers/Kconfig"
修改后:
source "$RTT_DIR/bsp/stm32/libraries/HAL_Drivers/Kconfig"

总结

本次修改主要对于bsp下的 Kconfig 和 board 下的 Kconfig 文件中对于 RTT 源码中 library 路径的引用,将其从相对路径修改成了基于环境变量的绝对路径,修改后该bsp就不会受其路径影响。

下一篇:【RT-Thread】将BSP工程从RT-Thread源码中独立出来开发(3)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值