How to read the default MAC address under Linux

Source: Internet
Author: User
Tags file system file permissions

How to read the default MAC address under Linux

The MAC (media access control, media access controls) computer uses it to define and identify the location of network devices. In embedded Linux learning will inevitably encounter Mac, this article mainly describes how to use OTP to read the embedded Linux Device network card MAC address

I. Scope of APPLICATION

This article mainly introduces the way to read the MAC address of the NIC, suitable for the easyarm-i.mx287a development Kit, the application principle and the matching example also apply to the product model listed in table 1.1 below.

Second, the principle of introduction

MAC (media access control, media access controls) is used to define the location of network devices. The identifier used to represent each site on the internet, in hexadecimal notation, and a total of six bytes (48 bits). Of these, the first three bytes are the code (high 24 bits) assigned to different manufacturers by the IEEE Registration Authority RA, also known as the "compiled unique identifier" (organizationally unique Identifier), followed by three bytes (Low 24 digits) The adapter interface, which is assigned by each manufacturer to the production, is called an extended identifier (uniqueness). An address block can generate 2^24 a different address. The MAC address is actually an adapter address or adapter identifier. MAC is globally unique.

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

After the kernel configures the OTP option, when the compiled kernel is started, the OTP device files are exported in the file system to read the information by manipulating the device files. The registered Nic Mac information can be first solidified into OTP and can be read at the application level. The lower 4 bits of the MAC0 address can be read through the device file "/sys/fsl_otg/sbk0", and the lower 4 bits of the MAC1 address can be read through the device file "/SYS/FSL_OTG/SBK1".

Note: If you are using a M287, M283 Industrial board, you do not need to configure the kernel.

Third, the technical realization

Kernel compilation

1. Configure the kernel

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

?

1 2 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 Figure 1 below.

Figure 1 Kernel Configuration

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

Figure 2 Kernel Configuration

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

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:

?

1 2 vmuser@linux-host:~/linux-2.6.35.3$ make clean vmuser@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 burned through the TF card to Nandflash.

Four, read Mac Real

The following is an introduction to the Mac operation of the read NIC, which is essentially operating the OTP device file.

Executing a Mac script file

Copy the mac.sh file in this document directory to the EASYARM-I.MX287A Development Kit via U disk or TF card, modify file permissions for executable permissions, and refer to the following commands:

?

1 2 root@easyarm-imx28x ~# chmod 777 mac.sh root@easyarm-imx28x. ~#

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

Figure 5 Network equipment diagram

View the "/sys/fsl_otp/hw_ocotp_srk1" and "/sys/fsl_otp/hw_ocotp_srk0" devices. As you can see, the NIC Mac low 4 bit is actually the value saved in OTP, as shown in Figure 6.

Figure 6 OTP Read graph

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.