Yocto使用devtool修改内核编译报KERNEL_LOCALVERSION展开失败
问题现象
通过devtool modify virtual/kernel创建内核本地工作区后编译内核,触发如下报错,未创建该工作区时编译流程无异常:
ERROR: ExpansionError during parsing /home/aws-fsp-build/rax-workspace/yocto/meta-ti/recipes-kernel/linux/linux-ti-staging-rt_5.10.bb Traceback (most recent call last): File "Var <KERNEL_LOCALVERSION>", line 1, in <module> bb.data_smart.ExpansionError: Failure expanding variable KERNEL_LOCALVERSION, expression was -g${@d.getVar('SRCPV', True).split('+')[1]} which triggered exception IndexError: list index out of range
当前使用meta-ti仓库的dunfell分支,因内核开发需求必须保留本地工作区,完整编译报错日志如下:
Loading cache: 100% |#########################################################################################################| Time: 0:00:00 Loaded 4480 entries from dependency cache. WARNING: /home/aws-fsp-build/rax-workspace/yocto/meta-ti/recipes-kernel/linux/linux-ti-staging-rt_5.10.bb: Exception during build_dependencies for do_configure WARNING: /home/aws-fsp-build/rax-workspace/yocto/meta-ti/recipes-kernel/linux/linux-ti-staging-rt_5.10.bb: Error during finalise of /home/aws-fsp-build/rax-workspace/yocto/meta-ti/recipes-kernel/linux/linux-ti-staging-rt_5.10.bb ERROR: ExpansionError during parsing /home/aws-fsp-build/rax-workspace/yocto/meta-ti/recipes-kernel/linux/linux-ti-staging-rt_5.10.bb Traceback (most recent call last): File "Var <KERNEL_LOCALVERSION>", line 1, in <module> bb.data_smart.ExpansionError: Failure expanding variable KERNEL_LOCALVERSION, expression was -g${@d.getVar('SRCPV', True).split('+')[1]} which triggered exception IndexError: list index out of range WARNING: /home/aws-fsp-build/rax-workspace/yocto/meta-ti/recipes-kernel/linux/linux-ti-staging-rt_5.4.bb: Cooker received SIGTERM, shutting down... WARNING: /home/aws-fsp-build/rax-workspace/yocto/meta-carrier/recipes-kernel/linux/linux-ti-staging_4.19.bb: Cooker received SIGTERM, shutting down... WARNING: /home/aws-fsp-build/rax-workspace/yocto/meta-carrier/recipes-kernel/mstp-mod/mstp-mod.bb: Cooker received SIGTERM, shutting down... Summary: There were 5 WARNING messages shown. Summary: There was 1 ERROR message shown, returning a non-zero exit code.
故障原因
报错来自KERNEL_LOCALVERSION变量的展开逻辑:配方中默认SRCPV变量值包含+分隔符,直接通过split('+')[1]取分割后的第二段内容。
执行devtool modify创建本地工作区后,内核源码源切换为本地目录,SRCPV的值不再包含+字符,分割后返回的列表长度仅为1,访问下标1时直接触发IndexError越界报错。
修复方案
无需删除本地工作区,任选以下一种方案即可修复:
- 方案1:给
KERNEL_LOCALVERSION的取值逻辑增加容错判断,兼容本地源码场景。找到对应内核配方(.bb文件)或自己维护的.bbappend文件中定义KERNEL_LOCALVERSION的行,替换为带判断的写法:
该写法在远程拉取源码场景下保持原有版本后缀逻辑不变,本地工作区场景下自动追加空后缀,不会触发下标越界,修改后直接重新执行编译即可。KERNEL_LOCALVERSION = "-g${@d.getVar('SRCPV', True).split('+')[1] if '+' in d.getVar('SRCPV', True) else ''}" - 方案2:手动指定源码提交哈希,让
SRCPV生成时保持原有带+的格式。首先进入本地内核工作区目录,执行命令获取当前提交的短哈希:
打开devtool自动生成的对应append配置文件(默认路径为git rev-parse --short HEADbuild/workspace/appends/目录下对应linux-ti-staging-rt的.bbappend文件),添加如下配置:
保存配置后重新执行编译即可。SRCREV = "<上一步获取到的git提交短哈希>"
内容的提问来源于stack exchange,提问作者Raxesh Oriya
相关产品推荐
相关产品推荐

