int misc_init_r(void)
{
- /* Write ethernet addr in NVRAM for VxWorks */
- nvram_write(CONFIG_ENV_ADDR + CONFIG_SYS_NVRAM_VXWORKS_OFFS,
- (char*)&gd->bd->bi_enetaddr[0], 6);
+ uchar ethaddr[6];
+
+ if (eth_getenv_enetaddr("ethaddr", ethaddr))
+ /* Write ethernet addr in NVRAM for VxWorks */
+ nvram_write(CONFIG_ENV_ADDR + CONFIG_SYS_NVRAM_VXWORKS_OFFS,
+ ethaddr, 6);
+
return 0;
}
ulong memory_data[2] = {0};
ulong flash_data[4] = {0};
ulong flash_reg[3] = {0};
+ uchar enetaddr[6];
memory_data[0] = cpu_to_be32 (bd->bi_memstart);
memory_data[1] = cpu_to_be32 (bd->bi_memsize);
sizeof (brg_data));
/* MAC adr */
+ eth_getenv_enetaddr("ethaddr", enetaddr);
fdt_set_node_and_value (blob, "/soc/cpm/ethernet", "mac-address",
- bd->bi_enetaddr, sizeof (u8) * 6);
+ enetaddr, sizeof (u8) * 6);
}
void ft_board_setup(void *blob, bd_t *bd)
ulong memory_data[2] = {0};
ulong flash_data[8] = {0};
flash_info_t *info;
+ uchar enetaddr[6];
memory_data[0] = cpu_to_be32 (bd->bi_memstart);
memory_data[1] = cpu_to_be32 (bd->bi_memsize);
fdt_set_node_and_value (blob, "/localbus", "ranges", flash_data,
sizeof (flash_data));
/* MAC addr */
+ eth_getenv_enetaddr("ethaddr", enetaddr);
fdt_set_node_and_value (blob, "/soc/cpm/ethernet", "mac-address",
- bd->bi_enetaddr, sizeof (u8) * 6);
+ enetaddr, sizeof (u8) * 6);
}
void ft_board_setup (void *blob, bd_t *bd)
cs8900_e2prom_write(addr, data);
} else if (strcmp(argv[2], "setaddr") == 0) {
uchar addr, i, csum; ushort data;
+ uchar ethaddr[6];
/* check for valid ethaddr */
- for (i = 0; i < 6; i++)
- if (gd->bd->bi_enetaddr[i] != 0)
- break;
-
- if (i < 6) {
+ if (eth_getenv_enetaddr("ethaddr", ethaddr)) {
addr = 1;
data = 0x2158;
cs8900_e2prom_write(addr, data);
csum = cs8900_chksum(data);
addr++;
for (i = 0; i < 6; i+=2) {
- data = gd->bd->bi_enetaddr[i+1] << 8 |
- gd->bd->bi_enetaddr[i];
+ data = enetaddr[i+1] << 8 |
+ enetaddr[i];
cs8900_e2prom_write(addr, data);
csum += cs8900_chksum(data);
addr++;
/* MAC Adresse */
nodeoffset = fdt_path_offset (blob, "/soc/cpm/ethernet");
if (nodeoffset >= 0) {
- ret = fdt_setprop (blob, nodeoffset, "mac-address", bd->bi_enetaddr,
+ uchar ethaddr[6];
+ eth_getenv_enetaddr("ethaddr", ethaddr);
+ ret = fdt_setprop (blob, nodeoffset, "mac-address", ethaddr,
sizeof (uchar) * 6);
if (ret < 0)
printf ("ft_blob_update): cannot set /soc/cpm/ethernet/mac-address "
void common_misc_init_r(void)
{
- char *s = getenv(DEFAULT_ETH_ADDR);
- char *e;
- int i;
- u32 serial = get_serial_number();
IPaddr_t ipaddr;
char *ipstring;
+ uchar ethaddr[6];
- for (i = 0; i < 6; ++i) {
- gd->bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0;
- if (s)
- s = (*e) ? e + 1 : e;
- }
-
- if (gd->bd->bi_enetaddr[3] == 0 &&
- gd->bd->bi_enetaddr[4] == 0 &&
- gd->bd->bi_enetaddr[5] == 0) {
- char ethaddr[22];
-
+ if (!eth_getenv_enetaddr(DEFAULT_ETH_ADDR, ethaddr)) {
/* Must be in sync with CONFIG_ETHADDR */
- gd->bd->bi_enetaddr[0] = 0x00;
- gd->bd->bi_enetaddr[1] = 0x60;
- gd->bd->bi_enetaddr[2] = 0x13;
- gd->bd->bi_enetaddr[3] = (serial >> 16) & 0xff;
- gd->bd->bi_enetaddr[4] = (serial >> 8) & 0xff;
- gd->bd->bi_enetaddr[5] = hcu_get_slot();
- sprintf(ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X%c",
- gd->bd->bi_enetaddr[0], gd->bd->bi_enetaddr[1],
- gd->bd->bi_enetaddr[2], gd->bd->bi_enetaddr[3],
- gd->bd->bi_enetaddr[4],
- gd->bd->bi_enetaddr[5],
- 0) ;
- printf("%s: Setting eth %s serial 0x%x\n", __FUNCTION__,
- ethaddr, serial);
- setenv(DEFAULT_ETH_ADDR, ethaddr);
+ u32 serial = get_serial_number();
+ ethaddr[0] = 0x00;
+ ethaddr[1] = 0x60;
+ ethaddr[2] = 0x13;
+ ethaddr[3] = (serial >> 16) & 0xff;
+ ethaddr[4] = (serial >> 8) & 0xff;
+ ethaddr[5] = hcu_get_slot();
+ eth_setenv_enetaddr(DEFAULT_ETH_ADDR, ethaddr);
}
/* IP-Adress update */
DECLARE_GLOBAL_DATA_PTR;
static int get_serial_number (char *string, int size);
-static int get_mac_address (int id, u8 * mac, char *string, int size);
+static void get_mac_address(int id, u8 *mac);
#ifdef CONFIG_SHOW_BOOT_PROGRESS
void show_boot_progress (int phase)
}
show_startup_phase (9);
- if (getenv ("ethaddr") == NULL &&
- get_mac_address (0, mac, str, sizeof (str)) > 0) {
- setenv ("ethaddr", str);
- memcpy (gd->bd->bi_enetaddr, mac, 6);
+ if (!eth_getenv_enetaddr("ethaddr", mac)) {
+ get_mac_address(0, mac);
+ eth_setenv_enetaddr("ethaddr", mac);
}
show_startup_phase (10);
#ifdef CONFIG_HAS_ETH1
- if (getenv ("eth1addr") == NULL &&
- get_mac_address (1, mac, str, sizeof (str)) > 0) {
- setenv ("eth1addr", str);
- memcpy (gd->bd->bi_enet1addr, mac, 6);
+ if (!eth_getenv_enetaddr("eth1addr", mac)) {
+ get_mac_address(1, mac);
+ eth_setenv_enetaddr("eth1addr", mac);
}
#endif /* CONFIG_HAS_ETH1 */
show_startup_phase (11);
return i;
}
-static int get_mac_address (int id, u8 * mac, char *string, int size)
+static void get_mac_address(int id, u8 *mac)
{
- if (size < 6 * 3)
- return -1;
-
i2155x_read_vpd (I2155X_VPD_MAC0_START + 6 * id, 6, mac);
- return sprintf (string, "%02x:%02x:%02x:%02x:%02x:%02x",
- mac[0], mac[1], mac[2],
- mac[3], mac[4], mac[5]);
}
int board_eth_init(bd_t *bis)
char* e;
int reg;
bd_t *bd = gd->bd;
+ uchar enetaddr[6];
memctl->memc_or2 = NVRAM_OR_PRELIM;
memctl->memc_br2 = NVRAM_BR_VALUE;
* is present it gets a unique address, otherwise it
* shares the FEC address.
*/
- s = getenv("eth1addr");
- if (s == NULL)
- s = getenv("ethaddr");
- for (reg=0; reg<6; ++reg) {
- bd->bi_enet1addr[reg] = s ? simple_strtoul(s, &e, 16) : 0;
- if (s)
- s = (*e) ? e+1 : e;
+ if (!eth_getenv_enetaddr("eth1addr", enetaddr)) {
+ eth_getenv_enetaddr("ethaddr", enetaddr);
+ eth_setenv_enetaddr("eth1addr", enetaddr);
}
return (0);
{
u32 Options;
XStatus Result;
+ uchar enetaddr[6];
#ifdef DEBUG
printf("EMAC Initialization Started\n\r");
/* make sure the Emac is stopped before it is started */
(void) XEmac_Stop(&Emac);
+ if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
#ifdef CONFIG_ENV_IS_NOWHERE
- memcpy(bis->bi_enetaddr, EMACAddr, 6);
+ memcpy(enetaddr, EMACAddr, 6);
+ eth_setenv_enetaddr("ethaddr", enetaddr);
#endif
+ }
- Result = XEmac_SetMacAddress(&Emac, bis->bi_enetaddr);
+ Result = XEmac_SetMacAddress(&Emac, enetaddr);
if (Result != XST_SUCCESS) {
return 0;
}