Skip to content

Commit

Permalink
Add Support for RTL8196E RTL8197D RTL8197F
Browse files Browse the repository at this point in the history
  • Loading branch information
ggbruno committed Aug 4, 2020
1 parent 6dba5d7 commit fa23e55
Show file tree
Hide file tree
Showing 74 changed files with 10,010 additions and 0 deletions.
27 changes: 27 additions & 0 deletions target/linux/realtek/Makefile
@@ -0,0 +1,27 @@
#
# Copyright (C) 2008-2011 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk

ARCH:=mips
BOARD:=realtek
BOARDNAME:=Realtek
SUBTARGETS:=rtl8197d rtl8196e rtl8197f
FEATURES:=squashfs gpio
MAINTAINER:=Anlix <contato@anlix.io>

KERNEL_PATCHVER:=4.14

define Target/Description
Build firmware images for Realtek based boards.
endef

include $(INCLUDE_DIR)/target.mk

DEFAULT_PACKAGES += \
kmod-gpio-button-hotplug swconfig

$(eval $(call BuildTarget))
65 changes: 65 additions & 0 deletions target/linux/realtek/base-files/etc/board.d/01_leds
@@ -0,0 +1,65 @@
#!/bin/sh

. /lib/functions/uci-defaults.sh

board_config_update

board=$(cat /tmp/sysinfo/board_name)

case $board in
dir-815-d1)
ucidef_set_led_switch "lan1" "lan1" "rtl819x:green:lan1" "switch0" "0x1"
ucidef_set_led_switch "lan2" "lan2" "rtl819x:green:lan2" "switch0" "0x2"
ucidef_set_led_switch "lan3" "lan3" "rtl819x:green:lan3" "switch0" "0x4"
ucidef_set_led_switch "lan4" "lan4" "rtl819x:green:lan4" "switch0" "0x8"
ucidef_set_led_switch "wan" "wan" "rtl819x:green:wan" "switch0" "0x10"
ucidef_set_led_netdev "wifi_led_2g" "wifi_2g" "rtl8192cd:green:wifi2" "wlan0"
ucidef_set_led_netdev "wifi_led_5g" "wifi_5g" "rtl8192cd:green:wifi5" "wlan1"
;;
gwr-300n-v1|\
re172-v1)
ucidef_set_led_switch "lan1" "lan1" "rtl819x:green:lan1" "switch0" "0x1"
ucidef_set_led_switch "lan2" "lan2" "rtl819x:green:lan2" "switch0" "0x2"
ucidef_set_led_switch "lan3" "lan3" "rtl819x:green:lan3" "switch0" "0x4"
ucidef_set_led_switch "lan4" "lan4" "rtl819x:green:lan4" "switch0" "0x8"
ucidef_set_led_switch "wan" "wan" "rtl819x:green:wan" "switch0" "0x10"
ucidef_set_led_netdev "wifi_led_2g" "wifi_2g" "rtl8192cd:green:wifi2" "wlan0"
;;
actionrg1200-v1)
ucidef_set_led_netdev "lan" "lan" "actionrg1200:blue:lan" "eth0" "tx rx"
ucidef_set_led_netdev "wan" "wan" "actionrg1200:blue:wan" "eth1" "tx rx"
ucidef_set_led_netdev "wifi0" "wifi0" "actionrg1200:blue:wifi0" "wlan0" "link tx rx"
ucidef_set_led_default "sys" "sys" "actionrg1200:blue:sys" "1"
;;
actionrf1200-v1)
ucidef_set_led_netdev "wifi0" "wifi0" "actionrf1200:blue:wifi0" "wlan0" "link tx rx"
ucidef_set_led_default "sys" "sys" "actionrf1200:blue:sys" "1"
;;
re708-v1)
ucidef_set_led_switch "wan" "wan" "rtl8367r:green:wan" "switch0" "0x10"
ucidef_set_led_switch "lan1" "lan1" "rtl8367r:green:lan1" "switch0" "0x1"
ucidef_set_led_switch "lan2" "lan2" "rtl8367r:green:lan2" "switch0" "0x2"
ucidef_set_led_switch "lan3" "lan3" "rtl8367r:green:lan3" "switch0" "0x4"
ucidef_set_led_switch "lan4" "lan4" "rtl8367r:green:lan4" "switch0" "0x8"
ucidef_set_led_netdev "wifi0" "wifi0" "rtl8192cd:green:wifi0" "wlan0" "link tx rx"
ucidef_set_led_netdev "wifi1" "wifi1" "rtl8192cd:green:wifi1" "wlan1" "link tx rx"
# Breaks device switch. Still needs fix before using it
# ucidef_set_led_default "wps" "wps" "re708:green:wps" "0"
;;
gwr1200ac-v1)
ucidef_set_led_netdev "wifi0" "wifi0" "rtl8192cd:green:wifi0" "wlan0" "link tx rx"
ucidef_set_led_netdev "wifi1" "wifi1" "rtl8192cd:green:wifi1" "wlan1" "link tx rx"
# Breaks device switch. Still needs fix before using it
# ucidef_set_led_default "wps" "wps" "gwr1200ac:green:wps" "0"
;;
gwr1200ac-v2)
ucidef_set_led_default "wifi0" "wifi0" "rtl8192cd:green:wifi0" "1"
ucidef_set_led_default "wifi1" "wifi1" "rtl8192cd:green:wifi1" "1"
# Breaks device switch. Still needs fix before using it
# ucidef_set_led_default "wps" "wps" "gwr1200ac:green:wps" "0"
;;
esac

board_config_flush

exit 0
53 changes: 53 additions & 0 deletions target/linux/realtek/base-files/etc/board.d/02_network
@@ -0,0 +1,53 @@
#!/bin/sh

. /lib/functions.sh
. /lib/functions/uci-defaults.sh
. /lib/functions/system.sh

board_config_update
board=$(cat /tmp/sysinfo/board_name)

ucidef_set_interfaces_lan_wan "eth0" "eth1"

lan_mac=""
wan_mac=""

case $board in
dir-815-d1)
offset=$(strings -t x "$(find_mtd_part boot)" | grep llconfig | head -n 1 | awk '{ print "0x"$1 }')
offset=$((offset+53))
wan_mac=$(mtd_get_mac_binary boot $offset)
lan_mac=$(macaddr_add "$wan_mac" 1)
;;
re708-v1)
wan_mac=$(mtd_get_mac_binary boot 131079)
lan_mac=$(macaddr_add "$wan_mac" 1)
;;
gwr1200ac-v1)
wan_mac=$(mtd_get_mac_binary boot 131091)
lan_mac=$(macaddr_add "$wan_mac" 1)
;;
gwr1200ac-v2)
wan_mac=$(mtd_get_mac_binary boot 131091)
lan_mac=$(macaddr_add "$wan_mac" 1)
;;
actionrg1200-v1 | \
actionrf1200-v1)
wan_mac=$(mtd_get_mac_ascii boot HW_NIC0_ADDR)
lan_mac=$(macaddr_add "$wan_mac" 1)
;;
gwr-300n-v1)
wan_mac=$(mtd_get_mac_binary boot 24595)
lan_mac=$(mtd_get_mac_binary boot 24583)
;;
re172-v1)
wan_mac=$(mtd_get_mac_binary boot 24583)
lan_mac=$(mtd_get_mac_binary boot 24595)
esac

[ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
[ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac

board_config_flush

exit 0
47 changes: 47 additions & 0 deletions target/linux/realtek/base-files/etc/uci-defaults/09_fix-header
@@ -0,0 +1,47 @@
#!/bin/sh

. /lib/functions.sh
. /lib/functions/system.sh

fix_header() {
mtdblock_path=$(find_mtd_part firmware)
mtdblockroot_path=$(find_mtd_part rootfs)
mtdblockfs_path=$(find_mtd_part rootfs_data)
mtdblockroot_size=$(mtd_get_part_size rootfs)
mtdblockfs_size=$(mtd_get_part_size rootfs_data)
mtdblockfsdiff_size=$((mtdblockroot_size-mtdblockfs_size))

imgsize_after_format=$(dd if=$mtdblockroot_path bs=1 skip=$((mtdblockfsdiff_size-16)) count=4 2> /dev/null | \
hexdump -C | awk 'NR==1 {printf $2$3$4$5}')

imutable_hex=$(dd if=$mtdblock_path bs=1 count=12 2> /dev/null | \
hexdump -C | awk 'NR==1 {printf $2$3$4$5$6$7$8$9$10$11$12$13}')

size_discounted_hex=
imutable_hex_concat=

for i in `seq 0 2 6`
do
draw="${imgsize_after_format:i:2}"
size_discounted_hex=$size_discounted_hex'\x'$draw
done

for i in `seq 0 2 22`
do
dimun="${imutable_hex:i:2}"
imutable_hex_concat=$imutable_hex_concat'\x'$dimun
done

printf $imutable_hex_concat$size_discounted_hex > /tmp/newcvimgheader.bin
dd if=/tmp/newcvimgheader.bin bs=1 count=16 of=$mtdblock_path 2> /dev/null
rm /tmp/newcvimgheader.bin
}

board=$(board_name)

case "$board" in
actionrg1200-v1 | \
actionrf1200-v1)
fix_header
;;
esac
@@ -0,0 +1,9 @@
#!/bin/sh

do_realtek_board_detection() {
. /lib/realtek.sh

realtek_board_detect
}

boot_hook_add preinit_main do_realtek_board_detection
50 changes: 50 additions & 0 deletions target/linux/realtek/base-files/lib/realtek.sh
@@ -0,0 +1,50 @@
#!/bin/sh
#
# Copyright (C) 2009-2011 OpenWrt.org
#

realtek_board_detect() {
local machine
local name

machine=$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /machine/ {print $2}' /proc/cpuinfo)

case "$machine" in
"GENERIC")
name="rlx"
;;
*"DIR-815 D1")
name="dir-815-d1"
;;
*"GWR-300N V1")
name="gwr-300n-v1"
;;
*"RE172 V1")
name="re172-v1"
;;
*"RE708 V1")
name="re708-v1"
;;
*"GWR1200AC V1")
name="gwr1200ac-v1"
;;
*"GWR1200AC V2")
name="gwr1200ac-v2"
;;
*"ACTIONRG1200 V1")
name="actionrg1200-v1"
;;
*"ACTIONRF1200 V1")
name="actionrf1200-v1"
;;
esac

# use generic board detect if no name is set
[ -z "$name" ] && return

[ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"

echo "$name" > /tmp/sysinfo/board_name
echo "$machine" > /tmp/sysinfo/model
}

16 changes: 16 additions & 0 deletions target/linux/realtek/base-files/lib/upgrade/platform.sh
@@ -0,0 +1,16 @@
#
# Copyright (C) 2011 OpenWrt.org
#

. /lib/functions/system.sh
. /lib/realtek.sh

PART_NAME=firmware

platform_do_upgrade() {
default_do_upgrade "$1"
}

platform_check_image() {
return 0
}
112 changes: 112 additions & 0 deletions target/linux/realtek/dts/ACTIONRF1200.dts
@@ -0,0 +1,112 @@
// SPDX-License-Identifier: GPL-2.0
/dts-v1/;

#include "RTL8197F.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>

/ {
compatible = "intelbras,actionrf1200", "realtek,rtl8197f-soc";
model = "Intelbras ACTIONRF1200 V1";

aliases {
led-boot = &led_status;
led-failsafe = &led_status;
led-running = &led_status;
led-upgrade = &led_status;
};

memory {
device_type = "memory";
reg = <0x0 0x4000000>;
};

chosen {
bootargs = "console=ttyS0,115200";
};

gpio-keys-polled {
compatible = "gpio-keys-polled";
#address-cells = <1>;
#size-cells = <0>;
poll-interval = <20>;

reset {
label = "reset";
gpios = <&gpio0 19 GPIO_ACTIVE_LOW>;
linux,code = <KEY_RESTART>;
};
};

gpio-leds {
compatible = "gpio-leds";

led_status: sys {
label = "actionrf1200:blue:sys";
gpios = <&gpio0 15 GPIO_ACTIVE_LOW>;
};

wifi0 {
label = "actionrf1200:blue:wifi0";
gpios = <&gpio1 1 GPIO_ACTIVE_LOW>;
};

wan {
label = "actionrf1200:blue:wan";
gpios = <&gpio1 22 GPIO_ACTIVE_LOW>;
};

lan0 {
label = "actionrf1200:blue:lan0";
gpios = <&gpio1 25 GPIO_ACTIVE_LOW>;
};

lan1 {
label = "actionrf1200:blue:lan1";
gpios = <&gpio1 24 GPIO_ACTIVE_LOW>;
};

lan2 {
label = "actionrf1200:blue:lan2";
gpios = <&gpio1 23 GPIO_ACTIVE_LOW>;
};
};
};

&gpio0 {
status = "okay";
};

&gpio1 {
status = "okay";
};

&spi0 {
status = "okay";

m25p80@0 {
#address-cells = <1>;
#size-cells = <1>;
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <41000000>;

partition@0 {
label = "boot";
reg = <0x0 0x30000>;
read-only;
};

partition@30000 {
label = "firmware";
reg = <0x30000 0x7B0000>;
};

partition@7E0000 {
label = "config";
reg = <0x7E0000 0x20000>;
read-only;
};
};
};

4 comments on commit fa23e55

@MattWestb
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey is the RTL8196E working in your implementation ?
I like getting openWRT running on tuya zigbee gateway with ethernet and its have one RTL8196E.
Only need the ethernet working and tunneling one comport to ZHA.

Thanks in advance !!!

@ggbruno
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the port of 96E to the new kernel 4.14.
Im currently working on the port for 5.4 and the network driver....
But you can use the realtek network driver. It works with this implementation.
You can get a package for openwrt in older repositories. Realtek have open the driver in openwrt BB.
Here is a source that I found in github, but there are others....
https://github.com/vladisslav2011/openwrt-AC10/tree/openwrt-18.06-rtkmipsel-3.18/target/linux/rtkmipsel/files/drivers/net/rtl819x

@Dimazhan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
I finished 5.4 from your 4.14 patches, but I only have totolink a3002ru (rtl8197dn) to check
as I understand it differs from dir815 by having an external switch

Why do you use the 80010000 address in the line
are you running dir815?
a3002ru started with address 80000000 only

@ggbruno
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dimazhan Thats great. I will upload a dsa driver for rtl819x shortly... This way, we can have the first working set...
The 80010000 address is from d-link dir815. This is the only 97D I have here...
I can work on a patch to make this address dynamic, like a variable in the openwrt image makefile.

Please sign in to comment.