用户工具

站点工具


jaysnote:kernel_compile

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录 前一修订版
后一修订版
前一修订版
jaysnote:kernel_compile [2018/11/15 20:20]
jaylee
jaysnote:kernel_compile [2021/06/22 23:14] (当前版本)
行 1: 行 1:
 <markdown> <markdown>
-GAC-350 Kernel Compile+# Kernel Compile
  
 ## 命令 ## 命令
行 26: 行 26:
     ```     ```
     scp jay@10.28.3.204:/home/jay/a64/linux-3.10/drivers/net/usb/* ./     scp jay@10.28.3.204:/home/jay/a64/linux-3.10/drivers/net/usb/* ./
-    ``` 
- 
-* 完整测试命令 
- 
-    ```shell 
-    t/usb/*.ko ./    ~/asix# scp jay@10.28.3.204:/home/jay/a64/linux-3.10/drivers/ne  
-     
-    asix.ko  cdc_ether.ko  mcs7830.ko  qf9700.ko  rtl8150.ko  usbnet.ko 
-    root@350-c1-emmc ~/asix#     
-    root@350-c1-emmc ~/asix# ls 
-    asix.ko  cdc_ether.ko  mcs7830.ko  qf9700.ko  rtl8150.ko  usbnet.ko 
-    root@350-c1-emmc ~/asix# lsmod 
-    root@350-c1-emmc ~/asix# rmmod asix 
-    root@350-c1-emmc ~/asix# rmmod usbnet 
-    root@350-c1-emmc ~/asix# lsmod 
-    root@350-c1-emmc ~/asix# dmesg -C 
-    root@350-c1-emmc ~/asix# insmod ./usbnet.ko  
-    root@350-c1-emmc ~/asix# insmod ./asix.ko    
-    root@350-c1-emmc ~/asix# dmesg -T 
-    [Thu Jun 14 15:26:27 2018] asix 1-1:1.0 eth0: register 'asix' at usb-sunxi-ehci-1, ASIX AX88772B USB 2.0 Ethernet, 02:00:00:00:00:00 
-    [Thu Jun 14 15:26:27 2018] usbcore: registered new interface driver asix 
-    root@350-c1-emmc ~/asix#  
     ```     ```
  
行 130: 行 108:
 同时直接干掉无线网卡支持。 同时直接干掉无线网卡支持。
  
-### 通过SID 生成mac地址。+### oui mac 和基于sid md5计算mac地址。
  
 +* 接收用户传参,用以用户通过应用空间传递oui mac。
 ```c ```c
-//linux-3.10/drivers/net/usb/asix_devices.c +//inux-3.10/drivers/char/sunxi_sys_info/chipid-sunxi.c         
-extern int sunxi_get_soc_chipid(u8 *chipid); +static char *user_mac  "00:00:00:00:00:00"
-sunxi_get_soc_chipid(chipid); +static bool  user_flag true
-        buf[0] 0x02/* Non OUI / registered MAC address */ +module_param(user_mac,charp,S_IRUSR)
-        buf[1] chipid[0]+``` 
-        buf[2] = chipid[12]+* 如果用户没有传递参数,则通过 sid md5 随机mac; 
-        buf[3] = chipid[13]; +```c 
-        buf[4] = chipid[14]; +//inux-3.10/drivers/char/sunxi_sys_info/chipid-sunxi.c        
-        buf[5] = chipid[15]; +
-        netdev_dbg(dev->net,"MDP MAC from SID: 02:%02x:%02x:%02x:%02x:%02x", +
-                buf[1], buf[2], buf[3], +
-                buf[4], buf[5]);+
  
-        asix_set_netdev_dev_addr(devbuf);+ #include "linux/cryptohash.h" //for md5 
 +//generate mac by hash cpuid 
 +void hash_gen_mac(u8 *mac){ 
 + 
 +    u32 data[16] = {0}; 
 +        u32 hash[ 4] = {0}; 
 + 
 +    memset(hash, 0, sizeof(hash)); 
 +    memset(data, 0, sizeof(data)); 
 + 
 +        //1. fill chipid to data 
 +        sunxi_get_soc_chipid((u8*)data); 
 +    //memcpy(data, dat, len); 
 + 
 +        printk(KERN_INFO "hash_gen_mac chipid: %08x %08x %08x %08x", data[0], data[1], data[2], data[3]); 
 + 
 + 
 +        //2. calc md5 
 +    md5_transform(hash, data); 
 +    //hash[0] ^= hash[2]; 
 +    //hash[1] ^= hash[3]; 
 +        printk(KERN_INFO "hash_gen_mac   hash: %08x %08x %08x %08x", hash[0], hash[1], hash[2], hash[3]); 
 + 
 +        //3. fill mac 
 +    memset(mac, 0, ETH_ALEN); 
 + 
 +    mac[0] = 0x06; //((0x1<<2) & 0xfe | 0x02); //clr multicast, set local bit// 0x06:* 
 +    //memcpy(&mac[1], hash, 5);  
 +    memcpy(&mac[1], hashETH_ALEN); 
 +}
 ``` ```
  
 +* 业务逻辑
 ```c ```c
 //inux-3.10/drivers/char/sunxi_sys_info/chipid-sunxi.c         //inux-3.10/drivers/char/sunxi_sys_info/chipid-sunxi.c        
-pr_info("%s,%dsun50i_sid_base  :%08x \n", __func__, __LINE__,(unsigned int)sun50i_sid_base ); +user_flag=true; 
-        //sunxi_soc_chipid[1] = readl(sun50i_sid_base 0x200 0x4); +printk(KERN_INFO "asix: user mac address is %s",user_mac); 
-        //sunxi_soc_chipid[2] = readl(sun50i_sid_base 0x200 0x8); +if(user_mac!=NULL&&strlen(user_mac)==17&&strcmp(user_mac,"00:00:00:00:00:00")!=0) { 
-        //sunxi_soc_chipid[3] = readl(sun50i_sid_base 0x200 0xc); +        for(i=0;i<6;i++
-        pr_info("%s,%dsunxi_soc_chipid  :0x%04x-%04x-%04x-%04x \n", __func__, __LINE__,sunxi_soc_chipid[0],sunxi_soc_chipid[1],sunxi_soc_chipid[2],sunxi_soc_chipid[3]); +                buf[i]=0; 
-        sunxi_soc_chipid[0= readl(sun50i_sid_base ); +                if(user_mac[3*i]>='0'&&user_mac[3*i]<='9') { 
-        sunxi_soc_chipid[1= readl(sun50i_sid_base + 0x4); +                        buf[i]|=((user_mac[3*i]-'0')*16); 
-        sunxi_soc_chipid[2] = readl(sun50i_sid_base + 0x8); +                }else if(user_mac[3*i]>='a'&&user_mac[3*i]<='f') { 
-        sunxi_soc_chipid[3] = readl(sun50i_sid_base + 0xc); +                        buf[i]|=((user_mac[3*i]-'a'+10)*16); 
-        pr_info("%s,%dsunxi_soc_chipid  :0x%04x-%04x-%04x-%04x \n", __func__, __LINE__,sunxi_soc_chipid[0],sunxi_soc_chipid[1],sunxi_soc_chipid[2],sunxi_soc_chipid[3]);+                }else if(user_mac[3*i]>='A'&&user_mac[3*i]<='F') { 
 +                        buf[i]|=((user_mac[3*i]-'A'+10)*16); 
 +                }else { 
 +                        user_flag=false; 
 +                        break; 
 +                } 
 +                if(user_mac[3*i+1]>='0'&&user_mac[3*i+1]<='9') { 
 +                        buf[i]|=(user_mac[3*i+1]-'0'); 
 +                }else if(user_mac[3*i+1]>='a'&&user_mac[3*i+1]<='f') { 
 +                        buf[i]|=(user_mac[3*i+1]-'a'+10); 
 +                }else if(user_mac[3*i+1]>='A'&&user_mac[3*i+1]<='F') { 
 +                        buf[i]|=(user_mac[3*i+1]-'A'+10); 
 +                }else { 
 +                        user_flag=false; 
 +                        break; 
 +                } 
 + 
 +        
 +}else { 
 +        user_flag=false; 
 +
 +if(user_flag&&((buf[0]&0x0F)%2)==0) { 
 +        printk(KERN_INFO "asix: mac form user setting:%02x:%02x:%02x:%02x:%02x:%02x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); 
 +}else { 
 +        printk(KERN_INFO "asix: mac form user is null or wrong format. "); 
 +        hash_gen_mac(buf); 
 +        printk(KERN_INFO "asix: mac form chip id hash: %02x:%02x:%02x:%02x:%02x:%02x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); 
 +}
 ``` ```
  
jaysnote/kernel_compile.1542284421.txt.gz · 最后更改: 2021/06/22 23:14 (外部编辑)