From 29f1adc1d304393fb62327145d475d3a3c0e87ab Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 5 Feb 2024 09:11:12 +0100 Subject: [PATCH] openwrt: Raspberry PI gpiomem fix --- hcxdumptool.c | 52 +++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/hcxdumptool.c b/hcxdumptool.c index c4f27bd19..4de7cf6d2 100644 --- a/hcxdumptool.c +++ b/hcxdumptool.c @@ -4530,7 +4530,7 @@ if((modinfo = fopen("/proc/device-tree/model", "r")) == NULL) len = fgetline(modinfo, RASPBERRY_INFO, linein); fclose(modinfo); if(len < RPINAME_SIZE) return false; -if(memcmp(&rpiname, &linein, RPINAME_SIZE) != 0) return false; +if(memcmp(rpiname, linein, RPINAME_SIZE) != 0) return false; if((procinfo = fopen("/proc/cpuinfo", "r")) != NULL) { while(1) @@ -4546,37 +4546,37 @@ if((procinfo = fopen("/proc/cpuinfo", "r")) != NULL) } fclose(procinfo); } -if((procinfo = fopen("/proc/iomem", "r")) != NULL) +if((fd_devinfo = open("/dev/gpiomem", O_RDWR | O_SYNC)) > 0) { - while(1) + gpio_map = mmap(NULL, RPI_BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd_devinfo, gpioperibase); + close(fd_devinfo); + } +else + { + if((procinfo = fopen("/proc/iomem", "r")) != NULL) { - if((len = fgetline(procinfo, RASPBERRY_INFO, linein)) == -1) break; - if(strstr(linein, ".gpio") != NULL) + while(1) { - if(linein[8] != '-') break; + if((len = fgetline(procinfo, RASPBERRY_INFO, linein)) == -1) break; + if(strstr(linein, ".gpio") != NULL) { - linein[8] = 0; - gpioperibase = strtoul(linein, NULL, 16); - break; + if(linein[8] != '-') break; + { + linein[8] = 0; + gpioperibase = strtoul(linein, NULL, 16); + if(gpioperibase != 0) + { + if((fd_devinfo = open("/dev/mem", O_RDWR | O_SYNC)) > 0) + { + gpio_map = mmap(NULL, RPI_BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd_devinfo, gpioperibase); + close(fd_devinfo); + } + } + break; + } } } - } - fclose(procinfo); - } -if(gpioperibase != 0) - { - if((fd_devinfo = open("/dev/mem", O_RDWR | O_SYNC)) > 0) - { - gpio_map = mmap(NULL, RPI_BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd_devinfo, gpioperibase); - close(fd_devinfo); - } - } -else - { - if((fd_devinfo = open("/dev/gpiomem", O_RDWR | O_SYNC)) > 0) - { - gpio_map = mmap(NULL, RPI_BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd_devinfo, gpioperibase); - close(fd_devinfo); + fclose(procinfo); } } if(gpio_map == MAP_FAILED)