BOBOBK

Compiling Custom LEDE Firmware for K2 Router Using GitHub Actions

TECHNOLOGY

I’ve been using LEDE OpenWRT firmware as my router’s firmware. Due to version updates, some software is no longer available in older LEDE versions, so I decided to compile a custom firmware that includes only the software I need for the Phicomm K2 router. Fortunately, GitHub Actions allows free users to use GitHub’s cloud servers for code compilation. Here’s a record of the process of compiling K2 router firmware using GitHub Actions.

  1. Fork the LEDE code repository
  2. Modify the GitHub Actions build file
  3. Compile and download the LEDE firmware
  4. Add Trojan support

Fork the LEDE Repository

No need to explain GitHub basics. The two repositories you’ll need are:

  • The LEDE source code from coolsnowwolf/lede. Fork it to your own GitHub account.

  • The OpenWrt-CI by KFERMercer, which has GitHub Actions config ready. You can directly copy the sample Actions code.

Modify GitHub Actions Build File

Once you fork the LEDE repo, go into your fork and open the actions tab.

Enable Actions:

After enabling, you can edit the workflow file under: lede/.github/workflows/openwrt-ci.yml.

Copy the contents from this example config file and paste it into your openwrt-ci.yml.

Make sure to change the branch to master before saving.

Click commit to confirm the changes.

If you didn’t switch to the correct branch or your indentation is incorrect, it will fail:

Compile and Download the LEDE Firmware

Once the YAML file is correctly saved, GitHub Actions will automatically start compiling. Click on Actions to view progress:

Click into the running build to monitor progress:

Compilation takes time—just leave it running and come back after a few hours to download the firmware:

Extract the downloaded firmware to check the contents.

Add Trojan Software Support

I wanted to integrate Trojan into the router firmware, so I needed to configure the .config file locally using make menuconfig. Then I searched for relevant Trojan settings to include in the YAML config.

Below is the key part to add Trojan support in openwrt-ci.yml:

          CONFIG_TARGET_ramips=y
          CONFIG_TARGET_ramips_mt7620=y
          CONFIG_TARGET_ramips_mt7620_DEVICE_phicomm_psg1208=y

          CONFIG_PACKAGE_luci-app-ssr-plus=y
          CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_V2ray_plugin=y
          CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_V2ray=y
          CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Trojan=y

          CONFIG_PACKAGE_trojan=y

Replace the appropriate section of the YAML with this snippet. However, the resulting firmware will not include sysupgrade, so you can’t upgrade firmware directly on the router.

To upgrade from the router UI, I generated a .config locally using:

make menuconfig

Then replaced the YAML build configuration accordingly.

You can click here to download my .config file directly. Here’s what the compiled firmware package looks like:

The firmware is in .bin format.

IPK packages are in the package folder, and you can upload them to the router to install additional software.

Finally, here’s a compressed archive of my K2P firmware, which includes Trojan and removes unnecessary software like FTP.

Download Firmware Package

Reference:

Beginner’s Guide: Automatically Compile LEDE with GitHub Actions

Related