I am using A10s board with nand image loaded.
I was trying to control the GPIO via uart0.
The problem i am facing is that, the folder /sys/class/gpio_sw does not contain any files to read or write to.
just to be sure, incase that the echo statement is supposed to create the required files i ran the command
echo 1 > /sys/class/gpio_sw/PE3/mul_sel
this is the reply i got..
sh: cannot create /sys/class/gpio_sw/PE3/mul_sel: No such file or directory
Help would be much appreciated
In an earlier post, I've mentionned that you can control the small green led on gpio :
According to schematic, the LED1 is connected to PE3(gpio21_pe3) and the page http://olimex.wordpress.com/2013/06/19/building-linux-for-a10s-from-scratch/
root@A10s:~# echo out > /sys/class/gpio/gpio21_pe3/direction
root@A10s:~# echo 1 > /sys/class/gpio/gpio21_pe3/value
root@A10s:~# echo 0 > /sys/class/gpio/gpio21_pe3/value
(But this is probably only for the Debian, I'm not sure about Android)
Maybe i should've mentioned. I am using Android 4gb nand image.
The application that i am building needs android.
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.
Ok got the debugger working. I guess the board is set to debug mode by default.
Got adb to find the A10s board, and send shell command over usb-otg.
I am still having problems controlling the GPIO.
Same as before, no files in the /sys/class/gpio_sw folder.
I have been looking online to see if anyone had the same problem.
Found quite a few people with similar problem on some other boards. :D
Found this as the solution
Got into the script.bin, of /dev/block/nanda, using mount and ADB pull
converted the file to fex file, and to my surprise i did not find any gpio_para.
Modified it to have 5 gpio pins (PE01 to PE05). converted the fex file back to .bin, sent it back to /dev/block/nanda
restarted the board, and still nothing. :(
I am starting to think that the modifications i made are incorrect.
Mainly because, i have seen different people having the same problem on different boards, and each had to modify their script.bin file differently. :-\
If anyone has GPIO working through android, could you be kind enough to share the script.bin file.
Thanks in advance. ;D
what does following command gives you "lsmod | grep gpio" ?
On Debian we getting such :
root@A10s:~# lsmod | grep gpio
gpio_sunxi 6767 29
when you tried tweaking your script.fex, Is that syntax look like the one below which comes from my Debian ?
[gpio_para]
gpio_used = 1
gpio_num = 29
gpio_pin_1 = port:PB14<0><default><default><1>
gpio_pin_2 = port:PB13<0><default><default><1>
gpio_pin_3 = port:PB12<0><default><default><1>
...
gpio_pin_29 = port:PE11<0><default><default><1>
[gpio_init]
pin_1 = port:PB14<0><default><default><1>
pin_2 = port:PB13<0><default><default><1>
pin_3 = port:PB12<0><default><default><1>
...
pin_29 = port:PE11<0><default><default><1>
The script.fex that i retrived did not have gpio_para or gopi_init.
I added a similar para and init to it, but with only 5 pins. It did not work, so went ahead searching online for answers.
I found this link which explained how to break open the img file, that had to be flashed into the board.
https://www.miniand.com/wiki/Allwinner/Unpacking+and+building+LiveSuit+images
Found out that the only kernel module with the name gpio in it was gpio_sw.ko.
Then i searched online a little more and found that, the normal kernel module used is sun4i_gpio.ko.
Well i am a noob at linux, android being faaaaar away, so i am trying to figure out what to do next..
Saw the reply just now.
The android image does not have grep, so had to lookup the result of lsmod manually
It has only one GPIO entry
gpio_sw 63245 0 - Live 0xbf0af000
I am hoping that the enrty 29 in your result means number of pins loaded, and my result will give you an idea on how to fix my problem.
Thanks for the reply.
I presume you've already saw this link :
http://olimex.wordpress.com/2013/05/23/a10s-olinuxino-android-gpio-control-led-toggle-app/
So, the question is why you don't see all those pins in /sys/class/gpio_sw/
Maybe it is a question of it needs to be "exported" first as some other people faced with Cubieboard :
http://www.cubieforums.com/index.php/topic,103.0.html
Do you have something like /sys/class/gpio/export ?
Since I also have a Android SDCard, tonight, I will boot it to see how /sys/class look like, and I will keep you posted.
The real question is not why i don't see the pins, but really why i don't see any files what so ever in the gpio_sw folder.
nope.. no /sys/class/gpio folder.
Been reading up on writing kernel modules.
I can't go around using kernel modules compiled for other kernels..
the system does not have modprobe in its bin.. the shell just replies
/system/bin/sh: modprobe: not found
So i searched around to where the kernel modules are stored in the system.. they are present under /vendor/modules
the only module with gpio in its name i see there is gpio_sw.ko
Worst part is i can't compile a kernel module for the system either.
The system does not have make command or gcc for that matter.
thought of cross compiling the module from my computer, but sadly no kernel sources. No clue where to find them as of yet..
Thought of pulling them out of the system, and then using.
Tried searching within the system at /usr/src but there is no /usr folder. :(
I am starting to think that this image was designed only for people developing android apps only. >:(
Well upside being that i am learning aloooot more then i would have other-wise. ;D
ok did aloooooot of learning in the last week.
-learned how to write kernel modules.
-got the source for the kernel within the nand_android_image
-compiled the kernel
-found the gpio_sw source
-modified the gpio_sw to echo out messeges into dmesg
-installed the modified gpio_sw
Here is what i learned at this point
The kernel module could not find the gpio_para within the script.bin
At this point i was totally confused, started thinking that something was wrong with my newely defined script.bin, so i modified the gpio_sw to search for uart_para0, and print to dmesg if found. insmoded the new kernel module and saw the dmesg. The kernel module found the usart_para0. Next thing i did was make a script.bin without the uart_para0 (changed to uart_para5), and put it into the boot partition (usual method).
this time i insmoded the previously compiled kernel module (the one searching for uart_para0), and the dmesg told me that it found the uart_para0
conclusion, for some reason the modifications that i make to script.bin within the bootloader are not being accepted.
to confirm this i pulled out the script.bin from within the boot, and converted it to fex, and to my suprise all the modifications that i had done to it were still there..
Now i am in a totally confused state. By whatever i have found out till now, the script.bin (and script0.bin) within /dev/block/nanda (bootloader partition) is t=not the script that script_parser_fetch() functions reads from.
Now i am trying to mount /dev/block/nandd (The boot partition). But i don't know what filetype it uses . :(
Seriously need help at this point.
Slight correction /dev/block/nandc is the boot partition
ok latest update on my trials.
Got kernel and android sources from here
https://drive.google.com/folderview?id=0B5JCBCiZ1VAKUkVXQXd2LWFweE0&usp=sharing
and tried to compile the android image
failed, then read up online here, about using gcc 4.4 instead
http://blog.markloiseau.com/2012/07/how-to-compile-android-on-ubuntu-12-04/
Succedded in compiling the image, but no dice.
The board does not boot up at all with the image i compiled.
Even if i run it under an emulator, it does not work..
Figured that it is probably a problem with the kernel that i compiled, from the fact that, i am not receiving any debug information over uart0, or uart1.
I need to know exactely what to set in the configs of the kernel, when i use the command
lichee\linux-3.0\$ make ARCH=arm menuconfig.
Please help.
I'm not familiar with the lichee branch, but you may try running
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- (or whatever your cross-compile chains is called) sun5i-defconfig sun5i_defconfig
Fernando
@Xfer: Thanks for the help, but sun5i_defconfig has pre-written configurations, which obviously have not worked.
What i wanted to know, was what configurations to setup, so that it will work.
Fro menuconfig, i can load the sun5i_defconfig, and make changes to it.
But i don't know what changes to make. :(
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.
Fernando
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:
console=ttyS0,115200
root=/dev/mmcblk0p2
loglevel=8
panic=10
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
machid=
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 :
http://olimex.wordpress.com/2013/05/23/a10s-olinuxino-android-gpio-control-led-toggle-app/
So, yesterday, I've spend few time to give it a try, I've made an Android SDcard using the following image :
A10S_ANDROID-SD-CARD-4GB-TOUCHSCREEN-GPIO-HDMI-WIFI-RELEASE-1.rar
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,
Martin
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_para]
gpio_used = 1
gpio_num = 1
gpio_pin_1 = port:PH20<1><default><default><0>
as well as initialize this pin:
[gpio_init]
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
etc
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_para]
gpio_used = 1
gpio_num = 2
gpio_pin_1 = port:PG09<1><default><default><0>
gpio_pin_2 = port:PG10<1><default><default><0>
[gpio_init]
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 https://github.com/linux-sunxi/sunxi-tools.
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_para]
gpio_used = 1
gpio_num = 1
gpio_pin_1 = port:PH20<1><default><default><0>
[gpio_init]
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 (http://linux-sunxi.org/Fex_Guide#.5Bgpio_para.5D) 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