OpenWrt Forum Archive

Topic: How to apply a patch to GPIO values?

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

I have a TP-Link Archer C7 V2, and the compiled image for it has a bug that causes the WiFi on/off switch on the back to not work. This bug is caused by the GPIO number configured for that button being incorrect for certain models, and there's a simple patch available for it that apparently still hasn't been included because it would in turn cause the switch to break on other models.

I've never compiled anything with a custom patch like this from scratch, but I'm sure I could get it done with the tutorials on the wiki. Before I open that can of worms, though, I'd like to ask a couple of questions.

1) Is there any way to fix this issue (basically remap the switch to GPIO23 from GPIO13) without having to build anything?

2) If I have to build something, do I have to rebuild the entire image and then reflash the device with that, or can I get away with rebuilding some specific package? If just a specific package, can I use the pre-compiled SDK thing to build it?

3) What package does this patch actually even affect?


Any advice would be appreciated.

(Last edited by burneddi on 13 Jul 2016, 02:46)

ー( ̄~ ̄)ξ

flexman wrote:

ー( ̄~ ̄)ξ

Gee thanks

Ended up sorting it out myself with a little help from the IRC channel, in case you're here from Google or something here's what I did:

1) Set up a Debian VM to build in

2) Follow the instructions over at https://wiki.openwrt.org/doc/howto/build and https://wiki.openwrt.org/doc/howto/buildroot.exigence

    2.1) For the most part I did everything according to those pages. Since I wanted my custom image to have the same packages as the default image, it was a bit tricky (and laborous) to find and select the exact ones I wanted. I'm told you can just select the right architecture and model for your router and you should automatically get everything it needs to function, but even after doing that I was missing some packages (for instance, the kmod-ath10k driver for 5G WiFi functionality) and had to rebuild the image with those packages manually selected, so yeah I don't really know. You'll probably want to include Luci in your packages, as it's missing by default
   
    2.2) Drop this patch into <openwrt sources directory>/target/linux/ar71xx/patches-3.18/ — name it something like archer-c7-v2-rfkill-fix.patch, it's very important that you drop it in the correct directory or else the file paths in the patch won't work and you'll get an error when compiling. If you're compiling a version other than 15.05, the numbers after the patches directory might be different. In this case you might want to check that the file the patch modifies still has the correct format.

--- a/arch/mips/ath79/mach-archer-c7.c
+++ b/arch/mips/ath79/mach-archer-c7.c
@@ -50,7 +50,7 @@
 #define ARCHER_C7_GPIO_LED_USB1        18
 #define ARCHER_C7_GPIO_LED_USB2        19
 
-#define ARCHER_C7_GPIO_BTN_RFKILL    13
+#define ARCHER_C7_GPIO_BTN_RFKILL    23
 #define ARCHER_C7_GPIO_BTN_RESET    16
 
 #define ARCHER_C7_GPIO_USB1_POWER    22

   2.3) If you're compiling 15.05, you might run into some errors because it fails to retrieve source packages due to those packages having moved (you'll get a 404 error). In this case either find the appropriate package yourself using your web search engine of choice and place it in the <openwrt sources directory>/dl/ directory, or correct the URL in the Makefile of that package.

3) After your image compiles with no errors, you'll find it in the /bin/ directory of your sources directory. The file you want is called something like "openwrt-ar71xx-generic-archer-c7-v2-squashfs-sysupgrade.bin".

4) Get a list of your currently installed packages by eg. copy-pasting them from the Luci software list. Upgrade your device with this file as per https://wiki.openwrt.org/doc/howto/generic.sysupgrade

5) After upgrading, check the currently installed packages on the system and compare them to the list you made earlier. If you're missing something reasonably important-looking, you can just enable it in your build config and rebuild the image, then upgrade to that new image.

6) Try flipping the rfkill switch on the back of the device, it should be working now. In my case the functionality of it is reversed, with the "on" marker actually turning WiFi off and vice versa. Changing this is a matter of fixing the script in /etc/rc.button/rfkill, but it's such a minor non-issue that I didn't bother figuring out how to do that.

Thanks for posting the solution.

Could you please comment if the WiFi button setting is respected on boot? I think I remember reading somewhere that even with the patch, when the router boots up the WiFi is always on, regardless of the button and if you boot the router with the WiFi button off, then switching it to on actually disables WiFi.

Thanks!

stangri wrote:

Thanks for posting the solution.

Could you please comment if the WiFi button setting is respected on boot? I think I remember reading somewhere that even with the patch, when the router boots up the WiFi is always on, regardless of the button and if you boot the router with the WiFi button off, then switching it to on actually disables WiFi.

Thanks!

I can't restart it right now, but when I booted it with the WiFi button in the "on" position (which serves as off in OpenWRT) after patching, it started with WiFi turned on. As I changed the button to the "off" position WiFi stayed on, and when I changed it back to the "on" position it turned off.

Because the functionality is implemented in the rc.button script this makes sense, as the script is only ran when the switch changes positions, and it isn't a toggle script but rather it checks which position the switch is moved into.

(Last edited by burneddi on 18 Jul 2016, 01:10)

The discussion might have continued from here.