Cygwin environment uses third-party ARMGCC to compile Ecos systems

Source: Internet
Author: User
Tags posix

Third-party ARMGCC are typically based on Mingw32, using Windows paths such as C:\ecos\packages\infra\current\src\ Startup.cxx, whereas the Ecos Configuration tool generates makefile based on Cygwin, using a POSIX path, such as/cygdrive/c/packages/infra/current/src/startup.cxx. The difference in path format leads to the inability to compile the ecos system directly using a third-party ARMGCC, but requires an intermediary program to convert the path. This provides the source code and compilation Instructions for the intermediate program that performs the path conversion.

ECOS Official website: http://ecos.sourceware.org

Ecos Chinese Technology Network: http://www.52ecos.net

Ecos Exchange QQ Group: 144940146.

http://blog.csdn.net/zoomdy/article/details/39553465

Mingdu.zheng<at>gmail<dot>com


Why do I need a third party ARMGCC

The ECOS project itself provides the GCC compiler, but the update is relatively slow, in arm company has launched CORTEX-M7 year also does not support CORTEX-M4 FPU, after all, Ecos project itself is to do real-time operating system, compiler is only one of its supporting tools. Third-party ARMGCC releases new versions almost every quarter to support the latest hardware.


Third party ARMGCC

Two third-party ARMGCC recommended here

    • GNU Tools for ARM Embedded processors

https://launchpad.net/gcc-arm-embedded

Look at the introduction of this project, should be the official ARM company participation, can be freely downloaded, without registration.

    • Sourcery Codebench Lite Edition

http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/

This originally was Codesourcery company's products, is now Mentorgraphics acquired, its lite version can be downloaded for free use, but need to register.


Implementation of PATH transformation

There are two locations where path conversions are required, one is the command-line arguments passed to GCC, the Ecos Configuration tool generates makefile using a POSIX path, and GCC requires a Windows path, So first you need to convert the POSIX path that appears in the command-line arguments to the Windows path and then to GCC, and the second is: the Ecos compilation system needs to use the GCC output dependency file, and the third-party gcc-generated file uses the Windows path. The Ecos compilation system requires a POSIX path, and the next step is to convert the Windows path in the dependency file into a POSIX path, which is the source code below.

main.cxx//by Zoomdy (mingdu.zheng <at> gmail <dot> com) #ifdef __cygwin__#include <windows.h># Include <sys/cygwin.h> #include <sys/wait.h>//For waitpid#include <stdio.h> #include <stdlib.h > #include <string.h>//For STRSTR, Strchr#include <unistd.h>//for Execvp#include <stdbool.h>int m    Ain (int argc, char *argv[]) {//First handler name char *p = STRCHR (argv[0], '-');        if (p = = NULL) {fprintf (stderr, "Invalid program name:%s", argv[0]);    return exit_failure;    } p++;    if (*p = = ' | | | *p = = '. ')        {fprintf (stderr, "Invalid program name:%s", argv[0]);    return exit_failure;    } char *q;    for (q = argv[0]; *p! = ' + '; q++, p++) {*q = *p;    } *q = ' + ';    Processing other parameters char buffer [MAX_PATH + 1];    char *deps = NULL;        for (int i = 1; i < argc; i++) {p = strstr (Argv[i], "/cygdrive/"); if (P! = NULL) {Cygwin_conv_to_win32_path (p, BuffER);        strcpy (p, buffer);        } p = strstr (Argv[i], "-WP,-MD,");        if (P! = NULL) {deps = p + strlen ("-WP,-MD,"); }//If the parameter named null file is found, create a blank file if (strcmp (Argv[i], "/dev/null") = = 0) {file* file = fo            Pen ("null", "w");            fclose (file);        strcpy (argv[i], "null");    }}//Print the changed command line printf ("==>");        for (int i = 0; i < argc; i++) {printf (argv[i]);    printf ("");    } printf ("\ n");        Call the changed command line if (deps = = NULL) {//If you do not need to process the dependency file, directly call the target program int retval = EXECVP (argv[0], argv);            if (retval = =-1) {perror (argv[0]);        return exit_failure;        } else {return exit_success;        }} else {//If you need to process a dependency file, create a child process and wait for the child process to finish processing the dependency file pid_t pid = fork ();            if (PID = =-1) {perror (argv[0]);        return exit_failure;      }  else if (PID = = 0) {int retval = EXECVP (argv[0], argv);                if (retval = =-1) {perror (argv[0]);            return exit_failure;            } else {return exit_success;            }} else {int stat_val;            Waitpid (PID, &stat_val, 0); If the child process completes correctly, then handle the dependency file if (wifexited (Stat_val)) {if (Wexitstatus (stat_val) = = Exit_su                    ccess) {//process the generated dependency file char Deps_cyg [MAX_PATH + 1];                    strcpy (Deps_cyg, deps);                    strcat (Deps_cyg, ". Cyg");                    file* File_win = fopen (Deps, "R");                    file* File_cyg = fopen (Deps_cyg, "w");                    BOOL Last_line = false;                    size_t Len_line;                      for (int line = 0; last_line = = false; line++) {  p = fgets (buffer, sizeof (buffer), file_win);                            if (p = = NULL) {perror (deps);                        return exit_failure;                        }//Skip the preceding space for (size_t i = 0; i < sizeof (buffer); i++)                            {if (*p = = ") {p++;                            } else {break; }}//Remove the trailing carriage return newline character and the space len_l                        ine = strlen (p); for (size_t i = len_line-1; I! = 0; i--) {if (p[i] = = ' | | p[i] = = ' \ R ' | |                                P[i] = = ' \ n ') {p[i] = ' + '; Len_line--;                            } else {break;                        }}//Determine if it is the last line if (p[len_line-1] = = ' \ \ ')                            {last_line = false;                            P[len_line-1] = ' + ';                        len_line--;                        } else {last_line = true;                        }//Remove trailing spaces for (size_t i = len_line-1; I! = 0; i--)                                {if (p[i] = = ") {P[i] = ' + ';                            len_line--;      } else {break;                      }}//Handle the special case of the first row, in which case the target and dependent files are on the same line                            if (line = = 0) {q = strstr (P, ". O:");                                if (q! = NULL) {p = q + strlen (". O:");                                Skip the preceding space for (size_t i = 0; i < sizeof (buffer); i++)                                        {if (*p = = ") {                                    p++; } else {Brea                                    K                                    }} if (Strlen (P) > 0) { Cygwin_conv_to_posix_path (P, p); }}}//Starting from the second line, convert the path if (li Ne > 0) {//Convert Windows path to POSIX path Cygwin_c                        Onv_to_posix_path (P, p);                            }//If it is not the last line, add a space and a backslash if (!last_line) {                        strcat (buffer, "\\\n");                        } else {strcat (buffer, "\ n");                        } int retval = fputs (buffer, FILE_CYG);                            if (retval = = EOF) {perror (DEPS_CYG);                        return exit_failure;                    }} fclose (File_win);                   Fclose (FILE_CYG); Delete the original file, rename the processed file to the original file name, remove (deps);                    Rename (Deps_cyg, deps);                return exit_success; }//Wexitstatus (Stat_val)}//Wifexited (stat_val)}//pid > 0}//Deps = = NULL return exit_f Ailure;} #else #error "invoke native tool only with use for Cygwin environment" #endif
Compile

Save the above source code content file as Mian.cxx, and then save the following code content file as makefile, placed in the same directory, and then open the Cygwin terminal, into the storage of the above two files, typing make.

# MAKEFILEALL:NATIVE.EXECP Native.exe NATIVE-ARM-NONE-EABI-GCC.EXECP native.exe NATIVE-ARM-NONE-EABI-AR.EXECP Native.exe native-arm-none-eabi-objcopy.exenative.exe:main.cxxgcc-wall-o2-o [email protected] $<CLEAN:RM-RF *. Exe
Use

Store the generated Native-arm-none-eabi-*.exe file in the directory you want to store, and append the directory to the system's PATH environment variable. Next, set the global build Options >> Global command prefix to Native-arm-none-eabi in the Ecos Configuration tool.



What's going to happen

When compiling a ecos system, any place where GCC is called will be called First NATIVE-ARM-NONE-EABI-GCC, NATIVE-ARM-NONE-EABI-GCC calls ARM-NONE-EABI-GCC if the POSIX path in the command line argument is converted to a Windows path, and if the command line contains parameters that generate a dependency file, Then NATIVE-ARM-NONE-EABI-GCC will wait for the ARM-NONE-EABI-GCC to process the path transitions in the dependency file after the compilation is complete.


The best solution

Use a Linux system instead of Cygwin as the ecos development environment. Developing ecos in Linux using a third-party ARMGCC is completely without the hassle, because everyone is using POSIX paths, there is no need to do any conversion, and in the Linux environment is much faster than the compilation speed in the Cygwin environment, After all, Cygwin increases the hierarchy of system calls, and Windows has a less file access cache mechanism than Linux, and antivirus software is in the middle. Of course, not everyone will use Linux, all have the ecos version of Cygwin, there is time to try Linux is also very good, today's Linux desktop system is quite mature.

Cygwin environment uses third-party ARMGCC to compile Ecos systems

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.