简体   繁体   中英

Generate ARM thumb-2 assembly code from android app for Cortex M3 architecture

I want to build an Android app which will be an interface to convert C++ into assembly code for ARM Cortex M3 architecture.

I'm not an android java developer, and I do mainly arduino projects with C/C++. So I need your help to point me in good directions about how to build an android app with java in Android Studio or similar, which will be able to convert from C++ source code to ASM code M3 Cortex.

I did some research and found that I need to use ARM NONE EABI GCC compiler to generate ASM code from C++, simple like these command line instructions:

arm-none-eabi-gcc -O2 -mthumb -c test.c -o test.o
arm-none-eabi-objdump -D test.o

I tried to build that compiler using android Termux app, but failed. I have followed many posts and articles about how to build arm-none-eabi-gcc binary file. Even tried to run different similar binaries in termux but always failed, probably because my smartphone device architecture is AARCH64 and I use third party app like Termux as linux terminal emulator, which results in different kind of errors. However I didn't found a good article about how to install this arm compiler on android using Termux.

Even opened a new question about how to build this compiler, but no answers yet.

I guess that in order to convert C++ to ASM (M3 Cortex) I have to execute some shell commands using an arm compiler as command line tool with parameters, from my android app something like:

try{
    Process su = Runtime.getRuntime().exec("su");
    DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());

    outputStream.writeBytes("arm-none-eabi-gcc -O2 -mthumb -c test.c -o test.o");
    outputStream.flush();

    outputStream.writeBytes("exit\n");
    outputStream.flush();
    su.waitFor();
}catch(IOException e){
    throw new Exception(e);
}catch(InterruptedException e){
    throw new Exception(e);
}

My method was to use GCC On Android Using Termux app as third party which have ARM compiler installed, that I can call with termux API from my android app to convert C++ to ASM, that will easier the process of building of my android app.

But I'm not sure if that is even the right way to do that, as I'm a beginner in android app development. So please help with suggestions, examples which will give me the right way to achive my goals.

A solution would be if in Termux app you will do next things: ( more details here )

  1. pkg install proot
  2. pkg install proot-distro
  3. proot-distro install debian
  4. proot-distro login debian

After that you should be logged in a Debian environment, and you can install almost any Arm packages available on debian repositories.

For example you should be able to install this Cortex compiler:

$ sudo apt-get remove binutils-arm-none-eabi gcc-arm-none-eabi
$ sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
$ sudo apt-get update
$ sudo apt-get install gcc-arm-none-eabi
$ sudo apt-get install gdb-arm-none-eabi

The only thing left to do is to write your android app, using Termux API which will pass input and get output as you already suggested in your question, which is a correct way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM