GPIO help

Started by Vinayakj70423, July 21, 2013, 05:11:04 PM

Previous topic - Next topic


Are you really sure that the problem lies in kernel configuration?

A straight build from sux5i_defconfig should at least boot, then maybe could not load some module etc., but should at least partially boot.
Maybe the problem lies in the initialization scripts?
I don't know about Android, but Linux needs initializations scripts, like script.bin and uEnv.txt, which make do for the lack of BIOS.
Some parameters in those scripts change from kernel to kernel (machid and such), so if, for example, you are using scripts from kernel 3.0 or 3.3 with kernel 3.4, they may not work and cause the kernel not to boot at all.

Just an idea.



ok i know about script.bin, changing that is not helping. what is uEnv.txt? not sure i have come across that in the source code..


uEnv.txt has been introduced in kernel 3.3 I think.
It's in boot partition, alongside script.bin and uImage.
It's an initialization file, kind of provides kernel parameter options.

For example, this is mine:


because my root partition is the second partition in the microSD card

Now if you use kernel 3.4, you need to specify your board ID, as the first line in uEnv.txt.
The parameter is
and you need to specify the ID of your board (I don't know, I have an A20).

All that said: recently I had a strange issue with my recompiled kernel.
It would not show anything on the HDMI screen.
So I assumed it did not boot. But it actually booted: just no HDMI output. So using ssh to login from network, it worked OK. Did you try that?


not using any display.
using ADB over usb otg.. Android does not have sshd installed.

And booting from nand.

But i did not see any uEnv.txt in the boot partition..


I have the same problem with cubieboard.
I edited the script.bin and added some gpios and leds in [gpio_para] and [leds_para] but in /sys/class/gpio_sw I still have the PB3, PH10, and PH20 folders.

I tried to change the value of /sys/class/gpio_sw/PH20/data and I can control the green led.
But none of these 3 pins are the pins I defined in script.bin, so where the module gpio_sw will get these pins?

The pins could be defined in the gpio_sw.ko?


Hi Vinayakj,

Back to you original question, if you remember my earlier answer, I was mentionning this link :

So, yesterday, I've spend few time to give it a try, I've made an Android SDcard using the following image :


And using Debug serial port, I've been able to toggle green led using those command:

echo 1 > /sys/class/gpio_sw/PE3/mul_sel
echo 1 > /sys/class/gpio_sw/PE3/data
echo 0 > /sys/class/gpio_sw/PE3/data

So, if you still wish to work with Android, maybe it should be easier to start again by using this image. although it is not an HDMI version, but it should be easy to switch it back to HDMI.

Hope this help,


Just some help to those who still were not able to control GPIO pins:

You should modify script.bin file and add/edit etc, for example:


gpio_used                = 1
gpio_num                 = 1
gpio_pin_1               = port:PH20<1><default><default><0>

as well as initialize this pin:


pin_2                    = port:PH20<1><default><default><1>

Now you will see it under the /sys/class/gpio_sw/ directory. Like it was already mentioned one can control those pins by these commands:

echo 1 > /sys/class/gpio_sw/PH20/mul_sel
echo 1 > /sys/class/gpio_sw/PH20/data
echo 0 > /sys/class/gpio_sw/PH20/data



I think there are some typos in this example, but even with them corrected I can't see anything under /sys/class/gpio_sw on my A10s-4GB board running Android.  Here's what I've done...

1) download script.bin from board

Connect board to Macbook using USB-OTG port
$ adb devices
$ adb connect
$ adb shell
# mkdir /mnt/bootloader
# mount -t vfat /dev/block/nanda /mnt/bootloader
# logout
$ adb pull /mnt/bootloader/script.bin

2) modify script.bin

$ bin2fex script.bin script.fex

edit script.fex and add this:-

gpio_used = 1
gpio_num = 2
gpio_pin_1 = port:PG09<1><default><default><0>
gpio_pin_2 = port:PG10<1><default><default><0>

pin_1 = port:PG09<1><default><default><0>
pin_2 = port:PG10<1><default><default><0>

I'm using PG09 and PG10 because I want to use the UART-3 pins in the GPIO-1 block (pins 3 and 4).

$ fex2bin script.fex script.bin

I built fex2bin and bin2fex from

3) Upload modified script.bin to A10s board and reboot

$ adb push script.bin /mnt/bootloader/script.bin
$ adb shell
# sync
# sync
# reboot

After reboot my /sys/class/gpio_sw directory is still empty.  I also tried a corrected version of the example given by the previous poster:-

gpio_used = 1
gpio_num = 1
gpio_pin_1 = port:PH20<1><default><default><0>

pin_1 = port:PH20<1><default><default><0>

That's exactly what I've been doing.  Can anyone please point out what I'm missing?

One other problem I have is that the Fex Guide ( doesn't say what the <1> and <0> in the above example mean.  I've also seen some examples with <0> at the first parameter and <default> as the last.  Any ideas?


"And in the filesystem i have found that /sys/class does not have a gpio folder.
It has gpio_sw folder, which does not have any files within it."

You have to config your kernel. The kernel needs to have the relevant modules selected.

cd lichee/linux-X-XX
make linux-menuconfig
select Device Drivers

select GPIO Support  (Line no 26 in linux-3.0)
Go inside and select all that you would like.

exit to the previous page.
at the bottom (last line) you have the GPIO_SW support.
deselect GPIO_SW support (if you dont need it)

save your config.
rebuild the kernel from there or from the buildroot (make linux-kernel) or from the lichee