Read the default MAC address in Linux

Source: Internet
Author: User

Read the default MAC address in Linux

GuideMAC (Media Access Control) allows a computer to define and identify the locations of network devices. MAC is inevitable in Embedded linux learning. This article mainly describes how to read the MAC address in the NIC of an embedded linux device through OTP!

I. Applicability

Here we mainly introduce the method of reading the MAC address of the NIC, suitable for the EasyARM-i.MX287A Development Kit, its application principle and supporting examples are also applicable to the product models listed in Table 1.1 below.

Ii. Principles

Media Access Control (MAC) is used to define the location of network devices. The identifier of each site on the Internet. It is expressed in hexadecimal notation and contains six bytes (48 bits ). Among them, the first three bytes are the code (up to 24 bits) allocated to different manufacturers by the IEEE Registrar RA ), it is also known as "Organization uniquely identified Identifier". The last three bytes (24 bits at low bits) are automatically assigned to the adapter interface of production by each manufacturer, it is called an extension identifier (uniqueness ). An address block can generate 2 ^ 24 different addresses. The MAC address is actually the adapter address or adapter identifier. MAC is globally unique.

"Default MAC of NIC" is a function developed by Guangzhou Zhiyuan Electronics Co., Ltd. for Awork Development Kit and M283 and M287 industrial control core board. The MAC address of NIC is stored through the chip OTP, the first two bytes of the MAC address of our factory core board and development kit are fixed as "0x00" and "0x04", and the last four bytes are stored in OTP, this document describes how to read the MAC address of the NIC by operating OTP.

Configure the OTP option in the kernel. After the compiled kernel is started, OTP device files will be exported to the file system to read information by operating these device files. The registered Nic MAC information can be first solidified into OTP and can be read at the application layer. The low 4 bits of the MAC0 address can be read through the device file "/sys/fsl_otg/SBK0". The low 4 bits of the MAC1 address can be read through the device file "/sys/fsl_otg/SBK1.

Note: If the M287 and M283 work control boards are used, you do not need to configure the kernel.

Iii. Technical Implementation

Kernel Compilation

1. Configure the kernel

Enter the linux-2.6.35.3 directory. Run make menuconfig to configure the kernel. The configuration steps are as follows:

sok@zlgmcu:~$ cd linux-2.6.35.3/sok@zlgmcu:~/linux-2.6.35.3$ make menuconfig

Press enter to enter the Device Drivers option, as shown in 1.

Figure 1 Kernel configuration

Press the Enter key To Go To The Chracter devices option. See figure 2.

Figure 2 Kernel configuration

Press the Space key and select <*> Freescale On-Chip OTP Memory Support option. 3. Kernel configuration figure 3.

Figure 3 Kernel configuration

Press enter to save and exit.

2. Compile the kernel

Run the following command in the current directory to compile the kernel:

vmuser@Linux-host:~/ linux-2.6.35.3$ make cleanvmuser@Linux-host:~/ linux-2.6.35.3$ make uImage

The kernel firmware is located in "arch/arm/boot/uImage", and the generated kernel firmware is written to NANDFlash through the TF card.

4. Read MAC operations

The following describes how to read the MAC of a NIC. The essence of this operation is to operate OTP device files.

Run the MAC script file

Copy the MAC. sh file in the directory of this document to the EasyARM-i.MX287A development kit through a USB flash drive or TF card, modify the File Permission to execute the permission, refer to the Command below:

root@EasyARM-iMX28x ~# chmod 777 MAC.shroot@EasyARM-iMX28x ~# ./MAC.sh

View the network device, as shown in mac5.

Figure 5 network device Diagram

View the "/sys/fsl_otp/HW_OCOTP_SRK1" and "/sys/fsl_otp/HW_OCOTP_SRK0" devices. It can be found that the four low MAC bits of the NIC are actually the values stored in OTP, as shown in figure 6.

Figure 6 OTP read Diagram

From: http://www.eepw.com.cn/article/201606/292409.htm

Address: http://www.linuxprobe.com/linux-default-mac.html


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.