Initial commit
Some checks failed
Build Kernel / Build all affected Kernels (push) Has been cancelled
Build all core packages / Build all core packages for selected target (push) Has been cancelled
Build and Push prebuilt tools container / Build and Push all prebuilt containers (push) Has been cancelled
Build Toolchains / Build Toolchains for each target (push) Has been cancelled
Build host tools / Build host tools for linux and macos based systems (push) Has been cancelled
Coverity scan build / Coverity x86/64 build (push) Has been cancelled

This commit is contained in:
domenico
2025-06-24 14:35:53 +02:00
commit c06fb25d1f
9263 changed files with 1750214 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
. /lib/functions/uci-defaults.sh
board_config_update
board=$(board_name)
case "$board" in
arcadyan,aw1000)
ucidef_set_led_netdev "5g" "5G" "green:5g" "wwan0"
ucidef_set_led_netdev "wan" "WAN" "green:internet" "wan"
ucidef_set_led_netdev "wan-port-link" "WAN-PORT-LINK" "90000.mdio-1:1c:green:wan" "wan" "tx rx link_10 link_100 link_1000 link_2500"
;;
asus,rt-ax89x)
ucidef_set_led_netdev "aqr" "AQR" "white:aqr10g" "10g-copper"
ucidef_set_led_netdev "sfp" "SFP" "white:sfp" "10g-sfp"
ucidef_set_led_netdev "wan" "WAN" "white:wan" "wan"
;;
dynalink,dl-wrx36)
ucidef_set_led_netdev "wan-port-link-green" "WAN-PORT-LINK-GREEN" "90000.mdio-1:1c:green:wan" "wan" "link_2500"
ucidef_set_led_netdev "wan-port-link-yellow" "WAN-PORT-LINK-YELLOW" "90000.mdio-1:1c:yellow:wan" "wan" "tx rx link_10 link_100 link_1000"
;;
edgecore,eap102)
ucidef_set_led_netdev "wan" "WAN" "green:wanpoe" "wan"
;;
netgear,rax120v2)
ucidef_set_led_netdev "aqr" "AQR" "white:aqr" "lan5"
;;
netgear,wax218)
ucidef_set_led_netdev "lan" "LAN" "blue:lan" "lan"
ucidef_set_led_wlan "wlan5g" "WIFI 5GHz" "blue:wlan5g" "phy0radio"
ucidef_set_led_wlan "wlan2g" "WIFI 2.4GHz" "blue:wlan2g" "phy1radio"
;;
netgear,wax620)
ucidef_set_led_netdev "lan" "LAN" "lan:green" "lan"
;;
netgear,wax630)
ucidef_set_led_netdev "lan1" "LAN1" "lan1:green" "lan1"
ucidef_set_led_netdev "lan2" "LAN2" "lan2:green" "lan2"
;;
redmi,ax6)
ucidef_set_led_netdev "wan" "WAN" "blue:network" "wan"
;;
xiaomi,ax3600)
ucidef_set_led_netdev "wan-port-link" "WAN-PORT-LINK" "90000.mdio-1:01:green:wan" "wan" "tx rx link_10 link_100 link_1000"
ucidef_set_led_netdev "lan1-port-link" "LAN1-PORT-LINK" "90000.mdio-1:02:green:lan" "lan1" "tx rx link_10 link_100 link_1000"
ucidef_set_led_netdev "lan2-port-link" "LAN2-PORT-LINK" "90000.mdio-1:03:green:lan" "lan2" "tx rx link_10 link_100 link_1000"
ucidef_set_led_netdev "lan3-port-link" "LAN3-PORT-LINK" "90000.mdio-1:04:green:lan" "lan3" "tx rx link_10 link_100 link_1000"
ucidef_set_led_netdev "wan" "WAN" "blue:network" "wan"
;;
xiaomi,ax9000)
ucidef_set_led_netdev "wan-port-link" "WAN-PORT-LINK" "90000.mdio-1:18:green:wan" "wan" "tx rx link_10 link_100 link_1000 link_2500"
ucidef_set_led_netdev "lan1-port-link" "LAN1-PORT-LINK" "90000.mdio-1:03:green:lan" "lan1" "tx rx link_10 link_100 link_1000"
ucidef_set_led_netdev "lan2-port-link" "LAN2-PORT-LINK" "90000.mdio-1:02:green:lan" "lan2" "tx rx link_10 link_100 link_1000"
ucidef_set_led_netdev "lan3-port-link" "LAN3-PORT-LINK" "90000.mdio-1:01:green:lan" "lan3" "tx rx link_10 link_100 link_1000"
ucidef_set_led_netdev "lan4-port-link" "LAN4-PORT-LINK" "90000.mdio-1:00:green:lan" "lan4" "tx rx link_10 link_100 link_1000"
;;
qnap,301w)
ucidef_set_led_netdev "lan1" "LAN1" "green:lan-1" "lan1"
ucidef_set_led_netdev "lan2" "LAN2" "green:lan-2" "lan2"
ucidef_set_led_netdev "lan3" "LAN3" "green:lan-3" "lan3"
ucidef_set_led_netdev "lan4" "LAN4" "green:lan-4" "lan4"
ucidef_set_led_netdev "10G_1" "10G_1" "green:10g-1" "10g-1"
ucidef_set_led_netdev "10G_2" "10G_2" "green:10g-2" "10g-2"
;;
yuncore,ax880)
ucidef_set_led_netdev "wan-port-link" "WAN-PORT-LINK" "90000.mdio-1:18:green:wan" "wan" "tx rx link_10 link_100 link_1000 link_2500"
ucidef_set_led_netdev "lan-port-link" "LAN-PORT-LINK" "90000.mdio-1:1c:green:lan" "lan" "tx rx link_10 link_100 link_1000 link_2500"
;;
zbtlink,zbt-z800ax)
ucidef_set_led_netdev "internet" "Internet" "green:wan-online" "wan"
;;
esac
board_config_flush
exit 0

View File

@@ -0,0 +1,112 @@
#
# Copyright (c) 2015 The Linux Foundation. All rights reserved.
# Copyright (c) 2011-2015 OpenWrt.org
#
. /lib/functions/uci-defaults.sh
. /lib/functions/system.sh
ipq807x_setup_interfaces()
{
local board="$1"
case "$board" in
asus,rt-ax89x)
ucidef_set_interfaces_lan_wan "10g-sfp 10g-copper lan1 lan2 lan3 lan4 lan5 lan6 lan7 lan8" "wan"
;;
arcadyan,aw1000|\
buffalo,wxr-5950ax12|\
dynalink,dl-wrx36|\
linksys,mx5300|\
linksys,mx8500|\
xiaomi,ax9000|\
zbtlink,zbt-z800ax)
ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
;;
cmcc,rm2-6)
ucidef_set_interfaces_lan_wan "lan plc" "wan"
;;
compex,wpq873|\
linksys,mx4200v1|\
linksys,mx4200v2|\
prpl,haze|\
redmi,ax6|\
spectrum,sax1v1k|\
xiaomi,ax3600)
ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" "wan"
;;
edgecore,eap102|\
yuncore,ax880|\
zte,mf269)
ucidef_set_interfaces_lan_wan "lan" "wan"
;;
edimax,cax1800)
ucidef_set_interfaces_lan_wan "lan"
;;
netgear,rax120v2)
ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4 lan5" "wan"
;;
netgear,sxr80|\
netgear,sxs80)
ucidef_set_interfaces_lan_wan "lan2 lan3 lan4 lan5" "wan"
;;
netgear,wax218|\
netgear,wax620)
ucidef_set_interface_lan "lan" "dhcp"
;;
netgear,wax630)
ucidef_set_interface_lan "lan1 lan2" "dhcp"
;;
qnap,301w)
ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4 10g-2" "10g-1"
;;
tplink,eap660hd-v1)
ucidef_set_interface_lan "lan" "dhcp"
;;
zyxel,nbg7815)
ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4 10g" "wan"
;;
*)
echo "Unsupported hardware. Network interfaces not initialized"
;;
esac
}
ipq807x_setup_macs()
{
local board="$1"
local lan_mac=""
local wan_mac=""
local label_mac=""
case "$board" in
linksys,mx4200v2)
label_mac=$(mtd_get_mac_ascii devinfo hw_mac_addr)
for i in $(seq 3 5); do
[ "$(mtd_get_mac_ascii u_env eth${i}addr)" != "$label_mac" ] && lan_mac=$label_mac
done
[ "$(mtd_get_mac_ascii u_env eth2addr)" != "$label_mac" ] && wan_mac=$label_mac
;;
linksys,mx8500)
label_mac=$(mtd_get_mac_ascii devinfo hw_mac_addr)
lan_mac=$(macaddr_add $label_mac 1)
wan_mac=$label_mac
;;
tplink,eap660hd-v1)
label_mac=$(get_mac_binary /tmp/factory_data/default-mac 0)
lan_mac=$label_mac
;;
esac
[ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
[ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
[ -n "$label_mac" ] && ucidef_set_label_macaddr $label_mac
}
board_config_update
board=$(board_name)
ipq807x_setup_interfaces $board
ipq807x_setup_macs $board
board_config_flush
exit 0

View File

@@ -0,0 +1,125 @@
#!/bin/sh
[ -e /lib/firmware/$FIRMWARE ] && exit 0
. /lib/functions/caldata.sh
board=$(board_name)
case "$FIRMWARE" in
"ath11k/IPQ8074/hw2.0/cal-ahb-c000000.wifi.bin")
case "$board" in
asus,rt-ax89x)
CI_UBIPART="UBI_DEV"
caldata_extract_ubi "Factory" 0x1000 0x20000
;;
arcadyan,aw1000|\
buffalo,wxr-5950ax12|\
cmcc,rm2-6|\
compex,wpq873|\
dynalink,dl-wrx36|\
edgecore,eap102|\
edimax,cax1800|\
linksys,mx5300|\
netgear,wax218|\
qnap,301w|\
redmi,ax6|\
xiaomi,ax3600|\
xiaomi,ax9000|\
yuncore,ax880|\
zte,mf269)
caldata_extract "0:art" 0x1000 0x20000
;;
linksys,mx4200v1|\
linksys,mx8500)
caldata_extract "0:art" 0x1000 0x20000
ath11k_remove_regdomain
;;
linksys,mx4200v2)
caldata_extract "0:art" 0x1000 0x20000
label_mac=$(mtd_get_mac_ascii devinfo hw_mac_addr)
ath11k_patch_mac $(macaddr_add $label_mac 2) 0
ath11k_patch_mac $(macaddr_add $label_mac 1) 1
ath11k_patch_mac $(macaddr_add $label_mac 3) 2
ath11k_remove_regdomain
ath11k_set_macflag
;;
netgear,rax120v2)
caldata_extract "0:art" 0x1000 0x20000
ath11k_patch_mac $(mtd_get_mac_binary boarddata1 0xc) 0
ath11k_patch_mac $(mtd_get_mac_binary boarddata1 0x0) 1
ath11k_patch_mac $(mtd_get_mac_binary boarddata1 0x6) 2
ath11k_set_macflag
;;
netgear,sxr80|\
netgear,sxs80)
caldata_extract "0:art" 0x1000 0x20000
label_mac=$(get_mac_label)
ath11k_patch_mac $(mtd_get_mac_binary boarddata1 0x0c) 0
#boarddata1 doesn't have a MAC for the 2G interface
ath11k_patch_mac $(macaddr_setbit_la $label_mac) 1
ath11k_patch_mac $(mtd_get_mac_binary boarddata1 0x12) 2
ath11k_set_macflag
;;
netgear,wax620)
caldata_extract "0:art" 0x1000 0x20000
label_mac=$(get_mac_label)
ath11k_patch_mac $(macaddr_add $label_mac -31) 1
ath11k_patch_mac $(macaddr_add $label_mac 1) 0
ath11k_set_macflag
;;
netgear,wax630)
caldata_extract "0:art" 0x1000 0x20000
label_mac=$(get_mac_label)
ath11k_patch_mac $(macaddr_add $label_mac -31) 1
ath11k_patch_mac $(macaddr_add $label_mac 1) 0
ath11k_patch_mac $(macaddr_add $label_mac 33) 2
ath11k_set_macflag
;;
prpl,haze|\
spectrum,sax1v1k)
caldata_extract_mmc "0:ART" 0x1000 0x20000
;;
tplink,eap660hd-v1)
caldata_from_file "/tmp/factory_data/radio" 0 0x20000
label_mac=$(get_mac_binary /tmp/factory_data/default-mac 0)
ath11k_patch_mac $label_mac 1
ath11k_patch_mac $(macaddr_add $label_mac 1) 0
ath11k_set_macflag
;;
zbtlink,zbt-z800ax)
caldata_extract "0:art" 0x1000 0x20000
label_mac=$(get_mac_label)
ath11k_patch_mac $(macaddr_add $label_mac -1) 0
ath11k_patch_mac $(macaddr_add $label_mac -2) 1
ath11k_set_macflag
;;
zyxel,nbg7815)
caldata_extract "0:art" 0x1000 0x20000
label_mac=$(get_mac_label)
ath11k_patch_mac $(macaddr_add $label_mac 3) 0
ath11k_patch_mac $(macaddr_add $label_mac 2) 1
ath11k_patch_mac $(macaddr_add $label_mac 4) 2
ath11k_set_macflag
;;
esac
;;
"ath11k/QCN9074/hw1.0/cal-pci-0000:01:00.0.bin"|\
"ath11k/QCN9074/hw1.0/cal-pci-0001:01:00.0.bin")
case "$board" in
linksys,mx8500)
caldata_extract "0:art" 0x26800 0x20000
ath11k_remove_regdomain
;;
prpl,haze)
caldata_extract_mmc "0:ART" 0x26800 0x20000
;;
xiaomi,ax9000)
caldata_extract "0:art" 0x26800 0x20000
;;
esac
;;
*)
exit 1
;;
esac

View File

@@ -0,0 +1,68 @@
#!/bin/sh
# This must run before 10-wifi-detect
[ "${ACTION}" = "add" ] || return
. /lib/functions.sh
check_kernel()
{
local kernel_current=$(uname -r)
if [ ${kernel_current//./} -lt "6600" ]; then
return 1
fi
}
do_migrate_radio()
{
local cfg="$1" from="$2" to="$3"
config_get path "$cfg" path
[ "$path" = "$from" ] || return
uci set "wireless.${cfg}.path=${to}"
WIRELESS_CHANGED=true
logger -t wifi-migrate "Updated path of wireless.${cfg} from '${from}' to '${to}'"
}
check_path()
{
local config
config="$1"
config_get path "$config" path
to=${path/soc\//soc@0\/}
# Checks if kernel version is less than 6.6.0, if it is and the path is using the new format,
# then path should be migrated to the old format. This would allow users on platforms with two partitions,
# to test 6.1 and 6.6.
check_kernel || to=${path/soc@0\//soc\/}
[ "$path" = "$to" ] || do_migrate_radio "$config" "$path" "$to"
}
migrate_radio()
{
config_load wireless
# Check if there is already a section with the target path: In this case, the system
# was already upgraded to a version without this migration script before; better bail out,
# as we can't be sure we don't break more than we fix.
config_foreach check_path wifi-device
}
WIRELESS_CHANGED=false
case "$(board_name)" in
*)
migrate_radio
;;
esac
$WIRELESS_CHANGED && uci commit wireless
exit 0

View File

@@ -0,0 +1,26 @@
[ "$ACTION" == "add" ] || exit 0
PHYNBR=${DEVPATH##*/phy}
[ -n $PHYNBR ] || exit 0
. /lib/functions.sh
. /lib/functions/system.sh
board=$(board_name)
case "$board" in
arcadyan,aw1000)
[ "$PHYNBR" = "0" ] && macaddr_add $(get_mac_label) 1 > /sys${DEVPATH}/macaddress
[ "$PHYNBR" = "1" ] && macaddr_add $(get_mac_label) 2 > /sys${DEVPATH}/macaddress
;;
buffalo,wxr-5950ax12)
[ "$PHYNBR" = "0" ] && macaddr_add $(get_mac_label) 8 > /sys${DEVPATH}/macaddress
[ "$PHYNBR" = "1" ] && macaddr_add $(get_mac_label) 16 > /sys${DEVPATH}/macaddress
;;
cmcc,rm2-6|\
zte,mf269)
[ "$PHYNBR" = "0" ] && macaddr_add $(get_mac_label) 2 > /sys${DEVPATH}/macaddress
[ "$PHYNBR" = "1" ] && macaddr_add $(get_mac_label) 3 > /sys${DEVPATH}/macaddress
;;
esac

View File

@@ -0,0 +1,20 @@
#!/bin/sh /etc/rc.common
START=99
boot() {
case $(board_name) in
edgecore,eap102|\
yuncore,ax880)
fw_setenv upgrade_available 0
# Unset changed flag after sysupgrade complete
fw_setenv changed
;;
linksys,mx4200v1|\
linksys,mx4200v2|\
linksys,mx5300|\
linksys,mx8500)
mtd resetbc s_env || true
;;
esac
}

View File

@@ -0,0 +1,122 @@
#!/bin/sh /etc/rc.common
######################################################################
# vim: set ft=bash
# shellcheck disable=2155,3019,3043,3057,3060
######################################################################
START=93
PROG=smp_affinity
log_msg() {
local irq_name="$1" affinity="$2" irq="$3"
msg="$(printf "Pinning IRQ($irq) %-24s to CPU ${affinity}\n" "$irq_name")"
logger -t "$PROG" "$msg"
}
######################################################################
### Takes a comma, space separated, or range list of CPU numbers and
## returns a bitmask of CPUs.
## cpus_to_bitmask "0,1,2,3" -> f
## cpus_to_bitmask "0 1 2 3" -> f
## cpus_to_bitmask "0-3" -> f
## cpus_to_bitmask "3" -> 8
#######################################################################
cpus_to_bitmask() {
local bitmask=0
# shellcheck disable=2048
for range in ${*//,/ }; do
start="${range%-*}"
end="${range#*-}"
if [ -z "$end" ]; then
bitmask="$((bitmask | 1 << start))"
else
bitmask="$((bitmask | (2 ** (end - start + 1) - 1) << start))"
fi
done
printf '%x' $bitmask
}
######################################################################
### Takes a bitmask of CPUs and returns a space separated list of
## CPU numbers.
## bitmask_to_cpus f -> 0 1 2 3
######################################################################
bitmask_to_cpus() {
[ "${1:0:2}" != "0x" ] && set -- "0x$1"
local bitmask="$(printf '%d' "$1")"
local cpus=""
for i in $(seq 0 63); do
if [ $((bitmask & 1)) -ne 0 ]; then
cpus="$cpus $i"
fi
bitmask=$((bitmask >> 1))
done
echo "${cpus# }"
}
######################################################################
### Sets the affinity of the IRQs with the given name to the given CPU.
## 1st argument: IRQ name ("reo2host-destination-ring1") (req)
## 2nd argument: CPU number (req)
######################################################################
set_affinity() {
local irq_name="$1" affinity="$2" bitmask irq
awk -v irq_name="$1" '$0 ~ irq_name { print substr($1, 1, length($1)-1); exit }' /proc/interrupts \
| while read -r irq; do
$enable_log && {
log_msg "$irq_name" "$affinity" "$irq"
}
bitmask=$(cpus_to_bitmask "$affinity") && echo "$bitmask" > "/proc/irq/$irq/smp_affinity"
done
}
enable_affinity_ipq807x() {
# assign 4 rx interrupts to each core
set_affinity 'reo2host-destination-ring1' 0
set_affinity 'reo2host-destination-ring2' 1
set_affinity 'reo2host-destination-ring3' 2
set_affinity 'reo2host-destination-ring4' 3
# assign 3 tcl completions to last 3 CPUs
set_affinity 'wbm2host-tx-completions-ring1' 1
set_affinity 'wbm2host-tx-completions-ring2' 2
set_affinity 'wbm2host-tx-completions-ring3' 3
# assign 3 ppdu mac interrupts to last 3 cores
set_affinity 'ppdu-end-interrupts-mac1' 1
set_affinity 'ppdu-end-interrupts-mac2' 2
set_affinity 'ppdu-end-interrupts-mac3' 3
# assign 4 lan/wan to core 4
set_affinity 'edma_txcmpl' 3
set_affinity 'edma_rxfill' 3
set_affinity 'edma_rxdesc' 3
set_affinity 'edma_misc' 3
}
boot() {
local enable
config_load smp_affinity
config_get_bool enable "general" enable 1
config_get_bool enable_log "general" enable_log 1
[ "$enable" -eq 1 ] && enable=true || enable=false
[ "$enable_log" -eq 1 ] && enable_log=true || enable_log=false
$enable && enable_affinity_ipq807x
}

View File

@@ -0,0 +1,11 @@
#!/bin/sh
uci -q get smp_affinity && exit 0
touch /etc/config/smp_affinity
uci -q batch << EOF
set smp_affinity.general=smp_affinity
set smp_affinity.general.enable='1'
set smp_affinity.general.enable_log='1'
commit smp_affinity
EOF

View File

@@ -0,0 +1,19 @@
#!/bin/sh
preinit_mount_factory_data() {
local mtd_path
. /lib/functions.sh
. /lib/functions/system.sh
case $(board_name) in
tplink,eap660hd-v1)
mtd_path=$(find_mtd_chardev "factory_data")
ubiattach --dev-path="$mtd_path" --devn=1
mkdir /tmp/factory_data
mount -o ro,noatime -t ubifs ubi1:ubi_factory_data /tmp/factory_data
;;
esac
}
boot_hook_add preinit_main preinit_mount_factory_data

View File

@@ -0,0 +1,55 @@
. /lib/functions.sh
# Prepare UBI devices for OpenWrt installation
# - rootfs (mtd22)
# - remove "ubi_rootfs" volume (rootfs on stock)
# - remove "fw_hash" volume (firmware hash)
# - user_property (mtd24)
# - remove "user_property_ubi" volume (user configuration)
# - remove "extra_property" volume (gzipped syslog)
buffalo_upgrade_prepare() {
local ubi_rootdev ubi_propdev
if ! ubi_rootdev="$(nand_attach_ubi rootfs)" || \
! ubi_propdev="$(nand_attach_ubi user_property)"; then
echo "failed to attach UBI volume \"rootfs\" or \"user_property\", rebooting..."
reboot -f
fi
ubirmvol /dev/$ubi_rootdev -N ubi_rootfs &> /dev/null || true
ubirmvol /dev/$ubi_rootdev -N fw_hash &> /dev/null || true
ubirmvol /dev/$ubi_propdev -N user_property_ubi &> /dev/null || true
ubirmvol /dev/$ubi_propdev -N extra_property &> /dev/null || true
}
# Re-create small dummy ubi_rootfs volume and update
# fw_hash volume to pass the checking by U-Boot
# - rootfs (mtd22)
# - re-create "ubi_rootfs" volume
# - re-create and update "fw_hash" volume
# - rootfs_recover (mtd23)
# - update "fw_hash" volume
buffalo_upgrade_optvol() {
local ubi_rootdev ubi_rcvrdev
local hashvol_root hashvol_rcvr
if ! ubi_rootdev="$(nand_attach_ubi rootfs)" || \
! ubi_rcvrdev="$(nand_attach_ubi rootfs_recover)"; then
echo "failed to attach UBI volume \"rootfs\" or \"rootfs_recover\", rebooting..."
reboot -f
fi
ubimkvol /dev/$ubi_rootdev -N ubi_rootfs -S 1
ubimkvol /dev/$ubi_rootdev -N fw_hash -S 1 -t static
if ! hashvol_root="$(nand_find_volume $ubi_rootdev fw_hash)" || \
! hashvol_rcvr="$(nand_find_volume $ubi_rcvrdev fw_hash)"; then
echo "\"fw_hash\" volume in \"rootfs\" or \"rootfs_recover\" not found, rebooting..."
reboot -f
fi
echo -n "00000000000000000000000000000000" > /tmp/dummyhash.txt
ubiupdatevol /dev/$hashvol_root /tmp/dummyhash.txt
ubiupdatevol /dev/$hashvol_rcvr /tmp/dummyhash.txt
}

View File

@@ -0,0 +1,277 @@
PART_NAME=firmware
REQUIRE_IMAGE_METADATA=1
RAMFS_COPY_BIN='fw_printenv fw_setenv head'
RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock'
xiaomi_initramfs_prepare() {
# Wipe UBI if running initramfs
[ "$(rootfs_type)" = "tmpfs" ] || return 0
local rootfs_mtdnum="$( find_mtd_index rootfs )"
if [ ! "$rootfs_mtdnum" ]; then
echo "unable to find mtd partition rootfs"
return 1
fi
local kern_mtdnum="$( find_mtd_index ubi_kernel )"
if [ ! "$kern_mtdnum" ]; then
echo "unable to find mtd partition ubi_kernel"
return 1
fi
ubidetach -m "$rootfs_mtdnum"
ubiformat /dev/mtd$rootfs_mtdnum -y
ubidetach -m "$kern_mtdnum"
ubiformat /dev/mtd$kern_mtdnum -y
}
asus_initial_setup() {
# Remove existing linux and jffs2 volumes
[ "$(rootfs_type)" = "tmpfs" ] || return 0
ubirmvol /dev/ubi0 -N linux
ubirmvol /dev/ubi0 -N jffs2
}
remove_oem_ubi_volume() {
local oem_volume_name="$1"
local oem_ubivol
local mtdnum
local ubidev
mtdnum=$(find_mtd_index "$CI_UBIPART")
if [ ! "$mtdnum" ]; then
return
fi
ubidev=$(nand_find_ubi "$CI_UBIPART")
if [ ! "$ubidev" ]; then
ubiattach --mtdn="$mtdnum"
ubidev=$(nand_find_ubi "$CI_UBIPART")
fi
if [ "$ubidev" ]; then
oem_ubivol=$(nand_find_volume "$ubidev" "$oem_volume_name")
[ "$oem_ubivol" ] && ubirmvol "/dev/$ubidev" --name="$oem_volume_name"
fi
}
tplink_get_boot_part() {
local cur_boot_part
local args
# Try to find rootfs from kernel arguments
read -r args < /proc/cmdline
for arg in $args; do
local ubi_mtd_arg=${arg#ubi.mtd=}
case "$ubi_mtd_arg" in
rootfs|rootfs_1)
echo "$ubi_mtd_arg"
return
;;
esac
done
# Fallback to u-boot env (e.g. when running initramfs)
cur_boot_part="$(/usr/sbin/fw_printenv -n tp_boot_idx)"
case $cur_boot_part in
1)
echo rootfs_1
;;
0|*)
echo rootfs
;;
esac
}
tplink_do_upgrade() {
local new_boot_part
case $(tplink_get_boot_part) in
rootfs)
CI_UBIPART="rootfs_1"
new_boot_part=1
;;
rootfs_1)
CI_UBIPART="rootfs"
new_boot_part=0
;;
esac
fw_setenv -s - <<-EOF
tp_boot_idx $new_boot_part
EOF
remove_oem_ubi_volume ubi_rootfs
nand_do_upgrade "$1"
}
platform_check_image() {
return 0;
}
platform_pre_upgrade() {
case "$(board_name)" in
asus,rt-ax89x)
asus_initial_setup
;;
redmi,ax6|\
xiaomi,ax3600|\
xiaomi,ax9000)
xiaomi_initramfs_prepare
;;
esac
}
platform_do_upgrade() {
case "$(board_name)" in
arcadyan,aw1000|\
cmcc,rm2-6|\
compex,wpq873|\
dynalink,dl-wrx36|\
edimax,cax1800|\
netgear,rax120v2|\
netgear,sxr80|\
netgear,sxs80|\
netgear,wax218|\
netgear,wax620|\
netgear,wax630)
nand_do_upgrade "$1"
;;
asus,rt-ax89x)
CI_UBIPART="UBI_DEV"
CI_KERNPART="linux"
CI_ROOTPART="jffs2"
nand_do_upgrade "$1"
;;
buffalo,wxr-5950ax12)
CI_KERN_UBIPART="rootfs"
CI_ROOT_UBIPART="user_property"
buffalo_upgrade_prepare
nand_do_flash_file "$1" || nand_do_upgrade_failed
nand_do_restore_config || nand_do_upgrade_failed
buffalo_upgrade_optvol
;;
edgecore,eap102)
active="$(fw_printenv -n active)"
if [ "$active" -eq "1" ]; then
CI_UBIPART="rootfs2"
else
CI_UBIPART="rootfs1"
fi
# force altbootcmd which handles partition change in u-boot
fw_setenv bootcount 3
fw_setenv upgrade_available 1
nand_do_upgrade "$1"
;;
linksys,mx4200v1|\
linksys,mx4200v2|\
linksys,mx5300|\
linksys,mx8500)
boot_part="$(fw_printenv -n boot_part)"
if [ "$boot_part" -eq "1" ]; then
fw_setenv boot_part 2
CI_KERNPART="alt_kernel"
CI_UBIPART="alt_rootfs"
else
fw_setenv boot_part 1
CI_UBIPART="rootfs"
fi
fw_setenv boot_part_ready 3
fw_setenv auto_recovery yes
nand_do_upgrade "$1"
;;
prpl,haze|\
qnap,301w)
CI_KERNPART="0:HLOS"
CI_ROOTPART="rootfs"
emmc_do_upgrade "$1"
;;
redmi,ax6|\
xiaomi,ax3600|\
xiaomi,ax9000)
# Make sure that UART is enabled
fw_setenv boot_wait on
fw_setenv uart_en 1
# Enforce single partition.
fw_setenv flag_boot_rootfs 0
fw_setenv flag_last_success 0
fw_setenv flag_boot_success 1
fw_setenv flag_try_sys1_failed 8
fw_setenv flag_try_sys2_failed 8
# Kernel and rootfs are placed in 2 different UBI
CI_KERN_UBIPART="ubi_kernel"
CI_ROOT_UBIPART="rootfs"
nand_do_upgrade "$1"
;;
spectrum,sax1v1k)
CI_KERNPART="0:HLOS"
CI_ROOTPART="rootfs"
CI_DATAPART="rootfs_data"
emmc_do_upgrade "$1"
;;
tplink,eap660hd-v1)
tplink_do_upgrade "$1"
;;
yuncore,ax880)
active="$(fw_printenv -n active)"
if [ "$active" -eq "1" ]; then
CI_UBIPART="rootfs_1"
else
CI_UBIPART="rootfs"
fi
# force altbootcmd which handles partition change in u-boot
fw_setenv bootcount 3
fw_setenv upgrade_available 1
nand_do_upgrade "$1"
;;
zbtlink,zbt-z800ax)
local mtdnum="$(find_mtd_index 0:bootconfig)"
local alt_mtdnum="$(find_mtd_index 0:bootconfig1)"
part_num="$(hexdump -e '1/1 "%01x|"' -n 1 -s 168 -C /dev/mtd$mtdnum | cut -f 1 -d "|" | head -n1)"
# vendor firmware may swap the rootfs partition location, u-boot append: ubi.mtd=rootfs
# since we use fixed-partitions, need to force boot from the first rootfs partition
if [ "$part_num" -eq "1" ]; then
mtd erase /dev/mtd$mtdnum
mtd erase /dev/mtd$alt_mtdnum
fi
nand_do_upgrade "$1"
;;
zte,mf269)
CI_KERN_UBIPART="ubi_kernel"
CI_ROOT_UBIPART="rootfs"
nand_do_upgrade "$1"
;;
zyxel,nbg7815)
local config_mtdnum="$(find_mtd_index 0:bootconfig)"
[ -z "$config_mtdnum" ] && reboot
part_num="$(hexdump -e '1/1 "%01x|"' -n 1 -s 168 -C /dev/mtd$config_mtdnum | cut -f 1 -d "|" | head -n1)"
if [ "$part_num" -eq "0" ]; then
CI_KERNPART="0:HLOS"
CI_ROOTPART="rootfs"
else
CI_KERNPART="0:HLOS_1"
CI_ROOTPART="rootfs_1"
fi
emmc_do_upgrade "$1"
;;
*)
default_do_upgrade "$1"
;;
esac
}
platform_copy_config() {
case "$(board_name)" in
prpl,haze|\
qnap,301w|\
spectrum,sax1v1k|\
zyxel,nbg7815)
emmc_copy_config
;;
esac
}