UART kernel module

We are evaluating if we can migrate our devices from raspbian to resinOS.

We got resinOS running on our CM3 based device, the last open task is porting our kernel module.
The problem is that it needs to replace /dev/ttyAMA0 (uart-pl011 driver) because we need to access this UART directly and uart-pl011 is not a module but built-in.

We have 2 different ways to map the UART I/O addresses into kernel space.

Method 1:
This method re-uses the existing ioremap() from the uart-pl011 driver
(which is the original /dev/ttyAMA0 driver after reboot).

Method 2:
This method creates its own ioremap() from the uart-pl011 driver and then removes the ioremap() from the uart-pl011 driver by unbinding the driver

In both methods shall /dev/ttyAMA0 not be removed, but shall instead renamed to e.g. /dev/NO-ttyAMA0. This is to prevent accidental use of /dev/ttyAMA0.

Method 1:

  • rename /dev/ttyAMA0 to /dev/NO-ttyAMA0.
  • determine the virtual address, say VIRT_ADDR, of the existing mapping by analyzing /proc/vmallocinfo.
  • insmod the elmos.ko module with module parameter membase="$VIRT_ADDR"

Method 2:

  • rename /dev/ttyAMA0 to /dev/NO-ttyAMA0.
  • insmod the elmos.ko module without module parameter membase. The module
    parameter membase can still be given but will have no effect since it is
    being overridden in the code line below.
  • unbind the uart-pl011 driver (which removes the ioremap() installed by it.
    It is important to unbind the driver AFTER the elmos.ko has installed its
    own ioremap().

How can this be done in resionOS.

Hi Seb,

I’m going to check with the OS team and see if they can offer you any guidance with this. In the meantime, you may find this repository a useful reference.

Hello Will,

I know that repo and I can successfully build the hello-world kernel module.

Before just using our raspbian approach on resinOS I wanted to check with you, if you allow that or may see a better solution. It’s just a little tricky to use the hardware thats occupied by a built-in driver.

thanks for your help


Hi Sebastian,
I am not aware of an explicit need to have it built in. We could switch it to a module instead

I don’t know why its built-in, its just how its done in raspbian. The colleague responsible for the kernel module is out of office until next week. I’ll discuss that with him and we’ll get back to you.

Hi @seb,

did you manage to talk with your colleague responsible for the kernel module?