Accessing IO memory from a Docker container

Hi all,

In my quest to use the GPT1 timer on my colibri i.MX7 module, I am looking at accessing its registers which are located (according to the NPX doc and the device tree) at 0x302d0000 and beyond.
Access is required from an application that I write with Visual Studio Code with the Torizon extension.

I’ve been looking at several examples from e.g. Toradex kernel code and I also found a method using /dev/mem and mmap().

The first one was suggested by jeremias.tx (in another post regarding GPT1) and is rather informative but this example does not compile in my application due to the #includes, I probably need to install an SDK etc. And there is perhaps also a problem with the fact that running within a container shields the application from the ‘real’ memory ? (like it is for e.g. TCP/UDP ports).

The second method seems feasible except that one needs to be root in order to open /dev/mem.
So my immediate question is:
How can I make my application/container execute as root ?

In a broader perspective, any kind of suggestion of how to read/write I/O registers from my application would be welcomed…

Best regards

Jeroen

Greetings @ompie,

How can I make my application/container execute as root ?

For our extension when you create a project it asks for a username. This username is the user that is used inside the container at runtime. You can change this via the username field in the configuration.

Best Regards,
Jeremias

Thanks @jeremias.tx,

Sometimes things are so easy :slight_smile:
However, even being root I could still not open /dev/mem. While googling, there seem to be further restrictions in order to avoid user programs having access to the physical memory. So this is probably not the way to go when I want to access I/O.
Any suggestions on how to do that another way would be welcome !

Another question concerning the change of user for the container : changing from ‘torizon’ to ‘root’ did work because they have the same password. But I was wondering where the password could be changed. When you create a new application, it asks for both user name and password but I could only find a ‘user name’ field in the Torizon extension once the application is already configured.

Best regards,

Jeroen

Another question concerning the change of user for the container : changing from ‘torizon’ to ‘root’ did work because they have the same password. But I was wondering where the password could be changed. When you create a new application, it asks for both user name and password but I could only find a ‘user name’ field in the Torizon extension once the application is already configured.

One thing to understand is that the user in the container is separate from the user outside of the container.

Inside the container the torizon and root user are password-less. These users are different from torizon and root` outside of the container.

Furthermore when you create a project with the extension only a username is required. This username being what user to use inside the container. Are you perhaps talking about the username/password required when adding a device? This username/password is for accessing the device via SSH, and is unrelated to your project and container.

Best Regards,
Jeremias

OK, so what could I do so that my application that runs inside the container has sufficient rights to open /dev/mem of the actual machine ?
(I did add /dev/mem to the “devices” list in the Torizon extension)

Yes, that’s probably the one…

Meanwhile, it is very well possible that this way, trying to use /dev/mem, is a dead end due to possible other restrictions for its use as I mentioned earlier. So any suggestions for other way to access the GTP register are still welcome…

Thanks,
Jeroen

Hi @ompie,

Can you please give us more details on your use case so that we can understand if there could be any alternatives for GPT that you could use. If you cans share as much information as possible from what you’re trying to achieve this would be great :smiley:

Thanks a lot,

Hi @gclaudino.tx,

I need to use GPT0 in order to divide an external clock (4MHz) to a lower frequency which is then output on a pin. This output signal is then used to start ADC conversions (at e.g. 100kHz) that are handled by the M4 core (another subject I did not yet fully explore :slight_smile: ). The fact to use the external source is important since the sampling time shall be related to this 4MHz signal that is used to modulate a signal that is sampled afterwards (the details are a bit complicated…)
As per I/O mux of the Colibri i.MX7D, SODIMM pin 60 is dedicated to GPT1.CLK and pin 93 is GPT1.COMPARE. I already “liberated” these pins from the standard function by modifying the device tree (see my post GPT1 )

Although nothing is fixed, I already have our custom motherboard on my desk, i.e. it will not be easy to re-map the 4MHz input and frequency programmable output signals to other SODIMM pins.

So far, I have been looking at different snippets of code which often appear to come from kernel source and require specific #includes which I do not have.
One of my other fears is that GPT1 is already used by the Linux kernel itself but I do not have the faintest idea of how to find this out. The only thing I know is that in the Colibri device tree, there are definitions for gpt1 … gpt4 in imx7s.dtsi and gpt1 is the only one that does not have the line status = "disabled".
For me this either means that it already should appear as a device under Linux or that it is reserved.

I have also tried to find a definition for the device tree syntax concerning gpt. How do you specify that the CLK and COMPARE pins mentioned above are associated with the device ?

Hopefully this information will give you some better idea of what I want to achieve…

Best regards,
Jeroen

Hi @ompie,

Thanks for the update and clarification.

You mention that you modified your device tree but you didn’t share with us the files. Would you be able to share it with us? You can use share.toradex.com to upload them if needed.


Can you also please share with us the output of the following commands?

  • dmesg
  • zcat /proc/config.gz

You can save the output of these commands as text files and then upload them together with the device tree.

Usually, it’s done when you define the nodes on the device tree. We’ll have a look on what you’ve done and suggest modifications if we think it might be necessary.

Best regards,

Hi @gclaudino.tx,

I uploaded both the device tree files and the output of the two commands you asked for
here.

The starting point of the device tree is the file imx7d-colibri-emmc-interferometer.dts. This will then include the other ones (maybe there are files which are not used but I think I pretty well limited the files to the minimum set). Any other file which is usually outside the dts-arm32 folder has not been modified are are identical to the one in the toradex Git repository.

Thanks in advance for having a look at them !

Jeroen

1 Like

Hi @gclaudino.tx,

Did you get any further with my device tree and how to use/control the GPT1 timer ?

Thanks,

Jeroen

Hi @ompie !

Sorry for the delay. I couldn’t test them properly yet. We’ll get back to you early next week.

Best regards,

OK no problem !