電気回路/zynq/自動起動の設定 の履歴(No.2)
更新電源投入後に初期化&アプリケーションを自動実行する†
- FPGA ロジックのプログラム
- 各種 dtso のデバイスツリーへの組み込み
- アプリケーションの実行
をしたい。
systemd にするか sysvinit にするか†
この際 systemd を使ってみようかしら、とも思ったけれど
- https://dev.classmethod.jp/cloud/aws/service-control-use-systemd/
- https://qiita.com/ledmonster/items/5f2e1633d4124cb978fe
何だかややこしいので Sysvinit でお茶を濁すことにする。
LANG:console $ runlevel N 5
通常起動時の runlevel は 5 なので、
/etc/init.d/fpga
LANG:sh #!/bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin . /lib/lsb/init-functions FPGA_PROGRAM=/usr/local/bin/fpga-program DTO=/usr/local/bin/dto BINFILES="/boot/design*.bin" DTSOFILES="/boot/dtso.d/*.dtso" test -x $DTO || exit 5 test -x $FPGA_PROGRAM || exit 5 num () { echo $# } program_fpga () { if [ $(num $BINFILES) = 0 ]; then echo "No .bin file found at /boot." return 1 fi if [ $(num $BINFILES) = 1 ]; then BINFILE=$BINFILES else echo "==== Multiple binary files found:" n=1 for bin in $BINFILES do echo " " $n : $bin n=$(($n + 1)) done echo -n "Which file should be loaded: " read selection n=1 for bin in $BINFILES do if [ $n = $selection ]; then BINFILE=$bin fi n=`expr $n + 1` done fi echo "Programming FPGA logic with $BINFILE" $FPGA_PROGRAM $BINFILE } load_dtso () { for dtso in $DTSOFILES do mountp=$(echo $dtso|sed "s/.*\///"|sed "s/\..*//") echo "Loading $dtso at $mountp" $DTO $mountp $dtso done } fpga_start () { for n in 901 902 903 904 905 do echo $n > /sys/class/gpio/export done lcd-show-ip } fpga_stop () { for n in 901 902 903 904 905 do echo $n > /sys/class/gpio/unexport done } unload_dtso () { for dtso in $DTSOFILES do mountp=$(echo $dtso|sed "s/.*\///"|sed "s/\..*//") echo "Unloading $dtso at $mountp" $DTO $mountp done } case $1 in start) log_daemon_msg "Starting FPGA logic" "fpga" program_fpga && load_dtso && fpga_start log_end_msg $? ;; stop) log_daemon_msg "Stopping FPGA logic" "fpga" fpga_stop && unload_dtso ;; status) fpga_status ;; restart|force-reload) $0 stop; sleep 1;$0 start ;; *) echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}" exit 2 ;; esac
を用意して、
LANG:console $ ln -s /etc/init.d/fpga /etc/rc5.d/S00fpga
すれば起動時に
Counter: 2386 (from 2010/06/03),
today: 5,
yesterday: 2