Android sys_config customization and peripherals

Hi,

I’m using Android on the M3 so that I can use the hardware acceleration for jpeg decoding and all the good stuff that we can’t yet access on Linux.

I made 2 “peripherals” with a small uC that send data via serial via a board mounted on the GPIO pins. The banana having only one USART port available by default on the GPIOs, I managed to use USART 3 on Linux (GPIO pin 31/33), but I can’t manage to find a way to do it on Android.

In the same fashion that I did it on Linux, and in the same way it’s done on some allwinner-based boards to modify things like the default resolution and such, I should be able to just modify the sys_config.fex file (obtained by extracting the .img android system image using tools like imgRepacker), and repack it with that same tool. While I got no error when doing this, and my modifications to the file being correctly extracted if I unpack/repack the image, it seems to have no influence on the system once flashed.

Is there a special way / tool to edit that sys_config.fex, or a similar file that I’m not aware of to make the system take my modifications into account ? Is there something special to do with the Bpi ?

If anyone managed to change the default GPIO function on android, I’d be interested : ).

Thanks,

It should be the same as outlined here for H3, they use nearly the same BSP. To get the ‘SDK’ grab SinoVoip’s M3 BSP and make your modifications in the right place.

1 Like

Thanks a lot ! That’s great, it did the trick :).

So, for anyone having the same problem that I had, modifying only the sys_config with a fex2bin pass in the “extracted” img and then rebuild it is not enough. You also need to update the boot0_sdcard.fex file as it seems to pack the sys_config and other stuff (I did copy the other files, but it may not be necessary).

Hello kailokyra

I’m also using Android on the M3 and want to use the UART’s of the GPIO can you tell me step by step what you did to get it to work on your setup maybe I could use it for my setup also i want to hookup a gps using the UART’s

Hi,

Step by step it would be something like :

  • Clone SinoVoip’s M3 BSP on their github ( https://github.com/BPI-SINOVOIP/BPI-M3-bsp )

  • Clone and compile sunxi-tools (in fact, you just need fex2bin) on the sunxi github ( http://linux-sunxi.org/Sunxi-tools )

  • Get imagerepacker 2.05 ( http://forum.xda-developers.com/showthread.php?t=1753473 )

  • Get LiveSuit ( http://linux-sunxi.org/LiveSuit#Debian.2FUbuntu )

  • Extract the android image file for BPI M3 (.img) with imgRepacker

  • Now that you have all that, build uboot by running the build script at the root of the bsp repo

  • go in the sunxi-pack folder and do :

  • edit the chips/sun8iw6p1/configs/BPI_M3_1080P/sys_config.fex file (or in any other BPI_M3_x folder, there’s 4 of them). Here, you need to go to the uart configuration section. The different options are self-explanatory so just set “used = 1” to the uart 2 / 3, with the correct number of wires as you wish.

  • Note that you have the port mapping, with the multiplexed function selected ect in the form “port:PB00< mux_function >”. (0 for GPIO input, 1 for output, function definitions on this link Banana pi BPI-M3 GPIO define starting from 2 to 7)

  • You have to remove the GPIO pin “device” corresponding to every pin used by a peripheral (so for UART 2, remove the line using PB00 and PB01 in the “gpio configuration” section.

Now that it’s done, You’ll need to execute something in this fashion in the sunxi-pack directory (replace with your own paths) :

mkdir out cp chips/sun8iw6p1/configs/BPI_M3_1080P/sys_config.fex out/sys_config.fex cp chips/sun8iw6p1/bin/boot0_sdcard_sun8iw6p1.bin out/boot0_sdcard.fex perl -i -p -e ‘s|[\r\n]+|\r\n|g’ out/sys_config.fex pctools/linux/mod_update/script out/sys_config.fex …/…/sunxi-tools/fex2bin out/sys_config.fex out/sys_config.bin pctools/linux/mod_update/update_boot0 out/boot0_sdcard.fex out/sys_config.bin SDMMC_CARD cp chips/sun8iw6p1/bin/u-boot-sun8iw6p1.bin out/u-boot.fex pctools/linux/mod_update/update_uboot out/u-boot.fex out/sys_config.bin cp out/* ~/BPI-M3_Android_HDMI_V2.img.dump/ cd ~/BPI-M3_Android_HDMI_V2.img.dump/ mv sys_config.bin config.fex cd ~ ./imgrepacker ~/BPI-M3_Android_HDMI_V2.img.dump

And, tada ! You got yourself a modified android image, ready to be flashed with Livesuite !

Hooking up a gps is straightforward if it’s a simple GPS module with a serial input/output. I know that there’s also a section in the .fex concerning a gps, but I don’t know more about it : )

4 Likes

Question 1:what this "…/…/sunxi-tools/fex2bin out/sys_config.fex out/sys_config.bin " mean? Question 2:what this “pctools/linux/mod_update/update_boot0 out/boot0_sdcard.fex out/sys_config.bin SDMMC_CARD” mean? especially the SDMMC_CARD? hope for your answer,thank you.

For your first question, it’s the sunxi-tools utilities that you have to get on https://github.com/linux-sunxi/sunxi-tools and compile it. Then it’s just passing sys_config.fex to the fex2bin so that it outputs a sys_config.bin.

For your second question, it’s an utility that you can find in the pctools/linux/mod_update folder in the bsp. you have to pass the path to the boot0.fex file and the sys_config.bin. I guess the SDMMC_CARD parameter is to specify that you want the boot mode to be set on SD/MMC, (I’m not certain of that, it’s just a supposition, so take that as is. It just happen that the other one didn’t work :slight_smile: )

Thank you, kailokyra ! Also i have some questions,hope for you answer. question 1:“cp out/* ~/BPI-M3_Android_HDMI_V2.img.dump/” this meas copy the file out to the xxx.img.dump? The file “out” keep the state of file in the xxx.img.dump?
question 2:“cd ~/BPI-M3_Android_HDMI_V2.img.dump/ mv sys_config.bin config.fex” these two command meas open the file of xxx.img.dump and move sys_config.bin config.fex?

Change the sys_config will help me add the GPS module to the GPIO pins? Thank you once again!

For your first question, the “out” and “BPI-M3_Android_HDMI_V2.img.dump” are not simple files, they are folders. It’s just doing a copy of everything that is in the folder “out/” into the folder “BPI-M3_Android_HDMI_V2.img.dump/”. It may replace some files, but it’s fine because you need them to be replaced anyway.

For your second question, it means "change the current directory to “BPI-M3_Android_HDMI_V2.img.dump/”, then replace the file named “config.fex” by the file “sys_config.bin”. (or copy over).

:slight_smile:

Regarding the use of the GPS, it may be useful to edit the sys_config if your module outputs its data via a serial link, because you’ll be able to use the UART 2 and 3 (but for the uart 0, you have to edit the bootloader command line, which may not be possible with this android image without recompiling).

To be able to open the serial port in a program not ran via adb (via the launcher for exemple), you may also need to add/change the permissions of the /dev/ttySx (0777), somewhere in an uevent*.d* file if the sources were available, but maybe there’s a file you can change somewhere to do the same thing, I don’t know.

Thank you for you help! Follow your step,i make a new img file,my GPS module is added to the uart2, i make a APP(write by myself),but i can’t accept the data. Could give me some advice?

By “can’t accept the data”, do you mean that you don’t receive anything when you should or that the data you get is wrong ? If it’s just garbled data, you may look into setting the right serial port configuration (speed and such) programmaticaly.

Did you :

  • set “used = 1” to the uart 2 / 3 in the sys_config.fex
  • If you don’t use the RTS or CTS line, you can set the uart_type to “2”.
  • Can you open /dev/ttyS2 via adb shell and does it output something ? (“adb shell cat /dev/ttyS2”)
  • You have to remove the GPIO pin “device” corresponding to every pin used by a peripheral (so for UART 2, remove the line using PB00 and PB01 in the “gpio configuration” section.

And as I said in the last message regarding apps not ran with adb :

[…] To be able to open the serial port in a program not ran via adb (via the launcher for exemple), you may also need to add/change the permissions of the /dev/ttySx (0777), somewhere in an uevent*.d* file if the sources were available, but maybe there’s a file you can change somewhere to do the same thing, I don’t know.

HI … kailokyra

Nice Article… things looksgood… for uboot & fex

what about zimge & android file system… to complete " BananapiM3_LCD7.img"

please update…remining thing… Thanks in Advance

Hi,

I don’t really get what issue you’re having ? What’s zimge ?

The steps I described should work with any android image, as long as you change the paths in the steps to the ones that matches what you want to do.

Hi, I want to do the same thing and use serial port of my bpi-m64. is there an alternative way to do the steps that you mentioned in windows? can i do the same things for bpi-m64 at all?

Thanks

Hi,

I don’t know if the tools I listed exist on Windows (except imagerepacker, there’s one for sure), but you can use a virtual machine to install linux if you don’t want to install it on your computer :slight_smile: You may even be able to use linux on the bananapi to do it.

I’m pretty sure you can apply this procedure to the BPI-M64, you’ll probably have to change a path or two.

Best,

Hi,

Thanks for your help. I can not find any BSP repository for BPI-M64. there are some BSP provided by Allwinner in Pine64 Website but I’m not able to download them yet. If I can download them, can I use them for BPI-M64 or they are costumized just for Pine64?

Is it necessary to build uboot at all? what does it do? can i do this without having BPI-M64 BSP?

any help would be appreciated

Thank you

I don’t think you can use the BSP for the Pine64 (well, you could maybe with some modifications in the device tree source (the dts file describing all the peripherals and values, but I can’t help with that).

Ask @sinovoip for the BSP if it exists for the BPI-M64

For uboot, it’s the bootloader. It should be in the bsp. I don’t know if you can do without, by just reusing the previous one, I haven’t tested.

Yes, there is none. The Banana guys simply used everything from Pine64 in the beginning (so neither Wi-Fi worked nor eMMC and a lot of other stuff on BPI_M64 in the beginning) and then users jumped in and fixed their stuff. So there’s still nothing useable from BPI manufacturer and your only hope is: https://github.com/avafinger/bpi-m64-firmware

To adjust stuff as UART you need dtc tool to convert .dtb to .dts and back (follow instructions for Pine64 since it’s the same)

apt-get install device-tree-compiler

Instructions on how to write

thank you very much kailokyra for your help in this post. I also want to try activating UART2 for GPS. Unfortunately, I can not continue because I do not understand the way.

I downloaded the Android 5.1.1 image and used it on SD card and eMMC. I have unpacked this image with “imgRePacker_206” and edited the file “sys_config.fex”.

When editing I wondered which pins of the 40 pin GPIO are the pins for UART2 or to which pins lead PB00 and PB01? I can not read that from the above linked images. Additionally, I wonder if RX must be set as input and TX as output.

[UART2]
uart_used = 1
uart_port = 2
uart_type = 2
uart_tx = port: PB00 <2> <1> <default> <default>
uart_rx = port: PB01 <2> <1> <default> <default>
uart_regulator = "vcc-io"

Is it correct that way?

and how do I rebuild the image? I did not understand that yet. Why flash with LiveSuite and not with PhoenixSuite?

P.S. I think “[gps_para]” is for “[rf_para] modul_num = 7”.