hello worldが出来てとりあえずarmelのstatic linkなバイナリで動きそう
でも arm-linux-gnueabi-gcc
とか長い.動作確認に qemu-arm-static
を指定するのも面倒.
ということでarmelのchroot環境を作ってみたメモ.
※実機での動作確認はしていないので注意
※遅いのでRaspberry Piとか余っている人はそこにarmelなディストリビューションを導入して動かしたほうが速いかも?(hostPCが遅いだけではという可能性)
debootstrap
等でchroot環境を構築.
今回は debian-buster-armel
ディレクトリにDebian buster armel環境を構築
$ export HTTP_PROXY=192.168.1.102:3142 #option(この環境ではcaching proxyを立てている) $ mkdir debian-buster-armel $ fakeroot debootstrap --variant=minbase --arch armlf buster ./debian-buster-armel http://deb.ja.debian.org/debian
ここではDebian busterを指定したが,他のディストリビューションなども指定可能.例えば focal
を指定するとUbuntu 20.04 LTSになる.ただしarmelには対応していないので今回の目的には使えない.
指定可能なコードネームは /usr/share/debootstrap/scripts/
以下を参照のこと.
$ ls -w 80 /usr/share/debootstrap/scripts/ aequorea dapper intrepid oldstable testing amber dasyatis jaunty oneiric trusty artful debian-common jessie potato unstable ascii disco jessie-kfreebsd precise utopic bartholomea edgy kali quantal vivid beowulf eoan kali-dev raring warty bionic etch kali-last-snapshot sarge warty.buildd bookworm etch-m68k kali-rolling sarge.buildd wheezy breezy feisty karmic sarge.fakechroot wily bullseye focal lenny saucy woody buster gutsy lucid sid woody.buildd ceres hardy maverick squeeze xenial chromodoris hoary natty stable yakkety cosmic hoary.buildd oldoldstable stretch zesty
armel環境のバイナリを実行できるようにするために qemu-user-static
を導入
$ sudo apt install qemu-user-static
前準備
$ sudo mount --rbind /dev ./debian-buster-armel/dev $ sudo mount -t proc none ./debian-buster-armel/proc $ sudo mount --rbind /sys ./debian-buster-armel/sys $ cp /etc/hosts ./debian-buster-armel/etc/ $ cp /proc/mounts ./debian-buster-armel/etc/mtab
chrootしてほげほげ(以前はchroot前に対象archtectureのqemu-user-staticのbinaryをchroot環境にcpしてあげる必要があったが最近は不要)
$ sudo chroot ./debian-buster-armel /bin/bash # uname -a Linux t430s 5.7.0-2-amd64 #1 SMP Debian 5.7.10-1 (2020-07-26) armv7l GNU/Linux
exitでchrootから抜ける
# exit
unmount
$ sudo umount -l ./debian-buster-armel/sys $ sudo umount ./debian-buster-armel/proc $ sudo umount -l ./debian-buster-armel/dev
tty-clock
パッケージ情報
# apt show tty-clock Package: tty-clock Version: 2.3-1+b1 Priority: optional Section: utils Source: tty-clock (2.3-1) Maintainer: Antoine Beaupré <anarcat@debian.org> Installed-Size: 42.0 kB Depends: libc6 (>= 2.4), libncurses6 (>= 6), libtinfo6 (>= 6) Homepage: https://github.com/xorg62/tty-clock Tag: implemented-in::c, interface::text-mode, role::program, scope::utility, uitoolkit::ncurses, use::timekeeping Download-Size: 12.2 kB APT-Manual-Installed: yes APT-Sources: http://deb.debian.org/debian buster/main armel Packages Description: simple terminal clock tty-clock is a simple ncurses-based clock that shows the time and date using a large display. It has a few commandline options to customize the output.
buildのためのパッケージの導入
# apt instal build-essential
ソースパッケージの入手
# cd /usr/local/src/ #作業ディレクトリに移動 # apt update #パッケージ情報更新 # apt source tty-clock #ソースパッケージを入手する # cd tty-clock-2.3
tty-clockのbuildに必要なパッケージを導入
# apt build-dep tty-clok
Makefile
を修正してstaticになるようにしてmake
# cp -p Makefile Makefile.org # vi Makefile # diff -u Makefile.org Makefile --- Makefile.org 2017-01-15 03:21:24.000000000 +0000 +++ Makefile 2020-08-13 17:41:58.308261282 +0000 @@ -23,7 +23,7 @@ tty-clock : ${SRC} @echo "building ${SRC}" - ${CC} ${CFLAGS} ${SRC} -o ${BIN} ${LDFLAGS} + ${CC} -static ${CFLAGS} ${SRC} -o ${BIN} -static ${LDFLAGS} install : ${BIN} # make
出来上がったバイナリ
# file ./tty-clock ./tty-clock: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 3.2.0, BuildID[sha1]=d1d8dac5b81a912ee8f6524a9d1574be3ec7ed9f, with debug_info, not stripped # ldd ./tty-clock not a dynamic executable
qemu環境で動作するのを確認
# ./tty-clock
# ./tty-clock -s -x -c -S
マイコンに持っていくために圧縮して符号化する
# strip ./tty-clock # xz -9 -c ./tty-clock | base91 > ./tty-clock.xz.base91
※この手順だとDebin固有patchが当たらない.Makefileのpatchも作ってdebuildを使うようにしたほうがいい?
コメント