OpenWrt Forum Archive

Topic: How to add Kernal Patch and Reghack to custom build image

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

I was up until recently using Arokh's build of OpenWRT. I have now decided for a couple of reasons to go with my own image.
For the most part, I have included my own packages etc that i require, but the only things I haven't been able to do yet, is add the Overclock patch and the Reghack for Wifi.

I asked Arokh how he added it to his image, and his response was this:

arokh wrote:

1. It's a kernel patch. It's in the top level directory and it's enabled through the CONFIG_KERNEL_OC_XXX options. (Patch located here: http://enduser.subsignal.org/~trondah/stuff/ )
2. It's jow's reghack from http://luci.subsignal.org/~jow/reghack/ and I apply it before modules are loaded in package/base-files/files/etc/init.d/boot.

I couldn't really piece it all together - I'm a complete novice (or n00b) when it comes to building my own image.

I thought I better start a new thread to get this stuff resolved... Is anyone able to assist in pointing me in the right direction please?

1. If you are building vanilla OpenWrt - download the patch from URL above, edit according to overclock.txt and place it in your target/linux/ar71xx/patches-3.10 before building.

2. Download reghack.mips.elf from URL above and place into files/lib/wifi (make sure it's executable with chmod +x) and edit the boot file as follows:

--- a/package/base-files/files/etc/init.d/boot
+++ b/package/base-files/files/etc/init.d/boot
@@ -35,6 +35,17 @@ boot() {
        grep -q debugfs /proc/filesystems && /bin/mount -o noatime -t debugfs debugfs /sys/kernel/debug
        [ "$FAILSAFE" = "true" ] && touch /tmp/.failsafe
 
+       grep -i -q mips /proc/cpuinfo && REGHACK=reghack.mips.elf
+       grep -i -q freescale /proc/cpuinfo && REGHACK=reghack.ppc.elf
+
+       # Install regdomain hack
+       if [ ! -f /etc/.regd ]; then
+         cd /lib/wifi
+         ./$REGHACK /lib/modules/*/ath.ko
+         ./$REGHACK /lib/modules/*/cfg80211.ko
+         touch /etc/.regd
+       fi
+
        /sbin/kmodloader
 
        # allow wifi modules time to settle

There's some logic to determine CPU architecture there, you can change that since you don't need it, or you can do it like that it will work for you anyway.

(Last edited by arokh on 8 Sep 2014, 09:00)

Mate, you truely are a legend! I will give that a try now...

arokh wrote:

1. If you are building vanilla OpenWrt - download the patch from URL above, edit according to overclock.txt and place it in your target/linux/ar71xx/patches-3.10 before building.

So do I only need to change li t2, 0xc0140190 to C0140198 for it to overclock to 800Mhz?


I will give the wifi stuff a try now...

Yes smile This is stuff made by other people though, I'm just putting it together.

arokh wrote:

Yes smile This is stuff made by other people though, I'm just putting it together.


No worries, thanks mate. appreciate the help!

It's currently 'making' at the moment... looks like it may take a while.

Will report back soon and let you know if I've ruined my router wink

... or you won't hear from me if I have!

this reghack is noting more then a patch for a binary or ?

just enable CONFIG_ATH_USER_REGD in make menuconfig for getting this.

It does more than that, it replaces the regulatory domain rules in the module to let you use all channels at max tx power including DFS ones.

Unfortunately nothing to report at this stage... started to compile, but its also doing the buildchain etc. as well neutral

THen it crashed and said it wont continue, so working on it again today, now that I've finished work.

Currently compiling the suite again, then the image...

Well, I tried and failed to build the image.

The SDK etc has all completed fine.. but I just can't get my img file to include my selected packages and patches.

I went through and did the make menuconfig etc. and included the files I wanted, but when I ran MAKE PROFILE=WNDR3700, it builds OpenWRT but without any of my stuff.

I have no idea what is going on here and all I can say is I have a new appreciation for what you guys do!!

EDIT: Rookie mistake. Saved my .config file as myfile.config, not realising it had to be just '.config'

looks like its including my files now... lets try again.

(Last edited by aaronta on 9 Sep 2014, 10:56)

The PROFILE variable is specific for the image generator I believe, you can just run make without any arguments. For a first run I'd use V=99 so you can get a proper error log.

arokh wrote:

The PROFILE variable is specific for the image generator I believe, you can just run make without any arguments. For a first run I'd use V=99 so you can get a proper error log.


Well, the good news is, I now got it to build successfully and include my stuff, using:
make PROFILE=WNDR3700 FILES='/home/aaron/trunk/files'

The issue I have now is actually testing it...

The OC I will test tomorrow (going to bed soon), not really a concern...

The wifi is the biggest issue and by that, I mean there is no Wifi at all!! No idea what happened to it... doesnt show up in LuCI and says there is nothing there when I do wifi detect.

I suspect I am missing a driver, but I thought that would have been included by default.

(Last edited by aaronta on 9 Sep 2014, 11:40)

If you did a make menuconfig and selected your router then the resulting .config should have the correct wifi drivers installed. The radios will however be disabled by default in /etc/config/wireless.

arokh wrote:

If you did a make menuconfig and selected your router then the resulting .config should have the correct wifi drivers installed. The radios will however be disabled by default in /etc/config/wireless.


The wireless config won't even generate though.

I'll give it another try with building a new image tomorrow to test.. All a bit weird

arokh wrote:

1. If you are building vanilla OpenWrt - download the patch from URL above, edit according to overclock.txt and place it in your target/linux/ar71xx/patches-3.10 before building.

2. Download reghack.mips.elf from URL above and place into files/lib/wifi (make sure it's executable with chmod +x) and edit the boot file as follows:

--- a/package/base-files/files/etc/init.d/boot
+++ b/package/base-files/files/etc/init.d/boot
@@ -35,6 +35,17 @@ boot() {
        grep -q debugfs /proc/filesystems && /bin/mount -o noatime -t debugfs debugfs /sys/kernel/debug
        [ "$FAILSAFE" = "true" ] && touch /tmp/.failsafe
 
+       grep -i -q mips /proc/cpuinfo && REGHACK=reghack.mips.elf
+       grep -i -q freescale /proc/cpuinfo && REGHACK=reghack.ppc.elf
+
+       # Install regdomain hack
+       if [ ! -f /etc/.regd ]; then
+         cd /lib/wifi
+         ./$REGHACK /lib/modules/*/ath.ko
+         ./$REGHACK /lib/modules/*/cfg80211.ko
+         touch /etc/.regd
+       fi
+
        /sbin/kmodloader
 
        # allow wifi modules time to settle

There's some logic to determine CPU architecture there, you can change that since you don't need it, or you can do it like that it will work for you anyway.

I always wonder how any patch like this will cause problems in the long run, especially with a trunk version of OpenWRT, when the operator starts doing the updates. There must be a better way to do this. If anyone here knows, please kindly chime in.

A change like this is easy to maintain even if this specific file gets updated in trunk (which it rarely or never does). You can choose to do it any way you want, for example in rc.local but that means you need an extra reboot once the modules are patched. You could also modify the compat-wireless Makefile to apply it there before the image is made. In any case you'll need to modify a script I'm not sure what you are worried about.

arokh wrote:

A change like this is easy to maintain even if this specific file gets updated in trunk (which it rarely or never does). You can choose to do it any way you want, for example in rc.local but that means you need an extra reboot once the modules are patched. You could also modify the compat-wireless Makefile to apply it there before the image is made. In any case you'll need to modify a script I'm not sure what you are worried about.

That is true. But, my concern is related to your suggestion to patch the /etc/init.d/boot file which gets updated frequently on the trunk. If this is the only patch, it can be simply and manually re-patched. However, if you had deal with 10+ patches that you have to manually re-patch every time OpenWRT modifies those files, then you will start to voice your concern.

It's really quite simple with basic knowledge of git/diff. That file isn't updated frequently I said rarely. 7 times the past year. The above patch is just an addition, it will pretty much apply cleanly every time. But yeah, with lots of changes you will need to keep an eye on what's happening in trunk. If you're worried about that stick with a stable release.

(Last edited by arokh on 9 Sep 2014, 19:32)

arokh wrote:

It's really quite simple with basic knowledge of git/diff.

I tried that with 10+ patches and I must say it is quite some works. OTOH, if your trunk is still on SVN, you will be spending more times to fix the patches.

That file isn't updated frequently I said rarely. 7 times the past year. The above patch is just an addition, it will pretty much apply cleanly every time. But yeah, with lots of changes you will need to keep an eye on what's happening in trunk. If you're worried about that stick with a stable release.

I used your suggested patch as an example and doesn't necessarily mean it is a single file.I am hoping some more knowledgeable readers here will chime with a much better solution.

I have around 50+ patches on my git tree and don't spend much time on them. Instead of being a condescending douche maybe you could explain to me what you mean with a "better solution"? Are you talking about adding the reghack to a build, or maintaining patches to the tree in general?

The scripting bit I do in the boot file could be placed in files/etc/uci-defaults/whatever and it will be run once on bootup. That will be clean like you want in that it will never conflict with trunk. Like I stated before that will also require you to do another reboot. If that's acceptable to you then you can use that method instead.

Anybody knows how to apply the reghack to the source?

Sorry to stress this again. I want to include the reghack patch directly to my image, but the patch fails.

I did the following:

Placed the reghack.mips.elf in openwrt/trunk/package/kernel/mac80211/files/lib/wifi/
Apply the patch to openwrt/trunk/package/base-files/files/etc/init.d/boot, but it was rejected

boot.rej

--- package/base-files/files/etc/init.d/boot
+++ package/base-files/files/etc/init.d/boot
@@ -35,6 +35,17 @@ boot() {
        grep -q debugfs /proc/filesystems && /bin/mount -o noatime -t debugfs debugfs /sys/kernel/debug
        [ "$FAILSAFE" = "true" ] && touch /tmp/.failsafe

+       grep -i -q mips /proc/cpuinfo && REGHACK=reghack.mips.elf
+       grep -i -q freescale /proc/cpuinfo && REGHACK=reghack.ppc.elf
+
+       # Install regdomain hack
+       if [ ! -f /etc/.regd ]; then
+         cd /lib/wifi
+         ./$REGHACK /lib/modules/*/ath.ko
+         ./$REGHACK /lib/modules/*/cfg80211.ko
+         touch /etc/.regd
+       fi
+
        /sbin/kmodloader

        # allow wifi modules time to settle

Is there no source patch? Can anyone help please?

Thanks!
greetings schnurzelat

It won't apply because the boot file changed. Just edit manually and insert the needed lines before kmodloader.

Thanks for advice, but it didn't worked. I manually edited the boot file. After compiling and flashing the firmware, i found the .regd file in /etc/.

Is my reghack.mips.elf in the correct folder? I put it in

openwrt/trunk/package/kernel/mac80211/files/lib/wifi/reghack.mips.elf

I made it executeable. In the folder is already a file called mac80211.sh.

Is this correct?

greetings schnurzelat

(Last edited by schnurzelat on 13 Mar 2015, 08:47)

No, it should be in openwrt/trunk/files/lib/wifi/reghack.mips.elf.

It worked for me now. I forgot

make package/kernel/mac80211/clean &&  make package/kernel/mac80211/compile

before building a new image.

But it seems to use space in the overlayfs. Is this correct?

(Last edited by schnurzelat on 13 Mar 2015, 10:35)

The discussion might have continued from here.