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/19.07.3/targets/brcm63xx/generic/openwrt-imagebuilder-19.07.3-brcm63xx-generic.Linux-x86_64.tar.xz
tar xvf ~/Downloads/openwrt-imagebuilder-19.07.3-brcm63xx-generic.Linux-x86_64.tar.xz
cd openwrt-imagebuilder-19.07.3-brcm63xx-generic.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="nano pciutils diffutils iw-full iwinfo wpad"
mypkgs+=" cgi-io kmod-lib-crc-ccitt kmod-lib-cordic kmod-slhc"
mypkgs+=" libiwinfo libjson-c2"
mypkgs+=" kmod-b43"
mypkgs+=" libiwinfo-lua liblua5.1.5"
mypkgs+=" liblucihttp-lua liblucihttp0 libubus-lua lua luci"
mypkgs+=" luci-app-firewall luci-app-opkg luci-base luci-lib-ip"
mypkgs+=" luci-lib-jsonc luci-lib-nixio luci-mod-admin-full"
mypkgs+=" luci-mod-network luci-mod-status luci-mod-system"
mypkgs+=" luci-proto-ipv6 luci-proto-ppp luci-theme-bootstrap"
mypkgs+=" rpcd rpcd-mod-file rpcd-mod-iwinfo rpcd-mod-luci"
mypkgs+=" rpcd-mod-rrdns uhttpd"
mypkgs+=" -wpad-basic"
mypkgs+=" -kmod-ppp -kmod-pppoe -kmod-pppox -ppp -ppp-mod-pppoe"
mydsrvs="dnsmasq firewall odhcpd"
To save some more flash ROM space you may want to remove any unused packages, for example:
mypkgs+=" -dnsmasq -odhcpd -odhcpd-ipv6only"
Finally, make the images:
make clean
make image PROFILE="A4001N" PACKAGES="$mypkgs" DISABLED_SERVICES="$mydsrvs" FILES=files/
make image PROFILE="A4001N1" 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/hwdata/technicolor/technicolor_tg582n
https://openwrt.org/toh/hwdata/technicolor/technicolor_tg582n_dant-t
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