Introduction Script Hardenading Linksys WRT 1900ACSV1
OpenWrt Build Script for Linksys WRT1900AC
A Bash script to automate the OpenWrt build process for Linksys WRT1900ACS v1 and v2.
The script supports two modes:
- First build: Clone OpenWrt, update and install feeds, apply patches, optionally copy a custom
.config, and build the firmware. - Update build: Clean an existing OpenWrt build tree, update the source code, reapply patches, restore the selected configuration, and rebuild the firmware.
The script remembers the configured paths in ~/.openwrt-build.conf, so you do not need to enter them every time.
⚠️ Supported Devices
This build script is intended exclusively for the following devices:
- Linksys WRT1900ACS v1
- Linksys WRT1900ACS v2
Other router models are not supported by this build configuration. Do not assume that firmware generated by this script is compatible with other devices.
Always verify the selected target, subtarget, and device profile in the OpenWrt configuration before building or flashing firmware.
Features
- Automated OpenWrt source checkout.
- Automatic feed updates and installation.
- Support for two patch directories:
- New patches: Patches from the Divested-WRT project.
- Extra patches: Additional patches for the target router.
- Optional import of an existing
.configfile. - Interactive configuration through
make nconfig. - Configurable download and compilation parallelism.
- Automatic saving of user-supplied paths.
- Update mode with confirmation before resetting the source tree.
- Patch application using
git am --3way.
Requirements
Run the script in a Linux environment with Bash and the tools required to build OpenWrt.
Required tools include:
- Git
- GNU Make
- GCC and the standard build toolchain
- Required OpenWrt build dependencies
readlinknproc- Bash
Install the dependencies recommended by the official OpenWrt build instructions for your Linux distribution.
Official documentation:
https://openwrt.org/docs/guide-developer/toolchain/install-buildsystem
You also need:
- A working internet connection.
- Sufficient disk space for the OpenWrt source tree, downloaded packages, and build artifacts.
- Sufficient RAM and CPU resources for the selected build parallelism.
- The Divested-WRT patch directory.
Directory Structure
The script expects you to provide the paths to your OpenWrt source directory, new patches, optional extra patches, and optional configuration file.
For example:
~/openwrt/
├── .config
├── package/
├── target/
├── scripts/
└── bin/
└── targets/
/path/to/Divested-WRT/
└── patches/
├── 001-example.patch
└── 002-example.patch
/path/to/router-patches/
├── 001-router-fix.patch
/path/to/config/
└── .config
The directory names above are examples. Use the actual paths on your system.
Usage
Make the script executable:
chmod +x build-openwrt.sh
1. First Build
Run:
./build-openwrt.sh first
The script asks for four paths:
| Prompt | Description |
|---|---|
| OpenWrt directory | Directory where the OpenWrt repository will be cloned. |
| New patches folder | Directory containing the Divested-WRT patches. |
| Extra patches folder | Optional directory containing additional router-specific patches. |
.config file | Optional existing OpenWrt build configuration. |
Press Enter to reuse a previously saved path.
To leave the extra patches directory or configuration file empty, press Enter when no previous value is configured.
The script then performs the following steps:
- Clone the OpenWrt repository.
- Configure Git settings.
- Update all package feeds.
- Install all package feeds.
- Apply the new patches.
- Apply the extra patches, if configured.
- Copy the supplied
.config, if configured. - Launch
make nconfig. - Download required source archives.
- Compile OpenWrt.
2. Update an Existing Build
Run:
./build-openwrt.sh update
The update process operates on an existing OpenWrt Git repository.
Before proceeding, the script displays a confirmation warning.
The update process performs these operations:
- Run
make clean. - Run
make dirclean. - Abort any unfinished Git patch application.
- Fetch updates from the upstream Git repository.
- Reset the source tree to the configured upstream tracking revision.
- Update and install feeds.
- Reapply the patches from the configured directories.
- Copy the supplied
.config, if configured. - Launch
make nconfig. - Download required source archives.
- Compile OpenWrt.
Important: Update mode resets the source tree and removes existing build artifacts. Local commits above the selected upstream revision will be discarded by the reset.
The script assumes that local changes are represented by the patches in your configured patch directories. Commit or back up any other changes before proceeding.
To skip the confirmation prompt:
./build-openwrt.sh update -y
Use -y only when you understand the consequences of resetting the existing source tree.
3. Interactive Menu
You can also run the script without specifying a mode:
./build-openwrt.sh
The script displays a menu:
What do you want to do?
1) First time (clone + build)
2) Update (existing tree)
Choose 1 or 2:
Select the appropriate operation.
Configuration
Saved Paths
The script stores the configured paths in:
~/.openwrt-build.conf
For example:
OWRT_DIR="/home/user/openwrt"
NEW_PATCHES="/home/user/Divested-WRT/patches"
EXTRA_PATCHES="/home/user/router-patches"
CONFIG_FILE="/home/user/openwrt-config/.config"
On subsequent runs, the script uses these saved values as defaults.
You can change the paths by running the script again and entering new values.
Note: The saved configuration file is sourced as a Bash script. Only use a configuration file that you trust.
Build Parallelism
The script supports two environment variables.
Download Jobs
Set the number of parallel jobs used by make download:
DL_JOBS=4 ./build-openwrt.sh first
Default:
DL_JOBS=4
Build Jobs
Set the number of parallel jobs used for compilation:
./build-openwrt.sh first
By default, the script uses the number of CPU cores reported by nproc.
You can combine both variables:
./build-openwrt.sh first
For an update:
./build-openwrt.sh update
These values affect parallelism, not the router’s hardware capabilities or the firmware target.
OpenWrt Repository
By default, the script clones the official OpenWrt Git repository:
https://git.openwrt.org/openwrt/openwrt.git
You can override the repository URL using REPO_URL:
REPO_URL="https://git.openwrt.org/openwrt/openwrt.git" \
./build-openwrt.sh first
Choose a repository and revision compatible with your patches.
Patch Management
The script applies patches from two directories in this order:
- New patches.
- Extra patches.
All files matching *.patch are processed in shell glob order, which is normally alphabetical.
Example:
patches/
├── 001-kernel-fix.patch
├── 002-network-fix.patch
└── 003-driver-update.patch
Use numbered filenames to control the application order.
Patches are applied with:
git am --3way patch-name.patch
This creates Git commits from the patch files.
Handling Patch Conflicts
If a patch fails, the script stops and prints instructions.
First, inspect the problem:
git status
Resolve the conflicts in the affected files, then stage the resolved files:
git add <resolved-file>
Continue applying the patch:
git am --continue
Alternatively, skip the problematic patch:
git am --skip
Or cancel the patch application:
git am --abort
Important: If you resolve a conflict manually, do not blindly rerun update mode. Update mode resets the source tree and reapplies the patch series, so your manual changes may be lost.
OpenWrt Configuration
Before building, make nconfig opens the interactive configuration interface.
Verify that the selected configuration targets the intended device:
- Target system and architecture.
- Subtarget.
- Device profile for Linksys WRT1900ACS v1 or v2.
- Required packages and kernel options.
Save the configuration and exit to continue the build.
If an external .config file is supplied, the script copies it into the OpenWrt source tree before launching make nconfig.
If no configuration file is supplied, the script relies on the configuration already present in the source tree or on the defaults provided by OpenWrt. Make sure the correct device profile is selected before compiling.
Build Output
After a successful build, the script reports the output directory:
<OpenWrt directory>/bin/targets/
Firmware images are normally stored in a target- and subtarget-specific directory beneath this location.
Check the generated image filenames and metadata to confirm that the firmware matches the intended WRT1900ACS hardware revision.
Do not flash an image solely because the build completed successfully.
Important Notes
- This script is intended for Linksys WRT1900ACS v1 and v2 only.
- The script does not independently guarantee that the selected
.configmatches the target device. - Patches may need modifications when the upstream OpenWrt source changes.
- The update operation resets the source tree and cleans existing build artifacts.
- Keep backups of custom configurations and patches.
- Confirm the generated firmware’s device compatibility before flashing.
- Interruptions, missing dependencies, patch conflicts, or download failures can cause the build to stop.
Troubleshooting
Patch application fails
Check the Git status and resolve or abort the current git am operation before continuing.
The configuration targets the wrong device
Run:
make nconfig
Select the correct target, subtarget, and device profile.
The build runs out of memory
Reduce the number of compilation jobs:
BUILD_JOBS=2 ./build-openwrt.sh first
For an existing tree, use update only if you intend to perform the full reset and rebuild.
Downloads fail
Check your internet connection and retry the download step:
make download -j4
Run this command from the OpenWrt source directory.
The source tree is not recognized
Update mode requires an existing OpenWrt Git repository:
git -C /path/to/openwrt status
If the directory is not an OpenWrt Git checkout, use first-build mode with a suitable empty directory.
License
Specify the license applicable to this script and its associated patches before redistributing the project.
OpenWrt and Divested-WRT components may have their own licensing requirements. Consult the corresponding project documentation for details.