当前位置:   article > 正文

buildroot patch 补丁文件使用方法_buildroot patch

buildroot patch

在使用 buildroot 编译内核源码时,时常会有修改驱动或第三方包的需求,直接在 output/build/ 下修改源码,make clean 修改内容就会丢失,使用打补丁方式,把补丁包放到package下对于的包中,就能够解决此问题。
本篇博文记录修改 xl2tpd 源码打补丁过程。

第一步,拷贝 需要修改的文件 xl2tpd.c 文件,至指定文件夹下:

$ cd buildroot/output/build
$ mkdir src.xl2tp-v1.3.6
$ cp xl2tp-v1.3.6/xl2tpd.c ./src.xl2tp-v1.3.6/
  • 1
  • 2
  • 3

修改文件内容如下:

void destroy_tunnel (struct tunnel *t)
{
....
if (t->lac)
    {
        t->lac->t = NULL;
        if (t->lac->redial && (t->lac->rtimeout > 0) && !t->lac->rsched &&
            t->lac->active)
        {
            l2tp_log (LOG_INFO, "Will redial in %d seconds\n",
                 t->lac->rtimeout);
            tv.tv_sec = t->lac->rtimeout;
            tv.tv_usec = 0;
            t->lac->rsched = schedule (tv, magic_lac_dial, t->lac);

            /* user add interface done process */
            l2tp_log(LOG_INFO, "IXE-cloud  Will closed usb 4g ether down...");
            system("ifconfig usb0 down");
            sleep(1);
            l2tp_log(LOG_INFO, "--> start 4g ether dailer ...");
            system("/etc/init.d/S99NDIS.sh");
			/* 增加内容如上 */
			
        }
    }
......
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

第二步,生成补丁文件

$ diff -uNr xl2tp-v1.3.6/xl2tpd.c src.xl2tp-v1.3.6/xl2tpd.c > 0003_dialer.patch

//补丁内容
--- xl2tp-v1.3.6/xl2tpd.c	2021-03-10 14:15:17.350065952 +0800
+++ src.xl2tp-v1.3.6/xl2tpd.c	2021-03-10 14:11:04.273344366 +0800
@@ -554,6 +554,8 @@
     struct call *c, *me;
     struct tunnel *p;
     struct timeval tv;
+    //char *ether_4g_down = "ifconfig usb0 down";
+
     if (!t)
         return;
 
@@ -619,6 +621,16 @@
             tv.tv_sec = t->lac->rtimeout;
             tv.tv_usec = 0;
             t->lac->rsched = schedule (tv, magic_lac_dial, t->lac);
+
+            /* user add interface done process */
+            l2tp_log(LOG_INFO, "IXE-cloud  Will closed usb 4g ether down...");
+            system("ifconfig usb0 down");
+            sleep(1);
+            l2tp_log(LOG_INFO, "--> start 4g ether dailer ...");
+            system("/etc/init.d/S99NDIS.sh");
+            //l2tp_log(LOG_INFO, "--> start l2tp service ...");
+            //system("echo \"c vpn\" > /var/run/xl2tpd/l2tp-control");
+
         }
     }
     /* XXX L2TP/IPSec: remove relevant SAs here?  NTB 20011010
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

第三步,拷贝补丁文件至 package/xl2tp/0003_redailer_4g.patch

$ cp 0003_dialer.patch ../../package/xl2tp/0003_dialer.patch
  • 1

第四步,编译验证补丁是否正确

build-2016$ make -j4
xl2tp-v1.3.6.tar.gz: OK (sha256: 49b069aa8d873e1d8f615ccc4212351e427bf681ba453fdd211256a8345bb7fb)
>>> xl2tp v1.3.6 Extracting
gzip -d -c /home/robot/buildroot/build-2016/dl/xl2tp-v1.3.6.tar.gz | tar --strip-components=1 -C /home/robot/buildroot/build-2016/output/build/xl2tp-v1.3.6   -xf -
>>> xl2tp v1.3.6 Patching

Applying 0001-legacy.patch using patch: 
patching file osport.h
Hunk #1 succeeded at 35 (offset -2 lines).

Applying 0002-musl.patch using patch: 
patching file xl2tpd.c
# 补丁包执行情况
Applying 0003_dialer.patch using patch: 
patching file xl2tpd.c
>>> xl2tp v1.3.6 Configuring
>>> xl2tp v1.3.6 Building

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

第5步 ,查看补丁后的源文件内容

    if (t->lac)
    {
        t->lac->t = NULL;
        if (t->lac->redial && (t->lac->rtimeout > 0) && !t->lac->rsched &&
            t->lac->active)
        {
            l2tp_log (LOG_INFO, "Will redial in %d seconds\n",
                 t->lac->rtimeout);
            tv.tv_sec = t->lac->rtimeout;
            tv.tv_usec = 0;
            t->lac->rsched = schedule (tv, magic_lac_dial, t->lac);

            /* user add patching */
            l2tp_log(LOG_INFO, "IXE-cloud  Will closed usb 4g ether down...");
            system("ifconfig usb0 down");
            sleep(1);
            l2tp_log(LOG_INFO, "--> start 4g ether dailer ...");
            system("/etc/init.d/S99NDIS.sh");
            //l2tp_log(LOG_INFO, "--> start l2tp service ...");
            //system("echo \"c vpn\" > /var/run/xl2tpd/l2tp-control");

        }
    }
    /* XXX L2TP/IPSec: remove relevant SAs here?  NTB 20011010
     * XXX But what if another tunnel is using same SA?
     */

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号