Skip to content

How to add a new package

Acris Liu edited this page Mar 28, 2019 · 25 revisions

For the case where Entware doesn't have the package on board that you wish to use, and your freely asked request for a new package gets declined, you have the option to create an Entware package yourself.

Prerequisites

Meet OpenWrt dependencies

First setup an environment that meets OpenWrt buildroot dependencies as can be read in OpenWrt build system installation. This is because Entware is a modified OpenWrt environment.

Setup Entware

Then setup Entware by cloning its repository:

$ git clone https://github.com/Entware/Entware.git
$ cd Entware

Setup the configuration for the target device

By copying a ready-made file name .config from folder configs. In this example the target is an Asus RT-N56U. The RT-N56U contains as processor a Ralink RT3883/RT3662 SoC (# cat /proc/cpuinfo | grep system\ type). SoC means System on Chip. That Ralink is a cpu of model MIPS 74Kc (# cat /proc/cpuinfo | grep cpu\ model). Such a MIPS 74Kc processor requires the bytes to be in little endian (el) order, and doesn't contain a floating point unit (FPU), that is why floating point operations need to be done in software (sf). This all means you can use a ready made configuration file that is located in the configs folder with the name mipselsf:

$ cp configs/mipsel-3.4.config .config

Prepare build environement

The full execution op OpenWRT Buildroot environment a.k.a. rebuild repo a.k.a. make in folder ./Entware is not necessary. You only need:

$ make tools/install
$ make toolchain/install
$ make target/compile

Note: I'm not sure whether this target/compile step is necessary, its in the OpenWrt build one package from scratch instructions.

Compile test package

Now you should be ready to compile an individual package. For starters you can test make package/.../compile using a tiny package that hasn't got dependencies, for example usbreset:

$ make package/usbreset/compile

When everything succeeds your package ends up in a subfolder of the Entware "bin" folder. For this mipselsf based example, you should find the .ipk file at bin/mipselsf-uClibc/packages:

$ ls bin/mipselsf-uClibc/packages | grep usbreset
usbreset_4_mipselsf.ipk

When you see the ..._mipselsf.ipk output, your first package is successfully build. Now it's time to ...

Create your own package

Create Makefile

For starters read OpenWrt creating a package and as a reference there is OpenWrt creating packages. Hint: use one of the Makefiles that is already in the Entware or OpenWrt repository, and modify that file to your needs.

Enable package in the build configuration

Next step, is that you also instruct your configuration (.config file) to Make the desired package.

Forgot to enable your package?

Without adapting your configuration file, the command make package/xxxxx/compile after a few seconds will enter your package folder:

 make[1] package/my_package_name/compile
 make[2] -C package/libs/toolchain compile
 make[2] -C package/SECTION/subfolder/my_package_name compile

And immediately (not build the package at all) return to your command prompt.

Or in the more verbose make package/xxxxx/compile V=s output this "mistake" will look like:

make[1]: Entering directory `/Volumes/Case-sensitive/Entware'
make[2]: Entering directory `/Volumes/Case-sensitive/Entware/package/libs/toolchain'
make[2]: Leaving directory `/Volumes/Case-sensitive/Entware/package/libs/toolchain'
make[2]: Entering directory `/Volumes/Case-sensitive/Entware/package/SECTION/subfolder/my_package_name'
make[2]: Leaving directory `/Volumes/Case-sensitive/Entware/package/SECTION/subfolder/my_package_name'
make[1]: Leaving directory `/Volumes/Case-sensitive/Entware'

Enable your package in .config

A command line interactive tool that lists the new options is $ make oldconfig. This will list all .config options and ask a question for each newly added package. Choose [m] for each package you might wish to build. In case there are no new options to configure, the output will be # configuration written to .config.

There also is a graphical (ncurses based) tool to enable your package: $ make menuconfig. Make sure your package is present in packages list and selected [*] or [M].

In case you prefer a non interactive command line, there is a third option. You can use this stream editor command to search for the "not set" text string and replace it with the string that will enable the make of your package:

$ sed -ir 's/# CONFIG_PACKAGE_my_package_name is not set/CONFIG_PACKAGE_my_package_name=m/' .config

A step-by-step example for the package ucspi-tcp. This shows the configuration file before, the command to run the search-and-replace enable package operation, and the .config file after the change so you can verify that this change is actually made:

$ cat .config | grep ucspi-tcp
# CONFIG_PACKAGE_ucspi-tcp is not set
$ sed -ir 's/# CONFIG_PACKAGE_ucspi-tcp is not set/CONFIG_PACKAGE_ucspi-tcp=m/' .config
$ cat .config | grep ucspi-tcp
CONFIG_PACKAGE_ucspi-tcp=m

Create startup script (optional)

You might want to start your package automatically when the router starts. For this purpose the router does execute scripts located in the folder '/opt/etc/init.d/'.

Entware init system

Here is a point where Entware and its predecessor Entware are different from OpenWrt. OpenWrt as well as Entware both use an 'init.d' folder (where init is short for initialization) containing scripts. Though the OpenWrt init scripts are not compatible with Entware. OpenWrt uses "rc.common" where on the contrary Entware uses "rc.func" as a wrapper to provide its main and default functionality. "Rc.func" does not check the script prior to execution as is done by OpenWrt's rc.common. Entware also uses "rc.unslung" as the helper script to start and stop all /opt/etc/init.d/ scripts. To be more precise, rc.unslung will process all executable files that start with a capital S and will do that in sorted order. Except for stopping, restarting and killing, then the executable S* init script files will be processed in reverse sorted order.

rc.func

Learn yourself bash scripting and have a look inside rc.func to understand its functionality. By this rc.func template, the available commands for any init script are as follows:

start         Start the service
stop          Stop the service
restart       Restart the service
check         Check the service (dead or alive)
kill          Kill the service
reconfigure   Reload configuration files (sends SIGHUP signal)

All these arguments can be passed to the script when run. For example, to restart the service call it with restart:

# /opt/etc/init.d/my_init_script restart

Entware init script

An example Entware init script, S15upsd init from the nut package, looks like this:

#!/bin/sh

ENABLED=yes
PROCS=upsd
ARGS="-u admin"
PREARGS=""
DESC=$PROCS
PATH=/opt/sbin:/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

. /opt/etc/init.d/rc.func

Porting an OpenWrt init script

Entware hasn't got functionality like OpenWrt to enable/disable init scripts. You need to name your init script starting with the capital letter S. Next name the file with a number. If you haven't got a clue which number to choose, look for the section START= in the OpenWrt init file. Neither is there a Unified Configuration Interface: OpenWrt UCI. Look for strings like /lib/functions/, those needs rework because they don't exist in Entware' world.

Clone this wiki locally