How to enable GPIO pins permanently

Hello,
In my work, I enabled two pins in the J21 connector as output.
This is my script:

sudo -s
echo 255 > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio255/direction
chmod +w /sys/class/gpio/gpio255/value
exit

Questions:

  1. I cannot just run this script in the terminal. The system is showing “… Permission denied” for each line.
    But everything works well if I run each command separately.
  2. When I restart my Tegra I should always run these commands again. How can I enable this pins constantly?

Thank you

hello igor.fedorov,

may I know which GPIO pin you would like to control.
please access Jetson TX2 Platform Adaptation and Bring-Up Guide via download center.
you should check [GPIO Changes] session for the formula of the gpio number calculation,
you might also checking kernel message about the allocation range.

please also refer to documentation, Jetson TX2 Pinmux and GPIO Configuration.
we usually have customize pinmux spreadsheet to have pinmux and gpio configuration.
thanks

Hello,
I would like to control gpio255 (GPIO_GEN3) according to this NVIDIA Jetson TX2 J21 Header Pinout
https://www.jetsonhacks.com/nvidia-jetson-tx2-j21-header-pinout/
This pin I can enable or unenable when my program is running. The problem when I reboot Tegra this pin configuration is not saved.

Hello,

I think I solved the problem.

I typed this command into rc.local

nvidia@tegra-ubuntu:~$ sudo su
root@tegra-ubuntu:/home/nvidia# nano /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/home/nvidia/jetson_clocks.sh&
./home/nvidia/DALSA/GigeV/tools/GigeDeviceStatus/GigeDeviceStatus&

#/home/nvidia/myscripts.sh

echo 255 > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio255/direction
chmod +w /sys/class/gpio/gpio255/value

echo 254 > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio254/direction
chmod +w /sys/class/gpio/gpio254/value

exit 0

Now, I dont need to enable pins again after rebooting.

Glad to know issue resolved, thanks for the update.