トップ «前の日記(2011-02-20) 最新 次の日記(2011-02-22)» 編集

ヨタの日々

2001|08|09|10|11|12|
2002|01|02|03|04|05|06|07|08|09|10|11|12|
2003|01|02|03|04|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|12|
2024|01|02|03|04|

2011-02-21 :-(

_

0500 起床 || {肩, 脚, 首}筋肉痛 | 腰痛

0830 出勤

_ 午後

1245 子供の教育にエロを応用すると驚異的な伸びを見せる(※ただし男子に限る)

1500 実機

_

1700 残業アワー

2000 退勤

2200 飯。牛丼

_ 価値

先日ブックオフにファミコン本体(初期じゃないアレ)、PS2(型番忘れた)、そして本をいくつか(学生のころ買った)売りに行ったんだが結局値段がついたのは PS2 の 600 円だけだった。岩波情報科学辞典は重要あるなら amazon で出品してもよかったか。

B0000648TM

4000800744

4000103555

4477016611

_ [NetBSD][翻訳][クロス開発]Cross-development with NetBSD

NetBSD でのクロス開発

Cross-Development with NetBSD Using NetBSD's new toolchain to develop for an embedded device

NetBSD の新しいツールチェインを使って組み込み機器をクロス開発する

Hubert Feyrer <hubert@feyrer.de>, October 2002

Introduction (はじめに)

When targeting a product for an embedded platform, it's not feasible to have all the development tools available on that same platform. Instead, some method of crosscompiling is usually used today. NetBSD 1.6 will contain (and NetBSD-current has today) a new framework to build both the operating system's kernel and the whole userland for either the same platform that the compiler runs on, or for a different platform, using crosscompiling. Crosscompiling requires assembler, linker, compiler etc. to be available and built for the target platform. The new build scheme will take care of creating these tools for a given platform, and make them available ready to use to do development work.

組み込み製品を開発するとき、同じプラットフォーム上ですべての開発ツールは利用できない。その代わり、最近はクロスコンパイル手法がよく使われる。NetBSD 1.6 ( と今の NetBSD-current ) には、同じプラットフォームでも異なるプラットフォームでもカーネルとユーザーランドをクロスコンパイルできるフレームワークがある。クロスコンパイルアセンブラ、リンカ、コンパイラなどを必要とする。これををターゲットのプラットフォーム向けに利用できるようにし、構築しておく。新しいビルドスキームはこうしたツールをターゲット向けに作成することができ、開発作業で使うために構築することができる。

Grabbing sources (ソースを取得する)

As an example, we will examine how to make a kernel for a Shark (StrongARM based system) from a machine running NetBSD/i386 in this article. The only requirement is that there is a fresh source tree of NetBSD-current checked out from CVS. "Fresh" here means that there should be no stale object files etc. in the tree - these can really get in the way here! The following commands can be used to get a copy of the -current branch checked out in /usr/cvs/src-current:

例として、ここでは NetBSD/i386 上で Shark (StrongARM based system) 向けのカーネルを構築してみよう。やり方は簡単だ。「最新」の NetBSD-current のソースツリーを CVS から取得すればよい。「最新」とは、安定していないといったことを意味する。ツリーはいまここで取得できるのさ。マジで。以下のコマンドは、-current ブランチをチェックアウトし、/usr/cvs/src-current にコピーする。

# mkdir /usr/cvs
# cd /usr/cvs
# env CVS_RSH=ssh cvs -d anoncvs@anoncvs.netbsd.org:/cvsroot co src
# mv src src-current

The process of crosscompiling a kernel consists of three steps, which we will describe in more detail below:

カーネルをクロスコンパイルするには 3 つの手順がある。以降で詳細を説明する。

1. Create toolchain for crosscompiling (compiler, assembler, linker, ...)
2. Configure kernel
3. Build

1. クロスコンパイルのためのツールチェイン( コンパイラ、アセンブラ、リンカ...)を作成する

2. カーネルを設定する

3. 構築する

Creating the Crosscompiler (クロスコンパイラを作成する)

The first step to do cross-development is to get all the necessary tools available. In NetBSD terminology, this is called the "toolchain", and it includes BSD-compatible make(1), C/C++ compilers, linker, assembler, config(8), as well as a fair number of tools that are only required when crosscompiling a full NetBSD release, which we won't cover here.

クロス開発の最初の手順は必要なツールを揃えることだ。ツールは、NetBSD では "toolchain" と呼ばれており、それには BSD 互換 make(1)、C/C++ コンパイラ、リンカ、アセンブラ、config(8) が含まれている。あと、NetBSD を完全にリリースするためだけにいくつかツールがあるのだが、ここでは割愛する。

The command to create the toolchain is quite simple, using NetBSD's new src/build.sh script:

toolchain を作成するコマンドはいたって簡単だ。NetBSD の src/build.sh スクリプトを使えばよい。

# cd /usr/cvs/src-current
# ./build.sh -m shark -u -t

This will build all the tools for the named target platform. Arguments used here are:

これで、指定されたターゲットプラットフォーム向けのツールを構築する。引数の意味はこう。

  • -m: define the machine, MACHINE
  • -u: update - only build files that have changed since last build
  • -t: only build the toolchain (i.e. the crosscompiler!)
  • -m: MACHINE として machine を定義する
  • -u: アップデートする。最後にビルドしてから変更があったファイルだけをビルドする
  • -t: toolchain だけをビルドする。( たとえばクロスコンパイラだ! )

During the build, object directories are used consistently, i.e. special directories are kept that keep the platform-specific object files and compile results. In our example, they will be kept in directories named "obj.shark" as we build for a Shark as target platform.

ビルド中はオブジェクトファイルが決められたディレクトリに作成される。たとえば、プラットフォーム独自のオブジェクトファイルとコンパイル結果が特殊なディレクトリに格納される。ここでは、Shark プラットフォーム向けのビルドなので "obj.shark" という名前のディレクトリが作成される。

The toolchain itself is part of this, but as it's hosted and compiled for a i386 system, it will get placed in it's own directory indicating where to cross-build from. Here's where our crosscompiler tools are located:

toolchain もこの中に入っているのだが、i386 上で i386 向けにコンパイルされたものも入っている。クロスビルドに使うための toolchain は独自のディレクトリに入っている。我々のクロスコンパイラツールは以下にある。

miyu# pwd
/usr/cvs/src-current
miyu# ls tools/obj.shark/
tools.NetBSD-1.6-i386

So the general rule of thumb is for a given "host" and "target" system combination, the crosscompiler will be placed in the "src/tools/obj.target/tools.host" directory by default. A full list of all tools created for crosscompiling the whole NetBSD operating system includes:

そして、通常は "host" と "target" の組み合わせが使われ、クロスコンパイラはデフォルトでは "src/tools/obj.target/tools.host" ディレクトリに配置される。NetBSD で作成されたクロスコンパイルツールの全リストはこう。

miyu# ls tools/obj.shark/tools.NetBSD-1.6-i386/bin/
arm--netbsdelf-addr2line  arm--netbsdelf-strings    nbmakefs
arm--netbsdelf-ar         arm--netbsdelf-strip      nbmakeinfo
arm--netbsdelf-as         nbasn1_compile            nbmakewhatis
arm--netbsdelf-c++        nbcap_mkdb                nbmenuc
arm--netbsdelf-c++filt    nbcompile_et              nbmkdep
arm--netbsdelf-cpp        nbconfig                  nbmklocale
arm--netbsdelf-dbsym      nbcrunchgen               nbmsgc
arm--netbsdelf-g++        nbctags                   nbmtree
arm--netbsdelf-g77        nbeqn                     nbpax
arm--netbsdelf-gasp       nbgencat                  nbpic
arm--netbsdelf-gcc        nbgroff                   nbpwd_mkdb
arm--netbsdelf-gcov       nbhost-mkdep              nbrefer
arm--netbsdelf-ld         nbindxbib                 nbrpcgen
arm--netbsdelf-lint       nbinfo                    nbsoelim
arm--netbsdelf-mdsetimage nbinstall                 nbtbl
arm--netbsdelf-nm         nbinstall-info            nbtexi2dvi
arm--netbsdelf-objcopy    nblex                     nbtexindex
arm--netbsdelf-objdump    nblorder                  nbtsort
arm--netbsdelf-ranlib     nbm4                      nbuudecode
arm--netbsdelf-readelf    nbmake                    nbyacc
arm--netbsdelf-size       nbmake-shark              nbzic

As you can see, most of the tools that are available natively on NetBSD are also available, with some program prefix to identify the target platform. (The naming here is a bit redundant due to the directory structure containing all the information, but the program names are created by the GNU based toolchain and were chosen not to be changed).

このように、ネイティブの NetBSD 上で使えるほとんどのツールが使えるようになっている。ターゲットプラットフォームの接頭字がついているプログラムがいくつかある。(ディレクトリ名で区別できるのでこの命名は冗長なのだが、これらは GNU ベースの toolchain で作成されたので名前を変更できないのである)

One important tool that should be pointed out here is "nbmake-shark". This is a shell wrapper for a BSD compatible make(1) command that's setup to use all the right commands from the crosscompiler toolchain. Using this wrapper instead of /usr/bin/make allows crosscompiling programs that were written using the NetBSD Makefile infrastructure (see src/share/mk). We will use this make(1) wrapper in a second!

"nbmake-shark" に注目。これが重要なツールだ。これは BSD 互換 make(1) をシェルでラップし、クロスコンパイラ toolchain のすべてのコマンドを設定するのに使う。NetBSD Makefile ( src/share/mk参照 ) と同じように書けば /usr/bin/make の代わりとしてクロスコンパイルプログラムを使うことができる。これでもう make(1) を使えるのさ!

Configuring the kernel (カーネルを設定する)

Now that we have a working crosscompiler available, the "usual" steps for building a kernel are needed - config, then build. As the config(8) program used to create header files and Makefile for a kernel build is platform specific, we need to use the "nbconfig" program that's part of our new toolchain. That aside, the procedure is just as like compiling a "native" NetBSD kernel. Commands involved here are:

すでにクロスコンパイラが使えるようになっている。カーネルをビルドする「通常の」手順では config をしてからビルドをする。config(8) プログラムは、プラットフォーム独自のカーネルをビルドするためのヘッダーファイルと Makefile を作成する。そのために "nbconfig" を使う。これは新しい toolchain に含まれているプログラムだ。ネイティブな NetBSD カーネルをコンパイルするのと同じ手順で出来るのである。コマンドはこう。

# cd /usr/cvs/src-current/sys/arch/shark/conf/
# /usr/cvs/src-current/tools/obj.shark/tools.NetBSD-1.6-i386/bin/nbconfig GENERIC

That's all. This command has created a directory "../compile/GENERIC" with a number of header files defining information about devices to compile into the kernel, a Makefile that is setup to build all the needed files for the kernel, and link them together. As the Shark port uses ELF as execution format but the Shark's OpenFirmware can only load a.out kernels, that Makefile will also convert the kernel from ELF to a.out once it's built.

以上。このコマンドは "../compile/GENERIC" ディレクトリを作成し、カーネルでデバイスを使うための情報を定義したいくつかのヘッダーファイルを格納する。Makefile にはカーネルが必要とする全てのファイルを作成、リンクする。Shark ポートは実行形式として ELF を使うのだが、Shark の OpenFirmware は a.out 形式のカーネルしかロードできない。Makefile ではカーネルを ELF から a.out 形式へ変換する。

More information about building NetBSD kernels can be found at http://www.netbsd.org/Documentation/kernel/.

NetBSD カーネルのビルドの詳細は http://www.netbsd.org/Documentation/kernel/ を参照。

Crosscompiling the kernel (カーネルをクロスコンパイルする)

We have all the files and tools available to crosscompile our ARM-based kernel from our Intel-based host system, so let's get to it! After changing in the directory created in the previous step, we need to use the crosscompiler toolchain's "nbmake-shark" shell wrapper, which just calls make(1) with all the necessary settings for crosscompiling for a shark:

これで Intel ベースのホストシステム上で ARM ベースのカーネルをクロスコンパイルするためのファイルやツールが全て揃った。あとはやるだけだ。先の手順で作成されたディレクトリへ移動しよう。クロスコンパイラ toolchain のシェルラッパー "nbmake-shark" がある。shark のクロスコンパイルに必要な設定をおこない、make(1) を呼び出すだけだ。

# cd ../compile/GENERIC/
# /usr/cvs/src-current/tools/obj.shark/tools.NetBSD-1.6-i386/bin/nbmake-shark

This will churn away a bit, then spit out a kernel:

いくつか印字し、カーネルを出力する。

...
text    data    bss     dec     hex     filename
1687520 69632   184576  1941728 1da0e0  netbsd.aout
miyu# ls -la netbsd.aout
-rwxr-xr-x  1 root  wheel  1757216 Mar 27 02:55 netbsd.aout
miyu# file netbsd.aout
netbsd.aout:    NetBSD/arm32 demand paged executable

Now the a.out(!) kernel can either be transferred to a shark (via NFS, FTP, scp, etc.) and booted from a possible harddisk, or directly from our cross-development machine using NFS. Be sure to actually use the a.out kernel, as the Shark's firmware cannot use the one in ELF format.

これで a.out カーネルを shark へ転送し( NFS、FTP、scp などで ) ハードディスクから起動したり、クロス開発用マシンから NFS で直接起動させることができる。Shark のファームウェアは ELF 形式を扱えないので a.out カーネルを使うこと。

Crosscompiling the whole Operating System (オペレーティングシステム全体をクロスコンパイルする)

Of course you can not only crosscompile the NetBSD kernel, but the whole system. This is as easy as:

もちろん NetBSD カーネルだけをクロスコンパイルできるわけじゃない。システム全体をクロスコンパイルできる。以下のように簡単だ。

$ ./build.sh -m shark -d \
                -D /usr/tmp/shark-root \
                -R /usr/tmp/shark-release

This command will first build a crosscompiler, as described above. After that it will crosscompile the whole operating system including all libraries, binaries, etc. To make things complete, kernels for installing and running the systems will be built, and everything will be packed into distribution sets & install media, so a full NetBSD release is available i /usr/tmp/shark-release after that command!

このコマンドは、先ほど述べたように最初にクロスコンパイラをビルドする。それからライブラリ、バイナリなどを含めたシステム全体をクロスコンパイルする。完了したら、カーネルをインストールし、システムを走らせるために、sets とインストールメディアに圧縮する。そして /usr/tmp/shark-release を実行すれば NetBSD のフルリリースが出来上がるのさ!

Too easy? Sorry, but that's NetBSD! :-)

NetBSD なら簡単でしょ? :-)

Summary (まとめ)

So much for our small example on how to use the new build framework to do cross development of a kernel for and with NetBSD. Let me re-emphasize at this point again that the toolchain produced in the first step is capable of (re)building the complete NetBSD operating system including libraries and programs, not only the kernel. More information on building the whole operating system can be found in src/BUILDING. More documentation is also available as src/tools/compat/README, which has special emphasize on setting up crosscompiling from various host operating systems, i.e. Solaris and Linux besides NetBSD.

ここでは少しの例で NetBSD 上で NetBSD カーネルをクロス開発するためのビルドフレームワークの使い方を示した。最初の手順で使った toolchain をおさらいしておくと、toolchain は NetBSD カーネルだけでなくライブラリやプログラムを含めた NetBSD オペレーティングシステム全体の構築(再構築も)に使う。オペレーティングシステム全体の構築についてのもっと詳しい情報は src/BUILDING にある。NetBSD だけでなく Solaris や Linux など様々なホストオペレーティングシステム上でのクロスコンパイルについての文書は src/tools/compat/README にある。

(c) Copyright 20020110 Hubert Feyrer <hubert@feyrer.de>

$Id: xdev.html,v 1.6 2002/10/15 23:46:15 feyrer Exp $