0

I am trying to use a git patch to update a Buildroot package. I want to upgrade ptp 2.0 to ptp 3.1.1.

I found a similar patch here that updates the Buildroot ptp package from 2.0 to 3.0.

Ptp 2.0 includes a patch (0002-fix-building-with-new-kernel-headers.patch) that is not required for ptp 3.0/3.1.1.

0002-fix-building-with-new-kernel-headers.patch:

From d663a483c40939bad58301c256d86da1f3da6cc0 Mon Sep 17 00:00:00 2001
From: Miroslav Lichvar <mlichvar@redhat.com>
Date: Tue, 13 Nov 2018 13:16:08 +0100
Subject: [PATCH] Fix building with new kernel headers.

net_tstamp.h in recent kernel versions requires time.h for clockid_t.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
---
 clock.c      | 2 +-
 sk.c         | 1 +
 timemaster.c | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clock.c b/clock.c
index 9c493c3..8533b39 100644
--- a/clock.c
+++ b/clock.c
@@ -17,11 +17,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 #include <errno.h>
+#include <time.h>
 #include <linux/net_tstamp.h>
 #include <poll.h>
 #include <stdlib.h>
 #include <string.h>
-#include <time.h>
 #include <sys/queue.h>
 
 #include "address.h"
diff --git a/sk.c b/sk.c
index e2b1f28..30162eb 100644
--- a/sk.c
+++ b/sk.c
@@ -18,6 +18,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 #include <errno.h>
+#include <time.h>
 #include <linux/net_tstamp.h>
 #include <linux/sockios.h>
 #include <linux/ethtool.h>
diff --git a/timemaster.c b/timemaster.c
index 058678f..00db59f 100644
--- a/timemaster.c
+++ b/timemaster.c
@@ -22,6 +22,7 @@
 #include <errno.h>
 #include <libgen.h>
 #include <limits.h>
+#include <time.h>
 #include <linux/net_tstamp.h>
 #include <net/if.h>
 #include <signal.h>

My upgrade-linuxptp-package.patch file:

diff --git a/package/linuxptp/0002-fix-building-with-new-kernel-headers.patch b/package/linuxptp/0002-fix-building-with-new-kernel-headers.patch
deleted file mode 100644
index 332e549..0000000
--- a/package/linuxptp/0002-fix-building-with-new-kernel-headers.patch
+++ /dev/null
@@ -1,55 +0,0 @@
-From d663a483c40939bad58301c256d86da1f3da6cc0 Mon Sep 17 00:00:00 2001
-From: Miroslav Lichvar <mlichvar@redhat.com>
-Date: Tue, 13 Nov 2018 13:16:08 +0100
-Subject: [PATCH] Fix building with new kernel headers.
-
-net_tstamp.h in recent kernel versions requires time.h for clockid_t.
-
-Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
----
- clock.c      | 2 +-
- sk.c         | 1 +
- timemaster.c | 1 +
- 3 files changed, 3 insertions(+), 1 deletion(-)
-
-diff --git a/clock.c b/clock.c
-index 9c493c3..8533b39 100644
---- a/clock.c
-+++ b/clock.c
-@@ -17,11 +17,11 @@
-  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-  */
- #include <errno.h>
-+#include <time.h>
- #include <linux/net_tstamp.h>
- #include <poll.h>
- #include <stdlib.h>
- #include <string.h>
--#include <time.h>
- #include <sys/queue.h>
-
- #include "address.h"
-diff --git a/sk.c b/sk.c
-index e2b1f28..30162eb 100644
---- a/sk.c
-+++ b/sk.c
-@@ -18,6 +18,7 @@
-  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-  */
- #include <errno.h>
-+#include <time.h>
- #include <linux/net_tstamp.h>
- #include <linux/sockios.h>
- #include <linux/ethtool.h>
-diff --git a/timemaster.c b/timemaster.c
-index 058678f..00db59f 100644
---- a/timemaster.c
-+++ b/timemaster.c
-@@ -22,6 +22,7 @@
- #include <errno.h>
- #include <libgen.h>
- #include <limits.h>
-+#include <time.h>
- #include <linux/net_tstamp.h>
- #include <net/if.h>
- #include <signal.h>
diff --git a/package/linuxptp/linuxptp.hash b/package/linuxptp/linuxptp.hash
index 5e6c774..5c799a7 100644
--- a/package/linuxptp/linuxptp.hash
+++ b/package/linuxptp/linuxptp.hash
@@ -1,9 +1,9 @@
-# From https://sourceforge.net/projects/linuxptp/files/v2.0/
-sha1 592ca42c6146a79c1fcabed7c19fa7af4803d4f6  linuxptp-2.0.tgz
-md5 d8bb7374943bb747db7786ac26f17f11  linuxptp-2.0.tgz
+# From https://sourceforge.net/projects/linuxptp/files/v3.1/
+sha1 f905eabc6fd0f03c6a353f9c4ba188a3bd1b774c  linuxptp-3.1.1.tgz
+md5 3b79ab5e77c5b5cf06bc1c8350d405bb  linuxptp-3.1.1.tgz

 # Locally computed:
-sha256 0a24d9401e87d4af023d201e234d91127d82c350daad93432106284aa9459c7d  linuxptp-2.0.tgz
+sha256 94d6855f9b7f2d8e9b0ca6d384e3fae6226ce6fc012dbad02608bdef3be1c0d9  linuxptp-3.1.1.tgz

 # Hash for license file:
 sha256 8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643  COPYING
diff --git a/package/linuxptp/linuxptp.mk b/package/linuxptp/linuxptp.mk
index c304ff6..b10368f 100644
--- a/package/linuxptp/linuxptp.mk
+++ b/package/linuxptp/linuxptp.mk
@@ -4,7 +4,7 @@
 #
 ################################################################################

-LINUXPTP_VERSION = 2.0
+LINUXPTP_VERSION = 3.1.1
 LINUXPTP_SOURCE = linuxptp-$(LINUXPTP_VERSION).tgz
 LINUXPTP_SITE = http://downloads.sourceforge.net/linuxptp
 LINUXPTP_LICENSE = GPL-2.0+

When I go apply my patch (CentOS 7, git version 1.8.3.1 & 2.34.1), I get the following "error: while searching for:" error:

$ git apply --verbose upgrade-linuxptp-package.patch
Checking patch package/linuxptp/0002-fix-building-with-new-kernel-headers.patch...
error: while searching for:
From d663a483c40939bad58301c256d86da1f3da6cc0 Mon Sep 17 00:00:00 2001
From: Miroslav Lichvar <mlichvar@redhat.com>
Date: Tue, 13 Nov 2018 13:16:08 +0100
Subject: [PATCH] Fix building with new kernel headers.

net_tstamp.h in recent kernel versions requires time.h for clockid_t.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
---
 clock.c      | 2 +-
 sk.c         | 1 +
 timemaster.c | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clock.c b/clock.c
index 9c493c3..8533b39 100644
--- a/clock.c
+++ b/clock.c
@@ -17,11 +17,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 #include <errno.h>
+#include <time.h>
 #include <linux/net_tstamp.h>
 #include <poll.h>
 #include <stdlib.h>
 #include <string.h>
-#include <time.h>
 #include <sys/queue.h>

 #include "address.h"
diff --git a/sk.c b/sk.c
index e2b1f28..30162eb 100644
--- a/sk.c
+++ b/sk.c
@@ -18,6 +18,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 #include <errno.h>
+#include <time.h>
 #include <linux/net_tstamp.h>
 #include <linux/sockios.h>
 #include <linux/ethtool.h>
diff --git a/timemaster.c b/timemaster.c
index 058678f..00db59f 100644
--- a/timemaster.c
+++ b/timemaster.c
@@ -22,6 +22,7 @@
 #include <errno.h>
 #include <libgen.h>
 #include <limits.h>
+#include <time.h>
 #include <linux/net_tstamp.h>
 #include <net/if.h>
 #include <signal.h>

error: patch failed: package/linuxptp/0002-fix-building-with-new-kernel-headers.patch:1
error: package/linuxptp/0002-fix-building-with-new-kernel-headers.patch: patch does not apply
Checking patch package/linuxptp/linuxptp.hash...
Checking patch package/linuxptp/linuxptp.mk...

I have tried shorting my patch file to remove the first 20+ lines. This works until I try removing line 27. To clarify, I can successfully remove lines 1-26 of the 0002-fix-building-with-new-kernel-headers.patch (down to #include <stdlib.h>). If I try to remove lines 1-27 of 0002-fix-building-with-new-kernel-headers.patch (down to #include <string.h>), the "error: while searching for:" error is returned.

Is this a parsing error in git apply? Do I need to escape characters when applying a patch that modifies a patch? Can I create a patch file that does nothing (when applied, no changes are made)?

Thanks

mhck
  • 873
  • 1
  • 10
  • 20
  • 1
    I do not understand what you are trying to do. If you want to completely exclude the 0002 patch, why don't you just move that specific patch file away from the directory ? – LeGEC Jan 10 '23 at 05:11
  • Effectively that is what I am trying to do. The 0002 patch file is deployed by default as part of the Buildroot ptp 2.0 package. The Buildroot build process is automated. The build steps (in simplified terms): 1.download_package, 2.unpack, 3.apply_patches, 4.build. If I delete the 0002 patch, steps 1 and 2 will replace it the next time I build. My question applies to the 3.apply_patches step, which allows for additional external patches to be applied. That is why the ptp maintainers took a similar approach to upgrade from ptp 2.0 to 3.0 (see link above). Thanks for asking. – mhck Jan 10 '23 at 10:24
  • ok (I'm not sure I fully understand the buildroot thing) in that case : why patch the patch file ? can't you apply a final patch on the *code files* to get the result you wish for ? – LeGEC Jan 10 '23 at 10:56
  • another remark: to generate a patch, rather than editing a patch file by hand, a more convenient way is to have a `before/` and an `after/` directory with the content you want, and run `diff before/ after/` (or `git diff --no-index before/ after/`) – LeGEC Jan 10 '23 at 10:59
  • The short answer is no. There are 2 layers of unpacking and patching that happen at different times when making a Buildroot image. I can patch Buildroot (more specifically Buildroot package files), and then the Buildroot package files will unpack and patch the associated source (*code* *files*) at build time. Thanks, that is the method I used to generate the patch. No hand editing was performed. – mhck Jan 10 '23 at 12:12

1 Answers1

0

Follow up:

Based on this stackoverflow page, I switched to using diff -uraN instead of git diff. From the new patches I generated, I was able to identify two problems with the original patches I generated.

  1. At some point, the lines containing "- " converted to "-". The trailing space was removed. I believe this caused the error: while searching for: error.
  2. On various iterations of my git diff patches, the email address "mlichvar@redhat.com" converted to "mlichvar at redhat.com". This is probably related to a font ligatures setting in my X11 server terminal / SSH client (I did not track down the exact cause). This problem was not present in the patch I posted in my question, but it is a concern to watch out for.

The differences between a working patch and a problem patch: enter image description here

mhck
  • 873
  • 1
  • 10
  • 20