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
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.
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
1. Configure the kernel
Enter the linux-18.104.22.168 directory. Execute make menuconfig to configure the kernel. The configuration steps are as follows:
Press enter to enter the device drivers option, as shown in Figure 1 below.
Figure 1 kernel configuration
Press enter to enter the character devices option. As shown in Figure 2 below.
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.
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:
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:
After execution, check the network device, and the MAC is as shown in Figure 5.
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.
Figure 6 OTP reading diagram