Read the default MAC address under Linux

Source: Internet
Author: User

the Guide to MAC (media access control) is a computer that defines and identifies the location of network devices. In the embedded Linux learning inevitably also encounter Mac, this article mainly describes how to read the embedded Linux Device network card in the MAC address through the operation of OTP!

I. Scope of application

This article mainly introduces the method of reading the MAC address of the NIC, which is suitable for the easyarm-i.mx287a development Kit, and its application principles and supporting examples are also applicable to the product models listed in table 1.1 below.

second, the principle of introduction

MAC (media access control) is used to define the location of network devices. The identifier used to represent each site on the internet, in hexadecimal notation, with a total of six bytes (48 bits). Of these, the first three bytes are the code (high 24 bits) assigned by the registration Authority RA of the IEEE to different manufacturers, also known as the "unique identifier" (organizationally unique Identifier), and the last three bytes (low 24-bit) Adapter interfaces that are assigned to production by each manufacturer are called extension identifiers (uniqueness). A block of addresses can generate 2^24 different addresses. The MAC address is actually the adapter address or adapter identifier. MAC has global uniqueness.

"The default Mac of network card" is Guangzhou Zhiyuan Electronics Co., Ltd. for awork Development Kit and M283, M287 Industrial Core Board development of a function, through the chip OTP to store the network card MAC address, our factory core board and development Kit MAC address of the first two bytes fixed to "0x00 "," 0x04 ", after four bytes saved in OTP, this document mainly describes how to read the NIC MAC address by manipulating the OTP.

The OTP option is configured in the kernel, and after the compiled kernel is booted, the OTP device files are exported in the file system to read the information by manipulating these device files. The registered Nic Mac information can be cured first in the 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", and the low 4 bits of the MAC1 address can be read through the device file "/SYS/FSL_OTG/SBK1".

Note: If you are using the M287, M283 Control Board, you do not need to configure the kernel.

third, the realization of technology

Kernel compilation

1. Configuring the kernel

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

[Email protected]:~$ cd linux-2.6.35.3/[email protected]:~/linux-2.6.35.3$ make Menuconfig

Press ENTER to enter the device drivers option, as shown in 1.

Figure 1 Kernel Configuration

Press ENTER to enter the Chracter devices option. As shown in 2.

Figure 2 Kernel Configuration

Press SPACEBAR to select the <*> Freescale on-chip OTP Memory support option, as shown in Figure 3 of the 3 kernel configuration.

Figure 3 Kernel Configuration

Press ENTER to save the exit.

2. Compiling the kernel

In the current directory, execute the following command to compile the kernel, the reference command is as follows:

[Email protected]:~/linux-2.6.35.3$ make clean[email protected]:~/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 via TF card.

Four, read Mac real

The following describes the Read network card MAC operation process, the essence is to operate OTP device files.

Execute Mac script file

Copy the mac.sh file in this document directory to the EASYARM-I.MX287A Development Kit via a USB flash drive or TF card, and modify the file permissions to the executable permission, the Reference command is as follows:

[Email protected] ~# chmod 777 Mac.sh[email protected] ~#./mac.sh

After execution, look at the network device, as shown in MAC5.

Figure 5 Network equipment diagram

View "/sys/fsl_otp/hw_ocotp_srk1" and "/sys/fsl_otp/hw_ocotp_srk0" devices. It can be found that the NIC Mac low 4 bit is actually saved in the OTP value, 6 is shown.

Figure 6 OTP Read graph

Read the default MAC address under Linux

Related Article

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.