
Building OpenWrt from Source Code is a great way to customize your router's firmware, but it can be a bit intimidating if you're new to the process.
First, you'll need to download the OpenWrt source code from the official repository. This can be done using Git, with the command `git clone https://git.openwrt.org/openwrt/openwrt.git`.
To build OpenWrt, you'll need to have a C compiler installed on your system, such as GCC. The build process will also require a significant amount of disk space, so make sure you have enough free space available.
The OpenWrt build process involves several steps, including configuration, compilation, and packaging.
For your interest: Openwrt Update Firmware
Preparation
To start building OpenWRT, you need to prepare your SDK by installing the necessary packages. This process involves downloading sources and additional files from a repository.
You'll need to issue a command to install the package you want to rebuild, such as ./scripts/feeds install tcpdump.
The SDK will then download the sources, additional files, and required packages, including any dependencies like libpcap.
The output of this command will show the SDK's progress in preparing the package for building.
Updating and Configuring
To update your current project to the latest Gateworks patches, you can use Git, which is the most developer-friendly option.
Using Git, you can update to the latest patches on the same branch by running `git remote update` and then `git pull --rebase`.
This will update the current working branch to the latest upstream and then attempt to rebase any local patches on top.
If you need to change to a new branch, you'll first need to update your refs with `git remote update`.
Then, you can checkout the upstream branch and create a local branch with a command like `git checkout remotes/origin/16.02 -b 16.02`.
This will create a new local branch named 16.02 based on the upstream branch 16.02.
Here are the steps to update to the latest patches on the same branch and change to a new branch:
- To update to the latest patches on the same branch:
- git remote update
- git pull --rebase
- To change to a new branch:
- git remote update
- git checkout remotes/origin/16.02 -b 16.02
Image Configuration
To build the image, first save your configuration and exit the menuconfig interface. Then, build the image with the make command to generate the binaries.
The binaries will be generated inside the /bin/mvebu64/ directory. They'll have the same file name regardless of the chosen version.
You'll need the armada-3720-community.dtb device tree file, openwrt-armada-ESPRESSObin-Image image, and openwrt-mvebu64-armada-espressobin-rootfs.tar.gz root file system.
Image Configuration

To speed up the build process, you can utilize multiple cores with the command that utilizes multiple cores.
Save your configuration and exit the menuconfig interface.
The binaries will be generated inside the /bin/mvebu64/ directory after the build process finishes.
We will need the armada-3720-community.dtb device tree file and openwrt-mvebu64-armada-espressobin-rootfs.tar.gz root file system.
Binaries have the same file name regardless of the chosen version.
To flash these files onto a USB device or SD card, see Boot from MicroSD card/USB stick - OpenWrt.
Defconfig
Defconfig is a great way to configure your build system. It will produce a general purpose configuration including a check of dependencies and prerequisites for the build environment.
This process is quite thorough, checking for dependencies and installing any missing ones before running the build again. You can trigger this process by running the command "make defconfig".
If you're not sure what's missing, don't worry - defconfig will take care of it for you. It's a convenient way to ensure your build environment is complete and ready to go.
Defining What to (Re)build

To rebuild a package, like tcpdump, you need to "mark" the rebuilding process via the "make menuconfig" application.
The process involves telling the SDK what you want to rebuild by firing the make menuconfig command, which provides a curses-based interface where you can define what you need.
To rebuild a package, you need to "mark" such a rebuilding process, via the "make menuconfig" application.
You can find references of the package you're rebuilding "inside" the "make menuconfig" menus by "installing" the package sources from the related "feed".
In order for the package to be "feed-installable", you need to "update" the repository/feeds (feeds update).
To properly use the "scripts/feeds" utility, you need to download the SDK (specific to your platform).
You can download the SDK (specific to your platform) to properly use the "scripts/feeds" utility.
To define what to (re)build, you can use the following steps:
- Rebuild a package (like tcpdump) by firing the make menuconfig command.
- Find references of the package you're rebuilding "inside" the "make menuconfig" menus by "installing" the package sources from the related "feed".
- Update the repository/feeds (feeds update) to make the package "feed-installable".
- Download the SDK (specific to your platform) to properly use the "scripts/feeds" utility.
- Define the STAGING_DIR environment variable and update the ensure to point to SDK binaries, via properly prepending the SDK bin PATH to your pre-existing PATH variable.
By following these steps, you can define what to (re)build and proceed with the build process.
Building OpenWrt
Building OpenWrt involves downloading the OpenWrt version supported for your device, such as Designated Driver (DD), and creating a directory for it in /opt/openwrt/openwrt-dd.
To get started, you'll need to checkout the respective OpenWrt branch based on your chosen Marvell LSP kernel version. Once you've downloaded the necessary repositories, update and index the feeds with a command from the OpenWrt directory.
You can then issue a "make" command to compile the sources of the package, which may take some time depending on your CPU. According to one user, building the firmware using a parallel approach with "-j8" can significantly speed up the process.
Here's a rough estimate of the time it may take to build the firmware:
Keep in mind that actual build times may vary depending on your device and system configuration.
Launching Real Rebuilding
Launching the real rebuilding process, also known as compiling the sources of the package, is a crucial step in building OpenWrt. You'll need to issue a "make" command, and if you have a multi-core CPU, you can use the "-j" option to take advantage of multiple cores.
The command to launch the rebuilding process is "make" or "make -j8" if you have an 8-core CPU. The rebuilding process will take some time, so it's a good idea to take a break while it's running.
After the rebuilding process is complete, you'll have a compiled package that you can use in your OpenWrt firmware.
OpenWrt
To build OpenWrt, you'll need to download the Designated Driver (DD) version, specifically for the ESPRESSObin board, with additional patches for the boards.
Create a directory /opt/openwrt/openwrt-dd and navigate there.
Download the necessary repositories, then update and index the feeds with the command from within the OpenWrt directory.
Expand your knowledge: Directory Link Building
Troubleshooting and Maintenance
Building OpenWRT can be a bit tricky, but don't worry, I've got some tips to help you troubleshoot common issues.
If you're having trouble generating images for your device, check if you've selected too many options in make config or make menuconfig. This can result in an image that's too big to flash onto your device.
The OpenWRT buildroot won't display any warnings or error messages if an image can't be created because it's too big for its target board. This can be frustrating, but it's good to know what to look out for.
To avoid this issue, keep in mind that you won't be able to use all the flash memory in your device exclusively for your OpenWRT image. There are separate flash partitions for things like the boot loader, wifi calibration data, and configuration data.
Here are some common causes of image generation issues:
- Too many options enabled in make config or make menuconfig
- Insufficient flash memory for the image
Create Diff File
Creating a diff file is an optional but good practice when working with OpenWRT. It includes only the changes compared to the default configuration.
This file can be version controlled with your OpenWRT-based project, making it easier to track changes over time. It's also less affected by OpenWRT updates, since it only contains the changes.
To create a diff file, you can use the `diffconfig.sh` script. Here's how to do it:
- Run the command `./scripts/diffconfig.sh > diffconfig` to write the changes to the diffconfig file.
Troubleshooting
Troubleshooting can be a real challenge, but it's often easier than you think. If you're having trouble building an OpenWRT image for your device, check if both a sysupgrade and a factory image are being generated for your board.
One common issue is that the OpenWRT buildroot won't display any warning or error message if an image cannot be created because it's too big for its target board. This can happen if you've selected/enabled too much stuff in the make config or make menuconfig.
In most cases, you won't be able to use all the flash memory in your device for your OpenWRT image, because there are separate flash partitions dedicated to things like the boot loader and configuration data.
Here are some possible causes of build failures:
- Source URLs disappearing, causing source files to not be there during build-time
- Source files not being found locally, in the original source URL, or on Gateworks' development site
Gateworks has put up source tarballs on their development site to help alleviate this issue, and their build environment takes advantage of this by uploading files for required feeds and automatically selecting them if all other options fail.
Cleaning Up

Cleaning up your build environment is an essential part of troubleshooting and maintenance. It's a good idea to clean your build environment every now and then to get rid of any unnecessary files and configurations.
You'll need to use specific make-targets to clean up your environment, so be careful not to delete anything important. The following targets are useful for this job: Clean, Dirclean, Distclean, and Clean small part.
These targets will erase your build configuration, toolchain, and all other sources, so use them with care. If you're not sure which one to use, it's always a good idea to start with the least aggressive option.
Here are the specific make-targets you can use for cleaning up:
- Clean
- Dirclean
- Distclean
- Clean small part
Packages and Repositories
To add your own package to OpenWRT, you'll need to create a custom repository. This is as simple as creating a folder and a Makefile.
Packages are the way to distribute software components within the OpenWRT ecosystem. They're essentially the building blocks of your customized firmware.
A package repository is a collection of packages that can be retrieved by the opkg package manager. You can think of it as a library of available software components.
To update the list of available packages, you'll need to run the opkg update command. This will connect to remote sites and download a list of packages that can be retrieved from those sites.
A feed is a directive that specifies where packages are stored and can be retrieved by the opkg package manager. It's essentially a URL that points to a package repository.
Here are the six pre-configured feeds found in a stock OpenWRT box:
In the SDK, feeds need to be updated using the ./scripts/feeds update -a command. This is required to know where to download packages that may be needed during building activities.
Build Environment
Building an OpenWrt image requires a stable GNU/Linux distribution. Most cases can be solved with your choice of distribution, but using testing repositories, bleeding-edge distros, or latest/unstable development packages might lead to problems with building OpenWrt's cross-toolchain and/or compiler.
To avoid these issues, consider using a Docker container with a stable image, such as Ubuntu 16.04. This will provide a consistent and reliable environment for building OpenWrt.
It's essential to work as a non-root user and issue all OpenWrt build system commands in the directory where you've cloned OpenWrt. This is crucial for maintaining a secure and stable build environment.
Here are some key points to keep in mind:
- Do everything as a non-root user.
- Issue all OpenWrt build system commands in the directory where you've cloned OpenWrt.
- Make sure to issue all OpenWrt commands in the directory where you have cloned OpenWrt, or in our case, this will be the opt/openwrt/openwrt-dd/ directory.
- Changing ownership for working directories to other than root user is also important.
Step-by-Step Instructions
Building OpenWrt can seem daunting, but it's actually quite straightforward. You'll want to start by getting the source code for Gateworks OpenWrt 24.01, which is recommended for OcteonTX based Newport boards.
To do this, use the command `git clone https://github.com/Gateworks/openwrt/ gateworks-openwrt -b 24.01` to download the code. Then, navigate to the directory with `cd gateworks-openwrt`.
If you want to save some time and bandwidth, you can create a symlink to the dl directory with `ln -s /usr/src/dl .`. This will allow you to share downloads across multiple projects.
Next, update the package feeds with `./scripts/feeds update -a` and `./scripts/feeds install -a`. This will ensure you have the latest packages available.
To start with a basic configuration, copy the example config with `cp gateworks/configs/venice/diffconfig .config`. You can then use `make defconfig` to create a default configuration.
If you want to customize your config, use `make menuconfig` to open the menu configuration tool. From there, you can select the options you want to change.
Once you've customized your config, use `make -j8 V=s` to build the image. This will use 8 threads and show verbose output.
Finally, copy the disk image to your tftpboot directory with `bin/targets/imx/cortexa53/gateworks-imx-cortexa53-gateworks_venice-squashfs-img.gz /tftpboot/openwrt-venice.img.gz`.
Frequently Asked Questions
What language is OpenWrt written in?
OpenWrt is written in C, a programming language used for its source code examples. This series will guide you through OpenWrt development with each chapter introducing a new concept.
Featured Images: pexels.com


