Support for Linksys E2500 V4

i rebooted it and now the first command worked.

root@OpenWrt:/# cat /etc/config/network

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fdde:f35b:bca3::/48'

config interface 'lan'
        option type 'bridge'
        option ifname 'eth0.1'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config device 'lan_eth0_1_dev'
        option name 'eth0.1'
        option macaddr '30:23:03:fe:cb:75'

config interface 'wan'
        option ifname 'eth0.2'
        option proto 'dhcp'

config device 'wan_eth0_2_dev'
        option name 'eth0.2'
        option macaddr '30:23:03:fe:cb:76'

config interface 'wan6'
        option ifname 'eth0.2'
        option proto 'dhcpv6'

Something wrong. No switch config in network configuration. It's possibly bug in 19.07.2 release. I'll rebuild release 19.07.1 in couple of minutes for test. Ok?

sounds good to me! i'll be waiting to test it.

Version 19.07.1 here


After upgrade in serial console run firstboot command and show /etc/config/network again.

did that and this is what it says but it assigns an IP address now.

root@OpenWrt:/# show /etc/config/network
/bin/ash: show: not found

Command looks like:

cat /etc/config/network
root@OpenWrt:/# cat /etc/config/network

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fd0b:e6e8:7ca8::/48'

config interface 'lan'
        option type 'bridge'
        option ifname 'eth0.1'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config device 'lan_eth0_1_dev'
        option name 'eth0.1'
        option macaddr '30:23:03:fe:cb:75'

config interface 'wan'
        option ifname 'eth0.2'
        option proto 'dhcp'

config device 'wan_eth0_2_dev'
        option name 'eth0.2'
        option macaddr '30:23:03:fe:cb:76'

config interface 'wan6'
        option ifname 'eth0.2'
        option proto 'dhcpv6'

config switch
        option name 'switch0'
        option reset '1'
        option enable_vlan '1'

config switch_vlan
        option device 'switch0'
        option vlan '1'
        option ports '0 1 2 3 6t'

config switch_vlan
        option device 'switch0'
        option vlan '2'
        option ports '4 6t'

Ok. Now you can find all leds and buttons.
Pay attension to the correspondence of lan numbers in LUCI interface and in device. LUCI by default show physical port numbers.

Well it has 6 LED's total.
4=LAN
1=WAN
1=WPS

2 buttons total
1=Reset on the bottom
1=WPS between WAN port and power plug

As I understand lan/wan leds working? And what about wps?
I've said above than by default short hit of reset button reboot router.
Pls check both button.

WPS button reboots router, LED's appear to be working as normal except for WPS LED. reset button does nothing.

It's really long story to find gpio for button and leds. Full instruction here
https://openwrt.org/docs/techref/hardware/port.gpio
I'll correct firmware if you do this job.
But it's only cosmetic.

i will look at it now and reply back.

question. now could i flash the last BIN file to another E2500 V4 router i have over the linksys web upgrade?

also i used binwalk and such to decompress the factory firmware. i wonder if there might be hints in there to cheat at getting the GPIO ports right?

No. Linksys firmware is signed. As we see uboot check signature for tftp images too. Only by hand through serial console.

ok, i will solder header into my other router for serial port than.

Decompressed factory firmware may help but I'm not sure that it will be faster then openwrt instruction. You can see GPL sources too.

dont know if this will help but i just found this in the factory firmware in a file called check_fw.sh.

#!/bin/sh

#FW_TYPE="Stage"

#test URL
STAGE_URL="https://update1-stage.linksys.com/api/v2/fw/update"
#normal URL
PROD_URL="https://update1.linksys.com/api/v2/fw/update"
if [ "${FW_TYPE}" = "Stage" ]; then
	FW_URL="${STAGE_URL}"
else
	FW_URL="${PROD_URL}"
fi

RESP="/tmp/.resp"
FW_INFO="/tmp/.fw_info"

wan_mac="$(nvram_get 2860 wan_hwaddr)"
hw_version="$(nvram_get 2860 hw_version)"
model_number="$(nvram_get 2860 model_number)"
fw_ver="$(nvram_get 2860 fw_version)"
wan_ip="$(nvram_get 2860 wan_ipaddr)"
sn="$(nvram_get 2860 get_sn)"
params="mac_address=$wan_mac&hardware_version=$hw_version&model_number=$model_number&installed_version=$fw_ver&ip_address=$wan_ip&serial_number=$sn"

retry=3

rm $RESP -rf 
rm $FW_INFO -rf 

#cp /lib/libcrypto.so.1.0.0.lzma /lib/libcrypto.so.1.0.0.lzma-1
cp /lib/libssl.so.1.0.0.lzma /lib/libssl.so.1.0.0.lzma-1
cp /lib/libcurl.so.lzma /lib/libcurl.so.lzma-1

unlzma /lib/libcurl.so.lzma
#unlzma /lib/libcrypto.so.1.0.0.lzma
unlzma /lib/libssl.so.1.0.0.lzma
#ln -sf /lib/libcrypto.so.1.0.0 /lib/libcrypto.so
ln -sf /lib/libssl.so.1.0.0 /lib/libssl.so

while [ $retry -gt 0 ]; do
if curl -m 30 -o "$RESP" -k "$FW_URL?$params"; then
#        if curl -m 300 -o "$RESP" -k "$FW_URL"; then
                if [ -s $RESP ];then
                        echo "check f/w info OK!" >/dev/console
                        retry=0
                        local fw_info="$(cat $RESP | sed -e 's/{//g' -e 's/}//g' -e 's/"//g')"
                        echo $fw_info >$FW_INFO 
                else
                        echo "curl reponse null to check f/w info from Update Server!" >/dev/console
			retry=`awk -v a=$retry 'BEGIN{print a-1}'`
                fi
        else
                echo "fail to check f/w info from Internet Server!" >/dev/console
		retry=`awk -v a=$retry 'BEGIN{print a-1}'`
        fi
done

#rm /lib/libcrypto.so.1.0.0 -rf
rm /lib/libssl.so.1.0.0 -rf
#rm /lib/libcrypto.so -rf
rm /lib/libssl.so -rf
#mv /lib/libcrypto.so.1.0.0.lzma-1 /lib/libcrypto.so.1.0.0.lzma
mv /lib/libssl.so.1.0.0.lzma-1 /lib/libssl.so.1.0.0.lzma
mv /lib/libcurl.so.lzma-1 /lib/libcurl.so.lzma

and this was in a file called fw_upgrade.sh

#!/bin/sh

FW_URL="$(nvram_get 2860 online_fw_dl_url)"
GPG_FW_PATH="/tmp/code.bin.gpg"
FW_PATH="/tmp/code.bin"
DEFAULT_KEY="/etc_ro/pubkey"
PUB_KEY="/tmp/pub_key"

manufacturer="cybertan"
mac_address=`nvram_get 2860 WAN_MAC_ADDR`
wan_mac=`echo $mac_address | sed 's/:/-/g'`
hardware_version=`nvram_get 2860 hw_version`
model_number=`nvram_get 2860 model_name`
installed_version=`nvram_get 2860 fw_version`
serial_number=`nvram_get 2860 get_sn`

KEY_URL="https://update.linksys.com/api/v2/key?manufacturer=$manufacturer&mac_address=$wan_mac&hardware_version=$hardware_version&model_number=$model_number&installed_version=$installed_version&serial_number=$serial_number"

kill_process()
{
	killall miniupnpd
	killall tftpd
	killall cron
#	killall cesmDNS
#	killall dnsmasq
	killall dhcpd
	rm /lib/libzebra-0.9.28.so
	rm /lib/libdhcp.so
	unlzma /lib/libcurl.so.lzma
#	unlzma /lib/libcrypto.so.1.0.0.lzma
	unlzma /lib/libssl.so.1.0.0.lzma
#	ln -sf /lib/libcrypto.so.1.0.0 /lib/libcrypto.so
	ln -sf /lib/libssl.so.1.0.0 /lib/libssl.so

	echo 3 > /proc/sys/vm/drop_caches
}

check_mem()
{
	mem=`expr $1 \* 1024`
	free_mem=`free | awk '/Mem/ {print $4}'`
	echo "free:$free_mem------need mem:$mem"
	if [ $free_mem -ge $mem ]; then
		return 0
	fi
	return 1
}

handle_cbt_download_fw()
{
	retry=3
	kill_process
	check_mem 10
	ret=$?
	if [ $ret -eq 0 ];then
		while [ $retry -gt 0 ]; do
			if curl -m 120 -o "$GPG_FW_PATH" -k "$FW_URL"; then
				if [ -s $GPG_FW_PATH ];then
					echo "Download f/w OK!" >/dev/console
					return 0	
				else
					echo "download f/w fail from Internet Server!" >/dev/console
					retry=`awk -v a=$retry 'BEGIN{print a-1}'`
					rm $FW_PATH
				fi
			else
				echo "fail to download f/w from Internet Server!" >/dev/console
				retry=`awk -v a=$retry 'BEGIN{print a-1}'`
				rm $GPG_FW_PATH
			fi
		done
	fi
	return 1
}

backup_to_local()
{
	unlzma /bin/openssl.lzma
	cbtinfo w pubkey $PUB_KEY
	return 0
}

load_local_key()
{
	cbtinfo r pubkey
	return 0
}

check_key()
{
	sta=`cat $PUB_KEY | sed -n 1p | cut -d '"' -f 4`
	content=`cat $PUB_KEY | sed '1d' | sed '$d'`
	end=`cat $PUB_KEY | sed -n '$p' | cut -d '"' -f 1`
	echo "$sta" > $PUB_KEY
	echo "$content" >> $PUB_KEY
	echo "$end" >> $PUB_KEY
}

handle_cbt_download_pubkey()
{
	retry=3
	while [ $retry -gt 0 ]; do
#if wget -O "$PUB_KEY" "$KEY_URL"; then
		if curl -m 300 -o "$PUB_KEY" -k "$KEY_URL"; then
			if [ -s $PUB_KEY ];then
				echo "Download key OK!" >/dev/console
				check_key
				backup_to_local
				return 0	
			else
				echo "download f/w fail from Internet Server!" >/dev/console
				retry=`awk -v a=$retry 'BEGIN{print a-1}'`
				rm $PUB_KEY
			fi
		else
			echo "fail to download f/w from Internet Server!" >/dev/console
			retry=`awk -v a=$retry 'BEGIN{print a-1}'`
			rm $PUB_KEY
		fi
	done
	load_local_key
	ret=$?
	if [ $ret -eq 0 ];then
		return 0
	else
		return 1
	fi
}

verify_sign_fw()
{
	unlzma /usr/sbin/gpg.lzma
	free_mem.sh
	check_mem 10
	ret=$?
	if [ $ret -eq 0 ];then
		echo "key file:$PUB_KEY"
		if gpg --import "$PUB_KEY"; then
			if gpg --verify "$GPG_FW_PATH"; then
				if gpg -vv "$GPG_FW_PATH"; then
					return 0
				else
					echo "gpg -vv fail"
					return -1
				fi
			fi
		fi
	fi
	return 1
}

handle_cbt_code_pattern()
{
	[ -z "$1" ] && exit 0
	if [ $(hexdump -n 4 -e '4 "%c"' $1) != "$(nvram_get 2860 code_pt)" ]; then
		echo "code pattern is wrong!" > /dev/console
		return 1
        fi

	return 0	
}

mtd_write_fw()
{
	handle_cbt_code_pattern $FW_PATH
	ret=$?
	if [ $ret -eq 0 ];then
		size=`ls -l $FW_PATH | awk '{print $5}'`
		#ignore 32 bytes code header
		mtd_write -o 32 -l $size write $FW_PATH Kernel
		ret=$?
		if [ $ret -eq 0 ];then
			echo "1" > /tmp/.fw_up_result
			nvram_set 2860 wz_fw_up_result 1
			nvram_commit 2860
			return 0
		fi
	fi
}

handle_cbt_download_fw
ret=$?
if [ $ret -eq 0 ];then
	handle_cbt_download_pubkey
	ret=$?
	if [ $ret -eq 0 ];then
		verify_sign_fw
		ret=$?
		if [ $ret -eq 0 ];then
			mtd_write_fw
			return 0
		elif [ $ret -eq 1 ];then
			echo "user default key"
			PUB_KEY=$DEFAULT_KEY
			verify_sign_fw
			ret=$?
			if [ $ret -eq 0 ];then
				mtd_write_fw
				return 0
			fi
		fi
	fi
fi
echo "0" >/tmp/.fw_up_result
nvram_set 2860 wz_fw_up_result 0
nvram_commit 2860