Skip to content

Commit 10f0602

Browse files
committed
eep9287: implement update function
Implement updating MAC and clearing CTL data for AR9287 chipsets. Run-tested on Ubiquiti Nanobridge M2 (XM), and by re-dumping the modified data. Based on code from AR5416. As CTL data starts on even offset in this chip, the logic handling half-words can be skipped.
1 parent 2cc3716 commit 10f0602

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

eep_9287.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,62 @@ static void eep_9287_dump_power_info(struct atheepmgr *aem)
407407
#undef PR_TARGET_POWER
408408
}
409409

410+
static bool eep_9287_update_eeprom(struct atheepmgr *aem, int param,
411+
const void *data)
412+
{
413+
struct eep_9287_priv *emp = aem->eepmap_priv;
414+
struct ar9287_eeprom *eep = &emp->eep;
415+
uint16_t *buf = aem->eep_buf;
416+
int data_pos, data_len = 0, addr, el;
417+
uint16_t sum;
418+
419+
switch (param) {
420+
case EEP_UPDATE_MAC:
421+
data_pos = AR9287_DATA_START_LOC +
422+
EEP_FIELD_OFFSET(baseEepHeader.macAddr);
423+
data_len = EEP_FIELD_SIZE(baseEepHeader.macAddr);
424+
memcpy(&buf[data_pos], data, data_len * sizeof(uint16_t));
425+
break;
426+
#ifdef CONFIG_I_KNOW_WHAT_I_AM_DOING
427+
case EEP_ERASE_CTL:
428+
/* It is enough to erase the CTL index only */
429+
data_pos = AR9287_DATA_START_LOC + EEP_FIELD_OFFSET(ctlIndex);
430+
data_len = EEP_FIELD_SIZE(ctlIndex);
431+
for (addr = data_pos; addr < (data_pos + data_len); ++addr)
432+
buf[addr] = 0x0000;
433+
break;
434+
#endif
435+
default:
436+
fprintf(stderr, "Internal error: unknown parameter Id\n");
437+
return false;
438+
}
439+
440+
/* Store updated data */
441+
for (addr = data_pos; addr < (data_pos + data_len); ++addr) {
442+
if (!EEP_WRITE(addr, buf[addr])) {
443+
fprintf(stderr, "Unable to write EEPROM data at 0x%04x\n",
444+
addr);
445+
return false;
446+
}
447+
}
448+
449+
/* Update checksum if need it */
450+
if (data_pos > AR9287_DATA_START_LOC) {
451+
el = eep->baseEepHeader.length / sizeof(uint16_t);
452+
if (el > AR9287_DATA_SZ)
453+
el = AR9287_DATA_SZ;
454+
buf[AR9287_DATA_CSUM_LOC] = 0xffff;
455+
sum = eep_calc_csum(&buf[AR9287_DATA_START_LOC], el);
456+
buf[AR9287_DATA_CSUM_LOC] = sum;
457+
if (!EEP_WRITE(AR9287_DATA_CSUM_LOC, sum)) {
458+
fprintf(stderr, "Unable to update EEPROM checksum\n");
459+
return false;
460+
}
461+
}
462+
463+
return true;
464+
}
465+
410466
const struct eepmap eepmap_9287 = {
411467
.name = "9287",
412468
.desc = "AR9287 chip EEPROM map",
@@ -424,4 +480,10 @@ const struct eepmap eepmap_9287 = {
424480
[EEP_SECT_MODAL] = eep_9287_dump_modal_header,
425481
[EEP_SECT_POWER] = eep_9287_dump_power_info,
426482
},
483+
.update_eeprom = eep_9287_update_eeprom,
484+
.params_mask = BIT(EEP_UPDATE_MAC)
485+
#ifdef CONFIG_I_KNOW_WHAT_I_AM_DOING
486+
| BIT(EEP_ERASE_CTL)
487+
#endif
488+
,
427489
};

eep_9287.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define EEP_9287_H
1919

2020
#define AR9287_DATA_START_LOC 0x0080
21+
#define AR9287_DATA_CSUM_LOC (AR9287_DATA_START_LOC + 1)
2122
#define AR9287_CUSTOMER_DATA_SZ 32
2223
#define AR9287_MAX_CHAINS 2
2324
#define AR9287_NUM_2G_CAL_PIERS 3

0 commit comments

Comments
 (0)