1. 程式人生 > 其它 >09 --> OpenWRT 的 linux核心patch方法,新增5G模組驅動

09 --> OpenWRT 的 linux核心patch方法,新增5G模組驅動

技術標籤:OpenWrt routing 開發

1.準備核心原始碼樹

使用如下命令

make target/linux/clean V=s QUILT=1
make targe/linux/prepare V=s QUILT=1

2.進入kernel原始碼樹目錄

/OpenWrt/LS1046A-19.07/build_dir/target-aarch64_generic_glibc/linux-layerscape_armv8_64b/linux-4.14.200$ ls
arch   certs    CREDITS  Documentation  firmware  include  ipc     Kconfig  lib          Makefile  net      README   scripts   sound  usr
block  COPYING  crypto   drivers        fs        init     Kbuild  kernel   MAINTAINERS  mm        patches  samples  security  tools  virt

3.更新核心補丁檔案

quilt push -a
 quilt push -a
Applying patch generic-backport/010-Kbuild-don-t-hardcode-path-to-awk-in-scripts-ld-vers.patch
patching file scripts/ld-version.sh

Applying patch generic-backport/011-kbuild-export-SUBARCH.patch
patching file Makefile

Applying patch generic-backport/012-kbuild-add-
macro-for-controlling-warnings-to-linux-c.patch patching file include/linux/compiler-gcc.h patching file include/linux/compiler_types.h Applying patch generic-backport/013-disable-Wattribute-alias-warning-for-SYSCALL_DEFINEx.patch patching file include/linux/compat.h

4. 建立新patch、修改核心驅動

以修改SIM8200 的 5G模組驅動為例

linux-4.14.200$ quilt top 
platform/825-tmu-support-layerscape.patch
linux-4.14.200$ quilt new platform/826-ls10xx-usb-serial-option.patch
linux-4.14.200$ quilt add drivers/usb/serial/option.c
# vim drivers/usb/serial/option.c 補充修改內容
linux-4.14.200$ quilt diff
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -85,6 +85,7 @@ static void option_instat_callback(struc
 #define HUAWEI_PRODUCT_K3765                   0x1465
 #define HUAWEI_PRODUCT_K4605                   0x14C6
 #define HUAWEI_PRODUCT_E173S6                  0x1C07
+#define HUAWEI_PRODUCT_ME906S                  0x15c1
 
 #define QUANTA_VENDOR_ID                       0x0408
 #define QUANTA_PRODUCT_Q101                    0xEA02
@@ -348,6 +349,7 @@ static void option_instat_callback(struc
 
 #define ALINK_VENDOR_ID                        0x1e0e
 #define SIMCOM_PRODUCT_SIM7100E                0x9001 /* Yes, ALINK_VENDOR_ID */
+#define SIMCOM_PRODUCT_SIM8200                 0x9011 /* SIMCOM 7600,8200 serial */
 #define ALINK_PRODUCT_PH300                    0x9100
 #define ALINK_PRODUCT_3GU                      0x9200

5. 更新patch 的內容

linux-4.14.200$ quilt refresh 
Refreshed patch 1000-ls10xx-usb-serial-option.patch

6.儲存patch檔案到buildroot

linux-4.14.200$ cd ../../../../
[email protected]:~/OpenWrt/LS1046A-19.07$ make target/linux/update V=s
make[1]: Entering directory '/home/robot/OpenWrt/LS1046A-19.07'
make[2]: Entering directory '/home/robot/OpenWrt/LS1046A-19.07/target/linux'
make[3]: Entering directory '/home/robot/OpenWrt/LS1046A-19.07/target/linux/layerscape'
if [ -s "/home/robot/OpenWrt/LS1046A-19.07/build_dir/target-aarch64_generic_glibc/linux-layerscape_armv8_64b/linux-4.14.200/patches/series" ]; then (cd "/home/robot/OpenWrt/LS1046A-19.07/build_dir/target-aarch64_generic_glibc/linux-layerscape_armv8_64b/linux-4.14.200"; if quilt --quiltrc=- next >/dev/null 2>&1; then quilt --quiltrc=- push -a; else quilt --quiltrc=- top >/dev/null 2>&1; fi ); fi
'/home/robot/OpenWrt/LS1046A-19.07/build_dir/target-aarch64_generic_glibc/linux-layerscape_armv8_64b/linux-4.14.200/patches/platform/825-tmu-support-layerscape.patch' -> '/home/robot/OpenWrt/LS1046A-19.07/target/linux/layerscape/patches-4.14/825-tmu-support-layerscape.patch'
# 新產生補丁包路徑及名稱
'/home/robot/OpenWrt/LS1046A-19.07/build_dir/target-aarch64_generic_glibc/linux-layerscape_armv8_64b/linux-4.14.200/patches/platform/826-ls10xx-usb-serial-option.patch' -> '/home/robot/OpenWrt/LS1046A-19.07/target/linux/layerscape/patches-4.14/***826-ls10xx-usb-serial-option.patch***'
make[3]: Leaving directory '/home/robot/OpenWrt/LS1046A-19.07/target/linux/layerscape'
make[2]: Leaving directory '/home/robot/OpenWrt/LS1046A-19.07/target/linux'

6.補丁檔案修改更新


####### (1) 打補丁檔案並更新內容
linux-4.14.200$ quilt push -a
File series fully applied, ends at patch platform/826-ls10xx-usb-serial-option.patch
linux-4.14.200$ vim drivers/usb/serial/option.c 

#######(2) 檢視更新內容        
linux-4.14.200$ quilt diff
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -85,6 +85,7 @@ static void option_instat_callback(struc
 #define HUAWEI_PRODUCT_K3765                   0x1465
 #define HUAWEI_PRODUCT_K4605                   0x14C6
 #define HUAWEI_PRODUCT_E173S6                  0x1C07
+#define HUAWEI_PRODUCT_ME906S                  0x15C1
 #define QUANTA_VENDOR_ID                       0x0408
 #define QUANTA_PRODUCT_Q101                    0xEA02
@@ -348,6 +349,7 @@ static void option_instat_callback(struc
 #define ALINK_VENDOR_ID                                0x1e0e
 #define SIMCOM_PRODUCT_SIM7100E                        0x9001 /* Yes, ALINK_VENDOR_ID */
+#define SIMCOM_PRODUCT_SIM8200      0x9011 /* simcom 7600 & 8200 product id */
 #define ALINK_PRODUCT_PH300                    0x9100
 #define ALINK_PRODUCT_3GU                      0x9200
@@ -628,6 +630,8 @@ static const struct usb_device_id option
          .driver_info = RSVD(1) },
        { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4605, 0xff, 0xff, 0xff),
          .driver_info = RSVD(1) | RSVD(2) },
+  { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ME906S, 0xff, 0xff, 0xff),
+    .driver_info = RSVD(1) | RSVD(2) },    
        { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0xff, 0xff) },
        { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x01) },
        { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x01, 0x02) },
@@ -1824,7 +1828,7 @@ static const struct usb_device_id option
        { USB_DEVICE(ALINK_VENDOR_ID, SIMCOM_PRODUCT_SIM7100E),
          .driver_info = RSVD(5) | RSVD(6) },
        { USB_DEVICE_INTERFACE_CLASS(0x1e0e, 0x9003, 0xff) },   /* Simcom SIM7500/SIM7600 MBIM mode */
-       { USB_DEVICE_INTERFACE_CLASS(0x1e0e, 0x9011, 0xff),     /* Simcom SIM7500/SIM7600 RNDIS mode */
+       { USB_DEVICE_INTERFACE_CLASS(0x1e0e, SIMCOM_PRODUCT_SIM8200, 0xff),     /* Simcom SIM7500/SIM7600 RNDIS mode */
          .driver_info = RSVD(7) },
        { USB_DEVICE_INTERFACE_CLASS(0x1e0e, 0x9205, 0xff) },   /* Simcom SIM7070/SIM7080/SIM7090 AT+ECM mode */
        { USB_DEVICE_INTERFACE_CLASS(0x1e0e, 0x9206, 0xff) },   /* Simcom SIM7070/SIM7080/SIM7090 AT-only mode */

####### (3) 更新補丁檔案的內容        
linux-4.14.200$ quilt refresh 
Warning: trailing whitespace in line 634 of drivers/usb/serial/option.c
Refreshed patch platform/826-ls10xx-usb-serial-option.patch


####### (4) 更新補丁檔案至 target/linux/layerscape  目錄
/OpenWrt/LS1046A-19.07$ make target/linux/refresh V=s
make[1]: Entering directory '/home/robot/OpenWrt/LS1046A-19.07'
make[2]: Entering directory '/home/robot/OpenWrt/LS1046A-19.07/target/linux'
make[3]: Entering directory '/home/robot/OpenWrt/LS1046A-19.07/target/linux/layerscape'
Applying patch generic-backport/010-Kbuild-don-t-hardcode-path-to-awk-in-scripts-ld-vers.patch
patching file scripts/ld-version.sh
'/home/robot/OpenWrt/LS1046A-19.07/build_dir/target-aarch64_generic_glibc/linux-layerscape_armv8_64b/linux-4.14.200/patches/platform/826-ls10xx-usb-serial-option.patch' -> '/home/robot/OpenWrt/LS1046A-19.07/target/linux/layerscape/patches-4.14/826-ls10xx-usb-serial-option.patch'
make[3]: Leaving directory '/home/robot/OpenWrt/LS1046A-19.07/target/linux/layerscape'
make[2]: Leaving directory '/home/robot/OpenWrt/LS1046A-19.07/target/linux'
time: target/linux/refresh#51.70#18.13#65.19

7. 編譯核心


[email protected]:~/OpenWrt/LS1046A-19.07$ make target/linux/compile
time: target/linux/prereq#0.08#0.01#0.10
 make[1] target/linux/compile
 make[2] -C target/linux compile
 
[email protected]:~/OpenWrt/LS1046A-19.07$ make target/linux/install
 make[1] target/linux/install
 make[2] -C target/linux install

8.驗證5G驅動程式

在這裡插入程式碼片