mruby vm ポーティング手順マニュアルmrubyポーティングの概要...

41
mruby VM ポーティング手順マニュアル ポーティング手順マニュアル ポーティング手順マニュアル ポーティング手順マニュアル

Upload: others

Post on 18-Apr-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mruby VMポーティング手順マニュアルポーティング手順マニュアルポーティング手順マニュアルポーティング手順マニュアル

Page 2: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mrubyポーティング

� mrubyポーティングとは

mrubyを特定のシステム上で動作させるためには、mrubyの移植作業 (修正および再構築) mrubyを特定のシステム上で動作させるためには、mrubyの移植作業 (修正および再構築)

が必要となる。この移植作業がポーティングである。

mrubyのポーティングでは、mrubyの実⾏基盤であるmruby仮想マシン (mruby VM) を

実⾏環境で動作させることが必要となる。

本稿では、mrubyをQSIPボードで動作させるために実施したポーティング作業の概要を示す。

1

Page 3: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mrubyポーティングの概要

� mrubyポーティングの概要� mrubyポーティングの概要QSIPボードにmrubyをポーティングする手順を以下に示す。

1. mrubyビルド環境の構築1. mrubyビルド環境の構築mrubyをビルドするための開発環境を構築する。本稿ではWindows上にmrubyビルド環境を構築した。

2. QSIP向けのmrubyクロスビルドmrubyをQSIPボード用にクロスコンパイルし、mrubyライブラリ (libmruby.a) を作成する。本稿では、IAR Embedded Workbench for ARMにmrubyクロスビルド環境を構する。本稿では、IAR Embedded Workbench for ARMにmrubyクロスビルド環境を構築した。

3. QSIPアプリケーションへのmruby組み込み3. QSIPアプリケーションへのmruby組み込みQSIPアプリケーションにmruby VMを呼び出す処理 (mruby API) を追加し、mrubyライブラリ(libmruby.a)をリンクする。

4. QSIP用ライブラリの作成QSIPボードに搭載されているデバイスを制御するためのクラスライブラリを作成し、QSIPボードに搭載されているデバイスを制御するためのクラスライブラリを作成し、mruby VMに組み込むことで、mrubyアプリケーションからQSIP搭載デバイスの制御を可能とする。

5. 2

Page 4: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mrubyビルド環境の構築mrubyビルド環境の構築

Fujitsu Kyushu Network Technologies CONFIDENTIAL3

Page 5: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

環境構築

� ターゲット環境仕様

mrubyポーティングのターゲット環境(QSIPボード)の仕様を以下に示す。mrubyポーティングのターゲット環境(QSIPボード)の仕様を以下に示す。

メインメインメインメインMPU

プロセッサ MK24FN1M0VLL12

ROM 1MB

RAM 256KB

サブサブサブサブMPU

プロセッサ MKL93Z32VFK4

ROM 32KBROM 32KB

RAM 2KB

デバイスデバイスデバイスデバイスデバイスデバイスデバイスデバイス

外部フラシュメモリ 32MB

センサ 磁力、電圧検出、光、温湿度、静電容量、ジャイロ

4

センサ 磁力、電圧検出、光、温湿度、静電容量、ジャイロ

インターフェイス RS232C、JTAG

Page 6: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

環境構築

� 開発環境仕様

mrubyポーティング作業に使用した環境を以下に示す。mrubyポーティング作業に使用した環境を以下に示す。

PCPCPCPC

モデル Fujitsu FMVNSS8AEFujitsu FMVNSS8AE

OS Windows 7 Professional (32bit)

プロセッサ Intel® Core™ is-3340M CPU (2.7GHz)

RAM 4GB

ソフトウェアソフトウェアソフトウェアソフトウェア

Cygwin 2.6.1-1

GNU Bison 2.4.1

Ruby 2.3.3-p222Ruby 2.3.3-p222

EWARM 7.80.4

5

Page 7: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

環境構築

� Windowsビルド環境構築

Windows上にmrubyビルド環境を構築するWindows上にmrubyビルド環境を構築する

① C言語ビルド環境(Cygwin)のセットアップ

② Rubyのセットアップ② Rubyのセットアップ

③ パーサージェネレータ(GNU Bison)のセットアップ

④ mrubyソースコードの入手・mrubyのビルド

⑤ 動作確認

6

Page 8: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

Windows ビルド環境 ①ターミナル

Cygwin ダウンロード編� Cygwin ダウンロード編�公式サイトよりインストール

•http://cygwin.com/•http://cygwin.com/

クリックしてダウンロード

�参考URL�参考URL

•http://musashi.osdn.jp/cygwin/cygwin.html

7

Page 9: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

Windows ビルド環境 ①ターミナル

Cygwin インストール編� Cygwin インストール編 任意のフォルダを指定

末尾 .jpを選択を選択

任意のフォルダを指定

(次スライドに続く)

8

Page 10: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

Windows ビルド環境 ①ターミナル

Cygwin インストール編� Cygwin インストール編

“Category” の“Devel” を“Devel” を

Install にする

“binutils” と “bison”、”gcc-core” を最新バージョンにする

“binutils” と “bison”、”gcc-core” を最新バージョンにする最新バージョンにする最新バージョンにする

9

Page 11: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

Windows ビルド環境 ②Ruby

Ruby ダウンロード編�Ruby ダウンロード編�公式サイトよりダウンロード

•https://rubyinstaller.org/•https://rubyinstaller.org/

クリックしてダウンロードダウンロード

�参考URL�参考URL

•http://www.rubylife.jp/install/install/index1.html

10

Page 12: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

Windows ビルド環境 ②Ruby

Ruby インストール編�Ruby インストール編任意のフォルダを

指定指定

11

Page 13: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

Windows ビルド環境 ③パーサー

bison ダウンロード編� bison ダウンロード編�公式サイトよりダウンロード

•http://gnuwin32.sourceforge.net/packages/bison.htm•http://gnuwin32.sourceforge.net/packages/bison.htm

クリックしてクリックしてダウンロード

�参考URL

•http://ameblo.jp/oregano-blog/entry-10400001478.htm

12

Page 14: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

Windows ビルド環境 ③パーサー

bison インストール編� bison インストール編 任意のフォルダを指定

13

Page 15: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

Windows ビルド環境 ④ビルド

mruby ソースコード ダウンロード編� mruby ソースコード ダウンロード編� GitHub から mruby の最新ソースコードをダウンロード

•https://github.com/mruby/mruby•https://github.com/mruby/mruby

クリックしてダウンロード

� 取得リビジョン c48aef0b653ba83452c97b1d1017869de2a846b9

� 参考URL http://qiita.com/ko2a/items/b29acc616f67738465ea

14

Page 16: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

Windows ビルド環境 ④ビルド

mruby ソースコード ビルド編�mruby ソースコード ビルド編�ダウンロードした

zipファイル(mrubymruby--mastermaster) をzipファイル(mrubymruby--mastermaster) を

任意のディレクトリ任意のディレクトリ に解凍する。

� Cygwin を起動し、

解凍解凍先のディレクトリ先のディレクトリ に移動する。

15

Page 17: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

Windows ビルド環境 ④ビルド

mruby ソースコード ビルド編�mruby ソースコード ビルド編��makemake コマンドを⼊⼒する

⇒ 下図の画面が表示されたらビルド成功。⇒ 下図の画面が表示されたらビルド成功。

16

Page 18: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

Windows ビルド環境 ⑤動作確認

Hello, mruby world !! メイク編�Hello, mruby world !! メイク編�mrubyソース(mrubymruby--mastermaster) の binbinフォルダフォルダ に 「 Hello.rbHello.rb 」 を作成する。

ソースコード "Hello.rb"

puts “Hello, mruby world !!”

17

Page 19: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

Windows ビルド環境 ⑤動作確認

� Hello, mruby world !! 動作確認編� Hello, mruby world !! 動作確認編�� mrubymruby--master/binmaster/binディレクトリディレクトリ に移動して、 ././mruby mruby HHello.rbello.rb コマンドを⼊⼒する。

⇒ Hello, mruby world !! と表示されたら成功。⇒ Hello, mruby world !! と表示されたら成功。

18

Page 20: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

QSIP向けのmrubyクロスビルドQSIP向けのmrubyクロスビルド

Fujitsu Kyushu Network Technologies CONFIDENTIAL19

Page 21: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

環境構築

� mrubyクロスビルド

QSIP向けクロスビルド環境 IAR Embedded Workbench for ARM を使用して、QSIP向けクロスビルド環境 IAR Embedded Workbench for ARM を使用して、

mrubyをQSIP向けにクロスビルドする。

① IAR Embedded Workbench for ARM (EWARM)① IAR Embedded Workbench for ARM (EWARM)

のセットアップ

② mrubyのクロスビルド (libmruby.aの作成)② mrubyのクロスビルド (libmruby.aの作成)

20

Page 22: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mrubyポーティング ①EWARMインストール

� IAR Embedded Workbench for ARM ダウンロード編� IAR Embedded Workbench for ARM ダウンロード編�公式サイトより無償評価版(30日期間限定版)をダウンロード

•https://www.iar.com/jp/•https://www.iar.com/jp/

クリックしてクリックしてダウンロード

セットアップ手順についてはここを参照してください

21

ここを参照してください

Page 23: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mrubyポーティング ②ビルド

�クロスコンパイル libmruby.a 作成編�クロスコンパイル libmruby.a 作成編�mrubyソース(mrubymruby--mastermaster) 内の build_config.rbbuild_config.rb を編集し、

再度 makemake すると 「 QSIP 」フォルダ配下に libmruby.alibmruby.a が生成される再度 makemake すると 「 QSIP 」フォルダ配下に libmruby.alibmruby.a が生成されるMRuby::CrossBuild.new('QSIP') do |conf|

toolchain :gccconf.linker.flags << "-m32"

conf.cc do |cc| cc.command='C:/Devz/ARM/LAUNCHPAD/bin/arm-none-eabi-gcc' cc.flags = [] cc.flags << '-mcpu=cortex-m4 -march=armv7e-m -mtune=cortex-m4' cc.flags << '-mthumb -mlittle-endian -mno-unaligned-access' cc.flags << '-mapcs-frame -mno-sched-prolog -mfpu=fpv4-sp-d16 -mfloat-abi=soft ' cc.flags << '-std=gnu99 ' cc.flags << '-fno-strict-aliasing -fsigned-char' cc.flags << '-fno-strict-aliasing -fsigned-char' cc.flags << '-ffunction-sections -fdata-sections ' cc.flags << '-fno-schedule-insns2 ' cc.flags << '--param max-inline-insns-single=1000 ' cc.flags << '-nostartfiles -fno-common ' cc.flags << '-fno-hosted' cc.flags << '-gdwarf-2 -O0 -flto-partition=none -fipa-sra' cc.flags << %w(-DMRB_USE_FLOAT)

cc.defines << %w(MRB_HEAP_PAGE_SIZE=8) cc.defines << %(MRB_IREP_ARRAY_INIT_SIZE=128u) cc.defines << %w(MRB_USE_IV_SEGLIST) cc.defines << %w(KHASH_DEFAULT_SIZE=8) cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20) #cc.defines << %w(DISABLE_STDIO) #if you dont need cc.defines << %w(MRB_GC_STRESS) #no document cc.defines << %w(POOL_PAGE_SIZE=256) #effective only for use with mruby-eval

end

conf.archiver do |ar| ar.command = ‘C:/Devz/ARM/LAUNCHPAD/bin/arm-none-eabi-ar’

end

conf.bins = [] conf.build_mrbtest_lib_only# conf.gem :core => "mruby-print" conf.gem :core => "mruby-math“

22

conf.gem :core => "mruby-math“# conf.gem :core => "mruby-enum-ext“# conf.gem '../mruby-direct‘end

Page 24: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mrubyポーティング ②ビルド

� クロスコンパイル libmruby.a 作成編� クロスコンパイル libmruby.a 作成編� mrubyソース(mrubymruby--mastermaster) 内の build_config.rbbuild_config.rb を編集し、

再度 makemake すると 「 QSIP 」フォルダ配下に libmruby.alibmruby.a が生成される再度 makemake すると 「 QSIP 」フォルダ配下に libmruby.alibmruby.a が生成されるbuild_config.rb

MRuby::Build.new do |conf|# load specific toolchain settings

# end

# mrbc settings# Gets set by the VS command prompts.if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR' ]

toolchain :visualcppelse

toolchain :gccend

# mrbc settings# conf.mrbc do |mrbc|# mrbc.compile_options = "-g -B%{funcname} -o-" # The -g

option is required for line numbers# end

# Linker settings# conf.linker do |linker|

enable_debug

# Use mrbgems# conf.gem 'examples/mrbgems/ruby_extension_example'# conf.gem 'examples/mrbgems/c_extension_example' do |g|# g.cc.flags << '-g' # append cflags in this gem# end

# conf.linker do |linker|# linker.command = ENV['LD'] || 'gcc'# linker.flags = [ENV['LDFLAGS'] || []]# linker.flags_before_libraries = []# linker.libraries = %w()# linker.flags_after_libraries = []# linker.library_paths = []# linker.option_library = ' - l%s '# end

# conf.gem 'examples/mrbgems/c_and_ruby_extension_ex ample'# conf.gem :github => 'masuidrive/mrbgems-

example', :checksum_hash => '76518e8aecd131d047378448ac8055fa29d974a9'

# conf.gem :git => '[email protected]:masuidrive/mrbgems -example.git', :branch => 'master', :options => '-v'

# linker.option_library = ' - l%s '# linker.option_library_path = '-L%s'# linker.link_options = "%{flags} -

o %{outfile} %{objs} %{libs}"# end

# Archiver settings# conf.archiver do | archiver |

# include the default GEMsconf.gembox 'default'# C compiler settings# conf.cc do |cc|# cc.command = ENV['CC'] || 'gcc'# cc.flags = [ENV['CFLAGS'] || %w()]# cc.include_paths = ["#{root}/include"]

# archiver.command = ENV['AR'] || 'ar'# archiver.archive_options = 'rs %{outfile} %{objs} '# end

# Parser generator settings# conf.yacc do |yacc|# yacc.command = ENV['YACC'] || 'bison'

23

# cc.defines = %w(DISABLE_GEMS)# cc.option_include_path = '-I%s'# cc.option_define = '-D%s'# cc.compile_options = "%{flags} -MMD -o %{outfile } -

c %{infile}"

# yacc.compile_options = '-o %{outfile} %{infile}'# end

# gperf settings# conf.gperf do |gperf|

Page 25: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mrubyポーティング ②ビルドbuild_config.rb (続き)build_config.rb (続き)

# gperf.command = 'gperf'# gperf.compile_options = '-L ANSI-C -C -p -j1 -i 1 -g -o -t -

N mrb_reserved_word -k"1,3,$" %{infile} > %{outfile} '# end

MRuby::Build.new('test') do |conf|# Gets set by the VS command prompts.if ENV[' VisualStudioVersion '] || ENV['VSINSTALLDIR']# end

# file extensions# conf.exts do |exts|# exts.object = '.o'# exts.executable = '' # '.exe' if Windows# exts.library = '.a'# end

if ENV[' VisualStudioVersion '] || ENV['VSINSTALLDIR']toolchain :visualcpp

elsetoolchain :gcc

end

enable_debugconf.enable_bintest# end

# file separetor# conf.file_separator = '/'

# bintest# conf.enable_bintest

end

conf.enable_bintestconf.enable_test

conf.gembox 'default'end

MRuby::Build.new('bench') do |conf|# Gets set by the VS command prompts.

MRuby::Build.new('host-debug') do |conf|# load specific toolchain settings

# Gets set by the VS command prompts.if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR' ]

toolchain :visualcpp

if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR' ]toolchain :visualcpp

elsetoolchain :gccconf.cc.flags << '-O3'

end

elsetoolchain :gcc

end

enable_debug

# include the default GEMs

conf.gembox 'default'end

# Define cross build settings# MRuby::CrossBuild.new('32bit') do |conf|# toolchain :gcc#

conf.gembox 'default'

# C compiler settingsconf.cc.defines = %w(MRB_ENABLE_DEBUG_HOOK)

# Generate mruby debugger command (require mruby-ev al)conf.gem :core => "mruby-bin-debugger"

# conf.cc.flags << "-m32"# conf.linker.flags << "-m32"## conf.build_mrbtest_lib_only## conf.gem 'examples/mrbgems/c_and_ruby_extension_ example'#

24

# bintest# conf.enable_bintest

end

# conf.test_runner.command = 'env'## end

Page 26: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mrubyポーティング ②ビルドbuild_config.rb (続き) ※赤字は追加コードbuild_config.rb (続き) ※赤字は追加コード

#add QNETMRuby::CrossBuild.new('QSIP') do |conf|

toolchain :gcc

conf.linker.flags << "-m32"

conf.cc do |cc|cc.command='C:/Devz/ARM/LAUNCHPAD/bin/arm-none-eabi -gcc'cc.flags = []cc.flags << '-mcpu=cortex-m4 -march=armv7e-m -mtune= cortex-

m4'm4'cc.flags << '-mthumb -mlittle-endian -mno-unaligned-a ccess'cc.flags << '-mapcs-frame -mno-sched-prolog -mfpu=fp v4-sp-d16

-mfloat-abi=soft 'cc.flags << '-std=gnu99 'cc.flags << '-fno-strict-aliasing -fsigned-char'cc.flags << '-ffunction-sections -fdata-sections 'cc.flags << ' - fno - schedule - insns2 'cc.flags << '--param max-inline-insns-single=1000 'cc.flags << '-nostartfiles -fno-common 'cc.flags << '-fno-hosted'cc.flags << '-gdwarf-2 -O0 -flto-partition=none -fip a-sra'cc.flags << %w(-DMRB_USE_FLOAT)cc.defines << %w(MRB_HEAP_PAGE_SIZE=8)cc.defines << %(MRB_IREP_ARRAY_INIT_SIZE=128u)cc.defines << %w(MRB_USE_IV_SEGLIST)cc.defines << %w(KHASH_DEFAULT_SIZE=8)cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20)#cc.defines << %w(DISABLE_STDIO) #if you dont needcc.defines << %w(MRB_GC_STRESS) #no documentcc.defines << %w(POOL_PAGE_SIZE=256) #effective only for use

with mruby-evalend

conf.bins = []conf.build_mrbtest_lib_only

# conf.gem :core => "mruby-print"# conf.gem :core => "mruby-math"# conf.gem :core => "mruby-enum-ext"

25

# conf.gem '../mruby-direct'end

Page 27: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

QSIPアプリケーションへのmruby組み込み

QSIPアプリケーションへのmruby組み込み

Fujitsu Kyushu Network Technologies CONFIDENTIAL26

Page 28: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

� QSIPアプリケーションへのmruby組み込み

QSIP用のC言語アプリケーションにmrubyライブラリ(libmruby.a)およびmrubyアプリケーQSIP用のC言語アプリケーションにmrubyライブラリ(libmruby.a)およびmrubyアプリケー

ションをリンクする。

① EWARM設定① EWARM設定

1. QSIPアプリケーションへのmrubyソースコードの追加

2. インクルードディレクトリにmrubyのインクルードパスを追加2. インクルードディレクトリにmrubyのインクルードパスを追加

3. リンカ設定でmrubyライブラリ (libmruby.a) を追加

② mruby動作確認用アプリケーションの作成② mruby動作確認用アプリケーションの作成

27

Page 29: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mrubyポーティング ②ビルド

� EWARMへのmrubyソースコード追加� EWARMへのmrubyソースコード追加� EWARM の

ワークスペース > ファイル(既存ソースコード) にワークスペース > ファイル(既存ソースコード) に

mruby ソースコードを追加する

28

Page 30: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mrubyポーティング ②ビルド

� EWARMインクルードディレクトリの追加� EWARMインクルードディレクトリの追加� EWARM の

プロジェクト > オプション > カテゴリ:C,C++コンパイラ > タブ:プリプロセッサプロジェクト > オプション > カテゴリ:C,C++コンパイラ > タブ:プリプロセッサ

より、追加インクルードディレクトリに mruby ヘッダソースのパスを追加

29

Page 31: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mrubyポーティング ②ビルド

� EWARMのリンカ設定� EWARMのリンカ設定� EWARM の

プロジェクト > オプション > カテゴリ:リンカ > タブ:ライブラリ よりプロジェクト > オプション > カテゴリ:リンカ > タブ:ライブラリ より

前スライドで生成したライブラリ(libmruby.alibmruby.a)のパスをリンカに追加する

30

Page 32: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mrubyポーティング ③動作確認

�mruby動作確認用のアプリケーション作成�mruby動作確認用のアプリケーション作成�下記のソースコードを作成してQSIPアプリケーションをビルドし、アプリケーションを含

むファームウェアをQSIPボードに書き込んで実⾏する。むファームウェアをQSIPボードに書き込んで実⾏する。QSIPアプリケーションからmruby VMが起動できていることを確認する。

#include "mruby.h"#include <stdio.h>

void main(void)void main(void){

printf(“mrb_open¥n”);// mruby 仮想マシンの作成mrb_state * mrb = mrb_open ();mrb_state * mrb = mrb_open ();

printf(“mrb_close¥n”);// 仮想マシンを閉じるmrb_close ( mrb);mrb_close ( mrb);

printf(“finish¥n”);}

31

Page 33: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

QSIP用ライブラリの作成QSIP用ライブラリの作成

Fujitsu Kyushu Network Technologies CONFIDENTIAL32

Page 34: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

� QSIPアプリケーションへのmruby組み込み

QSIPボード用のmrbgems (mrubyクラスライブラリ)を作成し、libmruby.aにライブラリをQSIPボード用のmrbgems (mrubyクラスライブラリ)を作成し、libmruby.aにライブラリを

追加する。

① mrbgems作成① mrbgems作成

② mruby VMへのmrbgems追加

③ mruby動作確認用アプリケーションの作成③ mruby動作確認用アプリケーションの作成

33

Page 35: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mrubyポーティング ④ライブラリ化

� mrbgems作成� mrbgems作成� mruby-master¥mrbgems以下に下記ディレクトリ、ファイルを作成する.

mruby-master¥

mrbgems¥

sample_qsip¥sample_qsip¥

mrbgem.rake

src¥作成対象

src¥

sample_qsip.c

34

Page 36: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mrubyポーティング ④ライブラリ化

�mrbgems作成�mrbgems作成�mruby-master¥mrbgems¥sample_qsip¥mrbgem.rake

MRuby::Gem::Specification.new('sample_qsip') do |spec|spec.license = 'MIT'spec.author = 'QNET'spec.summary = 'QSIP sample library'spec.summary = 'QSIP sample library'

end

35

Page 37: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mrubyポーティング ④ライブラリ化

�mrbgems作成�mrbgems作成�mruby-master¥mrbgems¥qsip_sample¥src¥qsip_sample.c

#include "mruby.h"#include <stdio.h>

// ライブラリ化する処理static mrb_valuestatic mrb_valuemrb_sample_qsip(mrb_state *mrb, mrb_value self) {

puts("mruby on QSIP"); // 文字列を表示return mrb_nil_value(); // nil を返す

}

voidmrb_sample_qsip_gem_init(mrb_state* mrb) {

// Sample_QSIP モジュールの登録struct RClass *class_sample_qsip = mrb_define_module(mrb, “Sample_ QSIP");// sample_qsip メソッドの登録// sample_qsip メソッドの登録mrb_define_class_method(mrb, class_sample_qsip, “sample_qsip", mr b_sample_qsip, ARGS_NONE());

}

voidmrb_sample_qsip_gem_final ( mrb_state * mrb) {

Sample_QSIP::sample_qsip メソッドとして実装した。

mrb_sample_qsip_gem_final ( mrb_state * mrb) {}

Sample_QSIP::sample_qsip メソッドとして実装した。

36

Page 38: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mrubyポーティング ④ライブラリ化

� mruby VMへのmrbgems追加� mruby VMへのmrbgems追加�� build_config.rbbuild_config.rb に

作成した mrbgems を追記し、

MRuby::CrossBuild.new('QSIP') do |conf| toolchain :gccconf.linker.flags << "-m32"

conf.cc do |cc| cc.command='C:/Devz/ARM/LAUNCHPAD/bin/arm-none-eabi-gcc' 作成した mrbgems を追記し、

再度 makemake する。

build¥QSIP¥lib フォルダ配下には

cc.command='C:/Devz/ARM/LAUNCHPAD/bin/arm-none-eabi-gcc' cc.flags = [] cc.flags << '-mcpu=cortex-m4 -march=armv7e-m -mtune=cortex-m4' cc.flags << '-mthumb -mlittle-endian -mno-unaligned-access' cc.flags << '-mapcs-frame -mno-sched-prolog -mfpu=fpv4-sp-d16 -mfloat-abi=soft ' cc.flags << '-std=gnu99 ' cc.flags << '-fno-strict-aliasing -fsigned-char' cc.flags << '-ffunction-sections -fdata-sections '

build¥QSIP¥lib フォルダ配下には

作成した mrbgems が追加された

libmruby.alibmruby.a が生成される

cc.flags << '-ffunction-sections -fdata-sections ' cc.flags << '-fno-schedule-insns2 ' cc.flags << '--param max-inline-insns-single=1000 ' cc.flags << '-nostartfiles -fno-common ' cc.flags << '-fno-hosted' cc.flags << '-gdwarf-2 -O0 -flto-partition=none -fipa-sra' cc.flags << %w(-DMRB_USE_FLOAT) libmruby.alibmruby.a が生成されるcc.defines << %w(MRB_HEAP_PAGE_SIZE=8) cc.defines << %(MRB_IREP_ARRAY_INIT_SIZE=128u) cc.defines << %w(MRB_USE_IV_SEGLIST) cc.defines << %w(KHASH_DEFAULT_SIZE=8) cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20) #cc.defines << %w(DISABLE_STDIO) #if you dont need cc.defines << %w(MRB_GC_STRESS) #no document cc.defines << %w(MRB_GC_STRESS) #no document cc.defines << %w(POOL_PAGE_SIZE=256) #effective only for use with mruby-eval

end

conf.archiver do |ar| ar.command = ‘C:/Devz/ARM/LAUNCHPAD/bin/arm-none-eabi-ar’

end 作成したconf.bins = []conf.build_mrbtest_lib_only

conf.gem :core => "mruby-print" # conf.gem :core => "mruby-math“# conf.gem :core => "mruby-enum-ext“conf.gem :core => " mruby -sample -qsip “

作成したmrbgems

を追記

37

conf.gem :core => " mruby -sample -qsip “# conf.gem '../mruby-direct‘end

Page 39: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mrubyポーティング ④ライブラリ化

�mrbgems動作確認用のアプリケーション作成�mrbgems動作確認用のアプリケーション作成�下記のソースコード (app.rb) を作成する。puts "mruby application start."Sample_QSIP::sample_qsip # mrbgems のメソッド呼び出しputs "mruby application end."

�mrubyコンパイラ (mrbc) でコンパイルする。�mrubyコンパイラ (mrbc) でコンパイルする。mrbc –Bappbin –o./app.c app.rb

出⼒された app.c はアプリケーションプロジェクトに追加する。

38

Page 40: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1

mrubyポーティング ④ライブラリ化

�mrbgems動作確認用のアプリケーション作成�mrbgems動作確認用のアプリケーション作成�下記のソースコードを作成して、mrbgems組込み済みのlibmruby.aとリンクして

QSIPアプリケーションを作成する。アプリケーションを含むファームウェアをQSIPボードQSIPアプリケーションを作成する。アプリケーションを含むファームウェアをQSIPボードに書き込んで実⾏する。QSIPアプリケーションからmrbgemsのメソッドが呼び出されることを確認する。

#include "mruby.h"#include "mruby/irep.h"#include <stdio.h>

void main(void){

extern uint8_t appbin[]; // app.c のアプリケーションバイナリを外部参照するmrb_state *mrb = mrb_open();printf ("mruby VM opened. ¥n");printf ("mruby VM opened. ¥n");

mrb_load_irep(mrb, appbin); // mruby アプリケーション実⾏printf("mruby application done.¥n");

mrb_close ( mrb);mrb_close ( mrb);printf("mruby VM closed.¥n");

}

39

Page 41: mruby VM ポーティング手順マニュアルmrubyポーティングの概要 mrubyポーティングの概要 QSIPボードにmrubyをポーティングする手順を以下に示す。1