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

How to read MAC address under Linux

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

Share

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

Editor to share with you how to read the MAC address under Linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Mac (Medium Access Control) is the only network address used to identify network card devices in the network. The rom is uniformly assigned by the relevant hardware manufacturers and written in the form of fixed parameters inside the hardware chip. The standard hardware mac address is not allowed to be modified.

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.

Read default MAC address under Linux read default MAC address under Linux

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:

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 burned and written to NANDFlash through the 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:

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

After execution, 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

The above is all the contents of the article "how to read MAC address under Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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