mirror of
https://github.com/Ysurac/openmptcprouter.git
synced 2025-03-09 15:40:20 +00:00
Update Linux 5.4 kernel and clean some files
This commit is contained in:
parent
272324aa1a
commit
0a55523ea5
26 changed files with 870 additions and 4059 deletions
|
@ -1,171 +0,0 @@
|
|||
# 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"
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
# 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
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
. /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}
|
||||
}
|
|
@ -1,247 +0,0 @@
|
|||
#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)"
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
# 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
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
#
|
||||
# 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 "$@"
|
||||
}
|
|
@ -1,226 +0,0 @@
|
|||
# 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue