The method of reading the default MAC address under Linux

Time:2019-11-6

The MAC (media access control) computer uses it to define and identify the location of network devices. It is inevitable to encounter MAC in the learning of embedded Linux. This paper mainly describes how to read the MAC address in the network card of embedded Linux device by operating OTP

Linux下读取默认MAC地址Linux下读取默认MAC地址

I. scope of application

This paper mainly introduces the method of reading MAC address of network card, which is applicable to easyarm-i.mx287a development kit. Its application principle and supporting examples are also applicable to the product models listed in Table 1.1 below.

Linux下读取默认MAC地址Linux下读取默认MAC地址

II. Principle 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 number, is six bytes (48 bits). Among them, the first three bytes are the codes (high-order 24 bits) assigned to different manufacturers by the registration authority Ra of IEEE, also known as “organization unique identifier”. The last three bytes (low-order 24 bits) are assigned to the adapter interface of production by each manufacturer, which is called 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 network card” is a function developed by Guangzhou Zhiyuan Electronic Co., Ltd. for awork development kit and m283 and m287 industrial control core board. The MAC address of network card is stored through OTP of chip. The first two words of MAC address of core board and development kit delivered by our company are fixed as “0x00” and “0x04”, and the last four bytes are stored in OTP. This document mainly describes as follows: How to read MAC address of network card by operating OTP.

Configure the OTP option in the kernel. After the compiled kernel is started, the OTP device files will be exported in the file system to read information by operating these device files. MAC information of registered network card can be solidified into OTP first, and can be read in application layer. The lower 4 bits of mac0 address can be read through the device file “/ sys / fsl_otg / sbk0”, and the lower 4 bits of Mac1 address can be read through the device file “/ sys / fsl_otg / sbk1”.

Note: if m287 and m283 industrial control boards are used, there is no 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:

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

Linux下读取默认MAC地址Linux下读取默认MAC地址

Figure 1 kernel configuration

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

Linux下读取默认MAC地址Linux下读取默认MAC地址

Figure 2 kernel configuration

Press the space bar, and select the < * > Freescale on chip OTP memory support option, as shown in Figure 3 kernel configuration figure 3.

Linux下读取默认MAC地址Linux下读取默认MAC地址

Figure 3 kernel configuration

Press enter to save exit.

2. Compile kernel

Execute the following command in the current directory 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 burned to nandflash through TF card.

IV. read MAC operation

The following describes the operation process of reading MAC from network card. Its essence is to operate OTP device files.

Execute MAC script file

Copy the mac.sh file under the directory of this document to easyarm-i.mx287a development kit via U disk or TF card. Modify the file permission to executable permission. The reference command is as follows:

[email protected] ~# chmod 777 MAC.sh
[email protected] ~# ./MAC.sh

After execution, check the network device, and the MAC is as shown in Figure 5.

Linux下读取默认MAC地址Linux下读取默认MAC地址

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 lower 4 bits of network card MAC are actually the values saved in OTP, as shown in Figure 6.

Linux下读取默认MAC地址Linux下读取默认MAC地址

Figure 6 OTP reading diagram

Recommended Today

The use of progressbarcontrol, a progress bar control of devexpress – Taking ZedGraph as an example to add curve progress

scene WinForm control – devexpress18 download installation registration and use in vs: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100061243 When using ZedGraph to add curves, the number of curves is slower if there are many cases. So in the process of adding curve, the progress needs to be displayed, and the effect is as follows     Note: Blog home page:https://blog.csdn.net/badao_liumang_qizhi […]