OpenWrt Forum Archive

Topic: [python] RuntimeError: No access to /dev/mem.

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

Dear,

I have tried to run python script but I have encountered a problem:

root@OpenWrt:~# python lcd3.py
Traceback (most recent call last):
  File "lcd3.py", line 70, in <module>
    lcd = HD44780()
  File "lcd3.py", line 15, in __init__
    GPIO.setup(self.pin_e, GPIO.OUT)
RuntimeError: No access to /dev/mem.  Try running as root!

Unfortunately /dev/mem does not exist. Could you please help?

Any ideas?

kb06 wrote:

Any ideas?

Firstly, what architecture are you targeting. Some architectures have the kernel symbol CONFIG_DEVMEM defined, some don't. If it's not defined, the device node won't exist. For example, my x86_64 router has a /dev/mem, however my WRT1200AC does not, because the kernel config option is not enabled. If it's not enabled, you'll need to create a new kernel with the relevant config option enabled.

Moving beyond the basics (lack of a CONFIG_DEVMEM=y in the kernel config is almost certainly why /dev/mem does not exist), why are you trying to write directly to /dev/mem? This is a pretty dangerous thing to do unless you know exactly what you're doing.

On devices with CONFIG_DEVMEM enabled, OpenWrt kernel is compiled with CONFIG_STRICT_DEVMEM. Quoting directly from the manpage

Since Linux 2.6.26, and depending on the architecture, the
CONFIG_STRICT_DEVMEM kernel configuration option limits the areas
which can be accessed through this file.  For example: on x86, RAM
access is not allowed but accessing memory-mapped PCI regions is.

So even if it IS enabled, you may not be able to write to it in the way you desire.

Thank you for your response.
I try to run Python module RPi.GPIO (https://pypi.python.org/pypi/RPi.GPIO) on Raspberry Pi with OpenWRT from trunk.
RPi.GPIO has been installed using setup.py script, everything works fine until I run script.
The goal is to use HD44780 alphanumeric LCD connected to RPi's GPIO.

I will try with rebuilding kernel for my OpenWRT on RPi. Could you tell if I can do it using make menuconfig?

Do you know where this option is in make kernel_menuconfig ?

kb06 wrote:

Do you know where this option is in make kernel_menuconfig ?

An easy way to find where a symbol is located in the menuconfig hierarchy is, fro the source directory

 find . -name Kconfig | xargs grep DEVMEM
./drivers/char/Kconfig:config DEVMEM

So, as you can see, CONFIG_DEVMEM is under Device Drivers-->Character Devices

The discussion might have continued from here.