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 12:51:15 +02:00
commit 27c9d80f51
10493 changed files with 1885777 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
#
# Copyright (C) 2018 Weijie Gao <hackpascal@gmail.com>
#
# Helper function to extract mac addresses from mtd part for Phicomm K2T
#
. /lib/functions.sh
. /lib/functions/system.sh
. /usr/share/libubox/jshn.sh
k2t_config_load() {
local mtd_blk=$(find_mtd_part config)
if [ -z "$mtd_blk" ]; then
echo "k2t_config_load: no mtd part named config" >&2
exit 1
fi
local json_size=$(dd if=$mtd_blk bs=1 count=8 2>/dev/null)
json_size="0x$json_size"
json_size=$((json_size))
if [ "$?" -ne 0 ]; then
echo "k2t_config_load: invalid json data size" >&2
exit 2
fi
if [ "$json_size" -eq 0 ]; then
echo "k2t_config_load: empty json data" >&2
exit 3
fi
local json_data=$(dd if=$mtd_blk bs=1 skip=8 count=$json_size 2>/dev/null)
json_load "$json_data"
}
k2t_get_mac() {
local old_ns
json_set_namespace "k2t" old_ns
if k2t_config_load; then
json_select "this_dev_info"
json_get_var val "$1"
json_select ..
fi
json_set_namespace old_ns
echo $val
}

View File

@@ -0,0 +1,42 @@
. /lib/functions.sh
do_sysinfo_ath79_fixup() {
local model=""
case $(board_name) in
netgear,ex7300)
local part=$(find_mtd_part caldata)
local board_hw_id=$(dd if=$part bs=1 skip=67 count=10 2>/dev/null)
case "$board_hw_id" in
5508013406)
model="Netgear EX6400"
;;
5508013271)
model="Netgear EX7300"
;;
esac
;;
netgear,ex7300-v2)
local part=$(find_mtd_part artmtd)
local antenna_cfg=$(dd if=$part bs=1 skip=59 count=7 2>/dev/null)
local board_hw_id=$(dd if=$part bs=1 skip=67 count=6 2>/dev/null)
case "$antenna_cfg" in
3X3+3X3)
model="Netgear EX6250"
;;
3X3+4X4)
# EX6400 v2, EX6410, EX6420
model="Netgear ${board_hw_id:-EX6400 v2}"
;;
4X4+4X4)
# EX7300 v2, EX7320
model="Netgear ${board_hw_id:-EX7300 v2}"
;;
esac
;;
esac
[ -n "$model" ] && echo "$model" > /tmp/sysinfo/model
}
boot_hook_add preinit_main do_sysinfo_ath79_fixup

View File

@@ -0,0 +1,43 @@
. /lib/functions/system.sh
preinit_set_mac_address() {
case $(board_name) in
avm,fritz1750e|\
avm,fritz450e|\
avm,fritzdvbc)
ip link set dev eth0 address $(fritz_tffs -n maca -i $(find_mtd_part "tffs (1)"))
;;
dlink,dap-2695-a1|\
dlink,dap-3662-a1)
ip link set dev eth0 address $(mtd_get_mac_ascii bdcfg "lanmac")
ip link set dev eth1 address $(mtd_get_mac_ascii bdcfg "wanmac")
;;
engenius,epg5000|\
engenius,esr1200|\
engenius,esr1750|\
engenius,esr900)
ip link set dev eth0 address $(mtd_get_mac_ascii u-boot-env ethaddr)
;;
enterasys,ws-ap3705i)
ip link set dev eth0 address $(mtd_get_mac_ascii u-boot-env0 ethaddr)
;;
extreme-networks,ws-ap3805i|\
siemens,ws-ap3610)
ip link set dev eth0 address $(mtd_get_mac_ascii cfg1 ethaddr)
;;
moxa,awk-1137c)
ip link set dev eth0 address $(mtd_get_mac_ascii u-boot-env mac_addr)
;;
tplink,deco-s4-v2)
base_mac=$(mtd_get_mac_encrypted_deco $(find_mtd_part config))
ip link set dev eth0 address $base_mac
;;
zyxel,nbg6616)
ethaddr=$(mtd_get_mac_ascii u-boot-env ethaddr)
ip link set dev eth0 address $(macaddr_add $ethaddr 2)
ip link set dev eth1 address $(macaddr_add $ethaddr 3)
;;
esac
}
boot_hook_add preinit_main preinit_set_mac_address

View File

@@ -0,0 +1,105 @@
# The U-Boot loader with the datachk patchset for dualbooting requires image
# sizes and checksums to be provided in the U-Boot environment.
# The devices come with 2 main partitions - while one is active
# sysupgrade will flash the other. The boot order is changed to boot the
# newly flashed partition. If the new partition can't be booted due to
# upgrade failures the previously used partition is loaded.
platform_do_upgrade_dualboot_datachk() {
local tar_file="$1"
local restore_backup
local primary_kernel_mtd
local setenv_script="/tmp/fw_env_upgrade"
local inactive_mtd="$(find_mtd_index $PART_NAME)"
local inactive_offset="$(cat /sys/class/mtd/mtd${inactive_mtd}/offset)"
local total_size="$(cat /sys/class/mtd/mtd${inactive_mtd}/size)"
local flash_start_mem=0x9f000000
# detect to which flash region the new image is written to.
#
# 1. check what is the mtd index for the first flash region on this
# device
# 2. check if the target partition ("inactive") has the mtd index of
# the first flash region
#
# - when it is: the new bootseq will be 1,2 and the first region is
# modified
# - when it isnt: bootseq will be 2,1 and the second region is
# modified
#
# The detection has to be done via the hardcoded mtd partition because
# the current boot might be done with the fallback region. Let us
# assume that the current bootseq is 1,2. The bootloader detected that
# the image in flash region 1 is corrupt and thus switches to flash
# region 2. The bootseq in the u-boot-env is now still the same and
# the sysupgrade code can now only rely on the actual mtd indexes and
# not the bootseq variable to detect the currently booted flash
# region/image.
#
# In the above example, an implementation which uses bootseq ("1,2") to
# detect the currently booted image would assume that region 1 is booted
# and then overwrite the variables for the wrong flash region (aka the
# one which isn't modified). This could result in a device which doesn't
# boot anymore to Linux until it was reflashed with ap51-flash.
local next_boot_part="1"
case "$(board_name)" in
plasmacloud,pa300|\
plasmacloud,pa300e)
primary_kernel_mtd=3
;;
*)
echo "failed to detect primary kernel mtd partition for board"
return 1
;;
esac
[ "$inactive_mtd" = "$primary_kernel_mtd" ] || next_boot_part="2"
local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
board_dir=${board_dir%/}
local kernel_length=$(tar xf $tar_file ${board_dir}/kernel -O | wc -c)
local rootfs_length=$(tar xf $tar_file ${board_dir}/root -O | wc -c)
# rootfs without EOF marker
rootfs_length=$((rootfs_length-4))
local kernel_md5=$(tar xf $tar_file ${board_dir}/kernel -O | md5sum); kernel_md5="${kernel_md5%% *}"
# md5 checksum of rootfs with EOF marker
local rootfs_md5=$(tar xf $tar_file ${board_dir}/root -O | dd bs=1 count=$rootfs_length | md5sum); rootfs_md5="${rootfs_md5%% *}"
#
# add tar support to get_image() to use default_do_upgrade() instead?
#
# take care of restoring a saved config
[ -n "$UPGRADE_BACKUP" ] && restore_backup="${MTD_CONFIG_ARGS} -j ${UPGRADE_BACKUP}"
mtd -q erase inactive
tar xf $tar_file ${board_dir}/root -O | mtd -n -p $kernel_length $restore_backup write - $PART_NAME
tar xf $tar_file ${board_dir}/kernel -O | mtd -n write - $PART_NAME
# prepare new u-boot env
if [ "$next_boot_part" = "1" ]; then
echo "bootseq 1,2" > $setenv_script
else
echo "bootseq 2,1" > $setenv_script
fi
printf "kernel_size_%i %i\n" $next_boot_part $((kernel_length / 1024)) >> $setenv_script
printf "vmlinux_start_addr 0x%08x\n" $((flash_start_mem + inactive_offset)) >> $setenv_script
printf "vmlinux_size 0x%08x\n" ${kernel_length} >> $setenv_script
printf "vmlinux_checksum %s\n" ${kernel_md5} >> $setenv_script
printf "rootfs_size_%i %i\n" $next_boot_part $(((total_size-kernel_length) / 1024)) >> $setenv_script
printf "rootfs_start_addr 0x%08x\n" $((flash_start_mem+inactive_offset+kernel_length)) >> $setenv_script
printf "rootfs_size 0x%08x\n" ${rootfs_length} >> $setenv_script
printf "rootfs_checksum %s\n" ${rootfs_md5} >> $setenv_script
# store u-boot env changes
mkdir -p /var/lock
fw_setenv -s $setenv_script || {
echo "failed to update U-Boot environment"
return 1
}
}

View File

@@ -0,0 +1,64 @@
# U-Boot with the datachk patchset requires image sizes, offsets,
# and checksums to be provided in the U-Boot environment.
# This script is based on the dualboot version for devices that come with 2 OS partitions.
# For Senao boards with a "failsafe" partition image, the process is almost the same.
# Instead of booting a secondary instalation on checksum failure,
# the failsafe image is booted instead.
# These boards also use the OKLI lzma kernel loader and mtd-concat
# So the kernel check is for the loader, the rootfs check is for kernel + rootfs
platform_do_upgrade_failsafe_datachk() {
local flash_base=0x9f000000
local kernel_mtd=$(find_mtd_index ${KERNEL_PART:-kernel})
local rootfs_mtd=$(find_mtd_index ${ROOTFS_PART:-rootfs})
local kernel_offset=$(cat /sys/class/mtd/mtd${kernel_mtd}/offset)
local rootfs_offset=$(cat /sys/class/mtd/mtd${rootfs_mtd}/offset)
if [ -n "$IMAGE_LIST" ]; then
KERNEL_FILE=$($IMAGE_LIST | grep $KERNEL_FILE)
ROOTFS_FILE=$($IMAGE_LIST | grep $ROOTFS_FILE)
fi
local kernel_size=$($IMAGE_CMD $KERNEL_FILE | wc -c)
local rootfs_size=$($IMAGE_CMD $ROOTFS_FILE | wc -c)
# rootfs without JFFS2
local rootfs_blocks=$((rootfs_size / 4096))
rootfs_size=$((rootfs_blocks * 4096))
local kernel_md5=$($IMAGE_CMD $KERNEL_FILE | md5sum | cut -d ' ' -f1)
local rootfs_md5=$($IMAGE_CMD $ROOTFS_FILE | dd bs=4k count=$rootfs_blocks iflag=fullblock | md5sum | cut -d ' ' -f1)
# prepare new u-boot-env vars
printf "vmlinux_start_addr 0x%08x\n" $((flash_base + kernel_offset)) >> $ENV_SCRIPT
printf "vmlinux_size 0x%08x\n" ${kernel_size} >> $ENV_SCRIPT
printf "vmlinux_checksum %s\n" ${kernel_md5} >> $ENV_SCRIPT
printf "rootfs_start_addr 0x%08x\n" $((flash_base + rootfs_offset)) >> $ENV_SCRIPT
printf "rootfs_size 0x%08x\n" ${rootfs_size} >> $ENV_SCRIPT
printf "rootfs_checksum %s\n" ${rootfs_md5} >> $ENV_SCRIPT
# store u-boot-env
mkdir -p /var/lock
[ -n "$SKIP_HASH" ] || fw_setenv -s $ENV_SCRIPT || {
echo 'failed to update U-Boot environment'
exit 1
}
# sysupgrade
sleep 2 && sync && echo 3 > /proc/sys/vm/drop_caches
$IMAGE_CMD $KERNEL_FILE | mtd $MTD_ARGS write - ${KERNEL_PART:-kernel}
sleep 2 && sync && echo 3 > /proc/sys/vm/drop_caches
if [ -n "$UPGRADE_BACKUP" ]; then
$IMAGE_CMD $ROOTFS_FILE | mtd $MTD_ARGS $MTD_CONFIG_ARGS -j $UPGRADE_BACKUP write - ${ROOTFS_PART:-rootfs}
else
$IMAGE_CMD $ROOTFS_FILE | mtd $MTD_ARGS write - ${ROOTFS_PART:-rootfs}
fi
sync
}

View File

@@ -0,0 +1,114 @@
# The U-Boot loader of the OpenMesh devices requires image sizes and
# checksums to be provided in the U-Boot environment.
# The OpenMesh devices come with 2 main partitions - while one is active
# sysupgrade will flash the other. The boot order is changed to boot the
# newly flashed partition. If the new partition can't be booted due to
# upgrade failures the previously used partition is loaded.
cfg_value_get()
{
local cfg=$1 cfg_opt
local section=$2 our_section=0
local param=$3 our_param=
for cfg_opt in $cfg; do
[ "$cfg_opt" = "[$section]" ] && our_section=1 && continue
[ "$our_section" = "1" ] || continue
our_param=${cfg_opt%%=*}
[ "$param" = "$our_param" ] && echo ${cfg_opt##*=} && break
done
}
platform_do_upgrade_openmesh()
{
local img_path="$1"
local restore_backup
local setenv_script="/tmp/fw_env_upgrade"
local inactive_mtd="$(find_mtd_index $PART_NAME)"
local inactive_offset="$(cat /sys/class/mtd/mtd${inactive_mtd}/offset)"
local total_size="$(cat /sys/class/mtd/mtd${inactive_mtd}/size)"
local total_kbs=$((total_size / 1024))
local flash_start_mem=0x9f000000
local data_offset=$((64 * 1024))
# detect to which flash region the new image is written to.
#
# 1. check what is the mtd index for the first flash region on this
# device
# 2. check if the target partition ("inactive") has the mtd index of
# the first flash region
#
# - when it is: the new bootseq will be 1,2 and the first region is
# modified
# - when it isn't: bootseq will be 2,1 and the second region is
# modified
#
# The detection has to be done via the hardcoded mtd partition because
# the current boot might be done with the fallback region. Let us
# assume that the current bootseq is 1,2. The bootloader detected that
# the image in flash region 1 is corrupt and thus switches to flash
# region 2. The bootseq in the u-boot-env is now still the same and
# the sysupgrade code can now only rely on the actual mtd indexes and
# not the bootseq variable to detect the currently booted flash
# region/image.
#
# In the above example, an implementation which uses bootseq ("1,2") to
# detect the currently booted image would assume that region 1 is booted
# and then overwrite the variables for the wrong flash region (aka the
# one which isn't modified). This could result in a device which doesn't
# boot anymore to Linux until it was reflashed with ap51-flash.
local next_boot_part="1"
local primary_kernel_mtd="3"
[ "$inactive_mtd" = "$primary_kernel_mtd" ] || next_boot_part="2"
local cfg_size=$(dd if="$img_path" bs=8 skip=70 count=1 iflag=skip_bytes 2>/dev/null)
local cfg_length=$((0x$cfg_size))
local cfg_content=$(dd if="$img_path" bs=$cfg_length skip=$data_offset count=1 iflag=skip_bytes 2>/dev/null)
local kernel_size=$(dd if="$img_path" bs=8 skip=142 count=1 iflag=skip_bytes 2>/dev/null)
local kernel_length=$((0x$kernel_size))
local kernel_kbs=$((kernel_length / 1024))
local kernel_md5=$(cfg_value_get "$cfg_content" "vmlinux" "md5sum")
local rootfs_size=$(dd if="$img_path" bs=8 skip=214 count=1 iflag=skip_bytes 2>/dev/null)
local rootfs_length=$((0x$rootfs_size))
local rootfs_md5=$(cfg_value_get "$cfg_content" "rootfs" "md5sum")
local rootfs_checksize=$(cfg_value_get "$cfg_content" "rootfs" "checksize")
# take care of restoring a saved config
[ -n "$UPGRADE_BACKUP" ] && restore_backup="${MTD_CONFIG_ARGS} -j ${UPGRADE_BACKUP}"
# write image parts
mtd -q erase inactive
dd if="$img_path" bs=1 skip=$((data_offset + cfg_length + kernel_length)) count=$rootfs_length 2>&- | \
mtd -n -p $kernel_length $restore_backup write - $PART_NAME
dd if="$img_path" bs=1024 skip=$((data_offset + cfg_length)) count=$kernel_kbs iflag=skip_bytes 2>&- | \
mtd -n write - $PART_NAME
# prepare new u-boot env
if [ "$next_boot_part" = "1" ]; then
echo "bootseq 1,2" > $setenv_script
else
echo "bootseq 2,1" > $setenv_script
fi
printf "kernel_size_%i %i\n" $next_boot_part $kernel_kbs >> $setenv_script
printf "vmlinux_start_addr 0x%08x\n" $((flash_start_mem + inactive_offset)) >> $setenv_script
printf "vmlinux_size 0x%08x\n" ${kernel_length} >> $setenv_script
printf "vmlinux_checksum %s\n" ${kernel_md5} >> $setenv_script
printf "rootfs_size_%i %i\n" $next_boot_part $((total_kbs - kernel_kbs)) >> $setenv_script
printf "rootfs_start_addr 0x%08x\n" $((flash_start_mem+inactive_offset+kernel_length)) >> $setenv_script
printf "rootfs_size %s\n" $rootfs_checksize >> $setenv_script
printf "rootfs_checksum %s\n" ${rootfs_md5} >> $setenv_script
# store u-boot env changes
mkdir -p /var/lock
fw_setenv -s $setenv_script || {
echo "failed to update U-Boot environment"
return 1
}
}

View File

@@ -0,0 +1,119 @@
#
# Copyright (C) 2011 OpenWrt.org
#
PART_NAME=firmware
REQUIRE_IMAGE_METADATA=1
RAMFS_COPY_BIN='fw_printenv fw_setenv'
RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock'
platform_check_image() {
local board=$(board_name)
case "$board" in
jjplus,ja76pf2|\
ubnt,routerstation|\
ubnt,routerstation-pro)
platform_check_image_redboot_fis "$1"
;;
*)
return 0
;;
esac
}
platform_do_upgrade() {
local board=$(board_name)
case "$board" in
adtran,bsap1800-v2|\
adtran,bsap1840)
platform_do_upgrade_redboot_fis "$1" vmlinux_2
;;
allnet,all-wap02860ac|\
araknis,an-300-ap-i-n|\
araknis,an-500-ap-i-ac|\
araknis,an-700-ap-i-ac|\
engenius,eap1200h|\
engenius,eap1750h|\
engenius,eap300-v2|\
engenius,eap600|\
engenius,ecb600|\
engenius,ens1750|\
engenius,ens202ext-v1|\
engenius,enstationac-v1|\
engenius,ews660ap|\
watchguard,ap100|\
watchguard,ap200|\
watchguard,ap300)
ENV_SCRIPT="/tmp/fw_env"
IMAGE_LIST="tar tzf $1"
IMAGE_CMD="tar xzOf $1"
KERNEL_PART="loader"
ROOTFS_PART="fwconcat0"
KERNEL_FILE="uImage-lzma.bin"
ROOTFS_FILE="root.squashfs"
platform_do_upgrade_failsafe_datachk "$1"
;;
fortinet,fap-220-b|\
fortinet,fap-221-b)
SKIP_HASH="1"
ENV_SCRIPT="/dev/null"
IMAGE_LIST="tar tzf $1"
IMAGE_CMD="tar xzOf $1"
KERNEL_PART="loader"
ROOTFS_PART="fwconcat0"
KERNEL_FILE="uImage-lzma.bin"
ROOTFS_FILE="root.squashfs"
platform_do_upgrade_failsafe_datachk "$1"
;;
huawei,ap5030dn|\
huawei,ap6010dn)
# Store beginning address of the "firmware" partition
# as KernelA address and KernelB address, each to BootupA & BootupB
# This is the address from which the bootloader will try to load the kernel.
echo -n -e "\x9e\x10\x00\x00\x9e\x10\x00\x00" | dd of=$(find_mtd_part BootupA) bs=1 seek=$((0x254)) conv=notrunc
echo -n -e "\x9e\x10\x00\x00\x9e\x10\x00\x00" | dd of=$(find_mtd_part BootupB) bs=1 seek=$((0x254)) conv=notrunc
default_do_upgrade "$1"
;;
jjplus,ja76pf2)
platform_do_upgrade_redboot_fis "$1" linux
;;
openmesh,a40|\
openmesh,a60|\
openmesh,mr600-v1|\
openmesh,mr600-v2|\
openmesh,mr900-v1|\
openmesh,mr900-v2|\
openmesh,mr1750-v1|\
openmesh,mr1750-v2|\
openmesh,om2p-v1|\
openmesh,om2p-v2|\
openmesh,om2p-v4|\
openmesh,om2p-hs-v1|\
openmesh,om2p-hs-v2|\
openmesh,om2p-hs-v3|\
openmesh,om2p-hs-v4|\
openmesh,om2p-lc|\
openmesh,om5p|\
openmesh,om5p-ac-v1|\
openmesh,om5p-ac-v2|\
openmesh,om5p-an)
PART_NAME="inactive"
platform_do_upgrade_openmesh "$1"
;;
plasmacloud,pa300|\
plasmacloud,pa300e)
PART_NAME="inactive"
platform_do_upgrade_dualboot_datachk "$1"
;;
ubnt,routerstation|\
ubnt,routerstation-pro)
platform_do_upgrade_redboot_fis "$1" kernel
;;
*)
default_do_upgrade "$1"
;;
esac
}

View File

@@ -0,0 +1,31 @@
platform_check_image_redboot_fis() {
if [ "$(get_magic_word "$1")" != "7379" ]; then
v "Unknown image format, aborting!"
return 1
else
return 0
fi
}
platform_do_upgrade_redboot_fis() {
local append
local sysup_file="$1"
local kern_part="$2"
if [ "$(get_magic_word "$sysup_file")" = "7379" ]; then
local board_dir=$(tar tf $sysup_file | grep -m 1 '^sysupgrade-.*/$')
[ -f "$UPGRADE_BACKUP" ] && append="-j $UPGRADE_BACKUP"
if grep -q "mtd1.*loader" /proc/mtd; then
tar xf $sysup_file ${board_dir}kernel ${board_dir}root -O | \
mtd -r $append write - loader:firmware
else
local kern_length=$(tar xf $sysup_file ${board_dir}kernel -O | wc -c)
tar xf $sysup_file ${board_dir}kernel ${board_dir}root -O | \
mtd -r $append -F$kern_part:$kern_length:0x80060000,rootfs write - $kern_part:rootfs
fi
fi
}