Prerequisites
System Requirements
- Linux distribution (Ubuntu 20.04+ recommended) or WSL2 on Windows
- At least 4GB RAM (8GB+ recommended)
- 20GB+ free disk space
- Internet connection
Required Packages (Ubuntu/Debian)
sudo apt update
sudo apt install build-essential ccache ecj fastjar file g++ gawk \
gettext git java-propose-classpath libelf-dev libncurses5-dev \
libncursesw5-dev libssl-dev python3 python3-distutils python3-setuptools \
python3-dev rsync subversion swig time unzip wget xsltproc zlib1g-dev
Step 1: Clone OpenWrt Source Code
# Clone the latest stable release (24.10.x)
git clone https://github.com/openwrt/openwrt.git
cd openwrt
# Or clone specific version
git clone -b v24.10.2 https://github.com/openwrt/openwrt.git
cd openwrt
Step 2: Update Feeds
# Update package feeds
./scripts/feeds update -a
# Install all available packages
./scripts/feeds install -a
Step 3: Configure Build
# Start configuration menu
make menuconfig
Essential Configuration Options:
Target System Selection:
- Target System: Select your target (e.g., Qualcomm Atheros IPQ40xx, MediaTek MT7621, etc.)
- Subtarget: Choose specific variant(e.g., generic)
- Target Profile: Select your device model
Basic Settings:
- Target Images: Enable “squashfs” and “ext4” if needed
- Kernel modules: Select required modules
- LuCI: Web interface (optional)
- Network: Basic networking packages
Common Device Examples:
- OpenWrt One: Target System → MediaTek ARM → Filogic 8×0 (MT798x) → OpenWrt One
- TP-Link Archer C7: Target System → Atheros ATH79 → Generic → TP-Link Archer C7
- Raspberry Pi: Target System → Broadcom BCM27xx → Raspberry Pi 4
Step 4: Build Configuration
Option 1: Use Default Configuration
# For specific device (example: TP-Link Archer C7)
make defconfig
Option 2: Use Pre-configured Profile
# List available profiles
make menuconfig
# Or use specific profile
make profile
Step 5: Start Compilation
First Time Build (Download Sources)
# Download all sources (this may take a while)
make download
# Start compilation
make -j$(nproc) V=s
Subsequent Builds
# Clean previous build
make clean
# Or clean everything
make dirclean
# Rebuild
make -j$(nproc) V=s
Step 6: Monitor Build Process
Build Output Location:
- Firmware files:
bin/targets/[target]/[subtarget]/
Common Build Issues:
- Download failures: Run
make download
again - Memory issues: Reduce parallel jobs:
make -j2 V=s
- Disk space: Ensure 10GB+ free space
Step 7: Locate Firmware Files
After successful compilation, firmware files will be in:
# Navigate to firmware directory
cd bin/targets/[target]/[subtarget]/
# List available firmware files
ls -la *.bin *.img *.tar
Common Firmware File Types:
openwrt-[target]-[subtarget]-[device]-squashfs-factory.bin
– Factory firmwareopenwrt-[target]-[subtarget]-[device]-squashfs-sysupgrade.bin
– Upgrade firmwareopenwrt-[target]-[subtarget]-[device]-ext4-factory.img.gz
– Ext4 factory imageopenwrt-[target]-[subtarget]-[device]-ext4-sysupgrade.img.gz
– Ext4 upgrade image
Step 8: Flash Firmware
Via Web Interface (if upgrading existing OpenWrt):
- Access router’s web interface (usually 192.168.1.1)
- Go to System → Backup/Flash Firmware
- Upload the
*-sysupgrade.bin
file - Click “Flash image”
Build Optimization Tips
Speed Up Builds:
# Use ccache for faster recompilation
export USE_CCACHE=1
export CCACHE_DIR=~/.ccache
# Use multiple CPU cores
make -j$(nproc) V=s
# Skip download step if sources exist
make -j$(nproc) V=s
Reduce Build Size:
# In menuconfig, disable unnecessary packages
# Remove LuCI if not needed
# Disable unused kernel modules
# Use squashfs instead of ext4 for smaller images
Troubleshooting
Common Errors:
- “No rule to make target”: Run
make defconfig
first - Download failures: Check internet connection and run
make download
- Build failures: Check system requirements and dependencies
- Memory errors: Reduce parallel jobs or increase swap space
Debug Build:
# Verbose output for debugging
make V=99
# Check specific package build
make package/[package-name]/compile V=s