Search code examples
linuxyoctobitbakeyocto-recipeyocto-layer

Create directory and copy file in roofs in Yocto


I am trying to create a meta layer for my application. For testing purposes, I would like to have the Image pre-built with a sample video file. I have seen this answered, but it seems that all the answers I find are deprecated. I am running Yocto Kirkstone.

So, my meta-layer looks like this : video-image.bb

SUMMARY = "Adds usb-uvc capabilities, h264 encoding"
IMAGE_INSTALL = "packagegroup-core-boot ${CORE_IMAGE_EXTRA_INSTALL}"
IMAGE_LINGUAS = " "
LICENSE = "MIT"

inherit core-image

# Set rootfs to 1 GB by default
IMAGE_OVERHEAD_FACTOR ?= "1.0"
IMAGE_ROOTFS_SIZE ?= "1003520"
#IMAGE_ROOTFS_EXTRA_SPACE:append = "${@bb.utils.contains("DISTRO_FEATURES", "systemd", " + 4096", "", d)}"

inherit extrausers
# Change root password (note the capital -P)
EXTRA_USERS_PARAMS = " \
    usermod -p '\$6\$11223344\$N9q7Gt5eJJb54sBuR/.7ih8w/OeBBQ8D38FmefDKuTMVM5RbnR07FQayQQWSntbXw/DPpuS781UWLHDTY1lhr1' root; \
"

MY_FILES = "/home/antoine/Downloads/qb_helmet_sample.mp4"

FILES_${PN} += "${datadir}/movies"
FILES_${PN} += "${datadir}/movies/${MY_FILES}"

do_install(){
    install -d ${D}${datadir}/movies
    install -m 0644 ${MY_FILES} ${D}${datadir}/movies/
}

When I run bitbake video-image, the image is created and I can see the effect of my layer such as the modified root password, but the directory and files are not there. How can I fix this?


Solution

  • video-image inherits core-image which itself inherits image.

    To understand what you did, you need to understand that recipe has 2 types:

    • Package
    • Image

    A package recipe provides a final package that can be one of the following types:

    • deb
    • rpm
    • ipk

    This is controlled via the PACKAGE_CLASSES variable that you can find in your local.conf file.

    So, in order to create a package, a list of tasks are executed by bitbake on a given recipe .bb file, it is like cooking a recipe:

    1. do_fetch: Download what is in SRC_URI into DL_DIR (aka downloads)
    2. do_unpack: Upacks what is in DL_DIR into WORKDIR of the recipe
    3. do_patch: Apply some patches if .patch files found in SRC_URI
    4. do_configure: Do some configuration before compilation
    5. do_compile: The compilation process
    6. do_install: This install files to D which is WORKDIR/image that specifies what should be go into the final package
    7. do_package: Do create package and package-split folders for all packages to create of the recipe based on the FILES variable
    8. do_package_write_<type>: Create the final packages, type is one of deb rpm ipk

    Also there are some inter tasks like do_populate_sysroot and do_prepare_recipe_sysroot, do_package_qa, ... But it is not important right now.

    When dealing with Image recipes, there in no task of the previous list.

    Image recipes are just a collection of Package recipes that Bitbake will use to create the final rootfs, hince it has other tasks like:

    • do_rootfs
    • do_image_<type> type can be one of IMAGE_FSTYPES (Example: ext4, ..)
    • do_image_complete

    So, in order to add something to an image, it means that you need to add a Package recipe to the list that the Image recipe uses which is IMAGE_INSTALL.

    In your case:

    1. Create a recipe .bb to install your video files
    meta-custom
       | recipes-videos
           | videos
              | video-recipe_0.1.bb
              | files
                 | qb_helmet_sample.mp4
    
    • video-recipe_0.1.bb
    LICENSE = "CLOSED"
    
    MY_FILES = "qb_helmet_sample.mp4"
    
    SRC_URI = "file://${MY_FILES}"
    
    do_install(){
        install -d ${D}${datadir}/movies
        install -m 0644 ${MY_FILES} ${D}${datadir}/movies/
    }
    
    FILES:${PN} += "${datadir}/movies/*"
    
    1. Add your new recipe to your image:
    IMAGE_INSTALL:append = " video-recipe"
    

    IMPORTANT

    • Never ever ever use absolute paths in your Yocto metadata (layers, recipes, conf, ...)