Search code examples
yoctobitbake

bitbake recipe for installing deb package


I want to install my own custom deb package in yocto image. For this I am using following mydebpkg.bb recipe using ROOTFS_POSTPROCESS_COMMAND

SUMMARY = "Recipe for installing deb package"
DESCRIPTION = "It installs own deb package"
HOMEPAGE = "" 
LICENSE = "CLOSED"

inherit bin_package

my_install_pkg_deb() {

${STAGING_BINDIR_NATIVE}/dpkg \

--root=${IMAGE_ROOTFS}/ --admindir=${IMAGE_ROOTFS}/var/lib/dpkg/  \

-i /home/pi1/install/own_1.3-07u_armhf.deb

}

ROOTFS_POSTPROCESS_COMMAND +=  "my_install_pkg_deb; "

But while building image the process fails with following error cannot install package mydebpkg and Function failed: do_rootfs. Where I am making mistake and what will be the correct recipe for installing any deb package.


Solution

  • Installing precompiled .deb is an awful decision, you should avoid doing so anytime you are able to compile the package from source code. If this isn't the case, I'd suggest doing something like this:

    SUMMARY = "Recipe for installing deb package"
    DESCRIPTION = "It installs own deb package"
    HOMEPAGE = ""
    LICENSE = "CLOSED"
    
    DEPENDS += " dpkg-native "
    
    SRC_URI += " \
        file://own_1.3-07u_armhf.deb.zip \
    "
    
    do_install_append() {
        touch ${STAGING_DIR_NATIVE}/var/lib/dpkg/status
        ${STAGING_BINDIR_NATIVE}/dpkg --instdir=${D}/ \
        --admindir=${STAGING_DIR_NATIVE}/var/lib/dpkg/ \
         -i ${WORKDIR}/own_1.3-07u_armhf.deb
    }
    

    So: use SRC_URI variable to let bitbake copy your .deb file to the working dir. I suggest you zip the file as bitbake tries to unpack all the archives you supply him, and .deb is just another archive. So pack it to zip and let bitbake bring your .deb file to the working directory. Place your .deb.zip file by /path/to/your/recipe/files folder. Remember: never use absolute paths in yocto! Then in do_install function invoke dpkg to install your .deb file into deploy dir of your package. This code is not complete as in case of a successful installation (don't forget about conflict resolution), you will get a list of files and directories that installed but not shipped in any package. You will need to add to your recipe FILES_${PN} variable:

    FILES_${PN} += " \
        /usr/bin/some_file \
        /etc/some_config_file \
        /and_so_on \
    "
    

    The complete list what you need to add you can get from the error message. And remember: this method will only work if your target architecture is the same as your host architecture. Regarding that you used STAGING_BINDIR_NATIVE variable this is the case, regarding that your package contains arm, this isn't.