1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter.git synced 2025-03-09 15:40:20 +00:00

Add a directory by kernel instead of a common root, add qnap-301w and rpi4 kernel 6.1 suppport

This commit is contained in:
Ycarus (Yannick Chabanois) 2023-04-22 08:07:24 +02:00
parent e910436a7a
commit 46837ec4c0
9459 changed files with 362648 additions and 116345 deletions

View file

@ -0,0 +1,31 @@
# SPDX-License-Identifier: GPL-2.0-only
#
# Copyright (C) 2012-2020 OpenWrt.org
# Copyright (C) 2017 LEDE project
include $(TOPDIR)/rules.mk
ARCH:=arm
BOARD:=bcm27xx
BOARDNAME:=Broadcom BCM27xx
FEATURES:=ext4 usb usbgadget display gpio fpu squashfs rootfs-part boot-part
SUBTARGETS:=bcm2708 bcm2709 bcm2710 bcm2711
KERNEL_PATCHVER=5.4
define Target/Description
Build firmware image for Broadcom BCM27xx SoC devices.
Currently produces SD Card image for Raspberry Pi.
endef
include $(INCLUDE_DIR)/target.mk
DEFAULT_PACKAGES := $(filter-out urngd,$(DEFAULT_PACKAGES))
DEFAULT_PACKAGES += \
kmod-usb-hid \
kmod-fs-vfat kmod-nls-cp437 kmod-nls-iso8859-1 \
partx-utils mkf2fs e2fsprogs
KERNELNAME:=Image dtbs
$(eval $(call BuildTarget))

View file

@ -0,0 +1,80 @@
Index: linux-5.4.147/kernel/bpf/syscall.c
===================================================================
--- linux-5.4.147.orig/kernel/bpf/syscall.c
+++ linux-5.4.147/kernel/bpf/syscall.c
@@ -593,6 +593,11 @@ static int map_create(union bpf_attr *at
err = PTR_ERR(btf);
goto free_map;
}
+ if (btf_is_kernel(btf)) {
+ btf_put(btf);
+ err = -EACCES;
+ goto free_map;
+ }
err = map_check_btf(map, btf, attr->btf_key_type_id,
attr->btf_value_type_id);
Index: linux-5.4.147/kernel/bpf/verifier.c
===================================================================
--- linux-5.4.147.orig/kernel/bpf/verifier.c
+++ linux-5.4.147/kernel/bpf/verifier.c
@@ -6959,6 +6959,11 @@ static int check_btf_info(struct bpf_ver
btf = btf_get_by_fd(attr->prog_btf_fd);
if (IS_ERR(btf))
return PTR_ERR(btf);
+ if (btf_is_kernel(btf)) {
+ btf_put(btf);
+ return -EACCES;
+ }
+
env->prog->aux->btf = btf;
err = check_btf_func(env, attr, uattr);
Index: linux-5.4.147/include/linux/btf.h
===================================================================
--- linux-5.4.147.orig/include/linux/btf.h
+++ linux-5.4.147/include/linux/btf.h
@@ -47,6 +47,7 @@ void btf_type_seq_show(const struct btf
struct seq_file *m);
int btf_get_fd_by_id(u32 id);
u32 btf_id(const struct btf *btf);
+bool btf_is_kernel(const struct btf *btf);
bool btf_member_is_reg_int(const struct btf *btf, const struct btf_type *s,
const struct btf_member *m,
u32 expected_offset, u32 expected_size);
Index: linux-5.4.147/kernel/bpf/btf.c
===================================================================
--- linux-5.4.147.orig/kernel/bpf/btf.c
+++ linux-5.4.147/kernel/bpf/btf.c
@@ -212,6 +212,7 @@ struct btf {
refcount_t refcnt;
u32 id;
struct rcu_head rcu;
+ bool kernel_btf;
};
enum verifier_phase {
@@ -352,6 +353,11 @@ static bool btf_type_nosize(const struct
btf_type_is_func(t) || btf_type_is_func_proto(t);
}
+bool btf_is_kernel(const struct btf *btf)
+{
+ return btf->kernel_btf;
+}
+
static bool btf_type_nosize_or_null(const struct btf_type *t)
{
return !t || btf_type_nosize(t);
Index: linux-5.4.147/include/uapi/linux/bpf.h
===================================================================
--- linux-5.4.147.orig/include/uapi/linux/bpf.h
+++ linux-5.4.147/include/uapi/linux/bpf.h
@@ -3275,6 +3275,7 @@ struct bpf_btf_info {
__aligned_u64 btf;
__u32 btf_size;
__u32 id;
+ __u32 kernel_btf;
} __attribute__((aligned(8)));
/* User bpf_sock_addr struct to access socket fields and sockaddr struct passed

View file

@ -0,0 +1,48 @@
From 05acefb4872dae89e772729efb194af754c877e8 Mon Sep 17 00:00:00 2001
From: Miklos Szeredi <mszeredi@redhat.com>
Date: Tue, 2 Jun 2020 22:20:26 +0200
Subject: ovl: check permission to open real file
Call inode_permission() on real inode before opening regular file on one of
the underlying layers.
In some cases ovl_permission() already checks access to an underlying file,
but it misses the metacopy case, and possibly other ones as well.
Removing the redundant permission check from ovl_permission() should be
considered later.
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
fs/overlayfs/file.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
Index: linux-5.4.147/fs/overlayfs/file.c
===================================================================
--- linux-5.4.147.orig/fs/overlayfs/file.c
+++ linux-5.4.147/fs/overlayfs/file.c
@@ -34,10 +34,22 @@ static struct file *ovl_open_realfile(co
struct file *realfile;
const struct cred *old_cred;
int flags = file->f_flags | OVL_OPEN_FLAGS;
+ int acc_mode = ACC_MODE(flags);
+ int err;
+
+ if (flags & O_APPEND)
+ acc_mode |= MAY_APPEND;
old_cred = ovl_override_creds(inode->i_sb);
- realfile = open_with_fake_path(&file->f_path, flags, realinode,
- current_cred());
+ err = inode_permission(realinode, MAY_OPEN | acc_mode);
+ if (err) {
+ realfile = ERR_PTR(err);
+ } else if (!inode_owner_or_capable(realinode)) {
+ realfile = ERR_PTR(-EPERM);
+ } else {
+ realfile = open_with_fake_path(&file->f_path, flags, realinode,
+ current_cred());
+ }
revert_creds(old_cred);
pr_debug("open(%p[%pD2/%c], 0%o) -> (%p, 0%o)\n",

View file

@ -0,0 +1,73 @@
From 48bd024b8a40d73ad6b086de2615738da0c7004f Mon Sep 17 00:00:00 2001
From: Miklos Szeredi <mszeredi@redhat.com>
Date: Tue, 2 Jun 2020 22:20:25 +0200
Subject: ovl: switch to mounter creds in readdir
In preparation for more permission checking, override credentials for
directory operations on the underlying filesystems.
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
fs/overlayfs/readdir.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
Index: linux-5.4.147/fs/overlayfs/readdir.c
===================================================================
--- linux-5.4.147.orig/fs/overlayfs/readdir.c
+++ linux-5.4.147/fs/overlayfs/readdir.c
@@ -732,8 +732,10 @@ static int ovl_iterate(struct file *file
struct ovl_dir_file *od = file->private_data;
struct dentry *dentry = file->f_path.dentry;
struct ovl_cache_entry *p;
+ const struct cred *old_cred;
int err;
+ old_cred = ovl_override_creds(dentry->d_sb);
if (!ctx->pos)
ovl_dir_reset(file);
@@ -747,17 +749,20 @@ static int ovl_iterate(struct file *file
(ovl_same_sb(dentry->d_sb) &&
(ovl_is_impure_dir(file) ||
OVL_TYPE_MERGE(ovl_path_type(dentry->d_parent))))) {
- return ovl_iterate_real(file, ctx);
+ err = ovl_iterate_real(file, ctx);
+ } else {
+ err = iterate_dir(od->realfile, ctx);
}
- return iterate_dir(od->realfile, ctx);
+ goto out;
}
if (!od->cache) {
struct ovl_dir_cache *cache;
cache = ovl_cache_get(dentry);
+ err = PTR_ERR(cache);
if (IS_ERR(cache))
- return PTR_ERR(cache);
+ goto out;
od->cache = cache;
ovl_seek_cursor(od, ctx->pos);
@@ -769,7 +774,7 @@ static int ovl_iterate(struct file *file
if (!p->ino) {
err = ovl_cache_update_ino(&file->f_path, p);
if (err)
- return err;
+ goto out;
}
if (!dir_emit(ctx, p->name, p->len, p->ino, p->type))
break;
@@ -777,7 +782,10 @@ static int ovl_iterate(struct file *file
od->cursor = p->l_node.next;
ctx->pos++;
}
- return 0;
+ err = 0;
+out:
+ revert_creds(old_cred);
+ return err;
}
static loff_t ovl_dir_llseek(struct file *file, loff_t offset, int origin)

View file

@ -0,0 +1,61 @@
From 56230d956739b9cb1cbde439d76227d77979a04d Mon Sep 17 00:00:00 2001
From: Miklos Szeredi <mszeredi@redhat.com>
Date: Tue, 2 Jun 2020 22:20:26 +0200
Subject: ovl: verify permissions in ovl_path_open()
Check permission before opening a real file.
ovl_path_open() is used by readdir and copy-up routines.
ovl_permission() theoretically already checked copy up permissions, but it
doesn't hurt to re-do these checks during the actual copy-up.
For directory reading ovl_permission() only checks access to topmost
underlying layer. Readdir on a merged directory accesses layers below the
topmost one as well. Permission wasn't checked for these layers.
Note: modifying ovl_permission() to perform this check would be far more
complex and hence more bug prone. The result is less precise permissions
returned in access(2). If this turns out to be an issue, we can revisit
this bug.
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
fs/overlayfs/util.c | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
Index: linux-5.4.147/fs/overlayfs/util.c
===================================================================
--- linux-5.4.147.orig/fs/overlayfs/util.c
+++ linux-5.4.147/fs/overlayfs/util.c
@@ -475,7 +475,29 @@ bool ovl_is_whiteout(struct dentry *dent
struct file *ovl_path_open(struct path *path, int flags)
{
- return dentry_open(path, flags | O_NOATIME, current_cred());
+ struct inode *inode = d_inode(path->dentry);
+ int err, acc_mode;
+
+ switch (flags & O_ACCMODE) {
+ case O_RDONLY:
+ acc_mode = MAY_READ;
+ break;
+ case O_WRONLY:
+ acc_mode = MAY_WRITE;
+ break;
+ default:
+ BUG();
+ }
+
+ err = inode_permission(inode, acc_mode | MAY_OPEN);
+ if (err)
+ return ERR_PTR(err);
+
+ /* O_NOATIME is an optimization, don't fail if not permitted */
+ if (inode_owner_or_capable(inode))
+ flags |= O_NOATIME;
+
+ return dentry_open(path, flags, current_cred());
}
/* Caller should hold ovl_inode->lock */

View file

@ -0,0 +1,46 @@
From b6650dab404c701d7fe08a108b746542a934da84 Mon Sep 17 00:00:00 2001
From: Miklos Szeredi <mszeredi@redhat.com>
Date: Mon, 14 Dec 2020 15:26:14 +0100
Subject: ovl: do not fail because of O_NOATIME
In case the file cannot be opened with O_NOATIME because of lack of
capabilities, then clear O_NOATIME instead of failing.
Remove WARN_ON(), since it would now trigger if O_NOATIME was cleared.
Noticed by Amir Goldstein.
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
fs/overlayfs/file.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
Index: linux-5.4.147/fs/overlayfs/file.c
===================================================================
--- linux-5.4.147.orig/fs/overlayfs/file.c
+++ linux-5.4.147/fs/overlayfs/file.c
@@ -44,9 +44,10 @@ static struct file *ovl_open_realfile(co
err = inode_permission(realinode, MAY_OPEN | acc_mode);
if (err) {
realfile = ERR_PTR(err);
- } else if (!inode_owner_or_capable(realinode)) {
- realfile = ERR_PTR(-EPERM);
} else {
+ if (!inode_owner_or_capable(realinode))
+ flags &= ~O_NOATIME;
+
realfile = open_with_fake_path(&file->f_path, flags, realinode,
current_cred());
}
@@ -66,12 +67,6 @@ static int ovl_change_flags(struct file
struct inode *inode = file_inode(file);
int err;
- flags |= OVL_OPEN_FLAGS;
-
- /* If some flag changed that cannot be changed then something's amiss */
- if (WARN_ON((file->f_flags ^ flags) & ~OVL_SETFL_MASK))
- return -EIO;
-
flags &= OVL_SETFL_MASK;
if (((flags ^ file->f_flags) & O_APPEND) && IS_APPEND(inode))

View file

@ -0,0 +1,17 @@
Index: linux-5.4.124/drivers/net/ppp/pppoe.c
===================================================================
--- linux-5.4.124.orig/drivers/net/ppp/pppoe.c
+++ linux-5.4.124/drivers/net/ppp/pppoe.c
@@ -502,6 +502,12 @@ static int pppoe_disc_rcv(struct sk_buff
if (ph->code != PADT_CODE)
goto abort;
+ // compare the dst addr to the current net device addr and ignore packet if not matching
+ // otherwise it will terminate the connection
+ if(!ether_addr_equal(eth_hdr(skb)->h_dest, dev->dev_addr)) {
+ goto abort;
+ }
+
pn = pppoe_pernet(dev_net(dev));
po = get_item(pn, ph->sid, eth_hdr(skb)->h_source, dev->ifindex);
if (po)

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,319 @@
diff --git a/include/net/netfilter/nf_conntrack_ecache.h b/include/net/netfilter/nf_conntrack_ecache.h
index 12d967b..c2b98b6 100644
--- a/include/net/netfilter/nf_conntrack_ecache.h
+++ b/include/net/netfilter/nf_conntrack_ecache.h
@@ -72,6 +72,10 @@ struct nf_ct_event {
int report;
};
+#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
+extern int nf_conntrack_register_notifier(struct net *net, struct notifier_block *nb);
+extern int nf_conntrack_unregister_notifier(struct net *net, struct notifier_block *nb);
+#else
struct nf_ct_event_notifier {
int (*fcn)(unsigned int events, struct nf_ct_event *item);
};
@@ -80,6 +84,7 @@ int nf_conntrack_register_notifier(struc
struct nf_ct_event_notifier *nb);
void nf_conntrack_unregister_notifier(struct net *net,
struct nf_ct_event_notifier *nb);
+#endif
void nf_ct_deliver_cached_events(struct nf_conn *ct);
int nf_conntrack_eventmask_report(unsigned int eventmask, struct nf_conn *ct,
@@ -105,11 +110,13 @@ int nf_conntrack_eventmask_report(unsign
nf_conntrack_event_cache(enum ip_conntrack_events event, struct nf_conn *ct)
{
#ifdef CONFIG_NF_CONNTRACK_EVENTS
- struct net *net = nf_ct_net(ct);
struct nf_conntrack_ecache *e;
+#ifndef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
+ struct net *net = nf_ct_net(ct);
if (!rcu_access_pointer(net->ct.nf_conntrack_event_cb))
return;
+#endif
e = nf_ct_ecache_find(ct);
if (e == NULL)
@@ -124,10 +131,12 @@ static inline int
u32 portid, int report)
{
#ifdef CONFIG_NF_CONNTRACK_EVENTS
+#ifndef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
const struct net *net = nf_ct_net(ct);
if (!rcu_access_pointer(net->ct.nf_conntrack_event_cb))
return 0;
+#endif
return nf_conntrack_eventmask_report(1 << event, ct, portid, report);
#else
@@ -139,10 +148,12 @@ nf_conntrack_event_report(enum ip_conntr
nf_conntrack_event(enum ip_conntrack_events event, struct nf_conn *ct)
{
#ifdef CONFIG_NF_CONNTRACK_EVENTS
+#ifndef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
const struct net *net = nf_ct_net(ct);
if (!rcu_access_pointer(net->ct.nf_conntrack_event_cb))
return 0;
+#endif
return nf_conntrack_eventmask_report(1 << event, ct, 0, 0);
#else
diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
index e469e85..1d31db8 100644
--- a/include/net/netns/conntrack.h
+++ b/include/net/netns/conntrack.h
@@ -112,7 +112,11 @@ struct netns_ct {
struct ct_pcpu __percpu *pcpu_lists;
struct ip_conntrack_stat __percpu *stat;
+#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
+ struct atomic_notifier_head nf_conntrack_chain;
+#else
struct nf_ct_event_notifier __rcu *nf_conntrack_event_cb;
+#endif
struct nf_exp_event_notifier __rcu *nf_expect_event_cb;
struct nf_ip_net nf_ct_proto;
#if defined(CONFIG_NF_CONNTRACK_LABELS)
diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
index 63073be..08d7aab 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -148,6 +148,14 @@ config NF_CONNTRACK_RTCACHE
To compile it as a module, choose M here. If unsure, say N.
The module will be called nf_conntrack_rtcache.
+config NF_CONNTRACK_CHAIN_EVENTS
+ bool "Register multiple callbacks to ct events"
+ depends on NF_CONNTRACK_EVENTS
+ help
+ Support multiple registrations.
+
+ If unsure, say `N'.
+
config NF_CONNTRACK_TIMEOUT
bool 'Connection tracking timeout'
depends on NETFILTER_ADVANCED
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 6bd1508..9b81c7c 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -2592,6 +2592,9 @@ int nf_conntrack_init_net(struct net *ne
nf_conntrack_helper_pernet_init(net);
nf_conntrack_proto_pernet_init(net);
+#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
+ ATOMIC_INIT_NOTIFIER_HEAD(&net->ct.nf_conntrack_chain);
+#endif
return 0;
err_expect:
diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
index da9df2d..e0e2a8f 100644
--- a/net/netfilter/nf_conntrack_ecache.c
+++ b/net/netfilter/nf_conntrack_ecache.c
@@ -17,6 +17,9 @@
#include <linux/stddef.h>
#include <linux/err.h>
#include <linux/percpu.h>
+#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
+#include <linux/notifier.h>
+#endif
#include <linux/kernel.h>
#include <linux/netdevice.h>
#include <linux/slab.h>
@@ -117,6 +120,38 @@ static void ecache_work(struct work_stru
schedule_delayed_work(&ctnet->ecache_dwork, delay);
}
+#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
+int
+nf_conntrack_eventmask_report(unsigned int eventmask,
+ struct nf_conn *ct,
+ u32 portid,
+ int report)
+{
+ struct nf_conntrack_ecache *e;
+ struct net *net = nf_ct_net(ct);
+
+ e = nf_ct_ecache_find(ct);
+ if (e == NULL)
+ return 0;
+
+ if (nf_ct_is_confirmed(ct)) {
+ struct nf_ct_event item = {
+ .ct = ct,
+ .portid = e->portid ? e->portid : portid,
+ .report = report
+ };
+ /* This is a resent of a destroy event? If so, skip missed */
+ unsigned long missed = e->portid ? 0 : e->missed;
+
+ if (!((eventmask | missed) & e->ctmask))
+ return 0;
+
+ atomic_notifier_call_chain(&net->ct.nf_conntrack_chain, eventmask | missed, &item);
+ }
+
+ return 0;
+}
+#else
int nf_conntrack_eventmask_report(unsigned int eventmask, struct nf_conn *ct,
u32 portid, int report)
{
@@ -171,10 +206,52 @@ out_unlock:
rcu_read_unlock();
return ret;
}
+#endif
EXPORT_SYMBOL_GPL(nf_conntrack_eventmask_report);
/* deliver cached events and clear cache entry - must be called with locally
* disabled softirqs */
+#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
+void nf_ct_deliver_cached_events(struct nf_conn *ct)
+{
+ unsigned long events, missed;
+ struct nf_conntrack_ecache *e;
+ struct nf_ct_event item;
+ struct net *net = nf_ct_net(ct);
+
+ e = nf_ct_ecache_find(ct);
+ if (e == NULL)
+ return;
+
+ events = xchg(&e->cache, 0);
+
+ if (!nf_ct_is_confirmed(ct) || nf_ct_is_dying(ct) || !events)
+ return;
+
+ /* We make a copy of the missed event cache without taking
+ * the lock, thus we may send missed events twice. However,
+ * this does not harm and it happens very rarely. */
+ missed = e->missed;
+
+ if (!((events | missed) & e->ctmask))
+ return;
+
+ item.ct = ct;
+ item.portid = 0;
+ item.report = 0;
+
+ atomic_notifier_call_chain(&net->ct.nf_conntrack_chain,
+ events | missed,
+ &item);
+
+ if (likely(!missed))
+ return;
+
+ spin_lock_bh(&ct->lock);
+ e->missed &= ~missed;
+ spin_unlock_bh(&ct->lock);
+}
+#else
void nf_ct_deliver_cached_events(struct nf_conn *ct)
{
struct net *net = nf_ct_net(ct);
@@ -225,6 +302,7 @@ void nf_ct_deliver_cached_events(struct
out_unlock:
rcu_read_unlock();
}
+#endif
EXPORT_SYMBOL_GPL(nf_ct_deliver_cached_events);
void nf_ct_expect_event_report(enum ip_conntrack_expect_events event,
@@ -257,6 +335,12 @@ out_unlock:
rcu_read_unlock();
}
+#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
+int nf_conntrack_register_notifier(struct net *net, struct notifier_block *nb)
+{
+ return atomic_notifier_chain_register(&net->ct.nf_conntrack_chain, nb);
+}
+#else
int nf_conntrack_register_notifier(struct net *net,
struct nf_ct_event_notifier *new)
{
@@ -277,8 +361,15 @@ out_unlock:
mutex_unlock(&nf_ct_ecache_mutex);
return ret;
}
+#endif
EXPORT_SYMBOL_GPL(nf_conntrack_register_notifier);
+#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
+int nf_conntrack_unregister_notifier(struct net *net, struct notifier_block *nb)
+{
+ return atomic_notifier_chain_unregister(&net->ct.nf_conntrack_chain, nb);
+}
+#else
void nf_conntrack_unregister_notifier(struct net *net,
struct nf_ct_event_notifier *new)
{
@@ -292,6 +383,7 @@ void nf_conntrack_unregister_notifier(st
mutex_unlock(&nf_ct_ecache_mutex);
/* synchronize_rcu() is called from ctnetlink_exit. */
}
+#endif
EXPORT_SYMBOL_GPL(nf_conntrack_unregister_notifier);
int nf_ct_expect_register_notifier(struct net *net,
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 04111c1..8c741f7 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -32,6 +32,11 @@
#include <linux/siphash.h>
#include <linux/netfilter.h>
+
+#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
+#include <linux/notifier.h>
+#endif
+
#include <net/netlink.h>
#include <net/sock.h>
#include <net/netfilter/nf_conntrack.h>
@@ -676,14 +681,22 @@ static size_t ctnetlink_nlmsg_size(const
;
}
+#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
+static int ctnetlink_conntrack_event(struct notifier_block *this,
+ unsigned long events, void *ptr)
+#else
static int
ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item)
+#endif
{
const struct nf_conntrack_zone *zone;
struct net *net;
struct nlmsghdr *nlh;
struct nfgenmsg *nfmsg;
struct nlattr *nest_parms;
+#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
+ struct nf_ct_event *item = (struct nf_ct_event *)ptr;
+#endif
struct nf_conn *ct = item->ct;
struct sk_buff *skb;
unsigned int type;
@@ -3504,9 +3517,15 @@ static int ctnetlink_stat_exp_cpu(struct
}
#ifdef CONFIG_NF_CONNTRACK_EVENTS
+#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
+static struct notifier_block ctnl_notifier = {
+ .notifier_call = ctnetlink_conntrack_event,
+};
+#else
static struct nf_ct_event_notifier ctnl_notifier = {
.fcn = ctnetlink_conntrack_event,
};
+#endif
static struct nf_exp_event_notifier ctnl_notifier_exp = {
.fcn = ctnetlink_expect_event,

View file

@ -0,0 +1,253 @@
--- a/include/linux/if_bridge.h
+++ b/include/linux/if_bridge.h
@@ -52,6 +52,9 @@ struct br_ip_list {
extern void brioctl_set(int (*ioctl_hook)(struct net *, unsigned int, void __user *));
+extern void br_dev_update_stats(struct net_device *dev,
+ struct rtnl_link_stats64 *nlstats);
+
#if IS_ENABLED(CONFIG_BRIDGE) && IS_ENABLED(CONFIG_BRIDGE_IGMP_SNOOPING)
int br_multicast_list_adjacent(struct net_device *dev,
struct list_head *br_ip_list);
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -827,6 +827,10 @@ struct sk_buff {
#endif
__u8 scm_io_uring:1;
+#ifdef CONFIG_SHORTCUT_FE
+ __u8 fast_forwarded:1;
+#endif
+
#ifdef CONFIG_NET_SCHED
__u16 tc_index; /* traffic control index */
#endif
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -18,6 +18,10 @@ struct timer_list {
void (*function)(struct timer_list *);
u32 flags;
+#ifdef CONFIG_SHORTCUT_FE
+ unsigned long cust_data;
+#endif
+
#ifdef CONFIG_LOCKDEP
struct lockdep_map lockdep_map;
#endif
--- a/include/net/netfilter/nf_conntrack_ecache.h
+++ b/include/net/netfilter/nf_conntrack_ecache.h
@@ -75,6 +75,8 @@ struct nf_ct_event {
#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
extern int nf_conntrack_register_notifier(struct net *net, struct notifier_block *nb);
extern int nf_conntrack_unregister_notifier(struct net *net, struct notifier_block *nb);
+extern int nf_conntrack_register_chain_notifier(struct net *net, struct notifier_block *nb);
+extern int nf_conntrack_unregister_chain_notifier(struct net *net, struct notifier_block *nb);
#else
struct nf_ct_event_notifier {
int (*fcn)(unsigned int events, struct nf_ct_event *item);
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -763,6 +763,28 @@ void br_port_flags_change(struct net_bri
br_recalculate_neigh_suppress_enabled(br);
}
+void br_dev_update_stats(struct net_device *dev,
+ struct rtnl_link_stats64 *nlstats)
+{
+ struct net_bridge *br;
+ struct pcpu_sw_netstats *stats;
+
+ /* Is this a bridge? */
+ if (!(dev->priv_flags & IFF_EBRIDGE))
+ return;
+
+ br = netdev_priv(dev);
+ stats = this_cpu_ptr(br->stats);
+
+ u64_stats_update_begin(&stats->syncp);
+ stats->rx_packets += nlstats->rx_packets;
+ stats->rx_bytes += nlstats->rx_bytes;
+ stats->tx_packets += nlstats->tx_packets;
+ stats->tx_bytes += nlstats->tx_bytes;
+ u64_stats_update_end(&stats->syncp);
+}
+EXPORT_SYMBOL_GPL(br_dev_update_stats);
+
bool br_port_flag_is_set(const struct net_device *dev, unsigned long flag)
{
struct net_bridge_port *p;
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -3197,9 +3197,17 @@ static int xmit_one(struct sk_buff *skb,
unsigned int len;
int rc;
+#ifdef CONFIG_SHORTCUT_FE
+ /* If this skb has been fast forwarded then we don't want it to
+ * go to any taps (by definition we're trying to bypass them).
+ */
+ if (!skb->fast_forwarded) {
+#endif
if (dev_nit_active(dev))
dev_queue_xmit_nit(skb, dev);
-
+#ifdef CONFIG_SHORTCUT_FE
+ }
+#endif
#ifdef CONFIG_ETHERNET_PACKET_MANGLE
if (!dev->eth_mangle_tx ||
(skb = dev->eth_mangle_tx(dev, skb)) != NULL)
@@ -4715,6 +4723,11 @@ void netdev_rx_handler_unregister(struct
}
EXPORT_SYMBOL_GPL(netdev_rx_handler_unregister);
+#ifdef CONFIG_SHORTCUT_FE
+int (*athrs_fast_nat_recv)(struct sk_buff *skb) __rcu __read_mostly;
+EXPORT_SYMBOL_GPL(athrs_fast_nat_recv);
+#endif
+
/*
* Limit the use of PFMEMALLOC reserves to those protocols that implement
* the special handling of PFMEMALLOC skbs.
@@ -4765,6 +4778,10 @@ static int __netif_receive_skb_core(stru
int ret = NET_RX_DROP;
__be16 type;
+#ifdef CONFIG_SHORTCUT_FE
+ int (*fast_recv)(struct sk_buff *skb);
+#endif
+
net_timestamp_check(!READ_ONCE(netdev_tstamp_prequeue), skb);
trace_netif_receive_skb(skb);
@@ -4804,6 +4821,16 @@ another_round:
goto out;
}
+#ifdef CONFIG_SHORTCUT_FE
+ fast_recv = rcu_dereference(athrs_fast_nat_recv);
+ if (fast_recv) {
+ if (fast_recv(skb)) {
+ ret = NET_RX_SUCCESS;
+ goto out;
+ }
+ }
+#endif
+
if (skb_skip_tc_classify(skb))
goto skip_classify;
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -473,3 +473,6 @@ config HAVE_CBPF_JIT
# Extended BPF JIT (eBPF)
config HAVE_EBPF_JIT
bool
+
+config SHORTCUT_FE
+ bool "Enables kernel network stack path for Shortcut Forwarding Engine
--- a/net/netfilter/nf_conntrack_proto_tcp.c
+++ b/net/netfilter/nf_conntrack_proto_tcp.c
@@ -34,11 +34,19 @@
/* Do not check the TCP window for incoming packets */
static int nf_ct_tcp_no_window_check __read_mostly = 1;
+#ifdef CONFIG_SHORTCUT_FE
+EXPORT_SYMBOL_GPL(nf_ct_tcp_no_window_check);
+#endif
+
/* "Be conservative in what you do,
be liberal in what you accept from others."
If it's non-zero, we mark only out of window RST segments as INVALID. */
static int nf_ct_tcp_be_liberal __read_mostly = 0;
+#ifdef CONFIG_SHORTCUT_FE
+EXPORT_SYMBOL_GPL(nf_ct_tcp_be_liberal);
+#endif
+
/* If it is set to zero, we disable picking up already established
connections. */
static int nf_ct_tcp_loose __read_mostly = 1;
--- a/net/netfilter/nf_conntrack_ecache.c
+++ b/net/netfilter/nf_conntrack_ecache.c
@@ -158,7 +158,11 @@ int nf_conntrack_eventmask_report(unsign
rcu_read_lock();
notify = rcu_dereference(net->ct.nf_conntrack_event_cb);
+#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
+ if (!notify && !rcu_dereference_raw(net->ct.nf_conntrack_chain.head))
+#else
if (!notify)
+#endif
goto out_unlock;
e = nf_ct_ecache_find(ct);
@@ -177,7 +181,14 @@ int nf_conntrack_eventmask_report(unsign
if (!((eventmask | missed) & e->ctmask))
goto out_unlock;
+#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
+ ret = atomic_notifier_call_chain(&net->ct.nf_conntrack_chain,
+ eventmask | missed, &item);
+ if (notify)
+ ret = notify->fcn(eventmask | missed, &item);
+#else
ret = notify->fcn(eventmask | missed, &item);
+#endif
if (unlikely(ret < 0 || missed)) {
spin_lock_bh(&ct->lock);
if (ret < 0) {
@@ -259,7 +270,11 @@ void nf_ct_deliver_cached_events(struct
rcu_read_lock();
notify = rcu_dereference(net->ct.nf_conntrack_event_cb);
+#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
+ if ((notify == NULL) && !rcu_dereference_raw(net->ct.nf_conntrack_chain.head))
+#else
if (notify == NULL)
+#endif
goto out_unlock;
e = nf_ct_ecache_find(ct);
@@ -283,7 +298,15 @@ void nf_ct_deliver_cached_events(struct
item.portid = 0;
item.report = 0;
+#ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
+ ret = atomic_notifier_call_chain(&net->ct.nf_conntrack_chain,
+ events | missed,
+ &item);
+ if (notify != NULL)
+ ret = notify->fcn(events | missed, &item);
+#else
ret = notify->fcn(events | missed, &item);
+#endif
if (likely(ret == 0 && !missed))
goto out_unlock;
@@ -337,6 +360,11 @@ int nf_conntrack_register_notifier(struc
{
return atomic_notifier_chain_register(&net->ct.nf_conntrack_chain, nb);
}
+int nf_conntrack_register_chain_notifier(struct net *net, struct notifier_block *nb)
+{
+ return atomic_notifier_chain_register(&net->ct.nf_conntrack_chain, nb);
+}
+EXPORT_SYMBOL_GPL(nf_conntrack_register_chain_notifier);
#else
int nf_conntrack_register_notifier(struct net *net,
struct nf_ct_event_notifier *new)
@@ -366,6 +394,11 @@ int nf_conntrack_unregister_notifier(str
{
return atomic_notifier_chain_unregister(&net->ct.nf_conntrack_chain, nb);
}
+int nf_conntrack_unregister_chain_notifier(struct net *net, struct notifier_block *nb)
+{
+ return atomic_notifier_chain_unregister(&net->ct.nf_conntrack_chain, nb);
+}
+EXPORT_SYMBOL_GPL(nf_conntrack_unregister_chain_notifier);
#else
void nf_conntrack_unregister_notifier(struct net *net,
struct nf_ct_event_notifier *new)

View file

@ -0,0 +1,43 @@
From 582774df32849d6638133a675f7502730b46e217 Mon Sep 17 00:00:00 2001
From: Jonathan Bell <jonathan@raspberrypi.com>
Date: Wed, 11 Aug 2021 15:33:57 +0100
Subject: [PATCH] usb: xhci: workaround for bogus SET_DEQ_PENDING endpoint
state
See https://github.com/raspberrypi/linux/issues/3981
An unknown unsafe memory access can result in the ep_state variable
in xhci_virt_ep being trampled with a stuck SET_DEQ_PENDING state
despite successful completion of a Set TR Deq Pointer command.
All URB enqueue/dequeue calls for the endpoint will fail in this state
so no transfers are possible until the device is reconnected.
As a workaround, clear the flag if we see it set and issue a new Set
TR Deq command anyway - this should be harmless, as a prior Set TR Deq
command will only have been issued in the Stopped state, and if the
endpoint is Running then the controller is required to ignore it and
respond with a Context State Error event TRB.
Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
---
drivers/usb/host/xhci-ring.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 35b246aeb902a..726d8291bd31a 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -4223,9 +4223,9 @@ void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
}
ep = &xhci->devs[slot_id]->eps[ep_index];
if ((ep->ep_state & SET_DEQ_PENDING)) {
- xhci_warn(xhci, "WARN Cannot submit Set TR Deq Ptr\n");
- xhci_warn(xhci, "A Set TR Deq Ptr command is pending.\n");
- return;
+ xhci_warn(xhci, "WARN A Set TR Deq Ptr command is pending for slot %u ep %u\n",
+ slot_id, ep_index);
+ ep->ep_state &= ~SET_DEQ_PENDING;
}
/* This function gets called from contexts where it cannot sleep */

View file

@ -0,0 +1,47 @@
--- a/net/core/dev.c 2018-08-10 10:31:41.199494561 +0200
+++ b/net/core/dev.c 2018-08-10 10:32:03.635272509 +0200
@@ -6613,9 +6613,11 @@
}
}
if (dev->flags != old_flags) {
+ /*
pr_info("device %s %s promiscuous mode\n",
dev->name,
dev->flags & IFF_PROMISC ? "entered" : "left");
+ */
if (audit_enabled) {
current_uid_gid(&uid, &gid);
audit_log(current->audit_context, GFP_ATOMIC,
--- a/drivers/net/usb/r8152.c 2020-08-13 13:11:25.866435255 +0200
+++ b/drivers/net/usb/r8152.c 2020-08-13 13:11:51.973994306 +0200
@@ -2353,7 +2353,7 @@
if (netdev->flags & IFF_PROMISC) {
/* Unconditionally log net taps. */
- netif_notice(tp, link, netdev, "Promiscuous mode enabled\n");
+ //netif_notice(tp, link, netdev, "Promiscuous mode enabled\n");
ocp_data |= RCR_AM | RCR_AAP;
mc_filter[1] = 0xffffffff;
mc_filter[0] = 0xffffffff;
--- a/drivers/net/usb/pegasus.c 2020-08-13 13:14:15.519570376 +0200
+++ b/drivers/net/usb/pegasus.c 2020-08-13 13:14:26.795380006 +0200
@@ -1031,7 +1031,7 @@
if (net->flags & IFF_PROMISC) {
pegasus->eth_regs[EthCtrl2] |= RX_PROMISCUOUS;
- netif_info(pegasus, link, net, "Promiscuous mode enabled\n");
+ //netif_info(pegasus, link, net, "Promiscuous mode enabled\n");
} else if (!netdev_mc_empty(net) || (net->flags & IFF_ALLMULTI)) {
pegasus->eth_regs[EthCtrl0] |= RX_MULTICAST;
pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS;
--- a/drivers/net/ethernet/realtek/r8169_main.c 2020-08-13 13:15:44.478068638 +0200
+++ b/drivers/net/ethernet/realtek/r8169_main.c 2020-08-13 13:15:59.181820450 +0200
@@ -4313,7 +4313,7 @@
if (dev->flags & IFF_PROMISC) {
/* Unconditionally log net taps. */
- netif_notice(tp, link, dev, "Promiscuous mode enabled\n");
+ //netif_notice(tp, link, dev, "Promiscuous mode enabled\n");
rx_mode |= AcceptAllPhys;
} else if (netdev_mc_count(dev) > MC_FILTER_LIMIT ||
dev->flags & IFF_ALLMULTI ||

View file

@ -0,0 +1,50 @@
Index: linux-5.4.124/drivers/mtd/spi-nor/spi-nor.c
===================================================================
--- linux-5.4.124.orig/drivers/mtd/spi-nor/spi-nor.c
+++ linux-5.4.124/drivers/mtd/spi-nor/spi-nor.c
@@ -2241,6 +2241,9 @@ static const struct flash_info spi_nor_i
.fixups = &gd25q256_fixups,
},
+ /* Zbit */
+ { "zb25vq128", INFO(0xC84018, 0, 64 * 1024, 64, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
+
/* Intel/Numonyx -- xxxs33b */
{ "160s33b", INFO(0x898911, 0, 64 * 1024, 32, 0) },
{ "320s33b", INFO(0x898912, 0, 64 * 1024, 64, 0) },
@@ -2405,6 +2408,7 @@ static const struct flash_info spi_nor_i
{ "m25p32", INFO(0x202016, 0, 64 * 1024, 64, 0) },
{ "m25p64", INFO(0x202017, 0, 64 * 1024, 128, 0) },
{ "m25p128", INFO(0x202018, 0, 256 * 1024, 64, 0) },
+ { "n25q032", INFO(0x20ba16, 0, 64 * 1024, 64, 0) },
{ "m25p05-nonjedec", INFO(0, 0, 32 * 1024, 2, 0) },
{ "m25p10-nonjedec", INFO(0, 0, 32 * 1024, 4, 0) },
@@ -2508,10 +2512,14 @@ static const struct flash_info spi_nor_i
{ "XM25QH128A", INFO(0x207018, 0, 64 * 1024, 256, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
/* XTX Technology (Shenzhen) Limited */
+ { "XT25F128A", INFO(0x207018, 0, 64 * 1024, 256, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
{ "xt25f128b", INFO(0x0B4018, 0, 64 * 1024, 256, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
{ },
};
+static const struct flash_info spi_nor_unknown_id =
+ { "undefined", INFO(0x0, 0, 64 * 1024, 256, SECT_4K) };
+
static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
{
int tmp;
@@ -2542,9 +2550,12 @@ static const struct flash_info *spi_nor_
return &spi_nor_ids[tmp];
}
}
+ return &spi_nor_unknown_id; // for Teltonikia RUT devices
+ /*
dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
SPI_NOR_MAX_ID_LEN, id);
return ERR_PTR(-ENODEV);
+ */
}
static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,

View file

@ -0,0 +1,198 @@
From a07e31adf2753cad2fd9790db5bfc047c81e8152 Mon Sep 17 00:00:00 2001
From: Felix Matouschek <felix@matouschek.org>
Date: Fri, 2 Jul 2021 20:31:23 +0200
Subject: [PATCH] mtd: spinand: Add support for XTX XT26G0xA
Add support for XTX Technology XT26G01AXXXXX, XTX26G02AXXXXX and
XTX26G04AXXXXX SPI NAND.
These are 3V, 1G/2G/4Gbit serial SLC NAND flash devices with on-die ECC
(8bit strength per 512bytes).
Tested on Teltonika RUTX10 flashed with OpenWrt.
Datasheets available at
http://www.xtxtech.com/download/?AId=225
https://datasheet.lcsc.com/szlcsc/2005251034_XTX-XT26G01AWSEGA_C558841.pdf
Signed-off-by: Felix Matouschek <felix@matouschek.org>
---
drivers/mtd/nand/spi/Makefile | 2 +-
drivers/mtd/nand/spi/core.c | 1 +
drivers/mtd/nand/spi/xtx.c | 122 ++++++++++++++++++++++++++++++++++
include/linux/mtd/spinand.h | 1 +
4 files changed, 125 insertions(+), 1 deletion(-)
create mode 100644 drivers/mtd/nand/spi/xtx.c
Index: linux-5.4.132/drivers/mtd/nand/spi/Makefile
===================================================================
--- linux-5.4.132.orig/drivers/mtd/nand/spi/Makefile
+++ linux-5.4.132/drivers/mtd/nand/spi/Makefile
@@ -1,3 +1,3 @@
# SPDX-License-Identifier: GPL-2.0
-spinand-objs := core.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o
+spinand-objs := core.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o
obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
Index: linux-5.4.132/drivers/mtd/nand/spi/core.c
===================================================================
--- linux-5.4.132.orig/drivers/mtd/nand/spi/core.c
+++ linux-5.4.132/drivers/mtd/nand/spi/core.c
@@ -758,6 +758,7 @@ static const struct spinand_manufacturer
&paragon_spinand_manufacturer,
&toshiba_spinand_manufacturer,
&winbond_spinand_manufacturer,
+ &xtx_spinand_manufacturer,
};
static int spinand_manufacturer_detect(struct spinand_device *spinand)
Index: linux-5.4.132/drivers/mtd/nand/spi/xtx.c
===================================================================
--- /dev/null
+++ linux-5.4.132/drivers/mtd/nand/spi/xtx.c
@@ -0,0 +1,134 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Author:
+ * Felix Matouschek <felix@matouschek.org>
+ */
+
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/mtd/spinand.h>
+
+#define SPINAND_MFR_XTX 0x0B
+
+#define XT26G0XA_STATUS_ECC_MASK GENMASK(5, 2)
+#define XT26G0XA_STATUS_ECC_NO_DETECTED (0 << 2)
+#define XT26G0XA_STATUS_ECC_8_CORRECTED (3 << 4)
+#define XT26G0XA_STATUS_ECC_UNCOR_ERROR (2 << 4)
+
+static SPINAND_OP_VARIANTS(read_cache_variants,
+ SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
+ SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
+ SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
+ SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
+ SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
+ SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
+
+static SPINAND_OP_VARIANTS(write_cache_variants,
+ SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
+ SPINAND_PROG_LOAD(true, 0, NULL, 0));
+
+static SPINAND_OP_VARIANTS(update_cache_variants,
+ SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
+ SPINAND_PROG_LOAD(false, 0, NULL, 0));
+
+static int xt26g0xa_ooblayout_ecc(struct mtd_info *mtd, int section,
+ struct mtd_oob_region *region)
+{
+ if (section)
+ return -ERANGE;
+
+ region->offset = 8;
+ region->length = 40;
+
+ return 0;
+}
+
+static int xt26g0xa_ooblayout_free(struct mtd_info *mtd, int section,
+ struct mtd_oob_region *region)
+{
+ if (section)
+ return -ERANGE;
+
+ region->offset = 1;
+ region->length = 7;
+
+ return 0;
+}
+
+static const struct mtd_ooblayout_ops xt26g0xa_ooblayout = {
+ .ecc = xt26g0xa_ooblayout_ecc,
+ .free = xt26g0xa_ooblayout_free,
+};
+
+static int xt26g0xa_ecc_get_status(struct spinand_device *spinand,
+ u8 status)
+{
+ switch (status & XT26G0XA_STATUS_ECC_MASK) {
+ case XT26G0XA_STATUS_ECC_NO_DETECTED:
+ return 0;
+ case XT26G0XA_STATUS_ECC_8_CORRECTED:
+ return 8;
+ case XT26G0XA_STATUS_ECC_UNCOR_ERROR:
+ return -EBADMSG;
+ default: /* (1 << 2) through (7 << 2) are 1-7 corrected errors */
+ return (status & XT26G0XA_STATUS_ECC_MASK) >> 2;
+ }
+
+ return -EINVAL;
+}
+
+static const struct spinand_info xtx_spinand_table[] = {
+ SPINAND_INFO("XT26G01A", 0xE1,
+ NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
+ NAND_ECCREQ(8, 512),
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+ &write_cache_variants,
+ &update_cache_variants),
+ SPINAND_HAS_QE_BIT,
+ SPINAND_ECCINFO(&xt26g0xa_ooblayout,
+ xt26g0xa_ecc_get_status)),
+ SPINAND_INFO("XT26G02A", 0xE2,
+ NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 1, 1, 1),
+ NAND_ECCREQ(8, 512),
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+ &write_cache_variants,
+ &update_cache_variants),
+ SPINAND_HAS_QE_BIT,
+ SPINAND_ECCINFO(&xt26g0xa_ooblayout,
+ xt26g0xa_ecc_get_status)),
+ SPINAND_INFO("XT26G04A", 0xE3,
+ NAND_MEMORG(1, 2048, 64, 128, 2048, 40, 1, 1, 1),
+ NAND_ECCREQ(8, 512),
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+ &write_cache_variants,
+ &update_cache_variants),
+ SPINAND_HAS_QE_BIT,
+ SPINAND_ECCINFO(&xt26g0xa_ooblayout,
+ xt26g0xa_ecc_get_status)),
+};
+
+static int xtx_spinand_detect(struct spinand_device *spinand)
+{
+ u8 *id = spinand->id.data;
+ int ret;
+
+ if (id[1] != SPINAND_MFR_XTX)
+ return 0;
+
+ ret = spinand_match_and_init(spinand, xtx_spinand_table,
+ ARRAY_SIZE(xtx_spinand_table), id[2]);
+ if (ret)
+ return ret;
+
+ return 1;
+}
+
+static const struct spinand_manufacturer_ops xtx_spinand_manuf_ops = {
+ .detect = xtx_spinand_detect,
+};
+
+const struct spinand_manufacturer xtx_spinand_manufacturer = {
+ .id = SPINAND_MFR_XTX,
+ .name = "XTX",
+ .ops = &xtx_spinand_manuf_ops,
+};
Index: linux-5.4.132/include/linux/mtd/spinand.h
===================================================================
--- linux-5.4.132.orig/include/linux/mtd/spinand.h
+++ linux-5.4.132/include/linux/mtd/spinand.h
@@ -230,6 +230,7 @@ extern const struct spinand_manufacturer
extern const struct spinand_manufacturer paragon_spinand_manufacturer;
extern const struct spinand_manufacturer toshiba_spinand_manufacturer;
extern const struct spinand_manufacturer winbond_spinand_manufacturer;
+extern const struct spinand_manufacturer xtx_spinand_manufacturer;
/**
* struct spinand_op_variants - SPI NAND operation variants

View file

@ -0,0 +1,554 @@
From: Pablo Neira Ayuso <pablo@netfilter.org>
Date: Thu, 11 Jan 2018 16:32:00 +0100
Subject: [PATCH] netfilter: nf_flow_table: add hardware offload support
This patch adds the infrastructure to offload flows to hardware, in case
the nic/switch comes with built-in flow tables capabilities.
If the hardware comes with no hardware flow tables or they have
limitations in terms of features, the existing infrastructure falls back
to the software flow table implementation.
The software flow table garbage collector skips entries that resides in
the hardware, so the hardware will be responsible for releasing this
flow table entry too via flow_offload_dead().
Hardware configuration, either to add or to delete entries, is done from
the hardware offload workqueue, to ensure this is done from user context
given that we may sleep when grabbing the mdio mutex.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
create mode 100644 net/netfilter/nf_flow_table_hw.c
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -922,6 +922,13 @@ struct devlink;
struct tlsdev_ops;
+struct flow_offload;
+
+enum flow_offload_type {
+ FLOW_OFFLOAD_ADD = 0,
+ FLOW_OFFLOAD_DEL,
+};
+
/*
* This structure defines the management hooks for network devices.
* The following hooks can be defined; unless noted otherwise, they are
@@ -1154,6 +1161,10 @@ struct tlsdev_ops;
* int (*ndo_bridge_dellink)(struct net_device *dev, struct nlmsghdr *nlh,
* u16 flags);
*
+ * int (*ndo_flow_offload)(enum flow_offload_type type,
+ * struct flow_offload *flow);
+ * Adds/deletes flow entry to/from net device flowtable.
+ *
* int (*ndo_change_carrier)(struct net_device *dev, bool new_carrier);
* Called to change device carrier. Soft-devices (like dummy, team, etc)
* which do not represent real hardware may define this to allow their
@@ -1401,6 +1412,8 @@ struct net_device_ops {
int (*ndo_bridge_dellink)(struct net_device *dev,
struct nlmsghdr *nlh,
u16 flags);
+ int (*ndo_flow_offload)(enum flow_offload_type type,
+ struct flow_offload *flow);
int (*ndo_change_carrier)(struct net_device *dev,
bool new_carrier);
int (*ndo_get_phys_port_id)(struct net_device *dev,
--- a/include/net/netfilter/nf_flow_table.h
+++ b/include/net/netfilter/nf_flow_table.h
@@ -21,11 +21,17 @@ struct nf_flowtable_type {
struct module *owner;
};
+enum nf_flowtable_flags {
+ NF_FLOWTABLE_F_HW = 0x1,
+};
+
struct nf_flowtable {
struct list_head list;
struct rhashtable rhashtable;
const struct nf_flowtable_type *type;
+ u32 flags;
struct delayed_work gc_work;
+ possible_net_t ft_net;
};
enum flow_offload_tuple_dir {
@@ -68,6 +74,7 @@ struct flow_offload_tuple_rhash {
#define FLOW_OFFLOAD_DNAT 0x2
#define FLOW_OFFLOAD_DYING 0x4
#define FLOW_OFFLOAD_TEARDOWN 0x8
+#define FLOW_OFFLOAD_HW 0x10
struct flow_offload {
struct flow_offload_tuple_rhash tuplehash[FLOW_OFFLOAD_DIR_MAX];
@@ -120,6 +127,22 @@ unsigned int nf_flow_offload_ip_hook(voi
unsigned int nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state);
+void nf_flow_offload_hw_add(struct net *net, struct flow_offload *flow,
+ struct nf_conn *ct);
+void nf_flow_offload_hw_del(struct net *net, struct flow_offload *flow);
+
+struct nf_flow_table_hw {
+ struct module *owner;
+ void (*add)(struct net *net, struct flow_offload *flow,
+ struct nf_conn *ct);
+ void (*del)(struct net *net, struct flow_offload *flow);
+};
+
+int nf_flow_table_hw_register(const struct nf_flow_table_hw *offload);
+void nf_flow_table_hw_unregister(const struct nf_flow_table_hw *offload);
+
+extern struct work_struct nf_flow_offload_hw_work;
+
#define MODULE_ALIAS_NF_FLOWTABLE(family) \
MODULE_ALIAS("nf-flowtable-" __stringify(family))
--- a/include/uapi/linux/netfilter/nf_tables.h
+++ b/include/uapi/linux/netfilter/nf_tables.h
@@ -1516,6 +1516,7 @@ enum nft_object_attributes {
* @NFTA_FLOWTABLE_HOOK: netfilter hook configuration(NLA_U32)
* @NFTA_FLOWTABLE_USE: number of references to this flow table (NLA_U32)
* @NFTA_FLOWTABLE_HANDLE: object handle (NLA_U64)
+ * @NFTA_FLOWTABLE_FLAGS: flags (NLA_U32)
*/
enum nft_flowtable_attributes {
NFTA_FLOWTABLE_UNSPEC,
@@ -1525,6 +1526,7 @@ enum nft_flowtable_attributes {
NFTA_FLOWTABLE_USE,
NFTA_FLOWTABLE_HANDLE,
NFTA_FLOWTABLE_PAD,
+ NFTA_FLOWTABLE_FLAGS,
__NFTA_FLOWTABLE_MAX
};
#define NFTA_FLOWTABLE_MAX (__NFTA_FLOWTABLE_MAX - 1)
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -711,6 +711,15 @@ config NF_FLOW_TABLE
To compile it as a module, choose M here.
+config NF_FLOW_TABLE_HW
+ tristate "Netfilter flow table hardware offload module"
+ depends on NF_FLOW_TABLE
+ help
+ This option adds hardware offload support for the flow table core
+ infrastructure.
+
+ To compile it as a module, choose M here.
+
config NETFILTER_XTABLES
tristate "Netfilter Xtables support (required for ip_tables)"
default m if NETFILTER_ADVANCED=n
--- a/net/netfilter/Makefile
+++ b/net/netfilter/Makefile
@@ -123,6 +123,7 @@ obj-$(CONFIG_NF_FLOW_TABLE) += nf_flow_t
nf_flow_table-objs := nf_flow_table_core.o nf_flow_table_ip.o
obj-$(CONFIG_NF_FLOW_TABLE_INET) += nf_flow_table_inet.o
+obj-$(CONFIG_NF_FLOW_TABLE_HW) += nf_flow_table_hw.o
# generic X tables
obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -248,10 +248,16 @@ static inline bool nf_flow_has_expired(c
return nf_flow_timeout_delta(flow->timeout) <= 0;
}
+static inline bool nf_flow_in_hw(const struct flow_offload *flow)
+{
+ return flow->flags & FLOW_OFFLOAD_HW;
+}
+
static void flow_offload_del(struct nf_flowtable *flow_table,
struct flow_offload *flow)
{
struct flow_offload_entry *e;
+ struct net *net = read_pnet(&flow_table->ft_net);
rhashtable_remove_fast(&flow_table->rhashtable,
&flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].node,
@@ -271,6 +277,9 @@ static void flow_offload_del(struct nf_f
if (!(flow->flags & FLOW_OFFLOAD_TEARDOWN))
flow_offload_fixup_ct_state(e->ct);
+ if (nf_flow_in_hw(flow))
+ nf_flow_offload_hw_del(net, flow);
+
flow_offload_free(flow);
}
@@ -490,10 +502,43 @@ int nf_flow_dnat_port(const struct flow_
}
EXPORT_SYMBOL_GPL(nf_flow_dnat_port);
+static const struct nf_flow_table_hw __rcu *nf_flow_table_hw_hook __read_mostly;
+
+static int nf_flow_offload_hw_init(struct nf_flowtable *flow_table)
+{
+ const struct nf_flow_table_hw *offload;
+
+ if (!rcu_access_pointer(nf_flow_table_hw_hook))
+ request_module("nf-flow-table-hw");
+
+ rcu_read_lock();
+ offload = rcu_dereference(nf_flow_table_hw_hook);
+ if (!offload)
+ goto err_no_hw_offload;
+
+ if (!try_module_get(offload->owner))
+ goto err_no_hw_offload;
+
+ rcu_read_unlock();
+
+ return 0;
+
+err_no_hw_offload:
+ rcu_read_unlock();
+
+ return -EOPNOTSUPP;
+}
+
int nf_flow_table_init(struct nf_flowtable *flowtable)
{
int err;
+ if (flowtable->flags & NF_FLOWTABLE_F_HW) {
+ err = nf_flow_offload_hw_init(flowtable);
+ if (err)
+ return err;
+ }
+
INIT_DEFERRABLE_WORK(&flowtable->gc_work, nf_flow_offload_work_gc);
err = rhashtable_init(&flowtable->rhashtable,
@@ -534,6 +579,8 @@ static void nf_flow_table_iterate_cleanu
{
nf_flow_table_iterate(flowtable, nf_flow_table_do_cleanup, dev);
flush_delayed_work(&flowtable->gc_work);
+ if (flowtable->flags & NF_FLOWTABLE_F_HW)
+ flush_work(&nf_flow_offload_hw_work);
}
void nf_flow_table_cleanup(struct net_device *dev)
@@ -547,6 +594,26 @@ void nf_flow_table_cleanup(struct net_de
}
EXPORT_SYMBOL_GPL(nf_flow_table_cleanup);
+struct work_struct nf_flow_offload_hw_work;
+EXPORT_SYMBOL_GPL(nf_flow_offload_hw_work);
+
+/* Give the hardware workqueue the chance to remove entries from hardware.*/
+static void nf_flow_offload_hw_free(struct nf_flowtable *flowtable)
+{
+ const struct nf_flow_table_hw *offload;
+
+ flush_work(&nf_flow_offload_hw_work);
+
+ rcu_read_lock();
+ offload = rcu_dereference(nf_flow_table_hw_hook);
+ if (!offload) {
+ rcu_read_unlock();
+ return;
+ }
+ module_put(offload->owner);
+ rcu_read_unlock();
+}
+
void nf_flow_table_free(struct nf_flowtable *flow_table)
{
mutex_lock(&flowtable_lock);
@@ -556,9 +623,58 @@ void nf_flow_table_free(struct nf_flowta
nf_flow_table_iterate(flow_table, nf_flow_table_do_cleanup, NULL);
nf_flow_table_iterate(flow_table, nf_flow_offload_gc_step, flow_table);
rhashtable_destroy(&flow_table->rhashtable);
+ if (flow_table->flags & NF_FLOWTABLE_F_HW)
+ nf_flow_offload_hw_free(flow_table);
}
EXPORT_SYMBOL_GPL(nf_flow_table_free);
+/* Must be called from user context. */
+void nf_flow_offload_hw_add(struct net *net, struct flow_offload *flow,
+ struct nf_conn *ct)
+{
+ const struct nf_flow_table_hw *offload;
+
+ rcu_read_lock();
+ offload = rcu_dereference(nf_flow_table_hw_hook);
+ if (offload)
+ offload->add(net, flow, ct);
+ rcu_read_unlock();
+}
+EXPORT_SYMBOL_GPL(nf_flow_offload_hw_add);
+
+/* Must be called from user context. */
+void nf_flow_offload_hw_del(struct net *net, struct flow_offload *flow)
+{
+ const struct nf_flow_table_hw *offload;
+
+ rcu_read_lock();
+ offload = rcu_dereference(nf_flow_table_hw_hook);
+ if (offload)
+ offload->del(net, flow);
+ rcu_read_unlock();
+}
+EXPORT_SYMBOL_GPL(nf_flow_offload_hw_del);
+
+int nf_flow_table_hw_register(const struct nf_flow_table_hw *offload)
+{
+ if (rcu_access_pointer(nf_flow_table_hw_hook))
+ return -EBUSY;
+
+ rcu_assign_pointer(nf_flow_table_hw_hook, offload);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(nf_flow_table_hw_register);
+
+void nf_flow_table_hw_unregister(const struct nf_flow_table_hw *offload)
+{
+ WARN_ON(rcu_access_pointer(nf_flow_table_hw_hook) != offload);
+ rcu_assign_pointer(nf_flow_table_hw_hook, NULL);
+
+ synchronize_rcu();
+}
+EXPORT_SYMBOL_GPL(nf_flow_table_hw_unregister);
+
static int nf_flow_table_netdev_event(struct notifier_block *this,
unsigned long event, void *ptr)
{
--- /dev/null
+++ b/net/netfilter/nf_flow_table_hw.c
@@ -0,0 +1,169 @@
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/netfilter.h>
+#include <linux/rhashtable.h>
+#include <linux/netdevice.h>
+#include <net/netfilter/nf_flow_table.h>
+#include <net/netfilter/nf_conntrack.h>
+#include <net/netfilter/nf_conntrack_core.h>
+#include <net/netfilter/nf_conntrack_tuple.h>
+
+static DEFINE_SPINLOCK(flow_offload_hw_pending_list_lock);
+static LIST_HEAD(flow_offload_hw_pending_list);
+
+static DEFINE_MUTEX(nf_flow_offload_hw_mutex);
+
+struct flow_offload_hw {
+ struct list_head list;
+ enum flow_offload_type type;
+ struct flow_offload *flow;
+ struct nf_conn *ct;
+ possible_net_t flow_hw_net;
+};
+
+static int do_flow_offload_hw(struct net *net, struct flow_offload *flow,
+ int type)
+{
+ struct net_device *indev;
+ int ret, ifindex;
+
+ ifindex = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.iifidx;
+ indev = dev_get_by_index(net, ifindex);
+ if (WARN_ON(!indev))
+ return 0;
+
+ mutex_lock(&nf_flow_offload_hw_mutex);
+ ret = indev->netdev_ops->ndo_flow_offload(type, flow);
+ mutex_unlock(&nf_flow_offload_hw_mutex);
+
+ dev_put(indev);
+
+ return ret;
+}
+
+static void flow_offload_hw_work_add(struct flow_offload_hw *offload)
+{
+ struct net *net;
+ int ret;
+
+ if (nf_ct_is_dying(offload->ct))
+ return;
+
+ net = read_pnet(&offload->flow_hw_net);
+ ret = do_flow_offload_hw(net, offload->flow, FLOW_OFFLOAD_ADD);
+ if (ret >= 0)
+ offload->flow->flags |= FLOW_OFFLOAD_HW;
+}
+
+static void flow_offload_hw_work_del(struct flow_offload_hw *offload)
+{
+ struct net *net = read_pnet(&offload->flow_hw_net);
+
+ do_flow_offload_hw(net, offload->flow, FLOW_OFFLOAD_DEL);
+}
+
+static void flow_offload_hw_work(struct work_struct *work)
+{
+ struct flow_offload_hw *offload, *next;
+ LIST_HEAD(hw_offload_pending);
+
+ spin_lock_bh(&flow_offload_hw_pending_list_lock);
+ list_replace_init(&flow_offload_hw_pending_list, &hw_offload_pending);
+ spin_unlock_bh(&flow_offload_hw_pending_list_lock);
+
+ list_for_each_entry_safe(offload, next, &hw_offload_pending, list) {
+ switch (offload->type) {
+ case FLOW_OFFLOAD_ADD:
+ flow_offload_hw_work_add(offload);
+ break;
+ case FLOW_OFFLOAD_DEL:
+ flow_offload_hw_work_del(offload);
+ break;
+ }
+ if (offload->ct)
+ nf_conntrack_put(&offload->ct->ct_general);
+ list_del(&offload->list);
+ kfree(offload);
+ }
+}
+
+static void flow_offload_queue_work(struct flow_offload_hw *offload)
+{
+ spin_lock_bh(&flow_offload_hw_pending_list_lock);
+ list_add_tail(&offload->list, &flow_offload_hw_pending_list);
+ spin_unlock_bh(&flow_offload_hw_pending_list_lock);
+
+ schedule_work(&nf_flow_offload_hw_work);
+}
+
+static void flow_offload_hw_add(struct net *net, struct flow_offload *flow,
+ struct nf_conn *ct)
+{
+ struct flow_offload_hw *offload;
+
+ offload = kmalloc(sizeof(struct flow_offload_hw), GFP_ATOMIC);
+ if (!offload)
+ return;
+
+ nf_conntrack_get(&ct->ct_general);
+ offload->type = FLOW_OFFLOAD_ADD;
+ offload->ct = ct;
+ offload->flow = flow;
+ write_pnet(&offload->flow_hw_net, net);
+
+ flow_offload_queue_work(offload);
+}
+
+static void flow_offload_hw_del(struct net *net, struct flow_offload *flow)
+{
+ struct flow_offload_hw *offload;
+
+ offload = kmalloc(sizeof(struct flow_offload_hw), GFP_ATOMIC);
+ if (!offload)
+ return;
+
+ offload->type = FLOW_OFFLOAD_DEL;
+ offload->ct = NULL;
+ offload->flow = flow;
+ write_pnet(&offload->flow_hw_net, net);
+
+ flow_offload_queue_work(offload);
+}
+
+static const struct nf_flow_table_hw flow_offload_hw = {
+ .add = flow_offload_hw_add,
+ .del = flow_offload_hw_del,
+ .owner = THIS_MODULE,
+};
+
+static int __init nf_flow_table_hw_module_init(void)
+{
+ INIT_WORK(&nf_flow_offload_hw_work, flow_offload_hw_work);
+ nf_flow_table_hw_register(&flow_offload_hw);
+
+ return 0;
+}
+
+static void __exit nf_flow_table_hw_module_exit(void)
+{
+ struct flow_offload_hw *offload, *next;
+ LIST_HEAD(hw_offload_pending);
+
+ nf_flow_table_hw_unregister(&flow_offload_hw);
+ cancel_work_sync(&nf_flow_offload_hw_work);
+
+ list_for_each_entry_safe(offload, next, &hw_offload_pending, list) {
+ if (offload->ct)
+ nf_conntrack_put(&offload->ct->ct_general);
+ list_del(&offload->list);
+ kfree(offload);
+ }
+}
+
+module_init(nf_flow_table_hw_module_init);
+module_exit(nf_flow_table_hw_module_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
+MODULE_ALIAS("nf-flow-table-hw");
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -5743,6 +5743,13 @@ static int nf_tables_flowtable_parse_hoo
if (err < 0)
return err;
+ for (i = 0; i < n; i++) {
+ if (flowtable->data.flags & NF_FLOWTABLE_F_HW &&
+ !dev_array[i]->netdev_ops->ndo_flow_offload) {
+ return -EOPNOTSUPP;
+ }
+ }
+
ops = kcalloc(n, sizeof(struct nf_hook_ops), GFP_KERNEL);
if (!ops)
return -ENOMEM;
@@ -5873,10 +5880,19 @@ static int nf_tables_newflowtable(struct
}
flowtable->data.type = type;
+ write_pnet(&flowtable->data.ft_net, net);
+
err = type->init(&flowtable->data);
if (err < 0)
goto err3;
+ if (nla[NFTA_FLOWTABLE_FLAGS]) {
+ flowtable->data.flags =
+ ntohl(nla_get_be32(nla[NFTA_FLOWTABLE_FLAGS]));
+ if (flowtable->data.flags & ~NF_FLOWTABLE_F_HW)
+ goto err4;
+ }
+
err = nf_tables_flowtable_parse_hook(&ctx, nla[NFTA_FLOWTABLE_HOOK],
flowtable);
if (err < 0)
@@ -6002,7 +6018,8 @@ static int nf_tables_fill_flowtable_info
nla_put_string(skb, NFTA_FLOWTABLE_NAME, flowtable->name) ||
nla_put_be32(skb, NFTA_FLOWTABLE_USE, htonl(flowtable->use)) ||
nla_put_be64(skb, NFTA_FLOWTABLE_HANDLE, cpu_to_be64(flowtable->handle),
- NFTA_FLOWTABLE_PAD))
+ NFTA_FLOWTABLE_PAD) ||
+ nla_put_be32(skb, NFTA_FLOWTABLE_FLAGS, htonl(flowtable->data.flags)))
goto nla_put_failure;
nest = nla_nest_start_noflag(skb, NFTA_FLOWTABLE_HOOK);
--- a/net/netfilter/nft_flow_offload.c
+++ b/net/netfilter/nft_flow_offload.c
@@ -128,6 +128,9 @@ static void nft_flow_offload_eval(const
if (ret < 0)
goto err_flow_add;
+ if (flowtable->flags & NF_FLOWTABLE_F_HW)
+ nf_flow_offload_hw_add(nft_net(pkt), flow, ct);
+
dst_release(route.tuple[!dir].dst);
return;

View file

@ -0,0 +1,26 @@
From: Felix Fietkau <nbd@nbd.name>
Date: Sun, 25 Mar 2018 21:10:55 +0200
Subject: [PATCH] netfilter: nf_flow_table: rework hardware offload timeout
handling
Some offload implementations send keepalive packets + explicit
notifications of TCP FIN/RST packets. In this case it is more convenient
to simply let the driver update flow->timeout handling and use the
regular flow offload gc step.
For drivers that manage their own lifetime, a separate flag can be set
to avoid gc timeouts.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
--- a/include/net/netfilter/nf_flow_table.h
+++ b/include/net/netfilter/nf_flow_table.h
@@ -75,6 +75,7 @@ struct flow_offload_tuple_rhash {
#define FLOW_OFFLOAD_DYING 0x4
#define FLOW_OFFLOAD_TEARDOWN 0x8
#define FLOW_OFFLOAD_HW 0x10
+#define FLOW_OFFLOAD_KEEP 0x20
struct flow_offload {
struct flow_offload_tuple_rhash tuplehash[FLOW_OFFLOAD_DIR_MAX];

View file

@ -0,0 +1,14 @@
#!/bin/sh
CFG=$1
[ -n "$CFG" ] || CFG=/etc/board.json
[ -d "/etc/board.d/" -a ! -s "$CFG" ] && {
for a in $(ls /etc/board.d/*); do
[ -x $a ] || continue;
$(. $a)
done
}
[ -s "$CFG" ] || return 1

View file

@ -0,0 +1,307 @@
#!/bin/sh
#
# Copyright (c) 2015 The Linux Foundation. All rights reserved.
# Copyright (c) 2011-2015 OpenWrt.org
#
. /lib/functions/uci-defaults.sh
. /lib/functions/system.sh
CFG=/etc/board.json
# do not run on preinit/early init
[ "$EARLY_INIT" ] && return
strstr() {
[ "${1#*$2*}" = "$1" ] && return 1
return 0
}
print_array() {
json_add_array $1
case "$1" in
4G)
for element in $2
do
json_add_string "" "$(echo $element)"
done
;;
3G)
for element in $2
do
json_add_string "" "wcdma_$(echo $element)"
done
;;
2G)
for element in $2
do
json_add_string "" "$(echo $element)"
done
;;
esac
json_close_array
}
gather_band_capabilities() {
# Same logic as unhandler.c
###################### EG06 #########################
if strstr $revision_from_unhandler "EG06E"; then #EG06E
lte_bands="1 3 5 7 8 20 28 32 38 40 41" #B
trysg_bands="850 900 1800 2100" #MHz
dug_bands=""
elif strstr $revision_from_unhandler "EG06A"; then #EG06A
lte_bands="2 4 5 7 12 13 25 26 29 30 66"
trysg_bands="850 1700 1900"
dug_bands=""
###################### EC25 #########################
elif strstr $revision_from_unhandler "EC25EF"; then #EC25E
lte_bands="1 3 5 7 8 20 38 40 41"
trysg_bands="850 900 2100"
dug_bands="900 1800" #MHz
elif strstr $revision_from_unhandler "EC25EC"; then #EC25EC
lte_bands="1 3 7 8 20 28"
trysg_bands="900 2100"
dug_bands="900 1800"
elif strstr $revision_from_unhandler "EC25AUX"; then #EC25AUX
lte_bands="1 2 3 4 5 7 8 28 40"
trysg_bands="850 900 1700 1900 2100"
dug_bands="850 900 1800 1900"
elif strstr $revision_from_unhandler "EC25AFA"; then #EC25A
lte_bands="2 4 12"
trysg_bands="850 1700 1900"
dug_bands=""
elif strstr $revision_from_unhandler "EC25V"; then #EC25V
lte_bands="4 13"
trysg_bands=""
dug_bands=""
elif strstr $revision_from_unhandler "EC25AFX"; then #EC25AFX
lte_bands="2 4 5 12 13 14 66 71"
trysg_bands="850 1700 1900"
dug_bands=""
elif strstr $revision_from_unhandler "EC25AFF"; then #EC25AF
lte_bands="2 4 5 12 13 14 66 71"
trysg_bands="850 1700 1900"
dug_bands=""
elif strstr $revision_from_unhandler "EC25AUTF"; then #EC25AUT
lte_bands="1 3 5 7 28"
trysg_bands="850 2100"
dug_bands=""
elif strstr $revision_from_unhandler "EC25AUTL"; then #EC25AUTL
lte_bands="3 7 28"
trysg_bands=""
dug_bands=""
elif strstr $revision_from_unhandler "EC25AUF"; then #EC25AU
lte_bands="1 2 3 4 5 7 8 28 40"
trysg_bands="850 900 1900 2100"
dug_bands="850 900 1800 1900"
elif strstr $revision_from_unhandler "EC25J"; then #EC25J
lte_bands="1 3 8 18 19 26 41"
trysg_bands="800 900 2100"
dug_bands=""
elif strstr $revision_from_unhandler "EC25EUX"; then #EC25EUX
lte_bands="1 3 7 8 20 28 38 40 41"
trysg_bands="900 2100"
dug_bands="900 1800"
elif strstr $revision_from_unhandler "EC25EUF"; then #EC25EU
lte_bands="1 3 7 8 20 28 38 40 41"
trysg_bands="900 2100"
dug_bands="900 1800"
elif strstr $revision_from_unhandler "EC25EUG"; then #EC25EU
lte_bands="1 3 7 8 20 28 38 40 41"
trysg_bands="900 2100"
dug_bands="900 1800"
elif strstr $revision_from_unhandler "EC25MX"; then #EC25MX
lte_bands="2 4 5 7 28 66"
trysg_bands="850 1700 1900"
dug_bands=""
###################### EC21 #########################
elif strstr $revision_from_unhandler "EC21EUX"; then #EC21EUX
lte_bands="1 3 7 8 20 28"
trysg_bands="900 2100"
dug_bands="900 1800"
elif strstr $revision_from_unhandler "EC21EU"; then #EC21EU
lte_bands="1 3 7 8 20 28"
trysg_bands="900 2100"
dug_bands="900 1800"
elif strstr $revision_from_unhandler "EC21EC"; then #EC21EC
lte_bands="1 3 7 8 20 28"
trysg_bands="900 2100"
dug_bands="900 1800"
elif strstr $revision_from_unhandler "EC21E"; then #EC21E
lte_bands="1 3 5 7 8 20"
trysg_bands="850 900 2100"
dug_bands="900 1800"
elif strstr $revision_from_unhandler "EC21V"; then #EC21V
lte_bands="4 13"
trysg_bands=""
dug_bands=""
elif strstr $revision_from_unhandler "EC21KL"; then #EC21KL
lte_bands="1 3 5 7 8"
trysg_bands=""
dug_bands=""
elif strstr $revision_from_unhandler "EC21J"; then #EC21J
lte_bands="1 3 8 18 19 26"
trysg_bands=""
dug_bands=""
elif strstr $revision_from_unhandler "EC21AUX"; then #EC21AUX
lte_bands="1 2 3 4 5 7 8 28 40"
trysg_bands="850 900 1700 1900 2100"
dug_bands="850 900 1800 1900"
elif strstr $revision_from_unhandler "EC21AUT"; then #EC21AUT
lte_bands="1 3 5 7 28"
trysg_bands="850 2100"
dug_bands=""
elif strstr $revision_from_unhandler "EC21AU"; then #EC21AU
lte_bands="1 2 3 4 5 7 8 28 40"
trysg_bands="850 900 1900 2100"
dug_bands="850 900 1800 1900"
elif strstr $revision_from_unhandler "EC21A"; then #EC21A
lte_bands="2 4 12"
trysg_bands="850 1700 1900"
dug_bands=""
###################### EG25 #########################
elif strstr $revision_from_unhandler "EG25G"; then #EG25G
lte_bands="1 2 3 4 5 7 8 12 13 18 19 20 25 26 28 38 39 40 41"
trysg_bands="800 850 900 1700 1900 2100"
dug_bands="850 900 1800 1900"
elif strstr $revision_from_unhandler "EG12EA"; then #EG12EA
lte_bands="1 3 5 7 8 20 28 38 40 41"
trysg_bands="850 900 1800 2100"
dug_bands=""
elif strstr $revision_from_unhandler "EG12NA"; then #EG12NA
lte_bands="2 4 5 7 12 13 14 17 25 26 29 30 41 66 71"
trysg_bands="850 1700 1900"
dug_bands=""
elif strstr $revision_from_unhandler "BG96"; then #BG96M
lte_bands="1 2 3 4 5 8 12 13 18 19 20 26 28 39"
trysg_bands=""
dug_bands="850 900 1800 1900"
##################### SLM750 ########################
elif strstr $revision_from_unhandler "750VE"; then #SLM750VE
lte_bands="1 3 5 7 8 20 40"
trysg_bands="850 900 2100"
dug_bands="900 1800"
elif strstr $revision_from_unhandler "750VAU"; then #SLM750VAU
lte_bands="1 3 5 7 8 28 40"
trysg_bands="850 900 2100"
dug_bands="850 900 1800"
elif strstr $revision_from_unhandler "750VA"; then #SLM750VA
lte_bands="2 4 5 12 13 17 18 25 26 41"
trysg_bands="850 1700 1900"
dug_bands="850 1900"
elif strstr $revision_from_unhandler "750VJ"; then #SLM750VJ
lte_bands="1 3 8 18 19 26 41"
trysg_bands="800 900 2100"
dug_bands=""
elif strstr $revision_from_unhandler "750VSA"; then #SLM750VSA
lte_bands="2 4 5 7 8 28 40"
trysg_bands="850 900 1900"
dug_bands="850 900 1900"
###################### UC20 #########################
elif strstr $revision_from_unhandler "UC20E"; then #UC20E
lte_bands=""
trysg_bands="900 2100"
dug_bands="850 900 1800 1900"
elif strstr $revision_from_unhandler "UC20G"; then #UC20G
lte_bands=""
trysg_bands="800 850 900 1900 2100"
dug_bands="850 900 1800 1900"
elif strstr $revision_from_unhandler "UC20A"; then #UC20A
lte_bands=""
trysg_bands="850 1900"
dug_bands=""
else
lte_bands="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28"
trysg_bands="700 800 850 900 1500 1700 2600"
dug_bands="1700 1800 1900 2100"
fi
}
validate_service_modes() {
json_get_keys service_modes service_modes
found_modes="$(printf "$service_modes" | awk '!seen[$0]++'| wc -l)"
[ "$found_modes" -eq 0 ] && {
return 0
}
return 1
}
#~ Get model name for RUTX products
setup_modem() {
local key="$1"
local object_num="$2"
local id gps boudrate type desc control product vendor stop_bits
json_select "$object_num"
json_get_vars id product
if [ "$id" = "$id_from_unhandler" ]; then
[ -z "$product" ] || \
{
[ -f "/sys/bus/usb/devices/$id/idVendor" ] && [ -f "/sys/bus/usb/devices/$id/idProduct" ] || {
json_select ..
return 1
}
validate_service_modes && {
gather_band_capabilities
json_select_object service_modes
[ -z "$lte_bands" ] || print_array "4G" "$lte_bands"
[ -z "$trysg_bands" ] || print_array "3G" "$trysg_bands"
[ -z "$dug_bands" ] || print_array "2G" "$dug_bands"
json_select ..
}
json_select ..
return 1
}
vendor="$(cat "/sys/bus/usb/devices/$id/idVendor")"
product="$(cat "/sys/bus/usb/devices/$id/idProduct")"
[ -f "/lib/network/wwan/$vendor:$product" ] && {
devicename="$id"
gather_band_capabilities
json_set_namespace defaults old_cb
json_load "$(cat /lib/network/wwan/$vendor:$product)"
json_get_vars gps boudrate type desc control stop_bits
json_set_namespace "$old_cb"
[ "${devicename%%:*}" = "$devicename" ] && {
json_add_string vendor "$vendor"
json_add_string product "$product"
json_add_string gps "$gps"
json_add_string stop_bits "$stop_bits"
json_add_string boudrate "$boudrate"
json_add_string type "$type"
json_add_string desc "$desc"
json_add_string control "$control"
json_add_object service_modes
[ -z "$lte_bands" ] || print_array "4G" "$lte_bands"
[ -z "$trysg_bands" ] || print_array "3G" "$trysg_bands"
[ -z "$dug_bands" ] || print_array "2G" "$dug_bands"
json_close_object
}
}
fi
json_select ..
}
[ -s "${CFG}" ] || exit 1
id_from_unhandler="$1"
revision_from_unhandler="$2"
lock /var/run/board_modem.lock
board_config_update
json_for_each_item setup_modem modems
board_config_flush
lock -u /var/run/board_modem.lock
exit 0

View file

@ -0,0 +1,47 @@
#!/bin/sh
. /lib/functions/uci-defaults.sh
CFG=/etc/board.json
SLP=30
check_modem() {
json_select "$2"
json_get_vars id
[ -z "$id" ] && {
json_select ..
return 0
}
#logger -t "board-track" "ls -d /sys/bus/usb/devices/$id/${id}*/tty?*"
ttys=$(ls -d /sys/bus/usb/devices/$id/${id}*/tty?*)
[ -n "$ttys" ] || { #FAILED TO FIND MODEM
logger -t "board-track" "modem $id not detected"
for m in /sys/class/gpio/modem*_power; do
label="$(basename $m | awk -F_ '{print $1}')"
mctl -s -m ${label}
sleep 1
mctl -p -m ${label}
done
sleep 5
ip link set up dev wwan0 2>&1 >/dev/null
ip link set up dev wwan1 2>&1 >/dev/null
json_select ..
return 1
}
[ -n "$(ip link show dev wwan0 | grep DOWN)" ] && ip link set up dev wwan0 2>&1 >/dev/null
[ -n "$(ip link show dev wwan1 | grep DOWN)" ] && ip link set up dev wwan1 2>&1 >/dev/null
#MODEM UP
json_select ..
}
board_config_update
while true; do
json_for_each_item check_modem modems
sleep $SLP
[ $SLP -lt 300 ] && SLP=$((SLP+30))
done

View file

@ -0,0 +1,665 @@
#!/bin/sh
CFG=/etc/board.json
. /usr/share/libubox/jshn.sh
[ -s $CFG ] || /bin/board_detect || exit 1
[ -s /etc/config/network ] && \
[ -s /etc/config/system ] && \
[ -s /etc/config/hwinfo ] && \
[ -s /etc/config/blesem ] && \
exit 0
generate_static_network() {
uci -q batch <<-EOF
delete network.loopback
set network.loopback='interface'
set network.loopback.ifname='lo'
set network.loopback.proto='static'
set network.loopback.ipaddr='127.0.0.1'
set network.loopback.netmask='255.0.0.0'
EOF
[ -e /proc/sys/net/ipv6 ] && {
uci -q batch <<-EOF
delete network.globals
set network.globals='globals'
set network.globals.ula_prefix='auto'
EOF
}
if json_is_a dsl object; then
json_select dsl
if json_is_a atmbridge object; then
json_select atmbridge
local vpi vci encaps payload nameprefix
json_get_vars vpi vci encaps payload nameprefix
uci -q batch <<-EOF
delete network.atm
set network.atm='atm-bridge'
set network.atm.vpi='$vpi'
set network.atm.vci='$vci'
set network.atm.encaps='$encaps'
set network.atm.payload='$payload'
set network.atm.nameprefix='$nameprefix'
EOF
json_select ..
fi
if json_is_a modem object; then
json_select modem
local type annex firmware tone xfer_mode
json_get_vars type annex firmware tone xfer_mode
uci -q batch <<-EOF
delete network.dsl
set network.dsl='dsl'
set network.dsl.annex='$annex'
set network.dsl.firmware='$firmware'
set network.dsl.tone='$tone'
set network.dsl.xfer_mode='$xfer_mode'
EOF
json_select ..
fi
json_select ..
fi
}
addr_offset=2
generate_network() {
local keys var val ifname macaddr proto type ipaddr netmask
uci -q batch <<-EOF
delete "network.$1"
set network.$1='interface'
EOF
json_select network
json_select "$1"
json_get_keys keys
for var in $keys; do
json_get_var val "$var"
[ "${var#_*}" = "$var" ] && {
eval "$var=\"\$val\""
uci -q set "network.$1.$var=$val"
}
done
json_select ..
json_select ..
#~ [ -n "$ifname" ] || return
# force bridge for multi-interface devices (and lan)
case "$1:$ifname" in
*\ * | lan:*)
type="bridge"
uci -q set "network.$1.type=$type"
;;
esac
if [ -n "$macaddr" ]; then
for name in $ifname; do
uci -q batch <<-EOF
delete network.$1_${name/./_}_dev
set network.$1_${name/./_}_dev='device'
set network.$1_${name/./_}_dev.name='$name'
set network.$1_${name/./_}_dev.macaddr='$macaddr'
EOF
done
fi
case "$proto" in
static)
local ipad
case "$1" in
lan)
ipad=${ipaddr:-"192.168.100.1"}
;;
*) ipad=${ipaddr:-"192.168.$((addr_offset++)).1"} ;;
esac
netm=${netmask:-"255.255.255.0"}
uci -q batch <<-EOF
set network.$1.proto='static'
set network.$1.ipaddr='$ipad'
set network.$1.netmask='$netm'
EOF
[ -e /proc/sys/net/ipv6 ] && uci set network.$1.ip6assign='60'
;;
dhcp)
# fixup IPv6 slave interface if parent is a bridge
[ "$type" = "bridge" ] && ifname="br-$1"
uci set network.$1.proto='dhcp'
uci set network.$1.metric='1'
#[ -e /proc/sys/net/ipv6 ] && {
# uci -q batch <<-EOF
# delete network.${1}6
# set network.${1}6='interface'
# set network.${1}6.device='$ifname'
# set network.${1}6.proto='dhcpv6'
# set network.${1}6.metric='1'
# EOF
#}
;;
pppoe)
uci -q batch <<-EOF
set network.$1.proto='pppoe'
set network.$1.username='username'
set network.$1.password='password'
EOF
[ -e /proc/sys/net/ipv6 ] && {
uci -q batch <<-EOF
set network.$1.ipv6='1'
delete network.${1}6
set network.${1}6='interface'
set network.${1}6.ifname='@${1}'
set network.${1}6.proto='dhcpv6'
EOF
}
;;
esac
}
add_modem_section() {
local id="$1"
local num="$2"
local simcount="$3"
local builtin="$4"
for count in $(seq "$simcount"); do
interface="mob${num}s${count}a1"
local proto="wwan"
# just like this for now
# probably we should merge connm with wwan
[ -e /dev/smd9 ] && {
proto="connm"
}
uci -q batch <<-EOF
delete network.$interface
set network.$interface='interface'
set network.$interface.proto='$proto'
set network.$interface.modem='$id'
set network.$interface.metric='$((num+1))'
set network.$interface.sim='${count}'
set network.$interface.pdp='1'
EOF
# just like this for now
# probably we should merge connm with wwan
[ -e /dev/smd9 ] && {
uci set network.$interface.ifname='rmnet0'
}
update_firewall_zone "wan" "$interface"
create_multiwan_iface "$interface" "$num"
add_simcard_config "$id" "${count}" "${count}" "$builtin"
add_sim_switch_config "$id" "${count}"
add_quota_limit_config "$interface"
done
add_sms_storage_config "$id"
}
generate_dynamic_lte() {
[ -f /lib/functions/modem.sh ] || return
. /lib/functions/modem.sh
local interface num id simcount builtin
#creating simcard sections from board.json file
if json_is_a modems array; then
json_get_keys modems modems
json_select modems
num=1
for modem in $modems; do
json_select "$modem"
json_get_vars id simcount builtin
json_select ..
add_modem_section "$id" "$num" "$simcount" "$builtin"
num=$(( num + 1 ))
done
json_select ..
else
## because of RUTX8 have no default modem
# after this script runs out simcard config
# must not be empty due to external modems could appear to config
echo " " >> /etc/config/simcard
fi
#creating simcard sections from conneted via USB
for a in `ls /sys/bus/usb/devices`; do
local vendor product
[ -f "/sys/bus/usb/devices/$a/idVendor" ] && [ -f "/sys/bus/usb/devices/$a/idProduct" ] || continue
vendor=$(cat "/sys/bus/usb/devices/$a/idVendor")
product=$(cat "/sys/bus/usb/devices/$a/idProduct")
[ -f "/lib/network/wwan/${vendor}:${product}" ] && {
add_simcard_config "$a" "1" "0" ""
}
done
}
generate_switch_vlans_ports() {
local switch="$1"
local port ports role roles num attr val
#
# autogenerate vlans
#
if json_is_a roles array; then
json_get_keys roles roles
json_select roles
for role in $roles; do
json_select "$role"
json_get_vars ports
json_select ..
uci -q batch <<-EOF
add network switch_vlan
set network.@switch_vlan[-1].device='$switch'
set network.@switch_vlan[-1].vlan='$role'
set network.@switch_vlan[-1].ports='$ports'
EOF
done
json_select ..
fi
#
# write port specific settings
#
if json_is_a ports array; then
json_get_keys ports ports
json_select ports
for port in $ports; do
json_select "$port"
json_get_vars num
if json_is_a attr object; then
json_get_keys attr attr
json_select attr
uci -q batch <<-EOF
add network switch_port
set network.@switch_port[-1].device='$switch'
set network.@switch_port[-1].port=$num
EOF
for attr in $attr; do
json_get_var val "$attr"
uci -q set network.@switch_port[-1].$attr="$val"
done
json_select ..
fi
json_select ..
done
json_select ..
fi
}
generate_switch() {
local key="$1"
local vlans
json_select switch
json_select "$key"
json_get_vars enable reset blinkrate cpu_port \
ar8xxx_mib_type ar8xxx_mib_poll_interval
uci -q batch <<-EOF
add network switch
set network.@switch[-1].name='$key'
set network.@switch[-1].reset='$reset'
set network.@switch[-1].enable_vlan='$enable'
set network.@switch[-1].blinkrate='$blinkrate'
set network.@switch[-1].ar8xxx_mib_type='$ar8xxx_mib_type'
set network.@switch[-1].ar8xxx_mib_poll_interval='$ar8xxx_mib_poll_interval'
EOF
generate_switch_vlans_ports "$1"
json_select ..
json_select ..
}
generate_static_system() {
param=$(/sbin/mnf_info "--name")
hostname=${param:0:6}
uci -q batch <<-EOF
delete system.@system[0]
set system.system='system'
set system.@system[-1].hostname='OpenMPTCProuter'
set system.@system[-1].timezone='UTC'
set system.@system[-1].ttylogin='0'
set system.@system[-1].log_size='128'
set system.@system[-1].urandom_seed='0'
delete system.ntp
set system.ntp='timeserver'
set system.ntp.enabled='0'
set system.ntp.enable_server='0'
add_list system.ntp.server='0.pool.ntp.org'
add_list system.ntp.server='1.pool.ntp.org'
add_list system.ntp.server='2.pool.ntp.org'
add_list system.ntp.server='3.pool.ntp.org'
delete system.debug
set system.debug='debug'
set system.debug.sms_utils_debug_level='4'
EOF
if json_is_a system object; then
json_select system
local hostname
#if json_get_var hostname hostname; then
# uci -q set "system.@system[-1].hostname=$hostname"
#fi
if json_is_a ntpserver array; then
local keys key
json_get_keys keys ntpserver
json_select ntpserver
uci -q delete "system.ntp.server"
for key in $keys; do
local server
if json_get_var server "$key"; then
uci -q add_list "system.ntp.server=$server"
fi
done
json_select ..
fi
json_select ..
fi
}
generate_rssimon() {
local key="$1"
local cfg="rssid_$key"
local refresh threshold
json_select rssimon
json_select "$key"
json_get_vars refresh threshold
json_select ..
json_select ..
uci -q batch <<-EOF
delete system.$cfg
set system.$cfg='rssid'
set system.$cfg.dev='$key'
set system.$cfg.refresh='$refresh'
set system.$cfg.threshold='$threshold'
EOF
}
generate_led() {
local key="$1"
local cfg="led_$key"
json_select led
json_select "$key"
json_get_vars name sysfs type trigger default
uci -q batch <<-EOF
delete system.$cfg
set system.$cfg='led'
set system.$cfg.name='$name'
set system.$cfg.sysfs='$sysfs'
set system.$cfg.trigger='$trigger'
set system.$cfg.default='$default'
EOF
case "$type" in
gpio)
local gpio inverted
json_get_vars gpio inverted
uci -q batch <<-EOF
set system.$cfg.trigger='gpio'
set system.$cfg.gpio='$gpio'
set system.$cfg.inverted='$inverted'
EOF
;;
netdev)
local device mode
json_get_vars device mode
uci -q batch <<-EOF
set system.$cfg.trigger='netdev'
set system.$cfg.mode='$mode'
set system.$cfg.dev='$device'
EOF
;;
usb)
local device
json_get_vars device
uci -q batch <<-EOF
set system.$cfg.trigger='usbdev'
set system.$cfg.interval='50'
set system.$cfg.dev='$device'
EOF
;;
usbport)
local ports port
json_get_values ports ports
uci set system.$cfg.trigger='usbport'
for port in $ports; do
uci add_list system.$cfg.port=$port
done
;;
rssi)
local iface minq maxq offset factor
json_get_vars iface minq maxq offset factor
uci -q batch <<-EOF
set system.$cfg.trigger='rssi'
set system.$cfg.iface='rssid_$iface'
set system.$cfg.minq='$minq'
set system.$cfg.maxq='$maxq'
set system.$cfg.offset='$offset'
set system.$cfg.factor='$factor'
EOF
;;
switch)
local port_mask speed_mask mode
json_get_vars port_mask speed_mask mode
uci -q batch <<-EOF
set system.$cfg.port_mask='$port_mask'
set system.$cfg.speed_mask='$speed_mask'
set system.$cfg.mode='$mode'
EOF
;;
portstate)
local port_state
json_get_vars port_state
uci -q batch <<-EOF
set system.$cfg.port_state='$port_state'
EOF
;;
timer|oneshot)
local delayon delayoff
json_get_vars delayon delayoff
uci -q batch <<-EOF
set system.$cfg.trigger='$type'
set system.$cfg.delayon='$delayon'
set system.$cfg.delayoff='$delayoff'
EOF
;;
esac
json_select ..
json_select ..
}
generate_gpioswitch() {
local cfg="$1"
json_select gpioswitch
json_select "$cfg"
local name pin default
json_get_vars name pin default
uci -q batch <<-EOF
delete system.$cfg
set system.$cfg='gpio_switch'
set system.$cfg.name='$name'
set system.$cfg.gpio_pin='$pin'
set system.$cfg.value='$default'
EOF
json_select ..
json_select ..
}
generate_hwinfo() {
local parameter="$1"
local temp
json_select hwinfo
json_get_var temp "$parameter"
json_select ..
uci -q batch <<-EOF
set hwinfo.hwinfo='hwinfo'
set hwinfo.hwinfo.$parameter='$temp'
EOF
}
generate_bluetooth() {
uci -q batch <<-EOF
set blesem.general='section'
set blesem.general.enabled='0'
set blesem.settings='app'
set blesem.settings.refresh_time='30000'
EOF
}
add_firewall_zone() {
local ifname
json_select network
json_select "$1"
json_get_vars ifname
json_select ..
json_select ..
fw3 -q network "$1" || fw3 -q device "$ifname" && return
uci -q batch <<-EOF
add firewall zone
set firewall.@zone[-1].name='$1'
set firewall.@zone[-1].network='$1'
set firewall.@zone[-1].input='REJECT'
set firewall.@zone[-1].output='ACCEPT'
set firewall.@zone[-1].forward='REJECT'
add firewall forwarding
set firewall.@forwarding[-1].src='$1'
set firewall.@forwarding[-1].dest='wan'
add firewall rule
set firewall.@rule[-1].name='Allow-DNS-$1'
set firewall.@rule[-1].src='$1'
set firewall.@rule[-1].dest_port='53'
set firewall.@rule[-1].proto='tcp udp'
set firewall.@rule[-1].target='ACCEPT'
add firewall rule
set firewall.@rule[-1].name='Allow-DHCP-$1'
set firewall.@rule[-1].src='$1'
set firewall.@rule[-1].dest_port='67'
set firewall.@rule[-1].proto='udp'
set firewall.@rule[-1].family='ipv4'
set firewall.@rule[-1].target='ACCEPT'
EOF
}
add_dhcp() {
json_select network
json_select "$1"
json_get_vars _dhcp
json_select ..
json_select ..
[ "$_dhcp" = "1" ] || return
uci -q batch <<-EOF
set dhcp.$1='dhcp'
set dhcp.$1.interface='$1'
set dhcp.$1.start='100'
set dhcp.$1.limit='150'
set dhcp.$1.leasetime='1h'
EOF
}
json_init
json_load "$(cat ${CFG})"
umask 077
if [ ! -s /etc/config/network ]; then
touch /etc/config/network
generate_static_network
json_get_keys keys network
for key in $keys; do
generate_network $key
add_firewall_zone "$key"
add_dhcp "$key"
done
json_get_keys keys switch
for key in $keys; do generate_switch $key; done
generate_dynamic_lte
fi
if [ ! -s /etc/config/system ]; then
touch /etc/config/system
generate_static_system
json_get_keys keys rssimon
for key in $keys; do generate_rssimon $key; done
json_get_keys keys gpioswitch
for key in $keys; do generate_gpioswitch $key; done
json_get_keys keys led
for key in $keys; do generate_led $key; done
fi
if [ ! -s /etc/config/hwinfo ]; then
touch /etc/config/hwinfo
json_get_keys keys hwinfo
for key in $keys; do generate_hwinfo $key; done
fi
if [ ! -s /etc/config/blesem ]; then
bluetooth=""
json_select hwinfo
json_get_vars bluetooth
[ "$bluetooth" -eq 1 ] && {
touch /etc/config/blesem
touch /etc/config/ble_devices
generate_bluetooth
}
fi
uci commit

View file

@ -0,0 +1,71 @@
#!/bin/sh
awk -f - $* <<EOF
function bitcount(c) {
c=and(rshift(c, 1),0x55555555)+and(c,0x55555555)
c=and(rshift(c, 2),0x33333333)+and(c,0x33333333)
c=and(rshift(c, 4),0x0f0f0f0f)+and(c,0x0f0f0f0f)
c=and(rshift(c, 8),0x00ff00ff)+and(c,0x00ff00ff)
c=and(rshift(c,16),0x0000ffff)+and(c,0x0000ffff)
return c
}
function ip2int(ip) {
for (ret=0,n=split(ip,a,"\."),x=1;x<=n;x++) ret=or(lshift(ret,8),a[x])
return ret
}
function int2ip(ip,ret,x) {
ret=and(ip,255)
ip=rshift(ip,8)
for(;x<3;ret=and(ip,255)"."ret,ip=rshift(ip,8),x++);
return ret
}
function compl32(v) {
ret=xor(v, 0xffffffff)
return ret
}
BEGIN {
slpos=index(ARGV[1],"/")
if (slpos == 0) {
ipaddr=ip2int(ARGV[1])
dotpos=index(ARGV[2],".")
if (dotpos == 0)
netmask=compl32(2**(32-int(ARGV[2]))-1)
else
netmask=ip2int(ARGV[2])
} else {
ipaddr=ip2int(substr(ARGV[1],0,slpos-1))
netmask=compl32(2**(32-int(substr(ARGV[1],slpos+1)))-1)
ARGV[4]=ARGV[3]
ARGV[3]=ARGV[2]
}
network=and(ipaddr,netmask)
broadcast=or(network,compl32(netmask))
start=or(network,and(ip2int(ARGV[3]),compl32(netmask)))
limit=network+1
if (start<limit) start=limit
end=start+ARGV[4]
limit=or(network,compl32(netmask))-1
if (end>limit) end=limit
print "IP="int2ip(ipaddr)
print "NETMASK="int2ip(netmask)
print "BROADCAST="int2ip(broadcast)
print "NETWORK="int2ip(network)
print "PREFIX="32-bitcount(compl32(netmask))
# range calculations:
# ipcalc <ip> <netmask> <start> <num>
if (ARGC > 3) {
print "START="int2ip(start)
print "END="int2ip(end)
}
}
EOF

View file

@ -0,0 +1,214 @@
#!/bin/sh
#
# Copyright (c) 2015 The Linux Foundation. All rights reserved.
# Copyright (c) 2011-2015 OpenWrt.org
#
. /lib/functions/uci-defaults.sh
. /lib/functions/teltonika-defaults.sh
. /lib/functions/system.sh
setup_json() {
local model="$1"
case "$model" in
RUTX08*)
ucidef_set_interfaces_lan_wan "eth0" "eth1"
ucidef_add_switch "switch0" \
"0u@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "0u@eth1" "5:wan"
ucidef_set_hwinfo usb ethernet ios
;;
RUTX09*)
ucidef_set_interfaces_lan_wan "eth0" "eth1"
ucidef_add_switch "switch0" \
"0u@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "0u@eth1" "5:wan"
ucidef_add_static_modem_info "$model" "3-1" "2" "gps_out"
ucidef_set_hwinfo dual_sim usb gps mobile ethernet ios
;;
RUTX10*)
ucidef_set_interfaces_lan_wan "eth0" "eth1"
ucidef_add_switch "switch0" \
"0u@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "0u@eth1" "5:wan"
ucidef_set_hwinfo bluetooth usb wifi dual_band_ssid ethernet ios
;;
RUTX11*)
ucidef_set_interfaces_lan_wan "eth0" "eth1"
ucidef_add_switch "switch0" \
"0u@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "0u@eth1" "5:wan"
ucidef_add_static_modem_info "$model" "3-1" "2" "gps_out"
ucidef_set_hwinfo dual_sim usb gps mobile wifi dual_band_ssid bluetooth ethernet ios
;;
RUTXR1*)
ucidef_set_interfaces_lan_wan "eth0" "eth1"
ucidef_add_switch "switch0" \
"0u@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "0u@eth1" "5:wan"
ucidef_add_static_modem_info "$model" "3-1" "2"
ucidef_set_hwinfo dual_sim usb mobile wifi dual_band_ssid ethernet sfp_port
ucidef_set_release_version "2.3.1"
;;
RUTX12*)
ucidef_set_interfaces_lan_wan "eth0" "eth1"
ucidef_add_switch "switch0" \
"0u@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "0u@eth1" "5:wan"
# builtin and primary should be first modem
ucidef_add_static_modem_info "$model" "3-1" "1" "primary" "gps_out"
ucidef_add_static_modem_info "$model" "1-1.2" "1"
ucidef_set_hwinfo usb gps mobile wifi dual_band_ssid bluetooth ethernet ios
ucidef_set_release_version "2.3.1"
;;
RUTX14*)
ucidef_set_interfaces_lan_wan "eth0" "eth1"
ucidef_add_switch "switch0" \
"0u@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "0u@eth1" "5:wan"
ucidef_add_static_modem_info "$model" "1-1" "2" "gps_out"
ucidef_set_hwinfo usb gps dual_sim mobile wifi dual_band_ssid bluetooth ethernet ios at_sim
ucidef_set_release_version "2.6.1"
;;
RUTX18*)
ucidef_set_interfaces_lan_wan "eth0" "eth1"
ucidef_add_switch "switch0" \
"0u@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "0u@eth1" "5:wan"
ucidef_add_static_modem_info "$model" "2-1" "2" "gps_out"
ucidef_set_hwinfo usb gps dual_sim mobile wifi dual_band_ssid bluetooth ethernet ios
;;
RUTX50*)
ucidef_set_interfaces_lan_wan "eth0" "eth1"
ucidef_add_switch "switch0" \
"0u@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "0u@eth1" "5:wan"
ucidef_add_static_modem_info "$model" "2-1" "2" "gps_out"
ucidef_set_hwinfo dual_sim usb gps mobile wifi dual_band_ssid ethernet ios at_sim
;;
TRB2*)
ucidef_set_led_switch "lan" "LAN" "eth_led" "switch0" "0x04"
ucidef_set_interface_lan "eth0"
ucidef_add_static_modem_info "$model" "1-1.4" "2" "gps_out"
ucidef_add_serial_capabilities "rs232 rs485" \
"300 600 1200 2400 4800 9600 14400 19200 38400 56000 57600 115200 \
230400 460800 921600 1000000 3000000" \
"7 8"
ucidef_set_hwinfo dual_sim mobile gps ethernet ios
;;
RUT200* |\
RUT241*)
ucidef_set_led_switch "lan" "LAN" "eth1_led" "switch0" "0x2"
ucidef_set_led_switch "wan" "WAN" "eth2_led" "switch0" "0x1"
ucidef_add_switch "switch0" "1:lan" "0:wan" "6@eth0"
ucidef_set_interface_macaddr "lan" "$(mtd_get_mac_binary config 0x0)"
ucidef_set_interface_macaddr "wan" "$(macaddr_add "$(mtd_get_mac_binary config 0x0)" 1)"
ucidef_add_static_modem_info "$model" "1-1" "1"
[ "${model:7:1}" = "1" ] && ucidef_set_hwinfo mobile wifi \
ethernet || ucidef_set_hwinfo mobile wifi ethernet ios
;;
RUT2*)
ucidef_set_led_switch "lan" "LAN" "lan_led" "switch0" "0x04"
ucidef_set_led_netdev "wan" "WAN" "wan_led" "eth1"
ucidef_set_interfaces_lan_wan "eth0" "eth1"
ucidef_add_static_modem_info "$model" "1-1" "1"
[ "${model:6:1}" = "1" ] && ucidef_set_hwinfo mobile wifi \
ethernet || ucidef_set_hwinfo mobile wifi ethernet ios
;;
RUT300*)
ucidef_set_led_switch "lan1" "LAN1" "eth1_led" "switch0" "0x02"
ucidef_set_led_switch "lan2" "LAN2" "eth2_led" "switch0" "0x10"
ucidef_set_led_switch "lan3" "LAN3" "eth3_led" "switch0" "0x08"
ucidef_set_led_switch "lan4" "LAN4" "eth4_led" "switch0" "0x04"
ucidef_set_led_netdev "wan" "WAN" "wan_led" "eth1"
ucidef_set_interface_wan "eth1"
ucidef_add_switch "switch0" \
"0@eth0" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2"
ucidef_set_hwinfo usb ethernet ios
;;
RUT360*)
ucidef_set_led_switch "lan" "LAN" "eth1_led" "switch0" "0x10"
ucidef_set_led_netdev "wan" "WAN" "eth2_led" "eth1"
ucidef_set_interfaces_lan_wan "eth0" "eth1"
ucidef_add_static_modem_info "$model" "1-1" "1"
ucidef_set_hwinfo mobile wifi dual_band_ssid ethernet ios
;;
RUT950*)
ucidef_set_led_switch "lan1" "LAN1" "eth1_led" "switch0" "0x10"
ucidef_set_led_switch "lan2" "LAN2" "eth2_led" "switch0" "0x08"
ucidef_set_led_switch "lan3" "LAN3" "eth3_led" "switch0" "0x04"
ucidef_set_led_netdev "wan" "WAN" "wan_led" "eth1"
ucidef_set_interface_wan "eth1"
ucidef_add_switch "switch0" "0@eth0" "2:lan:3" "3:lan:2" "4:lan:1"
ucidef_add_static_modem_info "$model" "1-1" "2"
[ "${model:7:2}" = "06" ] && ucidef_set_hwinfo dual_sim mobile \
wifi ethernet || ucidef_set_hwinfo dual_sim mobile wifi ethernet ios
;;
RUT955*)
ucidef_set_led_switch "lan1" "LAN1" "eth1_led" "switch0" "0x10"
ucidef_set_led_switch "lan2" "LAN2" "eth2_led" "switch0" "0x08"
ucidef_set_led_switch "lan3" "LAN3" "eth3_led" "switch0" "0x04"
ucidef_set_led_netdev "wan" "WAN" "wan_led" "eth1"
ucidef_set_interface_wan "eth1"
ucidef_add_switch "switch0" "0@eth0" "2:lan:3" "3:lan:2" "4:lan:1"
ucidef_add_static_modem_info "$model" "1-1.4" "2" "gps_out"
[ "${model:7:2}" = "06" ] && ucidef_set_hwinfo dual_sim usb gps \
mobile wifi ethernet || ucidef_set_hwinfo dual_sim usb gps \
mobile wifi ethernet ios
ucidef_add_serial_capabilities "rs232" \
"200 300 600 1200 1800 2400 4800 9600 19200 38400 57600 115200 \
230400 460800 500000 576000" \
"5 6 7 8"
ucidef_add_serial_capabilities "rs485" \
"300 600 1200 1800 2400 4800 9600 19200 38400 57600 115200 230400 \
460800 500000 576000 921600 1000000 1152000 1500000 2000000 \
2500000 3000000" \
"8"
;;
TRB140*)
ucidef_set_interface_lan "eth0 rndis0"
ucidef_add_trb14x_lte_modem "$model"
ucidef_add_nand_info "$model"
[ "${model:7:1}" = "2" ] && ucidef_set_hwinfo mobile ethernet || \
ucidef_set_hwinfo mobile ethernet ios
;;
TRB141*)
ucidef_set_interface_lan "rndis0"
ucidef_add_trb14x_lte_modem "$model"
ucidef_add_nand_info "$model"
ucidef_set_hwinfo mobile ios
;;
TRB142* |\
TRB145*)
ucidef_set_interface_lan "rndis0"
ucidef_add_trb14x_lte_modem "$model"
ucidef_add_nand_info "$model"
[ "${model:7:1}" = "2" ] && ucidef_set_hwinfo mobile || \
ucidef_set_hwinfo mobile ios
[ "${model:5:1}" = "2" ] && local rs="rs232"
ucidef_add_serial_capabilities "${rs:-rs485}" \
"300 600 1200 2400 4800 9600 19200 38400 57600 115200 460800" \
"5 6 7 8"
[ "${model:5:2}" = "23" -o "${model:5:2}" = "52" ] && \
ucidef_set_release_version "7.1"
;;
TCR100*)
ucidef_set_led_switch "lan" "LAN" "eth1_led" "switch0" "0x10"
ucidef_set_led_netdev "wan" "WAN" "eth2_led" "eth1"
ucidef_set_interfaces_lan_wan "eth0" "eth1"
ucidef_set_interface guest proto static type bridge \
guest 1 _wireless true _dhcp true
ucidef_add_static_modem_info "$model" "1-1" "1"
ucidef_set_hwinfo mobile wifi dual_band_ssid wps ethernet
;;
*)
echo "Unsupported hardware. Network interfaces not intialized"
;;
esac
}
#~ Get model name for RUTX products
model="$(mnf_info --name)" 2>/dev/null
platform="$(cat /proc/device-tree/platform)" 2>/dev/null
board_config_update
setup_json "$model"
ucidef_set_board_platform "$platform"
board_config_flush
exit 0

View file

@ -0,0 +1,71 @@
#!/bin/sh
ath10kcal_die() {
echo "ath10cal: " "$*"
exit 1
}
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 iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \
ath10kcal_die "failed to extract calibration data from $mtd"
}
ensure_correct_art() {
# NOTE(rytis): Hardcoded hashes for 64 KiB file, filled with zeroes (md5b0) and ones (md5b1).
local md5b0="fcd6bcb56c1689fcef28b57c22475bad"
local md5b1="ecb99e6ffea7be1e5419350f725da86b"
local artdir="/dev/mtd12"
local bindir="/usr/share/art/art_rutx.bin"
local md5art="$(md5sum $artdir)"
md5art="${md5art%% *}"
local devicename="$(mnf_info -n)"
devicename="${devicename:0:6}"
if [ "$devicename" != "RUTX08" ] && [ "$devicename" != "RUTX09" ]; then
if [ "$md5art" == "$md5b0" ] || [ "$md5art" == "$md5b1" ] && [ -e "$bindir" ]; then
mtd write $bindir $artdir
fi
else
if [ "$md5art" != "$md5b0" ] && [ "$md5art" != "$md5b1" ]; then
mtd erase $artdir
fi
fi
}
[ -e /lib/firmware/$FIRMWARE ] && exit 0
. /lib/functions.sh
. /lib/functions/system.sh
board=$(board_name)
ensure_correct_art
case "$FIRMWARE" in
"ath10k/pre-cal-ahb-a000000.wifi.bin")
case "$board" in
teltonika,rutx)
ath10kcal_extract "0:ART" 4096 12064
;;
esac
;;
"ath10k/pre-cal-ahb-a800000.wifi.bin")
case "$board" in
teltonika,rutx)
ath10kcal_extract "0:ART" 20480 12064
;;
esac
;;
*)
exit 1
;;
esac

View file

@ -0,0 +1,23 @@
#!/bin/ash
[ "$ACTION" == "add" ] || exit 0
PHYNBR=${DEVPATH##*/phy}
[ -n $PHYNBR ] || exit 0
. /lib/functions.sh
. /lib/functions/system.sh
board=$(board_name)
case "$board" in
teltonika,rutx)
mac_addr=$(mtd_get_mac_binary 0:CONFIG 0)
if [ "$mac_addr" != "ff:ff:ff:ff:ff:ff" ]; then
echo $(macaddr_add $mac_addr $(($PHYNBR + 2)) ) > /sys${DEVPATH}/macaddress
fi
;;
*)
;;
esac

View file

@ -0,0 +1,70 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2011 OpenWrt.org
START=10
STOP=90
uci_apply_defaults() {
. /lib/functions/system.sh
cd /etc/uci-defaults || return 0
files="$(find . -type f | sort)"
[ -z "$files" ] && return 0
mkdir -p /tmp/.uci
for file in $files; do
( . "./$file" ) && rm -f "$file"
done
uci commit
}
boot() {
[ -f /proc/mounts ] || /sbin/mount_root
[ -f /proc/jffs2_bbc ] && echo "S" > /proc/jffs2_bbc
mkdir -p /var/run
mkdir -p /var/log
mkdir -p /var/lock
mkdir -p /var/state
mkdir -p /var/tmp
mkdir -p /tmp/.uci
chmod 0700 /tmp/.uci
touch /var/log/wtmp
touch /var/log/lastlog
mkdir -p /tmp/resolv.conf.d
touch /tmp/resolv.conf.d/resolv.conf.auto
ln -sf /tmp/resolv.conf.d/resolv.conf.auto /tmp/resolv.conf
grep -q debugfs /proc/filesystems && /bin/mount -o noatime -t debugfs debugfs /sys/kernel/debug
grep -q bpf /proc/filesystems && /bin/mount -o nosuid,nodev,noexec,noatime,mode=0700 -t bpf bpffs /sys/fs/bpf
grep -q pstore /proc/filesystems && /bin/mount -o noatime -t pstore pstore /sys/fs/pstore
# mount all entries in fstab
/bin/mount -a &
# /log directory might be created on preinit
# symlink /storage to /log on TRB14X devices
[ -d /storage -a ! -h /log ] && {
rm -rf /log
ln -sf /storage /log
}
# Wifi ---
param=$(/sbin/mnf_info "--name")
router_name=${param:0:6}
if [ $router_name == "RUTX08" ] || [ $router_name == "RUTX09" ]; then
rm /etc/modules.d/ath10k
fi
/bin/board_detect
/sbin/kmodloader
/bin/config_generate
uci_apply_defaults
[ -f "/etc/config/teltonika" ] && rm /etc/config/teltonika
# temporary hack until configd exists
/sbin/reload_config
# leave finished boot script indication
touch /var/run/boot-done
}

View file

@ -0,0 +1,13 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org
START=95
boot() {
mount_root done
rm -f /sysupgrade.tgz && sync
# process user commands
[ -f /etc/rc.local ] && {
sh /etc/rc.local
}
}

View file

@ -0,0 +1,66 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2015 OpenWrt.org
START=94
STOP=10
USE_PROCD=1
load_gpio_switch()
{
local name
local gpio_pin
local value
config_get gpio_pin "$1" gpio_pin
config_get name "$1" name
config_get value "$1" value 0
[ -z "$gpio_pin" ] && {
echo >&2 "Skipping gpio_switch '$name' due to missing gpio_pin"
return 1
}
local gpio_path
if [ -n "$(echo "$gpio_pin" | grep -E "^[0-9]+$")" ]; then
gpio_path="/sys/class/gpio/gpio${gpio_pin}"
# export GPIO pin for access
[ -d "$gpio_path" ] || {
echo "$gpio_pin" >/sys/class/gpio/export
# we need to wait a bit until the GPIO appears
[ -d "$gpio_path" ] || sleep 1
}
# direction attribute only exists if the kernel supports changing the
# direction of a GPIO
if [ -e "${gpio_path}/direction" ]; then
# set the pin to output with high or low pin value
{ [ "$value" = "0" ] && echo "low" || echo "high"; } \
>"$gpio_path/direction"
else
{ [ "$value" = "0" ] && echo "0" || echo "1"; } \
>"$gpio_path/value"
fi
else
gpio_path="/sys/class/gpio/${gpio_pin}"
[ -d "$gpio_path" ] && {
{ [ "$value" = "0" ] && echo "0" || echo "1"; } \
>"$gpio_path/value"
}
fi
}
service_triggers()
{
procd_add_reload_trigger "system"
}
start_service()
{
[ -e /sys/class/gpio/ ] && {
config_load system
config_foreach load_gpio_switch gpio_switch
}
}

View file

@ -0,0 +1,140 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2008 OpenWrt.org
START=96
load_led() {
local name
local sysfs
local trigger
local dev
local ports
local mode
local default
local delayon
local delayoff
local interval
config_get sysfs $1 sysfs
config_get name $1 name "$sysfs"
config_get trigger $1 trigger "none"
config_get dev $1 dev
config_get ports $1 port
config_get mode $1 mode
config_get_bool default $1 default "0"
config_get delayon $1 delayon
config_get delayoff $1 delayoff
config_get interval $1 interval "50"
config_get port_state $1 port_state
config_get delay $1 delay "150"
config_get message $1 message ""
config_get gpio $1 gpio "0"
config_get inverted $1 inverted "0"
if [ "$trigger" = "rssi" ]; then
# handled by rssileds userspace process
return
fi
[ "$trigger" = "usbdev" ] && {
# Backward compatibility: translate to the new trigger
trigger="usbport"
# Translate port of root hub, e.g. 4-1 -> usb4-port1
ports=$(echo "$dev" | sed -n 's/^\([0-9]*\)-\([0-9]*\)$/usb\1-port\2/p')
# Translate port of extra hub, e.g. 2-2.4 -> 2-2-port4
[ -z "$ports" ] && ports=$(echo "$dev" | sed -n 's/\./-port/p')
}
[ -e /sys/class/leds/${sysfs}/brightness ] && {
echo "setting up led ${name}"
printf "%s %s %d\n" \
"$sysfs" \
"$(sed -ne 's/^.*\[\(.*\)\].*$/\1/p' /sys/class/leds/${sysfs}/trigger)" \
"$(cat /sys/class/leds/${sysfs}/brightness)" \
>> /var/run/led.state
[ "$default" = 0 ] &&
echo 0 >/sys/class/leds/${sysfs}/brightness
echo $trigger > /sys/class/leds/${sysfs}/trigger 2> /dev/null
ret="$?"
[ $default = 1 ] &&
cat /sys/class/leds/${sysfs}/max_brightness > /sys/class/leds/${sysfs}/brightness
[ $ret = 0 ] || {
echo >&2 "Skipping trigger '$trigger' for led '$name' due to missing kernel module"
return 1
}
case "$trigger" in
"netdev")
[ -n "$dev" ] && {
echo $dev > /sys/class/leds/${sysfs}/device_name
for m in $mode; do
[ -e "/sys/class/leds/${sysfs}/$m" ] && \
echo 1 > /sys/class/leds/${sysfs}/$m
done
echo $interval > /sys/class/leds/${sysfs}/interval
}
;;
"timer"|"oneshot")
[ -n "$delayon" ] && \
echo $delayon > /sys/class/leds/${sysfs}/delay_on
[ -n "$delayoff" ] && \
echo $delayoff > /sys/class/leds/${sysfs}/delay_off
;;
"usbport")
local p
for p in $ports; do
echo 1 > /sys/class/leds/${sysfs}/ports/$p
done
;;
"port_state")
[ -n "$port_state" ] && \
echo $port_state > /sys/class/leds/${sysfs}/port_state
;;
"gpio")
echo $gpio > /sys/class/leds/${sysfs}/gpio
echo $inverted > /sys/class/leds/${sysfs}/inverted
;;
switch[0-9]*)
local port_mask speed_mask
config_get port_mask $1 port_mask
[ -n "$port_mask" ] && \
echo $port_mask > /sys/class/leds/${sysfs}/port_mask
config_get speed_mask $1 speed_mask
[ -n "$speed_mask" ] && \
echo $speed_mask > /sys/class/leds/${sysfs}/speed_mask
[ -n "$mode" ] && \
echo "$mode" > /sys/class/leds/${sysfs}/mode
;;
esac
}
}
start() {
[ -e /sys/class/leds/ ] && {
[ -s /var/run/led.state ] && {
local led trigger brightness
while read led trigger brightness; do
[ -e "/sys/class/leds/$led/trigger" ] && \
echo "$trigger" > "/sys/class/leds/$led/trigger"
[ -e "/sys/class/leds/$led/brightness" ] && \
echo "$brightness" > "/sys/class/leds/$led/brightness"
done < /var/run/led.state
rm /var/run/led.state
}
config_load system
config_foreach load_led led
}
}

View file

@ -0,0 +1,37 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2021 Teltonika Networks
# Copyright (C) 2022 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
START=2
USE_PROCD=1
PROG=/bin/board_track
NAME=board_track
PIDCOUNT=1
start_service() {
. /lib/functions
[ "$(board_name)" != "teltonika,rutx" ] && return 0
local pid_file="/var/run/${NAME}.${PIDCOUNT}.pid"
procd_open_instance
procd_set_param command "$PROG"
procd_set_param file /etc/config/system
procd_set_param respawn
procd_set_param stdout 1
procd_set_param pidfile $pid_file
procd_close_instance
}
reload_service() {
stop
start
}
service_triggers() {
procd_add_reload_trigger "system"
}

View file

@ -0,0 +1,28 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2021 Teltonika
START=50
STOP=51
USE_PROCD=1
service_triggers()
{
procd_add_reload_trigger "ntpserver"
}
start_service() {
. /lib/functions.sh
local enabled
config_load ntpserver
config_get enabled general enabled "0"
[ "$enabled" -gt 0 ] || return
logger -t "ntpd" "Starting NTP server"
procd_open_instance
procd_set_param respawn 0
procd_set_param command "ntpd" -ln
procd_close_instance
}

View file

@ -0,0 +1,32 @@
#!/bin/sh /etc/rc.common
START=98
ipq40xx_power_auto() {
# change scaling governor as ondemand to enable clock scaling based on system load
echo "performance" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# set scaling min freq as 200 MHz
echo "716000" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
# Change sampling rate for frequency scaling decisions to 1s, from 10 ms
#echo "1000000" > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate
# Change sampling rate for frequency down scaling decision to 10s
#echo 10 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor
# Change the CPU load threshold above which frequency is up-scaled to
# turbo frequency,to 50%
#echo 50 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
}
start() {
. /lib/functions.sh
local board=$(board_name)
case "$board" in
teltonika,rutx | ap-dk01.1-c1 | ap-dk01.1-c2 | ap-dk04.1-c1 | ap-dk04.1-c2 | ap-dk04.1-c3 | \
ap-dk04.1-c4 | ap-dk04.1-c5 | ap-dk05.1-c1 | ap-dk06.1-c1 | ap-dk07.1-c1 | ap-dk07.1-c2 | ap-dk07.1-c3)
ipq40xx_power_auto ;;
esac
}

View file

@ -0,0 +1,46 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org
START=11
apply_defaults() {
local mem="$(awk '/^MemTotal:/ {print $2}' /proc/meminfo)"
local min_free frag_low_thresh frag_high_thresh
if [ "$mem" -gt 65536 ]; then # 128M
min_free=16384
elif [ "$mem" -gt 32768 ]; then # 64M
#Too high for RUT3 device, lets make 2048
#min_free=8192
min_free=2048
else
min_free=1024
frag_low_thresh=393216
frag_high_thresh=524288
fi
sysctl -qw vm.min_free_kbytes="$min_free"
[ "$frag_low_thresh" ] && sysctl -qw \
net.ipv4.ipfrag_low_thresh="$frag_low_thresh" \
net.ipv4.ipfrag_high_thresh="$frag_high_thresh" \
net.ipv6.ip6frag_low_thresh="$frag_low_thresh" \
net.ipv6.ip6frag_high_thresh="$frag_high_thresh" \
net.netfilter.nf_conntrack_frag6_low_thresh="$frag_low_thresh" \
net.netfilter.nf_conntrack_frag6_high_thresh="$frag_high_thresh"
# first set default, then all interfaces to avoid races with appearing interfaces
if [ -d /proc/sys/net/ipv6/conf ]; then
echo 0 > /proc/sys/net/ipv6/conf/default/accept_ra
for iface in /proc/sys/net/ipv6/conf/*/accept_ra; do
echo 0 > "$iface"
done
fi
}
start() {
apply_defaults
for CONF in /etc/sysctl.d/*.conf /etc/sysctl.conf; do
[ -f "$CONF" ] && sysctl -e -p "$CONF" >&-
done
}

View file

@ -0,0 +1,34 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2013-2014 OpenWrt.org
START=00
STOP=90
RTC_DEV=/dev/rtc0
HWCLOCK=/sbin/hwclock
boot() {
# start && exit 0
local maxtime="$(maxtime)"
local curtime="$(date +%s)"
[ $curtime -lt $maxtime ] && date -s @$maxtime
}
start() {
boot
}
stop() {
[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -w -u -f $RTC_DEV && \
logger -t sysfixtime "saved '$(date)' to $RTC_DEV"
}
maxtime() {
local file newest
for file in $( find /etc -type f ) ; do
[ -z "$newest" -o "$newest" -ot "$file" ] && newest=$file
done
[ "$newest" ] && date -r "$newest" +%s
}

View file

@ -0,0 +1,45 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2014 OpenWrt.org
START=10
USE_PROCD=1
validate_system_section() {
uci_load_validate system system "$1" "$2" \
'hostname:string:%%NAME%%' \
'conloglevel:uinteger' \
'buffersize:uinteger' \
'timezone:string:UTC' \
'zonename:string'
}
system_config() {
[ "$2" = 0 ] || {
echo "validation failed"
return 1
}
echo "$hostname" > /proc/sys/kernel/hostname
[ -z "$conloglevel" -a -z "$buffersize" ] || dmesg ${conloglevel:+-n $conloglevel} ${buffersize:+-s $buffersize}
echo "$timezone" > /tmp/TZ
[ -n "$zonename" ] && [ -f "/usr/share/zoneinfo/${zonename// /_}" ] \
&& ln -sf "/usr/share/zoneinfo/${zonename// /_}" /tmp/localtime \
&& rm -f /tmp/TZ
# apply timezone to kernel
hwclock -u --systz
}
reload_service() {
config_load system
config_foreach validate_system_section system system_config
}
service_triggers() {
procd_add_reload_trigger "system"
procd_add_validation validate_system_section
}
start_service() {
reload_service
}

View file

@ -0,0 +1,13 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org
STOP=90
restart() {
:
}
stop() {
sync
/bin/umount -a -d -r
}

View file

@ -0,0 +1,26 @@
#!/bin/sh
SECTION="hwinfo"
CONFIG="hwinfo"
get_hw_info() {
param=$(/sbin/mnf_info "--name")
[ -n "$param" -a ${#param} == 12 ] && uci set "system"."@system[0]"."device_code"=$param
hostname=${param:0:6}
[ -n "$hostname" -a ${#hostname} == 6 -a -z "$(uci -q get system.@system[0].hostname)" ] && uci set "system"."@system[0]"."hostname"=OpenMPTCProuter
routername=${param:0:6}
[ -n "$routername" -a ${#routername} == 6 -a -z "$(uci -q get system.@system[0].routername)" ] && uci set "system"."@system[0]"."routername"=$routername
version=$(cat /etc/version)
[ -n "$version" ] && uci set "system"."@system[0]"."device_fw_version"=$version
uci commit "system"
}
# get device information
echo "Reading device information"
get_hw_info
exit 0

View file

@ -0,0 +1,34 @@
#!/bin/sh
. /lib/functions.sh
move_network(){
local section=$1
local device ports vlan
config_get ports "$section" ports
config_get device "$section" device
config_get vlan "$section" vlan
[ "$vlan" -eq 1 ] && {
if list_contains "ports" "0t" && list_contains "ports" "5"; then
uci_set network "$section" ports "${ports/0t/0}"
uci_set network "$section" vlan "2"
uci_remove network "$section" vid
fi
}
[ "$vlan" -eq 2 ] && {
if list_contains ports "0t"; then
echo "Contains"
uci_set network "$section" ports "${ports/0t/0}"
uci_set network "$section" vlan "1"
uci_remove network "$section" vid
fi
}
}
config_load network
config_foreach move_network switch_vlan
uci_commit network
exit 0

View file

@ -0,0 +1,40 @@
. /usr/share/libubox/jshn.sh
# when device contains 2 internal modems, this function will return '2' if
# selected modem(inc_id) is builtin and primary.
# And if it's only builtin, then '1'
is_builtin_modem() {
local inc_id="$1"
local modem modems id builtin primary
json_init
json_load_file "/etc/board.json"
json_get_keys modems modems
json_select modems
for modem in $modems; do
json_select "$modem"
json_get_vars id builtin primary
[ "$id" = "$inc_id" ] && {
[ -n "$builtin" ] && {
[ -n "$primary" ] && {
echo 2
return
}
echo 1
return
}
echo 0
return
}
json_select ..
done
echo 0
}

View file

@ -0,0 +1,196 @@
#!/bin/sh
. /lib/functions.sh
. /usr/share/libubox/jshn.sh
CFG_PATH="/etc/config/"
get_section_name() {
local ___var="$1"
[ "$#" -ge 1 ] && shift
local ___type="$1"
[ "$#" -ge 1 ] && shift
local section cfgtype
[ -z "$CONFIG_SECTIONS" ] && return 0
for section in ${CONFIG_SECTIONS}; do
config_get cfgtype "$section" TYPE
[ -n "$___type" -a "x$cfgtype" != "x$___type" ] && continue
eval export "${___var}=\${section}"
return 0
done
}
_set_option() {
local option="$1"
local value="$2"
uci_set "$_NEW_CONFIG" "$_NEW_SEC_NAME" "$option" "$value"
}
_set_list_option() {
local option="$1"
local value="$2"
for element in $value; do
uci_add_list "$_NEW_CONFIG" "$_NEW_SEC_NAME" "$option" "$element"
done
}
_del_uci_element() {
local section="$1"
local option="$2"
uci_remove "$_OLD_CONFIG" "$section" "$option"
}
_option_cond_cb() {
local value=$3
json_select $2
json_get_var old 1
json_get_var new 2
[ "$old" = "$value" ] && _COND_VALUE="$new"
json_select ..
}
_parse_condition(){
local value="$1"
_COND_VALUE=
json_for_each_item _option_cond_cb "if" "$value"
}
_option_rule_cb(){
local rule="$1"
local option="$2"
local value
[ -n "$rule" ] || return 0
json_select "$option"
json_get_vars new_name "if" default cb type
if [ -n "$cb" ]; then
eval "$cb \"\$option\" \"\$_OLD_SEC_NAME\" \"\$_NEW_SEC_NAME\""
[ "$?" -eq 0 ] && {
json_select ..
return 0
}
value="$_OPTION_VALUE"
else
config_get value $_OLD_SEC_NAME "$option" "$default"
fi
[ -n "$if" ] && {
_parse_condition "$value"
value="${_COND_VALUE:-${value:-$default}}"
}
if [ -n "$type" -a "$type" = "list" ]; then
_set_list_option "${new_name:-$option}" "$value"
else
_set_option "${new_name:-$option}" "$value"
fi
json_select ..
}
_init_section() {
local sec_t
json_get_vars old_name new_name new_type old_type
[ -n "$old_name" -o -n "$old_type" ] || return 1
if [ -z "$old_name" ]; then
get_section_name _OLD_SEC_NAME "$old_type"
else
_OLD_SEC_NAME=$old_name
fi
_NEW_SEC_NAME=$new_name
_OLD_SEC_TYPE=$old_type
_NEW_SEC_TYPE=${new_type:-$old_type}
[ -n "$_NEW_SEC_TYPE" ] || \
eval "_NEW_SEC_TYPE=\$CONFIG_${_OLD_SEC_NAME}_TYPE"
if [ -n "$_NEW_SEC_NAME" ]; then
uci set "$_NEW_CONFIG"."$_NEW_SEC_NAME"="$_NEW_SEC_TYPE"
else
_NEW_SEC_NAME="$(uci -q add "$_NEW_CONFIG" "$_NEW_SEC_TYPE")"
fi
[ -n "$_NEW_SEC_NAME" ] || return 1
}
_section_rule_cb(){
local rule="$1"
local section="$2"
local value
[ -n "$rule" ] || return 0
json_select "$section"
json_get_vars cb old_name new_name new_type old_type remove
[ -n "$cb" ] && {
eval "$cb \"\$old_name\" \"\$new_name\" \"\$old_type\" \"\$new_type\""
[ "$?" -eq 0 ] && {
json_select ..
return 0
}
}
_init_section
[ $? -ne 0 ] && {
logger -t "Migration" "Unable to init section"
json_select ..
return 1
}
json_for_each_item _option_rule_cb options
json_select ..
[ -n "$remove" ] && {
_del_uci_element "$old_name"
uci_commit "$_OLD_CONFIG"
}
}
_init_config() {
json_select config
json_get_vars old_name new_name
[ -n "$old_name" ] || return 1
[ -f "$CFG_PATH$old_name" ] || return 1
[ -f "$CFG_PATH$new_name" ] || touch $CFG_PATH$new_name
config_load "$old_name"
_NEW_CONFIG="${new_name:-$old_name}"
_OLD_CONFIG="$old_name"
json_select ..
}
migrate() {
local remove
local json_file="$1"
[ -f "$json_file" ] || return 0
json_init
json_load_file "$json_file"
json_select
_init_config
[ $? -ne 0 ] && {
logger -t "Migration" "Unable to load config"
return 1
}
json_for_each_item _section_rule_cb sections
uci_commit "$_NEW_CONFIG"
json_get_vars remove
[ -n "$remove" ] && rm "$CFG_PATH$_OLD_CONFIG"
}

View file

@ -0,0 +1,313 @@
# 1: destination variable
# 2: interface
# 3: path
# 4: separator
# 5: limit
__network_ifstatus() {
local __tmp
[ -z "$__NETWORK_CACHE" ] && {
__tmp="$(ubus call network.interface dump 2>&1)"
case "$?" in
4) : ;;
0) export __NETWORK_CACHE="$__tmp" ;;
*) echo "$__tmp" >&2 ;;
esac
}
__tmp="$(jsonfilter ${4:+-F "$4"} ${5:+-l "$5"} -s "${__NETWORK_CACHE:-{}}" -e "$1=@.interface${2:+[@.interface='$2']}$3")"
[ -z "$__tmp" ] && \
unset "$1" && \
return 1
eval "$__tmp"
}
# determine first IPv4 address of given logical interface
# 1: destination variable
# 2: interface
network_get_ipaddr() {
__network_ifstatus "$1" "$2" "['ipv4-address'][0].address";
}
# determine first IPv6 address of given logical interface
# 1: destination variable
# 2: interface
network_get_ipaddr6() {
__network_ifstatus "$1" "$2" "['ipv6-address'][0].address" || \
__network_ifstatus "$1" "$2" "['ipv6-prefix-assignment'][0]['local-address'].address" || \
return 1
}
# determine first IPv4 subnet of given logical interface
# 1: destination variable
# 2: interface
network_get_subnet() {
__network_ifstatus "$1" "$2" "['ipv4-address'][0]['address','mask']" "/"
}
# determine first IPv6 subnet of given logical interface
# 1: destination variable
# 2: interface
network_get_subnet6() {
local __nets __addr
if network_get_subnets6 __nets "$2"; then
# Attempt to return first non-fe80::/10, non-fc::/7 range
for __addr in $__nets; do
case "$__addr" in fe[8ab]?:*|f[cd]??:*)
continue
esac
export "$1=$__addr"
return 0
done
# Attempt to return first non-fe80::/10 range
for __addr in $__nets; do
case "$__addr" in fe[8ab]?:*)
continue
esac
export "$1=$__addr"
return 0
done
# Return first item
for __addr in $__nets; do
export "$1=$__addr"
return 0
done
fi
unset "$1"
return 1
}
# determine first IPv6 prefix of given logical interface
# 1: destination variable
# 2: interface
network_get_prefix6() {
__network_ifstatus "$1" "$2" "['ipv6-prefix'][0]['address','mask']" "/"
}
# determine all IPv4 addresses of given logical interface
# 1: destination variable
# 2: interface
network_get_ipaddrs() {
__network_ifstatus "$1" "$2" "['ipv4-address'][*].address"
}
# determine all IPv6 addresses of given logical interface
# 1: destination variable
# 2: interface
network_get_ipaddrs6() {
local __addr
local __list=""
if __network_ifstatus "__addr" "$2" "['ipv6-address'][*].address"; then
for __addr in $__addr; do
__list="${__list:+$__list }${__addr}"
done
fi
if __network_ifstatus "__addr" "$2" "['ipv6-prefix-assignment'][*]['local-address'].address"; then
for __addr in $__addr; do
__list="${__list:+$__list }${__addr}"
done
fi
if [ -n "$__list" ]; then
export "$1=$__list"
return 0
fi
unset "$1"
return 1
}
# determine all IP addresses of given logical interface
# 1: destination variable
# 2: interface
network_get_ipaddrs_all() {
local __addr __addr6
network_get_ipaddrs __addr "$2"
network_get_ipaddrs6 __addr6 "$2"
if [ -n "$__addr" -o -n "$__addr6" ]; then
export "$1=${__addr:+$__addr }$__addr6"
return 0
fi
unset "$1"
return 1
}
# determine all IPv4 subnets of given logical interface
# 1: destination variable
# 2: interface
network_get_subnets() {
__network_ifstatus "$1" "$2" "['ipv4-address'][*]['address','mask']" "/ "
}
# determine all IPv6 subnets of given logical interface
# 1: destination variable
# 2: interface
network_get_subnets6() {
local __addr __mask
local __list=""
if __network_ifstatus "__addr" "$2" "['ipv6-address'][*]['address','mask']" "/ "; then
for __addr in $__addr; do
__list="${__list:+$__list }${__addr}"
done
fi
if __network_ifstatus "__addr" "$2" "['ipv6-prefix-assignment'][*]['local-address'].address" && \
__network_ifstatus "__mask" "$2" "['ipv6-prefix-assignment'][*].mask"; then
for __addr in $__addr; do
__list="${__list:+$__list }${__addr}/${__mask%% *}"
__mask="${__mask#* }"
done
fi
if [ -n "$__list" ]; then
export "$1=$__list"
return 0
fi
unset "$1"
return 1
}
# determine all IPv6 prefixes of given logical interface
# 1: destination variable
# 2: interface
network_get_prefixes6() {
__network_ifstatus "$1" "$2" "['ipv6-prefix'][*]['address','mask']" "/ "
}
# determine IPv4 gateway of given logical interface
# 1: destination variable
# 2: interface
# 3: consider inactive gateway if "true" (optional)
network_get_gateway() {
__network_ifstatus "$1" "$2" ".route[@.target='0.0.0.0' && !@.table].nexthop" "" 1 && \
return 0
[ "$3" = 1 -o "$3" = "true" ] && \
__network_ifstatus "$1" "$2" ".inactive.route[@.target='0.0.0.0' && !@.table].nexthop" "" 1
}
# determine IPv6 gateway of given logical interface
# 1: destination variable
# 2: interface
# 3: consider inactive gateway if "true" (optional)
network_get_gateway6() {
__network_ifstatus "$1" "$2" ".route[@.target='::' && !@.table].nexthop" "" 1 && \
return 0
[ "$3" = 1 -o "$3" = "true" ] && \
__network_ifstatus "$1" "$2" ".inactive.route[@.target='::' && !@.table].nexthop" "" 1
}
# determine the DNS servers of the given logical interface
# 1: destination variable
# 2: interface
# 3: consider inactive servers if "true" (optional)
network_get_dnsserver() {
__network_ifstatus "$1" "$2" "['dns-server'][*]" && return 0
[ "$3" = 1 -o "$3" = "true" ] && \
__network_ifstatus "$1" "$2" ".inactive['dns-server'][*]"
}
# determine the domains of the given logical interface
# 1: destination variable
# 2: interface
# 3: consider inactive domains if "true" (optional)
network_get_dnssearch() {
__network_ifstatus "$1" "$2" "['dns-search'][*]" && return 0
[ "$3" = 1 -o "$3" = "true" ] && \
__network_ifstatus "$1" "$2" ".inactive['dns-search'][*]"
}
# 1: destination variable
# 2: addr
# 3: inactive
# 4: limit
__network_wan()
{
limit=1
[ -n "$4" ] && limit="$4"
__network_ifstatus "$1" "" \
"[@.route[@.target='$2' && !@.table]].interface" "" $limit && \
return 0
[ "$3" = 1 -o "$3" = "true" ] && \
__network_ifstatus "$1" "" \
"[@.inactive.route[@.target='$2' && !@.table]].interface" "" $limit
}
# find the logical interface which holds the current IPv4 default route
# 1: destination variable
# 2: consider inactive default routes if "true" (optional)
network_find_wan() { __network_wan "$1" "0.0.0.0" "$2" "$3"; }
# find the logical interface which holds the current IPv6 default route
# 1: destination variable
# 2: consider inactive default routes if "true" (optional)
network_find_wan6() { __network_wan "$1" "::" "$2"; }
# test whether the given logical interface is running
# 1: interface
network_is_up()
{
local __up
__network_ifstatus "__up" "$1" ".up" && [ "$__up" = 1 ]
}
# determine the protocol of the given logical interface
# 1: destination variable
# 2: interface
network_get_protocol() { __network_ifstatus "$1" "$2" ".proto"; }
# determine the uptime of the given logical interface
# 1: destination variable
# 2: interface
network_get_uptime() { __network_ifstatus "$1" "$2" ".uptime"; }
# determine the metric of the given logical interface
# 1: destination variable
# 2: interface
network_get_metric() { __network_ifstatus "$1" "$2" ".metric"; }
# determine the layer 3 linux network device of the given logical interface
# 1: destination variable
# 2: interface
network_get_device() { __network_ifstatus "$1" "$2" ".l3_device"; }
# determine the layer 2 linux network device of the given logical interface
# 1: destination variable
# 2: interface
network_get_physdev() { __network_ifstatus "$1" "$2" ".device"; }
# defer netifd actions on the given linux network device
# 1: device name
network_defer_device()
{
ubus call network.device set_state \
"$(printf '{ "name": "%s", "defer": true }' "$1")" 2>/dev/null
}
# continue netifd actions on the given linux network device
# 1: device name
network_ready_device()
{
ubus call network.device set_state \
"$(printf '{ "name": "%s", "defer": false }' "$1")" 2>/dev/null
}
# flush the internal value cache to force re-reading values from ubus
network_flush_cache() { unset __NETWORK_CACHE; }

View file

@ -0,0 +1,284 @@
#!/bin/ash
. /lib/functions.sh
. /usr/share/libubox/jshn.sh
ucidef_add_nand_info() {
local model="$1"
model=${model:0:7}
json_select_object nand
case "$model" in
TRB1412)
json_add_int blocksize 128
json_add_int pagesize 2048
json_add_int subpagesize 2048
;;
TRB1422 |\
TRB1423 |\
TRB1452)
json_add_int blocksize 256
json_add_int pagesize 4096
json_add_int subpagesize 4096
;;
TRB14*0)
json_add_int blocksize 128
json_add_int pagesize 2048
json_add_int subpagesize 2048
;;
TRB14*1)
json_add_int blocksize 256
json_add_int pagesize 4096
json_add_int subpagesize 4096
;;
esac
json_select ..
}
ucidef_add_static_modem_info() {
#Parameters: model usb_id sim_count other_params
local model usb_id count
local modem_counter=0
local sim_count=1
model="$1"
usb_id="$2"
[ -n "$3" ] && sim_count="$3"
json_get_keys count modems
[ -n "$count" ] && modem_counter="$(echo "$count" | wc -w)"
json_select_array "modems"
json_add_object
json_add_string id "$usb_id"
json_add_string num "$((modem_counter + 1))"
json_add_boolean builtin 1
json_add_int simcount "$sim_count"
for i in "$@"; do
case "$i" in
primary)
json_add_boolean primary 1
;;
gps_out)
json_add_boolean gps_out 1
;;
esac
done
json_close_object
json_select ..
}
ucidef_add_trb14x_lte_modem() {
print_array() {
json_add_array $1
for element in $2
do
json_add_string "" "$(echo $element)"
done
json_close_array
}
#Parameters: model primary
local model vendor product boudrate gps type desc control region modem_counter
modem_counter=1
json_select_array "modems"
model="$1"
model=${model:0:7}
case "$model" in
TRB1422)
vendor=05c6
product=9215
;;
TRB1412 |\
TRB1423 |\
TRB1452 |\
TRB140*)
vendor=2c7c
product=0125
;;
TRB14*)
vendor=2c7c
product=0121
;;
esac
case "$model" in
TRB1412 |\
TRB14*0)
region="EU"
[ "$product" = "0121" ] && {
lte_bands="1 3 7 8 20 28"
trysg_bands="wcdma_2100 wcdma_900"
dug_bands="gsm_1800 gsm_900"
}
[ "$product" = "0125" ] && {
lte_bands="1 3 7 8 20 28 38 40 41"
trysg_bands="wcdma_2100 wcdma_900"
dug_bands="gsm_1800 gsm_900"
}
;;
TRB1422)
region="CE"
lte_bands="1 3 5 8 34 38 39 40 41"
trysg_bands="bc-0-a-system bc-0-b-system wcdma_2100 wcdma_900"
dug_bands="gsm_1800 gsm_900"
;;
TRB1423 |\
TRB1452 |\
TRB14*1)
region="AU"
[ "$product" = "0121" ] && {
lte_bands="1 2 3 4 5 7 8 28 40"
trysg_bands="wcdma_2100 wcdma_1900 wcdma_900 wcdma_850"
dug_bands="gsm_1800 gsm_900 gsm_850 gsm_1900"
}
[ "$product" = "0125" ] && {
lte_bands="1 2 3 4 5 7 8 28 40"
trysg_bands="wcdma_2100 wcdma_1900 wcdma_900 wcdma_850"
dug_bands="gsm_1800 gsm_900 gsm_850 gsm_1900"
}
;;
esac
[ -f "/lib/network/wwan/$vendor:$product" ] && {
devicename="3-1"
json_set_namespace defaults old_cb
json_load "$(cat /lib/network/wwan/$vendor:$product)"
json_get_vars gps boudrate type desc control stop_bits
json_set_namespace $old_cb
[ "${devicename%%:*}" = "$devicename" ] && {
json_add_object
json_add_string id "$devicename"
json_add_string num "$modem_counter"
json_add_string vendor "$vendor"
json_add_string product "$product"
json_add_string stop_bits "$stop_bits"
json_add_string gps "$gps"
json_add_string boudrate "$boudrate"
json_add_string type "$type"
json_add_string desc "$desc"
json_add_string region "$region"
json_add_string control "$control"
json_add_int simcount 1
json_add_boolean builtin 1
[ -n "$2" ] && json_add_boolean primary 1
json_add_object service_modes
[ -z "$lte_bands" ] || print_array "4G" "$lte_bands"
[ -z "$trysg_bands" ] || print_array "3G" "$trysg_bands"
[ -z "$dug_bands" ] || print_array "2G" "$dug_bands"
json_close_object
json_close_object
}
}
json_select ..
}
ucidef_add_serial_capabilities() {
json_select_array serial
json_add_object
[ -n "$1" ] && {
json_select_array devices
for d in $1; do
json_add_string "" $d
done
json_select ..
}
json_select_array bauds
for b in $2; do
json_add_string "" $b
done
json_select ..
json_select_array data_bits
for n in $3; do
json_add_string "" $n
done
json_select ..
json_close_object
json_select ..
}
ucidef_set_hwinfo() {
local function
local dual_sim=0
local wifi=0
local dual_band_ssid=0
local wps=0
local mobile=0
local gps=0
local usb=0
local bluetooth=0
local ethernet=0
local sfp_port=0
local ios=0
for function in "$@"; do
case "$function" in
dual_sim)
dual_sim=1
;;
wifi)
wifi=1
;;
dual_band_ssid)
dual_band_ssid=1
;;
wps)
wps=1
;;
mobile)
mobile=1
;;
gps)
gps=1
;;
usb)
usb=1
;;
bluetooth)
bluetooth=1
;;
ethernet)
ethernet=1
;;
sfp_port)
sfp_port=1
;;
ios)
ios=1
;;
at_sim)
at_sim=1
;;
esac
done
json_select_object hwinfo
json_add_boolean dual_sim "$dual_sim"
json_add_boolean usb "$usb"
json_add_boolean bluetooth "$bluetooth"
json_add_boolean wifi "$wifi"
json_add_boolean dual_band_ssid "$dual_band_ssid"
json_add_boolean wps "$wps"
json_add_boolean mobile "$mobile"
json_add_boolean gps "$gps"
json_add_boolean ethernet "$ethernet"
json_add_boolean sfp_port "$sfp_port"
json_add_boolean ios "$ios"
json_add_boolean at_sim "$at_sim"
json_select ..
}
ucidef_set_release_version() {
json_add_string release_version "$1"
}

View file

@ -0,0 +1,10 @@
#!/bin/sh
. /usr/share/libubox/jshn.sh
is_ios_enabled() {
local ios
json_load_file "/etc/board.json" && \
json_select hwinfo && \
json_get_var ios ios && [ "$ios" = "1" ]
}

View file

@ -0,0 +1,626 @@
#!/bin/ash
. /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 network=$1; shift
[ -z "$network" ] && return
json_select_object network
json_select_object "$network"
while [ -n "$1" ]; do
local opt=$1; shift
local val=$1; shift
[ -n "$opt" -a -n "$val" ] || break
case "$val" in
true) json_add_boolean "$opt" "1" ;;
false) json_add_boolean "$opt" "0" ;;
*) json_add_string "$opt" "$val" ;;
esac
done
if ! json_is_a proto string; then
case "$network" in
lan) json_add_string proto static ;;
wan) json_add_string proto dhcp ;;
*) json_add_string proto none ;;
esac
fi
json_select ..
json_select ..
}
ucidef_set_board_id() {
json_select_object model
json_add_string id "$1"
json_select ..
}
ucidef_set_board_platform() {
json_select_object model
json_add_string platform "$1"
json_select ..
}
ucidef_set_model_name() {
json_select_object model
json_add_string name "$1"
json_select ..
}
ucidef_set_compat_version() {
json_select_object system
json_add_string compat_version "${1:-1.0}"
json_select ..
}
ucidef_set_interface_lan() {
ucidef_set_interface "lan" ifname "$1" proto "${2:-static}"
}
ucidef_set_interface_wan() {
ucidef_set_interface "wan" ifname "$1" proto "${2:-dhcp}"
}
ucidef_set_interfaces_lan_wan() {
local lan_if="$1"
local wan_if="$2"
ucidef_set_interface_lan "$lan_if"
ucidef_set_interface_wan "$wan_if"
}
_ucidef_add_switch_port() {
# inherited: $num $device $need_tag $want_untag $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 "$want_untag" ] && json_add_boolean want_untag "$want_untag"
[ -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 want_untag 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 want_untag
json_select ..
json_select ..
if [ ${need_tag:-0} -eq 1 -o ${want_untag:-0} -ne 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 ..
json_select ..
ucidef_set_interface "$role" ifname "$devices"
done
}
ucidef_set_ar8xxx_switch_mib() {
local name="$1"
local type="$2"
local interval="$3"
json_select_object switch
json_select_object "$name"
json_add_int ar8xxx_mib_type $type
json_add_int ar8xxx_mib_poll_interval $interval
json_select ..
json_select ..
}
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
want_untag=0
[ "${num%t}" != "$num" ] && {
num="${num%t}"
need_tag=1
}
[ "${num%u}" != "$num" ] && {
num="${num%u}"
want_untag=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 want_untag
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"
ucidef_set_interface "$network" macaddr "$macaddr"
}
ucidef_add_atm_bridge() {
local vpi="$1"
local vci="$2"
local encaps="$3"
local payload="$4"
local nameprefix="$5"
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_add_string nameprefix "$nameprefix"
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_ataport() {
_ucidef_set_led_trigger "$1" "$2" "$3" ata"$4"
}
_ucidef_set_led_common() {
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"
}
ucidef_set_led_default() {
local default="$4"
_ucidef_set_led_common "$1" "$2" "$3"
json_add_string default "$default"
json_select ..
json_select ..
}
ucidef_set_led_gpio() {
local gpio="$4"
local inverted="$5"
_ucidef_set_led_common "$1" "$2" "$3"
json_add_string trigger "$trigger"
json_add_string type gpio
json_add_int gpio "$gpio"
json_add_boolean inverted "$inverted"
json_select ..
json_select ..
}
ucidef_set_led_ide() {
_ucidef_set_led_trigger "$1" "$2" "$3" disk-activity
}
ucidef_set_led_netdev() {
local dev="$4"
local mode="${5:-link tx rx}"
_ucidef_set_led_common "$1" "$2" "$3"
json_add_string type netdev
json_add_string device "$dev"
json_add_string mode "$mode"
json_select ..
json_select ..
}
ucidef_set_led_oneshot() {
_ucidef_set_led_timer $1 $2 $3 "oneshot" $4 $5
}
ucidef_set_led_portstate() {
local port_state="$4"
_ucidef_set_led_common "$1" "$2" "$3"
json_add_string trigger port_state
json_add_string type portstate
json_add_string port_state "$port_state"
json_select ..
json_select ..
}
ucidef_set_led_rssi() {
local iface="$4"
local minq="$5"
local maxq="$6"
local offset="${7:-0}"
local factor="${8:-1}"
_ucidef_set_led_common "$1" "$2" "$3"
json_add_string type rssi
json_add_string name "$name"
json_add_string iface "$iface"
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_led_switch() {
local trigger_name="$4"
local port_mask="$5"
local speed_mask="$6"
local mode="$7"
_ucidef_set_led_common "$1" "$2" "$3"
json_add_string trigger "$trigger_name"
json_add_string type switch
json_add_string mode "$mode"
json_add_string port_mask "$port_mask"
json_add_string speed_mask "$speed_mask"
json_select ..
json_select ..
}
_ucidef_set_led_timer() {
local trigger_name="$4"
local delayon="$5"
local delayoff="$6"
_ucidef_set_led_common "$1" "$2" "$3"
json_add_string type "$trigger_name"
json_add_string trigger "$trigger_name"
json_add_int delayon "$delayon"
json_add_int delayoff "$delayoff"
json_select ..
json_select ..
}
ucidef_set_led_timer() {
_ucidef_set_led_timer $1 $2 $3 "timer" $4 $5
}
_ucidef_set_led_trigger() {
local trigger_name="$4"
_ucidef_set_led_common "$1" "$2" "$3"
json_add_string trigger "$trigger_name"
json_select ..
json_select ..
}
ucidef_set_led_usbdev() {
local dev="$4"
_ucidef_set_led_common "$1" "$2" "$3"
json_add_string type usb
json_add_string device "$dev"
json_select ..
json_select ..
}
ucidef_set_led_usbhost() {
_ucidef_set_led_trigger "$1" "$2" "$3" usb-host
}
ucidef_set_led_usbport() {
local obj="$1"
local name="$2"
local sysfs="$3"
shift
shift
shift
_ucidef_set_led_common "$obj" "$name" "$sysfs"
json_add_string type usbport
json_select_array ports
for port in "$@"; do
json_add_string port "$port"
done
json_select ..
json_select ..
json_select ..
}
ucidef_set_led_wlan() {
_ucidef_set_led_trigger "$1" "$2" "$3" "$4"
}
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 ..
}
ucidef_set_hostname() {
local hostname="$1"
json_select_object system
json_add_string hostname "$hostname"
json_select ..
}
ucidef_set_ntpserver() {
local server
json_select_object system
json_select_array ntpserver
for server in "$@"; do
json_add_string "" "$server"
done
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 -o ${CFG}
}

View file

@ -0,0 +1,20 @@
set_state() {
local label="$1"
local disable
[ -e "/sys/class/gpio/${label}_power/value" ] || return
config_get disable ${label} disable
[ "${disable}" -eq 1 ] && \
/sbin/mctl -s -m "${label}" || \
/sbin/mctl -p -m "${label}"
}
do_power_modem() {
/sbin/mctl -p || {
config_load system
config_foreach set_state mctl
}
}
boot_hook_add preinit_main do_power_modem

View file

@ -0,0 +1,383 @@
find_mmc_part() {
local DEVNAME PARTNAME
if grep -q "$1" /proc/mtd; then
echo "" && return 0
fi
for DEVNAME in /sys/block/mmcblk0/mmcblk*p*; do
PARTNAME=$(grep PARTNAME ${DEVNAME}/uevent | cut -f2 -d'=')
[ "$PARTNAME" = "$1" ] && echo "/dev/$(basename $DEVNAME)" && return 0
done
}
get_full_section_name() {
local img=$1
local sec=$2
dumpimage -l ${img} | grep "^ Image.*(${sec})" | \
sed 's,^ Image.*(\(.*\)),\1,'
}
image_contains() {
local img=$1
local sec=$2
dumpimage -l ${img} | grep -q "^ Image.*(${sec}.*)" || return 1
}
print_sections() {
local img=$1
dumpimage -l ${img} | awk '/^ Image.*(.*)/ { print gensub(/Image .* \((.*)\)/,"\\1", $0) }'
}
image_has_mandatory_section() {
local img=$1
local mandatory_sections=$2
for sec in ${mandatory_sections}; do
image_contains $img ${sec} || {\
return 1
}
done
}
image_demux() {
local img=$1
for sec in $(print_sections ${img}); do
local fullname=$(get_full_section_name ${img} ${sec})
local position=$(dumpimage -l ${img} | grep "(${fullname})" | awk '{print $2}')
dumpimage -i ${img} -o /tmp/${fullname}.bin -T "flat_dt" -p "${position}" ${fullname} > /dev/null || { \
echo "Error while extracting \"${sec}\" from ${img}"
return 1
}
done
return 0
}
image_is_FIT() {
if ! dumpimage -l $1 > /dev/null 2>&1; then
echo "$1 is not a valid FIT image"
return 1
fi
return 0
}
switch_layout() {
local layout=$1
local boot_layout=`find / -name boot_layout`
# Layout switching is only required as the boot images (up to u-boot)
# use 512 user data bytes per code word, whereas Linux uses 516 bytes.
# It's only applicable for NAND flash. So let's return if we don't have
# one.
[ -n "$boot_layout" ] || return
case "${layout}" in
boot|1) echo 1 > $boot_layout;;
linux|0) echo 0 > $boot_layout;;
*) echo "Unknown layout \"${layout}\"";;
esac
}
do_flash_mtd() {
local bin=$1
local mtdname=$2
local append=""
local mtdpart=$(grep "\"${mtdname}\"" /proc/mtd | awk -F: '{print $1}')
local pgsz=$(cat /sys/class/mtd/${mtdpart}/writesize)
[ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 -a "$2" == "rootfs" ] && append="-j $CONF_TAR"
dd if=/tmp/${bin}.bin bs=${pgsz} conv=sync | mtd $append -e "/dev/${mtdpart}" write - "/dev/${mtdpart}"
}
do_flash_emmc() {
local bin=$1
local emmcblock=$2
dd if=/dev/zero of=${emmcblock}
dd if=/tmp/${bin}.bin of=${emmcblock}
}
do_flash_partition() {
local bin=$1
local mtdname=$2
local emmcblock="$(find_mmc_part "$mtdname")"
if [ -e "$emmcblock" ]; then
do_flash_emmc $bin $emmcblock
else
do_flash_mtd $bin $mtdname
fi
}
do_flash_bootconfig() {
local bin=$1
local mtdname=$2
# Fail safe upgrade
if [ -f /proc/boot_info/getbinary_${bin} ]; then
cat /proc/boot_info/getbinary_${bin} > /tmp/${bin}.bin
do_flash_partition $bin $mtdname
fi
}
do_flash_failsafe_partition() {
local bin=$1
local mtdname=$2
local emmcblock
local primaryboot
# Fail safe upgrade
[ -f /proc/boot_info/$mtdname/upgradepartition ] && {
default_mtd=$mtdname
mtdname=$(cat /proc/boot_info/$mtdname/upgradepartition)
primaryboot=$(cat /proc/boot_info/$default_mtd/primaryboot)
if [ $primaryboot -eq 0 ]; then
echo 1 > /proc/boot_info/$default_mtd/primaryboot
else
echo 0 > /proc/boot_info/$default_mtd/primaryboot
fi
}
emmcblock="$(find_mmc_part "$mtdname")"
if [ -e "$emmcblock" ]; then
do_flash_emmc $bin $emmcblock
else
do_flash_mtd $bin $mtdname
fi
}
do_flash_ubi() {
local bin=$1
local mtdname=$2
local mtdpart
local primaryboot
mtdpart=$(grep "\"${mtdname}\"" /proc/mtd | awk -F: '{print $1}')
ubidetach -p /dev/${mtdpart}
# Fail safe upgrade
[ -f /proc/boot_info/$mtdname/upgradepartition ] && {
primaryboot=$(cat /proc/boot_info/$mtdname/primaryboot)
if [ $primaryboot -eq 0 ]; then
echo 1 > /proc/boot_info/$mtdname/primaryboot
else
echo 0 > /proc/boot_info/$mtdname/primaryboot
fi
mtdname=$(cat /proc/boot_info/$mtdname/upgradepartition)
}
mtdpart=$(grep "\"${mtdname}\"" /proc/mtd | awk -F: '{print $1}')
ubiformat /dev/${mtdpart} -y -f /tmp/${bin}.bin
}
do_flash_tz() {
local sec=$1
local mtdpart=$(grep "\"0:QSEE\"" /proc/mtd | awk -F: '{print $1}')
local emmcblock="$(find_mmc_part "0:QSEE")"
if [ -n "$mtdpart" -o -e "$emmcblock" ]; then
do_flash_failsafe_partition ${sec} "0:QSEE"
else
do_flash_failsafe_partition ${sec} "0:TZ"
fi
}
do_flash_ddr() {
local sec=$1
local mtdpart=$(grep "\"0:CDT\"" /proc/mtd | awk -F: '{print $1}')
local emmcblock="$(find_mmc_part "0:CDT")"
if [ -n "$mtdpart" -o -e "$emmcblock" ]; then
do_flash_failsafe_partition ${sec} "0:CDT"
else
do_flash_failsafe_partition ${sec} "0:DDRPARAMS"
fi
}
to_upper () {
echo $1 | awk '{print toupper($0)}'
}
flash_section() {
local sec=$1
local board=$(board_name)
case "${sec}" in
hlos*) switch_layout linux; do_flash_failsafe_partition ${sec} "0:HLOS";;
rootfs*) switch_layout linux; do_flash_failsafe_partition ${sec} "rootfs";;
fs*) switch_layout linux; do_flash_failsafe_partition ${sec} "rootfs";;
ubi*) switch_layout linux; do_flash_ubi ${sec} "rootfs";;
#sbl1*) switch_layout boot; do_flash_partition ${sec} "0:SBL1";;
#sbl2*) switch_layout boot; do_flash_failsafe_partition ${sec} "0:SBL2";;
#sbl3*) switch_layout boot; do_flash_failsafe_partition ${sec} "0:SBL3";;
#mibib*) switch_layout boot; do_flash_partition ${sec} "0:MIBIB";;
#dtb-$(to_upper $board)*) switch_layout boot; do_flash_partition ${sec} "0:DTB";;
u-boot*) switch_layout boot; do_flash_failsafe_partition ${sec} "0:APPSBL";;
#ddr-$(to_upper $board)*) switch_layout boot; do_flash_ddr ${sec};;
ddr-${board}-*) switch_layout boot; do_flash_failsafe_partition ${sec} "0:CDT";;
#ssd*) switch_layout boot; do_flash_partition ${sec} "0:SSD";;
tz*) switch_layout boot; do_flash_tz ${sec};;
#rpm*) switch_layout boot; do_flash_failsafe_partition ${sec} "0:RPM";;
*) echo "Section ${sec} ignored"; return 1;;
esac
echo "Flashed ${sec}"
}
erase_emmc_config() {
local emmcblock="$(find_mmc_part "rootfs_data")"
if [ -e "$emmcblock" ]; then
dd if=/dev/zero of=${emmcblock}
mkfs.ext4 "$emmcblock"
fi
}
platform_pre_upgrade() {
cp /sbin/upgraded /tmp
ubus call system nandupgrade "{\"path\": \"$1\" }"
}
platform_check_image_ipq() {
local board=$(board_name)
local mandatory_nand="ubi"
local mandatory_nor_emmc="hlos fs"
local mandatory_nor="hlos"
local mandatory_section_found=0
local optional="sbl2 u-boot ddr-${board} ssd tz rpm"
local ignored="mibib bootconfig sbl1"
image_is_FIT $1 || return 1
image_has_mandatory_section $1 ${mandatory_nand} && {\
mandatory_section_found=1
}
image_has_mandatory_section $1 ${mandatory_nor_emmc} && {\
mandatory_section_found=1
}
image_has_mandatory_section $1 ${mandatory_nor} && {\
mandatory_section_found=1
}
if [ $mandatory_section_found -eq 0 ]; then
echo "Error: mandatory section(s) missing from \"$1\". Abort..."
return 1
fi
for sec in ${optional}; do
image_contains $1 ${sec} || {\
echo "Warning: optional section \"${sec}\" missing from \"$1\". Continue..."
}
done
for sec in ${ignored}; do
image_contains $1 ${sec} && {\
echo "Warning: section \"${sec}\" will be ignored from \"$1\". Continue..."
}
done
image_demux $1 || {\
echo "Error: \"$1\" couldn't be extracted. Abort..."
return 1
}
[ -f /tmp/hlos_version ] && rm -f /tmp/*_version
dumpimage -c $1 2>/dev/null
return $?
}
platform_version_upgrade() {
local version_files="appsbl_version sbl_version tz_version hlos_version rpm_version"
local sys="/sys/devices/system/qfprom/qfprom0/"
local tmp="/tmp/"
for file in $version_files; do
[ -f "${tmp}${file}" ] && {
echo "Updating "${sys}${file}" with `cat "${tmp}${file}"`"
echo `cat "${tmp}${file}"` > "${sys}${file}"
rm -f "${tmp}${file}"
}
done
}
# The U-Boot loader of the OpenMesh devices requires image sizes and
# checksums to be provided in the U-Boot environment.
# The OpenMesh devices come with 2 main partitions - while one is active
# sysupgrade will flash the other. The boot order is changed to boot the
# newly flashed partition. If the new partition can't be booted due to
# upgrade failures the previously used partition is loaded.
platform_do_upgrade_ipq() {
local board=$(board_name)
# verify some things exist before erasing
if [ ! -e $1 ]; then
echo "Error: Can't find $1 after switching to ramfs, aborting upgrade!"
reboot
fi
for sec in $(print_sections $1); do
if [ ! -e /tmp/${sec}.bin ]; then
echo "Error: Cant' find ${sec} after switching to ramfs, aborting upgrade!"
reboot
fi
done
case "$board" in
teltonika,rutx)
for sec in $(print_sections $1); do
flash_section ${sec}
done
switch_layout linux
# update bootconfig to register that fw upgrade has been done
do_flash_bootconfig bootconfig "0:BOOTCONFIG"
do_flash_bootconfig bootconfig1 "0:BOOTCONFIG1"
platform_version_upgrade
erase_emmc_config
return 0;
;;
esac
echo "Upgrade failed!"
return 1;
}
platform_copy_config_ipq() {
local emmcblock="$(find_mmc_part "rootfs_data")"
mkdir -p /tmp/overlay
if [ -e "$emmcblock" ]; then
mount -t ext4 "$emmcblock" /tmp/overlay
cp /tmp/sysupgrade.tgz /tmp/overlay/
sync
umount /tmp/overlay
else
local mtdname=rootfs
local mtdpart
[ -f /proc/boot_info/$mtdname/upgradepartition ] && {
mtdname=$(cat /proc/boot_info/$mtdname/upgradepartition)
}
mtdpart=$(grep "\"${mtdname}\"" /proc/mtd | awk -F: '{print $1}')
ubiattach -p /dev/${mtdpart}
mount -t ubifs ubi0:rootfs_data /tmp/overlay
cp /tmp/sysupgrade.tgz /tmp/overlay/
sync
umount /tmp/overlay
fi
}

View file

@ -0,0 +1,216 @@
PART_NAME=firmware
REQUIRE_IMAGE_METADATA=1
RAMFS_COPY_BIN='fw_printenv fw_setenv'
RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock'
platform_check_image() {
case "$(board_name)" in
asus,rt-ac42u |\
asus,rt-ac58u)
local ubidev=$(nand_find_ubi $CI_UBIPART)
local asus_root=$(nand_find_volume $ubidev jffs2)
[ -n "$asus_root" ] || return 0
cat << EOF
jffs2 partition is still present.
There's probably no space left
to install the filesystem.
You need to delete the jffs2 partition first:
# ubirmvol /dev/ubi0 --name=jffs2
Once this is done. Retry.
EOF
return 1
;;
teltonika,rutx)
platform_check_image_ipq "$1"
;;
zte,mf286d)
CI_UBIPART="rootfs"
local mtdnum="$( find_mtd_index $CI_UBIPART )"
[ ! "$mtdnum" ] && return 1
ubiattach -m "$mtdnum" || true
local ubidev="$( nand_find_ubi $CI_UBIPART )"
local ubi_rootfs=$(nand_find_volume $ubidev ubi_rootfs)
local ubi_rootfs_data=$(nand_find_volume $ubidev ubi_rootfs_data)
[ -n "$ubi_rootfs" ] || [ -n "$ubi_rootfs_data" ] || return 0
cat << EOF
ubi_rootfs partition is still present.
You need to delete the stock partition first:
# ubirmvol /dev/ubi0 -N ubi_rootfs
Please also delete ubi_rootfs_data, if exist:
# ubirmvol /dev/ubi0 -N ubi_rootfs_data
Once this is done. Retry.
EOF
return 1
;;
esac
return 0;
}
askey_do_upgrade() {
local tar_file="$1"
local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
board_dir=${board_dir%/}
tar Oxf $tar_file ${board_dir}/root | mtd write - rootfs
nand_do_upgrade "$1"
}
zyxel_do_upgrade() {
local tar_file="$1"
local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
board_dir=${board_dir%/}
tar Oxf $tar_file ${board_dir}/kernel | mtd write - kernel
if [ -n "$UPGRADE_BACKUP" ]; then
tar Oxf $tar_file ${board_dir}/root | mtd -j "$UPGRADE_BACKUP" write - rootfs
else
tar Oxf $tar_file ${board_dir}/root | mtd write - rootfs
fi
}
platform_do_upgrade_mikrotik_nand() {
local fw_mtd=$(find_mtd_part kernel)
fw_mtd="${fw_mtd/block/}"
[ -n "$fw_mtd" ] || return
local board_dir=$(tar tf "$1" | grep -m 1 '^sysupgrade-.*/$')
board_dir=${board_dir%/}
[ -n "$board_dir" ] || return
local kernel_len=$(tar xf "$1" ${board_dir}/kernel -O | wc -c)
[ -n "$kernel_len" ] || return
tar xf "$1" ${board_dir}/kernel -O | ubiformat "$fw_mtd" -y -S $kernel_len -f -
CI_KERNPART="none"
nand_do_upgrade "$1"
}
platform_do_upgrade() {
case "$(board_name)" in
8dev,jalapeno |\
aruba,ap-303 |\
aruba,ap-303h |\
aruba,ap-365 |\
avm,fritzbox-7530 |\
avm,fritzrepeater-1200 |\
avm,fritzrepeater-3000 |\
buffalo,wtr-m2133hp |\
cilab,meshpoint-one |\
edgecore,ecw5211 |\
edgecore,oap100 |\
engenius,eap2200 |\
glinet,gl-ap1300 |\
luma,wrtq-329acn |\
mobipromo,cm520-79f |\
netgear,wac510 |\
p2w,r619ac-64m |\
p2w,r619ac-128m |\
qxwlan,e2600ac-c2)
nand_do_upgrade "$1"
;;
glinet,gl-b2200)
CI_KERNPART="0:HLOS"
CI_ROOTPART="rootfs"
CI_DATAPART="rootfs_data"
emmc_do_upgrade "$1"
;;
alfa-network,ap120c-ac)
part="$(awk -F 'ubi.mtd=' '{printf $2}' /proc/cmdline | sed -e 's/ .*$//')"
if [ "$part" = "rootfs1" ]; then
fw_setenv active 2 || exit 1
CI_UBIPART="rootfs2"
else
fw_setenv active 1 || exit 1
CI_UBIPART="rootfs1"
fi
nand_do_upgrade "$1"
;;
asus,map-ac2200)
CI_KERNPART="linux"
nand_do_upgrade "$1"
;;
asus,rt-ac42u |\
asus,rt-ac58u)
CI_KERNPART="linux"
nand_do_upgrade "$1"
;;
cellc,rtl30vw)
CI_UBIPART="ubifs"
askey_do_upgrade "$1"
;;
compex,wpj419)
nand_do_upgrade "$1"
;;
linksys,ea6350v3 |\
linksys,ea8300 |\
linksys,mr8300)
platform_do_upgrade_linksys "$1"
;;
meraki,mr33)
CI_KERNPART="part.safe"
nand_do_upgrade "$1"
;;
mikrotik,cap-ac|\
mikrotik,hap-ac2|\
mikrotik,lhgg-60ad|\
mikrotik,sxtsq-5-ac)
[ "$(rootfs_type)" = "tmpfs" ] && mtd erase firmware
default_do_upgrade "$1"
;;
mikrotik,hap-ac3)
platform_do_upgrade_mikrotik_nand "$1"
;;
netgear,rbr50 |\
netgear,rbs50 |\
netgear,srr60 |\
netgear,srs60)
platform_do_upgrade_netgear_orbi_upgrade "$1"
;;
openmesh,a42 |\
openmesh,a62 |\
plasmacloud,pa1200 |\
plasmacloud,pa2200)
PART_NAME="inactive"
platform_do_upgrade_dualboot_datachk "$1"
;;
teltonika,rutx)
platform_do_upgrade_ipq "$1"
;;
zte,mf286d)
CI_UBIPART="rootfs"
nand_do_upgrade "$1"
;;
zyxel,nbg6617)
zyxel_do_upgrade "$1"
;;
*)
default_do_upgrade "$1"
;;
esac
}
platform_copy_config() {
case "$(board_name)" in
glinet,gl-b2200)
emmc_copy_config
;;
teltonika,rutx)
platform_copy_config_ipq
;;
esac
return 0;
}

View file

@ -0,0 +1,138 @@
#!/bin/sh
. /lib/functions.sh
. /lib/functions/system.sh
export IMAGE="$1"
COMMAND="$2"
export INTERACTIVE=0
export VERBOSE=1
export CONFFILES=/tmp/sysupgrade.conffiles
RAMFS_COPY_BIN= # extra programs for temporary ramfs root
RAMFS_COPY_DATA= # extra data files
include /lib/upgrade
supivot() { # <new_root> <old_root>
/bin/mount | grep "on $1 type" 2>&- 1>&- || /bin/mount -o bind $1 $1
mkdir -p $1$2 $1/proc $1/sys $1/dev $1/tmp $1/overlay && \
/bin/mount -o noatime,move /proc $1/proc && \
pivot_root $1 $1$2 || {
/bin/umount -l $1 $1
return 1
}
/bin/mount -o noatime,move $2/sys /sys
/bin/mount -o noatime,move $2/dev /dev
/bin/mount -o noatime,move $2/tmp /tmp
/bin/mount -o noatime,move $2/overlay /overlay 2>&-
return 0
}
switch_to_ramfs() {
for binary in \
/bin/busybox /bin/ash /bin/sh /bin/mount /bin/umount \
pivot_root mount_root reboot sync kill sleep \
md5sum hexdump cat zcat bzcat dd tar \
ls basename find cp mv rm mkdir rmdir mknod touch chmod \
'[' printf wc grep awk sed cut \
mtd partx losetup mkfs.ext4 nandwrite flash_erase \
ubiupdatevol ubiattach ubiblock ubiformat \
ubidetach ubirsvol ubirmvol ubimkvol \
snapshot snapshot_tool date \
dumpimage $RAMFS_COPY_BIN
do
local file="$(command -v "$binary" 2>/dev/null)"
[ -n "$file" ] && install_bin "$file"
done
install_file /etc/resolv.conf /lib/*.sh /lib/functions/*.sh /lib/upgrade/*.sh /lib/upgrade/do_stage2 /usr/share/libubox/jshn.sh $RAMFS_COPY_DATA
[ -L "/lib64" ] && ln -s /lib $RAM_ROOT/lib64
supivot $RAM_ROOT /mnt || {
v "Failed to switch over to ramfs. Please reboot."
exit 1
}
/bin/mount -o remount,ro /mnt
/bin/umount -l /mnt
grep /overlay /proc/mounts > /dev/null && {
/bin/mount -o noatime,remount,ro /overlay
/bin/umount -l /overlay
}
}
kill_remaining() { # [ <signal> [ <loop> ] ]
local loop_limit=10
local sig="${1:-TERM}"
local loop="${2:-0}"
local run=true
local stat
local proc_ppid=$(cut -d' ' -f4 /proc/$$/stat)
vn "Sending $sig to remaining processes ..."
while $run; do
run=false
for stat in /proc/[0-9]*/stat; do
[ -f "$stat" ] || continue
local pid name state ppid rest
read pid name state ppid rest < $stat
name="${name#(}"; name="${name%)}"
# Skip PID1, our parent, ourself and our children
[ $pid -ne 1 -a $pid -ne $proc_ppid -a $pid -ne $$ -a $ppid -ne $$ ] || continue
local cmdline
read cmdline < /proc/$pid/cmdline
# Skip kernel threads
[ -n "$cmdline" ] || continue
_vn " $name"
kill -$sig $pid 2>/dev/null
[ $loop -eq 1 ] && run=true
done
let loop_limit--
[ $loop_limit -eq 0 ] && {
_v
v "Failed to kill all processes."
exit 1
}
done
_v
}
indicate_upgrade
killall -9 telnetd
killall -9 dropbear
killall -9 ash
kill_remaining TERM
sleep 3
kill_remaining KILL 1
sleep 1
echo 3 > /proc/sys/vm/drop_caches
if [ -n "$IMAGE" ] && type 'platform_pre_upgrade' >/dev/null 2>/dev/null; then
platform_pre_upgrade "$IMAGE"
fi
if [ -n "$(rootfs_type)" ]; then
v "Switching to ramdisk..."
switch_to_ramfs
fi
# Exec new shell from ramfs
exec /bin/busybox ash -c "$COMMAND"

View file

@ -0,0 +1,120 @@
#!/bin/sh
. /usr/share/libubox/jshn.sh
PS_ON=1
PS_OFF=2
MPS=0
MLBL="modem"
modem_reset() {
local label="$1"
[ -e "/sys/class/gpio/${label}_reset/value" ] || return
echo 1 > "/sys/class/gpio/${label}_reset/value"
sleep 1
echo 0 > "/sys/class/gpio/${label}_reset/value"
}
modem_off() {
local label="$1"
[ -e "/sys/class/gpio/${label}_reset/value" ] || return
echo 1 > "/sys/class/gpio/${label}_reset/value"
}
modem_power() {
local label="$1"
[ -e "/sys/class/gpio/${label}_power/value" ] || return
# simulate power press
echo 1 > "/sys/class/gpio/${label}_power/value"
sleep 1
echo 0 > "/sys/class/gpio/${label}_power/value"
}
modem_list() {
local list="modem"
local label
[ "$(modem_fetch_primary)" -eq 0 ] && {
echo "${list}"
return
}
for m in /sys/class/gpio/modem*_power; do
label="$(basename $m | awk -F_ '{print $1}')"
[ "${label}" != "modem" ] && list="${list},${label}"
done
echo "${list}"
}
modem_fetch_primary() {
local modem modems primary
json_init
json_load_file "/etc/board.json"
json_get_keys modems modems
json_select modems
for modem in $modems; do
json_select "$modem"
json_get_vars primary
[ -n "$primary" ] && {
echo 1
return
}
json_select ..
done
echo 0
}
modem_is_available() {
local label="$1"
[ -e "/sys/class/gpio/${label}_power/value" ]
}
usage() {
cat <<EOF
Usage $0 <option>
Control modem power state.
Options:
-p, --power-on power on modem
-s, --shutdown shutdown modem
-r, --reboot reboot modem
-m, --modem <label> use specified modem instead of default one
Available modem labels:
$(modem_list)
EOF
exit 1
}
while [ -n "$1" ]; do
case "$1" in
-p | --power-on) MPS="${PS_ON}";;
-s | --shutdown) MPS="${PS_OFF}";;
-r | --reboot) MPS="${PS_ON}";;
-m | --modem) MLBL="$2"; shift;;
-*) echo "Invalid option: $1"; usage;;
*) break;;
esac
shift
done
[ "${MPS}" -eq 0 ] && usage
modem_is_available "${MLBL}" || usage
case "${MPS}" in
"${PS_ON}") modem_reset "${MLBL}"; sleep 1; modem_power "${MLBL}";;
"${PS_OFF}") modem_off "${MLBL}";;
esac

View file

@ -0,0 +1,10 @@
#!/bin/sh
while [[ $# -gt 0 ]]; do
case $1 in
-n|--name)
echo $(dd if=/dev/mtd13 bs=1 count=12 skip=16 2>/dev/null)
shift
;;
esac
done

View file

@ -0,0 +1,477 @@
CONFIG_ALIGNMENT_TRAP=y
# CONFIG_APQ_GCC_8084 is not set
# CONFIG_APQ_MMCC_8084 is not set
CONFIG_AR40XX_PHY=y
CONFIG_ARCH_32BIT_OFF_T=y
CONFIG_ARCH_CLOCKSOURCE_DATA=y
CONFIG_ARCH_HIBERNATION_POSSIBLE=y
CONFIG_ARCH_IPQ40XX=y
CONFIG_ARCH_KEEP_MEMBLOCK=y
# CONFIG_ARCH_MDM9615 is not set
CONFIG_ARCH_MIGHT_HAVE_PC_PARPORT=y
# CONFIG_ARCH_MSM8960 is not set
# CONFIG_ARCH_MSM8974 is not set
# CONFIG_ARCH_MSM8X60 is not set
CONFIG_ARCH_MULTIPLATFORM=y
CONFIG_ARCH_MULTI_V6_V7=y
CONFIG_ARCH_MULTI_V7=y
CONFIG_ARCH_NR_GPIO=0
CONFIG_ARCH_OPTIONAL_KERNEL_RWX=y
CONFIG_ARCH_OPTIONAL_KERNEL_RWX_DEFAULT=y
CONFIG_ARCH_QCOM=y
CONFIG_ARCH_SUSPEND_POSSIBLE=y
CONFIG_ARM=y
CONFIG_ARM_AMBA=y
CONFIG_ARM_APPENDED_DTB=y
CONFIG_ARM_ARCH_TIMER=y
CONFIG_ARM_ARCH_TIMER_EVTSTREAM=y
# CONFIG_ARM_ATAG_DTB_COMPAT is not set
CONFIG_ARM_CPUIDLE=y
CONFIG_ARM_CPU_SUSPEND=y
# CONFIG_ARM_CPU_TOPOLOGY is not set
CONFIG_ARM_CRYPTO=y
CONFIG_ARM_GIC=y
CONFIG_ARM_HAS_SG_CHAIN=y
CONFIG_ARM_L1_CACHE_SHIFT=6
CONFIG_ARM_L1_CACHE_SHIFT_6=y
CONFIG_ARM_PATCH_IDIV=y
CONFIG_ARM_PATCH_PHYS_VIRT=y
# CONFIG_ARM_QCOM_CPUFREQ_HW is not set
# CONFIG_ARM_SMMU is not set
CONFIG_ARM_THUMB=y
CONFIG_ARM_UNWIND=y
CONFIG_ARM_VIRT_EXT=y
CONFIG_AT803X_PHY=y
CONFIG_AUTO_ZRELADDR=y
CONFIG_BCH=y
CONFIG_BINFMT_FLAT_ARGVP_ENVP_ON_STACK=y
CONFIG_BLK_DEV_LOOP=y
CONFIG_BLK_MQ_PCI=y
CONFIG_BOOTCONFIG_PARTITION=y
CONFIG_BOUNCE=y
# CONFIG_CACHE_L2X0 is not set
CONFIG_CLKDEV_LOOKUP=y
CONFIG_CLKSRC_QCOM=y
CONFIG_CLONE_BACKWARDS=y
CONFIG_COMMON_CLK=y
CONFIG_COMMON_CLK_QCOM=y
CONFIG_COMPAT_32BIT_TIME=y
CONFIG_CPUFREQ_DT=y
CONFIG_CPUFREQ_DT_PLATDEV=y
CONFIG_CPU_32v6K=y
CONFIG_CPU_32v7=y
CONFIG_CPU_ABRT_EV7=y
CONFIG_CPU_CACHE_V7=y
CONFIG_CPU_CACHE_VIPT=y
CONFIG_CPU_COPY_V6=y
CONFIG_CPU_CP15=y
CONFIG_CPU_CP15_MMU=y
CONFIG_CPU_FREQ=y
CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
# CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE is not set
CONFIG_CPU_FREQ_GOV_ATTR_SET=y
CONFIG_CPU_FREQ_GOV_COMMON=y
# CONFIG_CPU_FREQ_GOV_CONSERVATIVE is not set
CONFIG_CPU_FREQ_GOV_ONDEMAND=y
CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
# CONFIG_CPU_FREQ_GOV_POWERSAVE is not set
# CONFIG_CPU_FREQ_GOV_USERSPACE is not set
CONFIG_CPU_FREQ_STAT=y
CONFIG_CPU_HAS_ASID=y
CONFIG_CPU_IDLE=y
CONFIG_CPU_IDLE_GOV_LADDER=y
CONFIG_CPU_IDLE_GOV_MENU=y
CONFIG_CPU_IDLE_MULTIPLE_DRIVERS=y
CONFIG_CPU_PABRT_V7=y
CONFIG_CPU_PM=y
CONFIG_CPU_RMAP=y
CONFIG_CPU_SPECTRE=y
CONFIG_CPU_THERMAL=y
CONFIG_CPU_THUMB_CAPABLE=y
CONFIG_CPU_TLB_V7=y
CONFIG_CPU_V7=y
CONFIG_CRC16=y
# CONFIG_CRC32_SARWATE is not set
CONFIG_CRC32_SLICEBY8=y
CONFIG_CRYPTO_ACOMP2=y
CONFIG_CRYPTO_AEAD=y
CONFIG_CRYPTO_AEAD2=y
CONFIG_CRYPTO_AES_ARM=y
CONFIG_CRYPTO_AES_ARM_BS=y
CONFIG_CRYPTO_CBC=y
CONFIG_CRYPTO_CRYPTD=y
CONFIG_CRYPTO_CTR=y
CONFIG_CRYPTO_DEFLATE=y
CONFIG_CRYPTO_DES=y
CONFIG_CRYPTO_DEV_QCE=y
# CONFIG_CRYPTO_DEV_QCE_ENABLE_ALL is not set
# CONFIG_CRYPTO_DEV_QCE_ENABLE_SHA is not set
CONFIG_CRYPTO_DEV_QCE_ENABLE_SKCIPHER=y
CONFIG_CRYPTO_DEV_QCE_SKCIPHER=y
CONFIG_CRYPTO_DEV_QCE_SW_MAX_LEN=512
CONFIG_CRYPTO_DEV_QCOM_RNG=y
CONFIG_CRYPTO_DRBG=y
CONFIG_CRYPTO_DRBG_HMAC=y
CONFIG_CRYPTO_DRBG_MENU=y
CONFIG_CRYPTO_ECB=y
CONFIG_CRYPTO_HASH=y
CONFIG_CRYPTO_HASH2=y
CONFIG_CRYPTO_HASH_INFO=y
CONFIG_CRYPTO_HMAC=y
CONFIG_CRYPTO_HW=y
CONFIG_CRYPTO_JITTERENTROPY=y
CONFIG_CRYPTO_LIB_DES=y
CONFIG_CRYPTO_LIB_SHA256=y
CONFIG_CRYPTO_LZO=y
CONFIG_CRYPTO_MANAGER=y
CONFIG_CRYPTO_MANAGER2=y
CONFIG_CRYPTO_NULL=y
CONFIG_CRYPTO_NULL2=y
CONFIG_CRYPTO_RNG=y
CONFIG_CRYPTO_RNG2=y
CONFIG_CRYPTO_RNG_DEFAULT=y
CONFIG_CRYPTO_SEQIV=y
CONFIG_CRYPTO_SHA1=y
CONFIG_CRYPTO_SHA1_ARM=y
CONFIG_CRYPTO_SHA1_ARM_NEON=y
CONFIG_CRYPTO_SHA256=y
CONFIG_CRYPTO_SHA256_ARM=y
CONFIG_CRYPTO_SHA512_ARM=y
CONFIG_CRYPTO_SIMD=y
CONFIG_CRYPTO_XTS=y
CONFIG_CRYPTO_ZSTD=y
CONFIG_CRYPTO_USER=y
CONFIG_DCACHE_WORD_ACCESS=y
CONFIG_DEBUG_LL_INCLUDE="mach/debug-macro.S"
CONFIG_DEBUG_MISC=y
CONFIG_DMADEVICES=y
CONFIG_DMA_ENGINE=y
CONFIG_DMA_OF=y
CONFIG_DMA_REMAP=y
CONFIG_DMA_SHARED_BUFFER=y
CONFIG_DMA_VIRTUAL_CHANNELS=y
CONFIG_DTC=y
CONFIG_DT_IDLE_STATES=y
CONFIG_DYNAMIC_DEBUG=y
CONFIG_EDAC_ATOMIC_SCRUB=y
CONFIG_EDAC_SUPPORT=y
CONFIG_EEPROM_AT24=y
CONFIG_ESSEDMA=y
CONFIG_EXTCON=y
CONFIG_FIXED_PHY=y
CONFIG_FIX_EARLYCON_MEM=y
CONFIG_FW_LOADER_PAGED_BUF=y
CONFIG_GENERIC_ALLOCATOR=y
CONFIG_GENERIC_BUG=y
CONFIG_GENERIC_CLOCKEVENTS=y
CONFIG_GENERIC_CLOCKEVENTS_BROADCAST=y
CONFIG_GENERIC_CPU_AUTOPROBE=y
CONFIG_GENERIC_EARLY_IOREMAP=y
CONFIG_GENERIC_IDLE_POLL_SETUP=y
CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK=y
CONFIG_GENERIC_IRQ_MULTI_HANDLER=y
CONFIG_GENERIC_IRQ_SHOW=y
CONFIG_GENERIC_IRQ_SHOW_LEVEL=y
CONFIG_GENERIC_MSI_IRQ=y
CONFIG_GENERIC_MSI_IRQ_DOMAIN=y
CONFIG_GENERIC_PCI_IOMAP=y
CONFIG_GENERIC_PHY=y
CONFIG_GENERIC_PINCONF=y
CONFIG_GENERIC_PINCTRL_GROUPS=y
CONFIG_GENERIC_PINMUX_FUNCTIONS=y
CONFIG_GENERIC_SCHED_CLOCK=y
CONFIG_GENERIC_SMP_IDLE_THREAD=y
CONFIG_GENERIC_STRNCPY_FROM_USER=y
CONFIG_GENERIC_STRNLEN_USER=y
CONFIG_GENERIC_TIME_VSYSCALL=y
CONFIG_GPIOLIB=y
CONFIG_GPIOLIB_IRQCHIP=y
CONFIG_GPIO_74X164=y
CONFIG_GPIO_WATCHDOG=y
CONFIG_GPIO_WATCHDOG_ARCH_INITCALL=y
CONFIG_HANDLE_DOMAIN_IRQ=y
CONFIG_HARDEN_BRANCH_PREDICTOR=y
CONFIG_HARDIRQS_SW_RESEND=y
CONFIG_HAS_DMA=y
CONFIG_HAS_IOMEM=y
CONFIG_HAS_IOPORT_MAP=y
CONFIG_HAVE_SMP=y
CONFIG_HIGHMEM=y
# CONFIG_HIGHPTE is not set
CONFIG_HWSPINLOCK=y
CONFIG_HWSPINLOCK_QCOM=y
CONFIG_HW_RANDOM=y
CONFIG_HW_RANDOM_OPTEE=y
CONFIG_HZ=100
CONFIG_HZ_100=y
CONFIG_HZ_FIXED=0
CONFIG_I2C=y
CONFIG_I2C_BOARDINFO=y
CONFIG_I2C_CHARDEV=y
CONFIG_I2C_HELPER_AUTO=y
CONFIG_I2C_QUP=y
CONFIG_INITRAMFS_SOURCE=""
# CONFIG_IOMMU_DEBUGFS is not set
# CONFIG_IOMMU_IO_PGTABLE_ARMV7S is not set
# CONFIG_IOMMU_IO_PGTABLE_LPAE is not set
CONFIG_IOMMU_SUPPORT=y
CONFIG_IO_URING=y
CONFIG_IPQ_GCC_4019=y
# CONFIG_IPQ_GCC_806X is not set
# CONFIG_IPQ_GCC_8074 is not set
# CONFIG_IPQ_LCC_806X is not set
CONFIG_IRQCHIP=y
CONFIG_IRQ_DOMAIN=y
CONFIG_IRQ_DOMAIN_HIERARCHY=y
CONFIG_IRQ_FORCED_THREADING=y
CONFIG_IRQ_WORK=y
# CONFIG_KPSS_XCC is not set
# CONFIG_KRAITCC is not set
CONFIG_LEDS_LP5523=y
CONFIG_LEDS_LP5562=y
CONFIG_LEDS_LP55XX_COMMON=y
CONFIG_LIBFDT=y
CONFIG_LOCK_DEBUGGING_SUPPORT=y
CONFIG_LOCK_SPIN_ON_OWNER=y
CONFIG_LZO_COMPRESS=y
CONFIG_LZO_DECOMPRESS=y
CONFIG_MDIO_BITBANG=y
CONFIG_MDIO_BUS=y
CONFIG_MDIO_DEVICE=y
CONFIG_MDIO_GPIO=y
CONFIG_MDIO_IPQ4019=y
# CONFIG_MDM_GCC_9615 is not set
# CONFIG_MDM_LCC_9615 is not set
CONFIG_MEMFD_CREATE=y
# CONFIG_MFD_QCOM_RPM is not set
# CONFIG_MFD_SPMI_PMIC is not set
CONFIG_MFD_SYSCON=y
CONFIG_MIGHT_HAVE_CACHE_L2X0=y
CONFIG_MIGRATION=y
CONFIG_MMC=y
CONFIG_MMC_BLOCK=y
CONFIG_MMC_SDHCI=y
CONFIG_MMC_SDHCI_IO_ACCESSORS=y
CONFIG_MMC_SDHCI_MSM=y
# CONFIG_MMC_SDHCI_PCI is not set
CONFIG_MMC_SDHCI_PLTFM=y
CONFIG_MODULES_USE_ELF_REL=y
# CONFIG_MSM_GCC_8660 is not set
# CONFIG_MSM_GCC_8916 is not set
# CONFIG_MSM_GCC_8960 is not set
# CONFIG_MSM_GCC_8974 is not set
# CONFIG_MSM_GCC_8994 is not set
# CONFIG_MSM_GCC_8996 is not set
# CONFIG_MSM_GCC_8998 is not set
# CONFIG_MSM_LCC_8960 is not set
# CONFIG_MSM_MMCC_8960 is not set
# CONFIG_MSM_MMCC_8974 is not set
# CONFIG_MSM_MMCC_8996 is not set
CONFIG_MTD_CMDLINE_PARTS=y
CONFIG_MTD_NAND_CORE=y
CONFIG_MTD_NAND_ECC_SW_BCH=y
CONFIG_MTD_NAND_ECC_SW_HAMMING=y
CONFIG_MTD_NAND_QCOM=y
CONFIG_MTD_RAW_NAND=y
CONFIG_MTD_SPI_NAND=y
CONFIG_MTD_SPI_NOR=y
CONFIG_MTD_SPLIT_FIRMWARE=y
CONFIG_MTD_SPLIT_FIT_FW=y
CONFIG_MTD_SPLIT_WRGG_FW=y
CONFIG_MTD_UBI=y
CONFIG_MTD_UBI_BEB_LIMIT=20
CONFIG_MTD_UBI_BLOCK=y
CONFIG_MTD_UBI_WL_THRESHOLD=4096
CONFIG_MUTEX_SPIN_ON_OWNER=y
CONFIG_NEED_DMA_MAP_STATE=y
CONFIG_NEON=y
CONFIG_NET_FLOW_LIMIT=y
CONFIG_NET_PTP_CLASSIFY=y
CONFIG_NLS=y
CONFIG_NO_HZ=y
CONFIG_NO_HZ_COMMON=y
CONFIG_NO_HZ_IDLE=y
CONFIG_NR_CPUS=4
CONFIG_NVMEM=y
CONFIG_NVMEM_SYSFS=y
CONFIG_OF=y
CONFIG_OF_ADDRESS=y
CONFIG_OF_EARLY_FLATTREE=y
CONFIG_OF_FLATTREE=y
CONFIG_OF_GPIO=y
CONFIG_OF_IRQ=y
CONFIG_OF_KOBJ=y
CONFIG_OF_MDIO=y
CONFIG_OF_NET=y
CONFIG_OLD_SIGACTION=y
CONFIG_OLD_SIGSUSPEND3=y
CONFIG_OPTEE=y
CONFIG_OPTEE_SHM_NUM_PRIV_PAGES=1
CONFIG_PADATA=y
CONFIG_PAGE_OFFSET=0xC0000000
CONFIG_PCI=y
CONFIG_PCIEAER=y
CONFIG_PCIEPORTBUS=y
CONFIG_PCIE_DW=y
CONFIG_PCIE_DW_HOST=y
CONFIG_PCIE_QCOM=y
CONFIG_PCI_DISABLE_COMMON_QUIRKS=y
CONFIG_PCI_DOMAINS=y
CONFIG_PCI_DOMAINS_GENERIC=y
CONFIG_PCI_MSI=y
CONFIG_PCI_MSI_IRQ_DOMAIN=y
CONFIG_PERF_USE_VMALLOC=y
CONFIG_PGTABLE_LEVELS=2
CONFIG_PHYLIB=y
# CONFIG_PHY_QCOM_APQ8064_SATA is not set
CONFIG_PHY_QCOM_IPQ4019_USB=y
# CONFIG_PHY_QCOM_IPQ806X_SATA is not set
# CONFIG_PHY_QCOM_PCIE2 is not set
# CONFIG_PHY_QCOM_QMP is not set
# CONFIG_PHY_QCOM_QUSB2 is not set
# CONFIG_PHY_QCOM_UFS is not set
CONFIG_PINCTRL=y
# CONFIG_PINCTRL_APQ8064 is not set
# CONFIG_PINCTRL_APQ8084 is not set
CONFIG_PINCTRL_IPQ4019=y
# CONFIG_PINCTRL_IPQ8064 is not set
# CONFIG_PINCTRL_IPQ8074 is not set
# CONFIG_PINCTRL_MDM9615 is not set
CONFIG_PINCTRL_MSM=y
# CONFIG_PINCTRL_MSM8660 is not set
# CONFIG_PINCTRL_MSM8916 is not set
# CONFIG_PINCTRL_MSM8960 is not set
# CONFIG_PINCTRL_MSM8994 is not set
# CONFIG_PINCTRL_MSM8996 is not set
# CONFIG_PINCTRL_MSM8998 is not set
# CONFIG_PINCTRL_QCOM_SPMI_PMIC is not set
# CONFIG_PINCTRL_QCOM_SSBI_PMIC is not set
# CONFIG_PINCTRL_QCS404 is not set
# CONFIG_PINCTRL_SC7180 is not set
# CONFIG_PINCTRL_SDM660 is not set
# CONFIG_PINCTRL_SDM845 is not set
# CONFIG_PINCTRL_SM8150 is not set
CONFIG_PLUGIN_HOSTCC="g++"
CONFIG_PM_OPP=y
CONFIG_POWER_RESET=y
CONFIG_POWER_RESET_MSM=y
CONFIG_POWER_SUPPLY=y
CONFIG_PPS=y
CONFIG_PRINTK_TIME=y
CONFIG_PTP_1588_CLOCK=y
CONFIG_QCA807X_PHY=y
CONFIG_QCOM_A53PLL=y
CONFIG_QCOM_BAM_DMA=y
# CONFIG_QCOM_COMMAND_DB is not set
# CONFIG_QCOM_EBI2 is not set
# CONFIG_QCOM_GENI_SE is not set
# CONFIG_QCOM_GSBI is not set
# CONFIG_QCOM_HFPLL is not set
# CONFIG_QCOM_IOMMU is not set
# CONFIG_QCOM_LLCC is not set
# CONFIG_QCOM_PDC is not set
CONFIG_QCOM_PM=y
CONFIG_QCOM_QFPROM=y
# CONFIG_QCOM_RMTFS_MEM is not set
CONFIG_QCOM_SCM=y
CONFIG_QCOM_SCM_32=y
# CONFIG_QCOM_SCM_DOWNLOAD_MODE_DEFAULT is not set
CONFIG_QCOM_SMEM=y
# CONFIG_QCOM_SMSM is not set
# CONFIG_QCOM_SOCINFO is not set
CONFIG_QCOM_TCSR=y
# CONFIG_QCOM_TSENS is not set
CONFIG_QCOM_WDT=y
# CONFIG_QCS_GCC_404 is not set
# CONFIG_QCS_TURING_404 is not set
# CONFIG_QRTR is not set
CONFIG_RAS=y
CONFIG_RATIONAL=y
CONFIG_RCU_CPU_STALL_TIMEOUT=21
CONFIG_RCU_NEED_SEGCBLIST=y
CONFIG_RCU_STALL_COMMON=y
CONFIG_REFCOUNT_FULL=y
CONFIG_REGMAP=y
CONFIG_REGMAP_I2C=y
CONFIG_REGMAP_MMIO=y
CONFIG_REGULATOR=y
CONFIG_REGULATOR_FIXED_VOLTAGE=y
# CONFIG_REGULATOR_QCOM_SPMI is not set
CONFIG_REGULATOR_VCTRL=y
CONFIG_REGULATOR_VQMMC_IPQ4019=y
CONFIG_RESET_CONTROLLER=y
# CONFIG_RESET_QCOM_AOSS is not set
# CONFIG_RESET_QCOM_PDC is not set
CONFIG_RFS_ACCEL=y
CONFIG_RPS=y
CONFIG_RTC_CLASS=y
CONFIG_RTC_I2C_AND_SPI=y
CONFIG_RTC_MC146818_LIB=y
CONFIG_RWSEM_SPIN_ON_OWNER=y
# CONFIG_SDM_CAMCC_845 is not set
# CONFIG_SDM_DISPCC_845 is not set
# CONFIG_SDM_GCC_660 is not set
# CONFIG_SDM_GCC_845 is not set
# CONFIG_SDM_GPUCC_845 is not set
# CONFIG_SDM_LPASSCC_845 is not set
# CONFIG_SDM_VIDEOCC_845 is not set
CONFIG_SERIAL_8250_FSL=y
CONFIG_SERIAL_MCTRL_GPIO=y
CONFIG_SERIAL_MSM=y
CONFIG_SERIAL_MSM_CONSOLE=y
CONFIG_SGL_ALLOC=y
CONFIG_SMP=y
CONFIG_SMP_ON_UP=y
# CONFIG_SM_GCC_8150 is not set
CONFIG_SPARSE_IRQ=y
CONFIG_SPI=y
CONFIG_SPI_BITBANG=y
CONFIG_SPI_GPIO=y
CONFIG_SPI_MASTER=y
CONFIG_SPI_MEM=y
CONFIG_SPI_QUP=y
CONFIG_SPMI=y
CONFIG_SPMI_MSM_PMIC_ARB=y
# CONFIG_SPMI_PMIC_CLKDIV is not set
CONFIG_SRCU=y
CONFIG_SWCONFIG=y
CONFIG_SWCONFIG_LEDS=y
CONFIG_SWPHY=y
CONFIG_SWP_EMULATE=y
CONFIG_SYS_SUPPORTS_APM_EMULATION=y
CONFIG_TEE=y
CONFIG_THERMAL=y
CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE=y
CONFIG_THERMAL_EMERGENCY_POWEROFF_DELAY_MS=0
CONFIG_THERMAL_GOV_STEP_WISE=y
CONFIG_THERMAL_OF=y
CONFIG_TICK_CPU_ACCOUNTING=y
CONFIG_TIMER_OF=y
CONFIG_TIMER_PROBE=y
CONFIG_TREE_RCU=y
CONFIG_TREE_SRCU=y
CONFIG_UBIFS_FS=y
CONFIG_UBIFS_FS_ADVANCED_COMPR=y
CONFIG_UBIFS_FS_LZO=y
CONFIG_UBIFS_FS_ZLIB=y
CONFIG_UBIFS_FS_ZSTD=y
CONFIG_UEVENT_HELPER_PATH=""
CONFIG_UNCOMPRESS_INCLUDE="debug/uncompress.h"
CONFIG_UNWINDER_ARM=y
CONFIG_USB=y
CONFIG_USB_COMMON=y
CONFIG_USB_SUPPORT=y
CONFIG_USE_OF=y
CONFIG_VFP=y
CONFIG_VFPv3=y
CONFIG_WATCHDOG_CORE=y
CONFIG_XPS=y
CONFIG_XXHASH=y
CONFIG_XZ_DEC_ARM=y
CONFIG_XZ_DEC_BCJ=y
CONFIG_ZBOOT_ROM_BSS=0
CONFIG_ZBOOT_ROM_TEXT=0
CONFIG_ZLIB_DEFLATE=y
CONFIG_ZLIB_INFLATE=y
CONFIG_ZSTD_COMPRESS=y
CONFIG_ZSTD_DECOMPRESS=y

View file

@ -0,0 +1 @@
/ { platform = "RUTX"; };

View file

@ -0,0 +1,57 @@
#include "qcom-ipq4018-rutx-common.dtsi"
#include "qcom-ipq4018-rutx-shiftreg.dtsi"
/ {
model = "Teltonika RUTX08/10";
soc {
gpio-export {
compatible = "gpio-export";
#size-cells = <0>;
gpio_modem_reset {
gpio-export,name = "modem_reset";
gpio-export,output = <0>;
gpios = <&shift_io 1 GPIO_ACTIVE_HIGH>;
};
gpio_modem_power {
gpio-export,name = "modem_power";
gpio-export,output = <0>;
gpios = <&shift_io 2 GPIO_ACTIVE_HIGH>;
};
gpio_sim_select {
gpio-export,name = "sim_sel";
gpio-export,output = <1>;
gpios = <&shift_io 3 GPIO_ACTIVE_HIGH>;
};
gpio_out_1 {
gpio-export,name = "gpio23";
gpio-export,output = <0>;
gpios = <&shift_io 0 GPIO_ACTIVE_HIGH>;
};
gpio_in_1 {
gpio-export,name = "gpio24";
gpio-export,input = <0>;
gpios = <&tlmm 0 GPIO_ACTIVE_HIGH>;
};
};
leds {
compatible = "gpio-leds";
led_wifi_24 {
label = "wifi_gen_2";
gpios = <&shift_io 5 GPIO_ACTIVE_HIGH>;
};
led_wifi_50 {
label = "wifi_gen_5";
gpios = <&shift_io 6 GPIO_ACTIVE_HIGH>;
};
};
};
};

View file

@ -0,0 +1,122 @@
#include "qcom-ipq4018-rutx-common.dtsi"
#include "qcom-ipq4018-rutx-shiftreg.dtsi"
/ {
model = "Teltonika RUTX09/11";
soc {
gpio-export {
compatible = "gpio-export";
#size-cells = <0>;
gpio_modem_reset {
gpio-export,name = "modem_reset";
gpio-export,output = <0>;
gpios = <&shift_io 1 GPIO_ACTIVE_HIGH>;
};
gpio_modem_power {
gpio-export,name = "modem_power";
gpio-export,output = <0>;
gpios = <&shift_io 2 GPIO_ACTIVE_HIGH>;
};
gpio_sim_select {
gpio-export,name = "sim_sel";
gpio-export,output = <1>;
gpios = <&shift_io 3 GPIO_ACTIVE_LOW>;
};
gpio_out_1 {
gpio-export,name = "gpio23";
gpio-export,output = <0>;
gpios = <&shift_io 0 GPIO_ACTIVE_HIGH>;
};
gpio_in_1 {
gpio-export,name = "gpio24";
gpio-export,input = <0>;
gpios = <&tlmm 0 GPIO_ACTIVE_HIGH>;
};
};
leds {
compatible = "gpio-leds";
led_wan_sim1 {
label = "wan_sim_1";
gpios = <&shift_io 21 GPIO_ACTIVE_HIGH>;
};
led_wan_sim2 {
label = "wan_sim_2";
gpios = <&shift_io 22 GPIO_ACTIVE_HIGH>;
};
led_wan_eth {
label = "wan_wifi_4"; // not wan_eth_3 !
gpios = <&shift_io 13 GPIO_ACTIVE_HIGH>;
};
led_wan_wifi {
label = "wan_eth_3"; // not wan_wifi_4 !
gpios = <&shift_io 20 GPIO_ACTIVE_HIGH>;
};
led_gen_2 {
label = "mob_gen_2";
gpios = <&shift_io 7 GPIO_ACTIVE_HIGH>;
};
led_gen_3 {
label = "mob_gen_3";
gpios = <&shift_io 8 GPIO_ACTIVE_HIGH>;
};
led_gen_4 {
label = "mob_gen_4";
gpios = <&shift_io 9 GPIO_ACTIVE_HIGH>;
};
led_ssid_1 {
label = "mob_ssid_1";
gpios = <&shift_io 10 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_ssid_2 {
label = "mob_ssid_2";
gpios = <&shift_io 11 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_ssid_3 {
label = "mob_ssid_3";
gpios = <&shift_io 12 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_ssid_4 {
label = "mob_ssid_4";
gpios = <&shift_io 14 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_ssid_5 {
label = "mob_ssid_5";
gpios = <&shift_io 15 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_wifi_24 {
label = "wifi_gen_2";
gpios = <&shift_io 5 GPIO_ACTIVE_HIGH>;
};
led_wifi_50 {
label = "wifi_gen_5";
gpios = <&shift_io 6 GPIO_ACTIVE_HIGH>;
};
};
};
};

View file

@ -0,0 +1,149 @@
#include "qcom-ipq4018-rutx-common.dtsi"
#include "qcom-ipq4018-rutx-shiftreg.dtsi"
/ {
model = "Teltonika RUTX12";
soc {
gpio-export {
compatible = "gpio-export";
#size-cells = <0>;
gpio_modem_reset {
gpio-export,name = "modem1_reset";
gpio-export,output = <0>;
gpios = <&shift_io 16 GPIO_ACTIVE_HIGH>;
};
gpio_modem_power {
gpio-export,name = "modem1_power";
gpio-export,output = <0>;
gpios = <&shift_io 17 GPIO_ACTIVE_HIGH>;
};
gpio_modem2_reset {
gpio-export,name = "modem2_reset";
gpio-export,output = <0>;
gpios = <&shift_io 18 GPIO_ACTIVE_HIGH>;
};
gpio_modem2_power {
gpio-export,name = "modem2_power";
gpio-export,output = <0>;
gpios = <&shift_io 19 GPIO_ACTIVE_HIGH>;
};
gpio_out_1 {
gpio-export,name = "gpio23";
gpio-export,output = <0>;
gpios = <&shift_io 20 GPIO_ACTIVE_HIGH>;
};
gpio_in_1 {
gpio-export,name = "gpio24";
gpio-export,input = <0>;
gpios = <&tlmm 0 GPIO_ACTIVE_HIGH>;
};
};
leds {
compatible = "gpio-leds";
led_wan_sim1 {
label = "wan_sim_1";
gpios = <&shift_io 14 GPIO_ACTIVE_HIGH>;
};
led_wan_sim2 {
label = "wan_sim_2";
gpios = <&shift_io 15 GPIO_ACTIVE_HIGH>;
};
led_wan_eth {
label = "wan_wifi_4"; // not wan_eth_3 !
gpios = <&shift_io 6 GPIO_ACTIVE_HIGH>;
};
led_wan_wifi {
label = "wan_eth_3"; // not wan_wifi_4 !
gpios = <&shift_io 7 GPIO_ACTIVE_HIGH>;
};
led_gen_2 {
label = "mob_gen_2";
gpios = <&shift_io 5 GPIO_ACTIVE_HIGH>;
};
led_gen_3 {
label = "mob_gen_3";
gpios = <&shift_io 4 GPIO_ACTIVE_HIGH>;
};
led_gen_4 {
label = "mob_gen_4";
gpios = <&shift_io 3 GPIO_ACTIVE_HIGH>;
};
led2_gen_2 {
label = "mob2_gen_2";
gpios = <&shift_io 11 GPIO_ACTIVE_HIGH>;
};
led2_gen_3 {
label = "mob2_gen_3";
gpios = <&shift_io 12 GPIO_ACTIVE_HIGH>;
};
led2_gen_4 {
label = "mob2_gen_4";
gpios = <&shift_io 13 GPIO_ACTIVE_HIGH>;
};
led_ssid_1 {
label = "mob_ssid_1";
gpios = <&shift_io 0 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_ssid_3 {
label = "mob_ssid_3";
gpios = <&shift_io 1 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_ssid_5 {
label = "mob_ssid_5";
gpios = <&shift_io 2 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led2_ssid_1 {
label = "mob2_ssid_1";
gpios = <&shift_io 8 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led2_ssid_3 {
label = "mob2_ssid_3";
gpios = <&shift_io 9 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led2_ssid_5 {
label = "mob2_ssid_5";
gpios = <&shift_io 10 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_wifi_24 {
label = "wifi_gen_2";
gpios = <&shift_io 22 GPIO_ACTIVE_HIGH>;
};
led_wifi_50 {
label = "wifi_gen_5";
gpios = <&shift_io 23 GPIO_ACTIVE_HIGH>;
};
};
};
};

View file

@ -0,0 +1,99 @@
#include "qcom-ipq4018-rutx-common.dtsi"
#include "qcom-ipq4018-rutx-shiftreg.dtsi"
/ {
model = "Teltonika RUTX14";
soc {
gpio-export {
compatible = "gpio-export";
#size-cells = <0>;
gpio_modem_reset {
gpio-export,name = "modem_reset";
gpio-export,output = <0>;
gpios = <&shift_io 8 GPIO_ACTIVE_HIGH>;
};
gpio_modem_power {
gpio-export,name = "modem_power";
gpio-export,output = <0>;
gpios = <&shift_io 9 GPIO_ACTIVE_HIGH>;
};
gpio_out_1 {
gpio-export,name = "gpio23";
gpio-export,output = <0>;
gpios = <&shift_io 10 GPIO_ACTIVE_HIGH>;
};
gpio_in_1 {
gpio-export,name = "gpio24";
gpio-export,input = <0>;
gpios = <&tlmm 0 GPIO_ACTIVE_HIGH>;
};
};
leds {
compatible = "gpio-leds";
led_wan_sim1 {
label = "wan_sim_1";
gpios = <&shift_io 14 GPIO_ACTIVE_HIGH>;
};
led_wan_sim2 {
label = "wan_sim_2";
gpios = <&shift_io 15 GPIO_ACTIVE_HIGH>;
};
led_wan_eth {
label = "wan_eth_3";
gpios = <&shift_io 7 GPIO_ACTIVE_HIGH>;
};
led_wan_wifi {
label = "wan_wifi_4";
gpios = <&shift_io 6 GPIO_ACTIVE_HIGH>;
};
led_gen_3 {
label = "mob_gen_3";
gpios = <&shift_io 5 GPIO_ACTIVE_HIGH>;
};
led_gen_4 {
label = "mob_gen_4";
gpios = <&shift_io 4 GPIO_ACTIVE_HIGH>;
};
led_ssid_1 {
label = "mob_ssid_1";
gpios = <&shift_io 0 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_ssid_3 {
label = "mob_ssid_3";
gpios = <&shift_io 1 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_ssid_5 {
label = "mob_ssid_5";
gpios = <&shift_io 2 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_wifi_24 {
label = "wifi_gen_2";
gpios = <&shift_io 12 GPIO_ACTIVE_HIGH>;
};
led_wifi_50 {
label = "wifi_gen_5";
gpios = <&shift_io 13 GPIO_ACTIVE_HIGH>;
};
};
};
};

View file

@ -0,0 +1,111 @@
#include "qcom-ipq4018-rutx-common.dtsi"
#include "qcom-ipq4018-rutx-shiftreg.dtsi"
/ {
model = "Teltonika RUTX50";
soc {
ext_io {
shift_io: shift_io@0 {
registers-number = <2>;
};
};
gpio-export {
compatible = "gpio-export";
#size-cells = <0>;
gpio_modem_reset {
gpio-export,name = "modem_reset";
gpio-export,output = <0>;
gpios = <&shift_io 8 GPIO_ACTIVE_HIGH>;
};
gpio_modem_power {
gpio-export,name = "modem_power";
gpio-export,output = <0>;
gpios = <&shift_io 9 GPIO_ACTIVE_HIGH>;
};
gpio_out_1 {
gpio-export,name = "gpio23";
gpio-export,output = <0>;
gpios = <&shift_io 10 GPIO_ACTIVE_HIGH>;
};
gpio_in_1 {
gpio-export,name = "gpio24";
gpio-export,input = <0>;
gpios = <&tlmm 0 GPIO_ACTIVE_HIGH>;
};
};
leds {
compatible = "gpio-leds";
led_wan_sim1 {
label = "wan_sim_1";
gpios = <&shift_io 14 GPIO_ACTIVE_HIGH>;
};
led_wan_sim2 {
label = "wan_sim_2";
gpios = <&shift_io 15 GPIO_ACTIVE_HIGH>;
};
led_wan_eth {
label = "wan_eth_3";
gpios = <&shift_io 6 GPIO_ACTIVE_HIGH>;
};
led_wan_wifi {
label = "wan_wifi_4";
gpios = <&shift_io 7 GPIO_ACTIVE_HIGH>;
};
led_gen_3 {
label = "mob_gen_3";
gpios = <&shift_io 5 GPIO_ACTIVE_HIGH>;
};
led_gen_4 {
label = "mob_gen_4";
gpios = <&shift_io 4 GPIO_ACTIVE_HIGH>;
};
led_gen_5 {
label = "mob_gen_5";
gpios = <&shift_io 3 GPIO_ACTIVE_HIGH>;
};
led_ssid_1 {
label = "mob_ssid_1";
gpios = <&shift_io 0 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_ssid_3 {
label = "mob_ssid_3";
gpios = <&shift_io 1 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_ssid_5 {
label = "mob_ssid_5";
gpios = <&shift_io 2 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_wifi_24 {
label = "wifi_gen_2";
gpios = <&shift_io 12 GPIO_ACTIVE_HIGH>;
};
led_wifi_50 {
label = "wifi_gen_5";
gpios = <&shift_io 13 GPIO_ACTIVE_HIGH>;
};
};
};
};

View file

@ -0,0 +1,84 @@
#include "qcom-ipq4018-rutx-common.dtsi"
#include "qcom-ipq4018-rutx-shiftreg.dtsi"
#include "qcom-ipq4018-rutx-i2c.dtsi" // SFP
/ {
model = "Teltonika RUTXR1";
soc {
gpio-export {
compatible = "gpio-export";
#size-cells = <0>;
gpio_modem_reset {
gpio-export,name = "modem_reset";
gpio-export,output = <0>;
gpios = <&shift_io 1 GPIO_ACTIVE_HIGH>;
};
gpio_modem_power {
gpio-export,name = "modem_power";
gpio-export,output = <0>;
gpios = <&shift_io 2 GPIO_ACTIVE_HIGH>;
};
gpio_sim_select {
gpio-export,name = "sim_sel";
gpio-export,output = <1>;
gpios = <&shift_io 3 GPIO_ACTIVE_LOW>;
};
};
leds {
compatible = "gpio-leds";
led_wan_sim1 {
label = "wan_sim_1";
gpios = <&shift_io 4 GPIO_ACTIVE_HIGH>;
};
led_wan_sim2 {
label = "wan_sim_2";
gpios = <&shift_io 5 GPIO_ACTIVE_HIGH>;
};
led_wan_eth {
label = "wan_wifi_4"; // not wan_eth_3 !
gpios = <&shift_io 11 GPIO_ACTIVE_HIGH>;
};
led_wan_mob {
label = "wan_mob_5";
gpios = <&shift_io 0 GPIO_ACTIVE_HIGH>;
};
led_gen_3 {
label = "mob_gen_3";
gpios = <&shift_io 6 GPIO_ACTIVE_HIGH>;
};
led_gen_4 {
label = "mob_gen_4";
gpios = <&shift_io 7 GPIO_ACTIVE_HIGH>;
};
led_ssid_1 {
label = "mob_ssid_1";
gpios = <&shift_io 8 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_ssid_3 {
label = "mob_ssid_3";
gpios = <&shift_io 9 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_ssid_5 {
label = "mob_ssid_5";
gpios = <&shift_io 10 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
};
};
};

View file

@ -0,0 +1,188 @@
#include "qcom-ipq4018-rutx-common.dtsi"
#include "qcom-ipq4018-rutx-i2c.dtsi"
/ {
model = "Teltonika RUTX STM32";
io_expander = "stm32";
soc {
i2c_0: i2c@78b7000 {
stm32_io: stm32@74 {
#gpio-cells = <2>;
compatible = "tlt,stm32v1";
reg = <0x74>;
gpio-controller;
interrupt-parent = <&tlmm>;
interrupts = <5 2>;
interrupt-controller;
#interrupt-cells = <2>;
};
};
gpio-export {
compatible = "gpio-export";
#size-cells = <0>;
gpio_modem_reset {
gpio-export,name = "modem1_reset";
gpio-export,output = <0>;
gpios = <&stm32_io 21 GPIO_ACTIVE_HIGH>;
};
gpio_modem_power {
gpio-export,name = "modem1_power";
gpio-export,output = <0>;
gpios = <&stm32_io 20 GPIO_ACTIVE_HIGH>;
};
gpio_modem2_reset {
gpio-export,name = "modem2_reset";
gpio-export,output = <0>;
gpios = <&stm32_io 13 GPIO_ACTIVE_HIGH>;
};
gpio_modem2_power {
gpio-export,name = "modem2_power";
gpio-export,output = <0>;
gpios = <&stm32_io 14 GPIO_ACTIVE_HIGH>;
};
gpio_sim_select {
gpio-export,name = "sim_sel";
gpio-export,output = <1>;
gpios = <&stm32_io 22 GPIO_ACTIVE_LOW>;
};
gpio_out_1 {
gpio-export,name = "gpio23";
gpio-export,output = <0>;
gpio-export,direction_may_change;
gpios = <&stm32_io 23 GPIO_ACTIVE_HIGH>;
};
gpio_in_1 {
gpio-export,name = "gpio24";
gpio-export,input = <0>;
gpio-export,direction_may_change;
gpios = <&stm32_io 24 GPIO_ACTIVE_LOW>;
};
};
leds {
compatible = "gpio-leds";
led_wan_sim1 {
label = "wan_sim_1";
gpios = <&stm32_io 0 GPIO_ACTIVE_HIGH>;
};
led_wan_sim2 {
label = "wan_sim_2";
gpios = <&stm32_io 1 GPIO_ACTIVE_HIGH>;
};
led_wan_eth {
label = "wan_eth_3";
gpios = <&stm32_io 2 GPIO_ACTIVE_HIGH>;
};
led_wan_wifi {
label = "wan_wifi_4";
gpios = <&stm32_io 3 GPIO_ACTIVE_HIGH>;
};
led_wan_mob {
label = "wan_mob_5";
gpios = <&stm32_io 16 GPIO_ACTIVE_HIGH>;
};
led_gen_2 {
label = "mob_gen_2";
gpios = <&stm32_io 4 GPIO_ACTIVE_HIGH>;
};
led_gen_3 {
label = "mob_gen_3";
gpios = <&stm32_io 5 GPIO_ACTIVE_HIGH>;
};
led_gen_4 {
label = "mob_gen_4";
gpios = <&stm32_io 6 GPIO_ACTIVE_HIGH>;
};
led2_gen_2 {
label = "mob2_gen_2";
gpios = <&stm32_io 32 GPIO_ACTIVE_HIGH>;
};
led2_gen_3 {
label = "mob2_gen_3";
gpios = <&stm32_io 33 GPIO_ACTIVE_HIGH>;
};
led2_gen_4 {
label = "mob2_gen_4";
gpios = <&stm32_io 34 GPIO_ACTIVE_HIGH>;
};
led_ssid_1 {
label = "mob_ssid_1";
gpios = <&stm32_io 7 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_ssid_2 {
label = "mob_ssid_2";
gpios = <&stm32_io 8 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_ssid_3 {
label = "mob_ssid_3";
gpios = <&stm32_io 9 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_ssid_4 {
label = "mob_ssid_4";
gpios = <&stm32_io 10 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_ssid_5 {
label = "mob_ssid_5";
gpios = <&stm32_io 11 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led2_ssid_1 {
label = "mob2_ssid_1";
gpios = <&stm32_io 31 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led2_ssid_3 {
label = "mob2_ssid_3";
gpios = <&stm32_io 30 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led2_ssid_5 {
label = "mob2_ssid_5";
gpios = <&stm32_io 29 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
led_wifi_24 {
label = "wifi_gen_2";
gpios = <&stm32_io 19 GPIO_ACTIVE_HIGH>;
};
led_wifi_50 {
label = "wifi_gen_5";
gpios = <&stm32_io 18 GPIO_ACTIVE_HIGH>;
};
};
};
};

View file

@ -0,0 +1,84 @@
#include "qcom-ipq4019-ap.dk01.1.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include "platform_name.dtsi"
/ {
compatible = "teltonika,rutx", "qcom,ap-dk01.1-c2", "qcom,ipq4019";
memory {
device_type = "memory";
reg = <0x80000000 0x10000000>;
};
soc {
mdio@90000 {
status = "ok";
pinctrl-0 = <&mdio_pins>;
pinctrl-names = "default";
phy-reset-gpio = <&tlmm 62 0>;
ethphy4: ethernet-phy@4 {
qcom,fiber-enable;
};
};
pinctrl@1000000 {
mdio_pins: mdio_pinmux {
mux_1 {
pins = "gpio53";
function = "mdio";
bias-pull-up;
};
mux_2 {
pins = "gpio52";
function = "mdc";
bias-pull-up;
};
};
};
spi_0: spi@78b5000 {
cs-gpios = <&tlmm 54 0>, <&tlmm 63 0>;
num-cs = <2>;
mx25l25635f@0 {
compatible = "n25q128a11", "mx25l25635f", "jedec,spi-nor";
#address-cells = <1>;
#size-cells = <1>;
reg = <0>;
spi-max-frequency = <24000000>;
};
mt29f@1 {
#address-cells = <1>;
#size-cells = <1>;
compatible = "spi-nand","spinand,mt29f";
reg = <1>;
spi-max-frequency = <24000000>;
};
};
gpio_keys {
compatible = "gpio-keys";
reset {
label = "reset";
gpios = <&tlmm 4 1>;
linux,code = <0x198>;
};
};
usb3: usb3@8af8800 {
dwc3@8a00000 {
snps,dis_u2_susphy_quirk;
snps,dis_u3_susphy_quirk;
};
};
usb2: usb2@60f8800 {
dwc3@6000000 {
snps,dis_u2_susphy_quirk;
};
};
};
};

View file

@ -0,0 +1,20 @@
/ {
soc {
pinctrl@1000000 {
i2c_0_pins: i2c_0_pinmux {
mux {
pins = "gpio58", "gpio59";
function = "blsp_i2c0";
bias-disable;
};
};
};
i2c_0: i2c@78b7000 { /* BLSP1 QUP2 */
pinctrl-0 = <&i2c_0_pins>;
pinctrl-names = "default";
clock-frequency = <400000>;
status = "ok";
};
};
};

View file

@ -0,0 +1,25 @@
/ {
io_expander = "shiftreg_1";
soc {
ext_io {
compatible = "spi-gpio";
#address-cells = <1>;
#size-cells = <0>;
gpio-sck = <&tlmm 1 GPIO_ACTIVE_HIGH>; // SRCLK
gpio-mosi = <&tlmm 3 GPIO_ACTIVE_HIGH>; // SER
cs-gpios = <&tlmm 2 GPIO_ACTIVE_HIGH>; // RCLK
num-chipselects = <1>;
shift_io: shift_io@0 {
compatible = "fairchild,74hc595";
reg = <0>;
gpio-controller;
#gpio-cells = <2>;
registers-number = <3>;
spi-max-frequency = <10000000>;
};
};
};
};

View file

@ -0,0 +1,18 @@
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
#include "qcom-ipq4019-r619ac.dtsi"
/ {
model = "P&W R619AC 128M";
compatible = "p2w,r619ac-128m";
};
&nand_rootfs {
/*
* Watch out: stock MIBIB is set up for a 64MiB chip.
* If a 128MiB flash chip is used, make sure to have
* the right values in MIBIB or the device might not
* boot.
*/
reg = <0x0 0x8000000>;
};

View file

@ -0,0 +1,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
#include "qcom-ipq4019-r619ac.dtsi"
/ {
model = "P&W R619AC 64M";
compatible = "p2w,r619ac-64m";
};
&nand_rootfs {
reg = <0x0 0x4000000>;
};

View file

@ -0,0 +1,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
#include "qcom-ipq4019-r619ac.dtsi"
/ {
model = "P&W R619AC";
compatible = "p2w,r619ac";
chosen {
bootargs-append = " root=/dev/ubiblock0_1 rootfstype=squashfs";
};
};

View file

@ -0,0 +1,364 @@
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
#include "qcom-ipq4019.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/soc/qcom,tcsr.h>
#include <dt-bindings/leds/common.h>
/ {
chosen {
bootargs-append = " ubi.mtd=ubi root=/dev/ubiblock0_1";
};
aliases {
led-boot = &led_sys;
led-failsafe = &led_sys;
led-running = &led_sys;
led-upgrade = &led_sys;
label-mac-device = &gmac0;
};
soc {
rng@22000 {
status = "okay";
};
mdio@90000 {
status = "okay";
pinctrl-0 = <&mdio_pins>;
pinctrl-names = "default";
};
ess-psgmii@98000 {
status = "okay";
};
tcsr@1949000 {
compatible = "qcom,tcsr";
reg = <0x1949000 0x100>;
qcom,wifi_glb_cfg = <TCSR_WIFI_GLB_CFG>;
};
tcsr@194b000 {
compatible = "qcom,tcsr";
reg = <0x194b000 0x100>;
qcom,usb-hsphy-mode-select = <TCSR_USB_HSPHY_HOST_MODE>;
};
ess_tcsr@1953000 {
compatible = "qcom,tcsr";
reg = <0x1953000 0x1000>;
qcom,ess-interface-select = <TCSR_ESS_PSGMII>;
};
tcsr@1957000 {
compatible = "qcom,tcsr";
reg = <0x1957000 0x100>;
qcom,wifi_noc_memtype_m0_m2 = <TCSR_WIFI_NOC_MEMTYPE_M0_M2>;
};
usb2@60f8800 {
status = "okay";
};
usb3@8af8800 {
status = "okay";
};
crypto@8e3a000 {
status = "okay";
};
watchdog@b017000 {
status = "okay";
};
ess-switch@c000000 {
status = "okay";
};
edma@c080000 {
status = "okay";
};
};
leds {
compatible = "gpio-leds";
led_sys: led-0 {
label = "blue:sys";
gpios = <&tlmm 39 GPIO_ACTIVE_HIGH>;
color = <LED_COLOR_ID_BLUE>;
function = LED_FUNCTION_POWER;
};
led-1 {
label = "blue:wlan2g";
gpios = <&tlmm 32 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "phy0tpt";
color = <LED_COLOR_ID_BLUE>;
function = LED_FUNCTION_WLAN;
function-enumerator = <0>;
};
led-2 {
label = "blue:wlan5g";
gpios = <&tlmm 50 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "phy1tpt";
color = <LED_COLOR_ID_BLUE>;
function = LED_FUNCTION_WLAN;
function-enumerator = <1>;
};
};
keys {
compatible = "gpio-keys";
reset {
label = "reset";
gpios = <&tlmm 18 GPIO_ACTIVE_LOW>;
linux,code = <KEY_RESTART>;
};
};
};
&blsp_dma {
status = "okay";
};
&blsp1_spi1 {
status = "okay";
flash@0 {
reg = <0>;
compatible = "jedec,spi-nor";
spi-max-frequency = <24000000>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
label = "SBL1";
reg = <0x0 0x40000>;
read-only;
};
partition@40000 {
label = "MIBIB";
reg = <0x40000 0x20000>;
read-only;
};
partition@60000 {
label = "QSEE";
reg = <0x60000 0x60000>;
read-only;
};
partition@c0000 {
label = "CDT";
reg = <0xc0000 0x10000>;
read-only;
};
partition@d0000 {
label = "DDRPARAMS";
reg = <0xd0000 0x10000>;
read-only;
};
partition@e0000 {
label = "APPSBLENV";
reg = <0xe0000 0x10000>;
read-only;
};
partition@f0000 {
label = "APPSBL";
reg = <0xf0000 0x80000>;
read-only;
};
partition@170000 {
label = "ART";
reg = <0x170000 0x10000>;
read-only;
compatible = "nvmem-cells";
#address-cells = <1>;
#size-cells = <1>;
precal_art_1000: precal@1000 {
reg = <0x1000 0x2f20>;
};
precal_art_5000: precal@5000 {
reg = <0x5000 0x2f20>;
};
};
};
};
};
&nand {
status = "okay";
nand@0 {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
nand_rootfs: partition@0 {
label = "ubi";
/* reg defined in 64M/128M variant dts. */
};
};
};
};
&blsp1_uart1 {
pinctrl-0 = <&serial_0_pins>;
pinctrl-names = "default";
status = "okay";
};
&cryptobam {
status = "okay";
};
&pcie0 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&pcie_pins>;
perst-gpio = <&tlmm 4 GPIO_ACTIVE_LOW>;
wake-gpio = <&tlmm 40 GPIO_ACTIVE_HIGH>;
/* Free slot for use */
bridge@0,0 {
reg = <0x00000000 0 0 0 0>;
#address-cells = <3>;
#size-cells = <2>;
ranges;
};
};
&qpic_bam {
status = "okay";
};
&sdhci {
pinctrl-0 = <&sd_0_pins>;
pinctrl-names = "default";
vqmmc-supply = <&vqmmc>;
status = "okay";
};
&tlmm {
pcie_pins: pcie_pinmux {
mux {
pins = "gpio2";
function = "gpio";
output-low;
bias-pull-down;
};
};
mdio_pins: mdio_pinmux {
mux_1 {
pins = "gpio6";
function = "mdio";
bias-pull-up;
};
mux_2 {
pins = "gpio7";
function = "mdc";
bias-pull-up;
};
};
sd_0_pins: sd_0_pinmux {
mux_1 {
pins = "gpio23", "gpio24", "gpio25", "gpio26", "gpio28";
function = "sdio";
drive-strength = <10>;
};
mux_2 {
pins = "gpio27";
function = "sdio";
drive-strength = <16>;
};
};
serial_0_pins: serial0-pinmux {
mux {
pins = "gpio16", "gpio17";
function = "blsp_uart0";
bias-disable;
};
};
};
&ethphy0 {
qcom,single-led-1000;
qcom,single-led-100;
qcom,single-led-10;
};
&ethphy1 {
qcom,single-led-1000;
qcom,single-led-100;
qcom,single-led-10;
};
&ethphy2 {
qcom,single-led-1000;
qcom,single-led-100;
qcom,single-led-10;
};
&ethphy3 {
qcom,single-led-1000;
qcom,single-led-100;
qcom,single-led-10;
};
&ethphy4 {
qcom,single-led-1000;
qcom,single-led-100;
qcom,single-led-10;
};
&usb3_ss_phy {
status = "okay";
};
&usb3_hs_phy {
status = "okay";
};
&usb2_hs_phy {
status = "okay";
};
&vqmmc {
status = "okay";
};
&wifi0 {
status = "okay";
nvmem-cell-names = "pre-calibration";
nvmem-cells = <&precal_art_1000>;
qcom,ath10k-calibration-variant = "P&W R619AC";
};
&wifi1 {
status = "okay";
nvmem-cell-names = "pre-calibration";
nvmem-cells = <&precal_art_5000>;
qcom,ath10k-calibration-variant = "P&W R619AC";
};

View file

@ -0,0 +1,350 @@
/*
* Copyright (c) 2015 - 2016, The Linux Foundation. All rights reserved.
*
* Permission to use, copy, modify, and/or distribute this software for
* any purpose with or without fee is hereby granted, provided that the
* above copyright notice and this permission notice appear in all copies.
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <linux/ethtool.h>
#include <linux/netdevice.h>
#include <linux/string.h>
#include <linux/version.h>
#include "edma.h"
struct edma_ethtool_stats {
uint8_t stat_string[ETH_GSTRING_LEN];
uint32_t stat_offset;
};
#define EDMA_STAT(m) offsetof(struct edma_ethtool_statistics, m)
#define DRVINFO_LEN 32
/* Array of strings describing statistics
*/
static const struct edma_ethtool_stats edma_gstrings_stats[] = {
{"tx_q0_pkt", EDMA_STAT(tx_q0_pkt)},
{"tx_q1_pkt", EDMA_STAT(tx_q1_pkt)},
{"tx_q2_pkt", EDMA_STAT(tx_q2_pkt)},
{"tx_q3_pkt", EDMA_STAT(tx_q3_pkt)},
{"tx_q4_pkt", EDMA_STAT(tx_q4_pkt)},
{"tx_q5_pkt", EDMA_STAT(tx_q5_pkt)},
{"tx_q6_pkt", EDMA_STAT(tx_q6_pkt)},
{"tx_q7_pkt", EDMA_STAT(tx_q7_pkt)},
{"tx_q8_pkt", EDMA_STAT(tx_q8_pkt)},
{"tx_q9_pkt", EDMA_STAT(tx_q9_pkt)},
{"tx_q10_pkt", EDMA_STAT(tx_q10_pkt)},
{"tx_q11_pkt", EDMA_STAT(tx_q11_pkt)},
{"tx_q12_pkt", EDMA_STAT(tx_q12_pkt)},
{"tx_q13_pkt", EDMA_STAT(tx_q13_pkt)},
{"tx_q14_pkt", EDMA_STAT(tx_q14_pkt)},
{"tx_q15_pkt", EDMA_STAT(tx_q15_pkt)},
{"tx_q0_byte", EDMA_STAT(tx_q0_byte)},
{"tx_q1_byte", EDMA_STAT(tx_q1_byte)},
{"tx_q2_byte", EDMA_STAT(tx_q2_byte)},
{"tx_q3_byte", EDMA_STAT(tx_q3_byte)},
{"tx_q4_byte", EDMA_STAT(tx_q4_byte)},
{"tx_q5_byte", EDMA_STAT(tx_q5_byte)},
{"tx_q6_byte", EDMA_STAT(tx_q6_byte)},
{"tx_q7_byte", EDMA_STAT(tx_q7_byte)},
{"tx_q8_byte", EDMA_STAT(tx_q8_byte)},
{"tx_q9_byte", EDMA_STAT(tx_q9_byte)},
{"tx_q10_byte", EDMA_STAT(tx_q10_byte)},
{"tx_q11_byte", EDMA_STAT(tx_q11_byte)},
{"tx_q12_byte", EDMA_STAT(tx_q12_byte)},
{"tx_q13_byte", EDMA_STAT(tx_q13_byte)},
{"tx_q14_byte", EDMA_STAT(tx_q14_byte)},
{"tx_q15_byte", EDMA_STAT(tx_q15_byte)},
{"rx_q0_pkt", EDMA_STAT(rx_q0_pkt)},
{"rx_q1_pkt", EDMA_STAT(rx_q1_pkt)},
{"rx_q2_pkt", EDMA_STAT(rx_q2_pkt)},
{"rx_q3_pkt", EDMA_STAT(rx_q3_pkt)},
{"rx_q4_pkt", EDMA_STAT(rx_q4_pkt)},
{"rx_q5_pkt", EDMA_STAT(rx_q5_pkt)},
{"rx_q6_pkt", EDMA_STAT(rx_q6_pkt)},
{"rx_q7_pkt", EDMA_STAT(rx_q7_pkt)},
{"rx_q0_byte", EDMA_STAT(rx_q0_byte)},
{"rx_q1_byte", EDMA_STAT(rx_q1_byte)},
{"rx_q2_byte", EDMA_STAT(rx_q2_byte)},
{"rx_q3_byte", EDMA_STAT(rx_q3_byte)},
{"rx_q4_byte", EDMA_STAT(rx_q4_byte)},
{"rx_q5_byte", EDMA_STAT(rx_q5_byte)},
{"rx_q6_byte", EDMA_STAT(rx_q6_byte)},
{"rx_q7_byte", EDMA_STAT(rx_q7_byte)},
{"tx_desc_error", EDMA_STAT(tx_desc_error)},
{"rx_alloc_fail_ctr", EDMA_STAT(rx_alloc_fail_ctr)},
};
#define EDMA_STATS_LEN ARRAY_SIZE(edma_gstrings_stats)
/* edma_get_strset_count()
* Get strset count
*/
static int edma_get_strset_count(struct net_device *netdev,
int sset)
{
switch (sset) {
case ETH_SS_STATS:
return EDMA_STATS_LEN;
default:
netdev_dbg(netdev, "%s: Invalid string set", __func__);
return -EOPNOTSUPP;
}
}
/* edma_get_strings()
* get stats string
*/
static void edma_get_strings(struct net_device *netdev, uint32_t stringset,
uint8_t *data)
{
uint8_t *p = data;
uint32_t i;
switch (stringset) {
case ETH_SS_STATS:
for (i = 0; i < EDMA_STATS_LEN; i++) {
memcpy(p, edma_gstrings_stats[i].stat_string,
min((size_t)ETH_GSTRING_LEN,
strlen(edma_gstrings_stats[i].stat_string)
+ 1));
p += ETH_GSTRING_LEN;
}
break;
}
}
/* edma_get_ethtool_stats()
* Get ethtool statistics
*/
static void edma_get_ethtool_stats(struct net_device *netdev,
struct ethtool_stats *stats, uint64_t *data)
{
struct edma_adapter *adapter = netdev_priv(netdev);
struct edma_common_info *edma_cinfo = adapter->edma_cinfo;
int i;
uint8_t *p = NULL;
edma_read_append_stats(edma_cinfo);
for(i = 0; i < EDMA_STATS_LEN; i++) {
p = (uint8_t *)&(edma_cinfo->edma_ethstats) +
edma_gstrings_stats[i].stat_offset;
data[i] = *(uint32_t *)p;
}
}
/* edma_get_drvinfo()
* get edma driver info
*/
static void edma_get_drvinfo(struct net_device *dev,
struct ethtool_drvinfo *info)
{
strlcpy(info->driver, "ess_edma", DRVINFO_LEN);
strlcpy(info->bus_info, "axi", ETHTOOL_BUSINFO_LEN);
}
/* edma_nway_reset()
* Reset the phy, if available.
*/
static int edma_nway_reset(struct net_device *netdev)
{
return -EINVAL;
}
/* edma_get_wol()
* get wake on lan info
*/
static void edma_get_wol(struct net_device *netdev,
struct ethtool_wolinfo *wol)
{
wol->supported = 0;
wol->wolopts = 0;
}
/* edma_get_msglevel()
* get message level.
*/
static uint32_t edma_get_msglevel(struct net_device *netdev)
{
return 0;
}
/* edma_get_settings()
* Get edma settings
*/
static int edma_get_settings(struct net_device *netdev,
struct ethtool_link_ksettings *cmd)
{
struct edma_adapter *adapter = netdev_priv(netdev);
if (adapter->poll_required) {
if ((adapter->forced_speed != SPEED_UNKNOWN)
&& !(adapter->poll_required))
return -EPERM;
phy_ethtool_ksettings_get(adapter->phydev, cmd);
if (linkmode_test_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, adapter->phydev->advertising))
cmd->base.port = PORT_FIBRE;
else
cmd->base.port = PORT_TP;
} else {
/* If the speed/duplex for this GMAC is forced and we
* are not polling for link state changes, return the
* values as specified by platform. This will be true
* for GMACs connected to switch, and interfaces that
* do not use a PHY.
*/
if (!(adapter->poll_required)) {
if (adapter->forced_speed != SPEED_UNKNOWN) {
/* set speed and duplex */
cmd->base.speed = SPEED_1000;
cmd->base.duplex = DUPLEX_FULL;
/* Populate capabilities advertised by self */
linkmode_zero(cmd->link_modes.advertising);
cmd->base.autoneg = 0;
cmd->base.port = PORT_TP;
cmd->base.transceiver = XCVR_EXTERNAL;
} else {
/* non link polled and non
* forced speed/duplex interface
*/
return -EIO;
}
}
}
return 0;
}
/* edma_set_settings()
* Set EDMA settings
*/
static int edma_set_settings(struct net_device *netdev,
const struct ethtool_link_ksettings *cmd)
{
struct edma_adapter *adapter = netdev_priv(netdev);
if ((adapter->forced_speed != SPEED_UNKNOWN) &&
!adapter->poll_required)
return -EPERM;
return phy_ethtool_ksettings_set(adapter->phydev, cmd);
}
/* edma_get_coalesce
* get interrupt mitigation
*/
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,15,0)
static int edma_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec,
struct kernel_ethtool_coalesce *kernel_coal,
struct netlink_ext_ack *extack)
#else
static int edma_get_coalesce(struct net_device *netdev,
struct ethtool_coalesce *ec)
#endif
{
u32 reg_val;
edma_get_tx_rx_coalesce(&reg_val);
/* We read the Interrupt Moderation Timer(IMT) register value,
* use lower 16 bit for rx and higher 16 bit for Tx. We do a
* left shift by 1, because IMT resolution timer is 2usecs.
* Hence the value given by the register is multiplied by 2 to
* get the actual time in usecs.
*/
ec->tx_coalesce_usecs = (((reg_val >> 16) & 0xffff) << 1);
ec->rx_coalesce_usecs = ((reg_val & 0xffff) << 1);
return 0;
}
/* edma_set_coalesce
* set interrupt mitigation
*/
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,15,0)
static int edma_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec,
struct kernel_ethtool_coalesce *kernel_coal,
struct netlink_ext_ack *extack)
#else
static int edma_set_coalesce(struct net_device *netdev,
struct ethtool_coalesce *ec)
#endif
{
if (ec->tx_coalesce_usecs)
edma_change_tx_coalesce(ec->tx_coalesce_usecs);
if (ec->rx_coalesce_usecs)
edma_change_rx_coalesce(ec->rx_coalesce_usecs);
return 0;
}
/* edma_set_priv_flags()
* Set EDMA private flags
*/
static int edma_set_priv_flags(struct net_device *netdev, u32 flags)
{
return 0;
}
/* edma_get_priv_flags()
* get edma driver flags
*/
static u32 edma_get_priv_flags(struct net_device *netdev)
{
return 0;
}
/* edma_get_ringparam()
* get ring size
*/
static void edma_get_ringparam(struct net_device *netdev,
struct ethtool_ringparam *ring)
{
struct edma_adapter *adapter = netdev_priv(netdev);
struct edma_common_info *edma_cinfo = adapter->edma_cinfo;
ring->tx_max_pending = edma_cinfo->tx_ring_count;
ring->rx_max_pending = edma_cinfo->rx_ring_count;
}
/* Ethtool operations
*/
static const struct ethtool_ops edma_ethtool_ops = {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,7,0)
.supported_coalesce_params = ETHTOOL_COALESCE_USECS,
#endif
.get_drvinfo = &edma_get_drvinfo,
.get_link = &ethtool_op_get_link,
.get_msglevel = &edma_get_msglevel,
.nway_reset = &edma_nway_reset,
.get_wol = &edma_get_wol,
.get_link_ksettings = &edma_get_settings,
.set_link_ksettings = &edma_set_settings,
.get_strings = &edma_get_strings,
.get_sset_count = &edma_get_strset_count,
.get_ethtool_stats = &edma_get_ethtool_stats,
.get_coalesce = &edma_get_coalesce,
.set_coalesce = &edma_set_coalesce,
.get_priv_flags = edma_get_priv_flags,
.set_priv_flags = edma_set_priv_flags,
.get_ringparam = edma_get_ringparam,
};
/* edma_set_ethtool_ops
* Set ethtool operations
*/
void edma_set_ethtool_ops(struct net_device *netdev)
{
netdev->ethtool_ops = &edma_ethtool_ops;
}

View file

@ -0,0 +1,865 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2020 Sartura Ltd.
*
* Author: Robert Marko <robert.marko@sartura.hr>
*
* Qualcomm QCA8072 and QCA8075 PHY driver
*/
#include <linux/version.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/phy.h>
#include <linux/bitfield.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,8,0)
#include <linux/ethtool_netlink.h>
#endif
#include <linux/gpio.h>
#include <linux/sfp.h>
#include <dt-bindings/net/qcom-qca807x.h>
#define PHY_ID_QCA8072 0x004dd0b2
#define PHY_ID_QCA8075 0x004dd0b1
#define PHY_ID_QCA807X_PSGMII 0x06820805
/* Downshift */
#define QCA807X_SMARTSPEED_EN BIT(5)
#define QCA807X_SMARTSPEED_RETRY_LIMIT_MASK GENMASK(4, 2)
#define QCA807X_SMARTSPEED_RETRY_LIMIT_DEFAULT 5
#define QCA807X_SMARTSPEED_RETRY_LIMIT_MIN 2
#define QCA807X_SMARTSPEED_RETRY_LIMIT_MAX 9
/* Cable diagnostic test (CDT) */
#define QCA807X_CDT 0x16
#define QCA807X_CDT_ENABLE BIT(15)
#define QCA807X_CDT_ENABLE_INTER_PAIR_SHORT BIT(13)
#define QCA807X_CDT_STATUS BIT(11)
#define QCA807X_CDT_MMD3_STATUS 0x8064
#define QCA807X_CDT_MDI0_STATUS_MASK GENMASK(15, 12)
#define QCA807X_CDT_MDI1_STATUS_MASK GENMASK(11, 8)
#define QCA807X_CDT_MDI2_STATUS_MASK GENMASK(7, 4)
#define QCA807X_CDT_MDI3_STATUS_MASK GENMASK(3, 0)
#define QCA807X_CDT_RESULTS_INVALID 0x0
#define QCA807X_CDT_RESULTS_OK 0x1
#define QCA807X_CDT_RESULTS_OPEN 0x2
#define QCA807X_CDT_RESULTS_SAME_SHORT 0x3
#define QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI1_SAME_OK 0x4
#define QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI2_SAME_OK 0x8
#define QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI3_SAME_OK 0xc
#define QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI1_SAME_OPEN 0x6
#define QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI2_SAME_OPEN 0xa
#define QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI3_SAME_OPEN 0xe
#define QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI1_SAME_SHORT 0x7
#define QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI2_SAME_SHORT 0xb
#define QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI3_SAME_SHORT 0xf
#define QCA807X_CDT_RESULTS_BUSY 0x9
#define QCA807X_CDT_MMD3_MDI0_LENGTH 0x8065
#define QCA807X_CDT_MMD3_MDI1_LENGTH 0x8066
#define QCA807X_CDT_MMD3_MDI2_LENGTH 0x8067
#define QCA807X_CDT_MMD3_MDI3_LENGTH 0x8068
#define QCA807X_CDT_SAME_SHORT_LENGTH_MASK GENMASK(15, 8)
#define QCA807X_CDT_CROSS_SHORT_LENGTH_MASK GENMASK(7, 0)
#define QCA807X_CHIP_CONFIGURATION 0x1f
#define QCA807X_BT_BX_REG_SEL BIT(15)
#define QCA807X_CHIP_CONFIGURATION_MODE_CFG_MASK GENMASK(3, 0)
#define QCA807X_CHIP_CONFIGURATION_MODE_QSGMII_SGMII 4
#define QCA807X_CHIP_CONFIGURATION_MODE_PSGMII_FIBER 3
#define QCA807X_CHIP_CONFIGURATION_MODE_PSGMII_ALL_COPPER 0
#define QCA807X_MEDIA_SELECT_STATUS 0x1a
#define QCA807X_MEDIA_DETECTED_COPPER BIT(5)
#define QCA807X_MEDIA_DETECTED_1000_BASE_X BIT(4)
#define QCA807X_MEDIA_DETECTED_100_BASE_FX BIT(3)
#define QCA807X_MMD7_FIBER_MODE_AUTO_DETECTION 0x807e
#define QCA807X_MMD7_FIBER_MODE_AUTO_DETECTION_EN BIT(0)
#define QCA807X_MMD7_1000BASE_T_POWER_SAVE_PER_CABLE_LENGTH 0x801a
#define QCA807X_CONTROL_DAC_MASK GENMASK(2, 0)
#define QCA807X_MMD7_LED_100N_1 0x8074
#define QCA807X_MMD7_LED_100N_2 0x8075
#define QCA807X_MMD7_LED_1000N_1 0x8076
#define QCA807X_MMD7_LED_1000N_2 0x8077
#define QCA807X_LED_TXACT_BLK_EN_2 BIT(10)
#define QCA807X_LED_RXACT_BLK_EN_2 BIT(9)
#define QCA807X_LED_GT_ON_EN_2 BIT(6)
#define QCA807X_LED_HT_ON_EN_2 BIT(5)
#define QCA807X_LED_BT_ON_EN_2 BIT(4)
#define QCA807X_GPIO_FORCE_EN BIT(15)
#define QCA807X_GPIO_FORCE_MODE_MASK GENMASK(14, 13)
#define QCA807X_INTR_ENABLE 0x12
#define QCA807X_INTR_STATUS 0x13
#define QCA807X_INTR_ENABLE_AUTONEG_ERR BIT(15)
#define QCA807X_INTR_ENABLE_SPEED_CHANGED BIT(14)
#define QCA807X_INTR_ENABLE_DUPLEX_CHANGED BIT(13)
#define QCA807X_INTR_ENABLE_LINK_FAIL BIT(11)
#define QCA807X_INTR_ENABLE_LINK_SUCCESS BIT(10)
#define QCA807X_FUNCTION_CONTROL 0x10
#define QCA807X_FC_MDI_CROSSOVER_MODE_MASK GENMASK(6, 5)
#define QCA807X_FC_MDI_CROSSOVER_AUTO 3
#define QCA807X_FC_MDI_CROSSOVER_MANUAL_MDIX 1
#define QCA807X_FC_MDI_CROSSOVER_MANUAL_MDI 0
#define QCA807X_PHY_SPECIFIC_STATUS 0x11
#define QCA807X_SS_SPEED_AND_DUPLEX_RESOLVED BIT(11)
#define QCA807X_SS_SPEED_MASK GENMASK(15, 14)
#define QCA807X_SS_SPEED_1000 2
#define QCA807X_SS_SPEED_100 1
#define QCA807X_SS_SPEED_10 0
#define QCA807X_SS_DUPLEX BIT(13)
#define QCA807X_SS_MDIX BIT(6)
/* PSGMII PHY specific */
#define PSGMII_QSGMII_DRIVE_CONTROL_1 0xb
#define PSGMII_QSGMII_TX_DRIVER_MASK GENMASK(7, 4)
#define PSGMII_MODE_CTRL 0x6d
#define PSGMII_MODE_CTRL_AZ_WORKAROUND_MASK GENMASK(3, 0)
#define PSGMII_MMD3_SERDES_CONTROL 0x805a
struct qca807x_gpio_priv {
struct phy_device *phy;
};
static int qca807x_get_downshift(struct phy_device *phydev, u8 *data)
{
int val, cnt, enable;
val = phy_read(phydev, MII_NWAYTEST);
if (val < 0)
return val;
enable = FIELD_GET(QCA807X_SMARTSPEED_EN, val);
cnt = FIELD_GET(QCA807X_SMARTSPEED_RETRY_LIMIT_MASK, val) + 2;
*data = enable ? cnt : DOWNSHIFT_DEV_DISABLE;
return 0;
}
static int qca807x_set_downshift(struct phy_device *phydev, u8 cnt)
{
int ret, val;
if (cnt > QCA807X_SMARTSPEED_RETRY_LIMIT_MAX ||
(cnt < QCA807X_SMARTSPEED_RETRY_LIMIT_MIN && cnt != DOWNSHIFT_DEV_DISABLE))
return -EINVAL;
if (!cnt) {
ret = phy_clear_bits(phydev, MII_NWAYTEST, QCA807X_SMARTSPEED_EN);
} else {
val = QCA807X_SMARTSPEED_EN;
val |= FIELD_PREP(QCA807X_SMARTSPEED_RETRY_LIMIT_MASK, cnt - 2);
phy_modify(phydev, MII_NWAYTEST,
QCA807X_SMARTSPEED_EN |
QCA807X_SMARTSPEED_RETRY_LIMIT_MASK,
val);
}
ret = genphy_soft_reset(phydev);
return ret;
}
static int qca807x_get_tunable(struct phy_device *phydev,
struct ethtool_tunable *tuna, void *data)
{
switch (tuna->id) {
case ETHTOOL_PHY_DOWNSHIFT:
return qca807x_get_downshift(phydev, data);
default:
return -EOPNOTSUPP;
}
}
static int qca807x_set_tunable(struct phy_device *phydev,
struct ethtool_tunable *tuna, const void *data)
{
switch (tuna->id) {
case ETHTOOL_PHY_DOWNSHIFT:
return qca807x_set_downshift(phydev, *(const u8 *)data);
default:
return -EOPNOTSUPP;
}
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,8,0)
static bool qca807x_distance_valid(int result)
{
switch (result) {
case QCA807X_CDT_RESULTS_OPEN:
case QCA807X_CDT_RESULTS_SAME_SHORT:
case QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI1_SAME_OK:
case QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI2_SAME_OK:
case QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI3_SAME_OK:
case QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI1_SAME_OPEN:
case QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI2_SAME_OPEN:
case QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI3_SAME_OPEN:
case QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI1_SAME_SHORT:
case QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI2_SAME_SHORT:
case QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI3_SAME_SHORT:
return true;
}
return false;
}
static int qca807x_report_length(struct phy_device *phydev,
int pair, int result)
{
int length;
int ret;
ret = phy_read_mmd(phydev, MDIO_MMD_PCS, QCA807X_CDT_MMD3_MDI0_LENGTH + pair);
if (ret < 0)
return ret;
switch (result) {
case ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT:
length = (FIELD_GET(QCA807X_CDT_SAME_SHORT_LENGTH_MASK, ret) * 800) / 10;
break;
case ETHTOOL_A_CABLE_RESULT_CODE_OPEN:
case ETHTOOL_A_CABLE_RESULT_CODE_CROSS_SHORT:
length = (FIELD_GET(QCA807X_CDT_CROSS_SHORT_LENGTH_MASK, ret) * 800) / 10;
break;
}
ethnl_cable_test_fault_length(phydev, pair, length);
return 0;
}
static int qca807x_cable_test_report_trans(int result)
{
switch (result) {
case QCA807X_CDT_RESULTS_OK:
return ETHTOOL_A_CABLE_RESULT_CODE_OK;
case QCA807X_CDT_RESULTS_OPEN:
return ETHTOOL_A_CABLE_RESULT_CODE_OPEN;
case QCA807X_CDT_RESULTS_SAME_SHORT:
return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT;
case QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI1_SAME_OK:
case QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI2_SAME_OK:
case QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI3_SAME_OK:
case QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI1_SAME_OPEN:
case QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI2_SAME_OPEN:
case QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI3_SAME_OPEN:
case QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI1_SAME_SHORT:
case QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI2_SAME_SHORT:
case QCA807X_CDT_RESULTS_CROSS_SHORT_WITH_MDI3_SAME_SHORT:
return ETHTOOL_A_CABLE_RESULT_CODE_CROSS_SHORT;
default:
return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC;
}
}
static int qca807x_cable_test_report(struct phy_device *phydev)
{
int pair0, pair1, pair2, pair3;
int ret;
ret = phy_read_mmd(phydev, MDIO_MMD_PCS, QCA807X_CDT_MMD3_STATUS);
if (ret < 0)
return ret;
pair0 = FIELD_GET(QCA807X_CDT_MDI0_STATUS_MASK, ret);
pair1 = FIELD_GET(QCA807X_CDT_MDI1_STATUS_MASK, ret);
pair2 = FIELD_GET(QCA807X_CDT_MDI2_STATUS_MASK, ret);
pair3 = FIELD_GET(QCA807X_CDT_MDI3_STATUS_MASK, ret);
ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A,
qca807x_cable_test_report_trans(pair0));
ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_B,
qca807x_cable_test_report_trans(pair1));
ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_C,
qca807x_cable_test_report_trans(pair2));
ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_D,
qca807x_cable_test_report_trans(pair3));
if (qca807x_distance_valid(pair0))
qca807x_report_length(phydev, 0, qca807x_cable_test_report_trans(pair0));
if (qca807x_distance_valid(pair1))
qca807x_report_length(phydev, 1, qca807x_cable_test_report_trans(pair1));
if (qca807x_distance_valid(pair2))
qca807x_report_length(phydev, 2, qca807x_cable_test_report_trans(pair2));
if (qca807x_distance_valid(pair3))
qca807x_report_length(phydev, 3, qca807x_cable_test_report_trans(pair3));
return 0;
}
static int qca807x_cable_test_get_status(struct phy_device *phydev,
bool *finished)
{
int val;
*finished = false;
val = phy_read(phydev, QCA807X_CDT);
if (!((val & QCA807X_CDT_ENABLE) && (val & QCA807X_CDT_STATUS))) {
*finished = true;
return qca807x_cable_test_report(phydev);
}
return 0;
}
static int qca807x_cable_test_start(struct phy_device *phydev)
{
int val, ret;
val = phy_read(phydev, QCA807X_CDT);
/* Enable inter-pair short check as well */
val &= ~QCA807X_CDT_ENABLE_INTER_PAIR_SHORT;
val |= QCA807X_CDT_ENABLE;
ret = phy_write(phydev, QCA807X_CDT, val);
return ret;
}
#endif
#ifdef CONFIG_GPIOLIB
static int qca807x_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,5,0)
return GPIO_LINE_DIRECTION_OUT;
#else
return GPIOF_DIR_OUT;
#endif
}
static int qca807x_gpio_get_reg(unsigned int offset)
{
return QCA807X_MMD7_LED_100N_2 + (offset % 2) * 2;
}
static int qca807x_gpio_get(struct gpio_chip *gc, unsigned int offset)
{
struct qca807x_gpio_priv *priv = gpiochip_get_data(gc);
int val;
val = phy_read_mmd(priv->phy, MDIO_MMD_AN, qca807x_gpio_get_reg(offset));
return FIELD_GET(QCA807X_GPIO_FORCE_MODE_MASK, val);
}
static void qca807x_gpio_set(struct gpio_chip *gc, unsigned int offset, int value)
{
struct qca807x_gpio_priv *priv = gpiochip_get_data(gc);
int val;
val = phy_read_mmd(priv->phy, MDIO_MMD_AN, qca807x_gpio_get_reg(offset));
val &= ~QCA807X_GPIO_FORCE_MODE_MASK;
val |= QCA807X_GPIO_FORCE_EN;
val |= FIELD_PREP(QCA807X_GPIO_FORCE_MODE_MASK, value);
phy_write_mmd(priv->phy, MDIO_MMD_AN, qca807x_gpio_get_reg(offset), val);
}
static int qca807x_gpio_dir_out(struct gpio_chip *gc, unsigned int offset, int value)
{
qca807x_gpio_set(gc, offset, value);
return 0;
}
static int qca807x_gpio(struct phy_device *phydev)
{
struct device *dev = &phydev->mdio.dev;
struct qca807x_gpio_priv *priv;
struct gpio_chip *gc;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
priv->phy = phydev;
gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL);
if (!gc)
return -ENOMEM;
gc->label = dev_name(dev);
gc->base = -1;
gc->ngpio = 2;
gc->parent = dev;
gc->owner = THIS_MODULE;
gc->can_sleep = true;
gc->get_direction = qca807x_gpio_get_direction;
gc->direction_output = qca807x_gpio_dir_out;
gc->get = qca807x_gpio_get;
gc->set = qca807x_gpio_set;
return devm_gpiochip_add_data(dev, gc, priv);
}
#endif
static int qca807x_read_copper_status(struct phy_device *phydev, bool combo_port)
{
int ss, err, page, old_link = phydev->link;
/* Only combo port has dual pages */
if (combo_port) {
/* Check whether copper page is set and set if needed */
page = phy_read(phydev, QCA807X_CHIP_CONFIGURATION);
if (!(page & QCA807X_BT_BX_REG_SEL)) {
page |= QCA807X_BT_BX_REG_SEL;
phy_write(phydev, QCA807X_CHIP_CONFIGURATION, page);
}
}
/* Update the link, but return if there was an error */
err = genphy_update_link(phydev);
if (err)
return err;
/* why bother the PHY if nothing can have changed */
if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link)
return 0;
phydev->speed = SPEED_UNKNOWN;
phydev->duplex = DUPLEX_UNKNOWN;
phydev->pause = 0;
phydev->asym_pause = 0;
err = genphy_read_lpa(phydev);
if (err < 0)
return err;
/* Read the QCA807x PHY-Specific Status register copper page,
* which indicates the speed and duplex that the PHY is actually
* using, irrespective of whether we are in autoneg mode or not.
*/
ss = phy_read(phydev, QCA807X_PHY_SPECIFIC_STATUS);
if (ss < 0)
return ss;
if (ss & QCA807X_SS_SPEED_AND_DUPLEX_RESOLVED) {
int sfc;
sfc = phy_read(phydev, QCA807X_FUNCTION_CONTROL);
if (sfc < 0)
return sfc;
switch (FIELD_GET(QCA807X_SS_SPEED_MASK, ss)) {
case QCA807X_SS_SPEED_10:
phydev->speed = SPEED_10;
break;
case QCA807X_SS_SPEED_100:
phydev->speed = SPEED_100;
break;
case QCA807X_SS_SPEED_1000:
phydev->speed = SPEED_1000;
break;
}
if (ss & QCA807X_SS_DUPLEX)
phydev->duplex = DUPLEX_FULL;
else
phydev->duplex = DUPLEX_HALF;
if (ss & QCA807X_SS_MDIX)
phydev->mdix = ETH_TP_MDI_X;
else
phydev->mdix = ETH_TP_MDI;
switch (FIELD_GET(QCA807X_FC_MDI_CROSSOVER_MODE_MASK, sfc)) {
case QCA807X_FC_MDI_CROSSOVER_MANUAL_MDI:
phydev->mdix_ctrl = ETH_TP_MDI;
break;
case QCA807X_FC_MDI_CROSSOVER_MANUAL_MDIX:
phydev->mdix_ctrl = ETH_TP_MDI_X;
break;
case QCA807X_FC_MDI_CROSSOVER_AUTO:
phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
break;
}
}
if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete)
phy_resolve_aneg_pause(phydev);
return 0;
}
static int qca807x_read_fiber_status(struct phy_device *phydev, bool combo_port)
{
int ss, err, page, lpa, old_link = phydev->link;
/* Check whether fiber page is set and set if needed */
page = phy_read(phydev, QCA807X_CHIP_CONFIGURATION);
if (page & QCA807X_BT_BX_REG_SEL) {
page &= ~QCA807X_BT_BX_REG_SEL;
phy_write(phydev, QCA807X_CHIP_CONFIGURATION, page);
}
/* Update the link, but return if there was an error */
err = genphy_update_link(phydev);
if (err)
return err;
/* why bother the PHY if nothing can have changed */
if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link)
return 0;
phydev->speed = SPEED_UNKNOWN;
phydev->duplex = DUPLEX_UNKNOWN;
phydev->pause = 0;
phydev->asym_pause = 0;
if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) {
lpa = phy_read(phydev, MII_LPA);
if (lpa < 0)
return lpa;
linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
phydev->lp_advertising, lpa & LPA_LPACK);
linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
phydev->lp_advertising, lpa & LPA_1000XFULL);
linkmode_mod_bit(ETHTOOL_LINK_MODE_Pause_BIT,
phydev->lp_advertising, lpa & LPA_1000XPAUSE);
linkmode_mod_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
phydev->lp_advertising,
lpa & LPA_1000XPAUSE_ASYM);
phy_resolve_aneg_linkmode(phydev);
}
/* Read the QCA807x PHY-Specific Status register fiber page,
* which indicates the speed and duplex that the PHY is actually
* using, irrespective of whether we are in autoneg mode or not.
*/
ss = phy_read(phydev, QCA807X_PHY_SPECIFIC_STATUS);
if (ss < 0)
return ss;
if (ss & QCA807X_SS_SPEED_AND_DUPLEX_RESOLVED) {
switch (FIELD_GET(QCA807X_SS_SPEED_MASK, ss)) {
case QCA807X_SS_SPEED_100:
phydev->speed = SPEED_100;
break;
case QCA807X_SS_SPEED_1000:
phydev->speed = SPEED_1000;
break;
}
if (ss & QCA807X_SS_DUPLEX)
phydev->duplex = DUPLEX_FULL;
else
phydev->duplex = DUPLEX_HALF;
}
return 0;
}
static int qca807x_read_status(struct phy_device *phydev)
{
int val;
/* Check for Combo port */
if (phy_read(phydev, QCA807X_CHIP_CONFIGURATION)) {
/* Check for fiber mode first */
if (linkmode_test_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, phydev->supported)) {
/* Check for actual detected media */
val = phy_read(phydev, QCA807X_MEDIA_SELECT_STATUS);
if (val & QCA807X_MEDIA_DETECTED_COPPER) {
qca807x_read_copper_status(phydev, true);
} else if ((val & QCA807X_MEDIA_DETECTED_1000_BASE_X) ||
(val & QCA807X_MEDIA_DETECTED_100_BASE_FX)) {
qca807x_read_fiber_status(phydev, true);
}
} else {
qca807x_read_copper_status(phydev, true);
}
} else {
qca807x_read_copper_status(phydev, false);
}
return 0;
}
static int qca807x_config_intr(struct phy_device *phydev)
{
int ret, val;
val = phy_read(phydev, QCA807X_INTR_ENABLE);
if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
/* Check for combo port as it has fewer interrupts */
if (phy_read(phydev, QCA807X_CHIP_CONFIGURATION)) {
val |= QCA807X_INTR_ENABLE_SPEED_CHANGED;
val |= QCA807X_INTR_ENABLE_LINK_FAIL;
val |= QCA807X_INTR_ENABLE_LINK_SUCCESS;
} else {
val |= QCA807X_INTR_ENABLE_AUTONEG_ERR;
val |= QCA807X_INTR_ENABLE_SPEED_CHANGED;
val |= QCA807X_INTR_ENABLE_DUPLEX_CHANGED;
val |= QCA807X_INTR_ENABLE_LINK_FAIL;
val |= QCA807X_INTR_ENABLE_LINK_SUCCESS;
}
ret = phy_write(phydev, QCA807X_INTR_ENABLE, val);
} else {
ret = phy_write(phydev, QCA807X_INTR_ENABLE, 0);
}
return ret;
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,12,0)
static int qca807x_ack_intr(struct phy_device *phydev)
{
int ret;
ret = phy_read(phydev, QCA807X_INTR_STATUS);
return (ret < 0) ? ret : 0;
}
#else
static irqreturn_t qca807x_handle_interrupt(struct phy_device *phydev)
{
int irq_status, int_enabled;
irq_status = phy_read(phydev, QCA807X_INTR_STATUS);
if (irq_status < 0) {
phy_error(phydev);
return IRQ_NONE;
}
/* Read the current enabled interrupts */
int_enabled = phy_read(phydev, QCA807X_INTR_ENABLE);
if (int_enabled < 0) {
phy_error(phydev);
return IRQ_NONE;
}
/* See if this was one of our enabled interrupts */
if (!(irq_status & int_enabled))
return IRQ_NONE;
phy_trigger_machine(phydev);
return IRQ_HANDLED;
}
#endif
static int qca807x_led_config(struct phy_device *phydev)
{
struct device_node *node = phydev->mdio.dev.of_node;
bool led_config = false;
int val;
val = phy_read_mmd(phydev, MDIO_MMD_AN, QCA807X_MMD7_LED_1000N_1);
if (val < 0)
return val;
if (of_property_read_bool(node, "qcom,single-led-1000")) {
val |= QCA807X_LED_TXACT_BLK_EN_2;
val |= QCA807X_LED_RXACT_BLK_EN_2;
val |= QCA807X_LED_GT_ON_EN_2;
led_config = true;
}
if (of_property_read_bool(node, "qcom,single-led-100")) {
val |= QCA807X_LED_HT_ON_EN_2;
led_config = true;
}
if (of_property_read_bool(node, "qcom,single-led-10")) {
val |= QCA807X_LED_BT_ON_EN_2;
led_config = true;
}
if (led_config)
return phy_write_mmd(phydev, MDIO_MMD_AN, QCA807X_MMD7_LED_1000N_1, val);
else
return 0;
}
static const struct sfp_upstream_ops qca807x_sfp_ops = {
.attach = phy_sfp_attach,
.detach = phy_sfp_detach,
};
static int qca807x_config(struct phy_device *phydev)
{
struct device_node *node = phydev->mdio.dev.of_node;
int control_dac, ret = 0;
u32 of_control_dac;
/* Check for Combo port */
if (phy_read(phydev, QCA807X_CHIP_CONFIGURATION)) {
int fiber_mode_autodect;
int psgmii_serdes;
int chip_config;
if (of_property_read_bool(node, "qcom,fiber-enable")) {
/* Enable fiber mode autodection (1000Base-X or 100Base-FX) */
fiber_mode_autodect = phy_read_mmd(phydev, MDIO_MMD_AN,
QCA807X_MMD7_FIBER_MODE_AUTO_DETECTION);
fiber_mode_autodect |= QCA807X_MMD7_FIBER_MODE_AUTO_DETECTION_EN;
phy_write_mmd(phydev, MDIO_MMD_AN, QCA807X_MMD7_FIBER_MODE_AUTO_DETECTION,
fiber_mode_autodect);
/* Enable 4 copper + combo port mode */
chip_config = phy_read(phydev, QCA807X_CHIP_CONFIGURATION);
chip_config &= ~QCA807X_CHIP_CONFIGURATION_MODE_CFG_MASK;
chip_config |= FIELD_PREP(QCA807X_CHIP_CONFIGURATION_MODE_CFG_MASK,
QCA807X_CHIP_CONFIGURATION_MODE_PSGMII_FIBER);
phy_write(phydev, QCA807X_CHIP_CONFIGURATION, chip_config);
linkmode_set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, phydev->supported);
linkmode_set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, phydev->advertising);
}
/* Prevent PSGMII going into hibernation via PSGMII self test */
psgmii_serdes = phy_read_mmd(phydev, MDIO_MMD_PCS, PSGMII_MMD3_SERDES_CONTROL);
psgmii_serdes &= ~BIT(1);
ret = phy_write_mmd(phydev, MDIO_MMD_PCS,
PSGMII_MMD3_SERDES_CONTROL,
psgmii_serdes);
}
if (!of_property_read_u32(node, "qcom,control-dac", &of_control_dac)) {
control_dac = phy_read_mmd(phydev, MDIO_MMD_AN,
QCA807X_MMD7_1000BASE_T_POWER_SAVE_PER_CABLE_LENGTH);
control_dac &= ~QCA807X_CONTROL_DAC_MASK;
control_dac |= FIELD_PREP(QCA807X_CONTROL_DAC_MASK, of_control_dac);
ret = phy_write_mmd(phydev, MDIO_MMD_AN,
QCA807X_MMD7_1000BASE_T_POWER_SAVE_PER_CABLE_LENGTH,
control_dac);
}
/* Optionally configure LED-s */
if (IS_ENABLED(CONFIG_GPIOLIB)) {
/* Check whether PHY-s pins are used as GPIO-s */
if (!of_property_read_bool(node, "gpio-controller"))
ret = qca807x_led_config(phydev);
} else {
ret = qca807x_led_config(phydev);
}
return ret;
}
static int qca807x_probe(struct phy_device *phydev)
{
struct device_node *node = phydev->mdio.dev.of_node;
int ret = 0;
if (IS_ENABLED(CONFIG_GPIOLIB)) {
/* Do not register a GPIO controller unless flagged for it */
if (of_property_read_bool(node, "gpio-controller"))
ret = qca807x_gpio(phydev);
}
/* Attach SFP bus on combo port*/
if (of_property_read_bool(node, "qcom,fiber-enable")) {
if (phy_read(phydev, QCA807X_CHIP_CONFIGURATION))
ret = phy_sfp_probe(phydev, &qca807x_sfp_ops);
}
return ret;
}
static int qca807x_psgmii_config(struct phy_device *phydev)
{
struct device_node *node = phydev->mdio.dev.of_node;
int psgmii_az, tx_amp, ret = 0;
u32 tx_driver_strength;
/* Workaround to enable AZ transmitting ability */
if (of_property_read_bool(node, "qcom,psgmii-az")) {
psgmii_az = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, PSGMII_MODE_CTRL);
psgmii_az &= ~PSGMII_MODE_CTRL_AZ_WORKAROUND_MASK;
psgmii_az |= FIELD_PREP(PSGMII_MODE_CTRL_AZ_WORKAROUND_MASK, 0xc);
ret = phy_write_mmd(phydev, MDIO_MMD_PMAPMD, PSGMII_MODE_CTRL, psgmii_az);
psgmii_az = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, PSGMII_MODE_CTRL);
}
/* PSGMII/QSGMII TX amp set to DT defined value instead of default 600mV */
if (!of_property_read_u32(node, "qcom,tx-driver-strength", &tx_driver_strength)) {
tx_amp = phy_read(phydev, PSGMII_QSGMII_DRIVE_CONTROL_1);
tx_amp &= ~PSGMII_QSGMII_TX_DRIVER_MASK;
tx_amp |= FIELD_PREP(PSGMII_QSGMII_TX_DRIVER_MASK, tx_driver_strength);
ret = phy_write(phydev, PSGMII_QSGMII_DRIVE_CONTROL_1, tx_amp);
}
return ret;
}
static struct phy_driver qca807x_drivers[] = {
{
PHY_ID_MATCH_EXACT(PHY_ID_QCA8072),
.name = "Qualcomm QCA8072",
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,8,0)
.flags = PHY_POLL_CABLE_TEST,
#endif
/* PHY_GBIT_FEATURES */
.probe = qca807x_probe,
.config_init = qca807x_config,
.read_status = qca807x_read_status,
.config_intr = qca807x_config_intr,
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,12,0)
.ack_interrupt = qca807x_ack_intr,
#else
.handle_interrupt = qca807x_handle_interrupt,
#endif
.soft_reset = genphy_soft_reset,
.get_tunable = qca807x_get_tunable,
.set_tunable = qca807x_set_tunable,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,8,0)
.cable_test_start = qca807x_cable_test_start,
.cable_test_get_status = qca807x_cable_test_get_status,
#endif
},
{
PHY_ID_MATCH_EXACT(PHY_ID_QCA8075),
.name = "Qualcomm QCA8075",
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,8,0)
.flags = PHY_POLL_CABLE_TEST,
#endif
/* PHY_GBIT_FEATURES */
.probe = qca807x_probe,
.config_init = qca807x_config,
.read_status = qca807x_read_status,
.config_intr = qca807x_config_intr,
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,12,0)
.ack_interrupt = qca807x_ack_intr,
#else
.handle_interrupt = qca807x_handle_interrupt,
#endif
.soft_reset = genphy_soft_reset,
.get_tunable = qca807x_get_tunable,
.set_tunable = qca807x_set_tunable,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,8,0)
.cable_test_start = qca807x_cable_test_start,
.cable_test_get_status = qca807x_cable_test_get_status,
#endif
},
{
PHY_ID_MATCH_EXACT(PHY_ID_QCA807X_PSGMII),
.name = "Qualcomm QCA807x PSGMII",
.probe = qca807x_psgmii_config,
},
};
module_phy_driver(qca807x_drivers);
static struct mdio_device_id __maybe_unused qca807x_tbl[] = {
{ PHY_ID_MATCH_EXACT(PHY_ID_QCA8072) },
{ PHY_ID_MATCH_EXACT(PHY_ID_QCA8075) },
{ PHY_ID_MATCH_MODEL(PHY_ID_QCA807X_PSGMII) },
{ }
};
MODULE_AUTHOR("Robert Marko");
MODULE_DESCRIPTION("Qualcomm QCA807x PHY driver");
MODULE_DEVICE_TABLE(mdio, qca807x_tbl);
MODULE_LICENSE("GPL");

View file

@ -0,0 +1,895 @@
DEVICE_VARS += NETGEAR_BOARD_ID NETGEAR_HW_ID
DEVICE_VARS += RAS_BOARD RAS_ROOTFS_SIZE RAS_VERSION
DEVICE_VARS += WRGG_DEVNAME WRGG_SIGNATURE
define Device/FitImage
KERNEL_SUFFIX := -fit-uImage.itb
KERNEL = kernel-bin | gzip | fit gzip $$(DTS_DIR)/$$(DEVICE_DTS).dtb
KERNEL_NAME := Image
endef
define Device/FitImageLzma
KERNEL_SUFFIX := -fit-uImage.itb
KERNEL = kernel-bin | lzma | fit lzma $$(DTS_DIR)/$$(DEVICE_DTS).dtb
KERNEL_NAME := Image
endef
define Device/FitzImage
KERNEL_SUFFIX := -fit-zImage.itb
KERNEL = kernel-bin | fit none $$(DTS_DIR)/$$(DEVICE_DTS).dtb
KERNEL_NAME := zImage
endef
define Device/UbiFit
KERNEL_IN_UBI := 1
IMAGES := nand-factory.ubi nand-sysupgrade.bin
IMAGE/nand-factory.ubi := append-ubi
IMAGE/nand-sysupgrade.bin := sysupgrade-tar | append-metadata
endef
define Device/DniImage
$(call Device/FitzImage)
NETGEAR_BOARD_ID :=
NETGEAR_HW_ID :=
IMAGES += factory.img
IMAGE/factory.img := append-kernel | pad-offset 64k 64 | append-uImage-fakehdr filesystem | append-rootfs | pad-rootfs | netgear-dni
IMAGE/sysupgrade.bin := append-kernel | pad-offset 64k 64 | append-uImage-fakehdr filesystem | \
append-rootfs | pad-rootfs | append-metadata | check-size
endef
define Build/append-rootfshdr
mkimage -A $(LINUX_KARCH) \
-O linux -T filesystem \
-C lzma -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
-n root.squashfs -d $(IMAGE_ROOTFS) $@.new
dd if=$@.new bs=64 count=1 >> $(IMAGE_KERNEL)
endef
define Build/append-rutx-metadata
echo \
'{ \
"device_code": [".*"], \
"hwver": [".*"], \
"batch": [".*"], \
"serial": [".*"], \
"supported_devices":["teltonika,rutx"] \
}' | fwtool -I - $@
endef
define Build/fit-rutx
$(TOPDIR)/scripts/mkits-rutx.sh \
-D $(DEVICE_NAME) -o $@.its -k $@ \
$(if $(word 2,$(1)),-d $(word 2,$(1))) -C $(word 1,$(1)) \
-a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
$(if $(DEVICE_FDT_NUM),-n $(DEVICE_FDT_NUM)) \
-c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config@1") \
-A $(LINUX_KARCH) -v $(LINUX_VERSION)
PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
@mv $@.new $@
endef
define Build/UbootFw
$(CP) ./uboot_fw/ $(STAGING_DIR_HOST)/
if [ -e $(STAGING_DIR_HOST)/uboot_fw/tz.mbn ]; then \
$(SED) 's~file\.ubi~$@~g' $(STAGING_DIR_HOST)/uboot_fw/norplusnand-flash.conf; \
$(SED) 's~file\.elf~$(BIN_DIR)/openwrt-ipq40xx-u-boot-stripped.elf~g' $(STAGING_DIR_HOST)/uboot_fw/norplusnand-flash.conf; \
python $(KDIR)/uboot-1.0/tools/pack.py -t norplusnand -B -F boardconfig_premium_tlt -o $@ $(STAGING_DIR_HOST)/uboot_fw; \
else \
$(SED) 's~file\.ubi~$@~g' $(STAGING_DIR_HOST)/uboot_fw/norplusnand-apps-flash.conf; \
$(SED) 's~file\.elf~$(BIN_DIR)/openwrt-ipq40xx-u-boot-stripped.elf~g' $(STAGING_DIR_HOST)/uboot_fw/norplusnand-apps-flash.conf; \
python $(KDIR)/uboot-1.0/tools/pack.py -t norplusnand -B -F appsboardconfig_premium_tlt -o $@ $(STAGING_DIR_HOST)/uboot_fw; \
fi
endef
define Build/mkmylofw_32m
$(eval device_id=$(word 1,$(1)))
$(eval revision=$(word 2,$(1)))
let \
size="$$(stat -c%s $@)" \
pad="$(subst k,* 1024,$(BLOCKSIZE))" \
pad="(pad - (size % pad)) % pad" \
newsize='size + pad'; \
$(STAGING_DIR_HOST)/bin/mkmylofw \
-B WPE72 -i 0x11f6:$(device_id):0x11f6:$(device_id) -r $(revision) \
-s 0x2000000 -p0x180000:$$newsize:al:0x80208000:"OpenWrt":$@ \
$@.new
@mv $@.new $@
endef
define Build/qsdk-ipq-factory-nand-askey
$(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh $@.its\
askey_kernel $(IMAGE_KERNEL) \
askey_fs $(IMAGE_ROOTFS) \
ubifs $@
PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
@mv $@.new $@
endef
define Build/SenaoFW
-$(STAGING_DIR_HOST)/bin/mksenaofw \
-n $(BOARD_NAME) -r $(VENDOR_ID) -p $(1) \
-c $(DATECODE) -w $(2) -x $(CW_VER) -t 0 \
-e $@ \
-o $@.new
@cp $@.new $@
endef
define Build/wrgg-image
mkwrggimg -i $@ \
-o $@.new \
-d "$(WRGG_DEVNAME)" \
-s "$(WRGG_SIGNATURE)" \
-v "" -m "" -B ""
mv $@.new $@
endef
define Device/8dev_habanero-dvk
$(call Device/FitImageLzma)
DEVICE_VENDOR := 8devices
DEVICE_MODEL := Habanero DVK
IMAGE_SIZE := 30976k
SOC := qcom-ipq4019
DEVICE_PACKAGES := ipq-wifi-8dev_habanero-dvk
IMAGE/sysupgrade.bin := append-kernel | pad-to 64k | append-rootfs | pad-rootfs | append-metadata | check-size
endef
TARGET_DEVICES += 8dev_habanero-dvk
define Device/8dev_jalapeno-common
$(call Device/FitImage)
$(call Device/UbiFit)
BLOCKSIZE := 128k
PAGESIZE := 2048
SOC := qcom-ipq4018
endef
define Device/8dev_jalapeno
$(call Device/8dev_jalapeno-common)
DEVICE_VENDOR := 8devices
DEVICE_MODEL := Jalapeno
endef
TARGET_DEVICES += 8dev_jalapeno
define Device/alfa-network_ap120c-ac
$(call Device/FitImage)
$(call Device/UbiFit)
DEVICE_VENDOR := ALFA Network
DEVICE_MODEL := AP120C-AC
SOC := qcom-ipq4018
DEVICE_PACKAGES := kmod-usb-acm kmod-tpm-i2c-atmel
BLOCKSIZE := 128k
PAGESIZE := 2048
IMAGE_SIZE := 65536k
IMAGES := nand-factory.bin nand-sysupgrade.bin
IMAGE/nand-factory.bin := append-ubi | qsdk-ipq-factory-nand
endef
TARGET_DEVICES += alfa-network_ap120c-ac
define Device/aruba_glenmorangie
$(call Device/FitImageLzma)
DEVICE_VENDOR := Aruba
SOC := qcom-ipq4029
DEVICE_PACKAGES := ipq-wifi-aruba_ap-303
endef
define Device/aruba_ap-303
$(call Device/aruba_glenmorangie)
DEVICE_MODEL := AP-303
endef
TARGET_DEVICES += aruba_ap-303
define Device/aruba_ap-303h
$(call Device/aruba_glenmorangie)
DEVICE_MODEL := AP-303H
endef
TARGET_DEVICES += aruba_ap-303h
define Device/aruba_ap-365
$(call Device/aruba_glenmorangie)
DEVICE_MODEL := AP-365
DEVICE_PACKAGES += kmod-hwmon-ad7418
endef
TARGET_DEVICES += aruba_ap-365
define Device/asus_map-ac2200
$(call Device/FitImageLzma)
DEVICE_VENDOR := ASUS
DEVICE_MODEL := Lyra (MAP-AC2200)
SOC := qcom-ipq4019
DEVICE_PACKAGES := ath10k-firmware-qca9888-ct kmod-ath3k
endef
TARGET_DEVICES += asus_map-ac2200
define Device/asus_rt-ac58u
$(call Device/FitImageLzma)
DEVICE_VENDOR := ASUS
DEVICE_MODEL := RT-AC58U
SOC := qcom-ipq4018
BLOCKSIZE := 128k
PAGESIZE := 2048
DTB_SIZE := 65536
IMAGE_SIZE := 20439364
FILESYSTEMS := squashfs
# Someone - in their infinite wisdom - decided to put the firmware
# version in front of the image name \03\00\00\04 => Version 3.0.0.4
# Since u-boot works with strings we either need another fixup step
# to add a version... or we are very careful not to add '\0' into that
# string and call it a day.... Yeah, we do the latter!
UIMAGE_NAME:=$(shell echo -e '\03\01\01\01RT-AC58U')
DEVICE_PACKAGES := -kmod-ath10k-ct kmod-ath10k-ct-smallbuffers \
kmod-usb-ledtrig-usbport
endef
TARGET_DEVICES += asus_rt-ac58u
define Device/avm_fritzbox-4040
$(call Device/FitImageLzma)
DEVICE_VENDOR := AVM
DEVICE_MODEL := FRITZ!Box 4040
SOC := qcom-ipq4018
BOARD_NAME := fritz4040
IMAGE_SIZE := 29056k
UBOOT_PATH := $(STAGING_DIR_IMAGE)/uboot-fritz4040.bin
UBOOT_PARTITION_SIZE := 524288
IMAGES += eva.bin
IMAGE/eva.bin := append-uboot | pad-to $$$$(UBOOT_PARTITION_SIZE) | append-kernel | append-rootfs | pad-rootfs
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata | check-size
DEVICE_PACKAGES := fritz-tffs fritz-caldata
endef
TARGET_DEVICES += avm_fritzbox-4040
define Device/avm_fritzbox-7530
$(call Device/FitImageLzma)
DEVICE_VENDOR := AVM
DEVICE_MODEL := FRITZ!Box 7530
SOC := qcom-ipq4019
DEVICE_PACKAGES := fritz-caldata fritz-tffs-nand
endef
TARGET_DEVICES += avm_fritzbox-7530
define Device/avm_fritzrepeater-1200
$(call Device/FitImageLzma)
DEVICE_VENDOR := AVM
DEVICE_MODEL := FRITZ!Repeater 1200
SOC := qcom-ipq4019
DEVICE_PACKAGES := fritz-caldata fritz-tffs-nand ipq-wifi-avm_fritzrepeater-1200
endef
TARGET_DEVICES += avm_fritzrepeater-1200
define Device/avm_fritzrepeater-3000
$(call Device/FitImageLzma)
DEVICE_VENDOR := AVM
DEVICE_MODEL := FRITZ!Repeater 3000
SOC := qcom-ipq4019
DEVICE_PACKAGES := ath10k-firmware-qca9984-ct fritz-caldata fritz-tffs-nand
endef
TARGET_DEVICES += avm_fritzrepeater-3000
define Device/buffalo_wtr-m2133hp
$(call Device/FitImage)
$(call Device/UbiFit)
DEVICE_VENDOR := Buffalo
DEVICE_MODEL := WTR-M2133HP
SOC := qcom-ipq4019
DEVICE_PACKAGES := ath10k-firmware-qca9984-ct ipq-wifi-buffalo_wtr-m2133hp
BLOCKSIZE := 128k
PAGESIZE := 2048
endef
TARGET_DEVICES += buffalo_wtr-m2133hp
define Device/cellc_rtl30vw
KERNEL_SUFFIX := -fit-uImage.itb
KERNEL_INITRAMFS = kernel-bin | gzip | fit gzip $$(DTS_DIR)/$$(DEVICE_DTS).dtb
KERNEL = kernel-bin | gzip | fit gzip $$(DTS_DIR)/$$(DEVICE_DTS).dtb | uImage lzma | pad-to 2048
KERNEL_NAME := Image
KERNEL_IN_UBI :=
IMAGES := nand-factory.bin nand-sysupgrade.bin
IMAGE/nand-factory.bin := append-rootfshdr | append-ubi | qsdk-ipq-factory-nand-askey
IMAGE/nand-sysupgrade.bin := append-rootfshdr | sysupgrade-tar | append-metadata
DEVICE_VENDOR := Cell C
DEVICE_MODEL := RTL30VW
SOC := qcom-ipq4019
DEVICE_DTS_CONFIG := config@5
KERNEL_INSTALL := 1
KERNEL_SIZE := 4096k
IMAGE_SIZE := 57344k
BLOCKSIZE := 128k
PAGESIZE := 2048
DEVICE_PACKAGES := kmod-usb-net-qmi-wwan kmod-usb-serial-option uqmi ipq-wifi-cellc_rtl30vw
endef
TARGET_DEVICES += cellc_rtl30vw
define Device/cilab_meshpoint-one
$(call Device/8dev_jalapeno-common)
DEVICE_VENDOR := Crisis Innovation Lab
DEVICE_MODEL := MeshPoint.One
DEVICE_PACKAGES := kmod-i2c-gpio kmod-iio-bmp280-i2c kmod-hwmon-ina2xx kmod-rtc-pcf2127
endef
TARGET_DEVICES += cilab_meshpoint-one
define Device/compex_wpj419
$(call Device/FitImage)
$(call Device/UbiFit)
DEVICE_VENDOR := Compex
DEVICE_MODEL := WPJ419
SOC := qcom-ipq4019
DEVICE_DTS_CONFIG := config@12
KERNEL_INSTALL := 1
BLOCKSIZE := 128k
PAGESIZE := 2048
FILESYSTEMS := squashfs
endef
TARGET_DEVICES += compex_wpj419
define Device/compex_wpj428
$(call Device/FitImage)
DEVICE_VENDOR := Compex
DEVICE_MODEL := WPJ428
SOC := qcom-ipq4028
DEVICE_DTS_CONFIG := config@4
BLOCKSIZE := 64k
IMAGE_SIZE := 31232k
KERNEL_SIZE := 4096k
IMAGES += cpximg-6a04.bin
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata
IMAGE/cpximg-6a04.bin := append-kernel | append-rootfs | pad-rootfs | mkmylofw_32m 0x8A2 3
DEVICE_PACKAGES := kmod-gpio-beeper
endef
TARGET_DEVICES += compex_wpj428
define Device/devolo_magic-2-wifi-next
$(call Device/FitImage)
DEVICE_VENDOR := devolo
DEVICE_MODEL := Magic 2 WiFi next
SOC := qcom-ipq4018
KERNEL_SIZE := 4096k
# If the bootloader sees 0xDEADC0DE and this trailer at the 64k boundary of a TFTP image
# it will bootm it, just like we want for the initramfs.
KERNEL_INITRAMFS := kernel-bin | gzip | fit gzip $$(DTS_DIR)/$$(DEVICE_DTS).dtb | pad-to 64k |\
append-string -e '\xDE\xAD\xC0\xDE{"fl_initramfs":""}\x00'
IMAGE_SIZE := 26624k
IMAGES := sysupgrade.bin
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata
DEVICE_PACKAGES := ipq-wifi-devolo_magic-2-wifi-next
endef
TARGET_DEVICES += devolo_magic-2-wifi-next
define Device/dlink_dap-2610
$(call Device/FitImageLzma)
DEVICE_VENDOR := D-Link
DEVICE_MODEL := DAP-2610
SOC := qcom-ipq4018
DEVICE_DTS_CONFIG := config@ap.dk01.1-c1
BLOCKSIZE := 64k
WRGG_DEVNAME := /dev/mtdblock/8
WRGG_SIGNATURE := wapac30_dkbs_dap2610
IMAGE_SIZE := 14080k
IMAGES += factory.bin
# Bootloader expects a special 160 byte header which is added by
# wrgg-image.
# Factory image size must be larger than 6MB, and size in wrgg header must
# match actual factory image size to be flashable from D-Link http server.
# Bootloader verifies checksum of wrgg image before booting, thus jffs2
# cannot be part of the wrgg image. This is solved in the factory image by
# having the rootfs at the end of the image (without pad-rootfs). And in
# the sysupgrade image only the kernel is included in the wrgg checksum,
# but this is not flashable from the D-link http server.
# append-rootfs must start on an erase block boundary.
IMAGE/factory.bin := append-kernel | pad-offset 6144k 160 | append-rootfs | wrgg-image | check-size
IMAGE/sysupgrade.bin := append-kernel | wrgg-image | pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | check-size | append-metadata
DEVICE_PACKAGES := ipq-wifi-dlink_dap2610
endef
TARGET_DEVICES += dlink_dap-2610
define Device/edgecore_ecw5211
$(call Device/FitImage)
$(call Device/UbiFit)
DEVICE_VENDOR := Edgecore
DEVICE_MODEL := ECW5211
SOC := qcom-ipq4018
BLOCKSIZE := 128k
PAGESIZE := 2048
DEVICE_DTS_CONFIG := config@ap.dk01.1-c2
DEVICE_PACKAGES := kmod-tpm-i2c-atmel kmod-usb-acm
endef
TARGET_DEVICES += edgecore_ecw5211
define Device/edgecore_oap100
$(call Device/FitImage)
$(call Device/UbiFit)
DEVICE_VENDOR := Edgecore
DEVICE_MODEL := OAP100
SOC := qcom-ipq4019
BLOCKSIZE := 128k
PAGESIZE := 2048
IMAGES := nand-sysupgrade.bin
DEVICE_DTS_CONFIG := config@ap.dk07.1-c1
DEVICE_PACKAGES := ipq-wifi-edgecore_oap100 kmod-usb-acm kmod-usb-net kmod-usb-net-cdc-qmi uqmi
endef
TARGET_DEVICES += edgecore_oap100
define Device/engenius_eap1300
$(call Device/FitImage)
DEVICE_VENDOR := EnGenius
DEVICE_MODEL := EAP1300
DEVICE_DTS_CONFIG := config@4
BOARD_NAME := eap1300
SOC := qcom-ipq4018
KERNEL_SIZE := 5120k
IMAGE_SIZE := 25344k
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata
endef
TARGET_DEVICES += engenius_eap1300
define Device/engenius_eap2200
$(call Device/FitImage)
$(call Device/UbiFit)
DEVICE_VENDOR := EnGenius
DEVICE_MODEL := EAP2200
SOC := qcom-ipq4019
BLOCKSIZE := 128k
PAGESIZE := 2048
DEVICE_PACKAGES := ath10k-firmware-qca9888-ct ipq-wifi-engenius_eap2200 -kmod-ath10k-ct kmod-ath10k-ct-smallbuffers
endef
TARGET_DEVICES += engenius_eap2200
define Device/engenius_emd1
$(call Device/FitImage)
DEVICE_VENDOR := EnGenius
DEVICE_MODEL := EMD1
DEVICE_DTS_CONFIG := config@4
SOC := qcom-ipq4018
IMAGE_SIZE := 30720k
IMAGES += factory.bin
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata
IMAGE/factory.bin := qsdk-ipq-factory-nor | check-size
DEVICE_PACKAGES := ipq-wifi-engenius_emd1
endef
TARGET_DEVICES += engenius_emd1
define Device/engenius_emr3500
$(call Device/FitImage)
DEVICE_VENDOR := EnGenius
DEVICE_MODEL := EMR3500
DEVICE_DTS_CONFIG := config@4
SOC := qcom-ipq4018
KERNEL_SIZE := 4096k
IMAGE_SIZE := 30720k
IMAGES += factory.bin
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata
IMAGE/factory.bin := qsdk-ipq-factory-nor | check-size
DEVICE_PACKAGES := ipq-wifi-engenius_emr3500
endef
TARGET_DEVICES += engenius_emr3500
define Device/engenius_ens620ext
$(call Device/FitImage)
DEVICE_VENDOR := EnGenius
DEVICE_MODEL := ENS620EXT
SOC := qcom-ipq4018
DEVICE_DTS_CONFIG := config@4
BLOCKSIZE := 64k
PAGESIZE := 256
BOARD_NAME := ENS620EXT
VENDOR_ID := 0x0101
PRODUCT_ID := 0x79
PRODUCT_ID_NEW := 0xA4
DATECODE := 190507
FW_VER := 3.1.2
FW_VER_NEW := 3.5.6
CW_VER := 1.8.99
IMAGE_SIZE := 21312k
KERNEL_SIZE := 5120k
FILESYSTEMS := squashfs
IMAGES += factory_30.bin factory_35.bin
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | check-size | append-metadata
IMAGE/factory_30.bin := append-kernel | pad-to $$$$(KERNEL_SIZE) | append-rootfs | pad-rootfs | check-size | SenaoFW $$$$(PRODUCT_ID) $$$$(FW_VER)
IMAGE/factory_35.bin := qsdk-ipq-factory-nor | check-size | SenaoFW $$$$(PRODUCT_ID_NEW) $$$$(FW_VER_NEW)
endef
TARGET_DEVICES += engenius_ens620ext
define Device/ezviz_cs-w3-wd1200g-eup
$(call Device/FitImage)
DEVICE_VENDOR := EZVIZ
DEVICE_MODEL := CS-W3-WD1200G
DEVICE_VARIANT := EUP
DEVICE_DTS_CONFIG := config@4
IMAGE_SIZE := 14848k
SOC := qcom-ipq4018
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | \
append-metadata
DEVICE_PACKAGES := -kmod-ath10k-ct kmod-ath10k-ct-smallbuffers \
ipq-wifi-ezviz_cs-w3-wd1200g-eup
endef
TARGET_DEVICES += ezviz_cs-w3-wd1200g-eup
define Device/glinet_gl-ap1300
$(call Device/FitImage)
$(call Device/UbiFit)
DEVICE_VENDOR := GL.iNet
DEVICE_MODEL := GL-AP1300
SOC := qcom-ipq4018
DEVICE_DTS_CONFIG := config@ap.dk01.1-c2
BLOCKSIZE := 128k
PAGESIZE := 2048
IMAGE_SIZE := 131072k
KERNEL_INSTALL := 1
DEVICE_PACKAGES := ipq-wifi-glinet_gl-ap1300
endef
TARGET_DEVICES += glinet_gl-ap1300
define Device/glinet_gl-b1300
$(call Device/FitImage)
DEVICE_VENDOR := GL.iNet
DEVICE_MODEL := GL-B1300
BOARD_NAME := gl-b1300
SOC := qcom-ipq4029
KERNEL_SIZE := 4096k
IMAGE_SIZE := 26624k
IMAGE/sysupgrade.bin := append-kernel |append-rootfs | pad-rootfs | append-metadata
endef
TARGET_DEVICES += glinet_gl-b1300
define Device/glinet_gl-s1300
$(call Device/FitImage)
DEVICE_VENDOR := GL.iNet
DEVICE_MODEL := GL-S1300
SOC := qcom-ipq4029
KERNEL_SIZE := 4096k
IMAGE_SIZE := 26624k
IMAGES := sysupgrade.bin
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata
DEVICE_PACKAGES := ipq-wifi-glinet_gl-s1300 kmod-fs-ext4 kmod-mmc kmod-spi-dev
endef
TARGET_DEVICES += glinet_gl-s1300
define Device/linksys_ea6350v3
# The Linksys EA6350v3 has a uboot bootloader that does not
# support either booting lzma kernel images nor booting UBI
# partitions. This uboot, however, supports raw kernel images and
# gzipped images.
#
# As for the time of writing this, the device will boot the kernel
# from a fixed address with a fixed length of 3MiB. Also, the
# device has a hard-coded kernel command line that requieres the
# rootfs and alt_rootfs to be in mtd11 and mtd13 respectively.
# Oh... and the kernel partition overlaps with the rootfs
# partition (the same for alt_kernel and alt_rootfs).
#
# If you are planing re-partitioning the device, you may want to
# keep those details in mind:
# 1. The kernel adresses you should honor are 0x00000000 and
# 0x02800000 respectively.
# 2. The kernel size (plus the dtb) cannot exceed 3.00MiB in size.
# 3. You can use 'zImage', but not a raw 'Image' packed with lzma.
# 4. The kernel command line from uboot is harcoded to boot with
# rootfs either in mtd11 or mtd13.
$(call Device/FitzImage)
DEVICE_VENDOR := Linksys
DEVICE_MODEL := EA6350
DEVICE_VARIANT := v3
SOC := qcom-ipq4018
BLOCKSIZE := 128k
PAGESIZE := 2048
KERNEL_SIZE := 3072k
IMAGE_SIZE := 37888k
UBINIZE_OPTS := -E 5
IMAGES += factory.bin
IMAGE/factory.bin := append-kernel | append-uImage-fakehdr filesystem | pad-to $$$$(KERNEL_SIZE) | append-ubi | linksys-image type=EA6350v3
endef
TARGET_DEVICES += linksys_ea6350v3
define Device/linksys_ea8300
$(call Device/FitzImage)
DEVICE_VENDOR := Linksys
DEVICE_MODEL := EA8300
SOC := qcom-ipq4019
KERNEL_SIZE := 3072k
IMAGE_SIZE := 87040k
BLOCKSIZE := 128k
PAGESIZE := 2048
UBINIZE_OPTS := -E 5 # EOD marks to "hide" factory sig at EOF
IMAGES += factory.bin
IMAGE/factory.bin := append-kernel | pad-to $$$$(KERNEL_SIZE) | append-ubi | linksys-image type=EA8300
DEVICE_PACKAGES := ath10k-firmware-qca9888-ct ipq-wifi-linksys_ea8300 kmod-usb-ledtrig-usbport
endef
TARGET_DEVICES += linksys_ea8300
define Device/linksys_mr8300
$(call Device/FitzImage)
DEVICE_VENDOR := Linksys
DEVICE_MODEL := MR8300
SOC := qcom-ipq4019
KERNEL_SIZE := 3072k
IMAGE_SIZE := 87040k
BLOCKSIZE := 128k
PAGESIZE := 2048
UBINIZE_OPTS := -E 5 # EOD marks to "hide" factory sig at EOF
IMAGES += factory.bin
IMAGE/factory.bin := append-kernel | pad-to $$$$(KERNEL_SIZE) | append-ubi | linksys-image type=MR8300
DEVICE_PACKAGES := ath10k-firmware-qca9888-ct ipq-wifi-linksys_mr8300-v0 kmod-usb-ledtrig-usbport
endef
TARGET_DEVICES += linksys_mr8300
define Device/luma_wrtq-329acn
$(call Device/FitImage)
DEVICE_VENDOR := Luma Home
DEVICE_MODEL := WRTQ-329ACN
SOC := qcom-ipq4018
DEVICE_PACKAGES := ipq-wifi-luma_wrtq-329acn kmod-ath3k kmod-eeprom-at24 kmod-i2c-gpio
IMAGE_SIZE := 76632k
BLOCKSIZE := 128k
PAGESIZE := 2048
endef
TARGET_DEVICES += luma_wrtq-329acn
define Device/meraki_mr33
$(call Device/FitImage)
DEVICE_VENDOR := Cisco Meraki
DEVICE_MODEL := MR33
SOC := qcom-ipq4029
BLOCKSIZE := 128k
PAGESIZE := 2048
DEVICE_PACKAGES := -swconfig ath10k-firmware-qca9887-ct
endef
TARGET_DEVICES += meraki_mr33
define Device/mobipromo_cm520-79f
$(call Device/FitzImage)
$(call Device/UbiFit)
DEVICE_VENDOR := MobiPromo
DEVICE_MODEL := CM520-79F
SOC := qcom-ipq4019
BLOCKSIZE := 128k
PAGESIZE := 2048
DEVICE_PACKAGES := ipq-wifi-mobipromo_cm520-79f kmod-usb-ledtrig-usbport
endef
TARGET_DEVICES += mobipromo_cm520-79f
define Device/netgear_ex61x0v2
$(call Device/DniImage)
DEVICE_VENDOR := NETGEAR
DEVICE_DTS_CONFIG := config@4
NETGEAR_BOARD_ID := EX6150v2series
NETGEAR_HW_ID := 29765285+16+0+128+2x2
IMAGE_SIZE := 14400k
SOC := qcom-ipq4018
endef
define Device/netgear_ex6100v2
$(call Device/netgear_ex61x0v2)
DEVICE_MODEL := EX6100
DEVICE_VARIANT := v2
endef
TARGET_DEVICES += netgear_ex6100v2
define Device/netgear_ex6150v2
$(call Device/netgear_ex61x0v2)
DEVICE_MODEL := EX6150
DEVICE_VARIANT := v2
endef
TARGET_DEVICES += netgear_ex6150v2
define Device/openmesh_a42
$(call Device/FitImageLzma)
DEVICE_VENDOR := OpenMesh
DEVICE_MODEL := A42
SOC := qcom-ipq4018
DEVICE_DTS_CONFIG := config@om.a42
BLOCKSIZE := 64k
KERNEL = kernel-bin | lzma | fit lzma $$(DTS_DIR)/$$(DEVICE_DTS).dtb | pad-to $$(BLOCKSIZE)
IMAGE_SIZE := 15616k
IMAGES += factory.bin
IMAGE/factory.bin := append-rootfs | pad-rootfs | openmesh-image ce_type=A42
IMAGE/sysupgrade.bin/squashfs := append-rootfs | pad-rootfs | sysupgrade-tar rootfs=$$$$@ | append-metadata
endef
TARGET_DEVICES += openmesh_a42
define Device/openmesh_a62
$(call Device/FitImageLzma)
DEVICE_VENDOR := OpenMesh
DEVICE_MODEL := A62
SOC := qcom-ipq4019
DEVICE_DTS_CONFIG := config@om.a62
BLOCKSIZE := 64k
KERNEL = kernel-bin | lzma | fit lzma $$(DTS_DIR)/$$(DEVICE_DTS).dtb | pad-to $$(BLOCKSIZE)
IMAGE_SIZE := 15552k
IMAGES += factory.bin
IMAGE/factory.bin := append-rootfs | pad-rootfs | openmesh-image ce_type=A62
IMAGE/sysupgrade.bin/squashfs := append-rootfs | pad-rootfs | sysupgrade-tar rootfs=$$$$@ | append-metadata
DEVICE_PACKAGES := ath10k-firmware-qca9888-ct
endef
TARGET_DEVICES += openmesh_a62
define Device/plasmacloud_pa1200
$(call Device/FitImageLzma)
DEVICE_VENDOR := Plasma Cloud
DEVICE_MODEL := PA1200
SOC := qcom-ipq4018
DEVICE_DTS_CONFIG := config@pc.pa1200
BLOCKSIZE := 64k
KERNEL = kernel-bin | lzma | fit lzma $$(DTS_DIR)/$$(DEVICE_DTS).dtb | pad-to $$(BLOCKSIZE)
IMAGE_SIZE := 15616k
IMAGES += factory.bin
IMAGE/factory.bin := append-rootfs | pad-rootfs | openmesh-image ce_type=PA1200
IMAGE/sysupgrade.bin/squashfs := append-rootfs | pad-rootfs | sysupgrade-tar rootfs=$$$$@ | append-metadata
DEVICE_PACKAGES := ipq-wifi-plasmacloud_pa1200
endef
TARGET_DEVICES += plasmacloud_pa1200
define Device/plasmacloud_pa2200
$(call Device/FitImageLzma)
DEVICE_VENDOR := Plasma Cloud
DEVICE_MODEL := PA2200
SOC := qcom-ipq4019
DEVICE_DTS_CONFIG := config@pc.pa2200
BLOCKSIZE := 64k
KERNEL = kernel-bin | lzma | fit lzma $$(DTS_DIR)/$$(DEVICE_DTS).dtb | pad-to $$(BLOCKSIZE)
IMAGE_SIZE := 15552k
IMAGES += factory.bin
IMAGE/factory.bin := append-rootfs | pad-rootfs | openmesh-image ce_type=PA2200
IMAGE/sysupgrade.bin/squashfs := append-rootfs | pad-rootfs | sysupgrade-tar rootfs=$$$$@ | append-metadata
DEVICE_PACKAGES := ath10k-firmware-qca9888-ct ipq-wifi-plasmacloud_pa2200
endef
TARGET_DEVICES += plasmacloud_pa2200
define Device/p2w_r619ac
$(call Device/FitzImage)
$(call Device/UbiFit)
DEVICE_VENDOR := P&W
DEVICE_MODEL := R619AC
SOC := qcom-ipq4019
DEVICE_DTS_CONFIG := config@10
BLOCKSIZE := 128k
PAGESIZE := 2048
IMAGES += nand-factory.bin
IMAGE/nand-factory.bin := append-ubi | qsdk-ipq-factory-nand
DEVICE_PACKAGES := ipq-wifi-p2w_r619ac
endef
TARGET_DEVICES += p2w_r619ac
define Device/p2w_r619ac-128m
$(call Device/FitzImage)
$(call Device/UbiFit)
DEVICE_VENDOR := P&W
DEVICE_MODEL := R619AC
DEVICE_VARIANT := 128M
SOC := qcom-ipq4019
DEVICE_DTS_CONFIG := config@10
BLOCKSIZE := 128k
PAGESIZE := 2048
DEVICE_PACKAGES := ipq-wifi-p2w_r619ac
endef
TARGET_DEVICES += p2w_r619ac-128m
define Device/qcom_ap-dk01.1-c1
DEVICE_VENDOR := Qualcomm Atheros
DEVICE_MODEL := AP-DK01.1
DEVICE_VARIANT := C1
BOARD_NAME := ap-dk01.1-c1
SOC := qcom-ipq4019
DEVICE_DTS := qcom-ipq4019-ap.dk01.1-c1
KERNEL_INSTALL := 1
KERNEL_SIZE := 4096k
IMAGE_SIZE := 26624k
$(call Device/FitImage)
IMAGE/sysupgrade.bin := append-kernel | pad-to $$$$(KERNEL_SIZE) | append-rootfs | pad-rootfs | append-metadata
endef
TARGET_DEVICES += qcom_ap-dk01.1-c1
define Device/qcom_ap-dk04.1-c1
$(call Device/FitImage)
$(call Device/UbiFit)
DEVICE_VENDOR := Qualcomm Atheros
DEVICE_MODEL := AP-DK04.1
DEVICE_VARIANT := C1
SOC := qcom-ipq4019
DEVICE_DTS := qcom-ipq4019-ap.dk04.1-c1
KERNEL_INSTALL := 1
KERNEL_SIZE := 4048k
BLOCKSIZE := 128k
PAGESIZE := 2048
BOARD_NAME := ap-dk04.1-c1
endef
TARGET_DEVICES += qcom_ap-dk04.1-c1
define Device/qxwlan_e2600ac-c1
$(call Device/FitImage)
DEVICE_VENDOR := Qxwlan
DEVICE_MODEL := E2600AC
DEVICE_VARIANT := C1
BOARD_NAME := e2600ac-c1
SOC := qcom-ipq4019
KERNEL_SIZE := 4096k
IMAGE_SIZE := 31232k
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata
DEVICE_PACKAGES := ipq-wifi-qxwlan_e2600ac
endef
TARGET_DEVICES += qxwlan_e2600ac-c1
define Device/qxwlan_e2600ac-c2
$(call Device/FitImage)
$(call Device/UbiFit)
DEVICE_VENDOR := Qxwlan
DEVICE_MODEL := E2600AC
DEVICE_VARIANT := C2
SOC := qcom-ipq4019
KERNEL_INSTALL := 1
BLOCKSIZE := 128k
PAGESIZE := 2048
DEVICE_PACKAGES := ipq-wifi-qxwlan_e2600ac
endef
TARGET_DEVICES += qxwlan_e2600ac-c2
define Device/teltonika_rutx
$(call Device/FitImage)
$(call Device/UbiFit)
DEVICE_VENDOR := Teltonika
DEVICE_MODEL := RUTX
BOARD_NAME := rutx
SOC := qcom-ipq4018
DEVICE_DTS_DIR := ../dts
DEVICE_DTS := $(foreach dts,$(notdir $(wildcard $(PLATFORM_DIR)/dts/*.dts)),$(patsubst %.dts,%,$(dts)))
DEVICE_DTS_CONFIG := config@5
KERNEL = kernel-bin | gzip | fit-rutx gzip "$$(KDIR)/{$$(subst $$(space),$$(comma),$$(addprefix image-,$$(addsuffix .dtb,$$(DEVICE_DTS))))}"
KERNEL_INSTALL := 1
BLOCKSIZE := 128k
PAGESIZE := 2048
FILESYSTEMS := squashfs
KERNEL_IN_UBI := 1
IMAGES := sysupgrade.bin
IMAGE/sysupgrade.bin := append-ubi | qsdk-ipq-factory-nand | append-rutx-metadata
#DEVICE_PACKAGES := ipq-wifi-teltonika_rutx kmod-bluetooth kmod-r2ec sysupgrade-helper
DEVICE_PACKAGES := ipq-wifi-teltonika_rutx kmod-bluetooth sysupgrade-helper
HW_SUPPORT := io_expander%stm32:shiftreg_1
endef
TARGET_DEVICES += teltonika_rutx
define Device/unielec_u4019-32m
$(call Device/FitImage)
DEVICE_VENDOR := Unielec
DEVICE_MODEL := U4019
DEVICE_VARIANT := 32M
BOARD_NAME := u4019-32m
SOC := qcom-ipq4019
KERNEL_SIZE := 4096k
IMAGE_SIZE := 31232k
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata
endef
TARGET_DEVICES += unielec_u4019-32m
define Device/zyxel_nbg6617
$(call Device/FitImageLzma)
DEVICE_VENDOR := ZyXEL
DEVICE_MODEL := NBG6617
SOC := qcom-ipq4018
KERNEL_SIZE := 4096k
ROOTFS_SIZE := 24960k
RAS_BOARD := NBG6617
RAS_ROOTFS_SIZE := 19840k
RAS_VERSION := "$(VERSION_DIST) $(REVISION)"
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata
IMAGES += factory.bin
# The ZyXEL firmware allows flashing thru the web-gui only when the rootfs is
# at least as large as the one of the initial firmware image (not the current
# one on the device). This only applies to the Web-UI, the bootlaoder ignores
# this minimum-size. However, the larger image can be flashed both ways.
IMAGE/factory.bin := append-rootfs | pad-rootfs | pad-to 64k | check-size $$$$(ROOTFS_SIZE) | zyxel-ras-image separate-kernel
IMAGE/sysupgrade.bin/squashfs := append-rootfs | pad-rootfs | check-size $$$$(ROOTFS_SIZE) | sysupgrade-tar rootfs=$$$$@ | append-metadata
DEVICE_PACKAGES := kmod-usb-ledtrig-usbport
endef
TARGET_DEVICES += zyxel_nbg6617
define Device/zyxel_wre6606
$(call Device/FitImage)
DEVICE_VENDOR := ZyXEL
DEVICE_MODEL := WRE6606
DEVICE_DTS_CONFIG := config@4
SOC := qcom-ipq4018
IMAGE_SIZE := 13184k
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata | check-size
DEVICE_PACKAGES := -kmod-ath10k-ct kmod-ath10k-ct-smallbuffers
endef
TARGET_DEVICES += zyxel_wre6606

View file

@ -0,0 +1,25 @@
--- a/drivers/mtd/nand/spi/xtx.c
+++ b/drivers/mtd/nand/spi/xtx.c
@@ -37,8 +37,8 @@
if (section)
return -ERANGE;
- region->offset = 8;
- region->length = 40;
+ region->offset = 48;
+ region->length = 16;
return 0;
}
@@ -49,8 +49,9 @@
if (section)
return -ERANGE;
- region->offset = 1;
- region->length = 7;
+ /* Reserve 2 bytes for the BBM. */
+ region->offset = 2;
+ region->length = 62;
return 0;
}

View file

@ -0,0 +1,165 @@
From 4267880319bc1a2270d352e0ded6d6386242a7ef Mon Sep 17 00:00:00 2001
From: John Crispin <blogic@openwrt.org>
Date: Tue, 12 Aug 2014 20:49:27 +0200
Subject: [PATCH 24/53] GPIO: add named gpio exports
Signed-off-by: John Crispin <blogic@openwrt.org>
---
drivers/gpio/gpiolib-of.c | 68 +++++++++++++++++++++++++++++++++++++++++
drivers/gpio/gpiolib-sysfs.c | 10 +++++-
include/asm-generic/gpio.h | 6 ++++
include/linux/gpio/consumer.h | 8 +++++
4 files changed, 91 insertions(+), 1 deletion(-)
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -19,6 +19,8 @@
#include <linux/pinctrl/pinctrl.h>
#include <linux/slab.h>
#include <linux/gpio/machine.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
#include "gpiolib.h"
#include "gpiolib-of.h"
@@ -915,3 +917,68 @@ void of_gpiochip_remove(struct gpio_chip
{
of_node_put(chip->of_node);
}
+
+static struct of_device_id gpio_export_ids[] = {
+ { .compatible = "gpio-export" },
+ { /* sentinel */ }
+};
+
+static int of_gpio_export_probe(struct platform_device *pdev)
+{
+ struct device_node *np = pdev->dev.of_node;
+ struct device_node *cnp;
+ u32 val;
+ int nb = 0;
+
+ for_each_child_of_node(np, cnp) {
+ const char *name = NULL;
+ int gpio;
+ bool dmc;
+ int max_gpio = 1;
+ int i;
+
+ of_property_read_string(cnp, "gpio-export,name", &name);
+
+ if (!name)
+ max_gpio = of_gpio_count(cnp);
+
+ for (i = 0; i < max_gpio; i++) {
+ unsigned flags = 0;
+ enum of_gpio_flags of_flags;
+
+ gpio = of_get_gpio_flags(cnp, i, &of_flags);
+ if (!gpio_is_valid(gpio))
+ return gpio;
+
+ if (of_flags == OF_GPIO_ACTIVE_LOW)
+ flags |= GPIOF_ACTIVE_LOW;
+
+ if (!of_property_read_u32(cnp, "gpio-export,output", &val))
+ flags |= val ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
+ else
+ flags |= GPIOF_IN;
+
+ if (devm_gpio_request_one(&pdev->dev, gpio, flags, name ? name : of_node_full_name(np)))
+ continue;
+
+ dmc = of_property_read_bool(cnp, "gpio-export,direction_may_change");
+ gpio_export_with_name(gpio, dmc, name);
+ nb++;
+ }
+ }
+
+ dev_info(&pdev->dev, "%d gpio(s) exported\n", nb);
+
+ return 0;
+}
+
+static struct platform_driver gpio_export_driver = {
+ .driver = {
+ .name = "gpio-export",
+ .owner = THIS_MODULE,
+ .of_match_table = of_match_ptr(gpio_export_ids),
+ },
+ .probe = of_gpio_export_probe,
+};
+
+module_platform_driver(gpio_export_driver);
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -571,7 +571,7 @@ static struct class gpio_class = {
*
* Returns zero on success, else an error.
*/
-int gpiod_export(struct gpio_desc *desc, bool direction_may_change)
+int __gpiod_export(struct gpio_desc *desc, bool direction_may_change, const char *name)
{
struct gpio_chip *chip;
struct gpio_device *gdev;
@@ -633,6 +633,8 @@ int gpiod_export(struct gpio_desc *desc,
offset = gpio_chip_hwgpio(desc);
if (chip->names && chip->names[offset])
ioname = chip->names[offset];
+ if (name)
+ ioname = name;
dev = device_create_with_groups(&gpio_class, &gdev->dev,
MKDEV(0, 0), data, gpio_groups,
@@ -654,6 +656,12 @@ err_unlock:
gpiod_dbg(desc, "%s: status %d\n", __func__, status);
return status;
}
+EXPORT_SYMBOL_GPL(__gpiod_export);
+
+int gpiod_export(struct gpio_desc *desc, bool direction_may_change)
+{
+ return __gpiod_export(desc, direction_may_change, NULL);
+}
EXPORT_SYMBOL_GPL(gpiod_export);
static int match_export(struct device *dev, const void *desc)
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -127,6 +127,12 @@ static inline int gpio_export(unsigned g
return gpiod_export(gpio_to_desc(gpio), direction_may_change);
}
+int __gpiod_export(struct gpio_desc *desc, bool direction_may_change, const char *name);
+static inline int gpio_export_with_name(unsigned gpio, bool direction_may_change, const char *name)
+{
+ return __gpiod_export(gpio_to_desc(gpio), direction_may_change, name);
+}
+
static inline int gpio_export_link(struct device *dev, const char *name,
unsigned gpio)
{
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -668,6 +668,7 @@ static inline void devm_acpi_dev_remove_
#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
+int _gpiod_export(struct gpio_desc *desc, bool direction_may_change, const char *name);
int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
int gpiod_export_link(struct device *dev, const char *name,
struct gpio_desc *desc);
@@ -675,6 +676,13 @@ void gpiod_unexport(struct gpio_desc *de
#else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
+static inline int _gpiod_export(struct gpio_desc *desc,
+ bool direction_may_change,
+ const char *name)
+{
+ return -ENOSYS;
+}
+
static inline int gpiod_export(struct gpio_desc *desc,
bool direction_may_change)
{

View file

@ -0,0 +1,20 @@
Index: linux-5.4.124/drivers/mtd/nand/spi/gigadevice.c
===================================================================
--- linux-5.4.124.orig/drivers/mtd/nand/spi/gigadevice.c
+++ linux-5.4.124/drivers/mtd/nand/spi/gigadevice.c
@@ -242,6 +242,15 @@ static const struct spinand_info gigadev
SPINAND_HAS_QE_BIT,
SPINAND_ECCINFO(&gd5fxgq4xa_ooblayout,
gd5fxgq4xa_ecc_get_status)),
+ SPINAND_INFO("GD5F2GQ4xB", 0xD2,
+ NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 1, 1, 1),
+ NAND_ECCREQ(8, 512),
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+ &write_cache_variants,
+ &update_cache_variants),
+ SPINAND_HAS_QE_BIT,
+ SPINAND_ECCINFO(&gd5fxgq4xa_ooblayout,
+ gd5fxgq4xa_ecc_get_status)),
SPINAND_INFO("GD5F4GQ4xA", 0xF4,
NAND_MEMORG(1, 2048, 64, 64, 4096, 80, 1, 1, 1),
NAND_ECCREQ(8, 512),

View file

@ -0,0 +1,53 @@
--- a/drivers/mtd/nand/spi/winbond.c
+++ b/drivers/mtd/nand/spi/winbond.c
@@ -75,7 +75,7 @@
}
static const struct spinand_info winbond_spinand_table[] = {
- SPINAND_INFO("W25M02GV", 0xAB,
+ SPINAND_INFO("W25M02GV", 0xAB21,
NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 2),
NAND_ECCREQ(1, 512),
SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
@@ -84,8 +84,16 @@
0,
SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL),
SPINAND_SELECT_TARGET(w25m02gv_select_target)),
- SPINAND_INFO("W25N01GV", 0xAA,
+ SPINAND_INFO("W25N01GV", 0xAA21,
NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
+ NAND_ECCREQ(1, 512),
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+ &write_cache_variants,
+ &update_cache_variants),
+ 0,
+ SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL)),
+ SPINAND_INFO("W25N02KV", 0xAA22,
+ NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 1, 1, 1),
NAND_ECCREQ(1, 512),
SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
&write_cache_variants,
@@ -102,17 +110,21 @@
static int winbond_spinand_detect(struct spinand_device *spinand)
{
u8 *id = spinand->id.data;
+ u16 did;
int ret;
/*
* Winbond SPI NAND read ID need a dummy byte,
* so the first byte in raw_id is dummy.
+ * Second and also third byte are device id
*/
if (id[1] != SPINAND_MFR_WINBOND)
return 0;
+ else
+ did = (id[2] << 8) + id[3];
ret = spinand_match_and_init(spinand, winbond_spinand_table,
- ARRAY_SIZE(winbond_spinand_table), id[2]);
+ ARRAY_SIZE(winbond_spinand_table), did);
if (ret)
return ret;

View file

@ -0,0 +1,25 @@
--- a/drivers/mtd/nand/spi/xtx.c
+++ b/drivers/mtd/nand/spi/xtx.c
@@ -37,8 +37,8 @@
if (section)
return -ERANGE;
- region->offset = 8;
- region->length = 40;
+ region->offset = 48;
+ region->length = 16;
return 0;
}
@@ -49,8 +49,9 @@
if (section)
return -ERANGE;
- region->offset = 1;
- region->length = 7;
+ /* Reserve 2 bytes for the BBM. */
+ region->offset = 2;
+ region->length = 62;
return 0;
}

View file

@ -0,0 +1,506 @@
Index: linux-5.4.124/drivers/platform/Kconfig
===================================================================
--- linux-5.4.124.orig/drivers/platform/Kconfig
+++ linux-5.4.124/drivers/platform/Kconfig
@@ -13,5 +13,9 @@ source "drivers/platform/chrome/Kconfig"
source "drivers/platform/mellanox/Kconfig"
source "drivers/platform/olpc/Kconfig"
source "drivers/platform/mikrotik/Kconfig"
+
+if ARCH_QCOM
+source "drivers/platform/ipq/Kconfig"
+endif
Index: linux-5.4.124/drivers/platform/Makefile
===================================================================
--- linux-5.4.124.orig/drivers/platform/Makefile
+++ linux-5.4.124/drivers/platform/Makefile
@@ -9,4 +9,5 @@ obj-$(CONFIG_MIPS) += mips/
obj-$(CONFIG_OLPC_EC) += olpc/
obj-$(CONFIG_GOLDFISH) += goldfish/
obj-$(CONFIG_CHROME_PLATFORMS) += chrome/
obj-$(CONFIG_MIKROTIK) += mikrotik/
+obj-$(CONFIG_ARCH_QCOM) += ipq/
Index: linux-5.4.124/drivers/platform/ipq/bootconfig.c
===================================================================
--- /dev/null
+++ linux-5.4.124/drivers/platform/ipq/bootconfig.c
@@ -0,0 +1,403 @@
+/*
+ * Copyright (c) 2015-2016 The Linux Foundation. All rights reserved.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/io.h>
+#include <linux/seq_file.h>
+#include <asm/setup.h>
+#include <linux/mtd/partitions.h>
+#include <linux/proc_fs.h>
+#include <linux/slab.h>
+#include <linux/uaccess.h>
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/genhd.h>
+#include <linux/major.h>
+#include <linux/mtd/blktrans.h>
+#include <linux/mtd/mtd.h>
+#include <linux/types.h>
+#include <linux/blkdev.h>
+#include "bootconfig.h"
+
+static struct proc_dir_entry *boot_info_dir;
+static struct proc_dir_entry *partname_dir[NUM_ALT_PARTITION];
+
+static unsigned int num_parts;
+static unsigned int flash_type_emmc;
+
+struct sbl_if_dualboot_info_type_v2 *bootconfig1;
+struct sbl_if_dualboot_info_type_v2 *bootconfig2;
+
+static int getbinary_show(struct seq_file *m, void *v)
+{
+ struct sbl_if_dualboot_info_type_v2 *sbl_info_v2;
+
+ sbl_info_v2 = m->private;
+ memcpy(m->buf + m->count, sbl_info_v2,
+ sizeof(struct sbl_if_dualboot_info_type_v2));
+ m->count += sizeof(struct sbl_if_dualboot_info_type_v2);
+
+ return 0;
+}
+
+static int getbinary_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, getbinary_show, PDE_DATA(inode));
+}
+
+static const struct file_operations getbinary_ops = {
+ .open = getbinary_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static int part_upgradepartition_show(struct seq_file *m, void *v)
+{
+ struct per_part_info *part_info_t = m->private;
+
+ /*
+ * In case of NOR\NAND, SBLs change the names of paritions in
+ * such a way that the partition to upgrade is always suffixed
+ * by _1. This is not the case in eMMC as paritions are read
+ * from GPT and we have no control on it. So for eMMC we need
+ * to check and generate the name wheres for NOR\NAND it is
+ * always _1 SBLs should be modified not to change partition
+ * names so that it is consistent with GPT. Till that is done
+ * we will take care of it here.
+ */
+
+ if (flash_type_emmc && (part_info_t->primaryboot))
+ seq_printf(m, "%s\n", part_info_t->name);
+ else
+ seq_printf(m, "%s_1\n", part_info_t->name);
+
+ return 0;
+
+}
+
+static int part_upgradepartition_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, part_upgradepartition_show, PDE_DATA(inode));
+}
+
+static const struct file_operations upgradepartition_ops = {
+ .open = part_upgradepartition_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+
+static ssize_t part_primaryboot_write(struct file *file,
+ const char __user *user,
+ size_t count, loff_t *data)
+{
+ int ret;
+ char optstr[64];
+ struct per_part_info *part_entry;
+ unsigned long val;
+
+ part_entry = PDE_DATA(file_inode(file));
+
+ if (count == 0 || count > sizeof(optstr))
+ return -EINVAL;
+
+ ret = copy_from_user(optstr, user, count);
+ if (ret)
+ return ret;
+
+ optstr[count - 1] = '\0';
+
+ ret = kstrtoul(optstr, 0, &val);
+ if (ret)
+ return ret;
+
+ part_entry->primaryboot = val;
+
+ return count;
+
+}
+
+static int part_primaryboot_show(struct seq_file *m, void *v)
+{
+ struct per_part_info *part_entry;
+
+ part_entry = m->private;
+ seq_printf(m, "%x\n", part_entry->primaryboot);
+ return 0;
+}
+
+static int part_primaryboot_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, part_primaryboot_show, PDE_DATA(inode));
+}
+
+static const struct file_operations primaryboot_ops = {
+ .open = part_primaryboot_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+ .write = part_primaryboot_write,
+};
+
+
+struct sbl_if_dualboot_info_type_v2 *read_bootconfig_mtd(
+ struct mtd_info *master,
+ uint64_t offset)
+{
+
+ size_t retlen = 0;
+ struct sbl_if_dualboot_info_type_v2 *bootconfig_mtd;
+ int ret;
+
+ while (mtd_block_isbad(master, offset)) {
+ offset += master->erasesize;
+ if (offset >= master->size) {
+ pr_alert("Bad blocks occurred while reading from \"%s\"\n",
+ master->name);
+ return NULL;
+ }
+ }
+ bootconfig_mtd = kmalloc(sizeof(struct sbl_if_dualboot_info_type_v2),
+ GFP_ATOMIC);
+
+ if (!bootconfig_mtd)
+ return NULL;
+
+ ret = mtd_read(master, offset,
+ sizeof(struct sbl_if_dualboot_info_type_v2),
+ &retlen, (void *)bootconfig_mtd);
+ if (ret < 0) {
+ pr_alert("error occured while reading from \"%s\"\n",
+ master->name);
+ bootconfig_mtd = NULL;
+ kfree(bootconfig_mtd);
+ return NULL;
+ }
+
+ if (bootconfig_mtd->magic_start != SMEM_DUAL_BOOTINFO_MAGIC_START) {
+ pr_alert("Magic not found in \"%s\"\n", master->name);
+ kfree(bootconfig_mtd);
+ return NULL;
+ }
+
+ return bootconfig_mtd;
+}
+
+struct sbl_if_dualboot_info_type_v2 *read_bootconfig_emmc(struct gendisk *disk,
+ struct hd_struct *part)
+{
+ sector_t n;
+ Sector sect;
+ int ret;
+ unsigned char *data;
+ struct sbl_if_dualboot_info_type_v2 *bootconfig_emmc;
+ unsigned ssz;
+ struct block_device *bdev = NULL;
+
+ bdev = bdget_disk(disk, 0);
+ if (!bdev)
+ return NULL;
+
+ bdev->bd_invalidated = 1;
+ ret = blkdev_get(bdev, FMODE_READ , NULL);
+ if (ret)
+ return NULL;
+
+ ssz = bdev_logical_block_size(bdev);
+ bootconfig_emmc = kmalloc(ssz, GFP_ATOMIC);
+ if (!bootconfig_emmc)
+ return NULL;
+
+ n = part->start_sect * (bdev_logical_block_size(bdev) / 512);
+ data = read_dev_sector(bdev, n, &sect);
+ put_dev_sector(sect);
+ blkdev_put(bdev, FMODE_READ);
+ if (!data) {
+ kfree(bootconfig_emmc);
+ return NULL;
+ }
+
+ memcpy(bootconfig_emmc, data, 512);
+
+ if (bootconfig_emmc->magic_start != SMEM_DUAL_BOOTINFO_MAGIC_START) {
+ pr_alert("Magic not found\n");
+ kfree(bootconfig_emmc);
+ return NULL;
+ }
+
+ return bootconfig_emmc;
+}
+
+#define BOOTCONFIG_PARTITION "0:BOOTCONFIG"
+#define BOOTCONFIG_PARTITION1 "0:BOOTCONFIG1"
+#define ROOTFS_PARTITION "rootfs"
+
+static int __init bootconfig_partition_init(void)
+{
+ struct per_part_info *part_info;
+ int i;
+ struct gendisk *disk = NULL;
+ struct disk_part_iter piter;
+ struct hd_struct *part;
+ struct mtd_info *mtd;
+ int partno;
+
+ /*
+ * In case of NOR\NAND boot, there is a chance that emmc
+ * might have bootconfig paritions. This will try to read
+ * the bootconfig partitions and create a proc entry which
+ * is not correct since it is not booting from emmc.
+ */
+
+ mtd = get_mtd_device_nm(ROOTFS_PARTITION);
+ if (IS_ERR(mtd))
+ flash_type_emmc = 1;
+ mtd = get_mtd_device_nm(BOOTCONFIG_PARTITION);
+ if (!IS_ERR(mtd)) {
+
+ bootconfig1 = read_bootconfig_mtd(mtd, 0);
+ mtd = get_mtd_device_nm(BOOTCONFIG_PARTITION1);
+ if (IS_ERR(mtd)) {
+ pr_alert("%s: " BOOTCONFIG_PARTITION1 " not found\n",
+ __func__);
+ return 0;
+ }
+
+ bootconfig2 = read_bootconfig_mtd(mtd, 0);
+ } else if (flash_type_emmc == 1) {
+ flash_type_emmc = 0;
+ disk = get_gendisk(MKDEV(MMC_BLOCK_MAJOR, 0), &partno);
+ if (!disk)
+ return 0;
+
+ disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
+ while ((part = disk_part_iter_next(&piter))) {
+
+ if (part->info) {
+ if (!strcmp((char *)part->info->volname,
+ BOOTCONFIG_PARTITION)) {
+ bootconfig1 = read_bootconfig_emmc(disk,
+ part);
+ }
+
+ if (!strcmp((char *)part->info->volname,
+ BOOTCONFIG_PARTITION1)) {
+ bootconfig2 = read_bootconfig_emmc(disk,
+ part);
+ flash_type_emmc = 1;
+ }
+ }
+ }
+ disk_part_iter_exit(&piter);
+
+ }
+
+ if (!bootconfig1) {
+ if (bootconfig2)
+ bootconfig1 = bootconfig2;
+ else
+ return 0;
+ }
+
+ if (!bootconfig2) {
+ if (bootconfig1)
+ bootconfig2 = bootconfig1;
+ else
+ return 0;
+ }
+/*
+ * The following check is to handle the case when an image without
+ * apps upgrade support is upgraded to the image that supports APPS
+ * upgrade. Earlier, the bootconfig file will be chosen based on age,
+ * but now bootconfig1 only is considered and bootconfig2 is a backup.
+ * When bootconfig2 is active in the older image and sysupgrade
+ * is done to it, we copy the bootconfig2 to bootconfig1 so that the
+ * failsafe parameters can be retained.
+ */
+ if (bootconfig2->age > bootconfig1->age)
+ bootconfig1 = bootconfig2;
+
+ num_parts = bootconfig1->numaltpart;
+ bootconfig1->age++;
+ part_info = (struct per_part_info *)bootconfig1->per_part_entry;
+ boot_info_dir = proc_mkdir("boot_info", NULL);
+ if (!boot_info_dir)
+ return 0;
+
+ for (i = 0; i < num_parts; i++) {
+ if (!flash_type_emmc &&
+ (strncmp(part_info[i].name, "kernel",
+ ALT_PART_NAME_LENGTH) == 0))
+ continue;
+
+ partname_dir[i] = proc_mkdir(part_info[i].name, boot_info_dir);
+ if (partname_dir != NULL) {
+ proc_create_data("primaryboot", S_IRUGO,
+ partname_dir[i],
+ &primaryboot_ops,
+ part_info + i);
+ proc_create_data("upgradepartition", S_IRUGO,
+ partname_dir[i],
+ &upgradepartition_ops,
+ part_info + i);
+ }
+ }
+
+ proc_create_data("getbinary_bootconfig", S_IRUGO, boot_info_dir,
+ &getbinary_ops, bootconfig1);
+ proc_create_data("getbinary_bootconfig1", S_IRUGO, boot_info_dir,
+ &getbinary_ops, bootconfig1);
+
+ return 0;
+}
+module_init(bootconfig_partition_init);
+
+static void __exit bootconfig_partition_exit(void)
+{
+ struct per_part_info *part_info;
+ int i;
+
+ if (!bootconfig1)
+ return;
+
+ if (!bootconfig2)
+ return;
+
+ part_info = (struct per_part_info *)bootconfig1->per_part_entry;
+ for (i = 0; i < num_parts; i++) {
+ if (!flash_type_emmc &&
+ (strncmp(part_info[i].name, "kernel",
+ ALT_PART_NAME_LENGTH) == 0))
+ continue;
+
+ remove_proc_entry("primaryboot", partname_dir[i]);
+ remove_proc_entry("upgradepartition", partname_dir[i]);
+ remove_proc_entry(part_info[i].name, boot_info_dir);
+ }
+ remove_proc_entry("getbinary_bootconfig", boot_info_dir);
+ remove_proc_entry("getbinary_bootconfig1", boot_info_dir);
+ remove_proc_entry("boot_info", NULL);
+ kfree(bootconfig1);
+ kfree(bootconfig2);
+}
+
+module_exit(bootconfig_partition_exit);
+
+MODULE_LICENSE("Dual BSD/GPL");
Index: linux-5.4.124/drivers/platform/ipq/bootconfig.h
===================================================================
--- /dev/null
+++ linux-5.4.124/drivers/platform/ipq/bootconfig.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2015-2016 The Linux Foundation. All rights reserved.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _BOOTCONFIG_H_
+#define _BOOTCONFIG_H_
+
+#define BOOTCONFIG_PART_IDX_MAX 21
+
+#define ALT_PART_NAME_LENGTH 16
+struct per_part_info {
+ char name[ALT_PART_NAME_LENGTH];
+ uint32_t primaryboot;
+};
+
+#define NUM_ALT_PARTITION 8
+
+/* version 2 */
+#define SMEM_DUAL_BOOTINFO_MAGIC_START 0xA3A2A1A0
+#define SMEM_DUAL_BOOTINFO_MAGIC_END 0xB3B2B1B0
+
+struct sbl_if_dualboot_info_type_v2 {
+ uint32_t magic_start;
+ uint32_t age;
+ uint32_t numaltpart;
+ struct per_part_info per_part_entry[NUM_ALT_PARTITION];
+ uint32_t magic_end;
+} __packed;
+
+#endif /* _BOOTCONFIG_H_ */
+
Index: linux-5.4.124/drivers/platform/ipq/Kconfig
===================================================================
--- /dev/null
+++ linux-5.4.124/drivers/platform/ipq/Kconfig
@@ -0,0 +1,11 @@
+menu "IPQ specific device drivers"
+ depends on ARCH_QCOM
+
+config BOOTCONFIG_PARTITION
+ tristate "BOOTCONFIG Partition support"
+ help
+ Say Y here if you would like to use hard disks under Linux which
+ were partitioned using MTD/EFI.
+
+endmenu
+
Index: linux-5.4.124/drivers/platform/ipq/Makefile
===================================================================
--- /dev/null
+++ linux-5.4.124/drivers/platform/ipq/Makefile
@@ -0,0 +1,5 @@
+#
+# Makefile for the IPQ specific device drivers.
+#
+
+obj-$(CONFIG_BOOTCONFIG_PARTITION) += bootconfig.o

View file

@ -0,0 +1,53 @@
--- a/fs/jffs2/writev.c
+++ b/fs/jffs2/writev.c
@@ -16,9 +16,18 @@
int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs,
unsigned long count, loff_t to, size_t *retlen)
{
+ int ret;
+
+ ret = mtd_writev(c->mtd, vecs, count, to, retlen);
+
if (!jffs2_is_writebuffered(c)) {
if (jffs2_sum_active()) {
int res;
+
+ if (ret ||
+ *retlen != iov_length((struct iovec *) vecs, count))
+ return ret;
+
res = jffs2_sum_add_kvec(c, vecs, count, (uint32_t) to);
if (res) {
return res;
@@ -26,18 +35,22 @@
}
}
- return mtd_writev(c->mtd, vecs, count, to, retlen);
+ return ret;
}
int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len,
size_t *retlen, const u_char *buf)
{
int ret;
+
ret = mtd_write(c->mtd, ofs, len, retlen, buf);
if (jffs2_sum_active()) {
struct kvec vecs[1];
int res;
+
+ if (ret || *retlen != len)
+ return ret;
vecs[0].iov_base = (unsigned char *) buf;
vecs[0].iov_len = len;
@@ -47,5 +60,6 @@
return res;
}
}
+
return ret;
}

View file

@ -0,0 +1,210 @@
--- a/drivers/net/phy/qca807x.c
+++ b/drivers/net/phy/qca807x.c
@@ -122,9 +122,24 @@
#define PSGMII_MODE_CTRL_AZ_WORKAROUND_MASK GENMASK(3, 0)
#define PSGMII_MMD3_SERDES_CONTROL 0x805a
+#define QCA8075_PHY4_PREFER_FIBER 0x400
+
struct qca807x_gpio_priv {
struct phy_device *phy;
};
+
+/* Phy medium type */
+typedef enum {
+ QCA8075_PHY_MEDIUM_COPPER = 0,
+ QCA8075_PHY_MEDIUM_FIBER = 1, /**< Fiber */
+ QCA8075_PHY_MEDIUM_NULL = 2 /**< NULL */
+} qca8075_phy_medium_t;
+
+static qca8075_phy_medium_t last_phy_medium = QCA8075_PHY_MEDIUM_NULL;
+static int last_phydev_link_state = -1;
+static int copper_link = 0;
+static int fiber_link = 0;
+static int report_last_status = 0;
static int qca807x_get_downshift(struct phy_device *phydev, u8 *data)
{
@@ -400,6 +415,142 @@
}
#endif
+static qca8075_phy_medium_t phy_prefer_medium_get(struct phy_device *phydev)
+{
+ int val;
+ val = phy_read(phydev, QCA807X_CHIP_CONFIGURATION);
+
+ return ((val & QCA8075_PHY4_PREFER_FIBER) ?
+ QCA8075_PHY_MEDIUM_FIBER : QCA8075_PHY_MEDIUM_COPPER);
+}
+
+static qca8075_phy_medium_t phy_active_medium_get(struct phy_device *phydev) {
+ int val;
+ val = phy_read(phydev, QCA807X_MEDIA_SELECT_STATUS);
+
+ if (val & QCA807X_MEDIA_DETECTED_COPPER) {
+ return QCA8075_PHY_MEDIUM_COPPER;
+ } else if ((val & QCA807X_MEDIA_DETECTED_1000_BASE_X) ||
+ (val & QCA807X_MEDIA_DETECTED_100_BASE_FX)) {
+ return QCA8075_PHY_MEDIUM_FIBER;
+ } else {
+ return phy_prefer_medium_get(phydev);
+ }
+}
+
+static int ar40xx_update_link(struct phy_device *phydev)
+{
+ int status = 0, bmcr;
+ qca8075_phy_medium_t phy_medium;
+
+ phy_medium = phy_active_medium_get(phydev);
+
+ /* Do a fake read */
+ bmcr = phy_read(phydev, MII_BMSR);
+ if (bmcr < 0)
+ return bmcr;
+
+ /* Autoneg is being started, therefore disregard BMSR value and
+ * report link as down.
+ */
+ if (bmcr & BMCR_ANRESTART)
+ goto done;
+
+ /* The link state is latched low so that momentary link
+ * drops can be detected. Do not double-read the status
+ * in polling mode to detect such short link drops except
+ * the link was already down.
+ */
+ if (!phy_polling_mode(phydev) || !phydev->link) {
+ status = phy_read(phydev, MII_BMSR);
+ if (status < 0)
+ return status;
+ else if (status & BMSR_LSTATUS)
+ goto done;
+ }
+
+ /* Read link and autonegotiation status */
+ status = phy_read(phydev, MII_BMSR);
+ if (status < 0)
+ return status;
+done:
+ if ( report_last_status > 0 ) {
+ report_last_status = 0;
+ phydev->link = last_phydev_link_state;
+ return 0;
+ }
+ /* reporting copper/fiber link state to netdev */
+ if ((status & BMSR_LSTATUS) == 0) {
+ phydev->link = 0;
+ if (last_phy_medium == phy_medium) { /* medium not changed */
+ if(phydev->link != last_phydev_link_state)
+ report_last_status++;
+ if (phy_medium == QCA8075_PHY_MEDIUM_FIBER)
+ fiber_link = 0;
+ else
+ copper_link = 0;
+ } else { /* medium changed, check current medium*/
+ if (phy_medium == QCA8075_PHY_MEDIUM_FIBER) { /* fiber active*/
+ if (copper_link == 1) { /* copper active, but not preferred*/
+ if(phydev->link == last_phydev_link_state) {
+ phydev->link = !phydev->link; /* toggle link state */
+ report_last_status++;
+ }
+ }
+ fiber_link = 0;
+ } else { /* copper active*/
+ if (fiber_link == 1) { /* fiber active, preferred*/
+ if(phydev->link == last_phydev_link_state) {
+ phydev->link = !phydev->link; /* toggle link state */
+ report_last_status++;
+ }
+ }
+ copper_link = 0;
+ }
+ }
+ } else {
+ phydev->link = 1;
+ if (last_phy_medium == phy_medium){
+ if (phy_medium == QCA8075_PHY_MEDIUM_FIBER)
+ fiber_link = 1;
+ else
+ copper_link = 1;
+ }
+ else {
+ if (phy_medium == QCA8075_PHY_MEDIUM_FIBER) { /* fiber active*/
+ if (copper_link == 1) { /* copper active, but not preferred*/
+ if(phydev->link == last_phydev_link_state) {
+ phydev->link = !phydev->link;
+ report_last_status++;
+ }
+ }
+ fiber_link = 1;
+ } else { /* copper active*/
+ if (fiber_link == 1) { /* fiber active, preferred*/
+ if(phydev->link == last_phydev_link_state) {
+ phydev->link = !phydev->link;
+ report_last_status++;
+ }
+ }
+ copper_link = 1;
+ }
+ }
+ }
+
+ phydev->autoneg_complete = status & BMSR_ANEGCOMPLETE ? 1 : 0;
+
+ /* Consider the case that autoneg was started and "aneg complete"
+ * bit has been reset, but "link up" bit not yet.
+ */
+ if (phydev->autoneg == AUTONEG_ENABLE && !phydev->autoneg_complete)
+ phydev->link = 0;
+
+ last_phy_medium = phy_medium;
+ last_phydev_link_state = phydev->link;
+
+ return 0;
+}
+
static int qca807x_read_copper_status(struct phy_device *phydev, bool combo_port)
{
int ss, err, page, old_link = phydev->link;
@@ -415,7 +566,7 @@
}
/* Update the link, but return if there was an error */
- err = genphy_update_link(phydev);
+ err = ar40xx_update_link(phydev);
if (err)
return err;
@@ -499,7 +650,7 @@
}
/* Update the link, but return if there was an error */
- err = genphy_update_link(phydev);
+ err = ar40xx_update_link(phydev);
if (err)
return err;
@@ -559,7 +710,7 @@
static int qca807x_read_status(struct phy_device *phydev)
{
- int val;
+ int val, err;
/* Check for Combo port */
if (phy_read(phydev, QCA807X_CHIP_CONFIGURATION)) {
@@ -572,6 +723,11 @@
} else if ((val & QCA807X_MEDIA_DETECTED_1000_BASE_X) ||
(val & QCA807X_MEDIA_DETECTED_100_BASE_FX)) {
qca807x_read_fiber_status(phydev, true);
+ } else {
+ /* Update the link, but return if there was an error */
+ err = ar40xx_update_link(phydev);
+ if (err)
+ return err;
}
} else {
qca807x_read_copper_status(phydev, true);

View file

@ -0,0 +1,63 @@
Index: linux-5.4.124/drivers/net/phy/ar40xx.c
===================================================================
--- linux-5.4.124.orig/drivers/net/phy/ar40xx.c
+++ linux-5.4.124/drivers/net/phy/ar40xx.c
@@ -771,9 +771,58 @@ ar40xx_sw_get_port_link(struct switch_de
return 0;
}
+static int
+ar40xx_sw_delay_reset(struct switch_dev *dev,
+ const struct switch_attr *attr,
+ struct switch_val *value)
+{
+ struct ar40xx_priv *priv = swdev_to_ar40xx(dev);
+ struct mii_bus *bus;
+ int i;
+ u16 val;
+
+ bus = priv->mii_bus;
+ for (i = 0; i < AR40XX_NUM_PORTS - 2; i++) {
+ mdiobus_write(bus, i, MII_CTRL1000, 0);
+ mdiobus_write(bus, i, MII_ADVERTISE, 0);
+ mdiobus_write(bus, i, MII_BMCR, BMCR_RESET | BMCR_ANENABLE);
+ ar40xx_phy_dbg_read(priv, i, AR40XX_PHY_DEBUG_0, &val);
+ val |= AR40XX_PHY_MANU_CTRL_EN;
+ ar40xx_phy_dbg_write(priv, i, AR40XX_PHY_DEBUG_0, val);
+ /* disable transmit */
+ ar40xx_phy_dbg_read(priv, i, AR40XX_PHY_DEBUG_2, &val);
+ val &= 0xf00f;
+ ar40xx_phy_dbg_write(priv, i, AR40XX_PHY_DEBUG_2, val);
+ }
+
+ msleep(1000 * value->value.i);
+
+ for (i = 0; i < AR40XX_NUM_PORTS - 2; i++) {
+ ar40xx_phy_dbg_read(priv, i, AR40XX_PHY_DEBUG_0, &val);
+ val &= ~AR40XX_PHY_MANU_CTRL_EN;
+ ar40xx_phy_dbg_write(priv, i, AR40XX_PHY_DEBUG_0, val);
+ mdiobus_write(bus, i,
+ MII_ADVERTISE, ADVERTISE_ALL |
+ ADVERTISE_PAUSE_CAP |
+ ADVERTISE_PAUSE_ASYM);
+ mdiobus_write(bus, i, MII_CTRL1000, ADVERTISE_1000FULL);
+ mdiobus_write(bus, i, MII_BMCR, BMCR_RESET | BMCR_ANENABLE);
+ }
+
+ ar40xx_phy_poll_reset(priv);
+
+ return 0;
+}
+
static const struct switch_attr ar40xx_sw_attr_globals[] = {
{
.type = SWITCH_TYPE_INT,
+ .name = "soft_reset",
+ .description = "Switch soft reset with delay (seconds)",
+ .set = ar40xx_sw_delay_reset
+ },
+ {
+ .type = SWITCH_TYPE_INT,
.name = "enable_vlan",
.description = "Enable VLAN mode",
.set = ar40xx_sw_set_vlan,

View file

@ -0,0 +1,151 @@
--- a/drivers/net/phy/ar40xx.c
+++ b/drivers/net/phy/ar40xx.c
@@ -82,6 +82,13 @@
MIB_DESC(1, AR40XX_STATS_TXLATECOL, "TxLateCol"),
};
+static int
+ar40xx_atu_flush(struct ar40xx_priv *);
+
+static int
+ar40xx_atu_dump(struct ar40xx_priv *);
+
+
static u32
ar40xx_read(struct ar40xx_priv *priv, int reg)
{
@@ -810,6 +817,35 @@
}
ar40xx_phy_poll_reset(priv);
+
+ return 0;
+}
+
+static int
+ar40xx_sw_atu_flush(struct switch_dev *dev,
+ const struct switch_attr *attr,
+ struct switch_val *val)
+{
+ struct ar40xx_priv *priv = swdev_to_ar40xx(dev);
+
+ return ar40xx_atu_flush(priv);
+}
+
+static int
+ar40xx_sw_atu_dump(struct switch_dev *dev,
+ const struct switch_attr *attr,
+ struct switch_val *val)
+{
+ struct ar40xx_priv *priv = swdev_to_ar40xx(dev);
+ int len=0;
+
+ len = ar40xx_atu_dump(priv);
+ if(len >= 0){
+ val->value.s = priv->buf;
+ val->len = len;
+ } else {
+ val->len = -1;
+ }
return 0;
}
@@ -868,6 +904,18 @@
.max = AR40XX_NUM_PORTS - 1
},
{
+ .type = SWITCH_TYPE_NOVAL,
+ .name = "flush_arl",
+ .description = "Flush ARL table",
+ .set = ar40xx_sw_atu_flush,
+ },
+ {
+ .type = SWITCH_TYPE_STRING,
+ .name = "dump_arl",
+ .description = "Dump ARL table with mac and port map",
+ .get = ar40xx_sw_atu_dump,
+ },
+ {
.type = SWITCH_TYPE_INT,
.name = "linkdown",
.description = "Link down all the PHYs",
@@ -925,6 +973,65 @@
pr_err("ar40xx: timeout for reg %08x: %08x & %08x != %08x\n",
(unsigned int)reg, t, mask, val);
return -ETIMEDOUT;
+}
+
+static int
+ar40xx_atu_dump(struct ar40xx_priv *priv)
+{
+ u32 ret;
+ u32 i = 0, len = 0, entry_len = 0;
+ volatile u32 reg[4] = {0,0,0,0};
+ u8 addr[ETH_ALEN] = { 0 };
+ char *buf;
+
+ buf = priv->buf;
+ memset(priv->buf, 0, sizeof(priv->buf));
+ do {
+ ret = ar40xx_wait_bit(priv, AR40XX_REG_ATU_FUNC,
+ AR40XX_ATU_FUNC_BUSY, 0);
+ if(ret != 0)
+ return -ETIMEDOUT;
+
+ reg[3] = AR40XX_ATU_FUNC_BUSY | AR40XX_ATU_FUNC_OP_GET_NEXT;
+ ar40xx_write(priv, AR40XX_REG_ATU_DATA0, reg[0]);
+ ar40xx_write(priv, AR40XX_REG_ATU_DATA1, reg[1]);
+ ar40xx_write(priv, AR40XX_REG_ATU_DATA2, reg[2]);
+ ar40xx_write(priv, AR40XX_REG_ATU_FUNC, reg[3]);
+
+ ret = ar40xx_wait_bit(priv, AR40XX_REG_ATU_FUNC,
+ AR40XX_ATU_FUNC_BUSY, 0);
+ if(ret != 0)
+ return -ETIMEDOUT;
+
+ reg[0] = ar40xx_read(priv, AR40XX_REG_ATU_DATA0);
+ reg[1] = ar40xx_read(priv, AR40XX_REG_ATU_DATA1);
+ reg[2] = ar40xx_read(priv, AR40XX_REG_ATU_DATA2);
+ reg[3] = ar40xx_read(priv, AR40XX_REG_ATU_FUNC);
+
+ if((reg[2] & 0xf) == 0)
+ break;
+
+ for(i=2; i<6; i++)
+ addr[i] = (reg[0] >> ((5 - i) << 3)) & 0xff;
+ for(i=0; i<2; i++)
+ addr[i] = (reg[1] >> ((1 - i) << 3)) & 0xff;
+
+ len += snprintf(buf + len, sizeof(priv->buf) - len, "MAC: %02x:%02x:%02x:%02x:%02x:%02x ",
+ addr[0],addr[1],addr[2],addr[3],addr[4],addr[5]);
+ len += snprintf(buf + len, sizeof(priv->buf) - len, "PORTMAP: 0x%02x ", ((reg[1] >> 16) & 0x7f));
+
+ len += snprintf(buf + len, sizeof(priv->buf) - len, "VID: 0x%x ", ((reg[2] >> 8) & 0xfff));
+
+ len += snprintf(buf + len, sizeof(priv->buf) - len, "STATUS: 0x%x\n", ((reg[2] & 0xf) == 0xf ? 1 : 0));
+
+ if (!entry_len)
+ entry_len = len;
+
+ if (sizeof(priv->buf) - len <= entry_len)
+ break;
+ } while(1);
+
+ return len;
}
static int
--- a/drivers/net/phy/ar40xx.h
+++ b/drivers/net/phy/ar40xx.h
@@ -243,6 +243,10 @@
#define AR40XX_PORT_LOOKUP_LOOPBACK BIT(21)
#define AR40XX_PORT_LOOKUP_ING_MIRROR_EN BIT(25)
+#define AR40XX_REG_ATU_DATA0 0x600
+#define AR40XX_REG_ATU_DATA1 0x604
+#define AR40XX_REG_ATU_DATA2 0x608
+
#define AR40XX_REG_ATU_FUNC 0x60c
#define AR40XX_ATU_FUNC_OP BITS(0, 4)
#define AR40XX_ATU_FUNC_OP_NOOP 0x0

View file

@ -0,0 +1,97 @@
--- a/drivers/net/phy/ar40xx.h
+++ b/drivers/net/phy/ar40xx.h
@@ -282,6 +282,13 @@
#define AR40XX_PHY_SPEC_STATUS_DUPLEX BIT(13)
#define AR40XX_PHY_SPEC_STATUS_SPEED BITS(14, 2)
+#define COMBO_PHY_ID 4
+#define QCA807X_CHIP_CONFIGURATION 0x1f /* Chip Configuration Register */
+
+#define QCA8075_PHY4_PREFER_FIBER 0x400
+#define PHY4_PREFER_COPPER 0x0
+#define PHY4_PREFER_FIBER 0x1
+
/* port forwarding state */
enum {
AR40XX_PORT_STATE_DISABLED = 0,
--- a/drivers/net/phy/ar40xx.c
+++ b/drivers/net/phy/ar40xx.c
@@ -612,6 +612,62 @@
ar40xx_port_phy_linkdown(priv);
else
ar40xx_phy_init(priv);
+
+ return 0;
+}
+
+static int phy_prefer_medium_set(struct ar40xx_priv *priv, u16 medium)
+{
+ struct mii_bus *bus;
+ u16 phy_medium;
+
+ bus = priv->mii_bus;
+ phy_medium =
+ mdiobus_read(bus, COMBO_PHY_ID , QCA807X_CHIP_CONFIGURATION);
+
+ if (medium == PHY4_PREFER_FIBER) {
+ phy_medium |= QCA8075_PHY4_PREFER_FIBER;
+ } else {
+ phy_medium &= ~QCA8075_PHY4_PREFER_FIBER;
+ }
+
+ mdiobus_write(bus, COMBO_PHY_ID, QCA807X_CHIP_CONFIGURATION, phy_medium );
+
+ return 0;
+}
+
+static int
+ar40xx_sw_set_preference(struct switch_dev *dev,
+ const struct switch_attr *attr,
+ struct switch_val *val)
+{
+ struct ar40xx_priv *priv = swdev_to_ar40xx(dev);
+ u16 pref;
+ if (val->value.i == 0)
+ pref = PHY4_PREFER_COPPER;
+ else
+ pref = PHY4_PREFER_FIBER;
+
+ phy_prefer_medium_set(priv, pref);
+
+ return 0;
+}
+
+static int
+ar40xx_sw_get_preference(struct switch_dev *dev,
+ const struct switch_attr *attr,
+ struct switch_val *val)
+{
+ struct ar40xx_priv *priv = swdev_to_ar40xx(dev);
+
+ struct mii_bus *bus;
+ u16 phy_medium;
+
+ bus = priv->mii_bus;
+ phy_medium =
+ mdiobus_read(bus, COMBO_PHY_ID , QCA807X_CHIP_CONFIGURATION);
+
+ val->value.i = phy_medium;
return 0;
}
@@ -922,6 +978,14 @@
.set = ar40xx_sw_set_linkdown,
.max = 1
},
+ {
+ .type = SWITCH_TYPE_INT,
+ .name = "preference",
+ .description = "Set fiber/copper combo preference",
+ .set = ar40xx_sw_set_preference,
+ .get = ar40xx_sw_get_preference,
+ .max = 1
+ },
};
static const struct switch_attr ar40xx_sw_attr_port[] = {

View file

@ -0,0 +1,13 @@
Index: linux-5.4.147/drivers/usb/host/xhci.h
===================================================================
--- linux-5.4.147.orig/drivers/usb/host/xhci.h
+++ linux-5.4.147/drivers/usb/host/xhci.h
@@ -1654,7 +1654,7 @@ struct urb_priv {
* (1K bytes * 8bytes/bit) / (4*32 bits) = 64 segment entries in the table,
* meaning 64 ring segments.
* Initial allocated size of the ERST, in number of entries */
-#define ERST_NUM_SEGS 1
+#define ERST_NUM_SEGS 16
/* Initial allocated size of the ERST, in number of entries */
#define ERST_SIZE 64
/* Initial number of event segment rings allocated */

View file

@ -0,0 +1,105 @@
--- a/drivers/spi/spi-qup.c
+++ b/drivers/spi/spi-qup.c
@@ -273,9 +273,6 @@
writel_relaxed(QUP_OP_IN_SERVICE_FLAG,
controller->base + QUP_OPERATIONAL);
- if (!remainder)
- goto exit;
-
if (is_block_mode) {
num_words = (remainder > words_per_block) ?
words_per_block : remainder;
@@ -305,13 +302,11 @@
* to refresh opflags value because MAX_INPUT_DONE_FLAG may now be
* present and this is used to determine if transaction is complete
*/
-exit:
- if (!remainder) {
- *opflags = readl_relaxed(controller->base + QUP_OPERATIONAL);
- if (is_block_mode && *opflags & QUP_OP_MAX_INPUT_DONE_FLAG)
- writel_relaxed(QUP_OP_IN_SERVICE_FLAG,
- controller->base + QUP_OPERATIONAL);
- }
+ *opflags = readl_relaxed(controller->base + QUP_OPERATIONAL);
+ if (is_block_mode && *opflags & QUP_OP_MAX_INPUT_DONE_FLAG)
+ writel_relaxed(QUP_OP_IN_SERVICE_FLAG,
+ controller->base + QUP_OPERATIONAL);
+
}
static void spi_qup_write_to_fifo(struct spi_qup *controller, u32 num_words)
@@ -358,10 +353,6 @@
/* ACK by clearing service flag */
writel_relaxed(QUP_OP_OUT_SERVICE_FLAG,
controller->base + QUP_OPERATIONAL);
-
- /* make sure the interrupt is valid */
- if (!remainder)
- return;
if (is_block_mode) {
num_words = (remainder > words_per_block) ?
@@ -576,24 +567,10 @@
return 0;
}
-static bool spi_qup_data_pending(struct spi_qup *controller)
-{
- unsigned int remainder_tx, remainder_rx;
-
- remainder_tx = DIV_ROUND_UP(spi_qup_len(controller) -
- controller->tx_bytes, controller->w_size);
-
- remainder_rx = DIV_ROUND_UP(spi_qup_len(controller) -
- controller->rx_bytes, controller->w_size);
-
- return remainder_tx || remainder_rx;
-}
-
static irqreturn_t spi_qup_qup_irq(int irq, void *dev_id)
{
struct spi_qup *controller = dev_id;
u32 opflags, qup_err, spi_err;
- unsigned long flags;
int error = 0;
qup_err = readl_relaxed(controller->base + QUP_ERROR_FLAGS);
@@ -625,11 +602,6 @@
error = -EIO;
}
- spin_lock_irqsave(&controller->lock, flags);
- if (!controller->error)
- controller->error = error;
- spin_unlock_irqrestore(&controller->lock, flags);
-
if (spi_qup_is_dma_xfer(controller->mode)) {
writel_relaxed(opflags, controller->base + QUP_OPERATIONAL);
} else {
@@ -638,21 +610,10 @@
if (opflags & QUP_OP_OUT_SERVICE_FLAG)
spi_qup_write(controller);
-
- if (!spi_qup_data_pending(controller))
- complete(&controller->done);
- }
-
- if (error)
+ }
+
+ if ((opflags & QUP_OP_MAX_INPUT_DONE_FLAG) || error)
complete(&controller->done);
-
- if (opflags & QUP_OP_MAX_INPUT_DONE_FLAG) {
- if (!spi_qup_is_dma_xfer(controller->mode)) {
- if (spi_qup_data_pending(controller))
- return IRQ_HANDLED;
- }
- complete(&controller->done);
- }
return IRQ_HANDLED;
}

View file

@ -0,0 +1,21 @@
Index: linux-5.4.147/drivers/mtd/nand/spi/micron.c
===================================================================
--- linux-5.4.147.orig/drivers/mtd/nand/spi/micron.c
+++ linux-5.4.147/drivers/mtd/nand/spi/micron.c
@@ -91,7 +91,7 @@ static int mt29f2g01abagd_ecc_get_status
}
static const struct spinand_info micron_spinand_table[] = {
- SPINAND_INFO("MT29F2G01ABAGD", 0x24,
+ SPINAND_INFO("MT29F2G01ABAGD", 0x24, // Note: XTX nand flash XT26G02E have same MAN_ID and DEV_ID
NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 2, 1, 1),
NAND_ECCREQ(8, 512),
SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
@@ -128,6 +128,6 @@ static const struct spinand_manufacturer
const struct spinand_manufacturer micron_spinand_manufacturer = {
.id = SPINAND_MFR_MICRON,
- .name = "Micron",
+ .name = "Micron / XTX",
.ops = &micron_spinand_manuf_ops,
};

View file

@ -0,0 +1,22 @@
include $(TOPDIR)/rules.mk
ARCH:=aarch64
BOARD:=ipq60xx
BOARDNAME:=Qualcomm Technologies, Inc IPQ60xx
FEATURES:=ubifs squashfs fpu ramdisk nand pcie usbgadget
CPU_TYPE:=cortex-a53
CPU_SUBTYPE:=neon-vfpv4
MAINTAINER:=John Crispin <blogic@openwrt.org>
SUBTARGETS:=generic ipq60xx_32
KERNELNAME:=zImage Image dtbs
KERNEL_PATCHVER:=5.4
include $(INCLUDE_DIR)/target.mk
DEFAULT_PACKAGES += \
uboot-envtools kmod-leds-gpio kmod-gpio-button-hotplug kmod-button-hotplug \
kmod-ata-core kmod-ata-ahci kmod-ata-ahci-platform kmod-usb2 kmod-usb3 \
swconfig kmod-usb-phy-ipq807x kmod-usb-dwc3-qcom-internal
$(eval $(call BuildTarget))

View file

@ -0,0 +1,68 @@
#!/bin/sh
#
# Copyright (C) 2015 OpenWrt.org
#
. /lib/functions/uci-defaults.sh
board_config_update
board=$(board_name)
boardname="${board##*,}"
case "$board" in
alfa-network,ap120c-ac)
ucidef_set_led_netdev "wan" "WAN" "${boardname}:amber:wan" "eth1"
;;
asus,rt-ac58u)
ucidef_set_led_wlan "wlan2g" "WLAN2G" "${boardname}:blue:wlan2G" "phy0tpt"
ucidef_set_led_wlan "wlan5g" "WLAN5G" "${boardname}:blue:wlan5G" "phy1tpt"
ucidef_set_led_netdev "wan" "WAN" "${boardname}:blue:wan" "eth1"
ucidef_set_led_switch "lan" "LAN" "${boardname}:blue:lan" "switch0" "0x1e"
;;
avm,fritzbox-4040)
ucidef_set_led_wlan "wlan" "WLAN" "fritz4040:green:wlan" "phy0tpt" "phy1tpt"
ucidef_set_led_netdev "wan" "WAN" "fritz4040:green:wan" "eth1"
ucidef_set_led_switch "lan" "LAN" "fritz4040:green:lan" "switch0" "0x1e"
;;
avm,fritzbox-7530 |\
glinet,gl-b1300)
ucidef_set_led_wlan "wlan" "WLAN" "${boardname}:green:wlan" "phy0tpt"
;;
engenius,eap1300)
ucidef_set_led_netdev "lan" "LAN" "${boardname}:blue:lan" "eth0"
ucidef_set_led_wlan "wlan2g" "WLAN2G" "${boardname}:blue:wlan2g" "phy0tpt"
ucidef_set_led_wlan "wlan5g" "WLAN5G" "${boardname}:yellow:wlan5g" "phy1tpt"
ucidef_set_led_default "mesh" "MESH" "${boardname}:blue:mesh" "0"
;;
engenius,ens620ext)
ucidef_set_led_wlan "wlan2g" "WLAN2G" "${boardname}:green:wlan2G" "phy0tpt"
ucidef_set_led_wlan "wlan5g" "WLAN5G" "${boardname}:green:wlan5G" "phy1tpt"
ucidef_set_led_netdev "lan1" "LAN1" "${boardname}:green:lan1" "eth0"
ucidef_set_led_netdev "lan2" "LAN2" "${boardname}:green:lan2" "eth1"
;;
netgear,ex6100v2 |\
netgear,ex6150v2)
ucidef_set_led_wlan "wlan2g" "WLAN2G" "ex61x0v2:green:router" "phy0tpt"
ucidef_set_led_wlan "wlan5g" "WLAN5G" "ex61x0v2:green:client" "phy1tpt"
;;
qxwlan,e2600ac-c1 |\
qxwlan,e2600ac-c2)
ucidef_set_led_wlan "wlan2g" "WLAN0" "e2600ac:green:wlan0" "phy0tpt"
ucidef_set_led_wlan "wlan5g" "WLAN1" "e2600ac:green:wlan1" "phy1tpt"
;;
zyxel,nbg6617)
ucidef_set_led_wlan "wlan2g" "WLAN2G" "${boardname}:green:wlan2G" "phy0tpt"
ucidef_set_led_wlan "wlan5g" "WLAN5G" "${boardname}:green:wlan5G" "phy1tpt"
;;
zyxel,wre6606)
ucidef_set_led_wlan "wlan2g" "WLAN2G" "${boardname}:green:wlan2g" "phy0tpt"
ucidef_set_led_wlan "wlan5g" "WLAN5G" "${boardname}:green:wlan5g" "phy1tpt"
;;
*)
;;
esac
board_config_flush
exit 0

View file

@ -0,0 +1,46 @@
#!/bin/sh
#
# Copyright (c) 2015, 2020 The Linux Foundation. All rights reserved.
# Copyright (C) 2011 OpenWrt.org
#
[ -e /etc/config/network ] && exit 0
CFG=/etc/board.json
. /lib/functions/uci-defaults.sh
ipq60xx_setup_interfaces()
{
local board="$1"
case "$board" in
qcom,ipq6018-ap-cp01-c1 |\
qcom,ipq6018-ap-cp01-c2 |\
qcom,ipq6018-ap-cp01-c3 |\
qcom,ipq6018-ap-cp01-c4 |\
qcom,ipq6018-ap-cp01-c5 |\
qcom,ipq6018-db-cp01)
ucidef_set_interfaces_lan_wan "eth1 eth2 eth3 eth4" "eth0"
;;
pangu,l6018|\
wf,hr6001)
ucidef_set_interfaces_lan_wan "eth0 eth1 eth2 eth3" "eth4"
;;
qcom,ipq6018-ap-cp02-c1 |\
qcom,ipq6018-ap-cp03-c1 |\
qcom,ipq6018-db-cp02)
ucidef_set_interfaces_lan_wan "eth1" "eth0"
;;
*)
echo "Unsupported hardware. Network interfaces not intialized"
;;
esac
}
board_config_update
board=$(board_name)
ipq60xx_setup_interfaces $board
board_config_flush
exit 0

View file

@ -0,0 +1,17 @@
# Copyright (c) 2013, 2020, The Linux Foundation. All rights reserved.
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K shutdown
ttyMSM0::askfirst:/bin/ash --login

View file

@ -0,0 +1,21 @@
PART_NAME=firmware
REQUIRE_IMAGE_METADATA=1
RAMFS_COPY_BIN='fw_printenv fw_setenv'
RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock'
platform_check_image() {
return 0;
}
platform_do_upgrade() {
case "$(board_name)" in
pangu,l6018|\
wf,hr6001)
nand_do_upgrade "$1"
;;
*)
default_do_upgrade "$1"
;;
esac
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,518 @@
// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
/*
* IPQ6018 CP01 board device tree source
*
* Copyright (c) 2019-2021 The Linux Foundation. All rights reserved.
*/
/dts-v1/;
#include "ipq6018.dtsi"
#include "ipq6018-cpr-regulator.dtsi"
/ {
model = "WF HR6001";
compatible = "wf,hr6001", "qcom,ipq6018";
aliases {
led-boot = &power;
led-failsafe = &power;
led-running = &power;
led-upgrade = &power;
serial0 = &blsp1_uart3;
/*
* Aliases as required by u-boot
* to patch MAC addresses
*/
ethernet0 = "/soc/dp1";
ethernet1 = "/soc/dp2";
ethernet2 = "/soc/dp3";
ethernet3 = "/soc/dp4";
ethernet4 = "/soc/dp5";
};
chosen {
stdout-path = "serial0:115200n8";
bootargs-append = " root=/dev/ubiblock0_1 swiotlb=1";
};
};
&blsp1_uart3 {
pinctrl-0 = <&serial_3_pins>;
pinctrl-names = "default";
status = "ok";
};
&spi_0 {
cs-select = <0>;
status = "ok";
m25p80@0 {
#address-cells = <1>;
#size-cells = <1>;
reg = <0>;
compatible = "n25q128a11";
spi-max-frequency = <50000000>;
SBL1@0 {
label = "0:SBL1";
reg = <0x0 0xc0000>;
read-only;
};
MIBIB@c0000 {
label = "0:MIBIB";
reg = <0xc0000 0x10000>;
};
BOOTCONFIG@d0000 {
label = "0:BOOTCONFIG";
reg = <0xd0000 0x20000>;
read-only;
};
BOOTCONFIG1@f0000 {
label = "0:BOOTCONFIG1";
reg = <0xf0000 0x20000>;
read-only;
};
QSEE@110000 {
label = "0:QSEE";
reg = <0x110000 0x1a0000>;
read-only;
};
QSEE_1@2b0000 {
label = "0:QSEE_1";
reg = <0x2b0000 0x1a0000>;
read-only;
};
DEVCFG@450000 {
label = "0:DEVCFG";
reg = <0x450000 0x10000>;
read-only;
};
DEVCFG_1@460000 {
label = "0:DEVCFG_1";
reg = <0x460000 0x10000>;
read-only;
};
RPM@470000 {
label = "0:RPM";
reg = <0x4700000 0x40000>;
};
RPM_1@4b0000 {
label = "0:RPM_1";
reg = <0x4b0000 0x40000>;
read-only;
};
CDT@4f0000 {
label = "0:CDT";
reg = <0x4f0000 0x10000>;
};
CDT_1@500000 {
label = "0:CDT_1";
reg = <0x500000 0x10000>;
};
APPSBLENV@510000 {
label = "0:APPSBLENV";
reg = <0x510000 0x10000>;
};
APPSBL@520000 {
label = "0:APPSBL";
reg = <0x520000 0xa0000>;
};
APPSBL_1@5c0000 {
label = "0:APPSBL_1";
reg = <0x5c0000 0xa0000>;
};
ART: ART@660000 {
label = "0:ART";
reg = <0x660000 0x40000>;
};
};
};
&tlmm {
spi_0_pins: spi-0-pins {
pins = "gpio38", "gpio39", "gpio40", "gpio41";
function = "blsp0_spi";
drive-strength = <8>;
bias-pull-down;
};
sd_pins: sd-pinmux {
pins = "gpio62";
function = "sd_card";
drive-strength = <8>;
bias-pull-up;
};
i2c_1_pins: i2c_1_pins {
mux {
pins = "gpio42", "gpio43";
function = "blsp2_i2c";
drive-strength = <8>;
bias-pull-down;
};
};
mdio_pins: mdio_pinmux {
mux_0 {
pins = "gpio64";
function = "mdc";
drive-strength = <8>;
bias-pull-up;
};
mux_1 {
pins = "gpio65";
function = "mdio";
drive-strength = <8>;
bias-pull-up;
};
mux_2 {
pins = "gpio75";
function = "gpio";
bias-pull-up;
};
mux_3 {
pins = "gpio77";
function = "gpio";
bias-pull-up;
};
};
button_pins: button_pins {
reset_button {
pins = "gpio19";
function = "gpio";
drive-strength = <8>;
bias-pull-up;
};
};
led_pins: leds_pins {
wlan5g {
pins = "gpio35";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
};
wlan2g {
pins = "gpio37";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
};
lan1 {
pins = "gpio51";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
};
lan2 {
pins = "gpio24";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
};
lan3 {
pins = "gpio53";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
};
lan4 {
pins = "gpio25";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
};
wan {
pins = "gpio9";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
};
};
pwm_pins: pwm_pinmux {
pins = "gpio18";
function = "pwm00";
drive-strength = <8>;
};
};
&soc {
mdio: mdio@90000 {
pinctrl-0 = <&mdio_pins>;
pinctrl-names = "default";
phy-reset-gpio = <&tlmm 75 0 &tlmm 77 1>;
status = "ok";
phy0: ethernet-phy@0 {
reg = <0>;
};
phy1: ethernet-phy@1 {
reg = <1>;
};
phy2: ethernet-phy@2 {
reg = <2>;
};
phy3: ethernet-phy@3 {
reg = <3>;
};
phy4: ethernet-phy@4 {
reg = <0x18>;
};
};
dp1 {
device_type = "network";
compatible = "qcom,nss-dp";
qcom,id = <1>;
reg = <0x3a001000 0x200>;
qcom,mactype = <0>;
local-mac-address = [000000000000];
qcom,link-poll = <1>;
qcom,phy-mdio-addr = <0>;
phy-mode = "sgmii";
};
dp2 {
device_type = "network";
compatible = "qcom,nss-dp";
qcom,id = <2>;
reg = <0x3a001200 0x200>;
qcom,mactype = <0>;
local-mac-address = [000000000000];
qcom,link-poll = <1>;
qcom,phy-mdio-addr = <1>;
phy-mode = "sgmii";
};
dp3 {
device_type = "network";
compatible = "qcom,nss-dp";
qcom,id = <3>;
reg = <0x3a001400 0x200>;
qcom,mactype = <0>;
local-mac-address = [000000000000];
qcom,link-poll = <1>;
qcom,phy-mdio-addr = <2>;
phy-mode = "sgmii";
};
dp4 {
device_type = "network";
compatible = "qcom,nss-dp";
qcom,id = <4>;
reg = <0x3a001600 0x200>;
qcom,mactype = <0>;
local-mac-address = [000000000000];
qcom,link-poll = <1>;
qcom,phy-mdio-addr = <3>;
phy-mode = "sgmii";
};
dp5 {
device_type = "network";
compatible = "qcom,nss-dp";
qcom,id = <5>;
reg = <0x3a001800 0x200>;
qcom,mactype = <0>;
local-mac-address = [000000000000];
qcom,link-poll = <1>;
qcom,phy-mdio-addr = <24>;
phy-mode = "sgmii";
};
ess-switch@3a000000 {
switch_cpu_bmp = <0x1>; /* cpu port bitmap */
switch_lan_bmp = <0x1e>; /* lan port bitmap */
switch_wan_bmp = <0x20>; /* wan port bitmap */
switch_inner_bmp = <0xc0>; /*inner port bitmap*/
switch_mac_mode = <0x0>; /* mac mode for uniphy instance0*/
switch_mac_mode1 = <0xf>; /* mac mode for uniphy instance1*/
switch_mac_mode2 = <0xff>; /* mac mode for uniphy instance2*/
qcom,port_phyinfo {
port@0 {
port_id = <1>;
phy_address = <0>;
};
port@1 {
port_id = <2>;
phy_address = <1>;
};
port@2 {
port_id = <3>;
phy_address = <2>;
};
port@3 {
port_id = <4>;
phy_address = <3>;
};
port@4 {
port_id = <5>;
phy_address = <0x18>;
port_mac_sel = "QGMAC_PORT";
};
};
};
nss-macsec0 {
compatible = "qcom,nss-macsec";
phy_addr = <0x18>;
phy_access_mode = <0>;
mdiobus = <&mdio>;
};
pwm {
pinctrl-0 = <&pwm_pins>;
pinctrl-names = "default";
};
gpio_keys {
compatible = "gpio-keys";
pinctrl-0 = <&button_pins>;
pinctrl-names = "default";
button@1 {
label = "wps";
linux,code = <KEY_WPS_BUTTON>;
gpios = <&tlmm 19 GPIO_ACTIVE_LOW>;
linux,input-type = <1>;
debounce-interval = <60>;
};
};
leds {
compatible = "gpio-leds";
pinctrl-0 = <&led_pins>;
pinctrl-names = "default";
led@35 {
label = "green:wlan5g";
gpios = <&tlmm 35 GPIO_ACTIVE_HIGH>;
};
power: led@37 {
label = "green:wlan2g";
gpios = <&tlmm 37 GPIO_ACTIVE_HIGH>;
};
led@51 {
label = "green:lan1";
gpios = <&tlmm 51 GPIO_ACTIVE_HIGH>;
};
led@24 {
label = "green:lan2";
gpios = <&tlmm 24 GPIO_ACTIVE_HIGH>;
};
led@53 {
label = "green:lan3";
gpios = <&tlmm 53 GPIO_ACTIVE_HIGH>;
};
led@25 {
label = "green:lan4";
gpios = <&tlmm 25 GPIO_ACTIVE_HIGH>;
};
led@31 {
label = "green:wan";
gpios = <&tlmm 31 GPIO_ACTIVE_HIGH>;
};
};
};
&qpic_bam {
status = "ok";
};
&qpic_nand {
status = "ok";
nand@0 {
reg = <0>;
#address-cells = <1>;
#size-cells = <1>;
nand-ecc-strength = <4>;
nand-ecc-step-size = <512>;
nand-bus-width = <8>;
};
};
&pcie_phy {
status = "ok";
};
&pcie0 {
status = "ok";
};
&qusb_phy_1 {
status = "ok";
};
&usb2 {
status = "ok";
};
&sdhc_2 {
pinctrl-0 = <&sd_pins>;
pinctrl-names = "default";
cd-gpios = <&tlmm 62 GPIO_ACTIVE_LOW>;
status = "ok";
};
&qusb_phy_0 {
status = "ok";
};
&ssphy_0 {
status = "ok";
};
&usb3 {
status = "ok";
};
&nss_crypto {
status = "ok";
};
&i2c_1 {
pinctrl-0 = <&i2c_1_pins>;
pinctrl-names = "default";
status = "ok";
};
&sdhc_2 {
pinctrl-0 = <&sd_pins>;
pinctrl-names = "default";
cd-gpios = <&tlmm 62 1>;
sd-ldo-gpios = <&tlmm 66 0>;
vqmmc-supply = <&ipq6018_l2>;
status = "ok";
};

View file

@ -0,0 +1,631 @@
// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
/*
* IPQ6018 CP01 board device tree source
*
* Copyright (c) 2019-2021 The Linux Foundation. All rights reserved.
*/
/dts-v1/;
#include "ipq6018.dtsi"
#include "ipq6018-cpr-regulator.dtsi"
/ {
model = "PANGU L6018";
compatible = "pangu,l6018", "qcom,ipq6018";
aliases {
led-boot = &power;
led-failsafe = &power;
led-running = &power;
led-upgrade = &power;
serial0 = &blsp1_uart3;
/*
* Aliases as required by u-boot
* to patch MAC addresses
*/
ethernet0 = "/soc/dp1";
ethernet1 = "/soc/dp2";
ethernet2 = "/soc/dp3";
ethernet3 = "/soc/dp4";
ethernet4 = "/soc/dp5";
};
chosen {
stdout-path = "serial0:115200n8";
bootargs-append = " root=/dev/ubiblock0_1 swiotlb=1";
};
};
&blsp1_uart3 {
pinctrl-0 = <&serial_3_pins>;
pinctrl-names = "default";
status = "ok";
};
&i2c_1 {
pinctrl-0 = <&i2c_1_pins>;
pinctrl-names = "default";
status = "ok";
};
&spi_0 {
cs-select = <0>;
status = "ok";
m25p80@0 {
#address-cells = <1>;
#size-cells = <1>;
reg = <0>;
compatible = "n25q128a11";
spi-max-frequency = <50000000>;
SBL1@0 {
label = "0:SBL1";
reg = <0x0 0xc0000>;
read-only;
};
MIBIB@c0000 {
label = "0:MIBIB";
reg = <0xc0000 0x10000>;
};
BOOTCONFIG@d0000 {
label = "0:BOOTCONFIG";
reg = <0xd0000 0x20000>;
read-only;
};
BOOTCONFIG1@f0000 {
label = "0:BOOTCONFIG1";
reg = <0xf0000 0x20000>;
read-only;
};
QSEE@110000 {
label = "0:QSEE";
reg = <0x110000 0x1a0000>;
read-only;
};
QSEE_1@2b0000 {
label = "0:QSEE_1";
reg = <0x2b0000 0x1a0000>;
read-only;
};
DEVCFG@450000 {
label = "0:DEVCFG";
reg = <0x450000 0x10000>;
read-only;
};
DEVCFG_1@460000 {
label = "0:DEVCFG_1";
reg = <0x460000 0x10000>;
read-only;
};
RPM@470000 {
label = "0:RPM";
reg = <0x4700000 0x40000>;
};
RPM_1@4b0000 {
label = "0:RPM_1";
reg = <0x4b0000 0x40000>;
read-only;
};
CDT@4f0000 {
label = "0:CDT";
reg = <0x4f0000 0x10000>;
};
CDT_1@500000 {
label = "0:CDT_1";
reg = <0x500000 0x10000>;
read-only;
};
APPSBLENV@510000 {
label = "0:APPSBLENV";
reg = <0x510000 0x10000>;
};
APPSBL@520000 {
label = "0:APPSBL";
reg = <0x520000 0xa0000>;
};
APPSBL_1@5c0000 {
label = "0:APPSBL_1";
reg = <0x5c0000 0xa0000>;
};
ART: ART@660000 {
label = "0:ART";
reg = <0x660000 0x40000>;
};
};
};
&tlmm {
spi_0_pins: spi-0-pins {
pins = "gpio38", "gpio39", "gpio40", "gpio41";
function = "blsp0_spi";
drive-strength = <8>;
bias-pull-down;
};
i2c_1_pins: i2c_1_pins {
mux {
pins = "gpio42", "gpio43";
function = "blsp2_i2c";
drive-strength = <8>;
bias-pull-down;
};
};
button_pins: button_pins {
wps_button {
pins = "gpio9";
function = "gpio";
drive-strength = <8>;
bias-pull-up;
};
};
rst_usb_hub_pinmux {
mux {
pins = "gpio66";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
output-high;
};
};
mdio_pins: mdio_pinmux {
mux_0 {
pins = "gpio64";
function = "mdc";
drive-strength = <8>;
bias-pull-up;
};
mux_1 {
pins = "gpio65";
function = "mdio";
drive-strength = <8>;
bias-pull-up;
};
mux_2 {
pins = "gpio75";
function = "gpio";
bias-pull-up;
};
mux_3 {
pins = "gpio77";
function = "gpio";
bias-pull-up;
};
};
pcie0_pins: pcie_pins {
pcie0_rst {
pins = "gpio60";
function = "pcie0_rst";
drive-strength = <8>;
bias-pull-down;
};
pcie0_wake {
pins = "gpio36";
function = "pcie0_wake";
drive-strength = <8>;
bias-pull-down;
};
};
leds_pins: leds_pins {
power {
pins = "gpio25";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
};
wlan5g {
pins = "gpio35";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
};
wlan2g {
pins = "gpio37";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
};
usb1 {
pins = "gpio24";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
};
usb0 {
pins = "gpio50";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
};
lte1 {
pins = "gpio34";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
};
lte2 {
pins = "gpio29";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
};
lte3 {
pins = "gpio30";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
};
lte4 {
pins = "gpio31";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
};
lte5 {
pins = "gpio32";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
};
lte6 {
pins = "gpio23";
function = "gpio";
drive-strength = <8>;
bias-pull-down;
};
lte1pwr {
pins = "gpio0";
function = "gpio";
drive-strength = <8>;
bias-pull-up;
output-high;
};
lte2pwr {
pins = "gpio16";
function = "gpio";
drive-strength = <8>;
bias-pull-up;
output-high;
};
lte3pwr {
pins = "gpio18";
function = "gpio";
drive-strength = <8>;
bias-pull-up;
output-high;
};
lte4pwr {
pins = "gpio2";
function = "gpio";
drive-strength = <8>;
bias-pull-up;
output-high;
};
lte5pwr {
pins = "gpio21";
function = "gpio";
drive-strength = <8>;
bias-pull-up;
output-high;
};
lte6pwr {
pins = "gpio22";
function = "gpio";
drive-strength = <8>;
bias-pull-up;
output-high;
};
};
};
&soc {
mdio: mdio@90000 {
pinctrl-0 = <&mdio_pins>;
pinctrl-names = "default";
phy-reset-gpio = <&tlmm 75 0 &tlmm 77 1>;
status = "ok";
phy0: ethernet-phy@0 {
reg = <0>;
};
phy1: ethernet-phy@1 {
reg = <1>;
};
phy2: ethernet-phy@2 {
reg = <2>;
};
phy3: ethernet-phy@3 {
reg = <3>;
};
phy4: ethernet-phy@4 {
reg = <0x30>;
};
};
dp1 {
device_type = "network";
compatible = "qcom,nss-dp";
qcom,id = <1>;
reg = <0x3a001000 0x200>;
qcom,mactype = <0>;
local-mac-address = [000000000000];
qcom,link-poll = <1>;
qcom,phy-mdio-addr = <0>;
phy-mode = "sgmii";
};
dp2 {
device_type = "network";
compatible = "qcom,nss-dp";
qcom,id = <2>;
reg = <0x3a001200 0x200>;
qcom,mactype = <0>;
local-mac-address = [000000000000];
qcom,link-poll = <1>;
qcom,phy-mdio-addr = <1>;
phy-mode = "sgmii";
};
dp3 {
device_type = "network";
compatible = "qcom,nss-dp";
qcom,id = <3>;
reg = <0x3a001400 0x200>;
qcom,mactype = <0>;
local-mac-address = [000000000000];
qcom,link-poll = <1>;
qcom,phy-mdio-addr = <2>;
phy-mode = "sgmii";
};
dp4 {
device_type = "network";
compatible = "qcom,nss-dp";
qcom,id = <4>;
reg = <0x3a001600 0x200>;
qcom,mactype = <0>;
local-mac-address = [000000000000];
qcom,link-poll = <1>;
qcom,phy-mdio-addr = <3>;
phy-mode = "sgmii";
};
dp5 {
device_type = "network";
compatible = "qcom,nss-dp";
qcom,id = <5>;
reg = <0x3a003000 0x3fff>;
qcom,mactype = <1>;
local-mac-address = [000000000000];
qcom,link-poll = <1>;
qcom,phy-mdio-addr = <30>;
phy-mode = "sgmii";
};
ess-switch@3a000000 {
switch_cpu_bmp = <0x1>; /* cpu port bitmap */
switch_lan_bmp = <0x1e>; /* lan port bitmap */
switch_wan_bmp = <0x20>; /* wan port bitmap */
switch_inner_bmp = <0xc0>; /*inner port bitmap*/
switch_mac_mode = <0x0>; /* mac mode for uniphy instance0*/
switch_mac_mode1 = <0xe>; /* mac mode for uniphy instance1*/
switch_mac_mode2 = <0xff>; /* mac mode for uniphy instance2*/
qcom,port_phyinfo {
port@0 {
port_id = <1>;
phy_address = <0>;
};
port@1 {
port_id = <2>;
phy_address = <1>;
};
port@2 {
port_id = <3>;
phy_address = <2>;
};
port@3 {
port_id = <4>;
phy_address = <3>;
};
port@4 {
port_id = <5>;
phy_address = <30>;
phy_i2c_address = <30>;
phy-i2c-mode; /*i2c access phy */
media-type = "sfp"; /* fiber mode */
};
};
};
gpio_keys {
compatible = "gpio-keys";
pinctrl-0 = <&button_pins>;
pinctrl-names = "default";
button@1 {
label = "wps";
linux,code = <KEY_WPS_BUTTON>;
gpios = <&tlmm 9 GPIO_ACTIVE_LOW>;
linux,input-type = <1>;
debounce-interval = <60>;
};
};
leds {
compatible = "gpio-leds";
pinctrl-0 = <&leds_pins>;
pinctrl-names = "default";
led@24 {
label = "green:usb1";
gpios = <&tlmm 24 GPIO_ACTIVE_HIGH>;
};
led@50 {
label = "green:usb0";
gpios = <&tlmm 50 GPIO_ACTIVE_HIGH>;
};
power: led@25 {
label = "green:power";
gpios = <&tlmm 25 GPIO_ACTIVE_HIGH>;
};
led@35 {
label = "green:wlan5g";
gpios = <&tlmm 35 GPIO_ACTIVE_HIGH>;
};
led@37 {
label = "green:wlan2g";
gpios = <&tlmm 37 GPIO_ACTIVE_HIGH>;
};
led@34 {
label = "green:lte1";
gpios = <&tlmm 34 GPIO_ACTIVE_HIGH>;
};
led@29 {
label = "green:lte2";
gpios = <&tlmm 29 GPIO_ACTIVE_HIGH>;
};
led@30 {
label = "green:lte3";
gpios = <&tlmm 30 GPIO_ACTIVE_HIGH>;
};
led@31 {
label = "green:lte4";
gpios = <&tlmm 31 GPIO_ACTIVE_HIGH>;
};
led@32 {
label = "green:lte5";
gpios = <&tlmm 32 GPIO_ACTIVE_HIGH>;
};
led@23 {
label = "green:lte6";
gpios = <&tlmm 23 GPIO_ACTIVE_HIGH>;
};
led@0 {
label = "green:lte1pwr";
gpios = <&tlmm 0 GPIO_ACTIVE_HIGH>;
};
led@16 {
label = "green:lte2pwr";
gpios = <&tlmm 16 GPIO_ACTIVE_HIGH>;
};
led@18 {
label = "green:lte3pwr";
gpios = <&tlmm 18 GPIO_ACTIVE_HIGH>;
};
led@2 {
label = "green:lte4pwr";
gpios = <&tlmm 2 GPIO_ACTIVE_HIGH>;
};
led@21 {
label = "green:lte5pwr";
gpios = <&tlmm 21 GPIO_ACTIVE_HIGH>;
};
led@22 {
label = "green:lte6pwr";
gpios = <&tlmm 22 GPIO_ACTIVE_HIGH>;
};
};
};
&qpic_bam {
status = "ok";
};
&qpic_nand {
status = "ok";
nand@0 {
reg = <0>;
#address-cells = <1>;
#size-cells = <1>;
nand-ecc-strength = <4>;
nand-ecc-step-size = <512>;
nand-bus-width = <8>;
};
};
&pcie_phy {
status = "ok";
};
&pcie0 {
perst-gpio = <&tlmm 60 1>;
status = "ok";
};
&qusb_phy_1 {
status = "ok";
};
&usb2 {
status = "ok";
};
&qusb_phy_0 {
status = "ok";
};
&ssphy_0 {
status = "ok";
};
&usb3 {
status = "ok";
};
&nss_crypto {
status = "ok";
};

View file

@ -0,0 +1,70 @@
# CONFIG_32BIT is not set
CONFIG_64BIT=y
# CONFIG_ACPI is not set
# CONFIG_ARCH_BCM_IPROC is not set
# CONFIG_ARCH_EXYNOS7 is not set
CONFIG_ARCH_HAS_CACHE_LINE_SIZE=y
CONFIG_ARCH_HAS_HOLES_MEMORYMODEL=y
# CONFIG_ARCH_LAYERSCAPE is not set
CONFIG_ARCH_PHYS_ADDR_T_64BIT=y
# CONFIG_ARCH_SEATTLE is not set
CONFIG_ARCH_SELECT_MEMORY_MODEL=y
CONFIG_ARCH_SPARSEMEM_DEFAULT=y
CONFIG_ARCH_SPARSEMEM_ENABLE=y
# CONFIG_ARCH_SPRD is not set
# CONFIG_ARCH_STRATIX10 is not set
# CONFIG_ARCH_THUNDER is not set
CONFIG_ARCH_WANT_COMPAT_IPC_PARSE_VERSION=y
CONFIG_ARCH_WANT_FRAME_POINTERS=y
CONFIG_ARCH_WANT_HUGE_PMD_SHARE=y
# CONFIG_ARCH_XGENE is not set
# CONFIG_ARCH_ZYNQMP is not set
CONFIG_ARM64=y
# CONFIG_ARM64_16K_PAGES is not set
CONFIG_ARM64_4K_PAGES=y
# CONFIG_ARM64_64K_PAGES is not set
# CONFIG_ARM64_CRYPTO is not set
# CONFIG_ARM64_ERRATUM_819472 is not set
# CONFIG_ARM64_ERRATUM_824069 is not set
# CONFIG_ARM64_ERRATUM_826319 is not set
# CONFIG_ARM64_ERRATUM_827319 is not set
# CONFIG_ARM64_ERRATUM_832075 is not set
# CONFIG_ARM64_ERRATUM_843419 is not set
# CONFIG_ARM64_ERRATUM_845719 is not set
CONFIG_ARM64_HW_AFDBM=y
# CONFIG_ARM64_LSE_ATOMICS is not set
CONFIG_ARM64_PAN=y
# CONFIG_ARM64_PTDUMP is not set
# CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET is not set
CONFIG_ARM64_VA_BITS=39
CONFIG_ARM64_VA_BITS_39=y
# CONFIG_ARM64_VA_BITS_48 is not set
# CONFIG_ARMV8_DEPRECATED is not set
# CONFIG_CAVIUM_ERRATUM_22375 is not set
# CONFIG_CAVIUM_ERRATUM_23154 is not set
# CONFIG_CAVIUM_ERRATUM_27456 is not set
# CONFIG_COMMON_CLK_VERSATILE is not set
CONFIG_COMMON_CLK_XGENE=y
CONFIG_COMPAT=y
CONFIG_COMPAT_BINFMT_ELF=y
# CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is not set
# CONFIG_DEBUG_ALIGN_RODATA is not set
CONFIG_FRAME_WARN=2048
# CONFIG_GPIO_XGENE is not set
# CONFIG_HUGETLBFS is not set
# CONFIG_I2C_CADENCE is not set
# CONFIG_KASAN is not set
# CONFIG_KVM is not set
# CONFIG_NET_VENDOR_CAVIUM is not set
# CONFIG_PCI_HISI is not set
CONFIG_PHYS_ADDR_T_64BIT=y
# CONFIG_PHY_XGENE is not set
# CONFIG_POWER_RESET_XGENE is not set
CONFIG_QCOM_SCM_64=y
# CONFIG_RTC_DRV_EFI is not set
CONFIG_SPARSEMEM=y
CONFIG_SPARSEMEM_EXTREME=y
CONFIG_SPARSEMEM_MANUAL=y
CONFIG_SPARSEMEM_VMEMMAP=y
CONFIG_SPARSEMEM_VMEMMAP_ENABLE=y
CONFIG_VIRTUALIZATION=y

View file

@ -0,0 +1,12 @@
SUBTARGET:=generic
BOARDNAME:=QTI IPQ60xx(64bit) based boards
CPU_TYPE:=cortex-a53
KERNELNAME:=Image dtbs
DEFAULT_PACKAGES += \
sysupgrade-helper
define Target/Description
Build firmware image for IPQ60xx 64 bit system.
endef

View file

@ -0,0 +1,71 @@
# Copyright (c) 2014 The Linux Foundation. All rights reserved.
#
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/image.mk
define Device/Default
PROFILES := Default
KERNEL_LOADADDR := 0x41080000
KERNEL_DEPENDS = $$(wildcard $(DTS_DIR)/$$(DEVICE_DTS).dts)
KERNEL_INITRAMFS_PREFIX := $$(IMG_PREFIX)-$(1)-initramfs
KERNEL_PREFIX := $$(IMAGE_PREFIX)
SUPPORTED_DEVICES := $(subst _,$(comma),$(1))
IMAGE/sysupgrade.bin = sysupgrade-tar | append-metadata
IMAGE/sysupgrade.bin/squashfs :=
endef
define Device/LegacyImage
KERNEL_SUFFIX := -uImage
KERNEL = kernel-bin | append-dtb | uImage none
KERNEL_NAME := zImage
endef
define Device/FitImage
KERNEL_SUFFIX := -fit-uImage.itb
KERNEL = kernel-bin | gzip | fit gzip $$(DTS_DIR)/$$(DEVICE_DTS).dtb
KERNEL_NAME := Image
endef
define Device/FitImageLzma
KERNEL_SUFFIX := -fit-uImage.itb
KERNEL = kernel-bin | lzma | fit lzma $$(DTS_DIR)/$$(DEVICE_DTS).dtb
KERNEL_NAME := Image
endef
define Device/UbiFit
KERNEL_IN_UBI := 1
IMAGES := nand-factory.bin nand-sysupgrade.bin
IMAGE/nand-factory.bin := append-ubi
IMAGE/nand-sysupgrade.bin := sysupgrade-tar | append-metadata
endef
define Device/pangu_l6018
$(call Device/FitImage)
$(call Device/UbiFit)
DEVICE_DTS := ipq6018-l6018
DEVICE_DTS_CONFIG := config@cp01-c3
BLOCKSIZE := 128k
PAGESIZE := 2048
BOARD_NAME := ap-cp01-c3
DEVICE_TITLE := PANGU L6018
endef
TARGET_DEVICES += pangu_l6018
define Device/wf_hr6001
$(call Device/FitImage)
$(call Device/UbiFit)
KERNEL_LOADADDR := 0x41080000
DEVICE_DTS := ipq6018-hr6001
DEVICE_DTS_CONFIG := config@cp01-c1
BLOCKSIZE := 128k
PAGESIZE := 2048
BOARD_NAME := ap-cp01-c1
DEVICE_TITLE := WF HR6001
endef
TARGET_DEVICES += wf_hr6001
define Image/Build/squashfs
$(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
endef
$(eval $(call BuildImage))

View file

@ -0,0 +1,6 @@
CONFIG_ARCH_IPQ6018=y
CONFIG_ARCH_MMAP_RND_BITS=8
CONFIG_PCIE_DW_PLAT=y
# CONFIG_USB_QCOM_DIAG_BRIDGE is not set
CONFIG_VMSPLIT_2G=y
# CONFIG_VMSPLIT_3G is not set

View file

@ -0,0 +1,13 @@
ARCH:=arm
SUBTARGET:=ipq60xx_32
BOARDNAME:=QTI IPQ60xx(32bit) based boards
CPU_TYPE:=cortex-a7
DEFAULT_PACKAGES += \
uboot-2016-ipq6018 uboot-2016-ipq6018_tiny lk-ipq6018 \
fwupgrade-tools
define Target/Description
Build firmware image for IPQ60xx SoC devices.
endef

Some files were not shown because too many files have changed in this diff Show more