From 7e2df345b754b16c23f9523fe3e87731b46e0680 Mon Sep 17 00:00:00 2001 From: NADAL Jean-Baptiste Date: Sat, 8 Apr 2017 21:17:43 +0200 Subject: [PATCH] Update overlay. --- bsp/board/domo/local.mk | 4 + bsp/board/domo/main.mk | 4 +- bsp/board/domo/ovl/etc/config/mountd | 3 + bsp/board/domo/ovl/etc/fstab | 2 +- bsp/board/domo/ovl/etc/init.d/network | 107 +++- bsp/board/domo/ovl/lib/functions/procd.sh | 2 +- .../domo/ovl/lib/functions/uci-defaults.sh | 593 ++++++++++++++++++ bsp/board/domo/ovl/lib/wifi/mac80211.sh | 133 ++++ bsp/board/domo/ovl/sbin/devstatus | 12 + bsp/board/domo/ovl/sbin/ifstatus | 13 + bsp/board/domo/ovl/sbin/ifup | 77 +++ bsp/board/domo/ovl/sbin/wifi | 236 +++++++ bsp/include/dtb.mk | 9 + bsp/scripts/clean_external_packages.sh | 19 + 14 files changed, 1204 insertions(+), 10 deletions(-) create mode 100644 bsp/board/domo/local.mk create mode 100644 bsp/board/domo/ovl/etc/config/mountd create mode 100644 bsp/board/domo/ovl/lib/functions/uci-defaults.sh create mode 100644 bsp/board/domo/ovl/lib/wifi/mac80211.sh create mode 100644 bsp/board/domo/ovl/sbin/devstatus create mode 100644 bsp/board/domo/ovl/sbin/ifstatus create mode 100644 bsp/board/domo/ovl/sbin/ifup create mode 100644 bsp/board/domo/ovl/sbin/wifi create mode 100644 bsp/include/dtb.mk create mode 100644 bsp/scripts/clean_external_packages.sh diff --git a/bsp/board/domo/local.mk b/bsp/board/domo/local.mk new file mode 100644 index 00000000..660f943f --- /dev/null +++ b/bsp/board/domo/local.mk @@ -0,0 +1,4 @@ + +LIBUBOX_OVERRIDE_SRCDIR = $(TOPDIR)/../../../src/3P/libubox/ + +UBUS_OVERRIDE_SRCDIR = $(TOPDIR)/../../../src/3P/ubus/ diff --git a/bsp/board/domo/main.mk b/bsp/board/domo/main.mk index 45acdcad..30eedb7f 100644 --- a/bsp/board/domo/main.mk +++ b/bsp/board/domo/main.mk @@ -1,5 +1,5 @@ # -# Main rules for raspberry board targets. +# Main rules for domo board targets. # # @@ -7,6 +7,6 @@ .PHONY: all all: msg buildroot - include ../../bsp/include/rules.mk include ../../bsp/include/buildroot.mk +include ../../bsp/include/dtb.mk diff --git a/bsp/board/domo/ovl/etc/config/mountd b/bsp/board/domo/ovl/etc/config/mountd new file mode 100644 index 00000000..56101295 --- /dev/null +++ b/bsp/board/domo/ovl/etc/config/mountd @@ -0,0 +1,3 @@ +config mountd mountd + option timeout 60 + option path /tmp/mounts/ diff --git a/bsp/board/domo/ovl/etc/fstab b/bsp/board/domo/ovl/etc/fstab index b3d5ebab..b1b1e250 100644 --- a/bsp/board/domo/ovl/etc/fstab +++ b/bsp/board/domo/ovl/etc/fstab @@ -1,5 +1,5 @@ # -/dev/root / ext2 rw,noauto 0 1 +/dev/root / ext2 ro,noauto 0 1 proc /proc proc defaults 0 0 devpts /dev/pts devpts defaults,gid=5,mode=620 0 0 tmpfs /dev/shm tmpfs mode=0777 0 0 diff --git a/bsp/board/domo/ovl/etc/init.d/network b/bsp/board/domo/ovl/etc/init.d/network index 1ae6718f..e3c12938 100755 --- a/bsp/board/domo/ovl/etc/init.d/network +++ b/bsp/board/domo/ovl/etc/init.d/network @@ -21,12 +21,11 @@ init_switch() { setup_switch } -start_service () { +start_service() { init_switch procd_open_instance - procd_set_param command "$PROG" - procd_set_param pidfile "$PIDFILE" + procd_set_param command /sbin/netifd procd_set_param respawn procd_set_param watch network.interface [ -e /proc/sys/kernel/core_pattern ] && { @@ -38,17 +37,113 @@ start_service () { reload_service() { init_switch ubus call network reload - #/sbin/wifi reload_legacy + /sbin/wifi reload_legacy } stop() { - #/sbin/wifi down + /sbin/wifi down procd_kill network '' } service_running() { ubus -t 30 wait_for network.interface - #/sbin/wifi reload_legacy + /sbin/wifi reload_legacy +} + +validate_atm_bridge_section() +{ + uci_validate_section network "atm-bridge" "${1}" \ + 'unit:uinteger:0' \ + 'vci:range(32, 65535):35' \ + 'vpi:range(0, 255):8' \ + 'atmdev:uinteger:0' \ + 'encaps:or("llc", "vc"):llc' \ + 'payload:or("bridged", "routed"):bridged' +} + +validate_route_section() +{ + uci_validate_section network route "${1}" \ + 'interface:string' \ + 'target:cidr4' \ + 'netmask:netmask4' \ + 'gateway:ip4addr' \ + 'metric:uinteger' \ + 'mtu:uinteger' \ + 'table:or(range(0,65535),string)' +} + +validate_route6_section() +{ + uci_validate_section network route6 "${1}" \ + 'interface:string' \ + 'target:cidr6' \ + 'gateway:ip6addr' \ + 'metric:uinteger' \ + 'mtu:uinteger' \ + 'table:or(range(0,65535),string)' +} + +validate_rule_section() +{ + uci_validate_section network rule "${1}" \ + 'in:string' \ + 'out:string' \ + 'src:cidr4' \ + 'dest:cidr4' \ + 'tos:range(0,31)' \ + 'mark:string' \ + 'invert:bool' \ + 'lookup:or(range(0,65535),string)' \ + 'goto:range(0,65535)' \ + 'action:or("prohibit", "unreachable", "blackhole", "throw")' +} + +validate_rule6_section() +{ + uci_validate_section network rule6 "${1}" \ + 'in:string' \ + 'out:string' \ + 'src:cidr6' \ + 'dest:cidr6' \ + 'tos:range(0,31)' \ + 'mark:string' \ + 'invert:bool' \ + 'lookup:or(range(0,65535),string)' \ + 'goto:range(0,65535)' \ + 'action:or("prohibit", "unreachable", "blackhole", "throw")' +} + +validate_switch_section() +{ + uci_validate_section network switch "${1}" \ + 'name:string' \ + 'enable:bool' \ + 'enable_vlan:bool' \ + 'reset:bool' +} + +validate_switch_vlan() +{ + uci_validate_section network switch_vlan "${1}" \ + 'device:string' \ + 'vlan:uinteger' \ + 'ports:list(ports)' +} + +service_triggers() +{ + procd_add_reload_trigger network wireless + + procd_open_validate + validate_atm_bridge_section + validate_route_section + validate_route6_section + validate_rule_section + validate_rule6_section + validate_switch_section + validate_switch_vlan + procd_close_validate } restart() { diff --git a/bsp/board/domo/ovl/lib/functions/procd.sh b/bsp/board/domo/ovl/lib/functions/procd.sh index 7b51931c..1c2edc67 100644 --- a/bsp/board/domo/ovl/lib/functions/procd.sh +++ b/bsp/board/domo/ovl/lib/functions/procd.sh @@ -51,7 +51,7 @@ _procd_wrapper() { _procd_ubus_call() { local cmd="$1" - echo "_procd_ubus_call= > ubus call service \"$cmd\" \"$(json_dump)\"" + [ -n "$PROCD_DEBUG" ] && json_dump >&2 ubus call service "$cmd" "$(json_dump)" json_cleanup diff --git a/bsp/board/domo/ovl/lib/functions/uci-defaults.sh b/bsp/board/domo/ovl/lib/functions/uci-defaults.sh new file mode 100644 index 00000000..b097fba3 --- /dev/null +++ b/bsp/board/domo/ovl/lib/functions/uci-defaults.sh @@ -0,0 +1,593 @@ +#!/bin/ash + +CFG=/etc/board.json + +. /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 name="$1" + local iface="$2" + local proto="$3" + + json_select_object "$name" + json_add_string ifname "$iface" + + if ! json_is_a protocol string; then + case "$proto" in + static|dhcp|none|pppoe) : ;; + *) + case "$name" in + lan) proto="static" ;; + wan) proto="dhcp" ;; + *) proto="none" ;; + esac + ;; + esac + + json_add_string protocol "$proto" + fi + + json_select .. +} + +ucidef_set_board_id() { + json_select_object model + json_add_string id "$1" + json_select .. +} + +ucidef_set_model_name() { + json_select_object model + json_add_string name "$1" + json_select .. +} + +ucidef_set_interface_lan() { + json_select_object network + _ucidef_set_interface lan "$@" + json_select .. +} + +ucidef_set_interface_wan() { + json_select_object network + _ucidef_set_interface wan "$@" + json_select .. +} + +ucidef_set_interfaces_lan_wan() { + local lan_if="$1" + local wan_if="$2" + + json_select_object network + _ucidef_set_interface lan "$lan_if" + _ucidef_set_interface wan "$wan_if" + json_select .. +} + +ucidef_set_interface_raw() { + json_select_object network + _ucidef_set_interface "$@" + json_select .. +} + +_ucidef_add_switch_port() { + # inherited: $num $device $need_tag $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 "$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 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 + json_select .. + json_select .. + + if [ $n_vlan -gt $n_cpu -o ${need_tag:-0} -eq 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 .. + + _ucidef_set_interface "$role" "$devices" + json_select .. + done +} + +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 + [ "${num%t}" != "$num" ] && { + num="${num%t}" + need_tag=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 + 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" + + json_select_object network + + json_select "$network" + [ $? -eq 0 ] || { + json_select .. + return + } + + json_add_string macaddr "$macaddr" + json_select .. + + json_select .. +} + +ucidef_add_atm_bridge() { + local vpi="$1" + local vci="$2" + local encaps="$3" + local payload="$4" + + 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_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_netdev() { + local cfg="led_$1" + local name="$2" + local sysfs="$3" + local dev="$4" + local mode="${5:-link tx rx}" + + json_select_object led + + json_select_object "$1" + json_add_string name "$name" + json_add_string type netdev + json_add_string sysfs "$sysfs" + json_add_string device "$dev" + json_add_string mode "$mode" + json_select .. + + json_select .. +} + +ucidef_set_led_usbdev() { + local cfg="led_$1" + local name="$2" + local sysfs="$3" + local dev="$4" + + json_select_object led + + json_select_object "$1" + json_add_string name "$name" + json_add_string type usb + json_add_string sysfs "$sysfs" + json_add_string device "$dev" + json_select .. + + json_select .. +} + +ucidef_set_led_wlan() { + local cfg="led_$1" + local name="$2" + local sysfs="$3" + local trigger="$4" + + json_select_object led + + json_select_object "$1" + json_add_string name "$name" + json_add_string type trigger + json_add_string sysfs "$sysfs" + json_add_string trigger "$trigger" + json_select .. + + json_select .. +} + +ucidef_set_led_switch() { + local cfg="led_$1" + local name="$2" + local sysfs="$3" + local trigger="$4" + local port_mask="$5" + local speed_mask="$6" + + json_select_object led + + json_select_object "$1" + json_add_string name "$name" + json_add_string type switch + json_add_string sysfs "$sysfs" + json_add_string trigger "$trigger" + json_add_string port_mask "$port_mask" + json_add_string speed_mask "$speed_mask" + json_select .. + + json_select .. +} + +ucidef_set_led_default() { + local cfg="led_$1" + local name="$2" + local sysfs="$3" + local default="$4" + + json_select_object led + + json_select_object "$1" + json_add_string name "$name" + json_add_string sysfs "$sysfs" + json_add_string default "$default" + json_select .. + + json_select .. +} + +ucidef_set_led_gpio() { + local cfg="led_$1" + local name="$2" + local sysfs="$3" + local gpio="$4" + local inverted="$5" + + json_select_object led + + json_select_object "$1" + json_add_string type gpio + json_add_string name "$name" + json_add_string sysfs "$sysfs" + json_add_string trigger "$trigger" + json_add_int gpio "$gpio" + json_add_boolean inverted "$inverted" + json_select .. + + json_select .. +} + +ucidef_set_led_ide() { + 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" + json_add_string trigger ide-disk + json_select .. + + json_select .. +} + +__ucidef_set_led_timer() { + local cfg="led_$1" + local name="$2" + local sysfs="$3" + local trigger="$4" + local delayon="$5" + local delayoff="$6" + + json_select_object led + + json_select_object "$1" + json_add_string type "$trigger" + json_add_string name "$name" + json_add_string sysfs "$sysfs" + json_add_int delayon "$delayon" + json_add_int delayoff "$delayoff" + json_select .. + + json_select .. +} + +ucidef_set_led_oneshot() { + __ucidef_set_led_timer $1 $2 $3 "oneshot" $4 $5 +} + +ucidef_set_led_timer() { + __ucidef_set_led_timer $1 $2 $3 "timer" $4 $5 +} + +ucidef_set_led_rssi() { + local cfg="led_$1" + local name="$2" + local sysfs="$3" + local iface="$4" + local minq="$5" + local maxq="$6" + local offset="$7" + local factor="$8" + + json_select_object led + + json_select_object "$1" + json_add_string type rssi + json_add_string name "$name" + json_add_string iface "$iface" + json_add_string sysfs "$sysfs" + 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_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 .. +} + +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 > /tmp/.board.json + mv /tmp/.board.json ${CFG} +} diff --git a/bsp/board/domo/ovl/lib/wifi/mac80211.sh b/bsp/board/domo/ovl/lib/wifi/mac80211.sh new file mode 100644 index 00000000..06f3b8b4 --- /dev/null +++ b/bsp/board/domo/ovl/lib/wifi/mac80211.sh @@ -0,0 +1,133 @@ +#!/bin/sh +append DRIVERS "mac80211" + +lookup_phy() { + [ -n "$phy" ] && { + [ -d /sys/class/ieee80211/$phy ] && return + } + + local devpath + config_get devpath "$device" path + [ -n "$devpath" ] && { + for phy in $(ls /sys/class/ieee80211 2>/dev/null); do + case "$(readlink -f /sys/class/ieee80211/$phy/device)" in + *$devpath) return;; + esac + done + } + + local macaddr="$(config_get "$device" macaddr | tr 'A-Z' 'a-z')" + [ -n "$macaddr" ] && { + for _phy in /sys/class/ieee80211/*; do + [ -e "$_phy" ] || continue + + [ "$macaddr" = "$(cat ${_phy}/macaddress)" ] || continue + phy="${_phy##*/}" + return + done + } + phy= + return +} + +find_mac80211_phy() { + local device="$1" + + config_get phy "$device" phy + lookup_phy + [ -n "$phy" -a -d "/sys/class/ieee80211/$phy" ] || { + echo "PHY for wifi device $1 not found" + return 1 + } + config_set "$device" phy "$phy" + + config_get macaddr "$device" macaddr + [ -z "$macaddr" ] && { + config_set "$device" macaddr "$(cat /sys/class/ieee80211/${phy}/macaddress)" + } + + return 0 +} + +check_mac80211_device() { + config_get phy "$1" phy + [ -z "$phy" ] && { + find_mac80211_phy "$1" >/dev/null || return 0 + config_get phy "$1" phy + } + [ "$phy" = "$dev" ] && found=1 +} + +detect_mac80211() { + devidx=0 + config_load wireless + while :; do + config_get type "radio$devidx" type + [ -n "$type" ] || break + devidx=$(($devidx + 1)) + done + + for _dev in /sys/class/ieee80211/*; do + [ -e "$_dev" ] || continue + + dev="${_dev##*/}" + + found=0 + config_foreach check_mac80211_device wifi-device + [ "$found" -gt 0 ] && continue + + mode_band="g" + channel="11" + htmode="" + ht_capab="" + + iw phy "$dev" info | grep -q 'Capabilities:' && htmode=HT20 + iw phy "$dev" info | grep -q '2412 MHz' || { mode_band="a"; channel="36"; } + + vht_cap=$(iw phy "$dev" info | grep -c 'VHT Capabilities') + cap_5ghz=$(iw phy "$dev" info | grep -c "Band 2") + [ "$vht_cap" -gt 0 -a "$cap_5ghz" -gt 0 ] && { + mode_band="a"; + channel="36" + htmode="VHT80" + } + + [ -n $htmode ] && append ht_capab " option htmode $htmode" "$N" + + if [ -x /usr/bin/readlink -a -h /sys/class/ieee80211/${dev} ]; then + path="$(readlink -f /sys/class/ieee80211/${dev}/device)" + else + path="" + fi + if [ -n "$path" ]; then + path="${path##/sys/devices/}" + case "$path" in + platform*/pci*) path="${path##platform/}";; + esac + dev_id=" option path '$path'" + else + dev_id=" option macaddr $(cat /sys/class/ieee80211/${dev}/macaddress)" + fi + + cat <" + exit 1 +} + +json_init +json_add_string name "$DEVICE" +ubus call network.device status "$(json_dump)" diff --git a/bsp/board/domo/ovl/sbin/ifstatus b/bsp/board/domo/ovl/sbin/ifstatus new file mode 100644 index 00000000..8a951e6e --- /dev/null +++ b/bsp/board/domo/ovl/sbin/ifstatus @@ -0,0 +1,13 @@ +#!/bin/sh +INTERFACE="$1" + +[ -n "$INTERFACE" ] || { + echo "Usage: $0 " + exit 1 +} + +ubus -S list "network.interface.$INTERFACE" >/dev/null || { + echo "Interface $INTERFACE not found" + exit 1 +} +ubus call network.interface status "{ \"interface\" : \"$INTERFACE\" }" diff --git a/bsp/board/domo/ovl/sbin/ifup b/bsp/board/domo/ovl/sbin/ifup new file mode 100644 index 00000000..5515b91f --- /dev/null +++ b/bsp/board/domo/ovl/sbin/ifup @@ -0,0 +1,77 @@ +#!/bin/sh + +ifup_all= +setup_wifi= + +if_call() { + local interface="$1" + for mode in $modes; do + ubus call network.interface $mode "{ \"interface\" : \"$interface\" }" + done +} + +case "$0" in + *ifdown) modes=down;; + *ifup) + modes="down up" + setup_wifi=1 + ;; + *) echo "Invalid command: $0";; +esac + +while :; do + case "$1" in + -a) + ifup_all=1 + shift + ;; + -w) + setup_wifi= + shift + ;; + *) + break + ;; + esac +done + +[ "$modes" = "down up" ] && ubus call network reload +if [ -n "$ifup_all" ]; then + for interface in `ubus -S list 'network.interface.*'`; do + if_call "${interface##network.interface.}" + done + [ -n "$setup_wifi" ] && /sbin/wifi up + exit +else + ubus -S list "network.interface.$1" > /dev/null || { + echo "Interface $1 not found" + exit + } + if_call "$1" +fi + +if [ -n "$setup_wifi" ] && grep -sq config /etc/config/wireless; then + . /lib/functions.sh + + find_related_radios() { + local wdev wnet + config_get wdev "$1" device + config_get wnet "$1" network + + if [ -n "$wdev" ]; then + for wnet in $wnet; do + if [ "$wnet" = "$network" ]; then + append radio_devs "$wdev" "$N" + fi + done + fi + } + + network="$1" + config_load wireless + config_foreach find_related_radios wifi-iface + + for dev in $(echo "$radio_devs" | sort -u); do + /sbin/wifi up "$dev" + done +fi diff --git a/bsp/board/domo/ovl/sbin/wifi b/bsp/board/domo/ovl/sbin/wifi new file mode 100644 index 00000000..24764143 --- /dev/null +++ b/bsp/board/domo/ovl/sbin/wifi @@ -0,0 +1,236 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +. /lib/functions.sh +. /usr/share/libubox/jshn.sh + +usage() { + cat </dev/null >/dev/null; then + eval "scan_$iftype '$device'" + eval "${1}_$iftype '$device'" || echo "$device($iftype): ${1} failed" + elif [ ! -f /lib/netifd/wireless/$iftype.sh ]; then + echo "$device($iftype): Interface type not supported" + fi + ); done +} + +wifi_updown() { + cmd=down + [ enable = "$1" ] && { + _wifi_updown disable "$2" + ubus_wifi_cmd "$cmd" "$2" + scan_wifi + cmd=up + } + ubus_wifi_cmd "$cmd" "$2" + _wifi_updown "$@" +} + +wifi_reload_legacy() { + _wifi_updown "disable" "$1" + scan_wifi + _wifi_updown "enable" "$1" +} + +wifi_reload() { + ubus call network reload + wifi_reload_legacy +} + +wifi_detect() { + for driver in ${2:-$DRIVERS}; do ( + if eval "type detect_$driver" 2>/dev/null >/dev/null; then + eval "detect_$driver" || echo "$driver: Detect failed" >&2 + else + echo "$driver: Hardware detection not supported" >&2 + fi + ); done +} + +start_net() {( + local iface="$1" + local config="$2" + local vifmac="$3" + + [ -f "/var/run/$iface.pid" ] && kill "$(cat /var/run/${iface}.pid)" 2>/dev/null + [ -z "$config" ] || { + include /lib/network + scan_interfaces + for config in $config; do + setup_interface "$iface" "$config" "" "$vifmac" + done + } +)} + +set_wifi_up() { + local cfg="$1" + local ifname="$2" + uci_set_state wireless "$cfg" up 1 + uci_set_state wireless "$cfg" ifname "$ifname" +} + +set_wifi_down() { + local cfg="$1" + local vifs vif vifstr + + [ -f "/var/run/wifi-${cfg}.pid" ] && + kill "$(cat "/var/run/wifi-${cfg}.pid")" 2>/dev/null + uci_revert_state wireless "$cfg" + config_get vifs "$cfg" vifs + for vif in $vifs; do + uci_revert_state wireless "$vif" + done +} + +scan_wifi() { + local cfgfile="$1" + DEVICES= + config_cb() { + local type="$1" + local section="$2" + + # section start + case "$type" in + wifi-device) + append DEVICES "$section" + config_set "$section" vifs "" + config_set "$section" ht_capab "" + ;; + esac + + # section end + config_get TYPE "$CONFIG_SECTION" TYPE + case "$TYPE" in + wifi-iface) + config_get device "$CONFIG_SECTION" device + config_get vifs "$device" vifs + append vifs "$CONFIG_SECTION" + config_set "$device" vifs "$vifs" + ;; + esac + } + config_load "${cfgfile:-wireless}" +} + +DEVICES= +DRIVERS= +include /lib/wifi +scan_wifi + +case "$1" in + down) wifi_updown "disable" "$2";; + detect) wifi_detect "$2";; + status) ubus_wifi_cmd "status" "$2";; + reload) wifi_reload "$2";; + reload_legacy) wifi_reload_legacy "$2";; + --help|help) usage;; + *) ubus call network reload; wifi_updown "enable" "$2";; +esac diff --git a/bsp/include/dtb.mk b/bsp/include/dtb.mk new file mode 100644 index 00000000..2c9c6001 --- /dev/null +++ b/bsp/include/dtb.mk @@ -0,0 +1,9 @@ + +dtb: + @echo "making device tree ...." + mkdir -p $(AW_STAGING)/dtb/ + mkdir -p $(AW_STAGING)/buildroot/images/ + $(AW_STAGING)/cross/usr/bin/fdtdump $(AW_STAGING)/buildroot/build/rpi-firmware-*/boot/$(DTB_BASE).dtb > $(AW_STAGING)/dtb/$(DTB_BASE).dts + cat $(AW_STAGING)/dtb/$(DTB_BASE).dts | tail -n +2 > $(AW_STAGING)/dtb/$(DTB_BASE).dti + cp dts/*.dt* $(AW_STAGING)/dtb/ + $(AW_STAGING)/cross/usr/bin/dtc -O dtb -o $(AW_STAGING)/buildroot/images/$(AW_PROJECT_NAME).dtb -i $(AW_STAGING)/dtb/ $(AW_STAGING)/dtb/$(AW_PROJECT_NAME).dts diff --git a/bsp/scripts/clean_external_packages.sh b/bsp/scripts/clean_external_packages.sh new file mode 100644 index 00000000..5cc30ab9 --- /dev/null +++ b/bsp/scripts/clean_external_packages.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +build_dir=$1 +external_dir=$2 + +echo "build dir : $build_dir" +echo "external dir : $external_dir" + +for file in ${external_dir}* +do + base_file=`basename $file` + full_file=`compgen -f ${build_dir}/${base_file}-*` + #echo "Processing $base_file" + #echo " >> $full_file" + if [ -n "$full_file" ]; then + # Do something when var is non-zero length + rm ${full_file}/.stamp_built + fi +done