boards: get mac address from environment

The boards that get converted here to use the environment for the mac
address rather than global data:
	debris
	mgcoge
	mgsuvd
	muas3001
	netstal
	pn62
	sixnet
	vcma9
	xilinx (the ones that use xilinx_enet)

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>
CC: Sangmoon Kim <dogoil@etinsys.com>
CC: Heiko Schocher <hs@denx.de>
CC: David Mueller <d.mueller@elsoft.ch>
CC: Niklaus Giger <niklaus.giger@netstal.com>
CC: Wolfgang Grandegger <wg@denx.de>
CC: Dave Ellis <DGE@sixnetio.com>
CC: Ricardo Ribalda <ricardo.ribalda@uam.es>
This commit is contained in:
Mike Frysinger 2009-02-11 18:38:38 -05:00 committed by Wolfgang Denk
parent 06a0c4381a
commit b6b4625d17
9 changed files with 48 additions and 68 deletions

View File

@ -173,9 +173,13 @@ void nvram_write(long dest, const void *src, size_t count)
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;
}

View File

@ -174,6 +174,7 @@ void ft_blob_update (void *blob, bd_t *bd)
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);
@ -195,8 +196,9 @@ void ft_blob_update (void *blob, bd_t *bd)
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)

View File

@ -326,6 +326,7 @@ void ft_blob_update (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);
@ -344,8 +345,9 @@ void ft_blob_update (void *blob, bd_t *bd)
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)

View File

@ -76,21 +76,18 @@ int do_vcma9(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
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++;

View File

@ -346,7 +346,9 @@ void ft_blob_update (void *blob, bd_t *bd)
/* 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 "

View File

@ -83,40 +83,20 @@ void set_params_for_sw_install(int install_requested, char *board_name )
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 */

View File

@ -30,7 +30,7 @@
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)
@ -138,18 +138,16 @@ int misc_init_r (void)
}
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);
@ -177,15 +175,9 @@ static int get_serial_number (char *string, int size)
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)

View File

@ -264,6 +264,7 @@ int misc_init_r (void)
char* e;
int reg;
bd_t *bd = gd->bd;
uchar enetaddr[6];
memctl->memc_or2 = NVRAM_OR_PRELIM;
memctl->memc_br2 = NVRAM_BR_VALUE;
@ -315,13 +316,9 @@ int misc_init_r (void)
* 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);

View File

@ -74,6 +74,7 @@ eth_init(bd_t * bis)
{
u32 Options;
XStatus Result;
uchar enetaddr[6];
#ifdef DEBUG
printf("EMAC Initialization Started\n\r");
@ -87,11 +88,14 @@ eth_init(bd_t * bis)
/* 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;
}