出典: M5Stack UnitV2でロボットを動かす(下準備):ししかわの二足ロボ研修 Part.4
Buildroot
出典に基づき確認を行った。
UnitV2の組み込みLinuxは、クロスコンパイル環境で容易に生成できるツール「Buildroot」を使用して作成されていた。
unitv2# cat /etc/os-release
NAME=Buildroot
VERSION=2020.02.8
ID=buildroot
VERSION_ID=2020.02.8
PRETTY_NAME="Buildroot 2020.02.8"
ロードされているカーネルモジュール
unitv2% lsmod
Module Size Used by Tainted: G
vfat 6820 1
ntfs 73756 0
nls_utf8 1457 0
msdos 5668 0
grace 5158 1
fat 42384 2 vfat,msdos
ehci_hcd 33777 0
cifs 169945 0
8188fu 836118 0
自動起動の仕組み
Buildrootのマニュアルによると、Linuxが起動して最初に実行されるのはinitというプログラムで、/etc/inittabに定義された処理を行う。
etc/inittabを確認
unitv2% cat inittab
# /etc/inittab
#
# Copyright (C) 2001 Erik Andersen
#
# Note: BusyBox init doesn't support runlevels. The runlevels field is
# completely ignored by BusyBox init. If you want runlevels, use
# sysvinit.
#
# Format for each entry: :::
#
# id == tty to run on, or empty for /dev/console
# runlevels == ignored
# action == one of sysinit, respawn, askfirst, wait, and once
# process == program to run
# Startup the system
::sysinit:/bin/mount -t proc proc /proc
::sysinit:/bin/mount -o remount,rw /
::sysinit:/bin/mkdir -p /dev/pts /dev/shm
::sysinit:/bin/mount -a
::sysinit:/sbin/swapon -a
null::sysinit:/bin/ln -sf /proc/self/fd /dev/fd
null::sysinit:/bin/ln -sf /proc/self/fd/0 /dev/stdin
null::sysinit:/bin/ln -sf /proc/self/fd/1 /dev/stdout
null::sysinit:/bin/ln -sf /proc/self/fd/2 /dev/stderr
::sysinit:/bin/hostname -F /etc/hostname
# now run any rc scripts
::sysinit:/etc/init.d/rcS
# Put a getty on the serial port
console::respawn:/sbin/getty -L console 0 vt100 # GENERIC_SERIAL
# Stuff to do for the 3-finger salute
#::ctrlaltdel:/sbin/reboot
# Stuff to do before rebooting
::shutdown:/etc/init.d/rcK
::shutdown:/sbin/swapoff -a
::shutdown:/bin/umount -a -r
/etc/init.d/rcS
unitv2% cat /etc/init.d/rcS
#!/bin/sh
# Start all init scripts in /etc/init.d
# executing them in numerical order.
#
for i in /etc/init.d/S??* ;do
# Ignore dangling symlinks (if any).
[ ! -f "$i" ] && continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
)
;;
*)
# No sh extension, so fork subprocess.
$i start
;;
esac
done
/etc/init.d
unitv2% ls -axl /etc/init.d
total 128
drwxr-xr-x 2 avahi avahi 2352 Jan 1 1970 .
drwxr-xr-x 19 avahi avahi 3920 Apr 21 15:17 ..
-rwxr-xr-x 1 avahi avahi 1012 Jan 18 2021 S01syslogd
-rwxr-xr-x 1 avahi avahi 1004 Jan 18 2021 S02klogd
-rwxr-xr-x 1 avahi avahi 1876 Jan 18 2021 S02sysctl
-rwxr-xr-x 1 avahi avahi 274 Jan 18 2021 S05avahi-setup.sh
-rwxrwxr-x 1 avahi avahi 1167 Sep 6 2021 S05initled
-rwxrwxr-x 1 avahi avahi 667 Sep 6 2021 S06wifipwr
-rwxrwxr-x 1 avahi avahi 552 Sep 6 2021 S100setup-priv
-rwxrwxr-x 1 avahi avahi 598 Sep 6 2021 S110thermal
-rwxr-xr-x 1 avahi avahi 1684 Jan 18 2021 S20urandom
-rwxr-xr-x 1 avahi avahi 404 Jan 18 2021 S21haveged
-rwxrwxr-x 1 avahi avahi 501 Sep 6 2021 S23oadfsko
-rwxr-xr-x 1 avahi avahi 459 Jan 18 2021 S30cgroupfs
-rwxr-xr-x 1 avahi avahi 1635 Jan 18 2021 S30dbus
-rwxr-xr-x 1 avahi avahi 438 Jan 18 2021 S40network
-rwxr-xr-x 1 avahi avahi 617 Jan 18 2021 S41dhcpcd
-rwxr-xr-x 1 avahi avahi 581 Jan 18 2021 S49ntp
-rwxr-xr-x 1 avahi avahi 285 Jan 18 2021 S50avahi-daemon
-rwxr-xr-x 1 avahi avahi 210 Sep 6 2021 S50mosquitto
-rwxr-xr-x 1 avahi avahi 445 Sep 6 2021 S50nginx
-rwxr-xr-x 1 avahi avahi 531 Sep 6 2021 S50sshd
-rwxr-xr-x 1 avahi avahi 916 Sep 6 2021 S80dhcp-relay
-rwxr-xr-x 1 avahi avahi 779 Sep 6 2021 S80dhcp-server
-rwxr-xr-x 1 avahi avahi 427 Jan 18 2021 S80dnsmasq
-rwxrwxr-x 1 avahi avahi 630 Sep 6 2021 S81mdev
-rwxrwxr-x 1 avahi avahi 636 Sep 6 2021 S85runpayload
-rwxrwxr-x 1 avahi avahi 739 Sep 6 2021 S90wifi-conf
-rwxrwxr-x 1 avahi avahi 1426 Sep 6 2021 S95ip-conf
-rwxrwxr-x 1 avahi avahi 594 Sep 6 2021 S96ntpdate
-rwxrwxr-x 1 avahi avahi 5490 Sep 6 2021 automount.sh
-rwxr-xr-x 1 avahi avahi 423 Jan 18 2021 rcK
-rwxr-xr-x 1 avahi avahi 408 Jan 18 2021 rcS
S85runpayloadの中味
unitv2% cat S85*
#!/bin/sh
case "$1" in
start)
printf "Starting payload: "
cd /home/m5stack/payload
python3 /home/m5stack/payload/server.py &> /tmp/payload.info &
[ $? = 0 ] && echo "OK" || echo "FAIL"
;;
stop)
printf "Stoping payload: "
killall -9 python3
[ $? = 0 ] && echo "OK" || echo "FAIL"
;;
restart|reload)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0%