allwinner: add sun8i-emac driver

本文介绍了Allwinner H3芯片在OpenWRT上的适配情况,包括遇到的问题及解决办法。文中提及了内网卡和声卡的支持,并提供了在特定版本中成功实现支持的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近看到网上有个H3芯片的一些板子挺便宜的。尝试了一下,编译了openwrt的固件,发现没有支持内置的网卡和声卡。但是在网上下载了一些厂家的镜像却发现,在发行版的系统里是支持网卡和声卡的。

今天是2016年7月31号。如果是要编译openwrt的话,trunk版本对h3支持的比较好。

在 http://linux-sunxi.org/ 上溜达。搜索 "sun8i emac" ,在github上有这个支持的链接了。在github上可以找到 linux-sun8i-emac-wip-v2,看了一下里面确实包含了H3的dtsi和dts文件了。往下还没仔细看内容,先发个博文标记一下。


另外参看https://lwn.net/Articles/694927/

内容如下:

From: LABBE Corentin <clabbe.montjoie@gmail.com>
To: robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@free-electrons.com, wens@csie.org, linux@armlinux.org.uk, davem@davemloft.net
Subject: [PATCH v2 0/5] net-next: ethernet: add sun8i-emac driver
Date: Wed, 20 Jul 2016 10:03:15 +0200
Message-ID: <1469001800-11615-1-git-send-email-clabbe.montjoie@gmail.com>
Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, LABBE Corentin <clabbe.montjoie@gmail.com>
Archive-link: ArticleThread

Hello

This patch series add the driver for sun8i-emac which handle the Ethernet MAC present on Allwinner H3/A83T/A64 SoCs.

It supports 10/100/1000 Mbit/s speed with half/full duplex.It can use an internal PHY (MII 10/100) or an external PHY via RGMII/RMII.

This patch series enable the driver only for the H3 SoC since A83T and A64 doesn't have the necessary clocks present in mainline.

This patch series enable the driver only for the OrangePiPC board since other board with H3 use external PHY which need optional regulators that will be
supported later.

The driver have been tested on the following boards:
- H3 Orange PI PC, Orange PI Plus, BananaPI-M2+
- A64 Pine64
- A83T BananaPI-M3

I would like to thanks Chen-Yu Tsai for his help on developing this driver.

Regards

Changes since v1
- Implement NAPI
- Sorted and reworded all define
- Reworked ethtools stats strings
- Removed all unneeded __packked and __aligned
- Added tuning of RX/TX ring size via ethtool
- Corrected use of sk/skb naming
- Added some wmb when needed
- Moved irq claim/free to emac_open/close
- Lots of code refactoring

LABBE Corentin (5):
  ethernet: add sun8i-emac driver
  MAINTAINERS: Add myself as maintainers of sun8i-emac
  ARM: sun8i: dt: Add DT bindings documentation for Allwinner sun8i-emac
  ARM: dts: sun8i-h3: add sun8i-emac ethernet driver
  ARM: dts: sun8i: Enable sun8i-emac on the Orange PI PC

 .../bindings/net/allwinner,sun8i-emac.txt          |   65 +
 MAINTAINERS                                        |    6 +
 arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts         |   11 +
 arch/arm/boot/dts/sun8i-h3.dtsi                    |   14 +
 drivers/net/ethernet/allwinner/Kconfig             |   13 +
 drivers/net/ethernet/allwinner/Makefile            |    1 +
 drivers/net/ethernet/allwinner/sun8i-emac.c        | 2127 ++++++++++++++++++++
 7 files changed, 2237 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/allwinner,sun8i-emac.txt
 create mode 100644 drivers/net/ethernet/allwinner/sun8i-emac.c


全志A80的以太网使用固定MAC地址.txt 2015/12/3 16:09 开发板:美睿的商业开发板 OS:android4.4.2(美睿提供) linux:3.4.39 发现全志平台的A80的以太网的MAC地址是变化的,由于需要做MAC地址和IP绑定的问题。 问了一些人,可以通过外挂EEPROM。外挂器件硬件不同意。(改版或者面积占用的问题) 当然在其它平台:比如freescale平台可以将eMMC分一个私有分区保存数据,在 恢复出厂设置 的时候,不会被擦除,感觉全志平台也应该有(只找到A80的,A80的没有找到)。 http://bbs.elecfans.com/jishu_427503_1_1.html [Android问答] 关于全志A20的分区问题(sys_partition.fex) ; keydata = 1 ; //私有数据分区,重新量产数据将不丢失 http://blog.youkuaiyun.com/memechashang/article/details/23999857 http://yobin.sinaapp.com/topic/2780/android%E7%9A%84deviceid%E7%9A%84%E6%B7%BB%E5%8A%A0 Android的DeviceID的添加 找了好久,可以看见文件:/proc/cpuinfo中的CPU的ID号是唯一的。 测试:先刷美睿的系统,然后再刷原生的系统(支持4K录像,但是美睿没有移植驱动的系统),发现序列号没变。 序列号查看的方法:设置→关于平板电脑→状态信息→序列号:38608c0010503dd3d65c 中看到。 shell@kylin-merrii:/ $ cat /proc/cpuinfo Processor : ARMv7 Processor rev 5 (v7l) processor : 0 BogoMIPS : 4800.00 Features : swp half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpv4 idiva idivt CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x0 CPU part : 0xc07 CPU revision : 5 Hardware : sun9i Revision : 0000 Serial : 38608c0010503dd3d65c shell@kylin-merrii:/ $ 换了一台机器,序列号:38608 c0010 501dd 3560e 感觉序列号应该是唯一的!^_这里不做担保。 思路:于是想办法读取序列号,取后12位作为MAC地址! MAC地址的有效性: http://blog.youkuaiyun.com/skyflying2012/article/details/40322563 MAC地址格式小结 在IPv4的环境中,区分单播和组播地址就是校检最低位的二进制数字,0代表单播地址,1代表组播地址。 也就是说第二个数字一定是0、2、4、6、8、A、C、E其中的一个。 全志A80的BSP中的有效性验证: Z:\wyb\finish_a80_4k_bsp\meirrii_merrii_a80_merrii\lichee\linux-3.4\include\linux\etherdevice.h Z:\wyb\finish_a80_4k_bsp\meirrii_merrii_a80_merrii\lichee\linux-3.4\drivers\net\ethernet\sunxi\eth\sunxi_geth.c addr [0] &= 0xfe; /* clear multicast bit */ addr [0] |= 0x02; /* set local assignment bit (IEEE802) */ 感觉要么就是全志的BUG,要么就是全志的设置更加严格,这样下来第二个数字一定是2、6、A、E(不能是0、4、8、C)其中的一个。 实现原理: 曾经研究过内核中如何生成随机的MAC地址,android层中的setting如何获取序列号,然后准备在framework中拦截,走不通了。 http://bbs.youkuaiyun.com/topics/360240853 android 获取平板电脑序列号 http://blog.youkuaiyun.com/zhanghao_hulk/article/details/8286916 [置顶] android平台获取手机IMSI,IMEI ,序列号,和 手机号的方法 http://www.cnblogs.com/Amandaliu/archive/2012/12/04/2802322.html 【Android】获取Mac地址【2】 后来想起来,调试 以太网卡驱动的时候,曾经出现过手工加载 insmod /system/vendor/modules/sunxi_gmac.ko 就可以获取MAC地址上网。 既然这样,就在init.rc的服务中启动一个C程序来获取序列号,然后配置在模块 sunxi_gmac.ko 中。 Z:\wyb\finish_a80_4k_bsp\meirrii_merrii_a80_merrii\android4.4\device\softwinner\kylin-merrii\init.sun9i.rc 关闭init.rc中的以太网卡驱动的加载, # insmod network insmod /system/vendor/modules/bcmdhd.ko insmod /system/vendor/modules/bcm_btlpm.ko insmod /system/vendor/modules/usbnet.ko insmod /system/vendor/modules/asix.ko insmod /system/vendor/modules/qf9700.ko insmod /system/vendor/modules/mcs7830.ko insmod /system/vendor/modules/rtl8150.ko insmod /system/vendor/modules/cdc_ether.ko # insmod /system/vendor/modules/sunxi_gmac.ko 然后在 init.rc 的最后面做一个服务,在系统启动的时候, #2015/12/3 11:49 edit the ethernet's MAC address!!!! service wenyuanbo /system/bin/chip_id_as_mac class main user root group root oneshot 文件名:Android.mk LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_MODULE = chip_id_as_mac # LOCAL_SRC_FILES := $(call all-subdir-c-files) LOCAL_SRC_FILES := chip_id_as_mac.c include $(BUILD_EXECUTABLE) 文件名:chip_id_as_mac.c // http://blog.youkuaiyun.com/21cnbao/article/details/7919055 // Z:\wyb\finish_a80_4k_bsp\meirrii_merrii_a80_merrii\android4.4\system\core\init #include #include #include #include #include #include #include #include #include #include #include #include static int get_chip_id(char *buf, size_t size) { char *path = "/proc/cpuinfo"; FILE *fd; char data[128]; char *key, *value, *end; int len = -1; fd = fopen(path, "r"); if (fd == NULL) { printf("****wyb %s:%d/%s()! ERROR !!!! cannot open %s\n", __FILE__, __LINE__, __func__, path); return -1; } while (fgets(data, sizeof(data), fd)) { key = data; value = strchr(key, ':'); if (value == 0) continue; *value++ = 0; if (strncmp(key, "Serial", 6)) continue; while (isspace(*value)) value++; end = strchr(value, '\n'); *end = 0; len = snprintf(buf, size, "%s", value); // printf("****wyb %s:%d/%s()! buf=%s len=%d\n", __FILE__, __LINE__, __func__, buf, len); break; } fclose(fd); return 0; } int main(int argc, char **argv) { int ret; char buf[32] = {0}; char buf2[32] = {0}; int i = 0; // unsigned char ucTemp = 0; char ucTemp = 0; char path[200] = "insmod /system/vendor/modules/sunxi_gmac.ko mac_str=\""; if (get_chip_id(buf, sizeof(buf)) < 0) { printf("****wyb %s:%d/%s()! ERROR!!!!\n", __FILE__, __LINE__, __func__); } else { printf("****wyb %s:%d/%s()! 2015/12/2 16:51 get_chip_id=%s sizeof(buf)=%d\n", __FILE__, __LINE__, __func__, buf, sizeof(buf)); // for(i=0; i<6; i++) for(i=0; iadb push chip_id_as_mac /system/bin/ C:\Users\wenyb>adb remount remount succeeded C:\Users\wenyb>adb shell root@kylin-merrii:/ # cd /system/bin cd /system/bin root@kylin-merrii:/system/bin # chmod 777 chip_id_as_mac chmod 777 chip_id_as_mac root@kylin-merrii:/system/bin # ll chip* ll chip* -rwxrwxrwx root root 5368 2015-12-03 15:23 chip_id_as_mac root@kylin-merrii:/system/bin # sync sync root@kylin-merrii:/system/bin # reboot 困惑,下面这个程序的执行之后,MAC地址就成为了:1F:50:3d:d3:d6:5c。找了好久也找不到原因。 // http://blog.youkuaiyun.com/21cnbao/article/details/7919055 // Z:\wyb\finish_a80_4k_bsp\meirrii_merrii_a80_merrii\android4.4\system\core\init #include #include #include #include #include #include #include #include #include #include #include #include static int get_chip_id(char *buf, size_t size) { char *path = "/proc/cpuinfo"; FILE *fd; char data[128]; char *key, *value, *end; int len = -1; fd = fopen(path, "r"); if (fd == NULL) { printf("****wyb %s:%d/%s()! ERROR !!!! cannot open %s\n", __FILE__, __LINE__, __func__, path); return -1; } while (fgets(data, sizeof(data), fd)) { key = data; value = strchr(key, ':'); if (value == 0) continue; *value++ = 0; if (strncmp(key, "Serial", 6)) continue; while (isspace(*value)) value++; end = strchr(value, '\n'); *end = 0; len = snprintf(buf, size, "%s", value); // printf("****wyb %s:%d/%s()! buf=%s len=%d\n", __FILE__, __LINE__, __func__, buf, len); break; } fclose(fd); return 0; } int main(int argc, char **argv) { int ret; char buf[32] = {0}; char buf2[32] = {0}; int i = 0; // unsigned char ucTemp = 0; char ucTemp = 0; char path[200] = "insmod /system/vendor/modules/sunxi_gmac.ko mac_str=\""; if (get_chip_id(buf, sizeof(buf)) < 0) { printf("****wyb %s:%d/%s()! ERROR!!!!\n", __FILE__, __LINE__, __func__); } else { printf("****wyb %s:%d/%s()! 2015/12/2 16:51 get_chip_id=%s sizeof(buf)=%d\n", __FILE__, __LINE__, __func__, buf, sizeof(buf)); // for(i=0; i<6; i++) for(i=0; i='a') && (ucTemp='A') && (ucTemp='0') && (ucTemp9) { ucTemp = (ucTemp-10) + 'A'; } else { ucTemp += '0'; } buf2[1] = ucTemp; printf("****wyb %s:%d/%s()! 2015/12/2 17:13 get_chip_id/buf2=%s sizeof(buf2)=%d\n", __FILE__, __LINE__, __func__, buf2, sizeof(buf2)); // strcat(d,s); // strcat(path, buf2); strncat(path, buf2, 17); strcat(path, "\""); printf("****wyb %s:%d/%s()! 2015/12/3 15:11 get_chip_id/buf2=%s sizeof(buf2)=%d path=%s\n", __FILE__, __LINE__, __func__, buf2, sizeof(buf2), path); system(path); } return 0; }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值