How to use the buildroot patch patch file

When using buildroot to compile the kernel source code, there is often a need to modify the driver or third-party package. You can directly modify the source code under output/build/, and the modified content of make clean will be lost. Use the patching method and put the patch package under the package. For the package, this problem can be solved.
This blog post records the patching process of modifying the xl2tpd source code.

The first step is to copy the file xl2tpd.c that needs to be modified to the specified folder:

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

The contents of the modified file are as follows:

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");
			/* 增加内容如上 */
			
        }
    }
......

The second step is to generate the patch file

$ 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

The third step is to copy the patch file to package/xl2tp/0003_redailer_4g.patch

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

The fourth step is to compile and verify that the patch is correct

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

Step 5, view the contents of the source file after the patch

    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?
     */

Guess you like

Origin blog.csdn.net/weixin_38387929/article/details/114593973