OpenWrt Forum Archive

Topic: [SOLVED]Applying patches newbie doubt

The content of this topic has been archived on 18 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello,

I was making a patch by follwoing wiki, but I have a doubt when patching a kernel module, after doint the set in which  I move back all the changes to the buildroot by typing

make target/linux/update package/index V=s

I have to go to the toplevel directory in my case

~$  cd openwrt/attitude_adjustment

And there I have to run

make target/linux/{compile,install}
make target/linux/update

After doing that the buildroot is updated, and then do I have to enter in the menuconfig again or just type make V=99 in order to compile the whole suite with my patched applied? Because as far as I could understand, the patched are applied after running make, don't they?

Thanks in advance!

(Last edited by ndarkness on 26 Mar 2013, 11:31)

i don't really understand what you're asking, but   "make menuconfig" just changes the .config file.

If your patch has to do with actual code and you haven't done a "make mrproper" or something since the last time you did a make menuconfig  then you don't have to do that again.

Just do a "make"  to build the images.

(Again... not sure what your concern is)

vhrm wrote:

i don't really understand what you're asking, but   "make menuconfig" just changes the .config file.

If your patch has to do with actual code and you haven't done a "make mrproper" or something since the last time you did a make menuconfig  then you don't have to do that again.

Just do a "make"  to build the images.

(Again... not sure what your concern is)

My concern was if after patching I should have to run again make menuconfig ot not. But you have solved it, thanks!

Another question  I would like to solve, it is concerning to where to put my patch, what is the main difference between generic and platform? Since I'm using the generic ar7xxx for a WDR4300 which has got an Atheros chipset, so as the patch affects to the atheros should I set it on platform? And in order to add in the right folder,  do I have to locate on ( platform for instance) platform with cd ( it's to say $~/linux-*/linux-*/patches/platform), and once I'm there type quilt new 099-whatever.patch?

Finally so as to apply my patch, once I had done the changes on the kernel file, what is the correct command sequency

 make target/linux/{compile,install} V=s
make target/linux/update package/index V=s 

or

 make target/linux/update package/index V=s
make target/linux/{compile,install} V=s 


Thanks again,

You don't need to go back to menuconfig if you are just adding a patch to the kernel, (if the patch does not require any active config).

But you should do "make clean" before compile to get the patch properly included: make target/linux/{clean,compile,install}

If you are doing the patch only for yourself, it makes no real difference where you place the patch. If you place it in generic, it will in theory get applied to all platforms, while in the "platform" it gets only applied to the specific platform you place it.

If your patch is by nature related to ar71xx, I would place it in https://dev.openwrt.org/browser#trunk/t … atches-3.8

But if it has no real connection/dependency to ar71xx, then https://dev.openwrt.org/browser/trunk/t … atches-3.8 would be more natural.

EDIT: and I don't understand the relevance of "make target/linux/update package/index V=s" at all. What is your patch doing?

(Last edited by hnyman on 24 Mar 2013, 17:50)

hnyman wrote:

You don't need to go back to menuconfig if you are just adding a patch to the kernel, (if the patch does not require any active config).

But you should do "make clean" before compile to get the patch properly included: make target/linux/{clean,compile,install}

If you are doing the patch only for yourself, it makes no real difference where you place the patch. If you place it in generic, it will in theory get applied to all platforms, while in the "platform" it gets only applied to the specific platform you place it.



The point is that  I don't know why my patch stays on ~/openwrt/attidude_adjustment/build_dir/linux-*/linux-*/patches but NOT inside the folder platform nor generic. So when I do make make target/linux/update package/index V=s and later make target/linux/{compile,install} it is not applied. Could you tell me what I'm doing wrong?

If your patch is by nature related to ar71xx, I would place it in https://dev.openwrt.org/browser#trunk/t … atches-3.8

But if it has no real connection/dependency to ar71xx, then https://dev.openwrt.org/browser/trunk/t … atches-3.8 would be more natural.

EDIT: and I don't understand the relevance of "make target/linux/update package/index V=s" at all. What is your patch doing?

I don't know what to say, since I was trying to apply what the wiki says... My patch is doing some modification on the atheros available channels.

(Last edited by ndarkness on 24 Mar 2013, 18:27)

ndarkness wrote:

The point is that  I don't know why my patch stays on ~/openwrt/attidude_adjustment/build_dir/linux-*/linux-*/patches but NOT inside the folder platform nor generic. So when I do make make target/linux/update package/index V=s and later make target/linux/{compile,install} it is not applied. Could you tell me what I'm doing wrong?

You are placing the patch in build_dir, which is a temporary place populated during the build process... Same goes for staging_dir. Nothing permanent should be placed in them. (make clean will clear those places destroying your patch.)

You should place your patch in ~/openwrt/attidude_adjustment/target/linux/generic/patches-3.3 (or whatever is the kernel for your platform) or in ~/openwrt/attidude_adjustment/target/linux/<platform>/patches-3.<3>

EDIT:
I read that wiki article you mentioned, and indeed it seems to suggest first placing the patch to <build_dir> and then using the update build command to somehow transfer that back to the proper place, but I have never used that approach. If you use it, the update command is meant for transferring the patch from the temporary build_dir back to permanent source tree in target/linux/generic (or platform). I think that i should make no difference if you run it before or after the make compile step.

(Last edited by hnyman on 24 Mar 2013, 19:27)

ndarkness wrote:

...
My patch is doing some modification on the atheros available channels.

Are you sure you need to be doing that?   There's the whole regulatory domain thing (as described here http://wiki.openwrt.org/doc/howto/wireless.utilities ) which may solve your issue.

If you're using a US device in some other country where more channels are allowed  (or something similar) then it's a good use of your programming powers.

If you're trying to use channels not allowed in your area then please reconsider.   Just because you can, doesn't mean you should.

hnyman wrote:
ndarkness wrote:

The point is that  I don't know why my patch stays on ~/openwrt/attidude_adjustment/build_dir/linux-*/linux-*/patches but NOT inside the folder platform nor generic. So when I do make make target/linux/update package/index V=s and later make target/linux/{compile,install} it is not applied. Could you tell me what I'm doing wrong?

You are placing the patch in build_dir, which is a temporary place populated during the build process... Same goes for staging_dir. Nothing permanent should be placed in them. (make clean will clear those places destroying your patch.)

You should place your patch in ~/openwrt/attidude_adjustment/target/linux/generic/patches-3.3 (or whatever is the kernel for your platform) or in ~/openwrt/attidude_adjustment/target/linux/<platform>/patches-3.<3>

OK, then I will locate my patch there and try to compile it.

EDIT:
I read that wiki article you mentioned, and indeed it seems to suggest first placing the patch to <build_dir> and then using the update build command to somehow transfer that back to the proper place, but I have never used that approach. If you use it, the update command is meant for transferring the patch from the temporary build_dir back to permanent source tree in target/linux/generic (or platform). I think that i should make no difference if you run it before or after the make compile step.

So, if I wanted to use that command how should I  use it? Beacause that was my problem, each time I typed it, the complete folder is erased and my pach with it ...

Thanks

hnyman wrote:
ndarkness wrote:

The point is that  I don't know why my patch stays on ~/openwrt/attidude_adjustment/build_dir/linux-*/linux-*/patches but NOT inside the folder platform nor generic. So when I do make make target/linux/update package/index V=s and later make target/linux/{compile,install} it is not applied. Could you tell me what I'm doing wrong?

You are placing the patch in build_dir, which is a temporary place populated during the build process... Same goes for staging_dir. Nothing permanent should be placed in them. (make clean will clear those places destroying your patch.)

You should place your patch in ~/openwrt/attidude_adjustment/target/linux/generic/patches-3.3 (or whatever is the kernel for your platform) or in ~/openwrt/attidude_adjustment/target/linux/<platform>/patches-3.<3>

EDIT:
I read that wiki article you mentioned, and indeed it seems to suggest first placing the patch to <build_dir> and then using the update build command to somehow transfer that back to the proper place, but I have never used that approach. If you use it, the update command is meant for transferring the patch from the temporary build_dir back to permanent source tree in target/linux/generic (or platform). I think that i should make no difference if you run it before or after the make compile step.

Hi again,

I have placed the patch on ~/openwrt/attidude_adjustment/target/linux/generic/patches-3.3, do make target/linux/update V=s  and my patch disappear from the patch folder as if it was deleted... I have tried the same on the oderl folder with the same output. So there's something I must be doing wrong because this isn´t normal...

I don't undersand the reason behind this, may someone enlighten me?

Thanks

As far as I understand, that "make target/linux/update V=s"  is not needed. Your patch is already in the correct place.

That comment is apparently meant for transferring the edited patches from <build_dir> back to the permanent place, and as your patch is already there, no other action should be needed.


Think the whole workflow this way:

Openwrt includes download instructions for Linux kernel package.
And it includes the patches in target/linux/generic and platform.

In the make process:
the kernel source is downloaded and uncompressed to build_dir
Then the generic and platform patches are applied to the temporary source in build_dir
Then this source is compiled from the build_dir.

When you do "make clean", the contents of the build_dir are deleted, including your possible changes.

If you edit the patches in the original patch dirs, they survive make clean and will be applied again the next time.

If you want to edit the patches in the temporary build_dir, you can do that. But to preserve your changes over the "make clean" (which is needed every now and then), you need to copy the patches back to permanent patches dirs. And the update command is for that.

hnyman wrote:

As far as I understand, that "make target/linux/update V=s"  is not needed. Your patch is already in the correct place.

That comment is apparently meant for transferring the edited patches from <build_dir> back to the permanent place, and as your patch is already there, no other action should be needed.


Think the whole workflow this way:

Openwrt includes download instructions for Linux kernel package.
And it includes the patches in target/linux/generic and platform.

In the make process:
the kernel source is downloaded and uncompressed to build_dir
Then the generic and platform patches are applied to the temporary source in build_dir
Then this source is compiled from the build_dir.

When you do "make clean", the contents of the build_dir are deleted, including your possible changes.

If you edit the patches in the original patch dirs, they survive make clean and will be applied again the next time.

If you want to edit the patches in the temporary build_dir, you can do that. But to preserve your changes over the "make clean" (which is needed every now and then), you need to copy the patches back to permanent patches dirs. And the update command is for that.

Hi hnyman,

Thanks again for replying,

I understand the proccess, so you are tellimg me that what I have to do is to set my patch on ~/openwrt/attidude_adjustment/target/linux/generic/patches-3.3 and then I have to go to the top directory ~/openwrt/attidude_adjustment/ and just type make in order my patch is being applied ?? And then forget about the build_dir ...

And in case I set the patch on build_dir after editing the files I just have to issue make target/linux/{clean,compile} and then what happens? Would I have some .bin with the applied patched?

Thanks

(Last edited by ndarkness on 25 Mar 2013, 15:50)

ndarkness wrote:

I understand the proccess, so you are tellimg me that what I have to do is to set my patch on ~/openwrt/attidude_adjustment/target/linux/generic/patches-3.3 and then I have to go to the top directory ~/openwrt/attidude_adjustment/ and just type make in order my patch is being applied ?? And then forget about the build_dir ...

Yes.
Or actually, if you have already compiled kernel earlier, you might need to do make clean first to get the new patches noticed later (when they are copied/applied to the temporary build_dir during the make).

ndarkness wrote:

And in case I set the patch on build_dir after editing the files I just have to issue make target/linux/{clean,compile} and then what happens? Would I have some .bin with the applied patched?

No. If you do make target/linux/{clean,compile}, the patch gets deleted.

If you do make clean, the patch will get removed from build_dir along everything else. build_dir is just for short-term testing & editing. Nothing permanent can be placed there.

You could just do make target/linux/compile and you would have a new kernel image. But then you need to compile also all the other packages etc. to get the final firmware for your device. A normal full "make".


If you want to edit the patch in build_dir, you have to copy that patch back to safety to the permanent storage at some point (before the next make clean).

hnyman wrote:
ndarkness wrote:

I understand the proccess, so you are tellimg me that what I have to do is to set my patch on ~/openwrt/attidude_adjustment/target/linux/generic/patches-3.3 and then I have to go to the top directory ~/openwrt/attidude_adjustment/ and just type make in order my patch is being applied ?? And then forget about the build_dir ...

Yes.
Or actually, if you have already compiled kernel earlier, you might need to do make clean first to get the new patches noticed later (when they are copied/applied to the temporary build_dir during the make)

Ok, I'm currently doing a complete new compilation(a make after setting the .conf) having set my patch on the ~/openwrt/attidude_adjustment/target/linux/generic/patches-3.3, so in principle it should have taken into account the patch I put there. is there a way apart from settling the .bin on the device to check whether the patch has been applied or not?

Thanks for all the aid you are providing nhyman!

(Last edited by ndarkness on 25 Mar 2013, 16:27)

Have you checked the files in build_dir/target-mips_uClibc-0.9.33.2/linux-ar71xx_generic/linux-3.8.3 that were supposed to be patched with your patch?

EDIT:
you might actually do
make target/linux/{clean,prepare} V=s
and follow what happens.

That cleans the kernel and then prepares it for new compilation by unpacking the kernel source and applying the patches. If your patch is there, it should get applied.

(Last edited by hnyman on 25 Mar 2013, 16:59)

hnyman wrote:

Have you checked the files in build_dir/target-mips_uClibc-0.9.33.2/linux-ar71xx_generic/linux-3.8.3 that were supposed to be patched with your patch?

EDIT:
you might actually do
make target/linux/{clean,prepare} V=s
and follow what happens.

That cleans the kernel and then prepares it for new compilation by unpacking the kernel source and applying the patches. If your patch is there, it should get applied.

Hi hnyman,

The patch is being applied after running make from top directory. I went to the path you mentioned and  the files that supposed to be patched indeed they're big_smile!! What's more with the command you provide in your EDIT, I can see that the patch is applied too.

One last quesion, now all the firmware images which are  created incorporate my patch rigth?

Thanks for all your help!

(Last edited by ndarkness on 26 Mar 2013, 10:05)

ndarkness wrote:

One last quesion, now all the firmware images which are  created incorporate my patch rigth?

Yes.

hnyman wrote:
ndarkness wrote:

One last quesion, now all the firmware images which are  created incorporate my patch rigth?

Yes.

hnyman, allow me another question, if I want to patch some file of iw-3.6,  I have found that  package is under ~/openwrt/attitude_adjustment/build_dir/target-mips_r2_uClibc-0.9.33.2 but that folder is created while doing the make. Then, if I wanted to patch it, should I create another patch just for that package or I can include the patch in my previos .patch? I ask that because in the folder where iw-3.6 is there is no patch folder and I cannot use quilt.

Thanks

robthebrew wrote:

Sorry, I have no answer, but I have followed the thread with interest.
Can you add the distilled wisdom to:
http://wiki.openwrt.org/doc/devel/patches

Yes, I will do it as soon as I solve my last doubt, but I'm seeing that I cannot log in with my forum account to modify the wiki, I need another account?

You should be able to edit it.
You might have to log in a second time (right hand side) with your normal login info.
Then "edit" button appear in the wiki.
If not, either raise a ticket, or post in the Developer forum

ndarkness wrote:

hnyman, allow me another question, if I want to patch some file of iw-3.6,  I have found that  package is under ~/openwrt/attitude_adjustment/build_dir/target-mips_r2_uClibc-0.9.33.2 but that folder is created while doing the make. Then, if I wanted to patch it, should I create another patch just for that package or I can include the patch in my previos .patch? I ask that because in the folder where iw-3.6 is there is no patch folder and I cannot use quilt.

You should place the patch in that package's "patches" folder. In your case in attitude_adjustment/package/iw/patches

(Last edited by hnyman on 26 Mar 2013, 16:21)

hnyman wrote:
ndarkness wrote:

hnyman, allow me another question, if I want to patch some file of iw-3.6,  I have found that  package is under ~/openwrt/attitude_adjustment/build_dir/target-mips_r2_uClibc-0.9.33.2 but that folder is created while doing the make. Then, if I wanted to patch it, should I create another patch just for that package or I can include the patch in my previos .patch? I ask that because in the folder where iw-3.6 is there is no patch folder and I cannot use quilt.

You should place the patch in that package's "patches" folder. In your case in attitude_adjustment/package/iw/patches

Perfect, thanks again!

The discussion might have continued from here.