Menu

#161 aarch64: Add kernel detection support

Done
None
Medium
Enhancement
2021-04-12
2018-08-04
No

Hi!

I just tried an aarch64 kernel on a RasPi 3 B+ (booted Devuan "ASCII"), and found that "This module can only be run on a Raspberry Pi!", because in aarch64, the "Hardware" and "Revision" aren't any longer in /proc/cpuinfo.

Similar information can be obtained:

root@astroreader:/proc/device-tree/system# cat linux,serial |xxd
00000000: 0000 0000 6d1e 9c7d ....m..}

root@astroreader:/proc/device-tree/system# cat linux,revision |xxd
00000000: 00a0 20d3 .. .

root@astroreader:/proc/device-tree# cat model
Raspberry Pi 3 Model B Plus Rev 1.3

root@astroreader:/proc/device-tree# cat serial-number
000000006d1e9c7d

The very same information cat be obtained from a genuine Raspbian kernel / installation.

Discussion

  • Jan-Benedict Glaw

    I hacked in an (inproper) quick patch:

    diff --git a/source/cpuinfo.c b/source/cpuinfo.c
    index b1db08d..b0864ec 100644
    --- a/source/cpuinfo.c
    +++ b/source/cpuinfo.c
    @@ -27,6 +27,13 @@ SOFTWARE.
    
     int get_rpi_info(rpi_info *info)
     {
    +#if 1
    +       info->type              = "Pi 3 Model B";
    +       info->processor         = "BCM2835";
    +       info->p1_revision       = 3;
    +       info->manufacturer      = "Sony";
    +       info->ram               = "1024M";
    +#else
        FILE *fp;
        char buffer[1024];
        char hardware[1024];
    @@ -187,6 +194,7 @@ int get_rpi_info(rpi_info *info)
              info->p1_revision = 3;
           }
        }
    +#endif
        return 0;
     }
    

    (didn't check manufacturer) and this makes GPIO useable for my usage case: check 3 GPIO pins for events (three simple buttons attached.) Though there are some warnings while building it:

    root@astroreader:~/raspberry-gpio-python-code# python3 setup.py build
    running build
    running build_py
    running build_ext
    building 'RPi._GPIO' extension
    aarch64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-kWxB2e/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -c source/py_gpio.c -o build/temp.linux-aarch64-3.5/source/py_gpio.o
    aarch64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-kWxB2e/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -c source/c_gpio.c -o build/temp.linux-aarch64-3.5/source/c_gpio.o
    source/c_gpio.c: In function ‘setup’:
    source/c_gpio.c:76:13: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
             if ((uint32_t)gpio_map < 0) {
                 ^
    source/c_gpio.c:125:9: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
         if ((uint32_t)gpio_mem % PAGE_SIZE)
             ^
    source/c_gpio.c:126:34: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
             gpio_mem += PAGE_SIZE - ((uint32_t)gpio_mem % PAGE_SIZE);
                                      ^
    source/c_gpio.c:130:9: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
         if ((uint32_t)gpio_map < 0)
             ^
    source/c_gpio.c:99:13: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
                 fgets(buffer, sizeof(buffer), fp);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    source/c_gpio.c:64:14: warning: ‘peri_base’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         uint32_t peri_base;
                  ^~~~~~~~~
    aarch64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-kWxB2e/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -c source/cpuinfo.c -o build/temp.linux-aarch64-3.5/source/cpuinfo.o
    aarch64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-kWxB2e/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -c source/event_gpio.c -o build/temp.linux-aarch64-3.5/source/event_gpio.o
    source/event_gpio.c: In function ‘gpio_export’:
    source/event_gpio.c:76:5: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
         write(fd, str_gpio, len);
         ^~~~~~~~~~~~~~~~~~~~~~~~
    source/event_gpio.c: In function ‘gpio_unexport’:
    source/event_gpio.c:91:5: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
         write(fd, str_gpio, len);
         ^~~~~~~~~~~~~~~~~~~~~~~~
    source/event_gpio.c: In function ‘gpio_set_direction’:
    source/event_gpio.c:118:9: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
             write(fd, "in", 3);
             ^~~~~~~~~~~~~~~~~~
    source/event_gpio.c:120:9: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
             write(fd, "out", 4);
             ^~~~~~~~~~~~~~~~~~~
    source/event_gpio.c: In function ‘gpio_set_edge’:
    source/event_gpio.c:136:5: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
         write(fd, stredge[edge], strlen(stredge[edge]) + 1);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    aarch64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-kWxB2e/python3.tor-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -c source/soft_pwm.c -o bui5/source/soft_pwm.o
    aarch64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-kWxB2e/python3.tor-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -c source/py_pwm.c -o buildsource/py_pwm.o
    aarch64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-kWxB2e/python3.tor-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -c source/common.c -o buildsource/common.o
    aarch64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-kWxB2e/python3.tor-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -c source/constants.c -o bu.5/source/constants.o
    aarch64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,relro -g -fdebug-prefix-map=/build/python3.=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-aarch64-3.5/source/py_gpich64-3.5/source/c_gpio.o build/temp.linux-aarch64-3.5/source/cpuinfo.o build/temp.linux-aarch64-3.5/source/event_gpio.o build/temp.linut_pwm.o build/temp.linux-aarch64-3.5/source/py_pwm.o build/temp.linux-aarch64-3.5/source/common.o build/temp.linux-aarch64-3.5/source/clinux-aarch64-3.5/RPi/_GPIO.cpython-35m-aarch64-linux-gnu.so
    
     
  • Jan-Benedict Glaw

    Is this Python module still maintained? I'd quite like to work on this. Maybe by just letting the code call a wrapper function that first tries the "old" method and then tries the generic aarch64 locations to gain the needed information?

     
    • Ben Croston

      Ben Croston - 2018-08-27

      The project is still maintained but doesn't get much attention any more. If you produce a patch for this issue, I will happily include it to the module.

      A new release is probably due soon to include a few miscellaneous patches.

       
  • Dave Jones

    Dave Jones - 2019-01-22

    Hi Ben - just attaching a patch for this. It gives priority to /proc/device-tree/system/linux,revision as this appears to be available on all distros now (including Raspbian), but still contains a fallback to the classic /proc/cpuinfo in order to continue supporting older releases that don't have /proc/device-tree.

     
  • Ben Croston

    Ben Croston - 2019-03-16

    The patch has been included and modified because it broke the detection of early boards. Could you please test the latest development copy on aarch64 and confirm that it works.
    The commands to install it will be something along the lines of:
    $ sudo apt install mercurial
    $ pip3 install --upgrade hg+http://hg.code.sf.net/p/raspberry-gpio-python/code#egg=RPi.GPIO

     
    • Dave Jones

      Dave Jones - 2019-03-18

      Brilliant, thanks Ben. Sorry about the old board detection - I should've used "%04x" in the sprintf call to match the old format. Anyway, I'll give this a whirl today.

       
      • Dave Jones

        Dave Jones - 2019-03-18

        Tested on a Pi 3B under aarch64; works nicely - many thanks!

         
  • Ben Croston

    Ben Croston - 2019-07-21
    • status: New --> Done
    • assigned_to: Ben Croston
     
  • Ben Croston

    Ben Croston - 2019-07-21

    In release 0.7.0

     
  • Shamkin Roman Alexandrovich

    Ben thanks, that all right!

     

    Last edit: Shamkin Roman Alexandrovich 2021-04-12

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.