なんとかなるさね

マイコンをネタにブログを始めてみました


Arduino IDE | Linux Arduino互換ライブラリをUbuntu/Linaro x86 Linux GCCでビルド→途中でエラー 

Intel Galileo Arduino IDEに同梱されているLinux Arduino互換ライブラリのソースコードをVMware Player
上のUbuntuのUbuntu/Linaro x86 Linux GCCでビルド出来るか試してみました。以前のエントリ(394397)
と同様、VMware Playerの共有フォルダ機能を使ってWindowsとVMware Player上のUbuntuでフォルダを
共有して、VMware Playerのハードウェア仮想化されたCOMポート経由でWindowsからVMware Player上の
Ubuntuのコマンドを実行するようにしています。いっそ、Linux版Arduino IDEを使った方が良かったのかも
しれませんが、ちょっと意地になって、Windows版Arduino IDEを使って試しました。しかしながら、途中
(というか最後のソースファイル)でコンパイルエラーになってしまいました。(とりあえず、今回も、これは
これで置いておいて、次はLinaro ARM Linux GCCでビルド出来るか試してみようと思っています。)

BuildLog.txt



書き換えたArduino IDEの環境設定ファイル: arduino-1.5.3\hardware\arduino\x86\platform.win.txt
環境設定ファイルの書き換え部分の内容:

# X86 compile variables
# ---------------------

name=Arduino X86 Boards
compiler.path={runtime.ide.path}/hardware/tools/x86/i686-linux-gnu/bin/
compiler.c.cmd=vmw-gcc.bat
compiler.c.flags= -m32 -march=i586 -c -g -Os -w -ffunction-sections -fdata-sections -MMD
compiler.c.elf.flags=-m32 -march=i586 -Os -Wl,--gc-sections
compiler.c.elf.cmd=vmw-g++.bat
compiler.S.flags=-c -g -assembler-with-cpp
compiler.cpp.cmd=vmw-g++.bat
compiler.cpp.flags= -m32 -march=i586 -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD
compiler.ar.cmd=vmw-ar.bat
compiler.ar.flags=rcs
compiler.objcopy.cmd=vmw-objcopy.bat
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
compiler.elf2hex.flags=-O ihex -R .eeprom
compiler.elf2hex.cmd=vmw-objcopy.bat
compiler.ldflags=
compiler.size.cmd=vmw-size.bat
compiler.strip.cmd=vmw-strip.bat
# this can be overriden in boards.txt
build.extra_flags=

# X86 compile patterns
# --------------------

## Compile c files
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -march={build.mcu} {build.f_cpu} -D{software}={runtime.ide.version} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"

## Compile c++ files
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -march={build.mcu} {build.f_cpu} -D{software}={runtime.ide.version} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"

## Create archives
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{build.path}/{archive_file}" "{object_file}"

## Combine gc-sections, archives, and objects
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -march={build.mcu} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "-L{build.path}" -lm -lpthread

## Create eeprom
recipe.objcopy.eep.pattern="{compiler.path}{compiler.strip.cmd}" "{build.path}/{build.project_name}.elf"

## Create hex
recipe.objcopy.hex.pattern=

## Compute size
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
recipe.size.regex=Total\s+([0-9]+).*

作成したバッチファイルのフォルダ: arduino-1.5.3\hardware\arduino\x86\i686-linux-gnu\bin
フォルダの内容:



作成したバッチファイル(例): arduino-1.5.3\hardware\arduino\x86\i686-linux-gnu\bin\cygwin-g++.bat
バッチファイルの内容(例):

@echo off
rem This code is in the public domain. You may use, modify or distribute it freely.
cscript -nologo %~dp0\vmwshdo.js \\.\pipe\vmware-serial-port g++ %*


ファイル: vmwshdo.js
内容:

// This code is in the public domain. You may use, modify or distribute it freely.
var fso, f, ts, str;
var ForReading = 1, ForWriting = 2, ForAppending = 8;
var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;

// ★★★★メンテしやすい方法へ要修正★★★★
var WindowsPath = /E:\/tools\/micom\/Intel/g; // 正規表現の'/'とパス区切り文字'/'が同じで煩雑
var UbuntuPath = "/home/ubuntu/Galileo";

var VMwareSerialMaxRetry = 10;
var VMwareSerialPortPipe = WScript.Arguments(0);
var VMwareExecuteCommand = "";
for (i = 1; i < WScript.Arguments.length; i++)
{
    VMwareExecuteCommand += WScript.Arguments(i) + " ";
}

fso = new ActiveXObject("Scripting.FileSystemObject");
for( i = 0; i < VMwareSerialMaxRetry; i++ )
{
    try
    {
        f = fso.GetFile(VMwareSerialPortPipe);
        break;
    }
    catch(e)
    {
        if( i == VMwareSerialMaxRetry - 1 ){
            // 指定された名前付きパイプが見つからなかった
            WScript.Quit(1);
        }
        WScript.Sleep(100); // ms
    }
}

// コマンドの送信(実行終了の目印に[[[END]]]が来るよう"; echo [[[END]]]"を付加して送信する)
for( i = 0; i < VMwareSerialMaxRetry; i++ )
{
    try
    {
        ts = f.OpenAsTextStream(ForAppending, TristateFalse);
        break;
    }
    catch(e)
    {
        if( i == VMwareSerialMaxRetry - 1 ){
            // 指定された名前付きパイプを他のプログラムが使用している(or 取られた)?
            WScript.Quit(1);
        }
        WScript.Sleep(100); // ms
    }
}
str = VMwareExecuteCommand;
// パス区切り文字を変更し、最後に"; echo [[[END]]]"を付加する
str = str.replace(/\\/g,"/") + "; echo [[[END]]]";
// Windows側→Ubuntu側のパス変換を行う
// ★★★★メンテしやすい方法へ要修正★★★★
str = str.replace(WindowsPath, UbuntuPath);
ts.WriteLine(str);
ts.Close();

// 実行結果の受信(実行終了の目印の[[[END]]]が来るまで受信する)
for( i = 0; i < VMwareSerialMaxRetry; i++ )
{
    try
    {
        ts = f.OpenAsTextStream(ForReading, TristateFalse);
        break;
    }
    catch(e)
    {
        if( i == VMwareSerialMaxRetry - 1 ){
            // 指定された名前付きパイプを他のプログラムが使用している(or 取られた)?
            WScript.Quit(1);
        }
        WScript.Sleep(100); // ms
    }
}
while (1)
{
    for( i = 0; i < VMwareSerialMaxRetry; i++ )
    {
        try
        {
            // しまった。ブロッキングリードだから最大リトライ回数チェックは無駄だった。
            str = ts.ReadLine();
            break;
        }
        catch(e)
        {
            if( i == VMwareSerialMaxRetry - 1 ){
                WScript.Quit(1);
            }
            WScript.Sleep(100); // ms
        }
    }
    if (str.search(/exit ; echo \[\[\[END\]\]\]$/) != -1)
    {
        // exitコマンドでは目印の[[[END]]]が来ないので待たずに終了
        break;
    }
    if (str.search(/^\[\[\[END\]\]\]/) != -1)
    {
        // コマンドの実行終了の目印の[[[END]]]が来たら終了
        break;
    }
    if (str.search(/ ; echo \[\[\[END\]\]\]$/) == -1 && str.search(/^[ \t]*$/) == -1)
    {
        // コマンドのエコーバックと空行を除きコマンドの実行結果を画面に表示する
        WScript.Echo(str);
    }
}
ts.Close();

// ★★★★Ubuntu側のエラーコードをWindows側へ渡す方法について要検討★★★★
WScript.Quit(0)


関連記事

2014/01/16   blog-entry-406   category: Arduino Lib & CrossGCC

go page top