如何将包含子目录的整个目录复制到yocto中的 /启动(IE bootf)时,如何继承核心图像类?

发布于 2025-01-26 02:26:54 字数 247 浏览 4 评论 0 原文

我有一个目录,该目录又包含子目录,这些子目录是其他食谱的一部分,并使用部署BB类移至Deploy_dir_image。因此,现在我想将其复制到主图像引导分区。

如果它是一个文件,则将需要文件名附加到image_efi_boot_files变量,然后Yocto将其复制到 /启动。但是,对于包含子目录的目录也不适用,请提供样式,即使包括子目录。谢谢

PS:我尝试了附加image_efi_boot_files +=“ parent_dir/*”不起作用。

I have a directory which again contains subdirectories, which are built has part of other recipe and moved to DEPLOY_DIR_IMAGE using deploy bb class. So now I want to copy it to main image boot partition.

If it was a single file then appending required filename to IMAGE_EFI_BOOT_FILES variable, then yocto copies it to /boot. But same doesn't work for directories containing subdirectories please provide style to include even the subdirectories. Thank you

PS: I have tried appending IMAGE_EFI_BOOT_FILES += "parent_dir/*" didnt work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

临风闻羌笛 2025-02-02 02:26:54

显然, image_efi_boot_files 的作用与众所周知的 image> image_boot_files 和其他负责在启动分区中运送所需文件的变量。这需要文件而不是目录。

因此,如果您不需要手工指定所有文件,而是要通过目录,我建议您使用Python方法为您收集文件并将其附加到变量上。

请参阅我开发和测试的以下示例:

def get_files(d, dir):
    import os
    dir_path = dir
    if not os.path.exists(os.path.dirname(dir)):
        dir_path = d.getVar(dir)
    return ' '.join(f for f in os.listdir(d.getVar(dir)) if os.path.isfile(f))

IMAGE_EFI_BOOT_FILES += "${@get_files(d, 'DEPLOY_DIR_IMAGE')}"

该方法将测试参数是否是真实的路径,则它将直接检查文件,如果没有,则假定它是Bitbake变量,并且将获得其内容,因此,如果 deploy_dir_image 是,例如/home/user/user/dir ,通过 deploy_dir_image //home/home/home/usr/usr/dir 将给予相同的结果。

重要

很明显, image_efi_boot_files .conf 文件中使用,例如 local.conf 或自定义机器配置文件。因此,添加 .conf 文件中的Python函数将无法工作。我建议为其创建一个类,并在您的 .conf 文件中全球继承它:

  • meta-custom/class/class/utils.bbclass

  • local.conf

INHERIT += "utils"
IMAGE_EFI_BOOT_FILES += "${@get_files(d, 'DEPLOY_DIR_IMAGE')}"

尝试一下,在评论中让我知道。

编辑

我刚刚意识到Bitbake已经在Python表达式扩展中导入 OS ,因此您可以在一行中进行此操作,而无需单独的Python函数:

PATH = "/path/to/directory/"  or
PATH = "A variable containing the path"
IMAGE_EFI_BOOT_FILES += "${@' '.join('%s' % f for f in os.listdir('${PATH}') if os.path.isfile(f))}"

It is obvious that IMAGE_EFI_BOOT_FILES is acting like the well known IMAGE_BOOT_FILES and other variables that are responsible for having the files necessary to be shipped in the boot partition. And that needs files and not directories.

So, if you do not need to specify all the files by hand, but instead you want to pass the directory, I suggest you use a python method to collect the files for you and append them to the variable.

See the following example I developed and tested:

def get_files(d, dir):
    import os
    dir_path = dir
    if not os.path.exists(os.path.dirname(dir)):
        dir_path = d.getVar(dir)
    return ' '.join(f for f in os.listdir(d.getVar(dir)) if os.path.isfile(f))

IMAGE_EFI_BOOT_FILES += "${@get_files(d, 'DEPLOY_DIR_IMAGE')}"

The method will test if the argument is a real path then it will directly check for files, if not it will assume that it is a bitbake variable and it will get its content, so if DEPLOY_DIR_IMAGE is, for example, /home/user/dir, passing DEPLOY_DIR_IMAGE or /home/usr/dir will give the same result.

IMPORTANT

It is obvious also that IMAGE_EFI_BOOT_FILES is used in a .conf file such as local.conf or a custom machine configuration file. So adding that python function in .conf file will not work. I suggest creating a class for it and inherit it globally in your .conf file:

  • meta-custom/classes/utils.bbclass

  • local.conf:

INHERIT += "utils"
IMAGE_EFI_BOOT_FILES += "${@get_files(d, 'DEPLOY_DIR_IMAGE')}"

Try this and let me know in the comments.

EDIT

I have just realized that bitbake already imports os within python expressions expansions, so you can do it in one line without any need for a separate python function:

PATH = "/path/to/directory/"  or
PATH = "A variable containing the path"
IMAGE_EFI_BOOT_FILES += "${@' '.join('%s' % f for f in os.listdir('${PATH}') if os.path.isfile(f))}"
落在眉间の轻吻 2025-02-02 02:26:54

注意:我正在寻找可以实现上述解决方案的Yocto内置,希望分享其他方法以解决社区的利益。

如果您使用一个或一个或请参阅talel-belhadjsalem使用utils.bbclass的答案。

def add_directory_bootfs(d, dirname, bootfs_dir):
    file_list = list()
    boot_files_list = list()
    deploy_dir_image = d.getVar('DEPLOY_DIR_IMAGE')
    for (dirpath, dirnames, filenames) in os.walk(os.path.join(deploy_dir_image, dirname)):
        file_list += [os.path.join(dirpath, file) for file in filenames]
    for file in file_list:
        file_rel_path = os.path.relpath(file, os.path.join(deploy_dir_image, dirname))
        boot_file_entry = os.path.join(dirname, file_rel_path) + ';' + os.path.join(bootfs_dir, dirname, file_rel_path)
        boot_files_list.append(boot_file_entry)
    return ' '.join(boot_files_list)

IMAGE_EFI_BOOT_FILES += "${@add_directory_bootfs(d, 'relative_path_to_dir_in_deploy_dir_image', 'EFI/BOOT')}"

Note: I am looking for Yocto built-in which can achieve solution for above mentioned , would like to share other way to resolve the functionality for community's benefit.

Add following in bb file if you are using one or refer to talel-belhadjsalem answer to use utils.bbclass.

def add_directory_bootfs(d, dirname, bootfs_dir):
    file_list = list()
    boot_files_list = list()
    deploy_dir_image = d.getVar('DEPLOY_DIR_IMAGE')
    for (dirpath, dirnames, filenames) in os.walk(os.path.join(deploy_dir_image, dirname)):
        file_list += [os.path.join(dirpath, file) for file in filenames]
    for file in file_list:
        file_rel_path = os.path.relpath(file, os.path.join(deploy_dir_image, dirname))
        boot_file_entry = os.path.join(dirname, file_rel_path) + ';' + os.path.join(bootfs_dir, dirname, file_rel_path)
        boot_files_list.append(boot_file_entry)
    return ' '.join(boot_files_list)

IMAGE_EFI_BOOT_FILES += "${@add_directory_bootfs(d, 'relative_path_to_dir_in_deploy_dir_image', 'EFI/BOOT')}"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文