Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to write epatch depends on target Kernel Version
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Cuong Nguyen
Apprentice
Apprentice


Joined: 18 Jan 2018
Posts: 152

PostPosted: Sat Nov 10, 2018 7:49 am    Post subject: How to write epatch depends on target Kernel Version Reply with quote

How can I write a patch file in /etc/portage/patches/<category>/<pn-pv> that only apply to certain kernel version?

For example, I want to patch x11-drivers/nvidia-drivers-394.54 that will by applied only if emerge for kernel version higher or equal 4.19? and leave as it for kernel version lower 4.19?

Thank you


Last edited by Cuong Nguyen on Sun Nov 11, 2018 3:52 am; edited 1 time in total
Back to top
View user's profile Send private message
DaggyStyle
Watchman
Watchman


Joined: 22 Mar 2006
Posts: 5909

PostPosted: Sat Nov 10, 2018 9:59 am    Post subject: Re: How to write epatch depends on Kernel Version Reply with quote

Cuong Nguyen wrote:
How can I write a patch file in /etc/portage/patches/<category>/<pn-pv> that only apply to certain kernel version?

For example, I want to patch x11-drivers/nvidia-drivers-394.54 that will by applied only if emerge for kernel version higher or equal 4.19? and leave as it for kernel version lower 4.19?

Thank you

afaik, you cannot do that, it will get applied regardless of kernel version.
what you can do however is try to condition the patched code to get compiled if the kernel's version is specific. see https://stackoverflow.com/questions/16721346/is-there-a-macro-definition-to-check-the-linux-kernel-version/16721774
_________________
Only two things are infinite, the universe and human stupidity and I'm not sure about the former - Albert Einstein
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54234
Location: 56N 3W

PostPosted: Sat Nov 10, 2018 10:12 am    Post subject: Reply with quote

DaggyStyle,

x11-drivers/nvidia-drivers builds against the kernel pointed to by /usr/src/linux, which may not be the running kernel.
Its that kernel version that needs to be tested, since the module will get installed to /lib/modules/<kernel-ver>/ and loaded from there when <kernel-ver> is actually running.

Detect /usr/src/linux at build time and write the patch to do the 'right thing' depending on the version that /usr/src/linux points to.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
DaggyStyle
Watchman
Watchman


Joined: 22 Mar 2006
Posts: 5909

PostPosted: Sat Nov 10, 2018 12:53 pm    Post subject: Reply with quote

NeddySeagoon wrote:
DaggyStyle,

x11-drivers/nvidia-drivers builds against the kernel pointed to by /usr/src/linux, which may not be the running kernel.
Its that kernel version that needs to be tested, since the module will get installed to /lib/modules/<kernel-ver>/ and loaded from there when <kernel-ver> is actually running.

Detect /usr/src/linux at build time and write the patch to do the 'right thing' depending on the version that /usr/src/linux points to.

I've just tried to offer him a solution, logically speaking, it is highly likely that the kernel he is running is the one on /usr/src/linux
if not, then there is no way to do so afaics
_________________
Only two things are infinite, the universe and human stupidity and I'm not sure about the former - Albert Einstein
Back to top
View user's profile Send private message
Naib
Watchman
Watchman


Joined: 21 May 2004
Posts: 6051
Location: Removed by Neddy

PostPosted: Sat Nov 10, 2018 1:01 pm    Post subject: Reply with quote

This sounds like an x-y problem.

What exactly are you patching for? why would you be concerned with kernel versions < 4.19 ? why not just hard mask < 4.19
_________________
Quote:
Removed by Chiitoo
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54234
Location: 56N 3W

PostPosted: Sat Nov 10, 2018 6:01 pm    Post subject: Reply with quote

DaggyStyle,

When I used nvidia-drivers, I used to update the kernel but not boot it. Fix the /usr/src/linux symlink then build nvidia-drivers.
That way, I could boot into the new kernel and have a GUI at the same time.
It does mean that when I built nvidia drivers, it was always built against a kernel that was not being run.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Naib
Watchman
Watchman


Joined: 21 May 2004
Posts: 6051
Location: Removed by Neddy

PostPosted: Sat Nov 10, 2018 7:05 pm    Post subject: Reply with quote

you could just set CONFIG_PM in the kernel and you don't have to worry about all this UNLESS there is a pressing need to keep booting and using and compiling against old kernels
_________________
Quote:
Removed by Chiitoo
Back to top
View user's profile Send private message
Cuong Nguyen
Apprentice
Apprentice


Joined: 18 Jan 2018
Posts: 152

PostPosted: Sun Nov 11, 2018 3:43 am    Post subject: Reply with quote

Yes, I always USE=symlink emerge *-sources or manually create symlink to proper kernel source tree in /usr/src. I always run module-build with KERN_VER= environment variable.

Here is the patch
Code:
diff -ur NVIDIA-Linux-x86_64-396.24/kernel/nvidia-drm/nvidia-drm-connector.c NVIDIA-Linux-x86_64-396.24.patched2/kernel/nvidia-drm/nvidia-drm-connector.c
--- NVIDIA-Linux-x86_64-396.24/kernel/nvidia-drm/nvidia-drm-connector.c 2018-04-26 10:34:46.000000000 +0200
+++ NVIDIA-Linux-x86_64-396.24.patched2/kernel/nvidia-drm/nvidia-drm-connector.c        2018-08-22 15:42:15.327407716 +0200
@@ -226,7 +226,7 @@


     if (nv_connector->edid != NULL) {
-        drm_mode_connector_update_edid_property(
+        drm_connector_update_edid_property(
             connector, nv_connector->edid);
     }

diff -ur NVIDIA-Linux-x86_64-396.24/kernel/nvidia-drm/nvidia-drm-encoder.c NVIDIA-Linux-x86_64-396.24.patched2/kernel/nvidia-drm/nvidia-drm-encoder.c
--- NVIDIA-Linux-x86_64-396.24/kernel/nvidia-drm/nvidia-drm-encoder.c   2018-04-26 10:34:46.000000000 +0200
+++ NVIDIA-Linux-x86_64-396.24.patched2/kernel/nvidia-drm/nvidia-drm-encoder.c  2018-08-22 15:41:25.356410694 +0200
@@ -216,7 +216,7 @@

     /* Attach encoder and connector */

-    ret = drm_mode_connector_attach_encoder(connector, encoder);
+    ret = drm_connector_attach_encoder(connector, encoder);

     if (ret != 0) {
         NV_DRM_DEV_LOG_ERR(

Actually its needed only for >= linux-4.19 . I know it can be fixed with less than 10 lines of code for KERNEL_VERSION macro and patch it. But it doesnt worth for patching only 2 lines of sources code. Just run emerge and will decide patch or unpatch later based on building error logs.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum