2018/05/05

モニタ、キーボードなしでRaspberryPiにraspbianをインストールする(改訂版)

最新のRaspbian Stretchは仕様変更があったようで昔の手順ではうまく出来なくなってしまいましたので手順を最新化して再掲します。

変更点は下記です。
  • 固定IPの設定方法変更 : etc/network/interface から /etc/dhcpcd.conf に変更
  • ssh有効化手順追加 : Raspbian Stretchは「デフォルトssh無効」に変わったため

RaspbanをインストールするにはモニタとキーボードをRaspberryPiに接続する必要があります。しかし、つなぐのは面倒なのでSSH経由でraspbianの初期設定する方法を試してみましたので備忘録を兼ねて紹介します。

■用意するもの

  • Linuxマシン
  • SDカードリーダ

■OSイメージをダウンロード

Linuxマシン上での作業です。
まずはOSイメージをミラーサイトからダウンロードします。
$ wget http://ftp.jaist.ac.jp/pub/raspberrypi/raspbian/images/raspbian-2018-04-19/2018-04-18-raspbian-stretch.zip
$ wget http://ftp.jaist.ac.jp/pub/raspberrypi/raspbian/images/raspbian-2018-04-19/2018-04-18-raspbian-stretch.zip.sha256
$ sha256sum -c 2018-04-18-raspbian-stretch.zip.sha256
2018-04-18-raspbian-stretch.zip: 完了

■イメージファイルをマウントする

Linuxマシン上での作業です。
raspbianのIPアドレスを固定するため、イメージファイルをマウントして設定ファイルを書き換えます。
$ unzip 2018-04-18-raspbian-stretch.zip
$ fdisk -l 2018-04-18-raspbian-stretch.img
Disk 2018-04-18-raspbian-stretch.img: 4.6 GiB, 4953473024 bytes, 9674752 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x9cba179a

Device                           Boot Start     End Sectors  Size Id Type
2018-04-18-raspbian-stretch.img1       8192   96453   88262 43.1M  c W95 FAT32 (LBA)
2018-04-18-raspbian-stretch.img2      98304 9674751 9576448  4.6G 83 Linux

  • 2018-04-18-raspbian-stretch.img1 : raspbian上では"/boot"にマウントされる
  • 2018-04-18-raspbian-stretch.img2 : raspbian上では"/"にマウントされる
ここからはrootでの作業です。
# mount -o loop,offset=50331648 2018-04-18-raspbian-stretch.img /mnt/

オフセットの値はfdisk中の98304にセクタサイズ512を掛けた値。

■ネットワーク関係のファイルを変更

ファイルのオーナがrootなのでrootになって作業します。
("xxx"部分は自分のネットワーク環境に合わせて適宜書き換える)

# vi /mnt/etc/dhcpcd.conf

・変更前
# Example static IP configuration:
#interface eth0
#static ip_address=192.168.0.10/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.0.1
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1

・変更後
# Example static IP configuration:
interface eth0
static ip_address=xxx.xxx.xxx.xxx/xx
#static ip6_address=fd51:42f8:caae:d92e::ff/64
static routers=xxx.xxx.xxx.xxx
static domain_name_servers=xxx.xxx.xxx.xxx

# umount /mnt

■sshを有効化

raspbian上の/bootに"ssh"というファイルを置くとsshが有効化されます。
# mount -o loop,offset=4194304 2018-04-18-raspbian-stretch.img /mnt/
オフセットの値はfdisk中の8192にセクタサイズ512を掛けた値。

# touch /mnt/ssh
# umount /mnt

■SDカードに書き込む

LinuxマシンからSDカードにイメージファイルを書き込みむ。("/dev/sdb"は自分の環境に合わせて適宜書き換える)

# dd bs=16M status=progress if=2018-04-18-raspbian-stretch.img of=/dev/sdb

■Raspberry PiにSDカードを挿入して起動する

Linuxマシンからssh経由でRaspberry Piにログインする。(user=pi, passwd=raspberry, xxx.xxx.xxx.xxxは先に設定したIPアドレス)
各種設定をする。
$ ssh pi@xxx.xxx.xxx.xxx
pi@xxx.xxx.xxx.xxx's password: raspberry
pi@raspberrypi ~ $ sudo raspi-config

これで完了です。

RaspberryPiにCUI版Emacsをインストールする

標準のEmacsではGUI対応のため、沢山のパッケージがインストールされます。ssh経由でしかEmacsを使用しないなどGUI不要の場合は"emacs-nox"をインストールすると良いです。XをサポートしないEmacsなので、インストールされるパッケージが少ないです。
# apt update
# apt install emacs-nox

■emacs-noxについて

GNU Emacs editor (metapackage, without X support)

■補足

emacs-noxではホイールマウスの設定は使えないようです。
.emacsの該当部分をコメントアウトする
;;;; ホイールマウス
;(mouse-wheel-mode t)
;(setq mouse-wheel-follow-mouse t)

2017/12/03

Raspberry PiのAVR開発環境を最新化する

より良い方法があったのでこちらをご覧ください。


先日、avr-libcのHomePageを眺めていた時にtime.hを見つけました。time.hはその名の通り時刻に関する操作を行うライブラリです。時計を作るのに使えそうだなと思い、簡単なコードを書いてコンパイルしたところコンパイラが"time.hがない"と言うではありませんか! ソースコードを確認したけどスペルミスはない。「またまた、ご冗談を…」と/usr/lib/avr/include/を覗いてみたところ確かに無かった。(絶句)

どうやらavr-libcのバージョンが異なるのが原因のようです。

  • avr-libcのHomePageの最新バージョンはv2.0.0
  • Raspberry Piにインストールされているavr-libcバージョンはv1.8
そこでRaspberry PiのAVR開発環境を最新化することにしました。

(1)最新化に必要なソフト


せっかくなのでgccも最新化します。

・binutils-2.29.1.tar.xz
 https://www.gnu.org/software/binutils/

・gcc-7.2.0.tar.xz
 https://gcc.gnu.org/

・gmp-6.1.2.tar.xz
 https://gmplib.org/

・mpfr-3.1.6.tar.xz
 http://www.mpfr.org/

・mpc-1.0.3.tar.gz
 http://www.multiprecision.org/index.php?prog=mpc

・avr-libc-2.0.0.tar.bz2
 http://www.nongnu.org/avr-libc/

・avr-size用パッチ
 https://gist.github.com/larsimmisch/4190960

(2)コンパイル手順


avr-libcのHomePageにコンパイル手順の説明があります。基本的にこの手順で実施すればOKです。

(2-1)環境設定


$ mkdir ~/local
$ PREFIX=$HOME/local
$ export PREFIX
$ PATH=$PATH:$PREFIX/bin
$ export PATH

(2-2)GNU Binutilsのコンパイル


$ cd ~/src/avr
$ wget https://ftp.gnu.org/gnu/binutils/binutils-2.29.1.tar.xz
$ tar xvf binutils-2.29.1.tar.xz
$ wget https://gist.github.com/larsimmisch/4190960/archive/16c6b9627f8451eeebd644a4b9a741edfdb0c45e.zip
$ unzip 16c6b9627f8451eeebd644a4b9a741edfdb0c45e.zip
$ cd binutils-2.29.1/binutils
$ patch -u < ../../4190960-16c6b9627f8451eeebd644a4b9a741edfdb0c45e/avr-binutils-size.patch
$ cd ..
$ mkdir obj-avr
$ cd obj-avr/
$ ../configure --prefix=$PREFIX --target=avr --disable-nls
$ make -j4
$ make install

(2-3) GNU gmpのコンパイル


gccをコンパイルするためにはgmp, mpfr, mpcが必要なため、先にコンパイルします。
$ cd ~/src/avr
$ wget https://gmplib.org/download/gmp/gmp-6.1.2.tar.xz
$ tar xvf gmp-6.1.2.tar.xz
$ cd gmp-6.1.2/
$ ./configure --prefix=$PREFIX
$ make -j4
$ make -j4 check
$ make install

(2-4) GNU mpfrのコンパイル


$ cd ~/src/avr
$ wget http://www.mpfr.org/mpfr-current/mpfr-3.1.6.tar.xz
$ tar xvf mpfr-3.1.6.tar.xz
$ cd mpfr-3.1.6
$ ./configure --prefix=$PREFIX --with-gmp-build=../gmp-6.1.2
$ make -j4
$ make -j4 check
$ make install

(2-5) GNU mpcのコンパイル


$ cd ~/src/avr
$ wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
$ tar xvf mpc-1.0.3.tar.gz
$ cd mpc-1.0.3
$ ./configure --prefix=$PREFIX --with-gmp=$PREFIX --with-mpfr=$PREFIX
$ make -j4
$ make -j4 check
$ make install

(2-6) gccのコンパイル


$ cd ~/src/avr
$ wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-7.2.0/gcc-7.2.0.tar.xz
$ tar xvf gcc-7.2.0.tar.xz
$ cd gcc-7.2.0/
$ mkdir obj-avr
$ cd obj-avr
$ ../configure --prefix=$PREFIX --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp --with-dwarf2 --with-gmp=$PREFIX --with-mpfr=$PREFIX --with-mpc=$PREFIX
$ make -j4
$ make install

(2-7)avr-libcのコンパイル


$ cd ~/src/avr
$ wget http://download.savannah.gnu.org/releases/avr-libc/avr-libc-2.0.0.tar.bz2
$ tar xvf avr-libc-2.0.0.tar.bz2
$ cd avr-libc-2.0.0/
$ ./configure --prefix=$PREFIX --build=`./config.guess` --host=avr
$ make -j4
$ make install

2017/11/12

Raspberry PiでAVR開発

 以前にdebianのAVR開発環境を紹介しましたが、Raspberry Piでも同じ手順でAVR開発環境が作れます。

■Raspberry Pi(Raspbian)でAVR開発環境を構築する手順

# apt update
# apt upgrade
# apt install gcc-avr binutils-avr avr-libc avrdude
 Raspberry PiでAVR開発するメリットは、「ソース修正→ISP書き込み」が気軽にどこでもできるということに尽きます。Raspberry Piに移行する前はノートPCのAVR開発環境にAVRISPmkIIを接続してデバッグしていたのですが、この場合、開発対象とノートPCをAVRISPmkIIのケーブルが届く範囲に留める必要があり、結局のところ、開発対象の近くにノートPCを持っていくしかありませんでした。
 Raspberry PiにAVR開発環境を置く場合、ノートPCは作業机に、Raspberry Piは開発対象の近くに設置し、ノートPCとRaspberry Pi間はイーサネット(無線LANでもOK)で接続し、SSHでRaspberry Piにログインして作業することができます。

バーニングシップフラクタル

bsf.knit 今回は『バーニングシップフラクタル』についての備忘録です。 バーニングシップフラクタルとは? Wikipedia ...