Port PIn Initializations and Default Configuration in Torizon Containers

Hi all,
I am new in Torizon platform but experienced in Yocto oe platform. Now I am developing in Colibri IMX8QXP + Iris v2 Carrier board + Torizon platform.

Basically I want to port an application which is developed with Colibri IMX7D + Iris v2 Carrier board + Yocto OE platform to Colibri IMX8QXP + Iris v2 Carrier board + Torizon platform.

I have done almost everything for it. But I am stucked with two issues:

1) Port Pin Initializations
I have to run a bash script which do port pin initializations: For ex:
#! /bin/bash
sudo chmod 777 /sys/class/gpio
sudo chmod 777 /sys/class/pwm
sudo chmod 777 /sys/class/gpio/export
sudo chmod 777 /sys/class/gpio/unexport
sudo echo 117 > /sys/class/gpio/export
sudo chmod 777 /sys/class/gpio/gpio117/value
sudo chmod 777 /sys/class/gpio/gpio117/direction

For this I created a bindmount -
/home/torizon/Config_Files → /Config_Files
and kept this file in the /home/torizon/Config_Files
and in docker-compose file I added the following command for the corresponding service:
command: bash -c “/Config_Files/pin_init.sh”
This method is finely working. But it is asking for torizon password.
When I try with:
echo “PASSWORD” | sudo -u root --stdin chmod 777 /sys/class/gpio
this is not accepted in debian Container.
Error messages are given below:
[sudo] password for torizon: Sorry, try again.
**lax_cfd_ddu_imx8qxp_no_flash_arm64v8-debian-no-ssh_bullseye_release_019d6325-cb43-40c1-997a-6498cf0d06fc_1 | [sudo] password for torizon: **
lax_cfd_ddu_imx8qxp_no_flash_arm64v8-debian-no-ssh_bullseye_release_019d6325-cb43-40c1-997a-6498cf0d06fc_1 | sudo: no password was provided
lax_cfd_ddu_imx8qxp_no_flash_arm64v8-debian-no-ssh_bullseye_release_019d6325-cb43-40c1-997a-6498cf0d06fc_1 | sudo: 1 incorrect password attempt

This command normally works well in a debian/ubuntu platform. But as I observed it is failing in a debian Conatiner.

In another method I tried to execute this total script from my C code with system() function. Here also password entry is failing.

Is there any special method to execute an initial script with sudo?

2) Default Configuration
I need to add some files which contains default Configuration values for example in
/Config_Files in the debian container.

Definitely I can do it easily by copying these default configuration files from my host system to target torizon system through SSH and copy them in /home/torizon/Config_Files and bindmounting it to /Config_Files.

Is it possible to directly copy this default configuration files to the Image folder, like we do it in case of Yocto/OE image. In Yocto/OE Image, when the root file system is uncompressed, then we will get the total directory strucure of the Target system. We can add/modify what is required and then compress it again. Is similar methods possible with Torizon?
Thanks in advance for the help.

Greetings @sajeevank,

It seems much of your difficulties here are related to the transition from a more traditional Yocto based approach to a Torizon/Containerized one. Out of curiosity if you are very experienced with Yocto then why not stick with a Yocto approach? Is there an aspect of Torizon that you hope to make use of?

As for your issues I have some documentation that may help clarify how to do these tasks in a Torizon workflow:

GPIO/Port initialization:
Here’s our general article on GPIO usage in TorizonCore: How to Use GPIO on TorizonCore | Toradex Developer Center

Some things to note:

  • I notice before you are using the sysfs interface to interact with GPIOs, this is a older deprecated method. The article I linked used libgpiod instead. You can in theory still use sysfs, but it’s unknown how well this works in a container to be honest.
  • I notice you’re trying to use sudo, in a container as well. One thing to note is that the torizon user inside the container is not the same as the torizon user outside of the container on the host OS. Therefore running sudo would fail since they don’t share the same password. In fact the torizon user inside the container is passwordless. The article I linked should show how to setup permissions for GPIO access without having to use sudo.

Default Configuration:
TorizonCore itself is still a Yocto built distribution: Build TorizonCore from Source With Yocto Project/OpenEmbedded | Toradex Developer Center
Meaning you can still do add your config related files that way if you so choose.

However, the way we typically recommend is by using our TorizonCore Builder tool: TorizonCore Builder Tool - Customizing TorizonCore Images | Toradex Developer Center
Which lets you perform such smaller customization of the OS without having to go through Yocto
In particular for adding configurations to an image by default you want to look at this article: Capturing Changes in the Configuration of a Board on TorizonCore | Toradex Developer Center

Take a look at those articles I’ve linked here and let me know if you have further questions.

Best Regards,

1 Like

Hi Jeremias,

Thank You very much for the detailed reply.
I think the link Capturing Changes in the Configuration of a Board on TorizonCore | Toradex Developer Center referred by You would, solve many of the issues that I am facing.
I have been testing as per the procedure in it. But at some points I am stuck for a while. So I couldn’t complete the testing.
I would give feedback tomorrow, when the testing is over.

Definitely please let me know how this works out for you. I’d be happy to clarify any questions or issues you might be having.

Best Regards,

Hi Jeremias,

Among the two problems I faced, the second problem, I could solve by following the procedure in the link Capturing Changes in the Configuration of a Board on TorizonCore | Toradex Developer Center.
I need to keep the folder Config_Files in /etc instead of /home/torizon.
On first boot with the original image, I need to copy the configuration files to /etc/Config_Files folder from the Host Ubuntu system.
And then with torizonecore builder isolate command capture the changes. Modify the tcbuild.yaml, to inlcude the captured changes and build the image second time.
With this the second issue is solved.

The torizonecore builder isolate command capture only the changes in /etc folder of Torizon OS image.
For port pin configuration, we need to change the access permission of /sys/class/gpio and other folders/files within it.
I think, capturing chnages in /sys/class/gpio is not possible.

So I think I have to drop the method of SYSFS and use libgpiod - Anyway SYSFS is deprecated method.
So by using libgpiod, the first problem also can be solved.
Thank You Very much for the support.

Glad I was able to help clarify things.

Best Regards,