qqhpc / gl-inet-imagebuilder

Warning!Please look at 'GL.iNET Imagebuilder Introduction' section.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Imagebuilder

Imagebuilder for GL.iNet devices. The Imagebuilder (previously called the Image Generator) is a pre-compiled environment suitable for creating custom images without having to compile the entire OpenWRT build environment.

Note: Using the imagebuilder you can build a firmware using GL.iNet Router API and User Interface. This is free for personal use. If you use for commercial project, you need to obtain a commercial license.

Introduction

As the old imagebuilder repository gets bigger and bigger, it makes it harder to download and use. Because of this we have improved the imagebuilder code. It is smaller and faster than before, however, executing 'git pull' under the old imagebuilder will conflict, so please clone the new imagebuilder to a new directory or delete the old one. The old imagebuilder has been moved to https://github.com/gl-inet/imagebuilder_archive.

The companion https://github.com/gl-inet/glinet repository is downloaded automatically when running the gl_image program. If you encounter any issues downloading the glinet repository, you can use the '--depth=' parameter to clone it manually:

git clone --depth=1 https://github.com/gl-inet/imagebuilder gl_imagebuilder

System requirements

  • x86_64 platform
  • Ubuntu or another linux distro

Running Imagebuilder under Windows can be done using the Windows Subsystem For Linux (WSL) with Ubuntu installed to it. Follow the guide bellow, installing Ubuntu 18.04 LTS from the Microsoft Store:

https://docs.microsoft.com/en-us/windows/wsl/install-win10

Note for Windows Subsystem For Linux (WSL) users:

The Imagebuilder requires a "case sensitive" system, Windows is unfortunately not. To run the Imagebuilder in WSL you MUST clone the repo to the linux folder tree, ie: /home/<username>/ or any other folder you choose. This is required, you CAN NOT run it from /mnt/c/ or any other windows native drive mounted in WSL. Running the Imagebuilder from a Windows mounted disk will result in a failed build with cryptic messages.

Preparing your build environment

To use the Imagebuilder on your system will usually require you to install some extra packages.

For Ubuntu 18.04 LTS, run the following commands to install the required packages:

sudo apt update && sudo apt upgrade -y
sudo apt install device-tree-compiler gawk gcc git g++ make ncurses-dev python unzip -y

Usage

Compile standard firmware based on GL.iNet(For example ar750s).

  1. clone imagebuilder
$ git clone https://github.com/gl-inet/imagebuilder.git
  1. switch to imagebuilder folder
$ cd imagebuilder
  1. clone glinet (default master branch)
$ git clone https://github.com/gl-inet/glinet.git
  1. go to the glinet directory and view the history tag
$ cd glinet
$ git pull
$ git tag | grep ar750s

You will get all the version about the ar750s product, like the list bebow, please switch the version tag what you want.

v3.003_ar750s
v3.009_ar750s
v3.025_ar750s
v3.100_ar750s
v3.101_ar750s
v3.104_ar750s
v3.105_ar150/ar300M/ar300M16/mt300n-v2/ar750/ar750s/x750/mifi/b1300/s1300/ap1300/mv1000/mv1000w
v3.201_ar150/mifi/usb150/ar300M/ar300M16/mt300n-v2/n300/ar750/ar750s/x750/e750/xe300/x300b/mt1300
v3.203_ar150/mifi/ar300M/ar300M16/mt300n-v2/n300/ar750/ar750s/x750/e750/x1200/xe300/x300b/mv1000/s1300/ap1300
v3.212_ar150/mifi/ar300m/usb150/n300/ar750/ar750s/x750/xe300/mt300n-v2/mv1000/b1300/s1300/ap1300/b2200
v3.215_ap1300/ar150/ar300m/ar750/ar750s/b1300/b2200/e750/mifi/mt1300/mt300n-v2/mv1000-emmc/n300/s1300/sf1200/sft1200/usb150/x300b/x750/xe300
  1. for example, switch to the 3.215 version of the ar750s firmware tag
$ git checkout v3.215_ap1300/ar150/ar300m/ar750/ar750s/b1300/b2200/e750/mifi/mt1300/mt300n-v2/mv1000-emmc/n300/s1300/sf1200/sft1200/usb150/x300b/x750/xe300
  1. return to the imagebuilder folder
$ cd ../
  1. compile firmware
$ ./gl_image -i -p ar750s

Add additional packages

For example, make an image for the ar750s with some extra packages included:

$ ./gl_image -i -p ar750s -e "tcpdump nano"

You'll find the compiled firmware image in bin/20220526/ar750s/

For other firmwares, the compiled firmware file is in bin/xxxxxxxx/<device_name>/

Shield the upgrade address of standard firmware

The GL.iNet standard firmware will checks the latest firmware from the GL.iNet server, so you need to shield the firmware upgrade address server when compiling the firmware.

If not, when GL.iNet releases the later firmware, your device will be prompted to upgrade on the Web interface, and if you or your customer clicks the upgrade button, GL.iNet standard firmware will replace your firmware.

Close the method: add useless address or your upgrade server in the /etc/config/glconfig file, like this:

config service 'autoupdate'
        option time '04:00'
        option enable '0'
        option firmware_path 'http://www.google.com'

The uci command to add address is as follows.

uci set glconfig.autoupdate.firmware_path='http://www.google.com'
uci commit

Build a custom ipk using imagebuilder

You can go to the link https://github.com/gl-inet/sdk according to the instructions to compile helloworld.ipk. Use this package for imagebuilder test.Or use your own ipk and emulate the following steps to build the firmware.

Basic configuration

All the GL device package configuration is done with the glinet/images.json file. The following

packages: The default packages included in all firmwares
profiles: Configuration for each firmware
{
	<image_name>:
	{
	    profile: The name of the device. Run "make info" for a list of available devices.
	    version: Firmware version. Generates a version file called /etc/glversion and overrides /etc/opk/distfeeds.conf with the version number
	    imagebuilder: Image builder folder
	    packages: Packages in the firmware. Variables include the default packages. Add the package name to include. "-" appended to the package name excludes the package, eg: "-mwan3"
	    files: Files folder, it allows customized configuration files to be included in images built with Image Generator, all files from the folder will be copied into device's rootfs("/").
	}
}

Add ipk packages

1.The new download of the uncompiled imagebuilder code in the root directory did not generate /imagebuilder/3.1/openwrt-imagebuilder-ar71xx-generic_3.1 directory structure, need to use ./gl_image -p <image_name> to compile the source code once.

Then create the packages directory in the gl_imagebuilder/imagebuilder/3.1/openwrt-imagebuilder-ar71xx-generic_3.1 directory and place the customized ipk in that directory, as shown below,I put in a helloworld_1.0_mips_24kc.ipk

linux@ubuntu:~/gl_imagebuilder/imagebuilder/3.1/openwrt-imagebuilder-ar71xx-generic_3.1# ls packages/

..............
..............
**helloworld_1.0_mips_24kc.ipk**                                 Packages
libc_1.1.19-1_mips_24kc.ipk                                      Packages.gz
..............
..............

2.Modify the glinet/images.json file.

"mifi": {
		"profile": "gl-mifi",
		"version": "3.027",
		"imagebuilder": "3.1/openwrt-imagebuilder-ar71xx-generic_3.1",
		"packages": "gl-base-files-ar $basic $vpn $storage $glinet $usb -wpa-cli -kmod-rt2800-usb helloworld"
	}

Set files properties

1.If you want to compile your own /etc/init.d/gl_init files or /www folders, you need to specify the files properties.Then create the files directory in the gl_imagebuilder/imagebuilder/3.1/openwrt-imagebuilder-ar71xx-generic_3.1 directory.

The modified /etc/init.d/gl_init file, according to the folder directory structure put into the gl_imagebuilder/imagebuilder/3.1/openwrt-imagebuilder-ar71xx-generic_3.1/files directory.

The modified /www folder is also placed in the files directory. As shown below.

linux@ubuntu:~/gl_imagebuilder/imagebuilder/3.1/openwrt-imagebuilder-ar71xx-generic_3.1/files$ ls

etc  www

2.Modify the glinet/images.json file.

"mifi": {
		"profile": "gl-mifi",
		"version": "3.027",
		"imagebuilder": "3.1/openwrt-imagebuilder-ar71xx-generic_3.1",
		"packages": "gl-base-files-ar $basic $vpn $storage $glinet $usb -wpa-cli -kmod-rt2800-usb helloworld",
		"files": "imagebuilder/3.1/openwrt-imagebuilder-ar71xx-generic_3.1/files"
	}

3.Save the glinet/images.json file.

4.Compile the code with ./gl_image -p mifi

5.Completed in gl_imagebuilder/bin/mifi/openwrt-mifi-3.027-0312.bin, find the bin file and installed to the routing.

Advanced configuration

Example

We want to create a clean customized firmware for our mifi device that includes helloworld.ipk, here is an example of a user-defined configuration file. We name it myfirst.json:

linux@ubuntu:~/gl_imagebuilder# cat myfirst.json

{
	"profiles":
	{
	    "helloworld":
		{
	        "profile": "gl-mifi",
	        "version": "3.027",
	        "imagebuilder": "3.1/openwrt-imagebuilder-ar71xx-generic_3.1",
	        "packages": "luci helloworld"
	    }
	}
}

Placing the helloworld.ipk in the glinet/ar71xx folder and running ./gl_image -c myfirst.json -p helloworld will build our clean image with our helloworld.ipk included.

Docker build environment

You can also use a docker container as build environment.

Install Docker to your system, here is how to do it for Ubuntu:

sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker

After cloning the Imagebuilder to your system as in the previous section, build the Docker image by running the following:

sudo docker build --rm -t gl_imagebuilder - < Dockerfile

To list all the possible device names:

sudo docker run -v "$(pwd)":/src gl_imagebuilder -l

And to make a firmware image for the Mifi with some extra packages included:

sudo docker run -v "$(pwd)":/src gl_imagebuilder -p mifi -e openssh-sftp-server nano htop

You'll find the compiled firmware image in bin//gl-mifi/openwrt-mifi-ar71xx-generic-gl-mifi-squashfs-sysupgrade.bin

For other firmwares, the compiled firmware file is in bin//<device_name>/

About

Warning!Please look at 'GL.iNET Imagebuilder Introduction' section.


Languages

Language:Python 99.0%Language:Dockerfile 1.0%