Fortunately it is straightforward to create a new OpenWrt firmware image – just follow the steps below.
Install build tools:
sudo apt-get install build-essential libncurses5-dev libncursesw5-dev zlib1g-dev gawk git gettext libssl-dev xsltproc wget unzip python
Download and unpack the OpenWrt ImageBuilder package:
wget https://downloads.openwrt.org/releases/18.06.8/targets/ar71xx/tiny/openwrt-imagebuilder-18.06.8-ar71xx-tiny.Linux-x86_64.tar.xz
tar xvf openwrt-imagebuilder-18.06.8-ar71xx-tiny.Linux-x86_64.tar.xz
cd openwrt-imagebuilder-18.06.8-ar71xx-tiny.Linux-x86_64/
If you already have config files on an other system and want to include them in the new image:
make image FILES=files/
mkdir -p files/etc/config
scp root@192.168.1.1:/etc/config/network files/etc/config/
scp root@192.168.1.1:/etc/config/wireless files/etc/config/
scp root@192.168.1.1:/etc/config/firewall files/etc/config/
Specify what packages to include in or exclude from the new image, and what services not to start:
mypkgs="lua luci-base luci-lib-ip luci-lib-jsonc luci-lib-nixio"
mypkgs+=" luci-mod-admin-full luci-proto-ipv6 luci-theme-bootstrap"
mypkgs+=" uhttpd rpcd-mod-rrdns libiwinfo libiwinfo-lua kmod-slhc"
mypkgs+=" kmod-nf-nat kmod-nf-conntrack kmod-nf-conntrack6"
mypkgs+=" kmod-ipt-nat kmod-lib-crc-ccitt kmod-ipt-conntrack"
mypkgs+=" wpad"
mypkgs+=" -wpad-mini -firewall -odhcpd-ipv6only -dnsmasq"
mypkgs+=" -ppp -ppp-mod-pppoe -kmod-ppp -kmod-pppoe -kmod-pppox"
mydsrvs="dnsmasq firewall odhcpd"
Finally, make the images:
make clean
make image PROFILE="tl-wa901nd-v2" PACKAGES="$mypkgs" DISABLED_SERVICES="$mydsrvs" FILES=files/
… and the result:
To see what other targets are available and for general help:
make info
make help
Additional information on-line:
https://openwrt.org/toh/tp-link/tl-wa901nd
https://openwrt.org/docs/guide-user/additional-software/imagebuilder
https://openwrt.org/faq/which_packages_can_i_safely_remove_to_save_space
https://openwrt.org/docs/techref/image.format
https://openwrt.org/docs/techref/flash.layout