Home » Development and Build » Yocto Embedded Linux » Configure Yocto to download from local mirror to save bandwidth

Configure Yocto to download from local mirror to save bandwidth

If you once have downloaded and compiled yocto build, it generates local tar files of all the source codes, using which we can configure Yocto to make sure our next build, if we start at any other location, downloads all the files from local server instead of always going to internet to download, thus saving lot of bandwidth.

For this first step will be to setup a local apache server and then copy the contents of DL_DIR i.e. downloads folder into /var/www/html/my_folder so that we can access those at http://mylocal_ip/my_folder

if you have check conf/local.conf for where to download the contents while first compilation of yocto build.

#
# Where to place downloads
#
# During a first build the system will download many different source code tarballs
# from various upstream projects. This can take a while, particularly if your network
# connection is slow. These are all stored in DL_DIR. When wiping and rebuilding you
# can preserve this directory to speed up this part of subsequent builds. This directory
# is safe to share between multiple builds on the same machine too.
#
# The default is a downloads directory under TOPDIR which is the build directory.
#
#DL_DIR ?= "${TOPDIR}/downloads"

Now, open your distro.conf as conf/distro/my_platform.conf and modify the below lines,

PREMIRRORS ?= "\
bzr://.*/.* http://mylocal_ip/my_folder/ \n \
cvs://.*/.* http://mylocal_ip/my_folder/ \n \
git://.*/.* http://mylocal_ip/my_folder/ \n \
hg://.*/.* http://mylocal_ip/my_folder/ \n \
osc://.*/.* http://mylocal_ip/my_folder/ \n \
p4://.*/.* http://mylocal_ip/my_folder/ \n \
svk://.*/.* http://mylocal_ip/my_folder/ \n \
svn://.*/.* http://mylocal_ip/my_folder/ \n"
MIRRORS =+ "\
ftp://.*/.* http://mylocal_ip/my_folder/ \n \
http://.*/.* http://mylocal_ip/my_folder/ \n \
https://.*/.* http://mylocal_ip/my_folder/ \n"

Now, save and compile, so yocto will first try to download from local mirrors instead of external network.

Reference : https://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html

3.3.4. Source Mirror(s)¶
Two kinds of mirrors exist: pre-mirrors and regular mirrors. The PREMIRRORS and MIRRORS variables point to these, respectively. BitBake checks pre-mirrors before looking upstream for any source files. Pre-mirrors are appropriate when you have a shared directory that is not a directory defined by the DL_DIR variable. A Pre-mirror typically points to a shared directory that is local to your organization.

Regular mirrors can be any site across the Internet that is used as an alternative location for source code should the primary site not be functioning for some reason or another.

Specifies additional paths from which the OpenEmbedded build system gets source code. When the build system searches for source code, it first tries the local download directory. If that location fails, the build system tries locations defined by PREMIRRORS, the upstream source, and then locations specified by MIRRORS in that order.

Assuming your distribution (DISTRO) is “poky”, the default value for PREMIRRORS is defined in the conf/distro/poky.conf file in the meta-yocto Git repository.

Typically, you could add a specific server for the build system to attempt before any others by adding something like the following to the local.conf configuration file in the Build Directory:

PREMIRRORS_prepend = "\
git://.*/.* http://www.yoctoproject.org/sources/ \n \
ftp://.*/.* http://www.yoctoproject.org/sources/ \n \
http://.*/.* http://www.yoctoproject.org/sources/ \n \
https://.*/.* http://www.yoctoproject.org/sources/ \n"

These changes cause the build system to intercept Git, FTP, HTTP, and HTTPS requests and direct them to the http:// sources mirror. You can use file:// URLs to point to local directories or network shares as well.


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

1 thought on “Configure Yocto to download from local mirror to save bandwidth”

Leave a Comment