1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter.git synced 2025-03-09 15:40:20 +00:00

Fix RUTX support

This commit is contained in:
Ycarus (Yannick Chabanois) 2022-03-07 20:21:35 +01:00
parent 6fc4d11e09
commit 0b14e36374
98 changed files with 11611 additions and 893 deletions

View file

@ -0,0 +1,40 @@
. /usr/share/libubox/jshn.sh
# when device contains 2 internal modems, this function will return '2' if
# selected modem(inc_id) is builtin and primary.
# And if it's only builtin, then '1'
is_builtin_modem() {
local inc_id="$1"
local modem modems id builtin primary
json_init
json_load_file "/etc/board.json"
json_get_keys modems modems
json_select modems
for modem in $modems; do
json_select "$modem"
json_get_vars id builtin primary
[ "$id" = "$inc_id" ] && {
[ -n "$builtin" ] && {
[ -n "$primary" ] && {
echo 2
return
}
echo 1
return
}
echo 0
return
}
json_select ..
done
echo 0
}

View file

@ -0,0 +1,171 @@
# Copyright (C) 2019 OpenWrt.org
. /lib/functions.sh
. /lib/functions/system.sh
caldata_dd() {
local source=$1
local target=$2
local count=$(($3))
local offset=$(($4))
dd if=$source of=$target iflag=skip_bytes,fullblock bs=$count skip=$offset count=1 2>/dev/null
return $?
}
caldata_die() {
echo "caldata: " "$*"
exit 1
}
caldata_extract() {
local part=$1
local offset=$(($2))
local count=$(($3))
local mtd
mtd=$(find_mtd_chardev $part)
[ -n "$mtd" ] || caldata_die "no mtd device found for partition $part"
caldata_dd $mtd /lib/firmware/$FIRMWARE $count $offset || \
caldata_die "failed to extract calibration data from $mtd"
}
caldata_extract_ubi() {
local part=$1
local offset=$(($2))
local count=$(($3))
local ubidev
local ubi
. /lib/upgrade/nand.sh
ubidev=$(nand_find_ubi $CI_UBIPART)
ubi=$(nand_find_volume $ubidev $part)
[ -n "$ubi" ] || caldata_die "no UBI volume found for $part"
caldata_dd /dev/$ubi /lib/firmware/$FIRMWARE $count $offset || \
caldata_die "failed to extract calibration data from $ubi"
}
caldata_extract_reverse() {
local part=$1
local offset=$2
local count=$(($3))
local mtd
local reversed
local caldata
mtd=$(find_mtd_chardev "$part")
reversed=$(hexdump -v -s $offset -n $count -e '/1 "%02x "' $mtd)
for byte in $reversed; do
caldata="\x${byte}${caldata}"
done
printf "%b" "$caldata" > /lib/firmware/$FIRMWARE
}
caldata_from_file() {
local source=$1
local offset=$(($2))
local count=$(($3))
local target=$4
[ -n "$target" ] || target=/lib/firmware/$FIRMWARE
caldata_dd $source $target $count $offset || \
caldata_die "failed to extract calibration data from $source"
}
caldata_sysfsload_from_file() {
local source=$1
local offset=$(($2))
local count=$(($3))
local target_dir="/sys/$DEVPATH"
local target="$target_dir/data"
[ -d "$target_dir" ] || \
caldata_die "no sysfs dir to write: $target"
echo 1 > "$target_dir/loading"
caldata_dd $source $target $count $offset
if [ $? != 0 ]; then
echo 1 > "$target_dir/loading"
caldata_die "failed to extract calibration data from $source"
else
echo 0 > "$target_dir/loading"
fi
}
caldata_valid() {
local expected="$1"
local target=$2
[ -n "$target" ] || target=/lib/firmware/$FIRMWARE
magic=$(hexdump -v -n 2 -e '1/1 "%02x"' $target)
[ "$magic" = "$expected" ]
return $?
}
caldata_patch_chksum() {
local mac=$1
local mac_offset=$(($2))
local chksum_offset=$(($3))
local target=$4
local xor_mac
local xor_fw_mac
local xor_fw_chksum
xor_mac=${mac//:/}
xor_mac="${xor_mac:0:4} ${xor_mac:4:4} ${xor_mac:8:4}"
xor_fw_mac=$(hexdump -v -n 6 -s $mac_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE)
xor_fw_mac="${xor_fw_mac:0:4} ${xor_fw_mac:4:4} ${xor_fw_mac:8:4}"
xor_fw_chksum=$(hexdump -v -n 2 -s $chksum_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE)
xor_fw_chksum=$(xor $xor_fw_chksum $xor_fw_mac $xor_mac)
printf "%b" "\x${xor_fw_chksum:0:2}\x${xor_fw_chksum:2:2}" | \
dd of=$target conv=notrunc bs=1 seek=$chksum_offset count=2
}
caldata_patch_mac() {
local mac=$1
local mac_offset=$(($2))
local chksum_offset=$3
local target=$4
[ -z "$mac" -o -z "$mac_offset" ] && return
[ -n "$target" ] || target=/lib/firmware/$FIRMWARE
[ -n "$chksum_offset" ] && caldata_patch_chksum "$mac" "$mac_offset" "$chksum_offset" "$target"
macaddr_2bin $mac | dd of=$target conv=notrunc oflag=seek_bytes bs=6 seek=$mac_offset count=1 || \
caldata_die "failed to write MAC address to eeprom file"
}
ath9k_patch_mac() {
local mac=$1
local target=$2
caldata_patch_mac "$mac" 0x2 "" "$target"
}
ath9k_patch_mac_crc() {
local mac=$1
local mac_offset=$2
local chksum_offset=$((mac_offset - 10))
local target=$4
caldata_patch_mac "$mac" "$mac_offset" "$chksum_offset" "$target"
}
ath10k_patch_mac() {
local mac=$1
local target=$2
caldata_patch_mac "$mac" 0x6 0x2 "$target"
}

View file

@ -0,0 +1,94 @@
# Copyright (C) 2013 OpenWrt.org
get_dt_led_path() {
local ledpath
local basepath="/proc/device-tree"
local nodepath="$basepath/aliases/led-$1"
[ -f "$nodepath" ] && ledpath=$(cat "$nodepath")
[ -n "$ledpath" ] && ledpath="$basepath$ledpath"
echo "$ledpath"
}
get_dt_led() {
local label
local ledpath=$(get_dt_led_path $1)
[ -n "$ledpath" ] && \
label=$(cat "$ledpath/label" 2>/dev/null) || \
label=$(cat "$ledpath/chan-name" 2>/dev/null) || \
label=$(basename "$ledpath")
echo "$label"
}
led_set_attr() {
[ -f "/sys/class/leds/$1/$2" ] && echo "$3" > "/sys/class/leds/$1/$2"
}
led_timer() {
led_set_attr $1 "trigger" "timer"
led_set_attr $1 "delay_on" "$2"
led_set_attr $1 "delay_off" "$3"
}
led_on() {
led_set_attr $1 "trigger" "none"
led_set_attr $1 "brightness" 255
}
led_off() {
led_set_attr $1 "trigger" "none"
led_set_attr $1 "brightness" 0
}
status_led_restore_trigger() {
local trigger
local ledpath=$(get_dt_led_path $1)
[ -n "$ledpath" ] && \
trigger=$(cat "$ledpath/linux,default-trigger" 2>/dev/null)
[ -n "$trigger" ] && \
led_set_attr "$(get_dt_led $1)" "trigger" "$trigger"
}
status_led_set_timer() {
led_timer $status_led "$1" "$2"
[ -n "$status_led2" ] && led_timer $status_led2 "$1" "$2"
}
status_led_set_heartbeat() {
led_set_attr $status_led "trigger" "heartbeat"
}
status_led_on() {
led_on $status_led
[ -n "$status_led2" ] && led_on $status_led2
}
status_led_off() {
led_off $status_led
[ -n "$status_led2" ] && led_off $status_led2
}
status_led_blink_slow() {
led_timer $status_led 1000 1000
}
status_led_blink_fast() {
led_timer $status_led 100 100
}
status_led_blink_preinit() {
led_timer $status_led 100 100
}
status_led_blink_failsafe() {
led_timer $status_led 50 50
}
status_led_blink_preinit_regular() {
led_timer $status_led 200 200
}

View file

@ -0,0 +1,196 @@
#!/bin/sh
. /lib/functions.sh
. /usr/share/libubox/jshn.sh
CFG_PATH="/etc/config/"
get_section_name() {
local ___var="$1"
[ "$#" -ge 1 ] && shift
local ___type="$1"
[ "$#" -ge 1 ] && shift
local section cfgtype
[ -z "$CONFIG_SECTIONS" ] && return 0
for section in ${CONFIG_SECTIONS}; do
config_get cfgtype "$section" TYPE
[ -n "$___type" -a "x$cfgtype" != "x$___type" ] && continue
eval export "${___var}=\${section}"
return 0
done
}
_set_option() {
local option="$1"
local value="$2"
uci_set "$_NEW_CONFIG" "$_NEW_SEC_NAME" "$option" "$value"
}
_set_list_option() {
local option="$1"
local value="$2"
for element in $value; do
uci_add_list "$_NEW_CONFIG" "$_NEW_SEC_NAME" "$option" "$element"
done
}
_del_uci_element() {
local section="$1"
local option="$2"
uci_remove "$_OLD_CONFIG" "$section" "$option"
}
_option_cond_cb() {
local value=$3
json_select $2
json_get_var old 1
json_get_var new 2
[ "$old" = "$value" ] && _COND_VALUE="$new"
json_select ..
}
_parse_condition(){
local value="$1"
_COND_VALUE=
json_for_each_item _option_cond_cb "if" "$value"
}
_option_rule_cb(){
local rule="$1"
local option="$2"
local value
[ -n "$rule" ] || return 0
json_select "$option"
json_get_vars new_name "if" default cb type
if [ -n "$cb" ]; then
eval "$cb \"\$option\" \"\$_OLD_SEC_NAME\" \"\$_NEW_SEC_NAME\""
[ "$?" -eq 0 ] && {
json_select ..
return 0
}
value="$_OPTION_VALUE"
else
config_get value $_OLD_SEC_NAME "$option" "$default"
fi
[ -n "$if" ] && {
_parse_condition "$value"
value="${_COND_VALUE:-${value:-$default}}"
}
if [ -n "$type" -a "$type" = "list" ]; then
_set_list_option "${new_name:-$option}" "$value"
else
_set_option "${new_name:-$option}" "$value"
fi
json_select ..
}
_init_section() {
local sec_t
json_get_vars old_name new_name new_type old_type
[ -n "$old_name" -o -n "$old_type" ] || return 1
if [ -z "$old_name" ]; then
get_section_name _OLD_SEC_NAME "$old_type"
else
_OLD_SEC_NAME=$old_name
fi
_NEW_SEC_NAME=$new_name
_OLD_SEC_TYPE=$old_type
_NEW_SEC_TYPE=${new_type:-$old_type}
[ -n "$_NEW_SEC_TYPE" ] || \
eval "_NEW_SEC_TYPE=\$CONFIG_${_OLD_SEC_NAME}_TYPE"
if [ -n "$_NEW_SEC_NAME" ]; then
uci set "$_NEW_CONFIG"."$_NEW_SEC_NAME"="$_NEW_SEC_TYPE"
else
_NEW_SEC_NAME="$(uci -q add "$_NEW_CONFIG" "$_NEW_SEC_TYPE")"
fi
[ -n "$_NEW_SEC_NAME" ] || return 1
}
_section_rule_cb(){
local rule="$1"
local section="$2"
local value
[ -n "$rule" ] || return 0
json_select "$section"
json_get_vars cb old_name new_name new_type old_type remove
[ -n "$cb" ] && {
eval "$cb \"\$old_name\" \"\$new_name\" \"\$old_type\" \"\$new_type\""
[ "$?" -eq 0 ] && {
json_select ..
return 0
}
}
_init_section
[ $? -ne 0 ] && {
logger -t "Migration" "Unable to init section"
json_select ..
return 1
}
json_for_each_item _option_rule_cb options
json_select ..
[ -n "$remove" ] && {
_del_uci_element "$old_name"
uci_commit "$_OLD_CONFIG"
}
}
_init_config() {
json_select config
json_get_vars old_name new_name
[ -n "$old_name" ] || return 1
[ -f "$CFG_PATH$old_name" ] || return 1
[ -f "$CFG_PATH$new_name" ] || touch $CFG_PATH$new_name
config_load "$old_name"
_NEW_CONFIG="${new_name:-$old_name}"
_OLD_CONFIG="$old_name"
json_select ..
}
migrate() {
local remove
local json_file="$1"
[ -f "$json_file" ] || return 0
json_init
json_load_file "$json_file"
json_select
_init_config
[ $? -ne 0 ] && {
logger -t "Migration" "Unable to load config"
return 1
}
json_for_each_item _section_rule_cb sections
uci_commit "$_NEW_CONFIG"
json_get_vars remove
[ -n "$remove" ] && rm "$CFG_PATH$_OLD_CONFIG"
}

View file

@ -0,0 +1,67 @@
. /lib/functions.sh
migrate_led_sysfs() {
local cfg="$1"; shift
local tuples="$@"
local sysfs
local name
config_get sysfs ${cfg} sysfs
config_get name ${cfg} name
[ -z "${sysfs}" ] && return
for tuple in ${tuples}; do
local old=${tuple%=*}
local new=${tuple#*=}
local new_sysfs
new_sysfs=$(echo ${sysfs} | sed "s/${old}/${new}/")
[ "${new_sysfs}" = "${sysfs}" ] && continue
uci set system.${cfg}.sysfs="${new_sysfs}"
logger -t led-migration "sysfs option of LED \"${name}\" updated to ${new_sysfs}"
done;
}
remove_devicename_led_sysfs() {
local cfg="$1"; shift
local exceptions="$@"
local sysfs
local name
local new_sysfs
config_get sysfs ${cfg} sysfs
config_get name ${cfg} name
# only continue if two or more colons are present
echo "${sysfs}" | grep -q ":.*:" || return
for exception in ${exceptions}; do
# no change if exceptions provided as argument are found for devicename
echo "${sysfs}" | grep -q "^${exception}:" && return
done
new_sysfs=$(echo ${sysfs} | sed "s/^[^:]*://")
uci set system.${cfg}.sysfs="${new_sysfs}"
logger -t led-migration "sysfs option of LED \"${name}\" updated to ${new_sysfs}"
}
migrate_leds() {
config_load system
config_foreach migrate_led_sysfs led "$@"
}
remove_devicename_leds() {
config_load system
config_foreach remove_devicename_led_sysfs led "$@"
}
migrations_apply() {
local realm="$1"
[ -n "$(uci changes ${realm})" ] && uci -q commit ${realm}
}

View file

@ -0,0 +1,247 @@
#Mobile configuration management lib
. /usr/share/libubox/jshn.sh
. /lib/functions.sh
gsm_soft_reset() {
gsmctl -n -A at+cfun=4
sleep 2
gsmctl -n -A at+cfun=1
}
qmi_error_handle() {
local error="$1"
local modem_id="$2"
$(echo "$error" | grep -q "error") && {
echo "$error"
}
$(echo "$error" | grep -q "Client IDs exhausted") && {
echo "ClientIdsExhausted! reseting counter..."
proto_notify_error "$interface" NO_CID
uqmi -s -d "$device" --sync
return 1
}
# Reik papildyt ERROR handlinima
# $(echo "$error" | grep -q "multiple-connection-to-same-pdn-not-allowed") && {
# echo "Reseting due dublicated connection..."
# qmicli -p -d "$device" --uim-sim-power-off=1
# qmicli -p -d "$device" --uim-sim-power-on=1
# return 1
# }
# $(echo "$error" | grep -q "Transaction timed out") && {
# echo "Device not responding, restarting module"
# gsmctl -O $modem_id -A at+cfun=1,1
# }
#
# $(echo "$error" | grep -q 'verbose call end reason (2,236)') && {
# echo "Failed to start network, clearing all cids"
# qmicli -p -d "$device" --wds-noop --device-open-sync
# return 1
# }
$(echo "$error" | grep -q "Call Failed") && {
echo "Device not responding, restarting module"
sleep 10
gsm_soft_reset
return 1
}
$(echo "$error" | grep -q "Policy Mismatch") && {
echo "Reseting network..."
gsm_soft_reset
return 1
}
$(echo "$error" | grep -q "Failed to connect to service") && {
echo "Device not responding, restarting module"
gsmctl -A at+cfun=1,1
return 1
}
$(echo "$error" | grep -q "error") && {
echo "$error"
}
return 0
}
passthrough_mode=
get_passthrough() {
config_get primary "$1" primary
[ "$primary" = "1" ] && {
config_get sim "$1" position;
passthrough_mode=$(uci -q get network.mob1s${sim}a1.passthrough_mode 2>/dev/null);
}
}
setup_bridge_v4() {
local dev="$1"
local dhcp_param_file="/tmp/dnsmasq.d/bridge"
echo "$parameters4"
json_load "$parameters4"
json_select "ipv4"
json_get_var bridge_ipaddr ip
json_get_var bridge_mask subnet
json_get_var bridge_gateway gateway
json_get_var bridge_dns1 dns1
json_get_var bridge_dns2 dns2
json_init
json_add_string name "${interface}_4"
json_add_string ifname "$dev"
json_add_string proto "none"
json_add_object "data"
ubus call network add_dynamic "$(json_dump)"
IFACE4="${interface}_4"
json_init
json_add_string interface "${interface}_4"
json_add_string zone "lan"
ubus call network.interface set_data "$(json_dump)"
json_init
json_add_string interface "${interface}"
json_add_string bridge_ipaddr "$bridge_ipaddr"
ubus call network.interface set_data "$(json_dump)"
json_init
json_add_string modem "$modem"
json_add_string sim "$sim"
ubus call network.interface."${interface}_4" set_data "$(json_dump)"
json_close_object
ip route add default dev "$dev" table 42
ip route add default dev br-lan table 43
ip route add "$bridge_ipaddr" dev br-lan
ip rule add pref 5042 from "$bridge_ipaddr" lookup 42
ip rule add pref 5043 iif "$dev" lookup 43
#sysctl -w net.ipv4.conf.br-lan.proxy_arp=1 #2>/dev/null
ip neighbor add proxy "$bridge_gateway" dev br-lan
iptables -A postrouting_rule -m comment --comment "Bridge mode" -o "$dev" -j ACCEPT -tnat
config_load simcard
config_foreach get_passthrough sim
> $dhcp_param_file
[ -z "$mac" ] && mac="*:*:*:*:*:*"
[ "$passthrough_mode" != "no_dhcp" ] && {
echo "dhcp-range=tag:mobbridge,$bridge_ipaddr,static,$bridge_mask,${leasetime:-1h}" > "$dhcp_param_file"
echo "shared-network=br-lan,$bridge_ipaddr" >> "$dhcp_param_file"
echo "dhcp-host=$mac,set:mobbridge,$bridge_ipaddr" >> "$dhcp_param_file"
echo "dhcp-option=tag:mobbridge,br-lan,3,$bridge_gateway" >> "$dhcp_param_file"
echo "dhcp-option=tag:mobbridge,br-lan,6,$bridge_dns1,$bridge_dns2" >> "$dhcp_param_file"
echo "server=$bridge_dns1" >> "$dhcp_param_file"
echo "server=$bridge_dns2" >> "$dhcp_param_file"
}
/etc/init.d/dnsmasq reload
swconfig dev 'switch0' set soft_reset 5 &
}
setup_static_v4() {
local dev="$1"
echo "Setting up $dev V4 static"
echo "$parameters4"
json_load "$parameters4"
json_select "ipv4"
json_get_var ip_4 ip
json_get_var dns1_4 dns1
json_get_var dns2_4 dns2
json_init
json_add_string name "${interface}_4"
json_add_string ifname "$dev"
json_add_string proto static
json_add_string gateway "0.0.0.0"
json_add_array ipaddr
json_add_string "" "$ip_4"
json_close_array
json_add_array dns
[ -n "$dns1_4" ] && json_add_string "" "$dns1_4"
[ -n "$dns2_4" ] && json_add_string "" "$dns2_4"
json_close_array
[ -n "$ip4table" ] && json_add_string ip4table "$ip4table"
proto_add_dynamic_defaults
ubus call network add_dynamic "$(json_dump)"
}
setup_dhcp_v4() {
local dev="$1"
echo "Setting up $dev V4 DCHP"
json_init
json_add_string name "${interface}_4"
json_add_string ifname "$dev"
json_add_string proto "dhcp"
json_add_string script "/lib/netifd/dhcp_mobile.script"
[ -n "$ip4table" ] && json_add_string ip4table "$ip4table"
proto_add_dynamic_defaults
[ -n "$zone" ] && json_add_string zone "$zone"
ubus call network add_dynamic "$(json_dump)"
}
setup_dhcp_v6() {
local dev="$1"
echo "Setting up $dev V6 DHCP"
json_init
json_add_string name "${interface}_6"
json_add_string ifname "$dev"
json_add_string proto "dhcpv6"
[ -n "$ip6table" ] && json_add_string ip6table "$ip6table"
json_add_boolean ignore_valid 1
proto_add_dynamic_defaults
# RFC 7278: Extend an IPv6 /64 Prefix to LAN
json_add_string extendprefix 1
[ -n "$zone" ] && json_add_string zone "$zone"
ubus call network add_dynamic "$(json_dump)"
}
setup_static_v6() {
local dev="$1"
echo "Setting up $dev V6 static"
echo "$parameters6"
json_load "$parameters6"
json_select "ipv6"
json_get_var ip6_with_prefix ip
ip_6="${ip6_with_prefix%/*}"
ip_prefix_length="${ip6_with_prefix#*/}"
json_get_var ip6_gateway_with_prefix gateway
gateway_6="${ip6_gateway_with_prefix%/*}"
json_get_var dns1_6 dns1
json_get_var dns2_6 dns2
json_init
json_add_string name "${interface}_6"
json_add_string ifname "$dev"
json_add_string proto static
json_add_string ip6gw "$gateway_6"
json_add_array ip6prefix
json_add_string "" "$ip6_with_prefix"
json_close_array
json_add_array ip6addr
json_add_string "" "$ip6_with_prefix"
json_close_array
json_add_array dns
[ -n "$dns1_6" ] && json_add_string "" "$dns1_6"
[ -n "$dns2_6" ] && json_add_string "" "$dns2_6"
json_close_array
[ -n "$ip6table" ] && json_add_string ip6table "$ip6table"
proto_add_dynamic_defaults
ubus call network add_dynamic "$(json_dump)"
}

View file

@ -0,0 +1,313 @@
# 1: destination variable
# 2: interface
# 3: path
# 4: separator
# 5: limit
__network_ifstatus() {
local __tmp
[ -z "$__NETWORK_CACHE" ] && {
__tmp="$(ubus call network.interface dump 2>&1)"
case "$?" in
4) : ;;
0) export __NETWORK_CACHE="$__tmp" ;;
*) echo "$__tmp" >&2 ;;
esac
}
__tmp="$(jsonfilter ${4:+-F "$4"} ${5:+-l "$5"} -s "${__NETWORK_CACHE:-{}}" -e "$1=@.interface${2:+[@.interface='$2']}$3")"
[ -z "$__tmp" ] && \
unset "$1" && \
return 1
eval "$__tmp"
}
# determine first IPv4 address of given logical interface
# 1: destination variable
# 2: interface
network_get_ipaddr() {
__network_ifstatus "$1" "$2" "['ipv4-address'][0].address";
}
# determine first IPv6 address of given logical interface
# 1: destination variable
# 2: interface
network_get_ipaddr6() {
__network_ifstatus "$1" "$2" "['ipv6-address'][0].address" || \
__network_ifstatus "$1" "$2" "['ipv6-prefix-assignment'][0]['local-address'].address" || \
return 1
}
# determine first IPv4 subnet of given logical interface
# 1: destination variable
# 2: interface
network_get_subnet() {
__network_ifstatus "$1" "$2" "['ipv4-address'][0]['address','mask']" "/"
}
# determine first IPv6 subnet of given logical interface
# 1: destination variable
# 2: interface
network_get_subnet6() {
local __nets __addr
if network_get_subnets6 __nets "$2"; then
# Attempt to return first non-fe80::/10, non-fc::/7 range
for __addr in $__nets; do
case "$__addr" in fe[8ab]?:*|f[cd]??:*)
continue
esac
export "$1=$__addr"
return 0
done
# Attempt to return first non-fe80::/10 range
for __addr in $__nets; do
case "$__addr" in fe[8ab]?:*)
continue
esac
export "$1=$__addr"
return 0
done
# Return first item
for __addr in $__nets; do
export "$1=$__addr"
return 0
done
fi
unset "$1"
return 1
}
# determine first IPv6 prefix of given logical interface
# 1: destination variable
# 2: interface
network_get_prefix6() {
__network_ifstatus "$1" "$2" "['ipv6-prefix'][0]['address','mask']" "/"
}
# determine all IPv4 addresses of given logical interface
# 1: destination variable
# 2: interface
network_get_ipaddrs() {
__network_ifstatus "$1" "$2" "['ipv4-address'][*].address"
}
# determine all IPv6 addresses of given logical interface
# 1: destination variable
# 2: interface
network_get_ipaddrs6() {
local __addr
local __list=""
if __network_ifstatus "__addr" "$2" "['ipv6-address'][*].address"; then
for __addr in $__addr; do
__list="${__list:+$__list }${__addr}"
done
fi
if __network_ifstatus "__addr" "$2" "['ipv6-prefix-assignment'][*]['local-address'].address"; then
for __addr in $__addr; do
__list="${__list:+$__list }${__addr}"
done
fi
if [ -n "$__list" ]; then
export "$1=$__list"
return 0
fi
unset "$1"
return 1
}
# determine all IP addresses of given logical interface
# 1: destination variable
# 2: interface
network_get_ipaddrs_all() {
local __addr __addr6
network_get_ipaddrs __addr "$2"
network_get_ipaddrs6 __addr6 "$2"
if [ -n "$__addr" -o -n "$__addr6" ]; then
export "$1=${__addr:+$__addr }$__addr6"
return 0
fi
unset "$1"
return 1
}
# determine all IPv4 subnets of given logical interface
# 1: destination variable
# 2: interface
network_get_subnets() {
__network_ifstatus "$1" "$2" "['ipv4-address'][*]['address','mask']" "/ "
}
# determine all IPv6 subnets of given logical interface
# 1: destination variable
# 2: interface
network_get_subnets6() {
local __addr __mask
local __list=""
if __network_ifstatus "__addr" "$2" "['ipv6-address'][*]['address','mask']" "/ "; then
for __addr in $__addr; do
__list="${__list:+$__list }${__addr}"
done
fi
if __network_ifstatus "__addr" "$2" "['ipv6-prefix-assignment'][*]['local-address'].address" && \
__network_ifstatus "__mask" "$2" "['ipv6-prefix-assignment'][*].mask"; then
for __addr in $__addr; do
__list="${__list:+$__list }${__addr}/${__mask%% *}"
__mask="${__mask#* }"
done
fi
if [ -n "$__list" ]; then
export "$1=$__list"
return 0
fi
unset "$1"
return 1
}
# determine all IPv6 prefixes of given logical interface
# 1: destination variable
# 2: interface
network_get_prefixes6() {
__network_ifstatus "$1" "$2" "['ipv6-prefix'][*]['address','mask']" "/ "
}
# determine IPv4 gateway of given logical interface
# 1: destination variable
# 2: interface
# 3: consider inactive gateway if "true" (optional)
network_get_gateway() {
__network_ifstatus "$1" "$2" ".route[@.target='0.0.0.0' && !@.table].nexthop" "" 1 && \
return 0
[ "$3" = 1 -o "$3" = "true" ] && \
__network_ifstatus "$1" "$2" ".inactive.route[@.target='0.0.0.0' && !@.table].nexthop" "" 1
}
# determine IPv6 gateway of given logical interface
# 1: destination variable
# 2: interface
# 3: consider inactive gateway if "true" (optional)
network_get_gateway6() {
__network_ifstatus "$1" "$2" ".route[@.target='::' && !@.table].nexthop" "" 1 && \
return 0
[ "$3" = 1 -o "$3" = "true" ] && \
__network_ifstatus "$1" "$2" ".inactive.route[@.target='::' && !@.table].nexthop" "" 1
}
# determine the DNS servers of the given logical interface
# 1: destination variable
# 2: interface
# 3: consider inactive servers if "true" (optional)
network_get_dnsserver() {
__network_ifstatus "$1" "$2" "['dns-server'][*]" && return 0
[ "$3" = 1 -o "$3" = "true" ] && \
__network_ifstatus "$1" "$2" ".inactive['dns-server'][*]"
}
# determine the domains of the given logical interface
# 1: destination variable
# 2: interface
# 3: consider inactive domains if "true" (optional)
network_get_dnssearch() {
__network_ifstatus "$1" "$2" "['dns-search'][*]" && return 0
[ "$3" = 1 -o "$3" = "true" ] && \
__network_ifstatus "$1" "$2" ".inactive['dns-search'][*]"
}
# 1: destination variable
# 2: addr
# 3: inactive
# 4: limit
__network_wan()
{
limit=1
[ -n "$4" ] && limit="$4"
__network_ifstatus "$1" "" \
"[@.route[@.target='$2' && !@.table]].interface" "" $limit && \
return 0
[ "$3" = 1 -o "$3" = "true" ] && \
__network_ifstatus "$1" "" \
"[@.inactive.route[@.target='$2' && !@.table]].interface" "" $limit
}
# find the logical interface which holds the current IPv4 default route
# 1: destination variable
# 2: consider inactive default routes if "true" (optional)
network_find_wan() { __network_wan "$1" "0.0.0.0" "$2" "$3"; }
# find the logical interface which holds the current IPv6 default route
# 1: destination variable
# 2: consider inactive default routes if "true" (optional)
network_find_wan6() { __network_wan "$1" "::" "$2"; }
# test whether the given logical interface is running
# 1: interface
network_is_up()
{
local __up
__network_ifstatus "__up" "$1" ".up" && [ "$__up" = 1 ]
}
# determine the protocol of the given logical interface
# 1: destination variable
# 2: interface
network_get_protocol() { __network_ifstatus "$1" "$2" ".proto"; }
# determine the uptime of the given logical interface
# 1: destination variable
# 2: interface
network_get_uptime() { __network_ifstatus "$1" "$2" ".uptime"; }
# determine the metric of the given logical interface
# 1: destination variable
# 2: interface
network_get_metric() { __network_ifstatus "$1" "$2" ".metric"; }
# determine the layer 3 linux network device of the given logical interface
# 1: destination variable
# 2: interface
network_get_device() { __network_ifstatus "$1" "$2" ".l3_device"; }
# determine the layer 2 linux network device of the given logical interface
# 1: destination variable
# 2: interface
network_get_physdev() { __network_ifstatus "$1" "$2" ".device"; }
# defer netifd actions on the given linux network device
# 1: device name
network_defer_device()
{
ubus call network.device set_state \
"$(printf '{ "name": "%s", "defer": true }' "$1")" 2>/dev/null
}
# continue netifd actions on the given linux network device
# 1: device name
network_ready_device()
{
ubus call network.device set_state \
"$(printf '{ "name": "%s", "defer": false }' "$1")" 2>/dev/null
}
# flush the internal value cache to force re-reading values from ubus
network_flush_cache() { unset __NETWORK_CACHE; }

View file

@ -0,0 +1,87 @@
# Copyright (C) 2006-2013 OpenWrt.org
# Copyright (C) 2010 Vertical Communications
boot_hook_splice_start() {
export -n PI_HOOK_SPLICE=1
}
boot_hook_splice_finish() {
local hook
for hook in $PI_STACK_LIST; do
local v; eval "v=\${${hook}_splice:+\$${hook}_splice }$hook"
export -n "${hook}=${v% }"
export -n "${hook}_splice="
done
export -n PI_HOOK_SPLICE=
}
boot_hook_init() {
local hook="${1}_hook"
export -n "PI_STACK_LIST=${PI_STACK_LIST:+$PI_STACK_LIST }$hook"
export -n "$hook="
}
boot_hook_add() {
local hook="${1}_hook${PI_HOOK_SPLICE:+_splice}"
local func="${2}"
[ -n "$func" ] && {
local v; eval "v=\$$hook"
export -n "$hook=${v:+$v }$func"
}
}
boot_hook_shift() {
local hook="${1}_hook"
local rvar="${2}"
local v; eval "v=\$$hook"
[ -n "$v" ] && {
local first="${v%% *}"
[ "$v" != "${v#* }" ] && \
export -n "$hook=${v#* }" || \
export -n "$hook="
export -n "$rvar=$first"
return 0
}
return 1
}
boot_run_hook() {
local hook="$1"
local func
while boot_hook_shift "$hook" func; do
local ran; eval "ran=\$PI_RAN_$func"
[ -n "$ran" ] || {
export -n "PI_RAN_$func=1"
$func "$1" "$2"
}
done
}
pivot() { # <new_root> <old_root>
/bin/mount -o noatime,move /proc $1/proc && \
pivot_root $1 $1$2 && {
/bin/mount -o noatime,move $2/dev /dev
/bin/mount -o noatime,move $2/tmp /tmp
/bin/mount -o noatime,move $2/sys /sys 2>&-
/bin/mount -o noatime,move $2/overlay /overlay 2>&-
return 0
}
}
fopivot() { # <rw_root> <work_dir> <ro_root> <dupe?>
/bin/mount -o noatime,lowerdir=/,upperdir=$1,workdir=$2 -t overlay "overlayfs:$1" /mnt
pivot /mnt $3
}
ramoverlay() {
mkdir -p /tmp/root
/bin/mount -t tmpfs -o noatime,mode=0755 root /tmp/root
mkdir -p /tmp/root/root /tmp/root/work
fopivot /tmp/root/root /tmp/root/work /rom 1
}

View file

@ -0,0 +1,103 @@
#
# service: simple wrapper around start-stop-daemon
#
# Usage: service ACTION EXEC ARGS...
#
# Action:
# -C check if EXEC is alive
# -S start EXEC, passing it ARGS as its arguments
# -K kill EXEC, sending it a TERM signal if not specified otherwise
#
# Environment variables exposed:
# SERVICE_DAEMONIZE run EXEC in background
# SERVICE_WRITE_PID create a pid-file and use it for matching
# SERVICE_MATCH_EXEC use EXEC command-line for matching (default)
# SERVICE_MATCH_NAME use EXEC process name for matching
# SERVICE_USE_PID assume EXEC create its own pid-file and use it for matching
# SERVICE_NAME process name to use (default to EXEC file part)
# SERVICE_PID_FILE pid file to use (default to /var/run/$SERVICE_NAME.pid)
# SERVICE_SIG signal to send when using -K
# SERVICE_SIG_RELOAD default signal used when reloading
# SERVICE_SIG_STOP default signal used when stopping
# SERVICE_STOP_TIME time to wait for a process to stop gracefully before killing it
# SERVICE_UID user EXEC should be run as
# SERVICE_GID group EXEC should be run as
#
# SERVICE_DEBUG don't do anything, but show what would be done
# SERVICE_QUIET don't print anything
#
SERVICE_QUIET=1
SERVICE_SIG_RELOAD="HUP"
SERVICE_SIG_STOP="TERM"
SERVICE_STOP_TIME=5
SERVICE_MATCH_EXEC=1
service() {
local ssd
local exec
local name
local start
ssd="${SERVICE_DEBUG:+echo }start-stop-daemon${SERVICE_QUIET:+ -q}"
case "$1" in
-C)
ssd="$ssd -K -t"
;;
-S)
ssd="$ssd -S${SERVICE_DAEMONIZE:+ -b}${SERVICE_WRITE_PID:+ -m}"
start=1
;;
-K)
ssd="$ssd -K${SERVICE_SIG:+ -s $SERVICE_SIG}"
;;
*)
echo "service: unknown ACTION '$1'" 1>&2
return 1
esac
shift
exec="$1"
[ -n "$exec" ] || {
echo "service: missing argument" 1>&2
return 1
}
[ -x "$exec" ] || {
echo "service: file '$exec' is not executable" 1>&2
return 1
}
name="${SERVICE_NAME:-${exec##*/}}"
[ -z "$SERVICE_USE_PID$SERVICE_WRITE_PID$SERVICE_PID_FILE" ] \
|| ssd="$ssd -p ${SERVICE_PID_FILE:-/var/run/$name.pid}"
[ -z "$SERVICE_MATCH_NAME" ] || ssd="$ssd -n $name"
ssd="$ssd${SERVICE_UID:+ -c $SERVICE_UID${SERVICE_GID:+:$SERVICE_GID}}"
[ -z "$SERVICE_MATCH_EXEC$start" ] || ssd="$ssd -x $exec"
shift
$ssd${1:+ -- "$@"}
}
service_check() {
service -C "$@"
}
service_signal() {
SERVICE_SIG="${SERVICE_SIG:-USR1}" service -K "$@"
}
service_start() {
service -S "$@"
}
service_stop() {
local try
SERVICE_SIG="${SERVICE_SIG:-$SERVICE_SIG_STOP}" service -K "$@" || return 1
while [ $((try++)) -lt $SERVICE_STOP_TIME ]; do
service -C "$@" || return 0
sleep 1
done
SERVICE_SIG="KILL" service -K "$@"
sleep 1
! service -C "$@"
}
service_reload() {
SERVICE_SIG="${SERVICE_SIG:-$SERVICE_SIG_RELOAD}" service -K "$@"
}

View file

@ -0,0 +1,226 @@
# Copyright (C) 2006-2013 OpenWrt.org
. /lib/functions.sh
. /usr/share/libubox/jshn.sh
get_mac_binary() {
local path="$1"
local offset="$2"
if ! [ -e "$path" ]; then
echo "get_mac_binary: file $path not found!" >&2
return
fi
hexdump -v -n 6 -s $offset -e '5/1 "%02x:" 1/1 "%02x"' $path 2>/dev/null
}
get_mac_label_dt() {
local basepath="/proc/device-tree"
local macdevice="$(cat "$basepath/aliases/label-mac-device" 2>/dev/null)"
local macaddr
[ -n "$macdevice" ] || return
macaddr=$(get_mac_binary "$basepath/$macdevice/mac-address" 0 2>/dev/null)
[ -n "$macaddr" ] || macaddr=$(get_mac_binary "$basepath/$macdevice/local-mac-address" 0 2>/dev/null)
echo $macaddr
}
get_mac_label_json() {
local cfg="/etc/board.json"
local macaddr
[ -s "$cfg" ] || return
json_init
json_load "$(cat $cfg)"
if json_is_a system object; then
json_select system
json_get_var macaddr label_macaddr
json_select ..
fi
echo $macaddr
}
get_mac_label() {
local macaddr=$(get_mac_label_dt)
[ -n "$macaddr" ] || macaddr=$(get_mac_label_json)
echo $macaddr
}
find_mtd_chardev() {
local INDEX=$(find_mtd_index "$1")
local PREFIX=/dev/mtd
[ -d /dev/mtd ] && PREFIX=/dev/mtd/
echo "${INDEX:+$PREFIX$INDEX}"
}
mtd_get_mac_ascii() {
local mtdname="$1"
local key="$2"
local part
local mac_dirty
part=$(find_mtd_part "$mtdname")
if [ -z "$part" ]; then
echo "mtd_get_mac_ascii: partition $mtdname not found!" >&2
return
fi
mac_dirty=$(strings "$part" | sed -n 's/^'"$key"'=//p')
# "canonicalize" mac
[ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty"
}
mtd_get_mac_text() {
local mtdname=$1
local offset=$(($2))
local part
local mac_dirty
part=$(find_mtd_part "$mtdname")
if [ -z "$part" ]; then
echo "mtd_get_mac_text: partition $mtdname not found!" >&2
return
fi
if [ -z "$offset" ]; then
echo "mtd_get_mac_text: offset missing!" >&2
return
fi
mac_dirty=$(dd if="$part" bs=1 skip="$offset" count=17 2>/dev/null)
# "canonicalize" mac
[ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty"
}
mtd_get_mac_binary() {
local mtdname="$1"
local offset="$2"
local part
part=$(find_mtd_part "$mtdname")
get_mac_binary "$part" "$offset"
}
mtd_get_mac_binary_ubi() {
local mtdname="$1"
local offset="$2"
. /lib/upgrade/nand.sh
local ubidev=$(nand_find_ubi $CI_UBIPART)
local part=$(nand_find_volume $ubidev $1)
get_mac_binary "/dev/$part" "$offset"
}
mtd_get_part_size() {
local part_name=$1
local first dev size erasesize name
while read dev size erasesize name; do
name=${name#'"'}; name=${name%'"'}
if [ "$name" = "$part_name" ]; then
echo $((0x$size))
break
fi
done < /proc/mtd
}
macaddr_add() {
local mac=$1
local val=$2
local oui=${mac%:*:*:*}
local nic=${mac#*:*:*:}
nic=$(printf "%06x" $((0x${nic//:/} + val & 0xffffff)) | sed 's/^\(.\{2\}\)\(.\{2\}\)\(.\{2\}\)/\1:\2:\3/')
echo $oui:$nic
}
macaddr_geteui() {
local mac=$1
local sep=$2
echo ${mac:9:2}$sep${mac:12:2}$sep${mac:15:2}
}
macaddr_setbit() {
local mac=$1
local bit=${2:-0}
[ $bit -gt 0 -a $bit -le 48 ] || return
printf "%012x" $(( 0x${mac//:/} | 2**(48-bit) )) | sed -e 's/\(.\{2\}\)/\1:/g' -e 's/:$//'
}
macaddr_unsetbit() {
local mac=$1
local bit=${2:-0}
[ $bit -gt 0 -a $bit -le 48 ] || return
printf "%012x" $(( 0x${mac//:/} & ~(2**(48-bit)) )) | sed -e 's/\(.\{2\}\)/\1:/g' -e 's/:$//'
}
macaddr_setbit_la() {
macaddr_setbit $1 7
}
macaddr_unsetbit_mc() {
local mac=$1
printf "%02x:%s" $((0x${mac%%:*} & ~0x01)) ${mac#*:}
}
macaddr_random() {
local randsrc=$(get_mac_binary /dev/urandom 0)
echo "$(macaddr_unsetbit_mc "$(macaddr_setbit_la "${randsrc}")")"
}
macaddr_2bin() {
local mac=$1
echo -ne \\x${mac//:/\\x}
}
macaddr_canonicalize() {
local mac="$1"
local canon=""
mac=$(echo -n $mac | tr -d \")
[ ${#mac} -gt 17 ] && return
[ -n "${mac//[a-fA-F0-9\.: -]/}" ] && return
for octet in ${mac//[\.:-]/ }; do
case "${#octet}" in
1)
octet="0${octet}"
;;
2)
;;
4)
octet="${octet:0:2} ${octet:2:2}"
;;
12)
octet="${octet:0:2} ${octet:2:2} ${octet:4:2} ${octet:6:2} ${octet:8:2} ${octet:10:2}"
;;
*)
return
;;
esac
canon=${canon}${canon:+ }${octet}
done
[ ${#canon} -ne 17 ] && return
printf "%02x:%02x:%02x:%02x:%02x:%02x" 0x${canon// / 0x} 2>/dev/null
}

View file

@ -0,0 +1,284 @@
#!/bin/ash
. /lib/functions.sh
. /usr/share/libubox/jshn.sh
ucidef_add_nand_info() {
local model="$1"
model=${model:0:7}
json_select_object nand
case "$model" in
TRB1412)
json_add_int blocksize 128
json_add_int pagesize 2048
json_add_int subpagesize 2048
;;
TRB1422 |\
TRB1423 |\
TRB1452)
json_add_int blocksize 256
json_add_int pagesize 4096
json_add_int subpagesize 4096
;;
TRB14*0)
json_add_int blocksize 128
json_add_int pagesize 2048
json_add_int subpagesize 2048
;;
TRB14*1)
json_add_int blocksize 256
json_add_int pagesize 4096
json_add_int subpagesize 4096
;;
esac
json_select ..
}
ucidef_add_static_modem_info() {
#Parameters: model usb_id sim_count other_params
local model usb_id count
local modem_counter=0
local sim_count=1
model="$1"
usb_id="$2"
[ -n "$3" ] && sim_count="$3"
json_get_keys count modems
[ -n "$count" ] && modem_counter="$(echo "$count" | wc -w)"
json_select_array "modems"
json_add_object
json_add_string id "$usb_id"
json_add_string num "$((modem_counter + 1))"
json_add_boolean builtin 1
json_add_int simcount "$sim_count"
for i in "$@"; do
case "$i" in
primary)
json_add_boolean primary 1
;;
gps_out)
json_add_boolean gps_out 1
;;
esac
done
json_close_object
json_select ..
}
ucidef_add_trb14x_lte_modem() {
print_array() {
json_add_array $1
for element in $2
do
json_add_string "" "$(echo $element)"
done
json_close_array
}
#Parameters: model primary
local model vendor product boudrate gps type desc control region modem_counter
modem_counter=1
json_select_array "modems"
model="$1"
model=${model:0:7}
case "$model" in
TRB1422)
vendor=05c6
product=9215
;;
TRB1412 |\
TRB1423 |\
TRB1452 |\
TRB140*)
vendor=2c7c
product=0125
;;
TRB14*)
vendor=2c7c
product=0121
;;
esac
case "$model" in
TRB1412 |\
TRB14*0)
region="EU"
[ "$product" = "0121" ] && {
lte_bands="1 3 7 8 20 28"
trysg_bands="wcdma_2100 wcdma_900"
dug_bands="gsm_1800 gsm_900"
}
[ "$product" = "0125" ] && {
lte_bands="1 3 7 8 20 28 38 40 41"
trysg_bands="wcdma_2100 wcdma_900"
dug_bands="gsm_1800 gsm_900"
}
;;
TRB1422)
region="CE"
lte_bands="1 3 5 8 34 38 39 40 41"
trysg_bands="bc-0-a-system bc-0-b-system wcdma_2100 wcdma_900"
dug_bands="gsm_1800 gsm_900"
;;
TRB1423 |\
TRB1452 |\
TRB14*1)
region="AU"
[ "$product" = "0121" ] && {
lte_bands="1 2 3 4 5 7 8 28 40"
trysg_bands="wcdma_2100 wcdma_1900 wcdma_900 wcdma_850"
dug_bands="gsm_1800 gsm_900 gsm_850 gsm_1900"
}
[ "$product" = "0125" ] && {
lte_bands="1 2 3 4 5 7 8 28 40"
trysg_bands="wcdma_2100 wcdma_1900 wcdma_900 wcdma_850"
dug_bands="gsm_1800 gsm_900 gsm_850 gsm_1900"
}
;;
esac
[ -f "/lib/network/wwan/$vendor:$product" ] && {
devicename="3-1"
json_set_namespace defaults old_cb
json_load "$(cat /lib/network/wwan/$vendor:$product)"
json_get_vars gps boudrate type desc control stop_bits
json_set_namespace $old_cb
[ "${devicename%%:*}" = "$devicename" ] && {
json_add_object
json_add_string id "$devicename"
json_add_string num "$modem_counter"
json_add_string vendor "$vendor"
json_add_string product "$product"
json_add_string stop_bits "$stop_bits"
json_add_string gps "$gps"
json_add_string boudrate "$boudrate"
json_add_string type "$type"
json_add_string desc "$desc"
json_add_string region "$region"
json_add_string control "$control"
json_add_int simcount 1
json_add_boolean builtin 1
[ -n "$2" ] && json_add_boolean primary 1
json_add_object service_modes
[ -z "$lte_bands" ] || print_array "4G" "$lte_bands"
[ -z "$trysg_bands" ] || print_array "3G" "$trysg_bands"
[ -z "$dug_bands" ] || print_array "2G" "$dug_bands"
json_close_object
json_close_object
}
}
json_select ..
}
ucidef_add_serial_capabilities() {
json_select_array serial
json_add_object
[ -n "$1" ] && {
json_select_array devices
for d in $1; do
json_add_string "" $d
done
json_select ..
}
json_select_array bauds
for b in $2; do
json_add_string "" $b
done
json_select ..
json_select_array data_bits
for n in $3; do
json_add_string "" $n
done
json_select ..
json_close_object
json_select ..
}
ucidef_set_hwinfo() {
local function
local dual_sim=0
local wifi=0
local dual_band_ssid=0
local wps=0
local mobile=0
local gps=0
local usb=0
local bluetooth=0
local ethernet=0
local sfp_port=0
local ios=0
for function in "$@"; do
case "$function" in
dual_sim)
dual_sim=1
;;
wifi)
wifi=1
;;
dual_band_ssid)
dual_band_ssid=1
;;
wps)
wps=1
;;
mobile)
mobile=1
;;
gps)
gps=1
;;
usb)
usb=1
;;
bluetooth)
bluetooth=1
;;
ethernet)
ethernet=1
;;
sfp_port)
sfp_port=1
;;
ios)
ios=1
;;
at_sim)
at_sim=1
;;
esac
done
json_select_object hwinfo
json_add_boolean dual_sim "$dual_sim"
json_add_boolean usb "$usb"
json_add_boolean bluetooth "$bluetooth"
json_add_boolean wifi "$wifi"
json_add_boolean dual_band_ssid "$dual_band_ssid"
json_add_boolean wps "$wps"
json_add_boolean mobile "$mobile"
json_add_boolean gps "$gps"
json_add_boolean ethernet "$ethernet"
json_add_boolean sfp_port "$sfp_port"
json_add_boolean ios "$ios"
json_add_boolean at_sim "$at_sim"
json_select ..
}
ucidef_set_release_version() {
json_add_string release_version "$1"
}

View file

@ -0,0 +1,10 @@
#!/bin/sh
. /usr/share/libubox/jshn.sh
is_ios_enabled() {
local ios
json_load_file "/etc/board.json" && \
json_select hwinfo && \
json_get_var ios ios && [ "$ios" = "1" ]
}

View file

@ -0,0 +1,626 @@
#!/bin/ash
. /lib/functions.sh
. /usr/share/libubox/jshn.sh
json_select_array() {
local _json_no_warning=1
json_select "$1"
[ $? = 0 ] && return
json_add_array "$1"
json_close_array
json_select "$1"
}
json_select_object() {
local _json_no_warning=1
json_select "$1"
[ $? = 0 ] && return
json_add_object "$1"
json_close_object
json_select "$1"
}
ucidef_set_interface() {
local network=$1; shift
[ -z "$network" ] && return
json_select_object network
json_select_object "$network"
while [ -n "$1" ]; do
local opt=$1; shift
local val=$1; shift
[ -n "$opt" -a -n "$val" ] || break
case "$val" in
true) json_add_boolean "$opt" "1" ;;
false) json_add_boolean "$opt" "0" ;;
*) json_add_string "$opt" "$val" ;;
esac
done
if ! json_is_a proto string; then
case "$network" in
lan) json_add_string proto static ;;
wan) json_add_string proto dhcp ;;
*) json_add_string proto none ;;
esac
fi
json_select ..
json_select ..
}
ucidef_set_board_id() {
json_select_object model
json_add_string id "$1"
json_select ..
}
ucidef_set_board_platform() {
json_select_object model
json_add_string platform "$1"
json_select ..
}
ucidef_set_model_name() {
json_select_object model
json_add_string name "$1"
json_select ..
}
ucidef_set_compat_version() {
json_select_object system
json_add_string compat_version "${1:-1.0}"
json_select ..
}
ucidef_set_interface_lan() {
ucidef_set_interface "lan" ifname "$1" proto "${2:-static}"
}
ucidef_set_interface_wan() {
ucidef_set_interface "wan" ifname "$1" proto "${2:-dhcp}"
}
ucidef_set_interfaces_lan_wan() {
local lan_if="$1"
local wan_if="$2"
ucidef_set_interface_lan "$lan_if"
ucidef_set_interface_wan "$wan_if"
}
_ucidef_add_switch_port() {
# inherited: $num $device $need_tag $want_untag $role $index $prev_role
# inherited: $n_cpu $n_ports $n_vlan $cpu0 $cpu1 $cpu2 $cpu3 $cpu4 $cpu5
n_ports=$((n_ports + 1))
json_select_array ports
json_add_object
json_add_int num "$num"
[ -n "$device" ] && json_add_string device "$device"
[ -n "$need_tag" ] && json_add_boolean need_tag "$need_tag"
[ -n "$want_untag" ] && json_add_boolean want_untag "$want_untag"
[ -n "$role" ] && json_add_string role "$role"
[ -n "$index" ] && json_add_int index "$index"
json_close_object
json_select ..
# record pointer to cpu entry for lookup in _ucidef_finish_switch_roles()
[ -n "$device" ] && {
export "cpu$n_cpu=$n_ports"
n_cpu=$((n_cpu + 1))
}
# create/append object to role list
[ -n "$role" ] && {
json_select_array roles
if [ "$role" != "$prev_role" ]; then
json_add_object
json_add_string role "$role"
json_add_string ports "$num"
json_close_object
prev_role="$role"
n_vlan=$((n_vlan + 1))
else
json_select_object "$n_vlan"
json_get_var port ports
json_add_string ports "$port $num"
json_select ..
fi
json_select ..
}
}
_ucidef_finish_switch_roles() {
# inherited: $name $n_cpu $n_vlan $cpu0 $cpu1 $cpu2 $cpu3 $cpu4 $cpu5
local index role roles num device need_tag want_untag port ports
json_select switch
json_select "$name"
json_get_keys roles roles
json_select ..
json_select ..
for index in $roles; do
eval "port=\$cpu$(((index - 1) % n_cpu))"
json_select switch
json_select "$name"
json_select ports
json_select "$port"
json_get_vars num device need_tag want_untag
json_select ..
json_select ..
if [ ${need_tag:-0} -eq 1 -o ${want_untag:-0} -ne 1 ]; then
num="${num}t"
device="${device}.${index}"
fi
json_select roles
json_select "$index"
json_get_vars role ports
json_add_string ports "$ports $num"
json_add_string device "$device"
json_select ..
json_select ..
json_select ..
json_select ..
json_select_object network
local devices
json_select_object "$role"
# attach previous interfaces (for multi-switch devices)
json_get_var devices ifname
if ! list_contains devices "$device"; then
devices="${devices:+$devices }$device"
fi
json_select ..
json_select ..
ucidef_set_interface "$role" ifname "$devices"
done
}
ucidef_set_ar8xxx_switch_mib() {
local name="$1"
local type="$2"
local interval="$3"
json_select_object switch
json_select_object "$name"
json_add_int ar8xxx_mib_type $type
json_add_int ar8xxx_mib_poll_interval $interval
json_select ..
json_select ..
}
ucidef_add_switch() {
local name="$1"; shift
local port num role device index need_tag prev_role
local cpu0 cpu1 cpu2 cpu3 cpu4 cpu5
local n_cpu=0 n_vlan=0 n_ports=0
json_select_object switch
json_select_object "$name"
json_add_boolean enable 1
json_add_boolean reset 1
for port in "$@"; do
case "$port" in
[0-9]*@*)
num="${port%%@*}"
device="${port##*@}"
need_tag=0
want_untag=0
[ "${num%t}" != "$num" ] && {
num="${num%t}"
need_tag=1
}
[ "${num%u}" != "$num" ] && {
num="${num%u}"
want_untag=1
}
;;
[0-9]*:*:[0-9]*)
num="${port%%:*}"
index="${port##*:}"
role="${port#[0-9]*:}"; role="${role%:*}"
;;
[0-9]*:*)
num="${port%%:*}"
role="${port##*:}"
;;
esac
if [ -n "$num" ] && [ -n "$device$role" ]; then
_ucidef_add_switch_port
fi
unset num device role index need_tag want_untag
done
json_select ..
json_select ..
_ucidef_finish_switch_roles
}
ucidef_add_switch_attr() {
local name="$1"
local key="$2"
local val="$3"
json_select_object switch
json_select_object "$name"
case "$val" in
true|false) [ "$val" != "true" ]; json_add_boolean "$key" $? ;;
[0-9]) json_add_int "$key" "$val" ;;
*) json_add_string "$key" "$val" ;;
esac
json_select ..
json_select ..
}
ucidef_add_switch_port_attr() {
local name="$1"
local port="$2"
local key="$3"
local val="$4"
local ports i num
json_select_object switch
json_select_object "$name"
json_get_keys ports ports
json_select_array ports
for i in $ports; do
json_select "$i"
json_get_var num num
if [ -n "$num" ] && [ $num -eq $port ]; then
json_select_object attr
case "$val" in
true|false) [ "$val" != "true" ]; json_add_boolean "$key" $? ;;
[0-9]) json_add_int "$key" "$val" ;;
*) json_add_string "$key" "$val" ;;
esac
json_select ..
fi
json_select ..
done
json_select ..
json_select ..
json_select ..
}
ucidef_set_interface_macaddr() {
local network="$1"
local macaddr="$2"
ucidef_set_interface "$network" macaddr "$macaddr"
}
ucidef_add_atm_bridge() {
local vpi="$1"
local vci="$2"
local encaps="$3"
local payload="$4"
local nameprefix="$5"
json_select_object dsl
json_select_object atmbridge
json_add_int vpi "$vpi"
json_add_int vci "$vci"
json_add_string encaps "$encaps"
json_add_string payload "$payload"
json_add_string nameprefix "$nameprefix"
json_select ..
json_select ..
}
ucidef_add_adsl_modem() {
local annex="$1"
local firmware="$2"
json_select_object dsl
json_select_object modem
json_add_string type "adsl"
json_add_string annex "$annex"
json_add_string firmware "$firmware"
json_select ..
json_select ..
}
ucidef_add_vdsl_modem() {
local annex="$1"
local tone="$2"
local xfer_mode="$3"
json_select_object dsl
json_select_object modem
json_add_string type "vdsl"
json_add_string annex "$annex"
json_add_string tone "$tone"
json_add_string xfer_mode "$xfer_mode"
json_select ..
json_select ..
}
ucidef_set_led_ataport() {
_ucidef_set_led_trigger "$1" "$2" "$3" ata"$4"
}
_ucidef_set_led_common() {
local cfg="led_$1"
local name="$2"
local sysfs="$3"
json_select_object led
json_select_object "$1"
json_add_string name "$name"
json_add_string sysfs "$sysfs"
}
ucidef_set_led_default() {
local default="$4"
_ucidef_set_led_common "$1" "$2" "$3"
json_add_string default "$default"
json_select ..
json_select ..
}
ucidef_set_led_gpio() {
local gpio="$4"
local inverted="$5"
_ucidef_set_led_common "$1" "$2" "$3"
json_add_string trigger "$trigger"
json_add_string type gpio
json_add_int gpio "$gpio"
json_add_boolean inverted "$inverted"
json_select ..
json_select ..
}
ucidef_set_led_ide() {
_ucidef_set_led_trigger "$1" "$2" "$3" disk-activity
}
ucidef_set_led_netdev() {
local dev="$4"
local mode="${5:-link tx rx}"
_ucidef_set_led_common "$1" "$2" "$3"
json_add_string type netdev
json_add_string device "$dev"
json_add_string mode "$mode"
json_select ..
json_select ..
}
ucidef_set_led_oneshot() {
_ucidef_set_led_timer $1 $2 $3 "oneshot" $4 $5
}
ucidef_set_led_portstate() {
local port_state="$4"
_ucidef_set_led_common "$1" "$2" "$3"
json_add_string trigger port_state
json_add_string type portstate
json_add_string port_state "$port_state"
json_select ..
json_select ..
}
ucidef_set_led_rssi() {
local iface="$4"
local minq="$5"
local maxq="$6"
local offset="${7:-0}"
local factor="${8:-1}"
_ucidef_set_led_common "$1" "$2" "$3"
json_add_string type rssi
json_add_string name "$name"
json_add_string iface "$iface"
json_add_string minq "$minq"
json_add_string maxq "$maxq"
json_add_string offset "$offset"
json_add_string factor "$factor"
json_select ..
json_select ..
}
ucidef_set_led_switch() {
local trigger_name="$4"
local port_mask="$5"
local speed_mask="$6"
local mode="$7"
_ucidef_set_led_common "$1" "$2" "$3"
json_add_string trigger "$trigger_name"
json_add_string type switch
json_add_string mode "$mode"
json_add_string port_mask "$port_mask"
json_add_string speed_mask "$speed_mask"
json_select ..
json_select ..
}
_ucidef_set_led_timer() {
local trigger_name="$4"
local delayon="$5"
local delayoff="$6"
_ucidef_set_led_common "$1" "$2" "$3"
json_add_string type "$trigger_name"
json_add_string trigger "$trigger_name"
json_add_int delayon "$delayon"
json_add_int delayoff "$delayoff"
json_select ..
json_select ..
}
ucidef_set_led_timer() {
_ucidef_set_led_timer $1 $2 $3 "timer" $4 $5
}
_ucidef_set_led_trigger() {
local trigger_name="$4"
_ucidef_set_led_common "$1" "$2" "$3"
json_add_string trigger "$trigger_name"
json_select ..
json_select ..
}
ucidef_set_led_usbdev() {
local dev="$4"
_ucidef_set_led_common "$1" "$2" "$3"
json_add_string type usb
json_add_string device "$dev"
json_select ..
json_select ..
}
ucidef_set_led_usbhost() {
_ucidef_set_led_trigger "$1" "$2" "$3" usb-host
}
ucidef_set_led_usbport() {
local obj="$1"
local name="$2"
local sysfs="$3"
shift
shift
shift
_ucidef_set_led_common "$obj" "$name" "$sysfs"
json_add_string type usbport
json_select_array ports
for port in "$@"; do
json_add_string port "$port"
done
json_select ..
json_select ..
json_select ..
}
ucidef_set_led_wlan() {
_ucidef_set_led_trigger "$1" "$2" "$3" "$4"
}
ucidef_set_rssimon() {
local dev="$1"
local refresh="$2"
local threshold="$3"
json_select_object rssimon
json_select_object "$dev"
[ -n "$refresh" ] && json_add_int refresh "$refresh"
[ -n "$threshold" ] && json_add_int threshold "$threshold"
json_select ..
json_select ..
}
ucidef_add_gpio_switch() {
local cfg="$1"
local name="$2"
local pin="$3"
local default="${4:-0}"
json_select_object gpioswitch
json_select_object "$cfg"
json_add_string name "$name"
json_add_int pin "$pin"
json_add_int default "$default"
json_select ..
json_select ..
}
ucidef_set_hostname() {
local hostname="$1"
json_select_object system
json_add_string hostname "$hostname"
json_select ..
}
ucidef_set_ntpserver() {
local server
json_select_object system
json_select_array ntpserver
for server in "$@"; do
json_add_string "" "$server"
done
json_select ..
json_select ..
}
board_config_update() {
json_init
[ -f ${CFG} ] && json_load "$(cat ${CFG})"
# auto-initialize model id and name if applicable
if ! json_is_a model object; then
json_select_object model
[ -f "/tmp/sysinfo/board_name" ] && \
json_add_string id "$(cat /tmp/sysinfo/board_name)"
[ -f "/tmp/sysinfo/model" ] && \
json_add_string name "$(cat /tmp/sysinfo/model)"
json_select ..
fi
}
board_config_flush() {
json_dump -i -o ${CFG}
}

View file

@ -0,0 +1,10 @@
#!/bin/sh
do_stm32_autoflash() {
# launch STM32 flash utility
[ -e "/sys/r2ec/reset" -a -f /usr/bin/autoflash ] && {
/usr/bin/autoflash
}
}
[ "$INITRAMFS" = "1" ] || boot_hook_add preinit_main do_stm32_autoflash

View file

@ -0,0 +1,20 @@
set_state() {
local label="$1"
local disable
[ -e "/sys/class/gpio/${label}_power/value" ] || return
config_get disable ${label} disable
[ "${disable}" -eq 1 ] && \
/sbin/mctl -s -m "${label}" || \
/sbin/mctl -p -m "${label}"
}
do_power_modem() {
[ -z "$(uci -q get system.modem.disable)" ] && /sbin/mctl -p || {
config_load system
config_foreach set_state mctl
}
}
boot_hook_add preinit_main do_power_modem

View file

@ -0,0 +1,21 @@
#!/bin/sh
# Copyright (C) 2006 OpenWrt.org
# Copyright (C) 2010 Vertical Communications
do_check_version() {
version="$(uci -q get system.@system[0].device_fw_version)"
[ -z "$version" ] && {
return 0
}
numeric_version="${version##*_}"
client_removed="${numeric_version#*.}"
major="${client_removed%%.*}"
[ -f /sysupgrade.tgz ] && [ -n "$major" ] && [ "$major" -lt 2 ] && {
echo "- migration work -"
cp /rom/etc/inittab /etc/inittab
}
}
[ "$INITRAMFS" = "1" ] || boot_hook_add preinit_main do_check_version

View file

@ -0,0 +1,383 @@
find_mmc_part() {
local DEVNAME PARTNAME
if grep -q "$1" /proc/mtd; then
echo "" && return 0
fi
for DEVNAME in /sys/block/mmcblk0/mmcblk*p*; do
PARTNAME=$(grep PARTNAME ${DEVNAME}/uevent | cut -f2 -d'=')
[ "$PARTNAME" = "$1" ] && echo "/dev/$(basename $DEVNAME)" && return 0
done
}
get_full_section_name() {
local img=$1
local sec=$2
dumpimage -l ${img} | grep "^ Image.*(${sec})" | \
sed 's,^ Image.*(\(.*\)),\1,'
}
image_contains() {
local img=$1
local sec=$2
dumpimage -l ${img} | grep -q "^ Image.*(${sec}.*)" || return 1
}
print_sections() {
local img=$1
dumpimage -l ${img} | awk '/^ Image.*(.*)/ { print gensub(/Image .* \((.*)\)/,"\\1", $0) }'
}
image_has_mandatory_section() {
local img=$1
local mandatory_sections=$2
for sec in ${mandatory_sections}; do
image_contains $img ${sec} || {\
return 1
}
done
}
image_demux() {
local img=$1
for sec in $(print_sections ${img}); do
local fullname=$(get_full_section_name ${img} ${sec})
local position=$(dumpimage -l ${img} | grep "(${fullname})" | awk '{print $2}')
dumpimage -i ${img} -o /tmp/${fullname}.bin -T "flat_dt" -p "${position}" ${fullname} > /dev/null || { \
echo "Error while extracting \"${sec}\" from ${img}"
return 1
}
done
return 0
}
image_is_FIT() {
if ! dumpimage -l $1 > /dev/null 2>&1; then
echo "$1 is not a valid FIT image"
return 1
fi
return 0
}
switch_layout() {
local layout=$1
local boot_layout=`find / -name boot_layout`
# Layout switching is only required as the boot images (up to u-boot)
# use 512 user data bytes per code word, whereas Linux uses 516 bytes.
# It's only applicable for NAND flash. So let's return if we don't have
# one.
[ -n "$boot_layout" ] || return
case "${layout}" in
boot|1) echo 1 > $boot_layout;;
linux|0) echo 0 > $boot_layout;;
*) echo "Unknown layout \"${layout}\"";;
esac
}
do_flash_mtd() {
local bin=$1
local mtdname=$2
local append=""
local mtdpart=$(grep "\"${mtdname}\"" /proc/mtd | awk -F: '{print $1}')
local pgsz=$(cat /sys/class/mtd/${mtdpart}/writesize)
[ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 -a "$2" == "rootfs" ] && append="-j $CONF_TAR"
dd if=/tmp/${bin}.bin bs=${pgsz} conv=sync | mtd $append -e "/dev/${mtdpart}" write - "/dev/${mtdpart}"
}
do_flash_emmc() {
local bin=$1
local emmcblock=$2
dd if=/dev/zero of=${emmcblock}
dd if=/tmp/${bin}.bin of=${emmcblock}
}
do_flash_partition() {
local bin=$1
local mtdname=$2
local emmcblock="$(find_mmc_part "$mtdname")"
if [ -e "$emmcblock" ]; then
do_flash_emmc $bin $emmcblock
else
do_flash_mtd $bin $mtdname
fi
}
do_flash_bootconfig() {
local bin=$1
local mtdname=$2
# Fail safe upgrade
if [ -f /proc/boot_info/getbinary_${bin} ]; then
cat /proc/boot_info/getbinary_${bin} > /tmp/${bin}.bin
do_flash_partition $bin $mtdname
fi
}
do_flash_failsafe_partition() {
local bin=$1
local mtdname=$2
local emmcblock
local primaryboot
# Fail safe upgrade
[ -f /proc/boot_info/$mtdname/upgradepartition ] && {
default_mtd=$mtdname
mtdname=$(cat /proc/boot_info/$mtdname/upgradepartition)
primaryboot=$(cat /proc/boot_info/$default_mtd/primaryboot)
if [ $primaryboot -eq 0 ]; then
echo 1 > /proc/boot_info/$default_mtd/primaryboot
else
echo 0 > /proc/boot_info/$default_mtd/primaryboot
fi
}
emmcblock="$(find_mmc_part "$mtdname")"
if [ -e "$emmcblock" ]; then
do_flash_emmc $bin $emmcblock
else
do_flash_mtd $bin $mtdname
fi
}
do_flash_ubi() {
local bin=$1
local mtdname=$2
local mtdpart
local primaryboot
mtdpart=$(grep "\"${mtdname}\"" /proc/mtd | awk -F: '{print $1}')
ubidetach -p /dev/${mtdpart}
# Fail safe upgrade
[ -f /proc/boot_info/$mtdname/upgradepartition ] && {
primaryboot=$(cat /proc/boot_info/$mtdname/primaryboot)
if [ $primaryboot -eq 0 ]; then
echo 1 > /proc/boot_info/$mtdname/primaryboot
else
echo 0 > /proc/boot_info/$mtdname/primaryboot
fi
mtdname=$(cat /proc/boot_info/$mtdname/upgradepartition)
}
mtdpart=$(grep "\"${mtdname}\"" /proc/mtd | awk -F: '{print $1}')
ubiformat /dev/${mtdpart} -y -f /tmp/${bin}.bin
}
do_flash_tz() {
local sec=$1
local mtdpart=$(grep "\"0:QSEE\"" /proc/mtd | awk -F: '{print $1}')
local emmcblock="$(find_mmc_part "0:QSEE")"
if [ -n "$mtdpart" -o -e "$emmcblock" ]; then
do_flash_failsafe_partition ${sec} "0:QSEE"
else
do_flash_failsafe_partition ${sec} "0:TZ"
fi
}
do_flash_ddr() {
local sec=$1
local mtdpart=$(grep "\"0:CDT\"" /proc/mtd | awk -F: '{print $1}')
local emmcblock="$(find_mmc_part "0:CDT")"
if [ -n "$mtdpart" -o -e "$emmcblock" ]; then
do_flash_failsafe_partition ${sec} "0:CDT"
else
do_flash_failsafe_partition ${sec} "0:DDRPARAMS"
fi
}
to_upper () {
echo $1 | awk '{print toupper($0)}'
}
flash_section() {
local sec=$1
local board=$(board_name)
case "${sec}" in
hlos*) switch_layout linux; do_flash_failsafe_partition ${sec} "0:HLOS";;
rootfs*) switch_layout linux; do_flash_failsafe_partition ${sec} "rootfs";;
fs*) switch_layout linux; do_flash_failsafe_partition ${sec} "rootfs";;
ubi*) switch_layout linux; do_flash_ubi ${sec} "rootfs";;
#sbl1*) switch_layout boot; do_flash_partition ${sec} "0:SBL1";;
#sbl2*) switch_layout boot; do_flash_failsafe_partition ${sec} "0:SBL2";;
#sbl3*) switch_layout boot; do_flash_failsafe_partition ${sec} "0:SBL3";;
#mibib*) switch_layout boot; do_flash_partition ${sec} "0:MIBIB";;
#dtb-$(to_upper $board)*) switch_layout boot; do_flash_partition ${sec} "0:DTB";;
u-boot*) switch_layout boot; do_flash_failsafe_partition ${sec} "0:APPSBL";;
#ddr-$(to_upper $board)*) switch_layout boot; do_flash_ddr ${sec};;
ddr-${board}-*) switch_layout boot; do_flash_failsafe_partition ${sec} "0:CDT";;
#ssd*) switch_layout boot; do_flash_partition ${sec} "0:SSD";;
tz*) switch_layout boot; do_flash_tz ${sec};;
#rpm*) switch_layout boot; do_flash_failsafe_partition ${sec} "0:RPM";;
*) echo "Section ${sec} ignored"; return 1;;
esac
echo "Flashed ${sec}"
}
erase_emmc_config() {
local emmcblock="$(find_mmc_part "rootfs_data")"
if [ -e "$emmcblock" ]; then
dd if=/dev/zero of=${emmcblock}
mkfs.ext4 "$emmcblock"
fi
}
platform_pre_upgrade() {
cp /sbin/upgraded /tmp
ubus call system nandupgrade "{\"path\": \"$1\" }"
}
platform_check_image_ipq() {
local board=$(board_name)
local mandatory_nand="ubi"
local mandatory_nor_emmc="hlos fs"
local mandatory_nor="hlos"
local mandatory_section_found=0
local optional="sbl2 u-boot ddr-${board} ssd tz rpm"
local ignored="mibib bootconfig sbl1"
image_is_FIT $1 || return 1
image_has_mandatory_section $1 ${mandatory_nand} && {\
mandatory_section_found=1
}
image_has_mandatory_section $1 ${mandatory_nor_emmc} && {\
mandatory_section_found=1
}
image_has_mandatory_section $1 ${mandatory_nor} && {\
mandatory_section_found=1
}
if [ $mandatory_section_found -eq 0 ]; then
echo "Error: mandatory section(s) missing from \"$1\". Abort..."
return 1
fi
for sec in ${optional}; do
image_contains $1 ${sec} || {\
echo "Warning: optional section \"${sec}\" missing from \"$1\". Continue..."
}
done
for sec in ${ignored}; do
image_contains $1 ${sec} && {\
echo "Warning: section \"${sec}\" will be ignored from \"$1\". Continue..."
}
done
image_demux $1 || {\
echo "Error: \"$1\" couldn't be extracted. Abort..."
return 1
}
[ -f /tmp/hlos_version ] && rm -f /tmp/*_version
dumpimage -c $1 2>/dev/null
return $?
}
platform_version_upgrade() {
local version_files="appsbl_version sbl_version tz_version hlos_version rpm_version"
local sys="/sys/devices/system/qfprom/qfprom0/"
local tmp="/tmp/"
for file in $version_files; do
[ -f "${tmp}${file}" ] && {
echo "Updating "${sys}${file}" with `cat "${tmp}${file}"`"
echo `cat "${tmp}${file}"` > "${sys}${file}"
rm -f "${tmp}${file}"
}
done
}
# 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.
platform_do_upgrade_ipq() {
local board=$(board_name)
# verify some things exist before erasing
if [ ! -e $1 ]; then
echo "Error: Can't find $1 after switching to ramfs, aborting upgrade!"
reboot
fi
for sec in $(print_sections $1); do
if [ ! -e /tmp/${sec}.bin ]; then
echo "Error: Cant' find ${sec} after switching to ramfs, aborting upgrade!"
reboot
fi
done
case "$board" in
teltonika,rutx)
for sec in $(print_sections $1); do
flash_section ${sec}
done
switch_layout linux
# update bootconfig to register that fw upgrade has been done
do_flash_bootconfig bootconfig "0:BOOTCONFIG"
do_flash_bootconfig bootconfig1 "0:BOOTCONFIG1"
platform_version_upgrade
erase_emmc_config
return 0;
;;
esac
echo "Upgrade failed!"
return 1;
}
platform_copy_config() {
local emmcblock="$(find_mmc_part "rootfs_data")"
mkdir -p /tmp/overlay
if [ -e "$emmcblock" ]; then
mount -t ext4 "$emmcblock" /tmp/overlay
cp /tmp/sysupgrade.tgz /tmp/overlay/
sync
umount /tmp/overlay
else
local mtdname=rootfs
local mtdpart
[ -f /proc/boot_info/$mtdname/upgradepartition ] && {
mtdname=$(cat /proc/boot_info/$mtdname/upgradepartition)
}
mtdpart=$(grep "\"${mtdname}\"" /proc/mtd | awk -F: '{print $1}')
ubiattach -p /dev/${mtdpart}
mount -t ubifs ubi0:rootfs_data /tmp/overlay
cp /tmp/sysupgrade.tgz /tmp/overlay/
sync
umount /tmp/overlay
fi
}

View file

@ -1,127 +1,45 @@
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() {
case "$(board_name)" in
asus,rt-ac58u)
CI_UBIPART="UBI_DEV"
local ubidev=$(nand_find_ubi $CI_UBIPART)
local asus_root=$(nand_find_volume $ubidev jffs2)
[ -n "$asus_root" ] || return 0
cat << EOF
jffs2 partition is still present.
There's probably no space left
to install the filesystem.
You need to delete the jffs2 partition first:
# ubirmvol /dev/ubi0 --name=jffs2
Once this is done. Retry.
EOF
return 1
;;
esac
return 0;
}
askey_do_upgrade() {
local tar_file="$1"
local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
board_dir=${board_dir%/}
tar Oxf $tar_file ${board_dir}/root | mtd write - rootfs
nand_do_upgrade "$1"
}
zyxel_do_upgrade() {
local tar_file="$1"
local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
board_dir=${board_dir%/}
tar Oxf $tar_file ${board_dir}/kernel | mtd write - kernel
if [ -n "$UPGRADE_BACKUP" ]; then
tar Oxf $tar_file ${board_dir}/root | mtd -j "$UPGRADE_BACKUP" write - rootfs
else
tar Oxf $tar_file ${board_dir}/root | mtd write - rootfs
fi
platform_check_image_ipq "$1"
}
platform_do_upgrade() {
case "$(board_name)" in
8dev,jalapeno |\
aruba,ap-303 |\
aruba,ap-303h |\
aruba,ap-365 |\
avm,fritzbox-7530 |\
avm,fritzrepeater-1200 |\
avm,fritzrepeater-3000 |\
buffalo,wtr-m2133hp |\
cilab,meshpoint-one |\
engenius,eap2200 |\
mobipromo,cm520-79f |\
qxwlan,e2600ac-c2)
nand_do_upgrade "$1"
;;
alfa-network,ap120c-ac)
part="$(awk -F 'ubi.mtd=' '{printf $2}' /proc/cmdline | sed -e 's/ .*$//')"
if [ "$part" = "rootfs1" ]; then
fw_setenv active 2 || exit 1
CI_UBIPART="rootfs2"
else
fw_setenv active 1 || exit 1
CI_UBIPART="rootfs1"
fi
nand_do_upgrade "$1"
;;
asus,map-ac2200)
CI_KERNPART="linux"
nand_do_upgrade "$1"
;;
asus,rt-ac58u)
CI_UBIPART="UBI_DEV"
CI_KERNPART="linux"
nand_do_upgrade "$1"
;;
cellc,rtl30vw)
CI_UBIPART="ubifs"
askey_do_upgrade "$1"
;;
compex,wpj419|\
p2w,r619ac-128m|\
p2w,r619ac)
nand_do_upgrade "$1"
;;
linksys,ea6350v3 |\
linksys,ea8300)
platform_do_upgrade_linksys "$1"
;;
meraki,mr33)
CI_KERNPART="part.safe"
nand_do_upgrade "$1"
;;
openmesh,a42 |\
openmesh,a62)
PART_NAME="inactive"
platform_do_upgrade_openmesh "$1"
;;
teltonika,rutx)
CI_UBIPART="rootfs"
nand_do_upgrade "$1"
;;
zyxel,nbg6617)
zyxel_do_upgrade "$1"
;;
*)
default_do_upgrade "$1"
;;
esac
platform_do_upgrade_ipq "$1"
}
# added with io_expander validation
platform_check_hw_support() {
local metadata="/tmp/sysupgrade.meta"
local io_expander_file="/proc/device-tree/io_expander"
local found=0
[ -e "$metadata" ] || ( fwtool -q -i $metadata $1 ) && {
json_load_file "$metadata"
# previous devices were always supported
[ ! -e "$io_expander_file" ] && return 0
json_select hw_support
# io_expander type validation
local io_expander="$(cat $io_expander_file)"
# if support type is absent in metadata, we assume it's supported
if ( json_select io_expander 2> /dev/null ); then
json_select io_expander
json_get_values io_exp_values
for val in $io_exp_values; do
regex_value=$(echo "$io_expander" | grep -e "$val")
[ "$io_expander" = "$regex_value" ] && found=1
done
[ $found -eq 0 ] && return 1
json_select ..
else
# fail if not default/initial type
[ "$io_expander" != "stm32" ] && return 1
fi
# ...
}
return 0;
}