Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the step of reading the default MAC address under Linux

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the steps of reading the default MAC address under Linux, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.

MAC addresses, also known as physical addresses and hardware addresses, are recorded in the EPROM of the network card when produced by the network equipment manufacturer.

Introduction to MAC: MAC Address,Media Access Control Address, also known as EHA (Ethernet Hardware Address), hardware address, physical address (Physical Address).

In the OSI node layer model, it belongs to the concept of the second link layer. A MAC address uniquely specifies a device, globally unique, and is usually burned in firmware.

MAC addresses are defined by IEEE (Institute of Electrical and Electronics Engineers), and there are three types: MAC-48, EUI-48, and EUI-64. EUI, Extended Unique Identifier .

Steps to read the default MAC address under Linux: I. scope of application

This paper mainly introduces the method of reading the MAC address of the network card, which is suitable for the EasyARM-i.MX287A development kit, and its application principle and supporting examples are also applicable to the product models listed in Table 1.1.

Introduction of the principle

MAC (Media Access Control, Media access Control) is used to define the location of network devices. The identifier used to represent each site on the Internet, expressed in hexadecimal numbers, with a total of six bytes (48 bits). Among them, the first three bytes are the codes assigned by IEEE's registration authority RA to different manufacturers (high 24 bits), also known as "compiling unique identifiers" (Organizationally Unique Identifier), and the last three bytes (low 24 bits) are assigned to the production adapter interface by each manufacturer, called extended identifiers (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 network card" is a function developed by Guangzhou Zhiyuan Electronics Co., Ltd. for Awork development kit and M283, M287 industrial control core board. The MAC address of the network card is stored through the OTP of the chip. The first two bytes of the MAC address of the core board and development kit of our company are fixed as "0x00" and "0x04". The last four bytes are saved in OTP. This document mainly describes how to read the MAC address of the network card by operating OTP.

After the kernel configures the OTP option, after the compiled kernel starts, the OTP device files are exported in the file system and the information is read by manipulating these device files. The registered network card MAC information can be first solidified into OTP and can be read in the application layer. 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 M287 or M283 industrial control boards, you do not need to configure the kernel.

III. Technical realization

Kernel compilation

1. Configure the kernel

Enter the linux-2.6.35.3 directory. Execute 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 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 exit.

two。 Compile the kernel

Execute the following command to compile the kernel in the current directory, and refer to the command as follows:

The vmuser@Linux-host:~/ linux-2.6.35.3$ make clean vmuser@Linux-host:~/ linux-2.6.35.3$ make uImage kernel firmware is located in "arch/arm/boot/uImage" and writes the generated kernel firmware to NANDFlash via TF card.

4. Read MAC actual operation

The following describes the process of reading the MAC of the network card, which is essentially the operation of OTP device files.

Execute MAC script file

Copy the MAC.sh file under this document directory to the EasyARM-i.MX287A development suite via U disk or TF card, and change the file permission to executable permission. Refer to the command as follows:

After root@EasyARM-iMX28x ~ # chmod 777 MAC.sh root@EasyARM-iMX28x ~ # / MAC.sh executes, look at the network devices, and the MAC is shown in figure 5.

Fig. 5 Network equipment diagram

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

Fig. 6 OTP read diagram

Thank you for reading this article carefully. I hope the article "what are the steps to read the default MAC address under Linux" shared by the editor will be helpful to you. At the same time, I also hope you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report