在 yocto 配方中生成一个文件并将其部署到图像

Generate a file and deploy it to image, inside a yocto recipe

我需要根据菜谱的内容生成某种清单。这个文件也需要部署到镜像中。

生成文件,我在很多bbclasses中看到python代码函数的使用方式类似如:

      python do_create_manifest () {
          [...]
          filename = d.expand("${D}${LOC}/${MANIFEST_NAME}")
          [...]
          with open (filename,'w') as manifest_file:
             json.dump(manifest_dict, manifest_file, indent=True)
          os.chmod(filename, 0o644)
      }

文件是在添加任务依赖后创建的,但是打包该文件时,文件中出现host-user-contaminated警告

尽管我在许多食谱中看到过使用:

        chown -R root:root ${D}${...}/${...}

这失败了,因为 chown 需要由 root 运行,而 bitbake 由当前用户 运行:

Log data follows:
| DEBUG: Executing shell function do_uncontaminate
| chown: changing ownership of '/mnt/thud/build-r0w/[...]/manifest.json': Operation not permitted
| WARNING: exit code 1 from a shell command.

注意:我知道这可以防止出现警告,但不能解决问题。

    INSANE_SKIP_${PN} = "host-user-contaminated"

您没有指定此文件的创建位置,filename 包含的路径,但根据错误我怀疑您是直接在 ${D} 某处创建的。

如果您改为在例如下面创建清单文件${B},然后在常规 do_install 期间使用例如安装它install -Dm0644 ${B}/my_manifest ${D}/dest/path/my_manifest所有权问题将与食谱安装的任何其他文件一样得到处理。

只需确保 do_create_manifest 任务在 do_install 之前 运行。