MT7615 eeprom binary from filesystem
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 888
- Forks
- 436
- PR merge metrics
- No merged PRs in 30d
Description
I am using an MT7615 mini pcie card (https://docs.banana-pi.org/en/BPI-MT7615/BananaPi_MT7615) in a x86/64 device (Futro 940) with latest OpenWRT 23.05.5 (combined-efi ext4). Since the card does not have its own eeprom, the data has to be loaded during initialization. In this x86/64 case it seems to be the easiest to load the eeprom binary from file system which is not supported by default. I therefore use the following patch (originally from here: https://github.com/frank-w/BPI-Router-Linux/commit/fe31dae2ab5c2fbd39b6609845920969d10dd465) to implement this functionality:
diff -Naur a/eeprom.c b/eeprom.c
--- a/eeprom.c
+++ b/eeprom.c
@@ -10,6 +10,48 @@
#include <linux/etherdevice.h>
#include "mt76.h"
+static int
+mt76_get_eeprom_file(struct mt76_dev *dev, void *eep, int len)
+{
+ char path[64]="";
+ struct file *fp;
+ loff_t pos=0;
+ int ret;
+ struct inode *inode = NULL;
+ loff_t size;
+
+ ret = snprintf(path,sizeof(path),"/lib/firmware/mediatek/%s_rf.bin",dev->dev->driver->name);
+ if(ret<0)
+ return -EINVAL;
+ dev_info(dev->dev,"Load eeprom: %s\n",path);
+ fp = filp_open(path, O_RDONLY, 0);
+ if (IS_ERR(fp)) {
+ dev_info(dev->dev,"Open eeprom file failed: %s\n",path);
+ return -ENOENT;
+ }
+
+ inode = file_inode(fp);
+ if ((!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))) {
+ printk(KERN_ALERT "invalid file type: %s\n", path);
+ return -ENOENT;
+ }
+ size = i_size_read(inode->i_mapping->host);
+ if (size < 0)
+ {
+ printk(KERN_ALERT "failed getting size of %s size:%lld \n",path,size);
+ return -ENOENT;
+ }
+ ret = kernel_read(fp, eep, len, &pos);
+ if(ret < size){
+ dev_info(dev->dev,"Load eeprom ERR, count %d byte (len:%d)\n",ret,len);
+ return -ENOENT;
+ }
+ filp_close(fp, 0);
+ dev_info(dev->dev,"Load eeprom OK, count %d byte\n",ret);
+
+ return 0;
+}
+
static int mt76_get_of_eeprom_data(struct mt76_dev *dev, void *eep, int len)
{
#if defined(CONFIG_OF) && defined(CONFIG_MTD)
@@ -414,6 +414,7 @@
if (!dev->eeprom.data)
return -ENOMEM;
- return !mt76_get_of_eeprom(dev, dev->eeprom.data, len);
+ return (!mt76_get_of_eeprom(dev, dev->eeprom.data, len)) ||
+ (!mt76_get_eeprom_file(dev, dev->eeprom.data, len));
}
EXPORT_SYMBOL_GPL(mt76_eeprom_init);
It would be great if this feature could be permanently added to eeprom.c.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in eeprom.c at mt76_eeprom_init and the existing EEPROM data-loading path, then compare the issue's proposed filesystem-loading patch with those paths. Done means EEPROM data can be loaded from the filesystem during initialization for the described MT7615 setup while preserving existing initialization behavior and handling failed loads safely.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, linux
- Domain
- embedded-iot, networking, operating-systems
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100