The Yocto Project is a powerful and flexible toolset for creating custom Linux distributions for embedded systems. However, during the build process, it often needs to download various files from the internet. In certain scenarios, you might want to prevent Yocto from accessing the external network, such as for security reasons or when building in a network-isolated environment. This is where the BB_NO_NETWORK variable comes into play. In this post, we will explore how to use BB_NO_NETWORK to block external network downloads during the Yocto build process.
Understanding BB_NO_NETWORK
BB_NO_NETWORK is a BitBake variable that, when set to “1”, instructs BitBake to avoid any network activity during the build process. This means that if any recipe tries to fetch files from the internet, it will fail, ensuring that no external downloads are performed.
Why Use BB_NO_NETWORK?
- Security:
 Prevent unauthorized network access and ensure all files come from trusted sources.
- Compliance:
 Adhere to organizational policies that restrict internet access during builds.
- Network Isolation:
 Useful in environments with limited or no internet connectivity.
How to Use BB_NO_NETWORK
To use BB_NO_NETWORK, you need to set it in your build configuration. This can be done in the local.conf file, which is typically located in the conf directory of your Yocto build environment.
- Open local.conf:
 Navigate to theconfdirectory and open thelocal.conffile in a text editor.
   nano conf/local.conf- Set BB_NO_NETWORK:
 Add the following line to thelocal.conffile to enable theBB_NO_NETWORKvariable:
   BB_NO_NETWORK = "1"- Save and Close:
 Save the changes and close the text editor.
With BB_NO_NETWORK set, BitBake will not attempt any network downloads during the build process.
Handling Missing Files
When BB_NO_NETWORK is enabled, all necessary source files and dependencies must be available locally. This means you need to ensure that all required files are either pre-fetched or available in your source mirrors.
- Mirror Configuration:
 Configure local mirrors to serve the required files. This can be done using thePREMIRRORSandMIRRORSvariables in thelocal.conffile.
   PREMIRRORS = "\
   git://.*/.* file:///path/to/local/mirror/ \
   https://.*/.* file:///path/to/local/mirror/ \
   ftp://.*/.* file:///path/to/local/mirror/ \
   "- Fetch All Sources:
 Before enablingBB_NO_NETWORK, perform a build to fetch all sources.
   bitbake <your-target>- Create Source Archive:
 Alternatively, you can create a source archive using thebitbake -c fetchall <your-target>command. This will download all necessary files without building the target.
   bitbake -c fetchall <your-target>- Verify Local Availability:
 Ensure that all source files are present in theDL_DIRdirectory, which is typically located in thedownloadsdirectory of your Yocto build environment.
Blocking external network downloads using BB_NO_NETWORK is a crucial step for maintaining security and compliance in certain build environments. By setting BB_NO_NETWORK and ensuring all necessary files are available locally, you can prevent BitBake from accessing the internet during the build process. This approach helps maintain a controlled and secure build environment, which is essential for many embedded Linux projects.