uClinux for m68k

Last modified: Dec 5, 2002
OKAZAKI Atsuya (okazaki@tl.cc.uec.ac.jp)

uCsimm uCdimm uClinuxをuCdimm DragonBall VZ, uCsimm Dragonball EZで触ったときのメモ。
uCdimm, uCsimmのパッケージに含まれていたCD-ROMの開発環境(m68k-coff)の使い方と m68k-coffからm68k-elfに移行した後の開発環境の構築方法と利用方法についての文書。

Table of Contents

m68k-coff

パッケージに含まれていたLineoのCD-ROMから開発環境を構築。 構築、利用方法は同梱されていた"uCdimm DragonBall VZ Hardware/Software Manual", "uCsimm/uC68EZ328 Hardware/Software Manual"を参照。 自分でsourceから開発環境を構築したい場合は、
Beyond Logic
http://www.beyondlogic.org/
uClinux - Part 1 : Setting up the Development Environment (2.0.38)
uClinux - Part 2 : Understanding the Build Tools
が参考になりそう。 ただ、新しいライブラリやカーネルを使うならm68k-elfに移行した方がよさそう。

Boot uClinux

ROM imageをROMに焼き込んでuClinuxを起動。

uCdimm

PC (Linux)からuCdimmのシリアルコンソールを叩くには、 RS232Cストレートケーブルで接続して、シリアル通信プログラムが必要になる。 ここではminicomを使った。 後々xmodemというプロトコルを用いてファイル転送をするためにこれを選択した。 他にkermitなど使えるかもしれないが、試していない。

minicomはrootでないと/var/logにlock fileを作れないために一般userが起動すると怒られる。 その場しのぎであるが、自分のhome directoryにlock fileを作る設定にした。 /etc/minirc.dlfなどというファイルに設定されている。 直接編集してもrootmでminicom -sでも設定できる。 さらに/dev/ttyS0を使用しようとすると/minirc._dev_ttyS0が無いと怒られるのでシンボリックリンクを張った。
# ln -s /etc/minirc.dfl /etc/minirc._dev_ttyS0
$ minicom -o -c on /dev/ttyS0
(ここでuCdimm 電源ON)
uCbootstrap v1.5.8 (c) Copyright 1999-2000 Rt-Control Inc.
                   (c) Copyright 2000-2001 Lineo, Inc.
All Rights Reserved.
FLASH type 00c0 [AT49BV1614]
DP|002000 DP|004000 DP|006000 DP|008000 DP|00a000 DP|00c000 
DP|00e000 D-|010000 D-|018000 D-|020000 D-|030000 D-|040000 
D-|050000 D-|060000 D-|070000 D-|080000 D-|090000 D-|0a0000 
D-|0b0000 D-|0c0000 D-|0d0000 D-|0e0000 D-|0f0000 D-|100000 
D-|110000 D-|120000 D-|130000 D-|140000 D-|150000 D-|160000 
D-|170000 D-|180000 D-|190000 D-|1a0000 D-|1b0000 D-|1c0000 
D-|1d0000 D-|1e0000 D-|1f0000 D-|200000 
B$ help

   Simple Help
sh: invoke a new shell
exit: exit from the current shell
help: display this command list
printenv: display the contents or envornment var
setenv: set or replace an environment var
eraseenv: erase all environment vars
pmask: set the protection mask
rx: receive XMODEM into the RAM buffer
program: erase OS, then burn OS from RAM buffer
verify: compare OS FLASH image to the RAM buffer
go: execute the OS image
goram: execute an image in ram
fast: change to 115200bps
slow: change to 19200bps
md: dump memory
mm: memory modify
envmm: memory modify from environment vars

B$ fast
baud set to:: 115200bps
(C-a p i)
uCbiitstrap (Bootloader)起動。コマンドはhelpと打つと一覧が取り出せる。 また、この表示が文字化けしてしまっった場合はボーレートの設定がうまく言っていないので、 C-a zでminicomのhelpを読んで設定する。 ちなみに
19200bps: C-a p f RET
115200bps: C-a p i RET

となる。(C-aはCtrl押しながらaという意味)
fastというコマンドをuCdimmに送ることによって、115200bpsの通信が可能になる。
B$ rx
(ここでimage.binをxmodemプロトコルで転送。C-a s, xmodem, fileを選択)
(115200bpsだと転送に失敗することが多々あった。)
B$ verify
verify...
done.
B$ program
erase..-done.
write../done.
B$ go
go!
O0T
68VZ328 DragonBall VZ support (c) 2001 Lineo Canada Corp.
(以下略)
(uClinux起動。bood画面途中からボーレートが19200bpsに戻るので設定しなおし。)

uCsimm

uCsimmの場合9600bps

m68k-elf

m68kはcoffからelfに移行したよう。 最初、これを知らずにcoffで新しいuClibc, uClinux, gccなどを使おうとしてはまる。 elfでならすんなり環境を構築できた。
m68k-elfを使って、uCdimm, uCsimmでuClinuxを動作させる。

Building gcc m68k-elf for uClinux

m68k-elfの開発環境構築

Reference

www.uclinux.org
http://www.uclinux.org/pub/uClinux/m68k-elf-tools/
http://www.uclinux.org/pub/uClinux/m68k-elf-tools/README-20020410

Beyond Logic
http://www.beyondlogic.org/
uClinux - Building gcc-2.95.3 m68k-elf for uClinux

Uwe's Personal uClinux pages
http://www.imbrium.de/uclinux/

Building

http://www.uclinux.org/pub/uClinux/m68k-elf-tools/
m68k-elf-tools-20020410.tar.gz
としてbinaryで開発環境が配布されている。 これは展開するだけで利用可能だが、 自分の環境ではうまくgccが動かなかったりしたのでsourceからmakeすることにする。
http://www.uclinux.org/pub/uClinux/m68k-elf-tools/README-20020410 を参照。
binutils-2.10.tar.bz2
binutils-2.10-full.patch
gcc-2.95.3.tar.bz2
gcc-2.95.3-full.patch
gcc-2.95.3-arm-pic.patch
gcc-2.95.3-arm-pic.patch2
gcc-2.95.3-arm-mlib.patch
gcc-2.95.3-sigset.patch
genromfs-0.5.1.tar.gz
elf2flt tree
uClibc tree
uClinux kernel (2.0/2.4) tree (linux kernel sourceにuClinuxパッチをあてる)
を用意してbuild-uclinux-tools.shを走らせれば開発環境が出来あがる。
$ tar zxvf elf2flt-20020214.tar.gz
$ tar zxvf uClibc.tar.gz
$ tar Ixvf linux-2.4.19.tar.bz2
$ gunzip uClinux-2.4.19-uc1.diff.gz
$ cp -rv linux-2.4.19 uClinux-2.4.19 (あとで見るかもしれないので、linuxのkernelを保管しておく)
$ cd uClinux-2.4.19
$ patch -p1 < ../uClinux-2.4.19-uc1.diff
$ cd ..
$ make ARCH=m68knommu oldconfig
$ make dep
$ vi build-uclinux-tools.sh
変更個所 ELF2FLT="$BASEDIR/elf2flt-20020214" UCLIBC="$BASEDIR/uClibc" KERNEL="$BASEDIR/uClinux-2.4.19" TARGET=m68k-elf PREFIX=/usr/local
$ ./build-uclinux-tools.sh build $ ./build-uclinux-tools.sh uclibc
動作確認 (sample C program: gethostname.c, gethostbyname.c)
$ m68k-elf-gcc -msep-data -m68000 -c gethostname.c
$ m68k-elf-ld.real -d -r -o gethostname.tmp
/usr/local/m68k-elf/lib/crt0.o gethostname.o
/usr/local/m68k-elf/lib/m68000/msep-data/libc.a
/usr/local/lib/gcc-lib/m68k-elf/2.95.3/m68000/libgcc.a
$ m68k-elf-ld.real -T /usr/local/m68k-elf/lib/elf2flt.ld -Ur -o
gethostname.elf gethostname.tmp 
$ m68k-elf-ld.real -T /usr/local/m68k-elf/lib/elf2flt.ld -o
gethostname.gdb gethostname.tmp
$ elf2flt -o gethostname -p gethostname.gdb gethostname.elf
ERROR: 
(error大量(略)。しかし、gethostnameは出来ている。)
$ elf2flt -r -o gethostname2 gethostname.elf
ERROR: 
(error大量(略)。しかし、gethostname2は出来ている。)

(省略して?) $ m68k-elf-gcc -Wl,-elf2flt -m68000 -o gethostbyname gethostbyname.c -lc $ m68k-elf-gcc -Wl,-elf2flt -m68000 -msep-data -o gethostbyname gethostbyname.c -lc

uCdot FAQ: What is the difference between uC-libc and uClibc

http://www.ucdot.org/article.pl?sid=02/08/21/1124218
の和訳(英語が苦手で嘘訳っぽいので対訳。?と思ったら英語を読んでください)。

There are two libc libraries commonly used with uClinux. uC-libc and uClibc. They are quite different despite their similar names. Here is a quick overview of how they are different.

uClinuxでは一般的にuC-libcとuClibcの二つのlibcが使われている。 これらは似たような名前にも関わらず、大きな違いがある。 両者にどのような違いがあるのか簡単な説明をする。

uC-libc is the original library for uClinux. It was based on sources from the Linux-8086 C library which was part of the ELKs project with m68000 support added by Jeff Dionne and Kenneth Albanowski. It is a fairly complete libc implementation, however, some of the API's are a little non-standard and quite a few common libc routines are not present. Currently it has stable support for m68000, ColdFire and ARM (Non-MMU) architectures. It was primary design goal is to be small and light weight. It does try to conform to any standards, although its API tries to be compatible with most libcs, it is not always exactly the same.

uC-libcはuClinux独自のライブラリである。これはJeff DionneとKenneth Albanowskiによってm68000をサポートしたELKsプロジェクトの一部である Linux-8086 C ライブラリのソースコードに基づいている。これは完全にlibc の実装であるが、APIによっては少し非標準で、非常に少ない一般的なlibcに はないものがある(訳注; 誤訳かも?)。現在、m68000とColdFire、ARM (Non-MMU)のアーキテクチャをサポートしている。設計の第一の目標は小さく、 軽い動作である。標準に準拠しようとしていて、APIははほとんどのlibcに互 換性があるように努力しているが、正確に同じ物とはなっていない。

uClibc is a derivative of uC-libc designed to fix the problems with uC-libc. It makes all the API's standard (correct types, args, etc), fills in many of the missing routines, and has been ported to a lot of architectures. In general it tries to provide glibc compatibility so that porting applications to the smaller uClibc is quite easy. It can be used on standard VM Linux and uClinux. To make it even more compact it can also be compiled as a shared library on most platforms with MMU support Erik Andersen has been the driving force behind uClibc and has done a great job. uClibc supports a large array of processors: m68000, Coldfire, ARM, MIPS, v850, x86, i960, Sparc, SuperH, Alpha, PowerPC and Hitachi 8. uClibc is much easier to adapt to a new architecture and its ever growing platform support is testimony to this.

uClibcはuC-libcの問題をフィックスするためのuC-libcの派生したライブラリ である。すべてのAPIを標準に準拠し、実装されていな多くのルーチンを埋め、 多くのアーキテクチャに移植されてきた。より小さいuClibcにアプリケーショ ンを移植しやすいように、全体的にglibc互換を提供しようとしている。 standard VM LinuxとuClinuxで動作可能。もっとコンパクトにするために、 Erik Andersenの努力とすばらしい成果によってMMUを持ったほとんどのプラッ トフォーム上で共有ライブラリとしてもコンパイル出来る。uClibcは多くのプ ロセッサ(m68000, Coldfire, ARM, MIPS, v850, x86, i960, Sparc, SuperH, Alpha, PowerPC, Hitachi 8)をサポートしている。uClibcは新しいアーキテク チャに対応するのがとても簡単になっていて、多くのプラットフォームに対応 していくことがその証である。

The uClinux distribution provides an environment that can compile using either uC-libc or uClibc depending on your needs. For m68000 and Coldfire platforms it is generally better to chose uC-libc as it supports shared libraries and is the most commonly used libc for these CPUs. uClibc also works quite well with almost all platforms supported by the distribution. Which libc you choose to use will be decided by your requirements.

uClinuxは開発者の需要によってuC-libcかuClibcのいずれかでコンパイル出来 る環境を提供している。m68000とColdfireプラットフォームでは共有ライブラ リをサポートしているし、これらのCPUでは最も一般的なlibcであるから、 uC-libcを選ぶのが一般的には良い。uClibcもまたディストリビューションに よってサポートされた多くのプラットフォームでとても良く動作する。どちら のlibcを利用するかはあなたの要求によるでしょう。

Building Operating System

m68k-elfのクロス開発環境でuClinux (patch -> linux-2.4.19)をコンパイルし、uCdimmに焼き込む。

Reference

Beyond Logic
http://www.beyondlogic.org/
uClinux - Part 2 : Understanding the Build Tools
(m68k-coff(古い)だけど役に立ちそう)
uClinux - Building gcc-2.95.3 m68k-elf for uClinux
uClinux - BFLT Binary Flat Format

Uwe's Personal uClinux pages
http://www.imbrium.de/uclinux/

uClinux-dist

a complete source distribution package for uClinux [www.uclinux.org] をdownload。 vendorとマシン名(基板名)を指定し、kernelとuser land programをcompileする。 ROM imageまで生成してくれる。
$ tar zxvf uClinux-dist-20020927.tar.gz
$ cd uClinux-dist
$ make menuconfig (xconfigだと、うまくvenderとか選べなかった。"Arcturus/uCdimm"を選択)
$ make dep
# mkdir /tftpboot
$ make
$ cd images
$ ls
image.bin  linux.data  linux.text  romfs.img
$ minicom
# fast
(C-a p I (set 115200bps))
# rx
(C-a s (send image.bin))
# program
# go
(boot 略)
# dmesg
Linux version 2.4.19-uc1 (okazaki@com) (gcc version 2.95.3 20010315 (release)
(ColdFire patches - 20010318 from http://fiddes.net/coldfire/)
(-msep-data patches)) #7 2002年10月17日(木) 15時31分38秒 JST

68VZ328 DragonBallVZ support (c) 2001 Lineo, Inc.
uCdimm serial string [991073836-01e7d]
uCdimm hwaddr 00:50:c2:03:6e:7d


uClinux/MC68VZ328
uCdimm by Lineo, Inc. 
M68VZ328 support by Evan Stawnyczy 
Flat model support (C) 1998,1999 Kenneth Albanowski, D. Jeff Dionne
On node 0 totalpages: 1536
zone(0): 0 pages.
zone(1): 1536 pages.
zone(2): 0 pages.
Kernel command line: 
Calibrating delay loop... 3.30 BogoMIPS
Memory available: 5696k/6016k RAM, 0k/0k ROM (573k kernel code, 236k data)
Dentry cache hash table entries: 1024 (order: 1, 8192 bytes)
Inode cache hash table entries: 512 (order: 0, 4096 bytes)
Mount-cache hash table entries: 512 (order: 0, 4096 bytes)
Buffer-cache hash table entries: 1024 (order: 0, 4096 bytes)
Page-cache hash table entries: 2048 (order: 1, 8192 bytes)
POSIX conformance testing by UNIFIX
Linux NET4.0 for Linux 2.4
Based upon Swansea University Computer Society NET3.039
Initializing RT netlink socket
Starting kswapd
pty: 256 Unix98 ptys configured
MC68328 serial driver version 1.00
ttyS0 at 0xfffff900 (irq = 2) is a builtin MC68328 UART
cs89x0:cs89x0_probe(0x0)
cs89x0: Setting up uCcs8900 Chip Select & IRQ ioaddr = 0x10000300
cs89x0.c: v2.4.3-pre1 Russell Nelson , Andrew Morton 
eth0: cs8900 rev J found at 0x10000300 
cs89x0 media RJ-45, IRQ 20, programmed I/O, MAC 00:50:c2:03:6e:7d
cs89x0_probe1() successful
Blkmem copyright 1998,1999 D. Jeff Dionne
Blkmem copyright 1998 Kenneth Albanowski
Blkmem 1 disk images:
0: 10CC5820-10D7881F [VIRTUAL 10CC5820-10D7881F] (RO)
RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize
NET4: Linux TCP/IP 1.0 for NET4.0
IP Protocols: ICMP, UDP, TCP
IP: routing cache hash table of 512 buckets, 4Kbytes
TCP: Hash tables configured (established 512 bind 512)
NET4: Unix domain sockets 1.0/SMP for Linux NET4.0.
VFS: Mounted root (romfs filesystem) readonly.
eth0: using half-duplex 10Base-T (RJ-45)
#

sample program

uCdimmとuCevolution (開発ボード)でPD0のLEDをUser Landのプログラムで最高速で点滅させてみる。 PD0をオシロスコープで観測した記録を掲載。
Makefile
max.c
#include <stdio.h>
#include <asm/MC68VZ328.h>

int main(int argc, char *argv[])
{
    PDSEL |= 0x01; /* Select the I/O function for PD0 */
    PDDIR |= 0x01; /* Set PD0 to output */

    puts("Let there be Blinking Lights!");

    while(1){
	PDDATA ^= 0x01; /* Toggle PD0 */
    }
}
アセンブラで書いた方が速いかも。(いやいやcompilerのoptimizationにまかせる?)
ということで、CFLAGS-Oを追加したら、 上記波形写真で 1/ΔX = 149kHzになっているところが、259kHzになった! -O2にしても同じ結果。

uClinux 2.4.19 for uCsimm

uCdimmでは起きなかったが、uCsimmはuClinux 2.4.19だと asm/MC68VZ328.hで定義されているようなレジスタにUser Landのプログラムからアクセスすると SIGSEGVで落ちてしまう。
原因はlinux 2.4.xから導入されたRegister protectらしい。 確か、2.2.xの時は起らなかった。

Glossary

PIC (Position Independent Code)
BFLT (Binary Flat format)
XIP (eXecute In Plase)
FLT (Flat Binary)
elf2flt (elf to Flat Binary Converter)
coff2flt (COFF - Common Object File Format to Flat Binary Converter)

Reference

uClinux

www.uclinux.org
www.uclibc.org
www.ucdot.org

John R. Levine "Linker & Loaders", Ohmsha
www.uclinux.com
小型組み込み機器向けLinux kumikomi.net
藤広哲也『組み込み型Linux 導入・開発ガイド』すばる舎 第6章 Pp.165-194
www.lineo.com
www.lineo.co.jp

uCdimm

LINEO uCdimm DragonBall VZ Hardware/Software Manual
www.ucdimm.com
Motorola, MC68VZ328 User's Manual
Software Design 2001 11 Pp.104-

uCsimm

LINEO uCsimm/uC68EZ328 Hardware/Software Manual
Software Design Linux Issue "すみからすみまでLinux テクニカル編" Pp.122-

back