1 --- a/driver/nvram_stub.c
2 +++ b/driver/nvram_stub.c
7 +#include <proto/ethernet.h>
10 #define NVR_MSG(x) printf x
11 @@ -24,6 +25,7 @@ typedef struct _vars {
12 static vars_t *vars = NULL;
13 static int nvram_init_done = 0;
14 extern char *nvram_buf[];
15 +static void fixup_mac_addr(vars_t *new);
18 BCMATTACHFN(nvram_init)(void *si)
19 @@ -55,6 +57,7 @@ BCMATTACHFN(nvram_init)(void *si)
22 bcopy((char *)(&nvh[1]), new->vars, nvs);
23 + fixup_mac_addr(new);
27 @@ -164,3 +167,65 @@ nvram_getall(char *buf, int count)
32 +static bool nvram_is_valid_mac(struct ether_addr *mac)
34 + return mac && !(mac->octet[0] == 0x00 && mac->octet[1] == 0x90 && mac->octet[2] == 0x4c);
37 +static int nvram_increase_mac_addr(struct ether_addr *mac, u8 num)
39 + u8 *oui = mac->octet + ETHER_ADDR_LEN/2 - 1;
40 + u8 *p = mac->octet + ETHER_ADDR_LEN - 1;
51 + pr_err("unable to fetch mac address\n");
57 +static void nvram_change_mac_addr(vars_t *new, struct ether_addr *valid, const char *name)
60 + struct ether_addr macaddr;
62 + macaddr_c = findvar(new->vars, new->vars + new->size, name);
66 + bcm_ether_atoe(macaddr_c, &macaddr);
67 + if (nvram_is_valid_mac(&macaddr))
69 + nvram_increase_mac_addr(valid, 1);
70 + bcm_ether_ntoa(valid, macaddr_c);
73 +static void fixup_mac_addr(vars_t *new)
75 + char *macaddr_base_c;
76 + struct ether_addr macaddr_base;
78 + macaddr_base_c = findvar(new->vars, new->vars + new->size, "et0macaddr");
79 + if (!macaddr_base_c)
82 + bcm_ether_atoe(macaddr_base_c, &macaddr_base);
83 + if (!nvram_is_valid_mac(&macaddr_base))
86 + /* jump over the first free address so it can be used for wan */
87 + nvram_increase_mac_addr(&macaddr_base, 1);
88 + nvram_change_mac_addr(new, &macaddr_base, "sb/1/macaddr");
89 + nvram_change_mac_addr(new, &macaddr_base, "pci/1/1/macaddr");
90 + nvram_change_mac_addr(new, &macaddr_base, "pci/1/2/macaddr");
91 + nvram_change_mac_addr(new, &macaddr_base, "pci/2/1/macaddr");