将网卡的MAC保存i2c的EEPROM
-
T507的板子,在sunxi-gamc.c文件中,网卡获取到随机的mac地址后,我想写入到i2c挂载的eeprom中,一直有问题,显示写入和读取成功,但是读出来一直是FF。
这个是驱动里面操作读写的地方。static void geth_check_addr(struct net_device *ndev, unsigned char *mac) { int i; int ret; char *p = mac; struct i2c_adapter *adapter = NULL; struct i2c_client client; u8 write_data[ETH_ALEN]; u8 read_data[ETH_ALEN]; struct i2c_msg msgs[2]; // 修改为两个I2C消息 if (!is_valid_ether_addr(ndev->dev_addr)) { for (i = 0; i < ETH_ALEN; i++, p++) { ndev->dev_addr[i] = simple_strtoul(p, &p, 16); } if (!is_valid_ether_addr(ndev->dev_addr)) { random_ether_addr(ndev->dev_addr); printk("%s: Use random MAC address\n", ndev->name); adapter = i2c_get_adapter(0); if (!adapter) { pr_err("Failed to get I2C adapter\n"); return; } /* 设置 i2c 设备地址和组件信息 */ client.addr = 0x0050; client.adapter = adapter; client.flags = 0; //.driver = NULL, client.dev.platform_data = NULL; /* 将 MAC 地址数据写入 I2C 设备 */ memcpy(write_data, ndev->dev_addr, ETH_ALEN); msgs[0].addr = client.addr; msgs[0].flags = 0; msgs[0].len = ETH_ALEN; msgs[0].buf = write_data; ret = i2c_transfer(client.adapter, msgs, 1); if (ret != 1) { pr_err("Failed to write MAC address to I2C device\n"); } else { printk("Succeeded to write MAC address to I2C device\n"); print_mac_address(write_data); printk("\n"); } /* 从 I2C 设备读取 MAC 地址数据 */ msgs[1].addr = client.addr; msgs[1].flags = I2C_M_RD; msgs[1].len = ETH_ALEN; msgs[1].buf = read_data; ret = i2c_transfer(client.adapter, msgs + 1, 1); if (ret != 1) { pr_err("Failed to read MAC address from I2C device\n"); } else { printk("Succeeded to read MAC address from I2C device\n"); print_mac_address(read_data); } } } if (adapter) i2c_put_adapter(adapter); }
日志显示的读写一直不一致
这个问题一直没有解决思路和办法,想请教一下 -
建议先用 i2c-utils测试,i2cset, i2cset命令通过 /dev/i2c-X 测试。
Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号