Device parameters MAC address is consistent in Uboot and Linux __linux

Source: Internet
Author: User

"ARM Linux development-warewin 2G/3G Wireless Transmission (DTU) and routers-notes"

Linux system, start Uboot First, then load Linux kernel and application. Start Uboot when the Uboot NIC driver started up, but after the kernel loaded uboot no longer work, Linux network card driver began to work. This makes the MAC address inconsistent because it is a two-stage driver.

The solution to this problem: first, the MAC address of the system can be set up through the Linux program (here is the Web parameter). Uboot can read this setting value, and can set the set value to the network card, Linux driver run time with the network card settings. So the Uboot and Linux two phases are all configured with a MAC address.

The Linux program saves the parameter Uboot how can read out. In Linux, the direct use of MTD driver in the agreed address to read and write flash, no file system in the Uboot boot, but can read the flash data directly, so as to solve the problem of data transmission.

1. read out MAC address in Uboot

Uboot adds the following red processing code to the/U-BOOT-1.3.4/LIB_ARM/BOARD.C void start_armboot (void) function by adding the value of the MAC address from the 0x80000 position of the Nandflash:

/* MAC Address * *

{

int i;

ULONG Reg;

Char *s, *e;

Char tmp[64];

i = Getenv_r ("Ethaddr", TMP, sizeof (TMP));

s = (i > 0)? Tmp:null;

for (reg = 0; reg < 6; ++reg) {

Gd->bd->bi_enetaddr[reg] = s? Simple_strtoul (S, &e, 16): 0;

if (s)

s = (*e)? E + 1:e;

}

................................

................................

memset (tmp, 0);///DEV/MTD2

size = 6;

RET = Nand_read (NAND, 0x80000, &size, (U_char *) tmp);//0x80000 MAC address if (ret = 0) {//DATAFLASH_OK

printf ("\nread MAC addr:");

for (reg = 0; reg < 6; ++reg) {

Gd->bd->bi_enetaddr[reg] = Tmp[reg];

printf ("%x", Tmp[reg]);

}

#ifdef CONFIG_HAS_ETH1

2, Uboot MAC address processing, read out of the MAC address to the network card register.

In/U-BOOT-1.3.4/DRIVERS/NET/MACB.C, add the following red font to the static int macb_init (struct eth_device *netdev, bd_t) function:

Macb_writel (MACB, RBQP, MACB->RX_RING_DMA);

Macb_writel (MACB, TBQP, MACB->TX_RING_DMA);

//------------------------------------------------------------------

/* Set hardware address setting MAC addresses

if (is_zero_ether_addr (bd->bi_enetaddr) | | Check to see if it's all 0

IS_MULTICAST_ETHER_ADDR (BD->BI_ENETADDR)) {

Hwaddr_bottom = cpu_to_le32 (* (U32 *) netdev->enetaddr));

Macb_writel (MACB, sa1b, Hwaddr_bottom);

Hwaddr_top = Cpu_to_le16 (* (U16 *) (NETDEV->ENETADDR + 4));

Macb_writel (MACB, sa1t, hwaddr_top);

}

Print Mac

printf ("MAC:%02x:%02x:%02x:%02x:%02x:%02x\n", Bd->bi_enetaddr[0],

BD->BI_ENETADDR[1], bd->bi_enetaddr[2], bd->bi_enetaddr[3],

BD->BI_ENETADDR[4], bd->bi_enetaddr[5]);

Hwaddr_bottom = cpu_to_le32 (* (U32 *) bd->bi_enetaddr));

Macb_writel (MACB, sa1b, Hwaddr_bottom);

Hwaddr_top = Cpu_to_le16 (* (U16 *) (BD->BI_ENETADDR + 4));

Macb_writel (MACB, sa1t, hwaddr_top);

//----------------------------------------------------------------

3, Linux kernel reading, the kernel directly from the network card registers read out Mac

In the Linux kernel MACB.C already has the read Mac from the controller, and the validity related judgment, does not need to make any changes, reads the section as follows in the following code:

.................................

static int __init macb_probe (struct platform_device *pdev)

Macb_writel (BP, ncfgr, config);

MACB_GET_HWADDR (BP); Judgment of//mac address

................................

4, processing in the application

The MTD driver can be invoked in a Linux application to write the MAC address directly to the Flash address 0x80000.

5. Compiling and testing

(1) Compile uboot to write again, burning the Linux kernel.

(2) After starting uboot call the saveenv command once, you can test.

(3) Restart Linux and use the ifconfig command to see if the new MAC address corresponds to the uboot print, or you can see the following information when debugging: Right

U-boot 1.3.4 (Mar 7 2011-21:27:00)

Dram:64 MB

nand:256 MiB

Warning-bad CRC or NAND, using default environment

Read MAC addr:50 0 A8 c0 0 ffin:serial

Out:serial

Err:serial

Net:macb0

Mac:50:00:a8:c0:00:ff

Macb0:starting autonegotiation ...

Macb0:autonegotiation Complete

Macb0:link up, 100Mbps Full-duplex (LPA:0X45E1)

Hit any key to stop autoboot:0

u-boot> Print

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.