mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-18 17:33:31 +00:00
ramips: add JD-Cloud router support (#3239)
* generic: support mtd-mac-address-ascii It supports formats of both 001122334455 and 00:11:22:33:44:55 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com> * ramips: add JDCloud Co-authored-by: Yousong Zhou <yszhou4tech@gmail.com>
This commit is contained in:
parent
5e271e43e3
commit
445949adbf
@ -32,17 +32,67 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
||||
{
|
||||
struct property *pp = of_find_property(np, name, NULL);
|
||||
|
||||
@@ -47,6 +48,79 @@ static const void *of_get_mac_addr(struc
|
||||
@@ -47,6 +48,138 @@ static const void *of_get_mac_addr(struc
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+typedef int(*mtd_mac_address_read)(struct mtd_info *mtd, loff_t from, u_char *buf);
|
||||
+
|
||||
+static int read_mtd_mac_address(struct mtd_info *mtd, loff_t from, u_char *mac)
|
||||
+{
|
||||
+ size_t retlen;
|
||||
+
|
||||
+ return mtd_read(mtd, from, 6, &retlen, mac);
|
||||
+}
|
||||
+
|
||||
+static int read_mtd_mac_address_ascii(struct mtd_info *mtd, loff_t from, u_char *mac)
|
||||
+{
|
||||
+ size_t retlen;
|
||||
+ char buf[17];
|
||||
+
|
||||
+ if (mtd_read(mtd, from, 12, &retlen, buf)) {
|
||||
+ return -1;
|
||||
+ }
|
||||
+ if (sscanf(buf, "%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
|
||||
+ &mac[0], &mac[1], &mac[2], &mac[3],
|
||||
+ &mac[4], &mac[5]) == 6) {
|
||||
+ if (mac[0] == '\0' && mac[1] == '\0') { /* First 2 bytes are zero, probably a bug. Trying to re-read */
|
||||
+ buf[4] = '\0'; /* Make it null-terminated */
|
||||
+ if (sscanf(buf, "%4hx", mac) == 1)
|
||||
+ *(uint16_t*)mac = htons(*(uint16_t*)mac);
|
||||
+ }
|
||||
+ return 0;
|
||||
+ }
|
||||
+ if (mtd_read(mtd, from+12, 5, &retlen, buf+12)) {
|
||||
+ return -1;
|
||||
+ }
|
||||
+ if (sscanf(buf, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
|
||||
+ &mac[0], &mac[1], &mac[2], &mac[3],
|
||||
+ &mac[4], &mac[5]) == 6) {
|
||||
+ return 0;
|
||||
+ }
|
||||
+ return -1;
|
||||
+}
|
||||
+
|
||||
+static struct mtd_mac_address_property {
|
||||
+ char *name;
|
||||
+ mtd_mac_address_read read;
|
||||
+} mtd_mac_address_properties[] = {
|
||||
+ {
|
||||
+ .name = "mtd-mac-address",
|
||||
+ .read = read_mtd_mac_address,
|
||||
+ }, {
|
||||
+ .name = "mtd-mac-address-ascii",
|
||||
+ .read = read_mtd_mac_address_ascii,
|
||||
+ },
|
||||
+};
|
||||
+
|
||||
+static const void *of_get_mac_address_mtd(struct device_node *np)
|
||||
+{
|
||||
+#ifdef CONFIG_MTD
|
||||
+ struct device_node *mtd_np = NULL;
|
||||
+ struct property *prop;
|
||||
+ size_t retlen;
|
||||
+ int size, ret;
|
||||
+ int size, ret = -1;
|
||||
+ struct mtd_info *mtd;
|
||||
+ const char *part;
|
||||
+ const __be32 *list;
|
||||
@ -51,28 +101,37 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
||||
+ u8 mac[ETH_ALEN];
|
||||
+ void *addr;
|
||||
+ u32 inc_idx;
|
||||
+ int i;
|
||||
+
|
||||
+ list = of_get_property(np, "mtd-mac-address", &size);
|
||||
+ if (!list || (size != (2 * sizeof(*list))))
|
||||
+ for (i = 0; i < ARRAY_SIZE(mtd_mac_address_properties); i++) {
|
||||
+ list = of_get_property(np, mtd_mac_address_properties[i].name, &size);
|
||||
+ if (!list || (size != (2 * sizeof(*list))))
|
||||
+ continue;
|
||||
+
|
||||
+ phandle = be32_to_cpup(list++);
|
||||
+ if (phandle)
|
||||
+ mtd_np = of_find_node_by_phandle(phandle);
|
||||
+
|
||||
+ if (!mtd_np)
|
||||
+ continue;
|
||||
+
|
||||
+ part = of_get_property(mtd_np, "label", NULL);
|
||||
+ if (!part)
|
||||
+ part = mtd_np->name;
|
||||
+
|
||||
+ mtd = get_mtd_device_nm(part);
|
||||
+ if (IS_ERR(mtd))
|
||||
+ continue;
|
||||
+
|
||||
+ ret = mtd_mac_address_properties[i].read(mtd, be32_to_cpup(list), mac);
|
||||
+ put_mtd_device(mtd);
|
||||
+ if (!ret) {
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ if (ret) {
|
||||
+ return NULL;
|
||||
+
|
||||
+ phandle = be32_to_cpup(list++);
|
||||
+ if (phandle)
|
||||
+ mtd_np = of_find_node_by_phandle(phandle);
|
||||
+
|
||||
+ if (!mtd_np)
|
||||
+ return NULL;
|
||||
+
|
||||
+ part = of_get_property(mtd_np, "label", NULL);
|
||||
+ if (!part)
|
||||
+ part = mtd_np->name;
|
||||
+
|
||||
+ mtd = get_mtd_device_nm(part);
|
||||
+ if (IS_ERR(mtd))
|
||||
+ return NULL;
|
||||
+
|
||||
+ ret = mtd_read(mtd, be32_to_cpup(list), 6, &retlen, mac);
|
||||
+ put_mtd_device(mtd);
|
||||
+ }
|
||||
+
|
||||
+ if (of_property_read_u32(np, "mtd-mac-address-increment-byte", &inc_idx))
|
||||
+ inc_idx = 5;
|
||||
@ -112,7 +171,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
||||
/**
|
||||
* Search the device tree for the best MAC address to use. 'mac-address' is
|
||||
* checked first, because that is supposed to contain to "most recent" MAC
|
||||
@@ -64,11 +138,18 @@ static const void *of_get_mac_addr(struc
|
||||
@@ -64,11 +192,18 @@ static const void *of_get_mac_addr(struc
|
||||
* addresses. Some older U-Boots only initialized 'local-mac-address'. In
|
||||
* this case, the real MAC is in 'local-mac-address', and 'mac-address' exists
|
||||
* but is all zeros.
|
||||
|
@ -32,17 +32,67 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
||||
{
|
||||
struct property *pp = of_find_property(np, name, NULL);
|
||||
|
||||
@@ -48,6 +49,79 @@ static const void *of_get_mac_addr(struc
|
||||
@@ -48,6 +49,138 @@ static const void *of_get_mac_addr(struc
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+typedef int(*mtd_mac_address_read)(struct mtd_info *mtd, loff_t from, u_char *buf);
|
||||
+
|
||||
+static int read_mtd_mac_address(struct mtd_info *mtd, loff_t from, u_char *mac)
|
||||
+{
|
||||
+ size_t retlen;
|
||||
+
|
||||
+ return mtd_read(mtd, from, 6, &retlen, mac);
|
||||
+}
|
||||
+
|
||||
+static int read_mtd_mac_address_ascii(struct mtd_info *mtd, loff_t from, u_char *mac)
|
||||
+{
|
||||
+ size_t retlen;
|
||||
+ char buf[17];
|
||||
+
|
||||
+ if (mtd_read(mtd, from, 12, &retlen, buf)) {
|
||||
+ return -1;
|
||||
+ }
|
||||
+ if (sscanf(buf, "%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
|
||||
+ &mac[0], &mac[1], &mac[2], &mac[3],
|
||||
+ &mac[4], &mac[5]) == 6) {
|
||||
+ if (mac[0] == '\0' && mac[1] == '\0') { /* First 2 bytes are zero, probably a bug. Trying to re-read */
|
||||
+ buf[4] = '\0'; /* Make it null-terminated */
|
||||
+ if (sscanf(buf, "%4hx", mac) == 1)
|
||||
+ *(uint16_t*)mac = htons(*(uint16_t*)mac);
|
||||
+ }
|
||||
+ return 0;
|
||||
+ }
|
||||
+ if (mtd_read(mtd, from+12, 5, &retlen, buf+12)) {
|
||||
+ return -1;
|
||||
+ }
|
||||
+ if (sscanf(buf, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
|
||||
+ &mac[0], &mac[1], &mac[2], &mac[3],
|
||||
+ &mac[4], &mac[5]) == 6) {
|
||||
+ return 0;
|
||||
+ }
|
||||
+ return -1;
|
||||
+}
|
||||
+
|
||||
+static struct mtd_mac_address_property {
|
||||
+ char *name;
|
||||
+ mtd_mac_address_read read;
|
||||
+} mtd_mac_address_properties[] = {
|
||||
+ {
|
||||
+ .name = "mtd-mac-address",
|
||||
+ .read = read_mtd_mac_address,
|
||||
+ }, {
|
||||
+ .name = "mtd-mac-address-ascii",
|
||||
+ .read = read_mtd_mac_address_ascii,
|
||||
+ },
|
||||
+};
|
||||
+
|
||||
+static const void *of_get_mac_address_mtd(struct device_node *np)
|
||||
+{
|
||||
+#ifdef CONFIG_MTD
|
||||
+ struct device_node *mtd_np = NULL;
|
||||
+ struct property *prop;
|
||||
+ size_t retlen;
|
||||
+ int size, ret;
|
||||
+ int size, ret = -1;
|
||||
+ struct mtd_info *mtd;
|
||||
+ const char *part;
|
||||
+ const __be32 *list;
|
||||
@ -51,28 +101,37 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
||||
+ u8 mac[ETH_ALEN];
|
||||
+ void *addr;
|
||||
+ u32 inc_idx;
|
||||
+ int i;
|
||||
+
|
||||
+ list = of_get_property(np, "mtd-mac-address", &size);
|
||||
+ if (!list || (size != (2 * sizeof(*list))))
|
||||
+ for (i = 0; i < ARRAY_SIZE(mtd_mac_address_properties); i++) {
|
||||
+ list = of_get_property(np, mtd_mac_address_properties[i].name, &size);
|
||||
+ if (!list || (size != (2 * sizeof(*list))))
|
||||
+ continue;
|
||||
+
|
||||
+ phandle = be32_to_cpup(list++);
|
||||
+ if (phandle)
|
||||
+ mtd_np = of_find_node_by_phandle(phandle);
|
||||
+
|
||||
+ if (!mtd_np)
|
||||
+ continue;
|
||||
+
|
||||
+ part = of_get_property(mtd_np, "label", NULL);
|
||||
+ if (!part)
|
||||
+ part = mtd_np->name;
|
||||
+
|
||||
+ mtd = get_mtd_device_nm(part);
|
||||
+ if (IS_ERR(mtd))
|
||||
+ continue;
|
||||
+
|
||||
+ ret = mtd_mac_address_properties[i].read(mtd, be32_to_cpup(list), mac);
|
||||
+ put_mtd_device(mtd);
|
||||
+ if (!ret) {
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ if (ret) {
|
||||
+ return NULL;
|
||||
+
|
||||
+ phandle = be32_to_cpup(list++);
|
||||
+ if (phandle)
|
||||
+ mtd_np = of_find_node_by_phandle(phandle);
|
||||
+
|
||||
+ if (!mtd_np)
|
||||
+ return NULL;
|
||||
+
|
||||
+ part = of_get_property(mtd_np, "label", NULL);
|
||||
+ if (!part)
|
||||
+ part = mtd_np->name;
|
||||
+
|
||||
+ mtd = get_mtd_device_nm(part);
|
||||
+ if (IS_ERR(mtd))
|
||||
+ return NULL;
|
||||
+
|
||||
+ ret = mtd_read(mtd, be32_to_cpup(list), 6, &retlen, mac);
|
||||
+ put_mtd_device(mtd);
|
||||
+ }
|
||||
+
|
||||
+ if (of_property_read_u32(np, "mtd-mac-address-increment-byte", &inc_idx))
|
||||
+ inc_idx = 5;
|
||||
@ -112,7 +171,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
||||
/**
|
||||
* Search the device tree for the best MAC address to use. 'mac-address' is
|
||||
* checked first, because that is supposed to contain to "most recent" MAC
|
||||
@@ -65,11 +139,18 @@ static const void *of_get_mac_addr(struc
|
||||
@@ -65,11 +193,18 @@ static const void *of_get_mac_addr(struc
|
||||
* addresses. Some older U-Boots only initialized 'local-mac-address'. In
|
||||
* this case, the real MAC is in 'local-mac-address', and 'mac-address' exists
|
||||
* but is all zeros.
|
||||
|
144
target/linux/ramips/dts/mt7621_jdcloud_re-sp-01b.dts
Normal file
144
target/linux/ramips/dts/mt7621_jdcloud_re-sp-01b.dts
Normal file
@ -0,0 +1,144 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
|
||||
/dts-v1/;
|
||||
|
||||
#include "mt7621.dtsi"
|
||||
|
||||
#include <dt-bindings/gpio/gpio.h>
|
||||
#include <dt-bindings/input/input.h>
|
||||
|
||||
/ {
|
||||
compatible = "jdcloud,re-sp-01b", "mediatek,mt7621-soc";
|
||||
model = "JDCloud RE-SP-01B";
|
||||
|
||||
aliases {
|
||||
led-boot = &led_red;
|
||||
led-failsafe = &led_red;
|
||||
led-running = &led_green;
|
||||
led-upgrade = &led_blue;
|
||||
label-mac-device = ðernet;
|
||||
};
|
||||
|
||||
chosen {
|
||||
bootargs = "console=ttyS0,115200";
|
||||
};
|
||||
|
||||
keys {
|
||||
compatible = "gpio-keys";
|
||||
|
||||
reset {
|
||||
label = "reset";
|
||||
gpios = <&gpio0 18 GPIO_ACTIVE_LOW>;
|
||||
linux,code = <KEY_RESTART>;
|
||||
};
|
||||
};
|
||||
|
||||
leds {
|
||||
compatible = "gpio-leds";
|
||||
|
||||
led_red: red {
|
||||
label = "jdcloud:red:sys";
|
||||
gpios = <&gpio0 6 GPIO_ACTIVE_LOW>;
|
||||
panic-indicator;
|
||||
};
|
||||
|
||||
led_green: green {
|
||||
label = "jdcloud:green:sys";
|
||||
gpios = <&gpio0 8 GPIO_ACTIVE_LOW>;
|
||||
};
|
||||
|
||||
led_blue: blue {
|
||||
label = "jdcloud:blue:sys";
|
||||
gpios = <&gpio0 12 GPIO_ACTIVE_LOW>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&sdhci {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&spi0 {
|
||||
status = "okay";
|
||||
|
||||
flash@0 {
|
||||
compatible = "jedec,spi-nor";
|
||||
reg = <0>;
|
||||
spi-max-frequency = <50000000>;
|
||||
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
partition@0 {
|
||||
label = "u-boot";
|
||||
reg = <0x0 0x30000>;
|
||||
read-only;
|
||||
};
|
||||
|
||||
config: partition@30000 {
|
||||
label = "config";
|
||||
reg = <0x30000 0x10000>;
|
||||
read-only;
|
||||
};
|
||||
|
||||
factory: partition@40000 {
|
||||
label = "factory";
|
||||
reg = <0x40000 0x10000>;
|
||||
read-only;
|
||||
};
|
||||
|
||||
partition@50000 {
|
||||
compatible = "denx,uimage";
|
||||
label = "firmware";
|
||||
reg = <0x50000 0x1ab0000>;
|
||||
};
|
||||
|
||||
partition@1b00000 {
|
||||
label = "mini";
|
||||
reg = <0x1b00000 0x400000>;
|
||||
read-only;
|
||||
};
|
||||
|
||||
partition@1f00000 {
|
||||
label = "oem";
|
||||
reg = <0x1f00000 0x100000>;
|
||||
read-only;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
ðernet {
|
||||
mtd-mac-address-ascii = <&config 0x4429>;
|
||||
};
|
||||
|
||||
&pcie {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&pcie0 {
|
||||
wifi@0,0 {
|
||||
reg = <0x0000 0 0 0 0>;
|
||||
mtd-mac-address-ascii = <&config 0x4429>;
|
||||
mediatek,mtd-eeprom = <&factory 0x0>;
|
||||
};
|
||||
};
|
||||
|
||||
&pcie1 {
|
||||
wifi@0,0 {
|
||||
reg = <0x0000 0 0 0 0>;
|
||||
mtd-mac-address-ascii = <&config 0x4429>;
|
||||
mtd-mac-address-increment = <0x80>;
|
||||
mtd-mac-address-increment-byte = <3>;
|
||||
mediatek,mtd-eeprom = <&factory 0x8000>;
|
||||
ieee80211-freq-limit = <5000000 6000000>;
|
||||
};
|
||||
};
|
||||
|
||||
&state_default {
|
||||
gpio {
|
||||
ralink,group = "uart2", "uart3", "wdt";
|
||||
ralink,function = "gpio";
|
||||
};
|
||||
};
|
@ -385,6 +385,14 @@ define Device/jcg_jhr-ac876m
|
||||
endef
|
||||
TARGET_DEVICES += jcg_jhr-ac876m
|
||||
|
||||
define Device/jdcloud_re-sp-01b
|
||||
IMAGE_SIZE := 27328k
|
||||
DEVICE_VENDOR := JDCloud
|
||||
DEVICE_MODEL := RE-SP-01B
|
||||
DEVICE_PACKAGES := kmod-fs-ext4 kmod-mt7603 kmod-mt7615e kmod-sdhci-mt7620 kmod-usb3 wpad-openssl
|
||||
endef
|
||||
TARGET_DEVICES += jdcloud_re-sp-01b
|
||||
|
||||
define Device/lenovo_newifi-d1
|
||||
IMAGE_SIZE := 32448k
|
||||
DEVICE_VENDOR := Newifi
|
||||
|
@ -124,6 +124,7 @@ ramips_setup_interfaces()
|
||||
ucidef_add_switch_attr "switch0" "enable" "false"
|
||||
ucidef_set_interface_lan "eth0"
|
||||
;;
|
||||
jdcloud,re-sp-01b|\
|
||||
mikrotik,rbm33g)
|
||||
ucidef_add_switch "switch0" \
|
||||
"1:lan" "2:lan" "0:wan" "6@eth0"
|
||||
|
Loading…
Reference in New Issue
Block a user