Search code examples
yoctoopenembeddedyocto-recipe

How to display new Yocto image option after source poky/oe-init-env


let say i have a new yocto image call stargazer-cmd what file should i edit so that every time i source poky/oe-init-env it display as a build option to the user?

kj@kj-Aspire-V3-471G:~/stm32Yoctominimal$ source poky/oe-init-build-env  build-mp1/

### Shell environment set up for builds. ###

You can now run 'bitbake <target>'

Common targets are:
    core-image-minimal
    core-image-sato
    meta-toolchain
    meta-ide-support

I wish to add stargazer-cmd on top of core-image-minimal, i am not sure what to google and what is the file i need to change.


Solution

  • Let me explain how to add a custom configuration to the OpenEmbedded build process.

    First of all, here is the process that is done when running:

    source poky/oe-init-build-env
    
    1. The oe-init-build-env script initializes OEROOT variable to point to the location of the script itself.

    2. The oe-init-build-env script sources another file $OEROOT/scripts/oe-buildenv-internal which will:

    • Check if OEROOT is set
    • Set BUILDDIR to your custom build directory name $1, or just build if you do not provide one
    • Set BBPATH to the poky/bitbake folder
    • Adds $BBPATH/bin and OEROOT/scripts to PATH (This will enable commands like bitbake and bitbake-layers ...)
    • Export BUILDDIR and PATH to the next file
    1. The oe-init-build-env script continues by running the final build script with:
    TEMPLATECONF="$TEMPLATECONF" $OEROOT/scripts/oe-setup-builddir
    
    1. The oe-setup-builddir script will:
    • Check if BUILDDIR is set
    • Create the conf directory under $BUILDDIR
    • Sources a template file that will check if there is a TEMPLATECONF variable is set:
    . $OEROOT/.templateconf
    

    That file contains:

    # Template settings
    TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
    

    it means that if TEMPLATECONF variable is not set, set it to meta-poky/conf, and that is where the default local.conf and bblayers.conf are coming from.

    • Copy $TEMPLATECONF to $BUILDDIR/conf/templateconf.cfg
    • Set some variables pointing to custom local.conf and bblayers.conf:
    OECORELAYERCONF="$TEMPLATECONF/bblayers.conf.sample"
    OECORELOCALCONF="$TEMPLATECONF/local.conf.sample"
    OECORENOTESCONF="$TEMPLATECONF/conf-notes.txt"
    

    In the oe-setup-builddir there is a comment saying that TEMPLATECONF can point to a directory:

    # 
    # $TEMPLATECONF can point to a directory for the template local.conf & bblayers.conf
    #
    
    • Copy local.conf.sample and bblayers.conf.sample from TEMPLATECONF directory into BUIDDIR/conf:
    cp -f $OECORELOCALCONF "$BUILDDIR/conf/local.conf"
    
    sed -e "s|##OEROOT##|$OEROOT|g" \
        -e "s|##COREBASE##|$OEROOT|g" \
            $OECORELAYERCONF > "$BUILDDIR/conf/bblayers.conf"
    

    Finally it will print what is inside OECORENOTESCONF which points to TEMPLATECONF/conf-notes.txt:

    [ ! -r "$OECORENOTESCONF" ] || cat $OECORENOTESCONF
    

    and by default that is located under meta-poky/conf/conf-notes.txt:

    ### Shell environment set up for builds. ###
    
    You can now run 'bitbake <target>'
    
    Common targets are:
        core-image-minimal
        core-image-sato
        meta-toolchain
        meta-ide-support
    
    You can also run generated qemu images with a command like 'runqemu qemux86'
    
    Other commonly useful commands are:
     - 'devtool' and 'recipetool' handle common recipe tasks
     - 'bitbake-layers' handles common layer tasks
     - 'oe-pkgdata-util' handles common target package tasks
    

    So, now, after understanding all of that, here is what you can do:

    1. Create a custom template directory for your project, containing:
    • local.conf.sample
    • bblayers.conf.sample
    • conf-notes.txt
    1. Do not forget to set the path to poky in bblayers.conf to ##OEROOT## as it will be set automatically by the build script.

    2. Set your custom message in conf-notes.txt

    3. Before any new build, just set TEMPLATECONF:

    TEMPLATECONF="<path/to/template-directory>" source poky/oe-init-build-env <build_name>
    

    Then, you will find a build with your custom local.conf and bblayers.conf with additional file conf/templateconf.cfg containing the path of TEMPLATECONF