From 53c474abbdfef8eb3499e2d10c9ad491788b8a72 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Sun, 6 May 2018 10:20:11 +0200 Subject: ath79: add new OF only target for QCA MIPS silicon This target aims to replace ar71xx mid-term. The big part that is still missing is making the MMIO/AHB wifi work using OF. NAND and mikrotik subtargets will follow. Signed-off-by: John Crispin --- target/linux/ath79/base-files/etc/board.d/01_leds | 21 ++ .../linux/ath79/base-files/etc/board.d/02_network | 44 ++++ target/linux/ath79/base-files/etc/diag.sh | 38 ++++ .../etc/hotplug.d/firmware/10-ath9k-eeprom | 40 ++++ .../etc/hotplug.d/firmware/11-ath10k-caldata | 58 ++++++ .../linux/ath79/base-files/lib/upgrade/platform.sh | 224 +++++++++++++++++++++ 6 files changed, 425 insertions(+) create mode 100644 target/linux/ath79/base-files/etc/board.d/01_leds create mode 100644 target/linux/ath79/base-files/etc/board.d/02_network create mode 100644 target/linux/ath79/base-files/etc/diag.sh create mode 100644 target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom create mode 100644 target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata create mode 100644 target/linux/ath79/base-files/lib/upgrade/platform.sh (limited to 'target/linux/ath79/base-files') diff --git a/target/linux/ath79/base-files/etc/board.d/01_leds b/target/linux/ath79/base-files/etc/board.d/01_leds new file mode 100644 index 0000000000..9d42861939 --- /dev/null +++ b/target/linux/ath79/base-files/etc/board.d/01_leds @@ -0,0 +1,21 @@ +#!/bin/sh + +. /lib/functions/uci-defaults.sh + +board_config_update + +board=$(board_name) + +case "$board" in +"glinet,ar150") + ucidef_set_led_wlan "wlan" "WLAN" "gl-ar150:orange:wlan" "phy0tpt" + ;; +"tplink,tl-wr1043nd-v1") + ucidef_set_led_usbdev "usb" "USB" "tp-link:green:usb" "1-1" + ucidef_set_led_wlan "wlan" "WLAN" "tp-link:green:wlan" "phy0tpt" + ;; +esac + +board_config_flush + +exit 0 diff --git a/target/linux/ath79/base-files/etc/board.d/02_network b/target/linux/ath79/base-files/etc/board.d/02_network new file mode 100644 index 0000000000..941d2ab511 --- /dev/null +++ b/target/linux/ath79/base-files/etc/board.d/02_network @@ -0,0 +1,44 @@ +#!/bin/sh + +. /lib/functions/system.sh +. /lib/functions/uci-defaults.sh + +ath79_setup_interfaces() +{ + local board="$1" + + case "$board" in + "ubnt,unifi") + ucidef_set_interface_lan "eth0" + ;; + + "tplink,tl-wr1043nd-v1") + ucidef_add_switch "switch0" \ + "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0" + ;; + "netgear,wndr3800") + ucidef_set_interfaces_lan_wan "eth0" "eth1" + ucidef_add_switch "switch0" \ + "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "5u@eth0" + + ucidef_add_switch_attr "switch0" "blinkrate" 2 + ucidef_add_switch_port_attr "switch0" 1 led 6 + ucidef_add_switch_port_attr "switch0" 2 led 9 + ucidef_add_switch_port_attr "switch0" 5 led 2 + ;; + "buffalo,wzr-hp-g450h") + ucidef_add_switch "switch0" \ + "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan" + ;; + *) + ucidef_set_interfaces_lan_wan "eth0" "eth1" + ;; + esac +} + +board_config_update +board=$(board_name) +ath79_setup_interfaces $board +board_config_flush + +exit 0 diff --git a/target/linux/ath79/base-files/etc/diag.sh b/target/linux/ath79/base-files/etc/diag.sh new file mode 100644 index 0000000000..c9b32df94e --- /dev/null +++ b/target/linux/ath79/base-files/etc/diag.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +. /lib/functions/leds.sh + +get_status_led() { + local board=$(board_name) + + case $board in + "glinet,ar150") + status_led="gl-ar150:orange:wlan" + ;; + "tplink,tl-wr1043nd-v1") + status_led="tp-link:green:system" + ;; + "ubnt,unifi") + status_led="ubnt:green:dome" + ;; + esac +} + +set_state() { + get_status_led + + case "$1" in + preinit) + status_led_blink_preinit + ;; + failsafe) + status_led_blink_failsafe + ;; + preinit_regular) + status_led_blink_preinit_regular + ;; + done) + status_led_on + ;; + esac +} diff --git a/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom b/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom new file mode 100644 index 0000000000..fc15caea6f --- /dev/null +++ b/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom @@ -0,0 +1,40 @@ +#!/bin/sh + +[ -e /lib/firmware/$FIRMWARE ] && exit 0 + +. /lib/functions.sh +. /lib/functions/system.sh + +ath9k_eeprom_die() { + echo "ath9k eeprom: " "$*" + exit 1 +} + +ath9k_eeprom_extract() { + local part=$1 + local offset=$2 + local count=$3 + local mtd + + mtd=$(find_mtd_chardev $part) + [ -n "$mtd" ] || \ + ath9k_eeprom_die "no mtd device found for partition $part" + + dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \ + ath9k_eeprom_die "failed to extract from $mtd" +} + +board=$(board_name) + +case "$FIRMWARE" in +"ath9k-eeprom-pci-0000:00:00.0.bin") + case $board in + "ubnt,unifi") + ath9k_eeprom_extract "art" 4096 2048 + ;; + *) + ath9k_eeprom_die "board $board is not supported yet" + ;; + esac + ;; +esac diff --git a/target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata new file mode 100644 index 0000000000..2bbe5923bc --- /dev/null +++ b/target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata @@ -0,0 +1,58 @@ +#!/bin/sh + +ath10kcal_die() { + echo "ath10cal: " "$*" + exit 1 +} + +ath10kcal_from_file() { + local source=$1 + local offset=$2 + local count=$3 + + dd if=$source of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \ + ath10kcal_die "failed to extract calibration data from $source" +} + +ath10kcal_extract() { + local part=$1 + local offset=$2 + local count=$3 + local mtd + + mtd=$(find_mtd_chardev $part) + [ -n "$mtd" ] || \ + ath10kcal_die "no mtd device found for partition $part" + + dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \ + ath10kcal_die "failed to extract calibration data from $mtd" +} + +ath10kcal_patch_mac() { + local mac=$1 + + [ -z "$mac" ] && return + + macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=6 count=6 +} + +[ -e /lib/firmware/$FIRMWARE ] && exit 0 + +. /lib/functions.sh +. /lib/functions/system.sh + +board=$(board_name) + +case "$FIRMWARE" in +"ath10k/cal-pci-0000:00:00.0.bin") + case $board in + openmesh,om5p-ac-v2) + ath10kcal_extract "ART" 20480 2116 + ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +16) + ;; + esac + ;; +*) + exit 1 + ;; +esac diff --git a/target/linux/ath79/base-files/lib/upgrade/platform.sh b/target/linux/ath79/base-files/lib/upgrade/platform.sh new file mode 100644 index 0000000000..b2b55e64e3 --- /dev/null +++ b/target/linux/ath79/base-files/lib/upgrade/platform.sh @@ -0,0 +1,224 @@ +# +# Copyright (C) 2011 OpenWrt.org +# + +. /lib/functions/system.sh + +PART_NAME=firmware +RAMFS_COPY_BIN='nandwrite' + +CI_BLKSZ=65536 +CI_LDADR=0x80060000 + +PLATFORM_DO_UPGRADE_COMBINED_SEPARATE_MTD=0 + +platform_find_partitions() { + local first dev size erasesize name + while read dev size erasesize name; do + name=${name#'"'}; name=${name%'"'} + case "$name" in + vmlinux.bin.l7|vmlinux|kernel|linux|linux.bin|rootfs|filesystem) + if [ -z "$first" ]; then + first="$name" + else + echo "$erasesize:$first:$name" + break + fi + ;; + esac + done < /proc/mtd +} + +platform_find_kernelpart() { + local part + for part in "${1%:*}" "${1#*:}"; do + case "$part" in + vmlinux.bin.l7|vmlinux|kernel|linux|linux.bin) + echo "$part" + break + ;; + esac + done +} + +platform_find_rootfspart() { + local part + for part in "${1%:*}" "${1#*:}"; do + [ "$part" != "$2" ] && echo "$part" && break + done +} + +platform_do_upgrade_combined() { + local partitions=$(platform_find_partitions) + local kernelpart=$(platform_find_kernelpart "${partitions#*:}") + local erase_size=$((0x${partitions%%:*})); partitions="${partitions#*:}" + local kern_length=0x$(dd if="$1" bs=2 skip=1 count=4 2>/dev/null) + local kern_blocks=$(($kern_length / $CI_BLKSZ)) + local root_blocks=$((0x$(dd if="$1" bs=2 skip=5 count=4 2>/dev/null) / $CI_BLKSZ)) + + if [ -n "$partitions" ] && [ -n "$kernelpart" ] && \ + [ ${kern_blocks:-0} -gt 0 ] && \ + [ ${root_blocks:-0} -gt 0 ] && \ + [ ${erase_size:-0} -gt 0 ]; + then + local rootfspart=$(platform_find_rootfspart "$partitions" "$kernelpart") + local append="" + [ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 ] && append="-j $CONF_TAR" + + if [ "$PLATFORM_DO_UPGRADE_COMBINED_SEPARATE_MTD" -ne 1 ]; then + ( dd if="$1" bs=$CI_BLKSZ skip=1 count=$kern_blocks 2>/dev/null; \ + dd if="$1" bs=$CI_BLKSZ skip=$((1+$kern_blocks)) count=$root_blocks 2>/dev/null ) | \ + mtd -r $append -F$kernelpart:$kern_length:$CI_LDADR,rootfs write - $partitions + elif [ -n "$rootfspart" ]; then + dd if="$1" bs=$CI_BLKSZ skip=1 count=$kern_blocks 2>/dev/null | \ + mtd write - $kernelpart + dd if="$1" bs=$CI_BLKSZ skip=$((1+$kern_blocks)) count=$root_blocks 2>/dev/null | \ + mtd -r $append write - $rootfspart + fi + fi + PLATFORM_DO_UPGRADE_COMBINED_SEPARATE_MTD=0 +} + +tplink_get_image_hwid() { + get_image "$@" | dd bs=4 count=1 skip=16 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"' +} + +tplink_get_image_mid() { + get_image "$@" | dd bs=4 count=1 skip=17 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"' +} + +tplink_get_image_boot_size() { + get_image "$@" | dd bs=4 count=1 skip=37 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"' +} + +tplink_pharos_check_image() { + local magic_long="$(get_magic_long "$1")" + [ "$magic_long" != "7f454c46" ] && { + echo "Invalid image magic '$magic_long'" + return 1 + } + + local model_string="$(tplink_pharos_get_model_string)" + local line + + # Here $1 is given to dd directly instead of get_image as otherwise the skip + # will take almost a second (as dd can't seek then) + # + # This will fail if the image isn't local, but that's fine: as the + # read loop won't be executed at all, it will return true, so the image + # is accepted (loading the first 1.5M of a remote image for this check seems + # a bit extreme) + dd if="$1" bs=1 skip=1511432 count=1024 2>/dev/null | while read line; do + [ "$line" = "$model_string" ] && break + done || { + echo "Unsupported image (model not in support-list)" + return 1 + } + + return 0 +} + +seama_get_type_magic() { + get_image "$@" | dd bs=1 count=4 skip=53 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"' +} + +wrgg_get_image_magic() { + get_image "$@" | dd bs=4 count=1 skip=8 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"' +} + +cybertan_get_image_magic() { + get_image "$@" | dd bs=8 count=1 skip=0 2>/dev/null | hexdump -v -n 8 -e '1/1 "%02x"' +} + +cybertan_check_image() { + local magic="$(cybertan_get_image_magic "$1")" + local fw_magic="$(cybertan_get_hw_magic)" + + [ "$fw_magic" != "$magic" ] && { + echo "Invalid image, ID mismatch, got:$magic, but need:$fw_magic" + return 1 + } + + return 0 +} + +platform_do_upgrade_compex() { + local fw_file=$1 + local fw_part=$PART_NAME + local fw_mtd=$(find_mtd_part $fw_part) + local fw_length=0x$(dd if="$fw_file" bs=2 skip=1 count=4 2>/dev/null) + local fw_blocks=$(($fw_length / 65536)) + + if [ -n "$fw_mtd" ] && [ ${fw_blocks:-0} -gt 0 ]; then + local append="" + [ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 ] && append="-j $CONF_TAR" + + sync + dd if="$fw_file" bs=64k skip=1 count=$fw_blocks 2>/dev/null | \ + mtd $append write - "$fw_part" + fi +} + +alfa_check_image() { + local magic_long="$(get_magic_long "$1")" + local fw_part_size=$(mtd_get_part_size firmware) + + case "$magic_long" in + "27051956") + [ "$fw_part_size" != "16318464" ] && { + echo "Invalid image magic \"$magic_long\" for $fw_part_size bytes" + return 1 + } + ;; + "68737173") + [ "$fw_part_size" != "7929856" ] && { + echo "Invalid image magic \"$magic_long\" for $fw_part_size bytes" + return 1 + } + ;; + esac + + return 0 +} + +platform_check_image() { + local board=$(board_name) + local magic="$(get_magic_word "$1")" + local magic_long="$(get_magic_long "$1")" + + [ "$#" -gt 1 ] && return 1 + + case "$board" in + "ubnt,unifi") + [ "$magic" != "2705" ] && { + echo "Invalid image type." + return 1 + } + + return 0 + ;; + esac + + echo "Sysupgrade is not yet supported on $board." + return 1 +} + +platform_do_upgrade() { + local board=$(board_name) + + case "$board" in + *) + default_do_upgrade "$ARGV" + ;; + esac +} + +disable_watchdog() { + killall watchdog + ( ps | grep -v 'grep' | grep '/dev/watchdog' ) && { + echo 'Could not disable watchdog' + return 1 + } +} + +append sysupgrade_pre_upgrade disable_watchdog -- cgit v1.2.3