diff options
author | Rafał Miłecki <zajec5@gmail.com> | 2015-05-13 08:30:45 +0000 |
---|---|---|
committer | Rafał Miłecki <zajec5@gmail.com> | 2015-05-13 08:30:45 +0000 |
commit | d2e5e2bf546955cb5782049e676e46e3ce442a21 (patch) | |
tree | cccd0bb7f0b969bb87fd84b637a9a7417c9b2572 /target/linux/bcm53xx | |
parent | 260383aeb17d8798d2da97a105da9fe8664fd8ea (diff) | |
download | mtk-20170518-d2e5e2bf546955cb5782049e676e46e3ce442a21.zip mtk-20170518-d2e5e2bf546955cb5782049e676e46e3ce442a21.tar.gz mtk-20170518-d2e5e2bf546955cb5782049e676e46e3ce442a21.tar.bz2 |
bcm53xx: sync NVRAM and SPROM drivers with upstream version
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
SVN-Revision: 45678
Diffstat (limited to 'target/linux/bcm53xx')
-rw-r--r-- | target/linux/bcm53xx/files/drivers/firmware/broadcom/bcm47xx_nvram.c | 22 | ||||
-rw-r--r-- | target/linux/bcm53xx/files/drivers/misc/bcm47xx-sprom.c | 20 |
2 files changed, 27 insertions, 15 deletions
diff --git a/target/linux/bcm53xx/files/drivers/firmware/broadcom/bcm47xx_nvram.c b/target/linux/bcm53xx/files/drivers/firmware/broadcom/bcm47xx_nvram.c index d0055a4..c7dcf1a 100644 --- a/target/linux/bcm53xx/files/drivers/firmware/broadcom/bcm47xx_nvram.c +++ b/target/linux/bcm53xx/files/drivers/firmware/broadcom/bcm47xx_nvram.c @@ -98,7 +98,7 @@ found: pr_err("The nvram size accoridng to the header seems to be bigger than the partition on flash\n"); if (header->len > NVRAM_SPACE) pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n", - header->len, NVRAM_SPACE); + header->len, NVRAM_SPACE - 1); src = (u32 *)header; dst = (u32 *)nvram_buf; @@ -106,6 +106,7 @@ found: *dst++ = __raw_readl(src++); for (; i < header->len && i < NVRAM_SPACE && i < size; i += 4) *dst++ = readl(src++); + nvram_buf[NVRAM_SPACE - 1] = '\0'; return 0; } @@ -150,10 +151,10 @@ static int nvram_init(void) u8 *dst = (uint8_t *)nvram_buf; size_t len = header.len; - if (header.len > NVRAM_SPACE) { + if (len >= NVRAM_SPACE) { + len = NVRAM_SPACE - 1; pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n", - header.len, NVRAM_SPACE); - len = NVRAM_SPACE; + header.len, len); } err = mtd_read(mtd, 0, len, &bytes_read, dst); @@ -170,7 +171,7 @@ static int nvram_init(void) int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len) { char *var, *value, *end, *eq; - int data_left, err; + int err; if (!name) return -EINVAL; @@ -183,19 +184,16 @@ int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len) /* Look for name=value and return value */ var = &nvram_buf[sizeof(struct nvram_header)]; - end = nvram_buf + sizeof(nvram_buf) - 2; - end[0] = '\0'; - end[1] = '\0'; - for (; *var; var = value + strlen(value) + 1) { - data_left = end - var; - - eq = strnchr(var, data_left, '='); + end = nvram_buf + sizeof(nvram_buf); + while (var < end && *var) { + eq = strchr(var, '='); if (!eq) break; value = eq + 1; if (eq - var == strlen(name) && strncmp(var, name, eq - var) == 0) return snprintf(val, val_len, "%s", value); + var = value + strlen(value) + 1; } return -ENOENT; } diff --git a/target/linux/bcm53xx/files/drivers/misc/bcm47xx-sprom.c b/target/linux/bcm53xx/files/drivers/misc/bcm47xx-sprom.c index e0cdd30..bb9f286 100644 --- a/target/linux/bcm53xx/files/drivers/misc/bcm47xx-sprom.c +++ b/target/linux/bcm53xx/files/drivers/misc/bcm47xx-sprom.c @@ -212,6 +212,9 @@ static void bcm47xx_sprom_fill_auto(struct ssb_sprom *sprom, bool fb = fallback; ENTRY(0xfffffffe, u16, pre, "boardrev", board_rev, 0, true); + ENTRY(0xfffffffe, u32, pre, "boardflags", boardflags, 0, fb); + ENTRY(0xfffffff0, u32, pre, "boardflags2", boardflags2, 0, fb); + ENTRY(0xfffff800, u32, pre, "boardflags3", boardflags3, 0, fb); ENTRY(0x00000002, u16, pre, "boardflags", boardflags_lo, 0, fb); ENTRY(0xfffffffc, u16, pre, "boardtype", board_type, 0, true); ENTRY(0xfffffffe, u16, pre, "boardnum", board_num, 0, fb); @@ -539,6 +542,8 @@ static int mac_addr_used = 2; static void bcm47xx_fill_sprom_ethernet(struct ssb_sprom *sprom, const char *prefix, bool fallback) { + bool fb = fallback; + nvram_read_macaddr(prefix, "et0macaddr", sprom->et0mac, fallback); nvram_read_u8(prefix, NULL, "et0mdcport", &sprom->et0mdcport, 0, fallback); @@ -551,6 +556,10 @@ static void bcm47xx_fill_sprom_ethernet(struct ssb_sprom *sprom, nvram_read_u8(prefix, NULL, "et1phyaddr", &sprom->et1phyaddr, 0, fallback); + nvram_read_macaddr(prefix, "et2macaddr", sprom->et2mac, fb); + nvram_read_u8(prefix, NULL, "et2mdcport", &sprom->et2mdcport, 0, fb); + nvram_read_u8(prefix, NULL, "et2phyaddr", &sprom->et2phyaddr, 0, fb); + nvram_read_macaddr(prefix, "macaddr", sprom->il0mac, fallback); nvram_read_macaddr(prefix, "il0macaddr", sprom->il0mac, fallback); @@ -629,6 +638,13 @@ void bcm47xx_fill_sprom(struct ssb_sprom *sprom, const char *prefix, bcm47xx_sprom_fill_auto(sprom, prefix, fallback); } +/* + * Having many NVRAM entries for PCI devices led to repeating prefixes like + * pci/1/1/ all the time and wasting flash space. So at some point Broadcom + * decided to introduce prefixes like 0: 1: 2: etc. + * If we find e.g. devpath0=pci/2/1 or devpath0=pci/2/1/ we should use 0: + * instead of pci/2/1/. + */ static void bcm47xx_sprom_apply_prefix_alias(char *prefix, size_t prefix_size) { size_t prefix_len = strlen(prefix); @@ -637,10 +653,8 @@ static void bcm47xx_sprom_apply_prefix_alias(char *prefix, size_t prefix_size) char buf[20]; int i; - if (prefix_len <= 0 || prefix[prefix_len - 1] != '/') { - pr_warn("Invalid prefix: \"%s\"\n", prefix); + if (prefix_len <= 0 || prefix[prefix_len - 1] != '/') return; - } for (i = 0; i < 3; i++) { if (snprintf(nvram_var, sizeof(nvram_var), "devpath%d", i) <= 0) |