MAC (Media Access Control) is used to define the location of network devices. In the embedded Linux learning, it is inevitable to encounter MAC. This article mainly describes how to read the MAC address in the embedded Linux device network card by operating OTP.
1.1 Scope of application
Here mainly introduces the method of reading the MAC address of the network card, which is applicable to the EasyARM-i.MX287A development kit. The application principle and supporting examples are also applicable to the product models listed in Table 1.1 below.
Table 1.1 Applicable product models
1.2 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, expressed in hexadecimal notation, for a total of six bytes (48 bits). Among them, the first three bytes are codes assigned by the IEEE registrar RA to different manufacturers (high 24 bits), also known as "OrganizaTIonally Unique IdenTIfier", the last three bytes. (lower 24 bits) The adapter interface assigned by each manufacturer to the production, called the 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.
"The default MAC of the network card" is a function developed by Guangzhou Zhiyuan Electronics Co., Ltd. for the Awork development kit and the M283, M287 industrial control core board. The OTP of the chip is used to store the MAC address of the network card. The core board and development kit of our company are shipped. The first two bytes of the MAC address are fixed to "0x00", "0x04", and the last four bytes are stored in the OTP. This document mainly describes how to read the MAC address of the network card by operating the OTP.
After the kernel is configured with the OTP option, after the compiled kernel is started, the OTP device files are exported in the file system, and the information is read by operating the device files. The MAC address information of the registered network card can be first solidified into the OTP, and can be read at the application layer. The lower 4 bits of the MAC0 address can be read by the device file "/sys/fsl_otg/SBK0". The lower 4 bits of the MAC1 address can be read by the device file "/sys/fsl_otg/SBK1".
Note: If you are using M287, M283 industrial control board, you do not need to configure the kernel.
1.3 Technology implementation
1.3.1 kernel compilation
1. Configure the kernel
Go to 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 the Enter key to enter the Device Drivers option, as shown in Figure 3.1 below.
Figure 3.1 Kernel Configuration
Press the Enter key to enter the Chracter devices option. As shown in Figure 3.2.
Figure 3.2 Kernel Configuration
Press the space bar to select the <*> Freescale On-Chip OTP Memory Support option, as shown in Figure 3.3.
Figure 3.3 Kernel Configuration
Press the Enter key to save and exit.
2. Compile the kernel
Run the following command in the current directory to compile the kernel. The reference commands are as follows:
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 written to the NANDFlash through the TF card.
1.4 Read MAC operation
The following describes the process of reading the MAC card MAC, which is essentially the operation of the OTP device file.
1.4.1 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 the file permissions to executable permissions. The reference commands are as follows:
Root@EasyARM-iMX28x ~# chmod 777 MAC.sh
Root@EasyARM-iMX28x ~# ./MAC.sh
After the execution, check the network device. The MAC is shown in Figure 4.1.
Figure 4.1 Network device diagram
Look at 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 is actually the value stored in the OTP, as shown in Figure 4.2.
Figure 4.2 OTP read graph
ATS22 is designed for most infrastructure and industrial applications for better in-class protection function and ease of use.
Schneider Inverter Drive,Variable Frequency Drive,High Frequency Converter,Frequency Inverter For Motor
Wuxi Trenty Machinery & Equipment Co., Ltd. , https://www.elec-inverter.com