OpenWrt for Arduino Yun cheat sheet

From misc notes
Jump to navigation Jump to search

OpenWrt running on Atheros AR9331 of Arduino Yun, LLC version OpenWrt-Yun also Linino, is in obsolete (and has secutiry issues) at kernel and various packages. I will try to investigate the upgrade to the latest version of OpenWrt. (With Absolutely NO Warranty)


Arduino Yun の Atheros AR9331 で稼働する OpenWrt が、LLC 版 OpenWrt-Yun も Linino もカーネルやパッケージが古くていろいろ残念。 OpenWrt の最新版(trunk)との同期がとれるかを実験する 。つまり Arduino Yun の Atheros AR9331 のオペレーティングシステム(OS)である OpenWrt-Yun のセキュリティバージョンアップに順次対応できるように準備する。

☆注意☆ Arduino Yun の AR9331 部が完全に文鎮化する可能性あり ☆注意☆

すでにある Chaos Calmer 15.05 版 OpenWrt-Yun

Arduino Yun フォーラムで発見した RedSnake64 さんの実装。

RedSnake64版 OpenWrt-Yun:

https://github.com/RedSnake64/openwrt-yun/tree/15.05
ChaosCalmer_v1.3
人柱で導入してみた。mDNS がつかえず .local でアクセスできなかった。IP 指定で設定まではいけたがいったん実験終了。
opkg install avahi-daemon-service-http
違いが見えてきたので OpenWrt trunk でつかえる Arduino Yun package つくることにする。

本家 OpenWrt の Yun Profile を調査する

OpenWrt Project には、すでに Arduino Yun の Profile がある。

target/linux/ar71xx/generic/profiles/arduino.mk
ar71xx: add Arduino Yun
https://github.com/openwrt/packages/tree/master/utils/yunbridge
yunbridge
Arduino YUN bridge library が取り込まれている。

OpenWrt snapshot images:

https://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/
https://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/packages/
openwrt-ar71xx-generic-yun-16M-squashfs-sysupgrade.bin
時々ビルドに失敗して snapshots から消えてしまうようだ。一週間ぐらい気長に待つ。
この System Image は Arduino Yun のハードウェアは対応してるが、もちろん Yun 独自のソフトウェアは組み込まれていない。
git.openwrt.org Git - openwrt trunk tree
OpenWrt 本体とコアなパッケージのレポジトリ。
https://github.com/openwrt/packages
https://github.com/openwrt/luci
https://github.com/openwrt-routing/packages
https://github.com/openwrt/telephony
https://github.com/openwrt/targets
https://github.com/openwrt-management/packages
本家のオプションパッケージは github で管理するようになっている。
Where to get packages OpenWrt Wiki

OpenWrt-Yun を調査する

OpenWrt-Yun で必要なもの

https://github.com/RedSnake64/openwrt-arduino-packages/tree/for-15.05
RedSnake64版 arduino package
https://github.com/arduino/openwrt-packages-yun/tree/master/arduino
LLC版 arduino package

Arduino OpenWrt Yún packages:

(y) avrdude *
(y) cpu-mcu-bridge *
(m) cwiid
(y) luci-app-arduino-webpanel
(m) node *
(m) node-bleno
(m) node-noble
(m) node-serialport *
(m) node-socket.io
(m) node-socket.io-client
(m) node-socket.io-client-legacy
(m) node-socket.io-legacy
(m) node-sqlite3
(m) node-ws
(y) rng-tools *
(y) spacebrew
(y) temboo
(y) uSDaemon
(m) v8m-rb *
(y) yun-conf
(y) yun-scripts
  1. avrdude は "packages/utils/avrdude" に純正パッケージがある。Yun 用の avrdude.conf があれば良い。avrdude.conf は files に配置する。
  2. cpu-mcu-bridge は純正パッケージの yunbridge と重なるが互換性をかんがえるとこっちにする。(あとで yunbridge を動作検証する)
  3. node は純正パッケージで。
  4. node-serialport は純正パッケージでエラーがでるのでこっちに取り込む。純正 node-arduino-firmata も同様なので取り込む
    もし、純正モジュールで稼働するなら不要。y ではないので m する必要はなく n よい。現状は純正モジュールが build 失敗しているようで ipk が配布されていないようだ。
    当面は arduino packages で取り込む方針にする。
  5. rng-tools は純正パッケージは問題あり。
    START=98 から START=48 にしないと Yun 独自の起動スクリプト S49generate_new_gpg_key で不具合がでる。これより前に rngd を起動する必要がある。
    純正パッケージの rngd.init にパッチあててから build させる方針にする。
  6. v8m-rb はコンパイルエラーになるが パッケージの patch に '-fno-strict-overflow'. 追加すればよい。(悪手だがやむなし)

kernel コンフィグレーションで必須な項目

CONFIG_TARGET_ar71xx=y
CONFIG_TARGET_ar71xx_generic=y
CONFIG_TARGET_ar71xx_generic_Yun=y

CONFIG_IMAGEOPT=y
CONFIG_PREINITOPT=y
CONFIG_TARGET_PREINIT_SUPPRESS_STDERR=y
CONFIG_TARGET_PREINIT_TIMEOUT=2
# CONFIG_TARGET_PREINIT_SHOW_NETMSG is not set
# CONFIG_TARGET_PREINIT_SUPPRESS_FAILSAFE_NETMSG is not set
CONFIG_TARGET_PREINIT_IFNAME=""
CONFIG_TARGET_PREINIT_IP="192.168.1.1"
CONFIG_TARGET_PREINIT_NETMASK="255.255.255.0"
CONFIG_TARGET_PREINIT_BROADCAST="192.168.1.255"
CONFIG_INITOPT=y
CONFIG_TARGET_INIT_PATH="/bin:/sbin:/usr/bin:/usr/sbin"
CONFIG_TARGET_INIT_ENV=""
CONFIG_TARGET_INIT_CMD="/sbin/init"
CONFIG_TARGET_INIT_SUPPRESS_STDERR=y
CONFIG_VERSIONOPT=y
CONFIG_VERSION_DIST="OpenWrtYun"
CONFIG_VERSION_NICK="Bleeding Edge"
CONFIG_VERSION_NUMBER=""
CONFIG_VERSION_REPO="http://downloads.openwrt.org/snapshots/trunk/%S/packages"
CONFIG_VERSION_MANUFACTURER="Arduino"
CONFIG_VERSION_MANUFACTURER_URL=""
CONFIG_VERSION_PRODUCT="Arduino Yun"
CONFIG_VERSION_HWREV="1.0"
CONFIG_VERSION_FILENAMES=y

CONFIG_PER_FEED_REPO=y
CONFIG_PER_FEED_REPO_ADD_DISABLED=y
CONFIG_PER_FEED_REPO_ADD_COMMENTED=y
CONFIG_FEED_packages=y
CONFIG_FEED_luci=y
CONFIG_FEED_routing=y
CONFIG_FEED_telephony=y
CONFIG_FEED_management=y
CONFIG_FEED_arduino=y
# CONFIG_SMIMEOPT is not set
CONFIG_OPKGSMIME_PASSPHRASE=y

CONFIG_DEFAULT_base-files=y
CONFIG_DEFAULT_busybox=y
CONFIG_DEFAULT_dnsmasq=y
CONFIG_DEFAULT_dropbear=y
CONFIG_DEFAULT_firewall=y
CONFIG_DEFAULT_fstools=y
CONFIG_DEFAULT_ip6tables=y
CONFIG_DEFAULT_iptables=y
CONFIG_DEFAULT_iwinfo=y
CONFIG_DEFAULT_kmod-ath9k=y
CONFIG_DEFAULT_kmod-gpio-button-hotplug=y
CONFIG_DEFAULT_kmod-usb-core=y
CONFIG_DEFAULT_kmod-usb2=y
CONFIG_DEFAULT_libc=y
CONFIG_DEFAULT_libgcc=y
CONFIG_DEFAULT_mtd=y
CONFIG_DEFAULT_netifd=y
CONFIG_DEFAULT_odhcp6c=y
CONFIG_DEFAULT_odhcpd=y
CONFIG_DEFAULT_opkg=y
CONFIG_DEFAULT_ppp=y
CONFIG_DEFAULT_ppp-mod-pppoe=y
CONFIG_DEFAULT_swconfig=y
CONFIG_DEFAULT_uboot-envtools=y
CONFIG_DEFAULT_uci=y
CONFIG_DEFAULT_uclient-fetch=y
CONFIG_DEFAULT_wpad-mini=y

CONFIG_PACKAGE_avrdude=y
CONFIG_PACKAGE_cpu-mcu-bridge=y
CONFIG_PACKAGE_python-cwiid=m
CONFIG_PACKAGE_libcwiid=m
CONFIG_PACKAGE_luci-app-arduino-webpanel=y
CONFIG_PACKAGE_node=m
CONFIG_PACKAGE_node-bleno=m
CONFIG_PACKAGE_node-noble=m
CONFIG_PACKAGE_node-serialport=m
CONFIG_PACKAGE_node-socket.io=m
CONFIG_PACKAGE_node-socket.io-client=m
CONFIG_PACKAGE_node-socket.io-client-legacy=m
CONFIG_PACKAGE_node-socket.io-legacy=m
CONFIG_PACKAGE_node-sqlite3=m
CONFIG_PACKAGE_node-ws=m
CONFIG_PACKAGE_rng-tools=y
CONFIG_PACKAGE_spacebrew=y
CONFIG_PACKAGE_temboo=y
CONFIG_PACKAGE_uSDaemon=y
CONFIG_PACKAGE_v8m-rb=m
CONFIG_PACKAGE_yun-conf=y
CONFIG_PACKAGE_yun-scripts=y

CONFIG_PACKAGE_kmod-nls-base=y
CONFIG_PACKAGE_kmod-nls-cp437=y
CONFIG_PACKAGE_kmod-nls-iso8859-1=y
CONFIG_PACKAGE_kmod-nls-utf8=y

CONFIG_PACKAGE_libavahi-client=y
CONFIG_PACKAGE_libavahi-dbus-support=y
CONFIG_PACKAGE_avahi-dbus-daemon=y
CONFIG_PACKAGE_avahi-dnsconfd=y
CONFIG_PACKAGE_avahi-utils=y

CONFIG_PACKAGE_nano=y
CONFIG_PACKAGE_curl=y
CONFIG_PACKAGE_wget=y
Python OpenWrt Wiki

python-mini が python-light に変更されている。

If you are using Chaos Calmer then python-mini package is replaced by python-light package. Currently python package adds a lot of dependencies so we suggest that you don't even try to install full version, unless you have at least 50MB of free space on your flash storage.

OpenWrt の考え方

サイズが最小限になるようにコンフィグレーションすることが最優先。(これが PC GNU/Linux と大きな方針の差であることに気がついた)

trunk 版の OpenWrt-Yun パッケージとビルド環境

https://github.com/nxhack/openwrt-arduino-packages
https://github.com/nxhack/openwrt-yun-build-extra

OpenWrt-Yun build メモ

LLC 版 OpenWrt-Yun:

git clone --depth=1 --branch master --single-branch https://github.com/arduino/openwrt-yun.git

RedSnake64 版 OpenWrt-Yun:

git clone --depth=1 --branch 15.05 --single-branch https://github.com/RedSnake64/openwrt-yun.git

LLC 版と RedSnake64 さん版を参考に、本家の trunk でビルド可能にする。

本家 OpenWrt:

git clone --depth=1 --branch master --single-branch https://github.com/openwrt/openwrt.git

Ubuntu 14.04 環境でクロスコンパイルのための準備。

apt-get update
apt-get install -y git subversion build-essential asciidoc \
	fastjar flex gawk libgtk2.0-dev intltool zlib1g-dev \
	genisoimage libncurses5-dev libssl-dev ruby sdcc unzip \
	bison libboost-dev libxml-parser-perl libusb-dev bin86 \
	bcc sharutils openjdk-7-jdk mercurial cvs bzr \
	nodejs-legacy curl g++-multilib squashfs-tools
出来上がった Image の検証用に squashfs-tools も入れておく。 (unsquashfs openwrt-ar71xx-generic-yun-16M-squashfs-sysupgrade.bin)
Installing Node.js via package manager | Node.js
Ubuntu 純正パッケージの nodejs, npm 使うとビルドこける。
https://downloads.openwrt.org/sources/
パッケージのソースの取得に失敗する場合はここからとって ./dl/ 配下に置いておく。
wget http://pkgs.fedoraproject.org/repo/pkgs/libconfuse/confuse-2.7.tar.gz/45932fdeeccbb9ef4228f1c1a25e9c8f/confuse-2.7.tar.gz
wget http://pkgs.fedoraproject.org/repo/pkgs/avrdude/avrdude-6.1.tar.gz/9db8c25b935d34234b9b1ba16ad55fd5/avrdude-6.1.tar.gz

./feeds.conf.default:

src-git packages https://github.com/openwrt/packages.git
src-git luci https://github.com/openwrt/luci.git
src-git routing https://github.com/openwrt-routing/packages.git
src-git telephony https://github.com/openwrt/telephony.git
src-git management https://github.com/openwrt-management/packages.git
##src-git targets https://github.com/openwrt/targets.git                                                                      
#src-git oldpackages http://git.openwrt.org/packages.git                                                                      
#src-svn xwrt http://x-wrt.googlecode.com/svn/trunk/package                                                                   
#src-svn phone svn://svn.openwrt.org/openwrt/feeds/phone                                                                      
#src-svn efl svn://svn.openwrt.org/openwrt/feeds/efl                                                                          
#src-svn xorg svn://svn.openwrt.org/openwrt/feeds/xorg                                                                        
#src-svn desktop svn://svn.openwrt.org/openwrt/feeds/desktop                                                                  
#src-svn xfce svn://svn.openwrt.org/openwrt/feeds/xfce                                                                        
#src-svn lxde svn://svn.openwrt.org/openwrt/feeds/lxde                                                                        
#src-link custom /usr/src/openwrt/custom-feed                                                                                 
#src-git arduino https://github.com/RedSnake64/openwrt-arduino-packages.git;for-15.05
src-git arduino https://github.com/nxhack/openwrt-arduino-packages.git;for-trunk
これでビルド実験中...

./build.sh:

#!/bin/bash -ex

#FEEDS
./scripts/feeds uninstall -a
rm -rf feeds
./scripts/feeds update -a
./scripts/feeds install -a

#UNINSTALL BROKEN PACKAGES
#./scripts/feeds uninstall aria2 freecwmp libfreecwmp libmicroxml crtmpserver dansguardian

#DELETE PACKAGES
rm -rf ./package/feeds/packages/node-serialport
rm -rf ./package/feeds/packages/node-arduino-firmata

#LINK CUSTOM PACKAGES
ln -s ../../../feeds/arduino/node-serialport ./package/feeds/arduino/node-serialport
ln -s ../../../feeds/arduino/node-arduino-firmata ./package/feeds/arduino/node-arduino-firmata

#PATCH SOME PACKAGES
sed -i -e s/^START=98/START=48/ ./feeds/packages/utils/rng-tools/files/rngd.init

#COPY CONFIG FILE
mv .config .config.feeds
cp openwrt-yun-minimum.config .config

make oldconfig
make
純正パッケージには(ar71xx環境では)コンパイルできない壊れたものもいろいろある。

LLC 版との差異

led の デバイス名が 変更になった。純正に合わせる。
arduino:blue:wlan  arduino:white:usb
target/linux/ar71xx/base-files/etc/uci-defaults/01_leds
https://github.com/nxhack/openwrt-arduino-packages/commit/eb7130ac331ce491765f27372d987d9d7415f6c0
rng-tools は純正版ではだめ LLC 版の init script に合わせる。
S98rngd -> S48rngd
START=98 -> START=48
START=98 から START=48 にしないと Yun独自の起動スクリプト S49generate_new_gpg_key で不具合がでる。これより前に rngd を起動する必要がある。
package build の前に rngd.init を変更する。
 sed -i -e s/^START=98/START=48/ ./feeds/packages/utils/rng-tools/files/rngd.init
BUSYBOX ASH BANNER の日付がなぜか出ない。
表示しないように変更されていた。
https://git.openwrt.org/?p=openwrt.git;a=commit;h=39fabb5068e95ab9c0901dd4f37129111d88ae00
+# don't create a version string containing the actual timestamp
+export KCONFIG_NOTIMESTAMP=1
+
BUSYBOX ASH HELP のバナーが出ない。
CONFIG_ASH_HELP がデフォルトが n に変更されていた。
https://github.com/openwrt/openwrt/blob/master/package/utils/busybox/Config-defaults.in
AR9331 を AVR ライタにするために /etc/avrdude.conf に設定追加する。
programmer
  id    = "linuxgpio";
  desc  = "Use the Linux sysfs interface to bitbang GPIO lines";
  type  = "linuxgpio";
  reset = ~18;
  sck   = 11;
  mosi  = 27;
  miso  = 8;
;

TO DO

  1. rc.local
    LLC の openwrt-yun 直下の files ディレクトリ以下を build する直下にもってくる。
    LLC の files 配下の lib ディレクトリ以下のファイルはバージョンが合わず、置き換えてはいけない。ハマった。
    RedSnake64 版の files をベースに必要なものを吟味して追加する。
  2. uboot-linino コンパイルエラーとる
    extern inline -> static inline, extern __inline__ -> static inline
    ブートローダの書き換え失敗したら完全に文鎮になるので検証はこわくてできない。
  3. .config 差異
  4. DISTRIB_TAINTS 意味調査
    ./include/version.mk 確認する。OpenWrt snapshot では、最終的に DISTRIB_TAINTS="" である。
  5. BUSYBOX 差異
    デフォルトが微妙にちがう。OpenWrt 本家を基本にするにはデフォルトは変更しない方針にする。
    気持ち悪いのが CROND_DIR="/var/spool/cron" から CROND_DIR="/etc" になっている事。動いてから考えよう。
  6. 純正パッケージの patch
    build.sh に純正パッケージのパッチを当てる処理を追加する。
  7. SD card の automount 方法調査する。(uSDaemon がいまいちすぎるので)
    OpenWrt (e)udev まだ試していないが。
    /etc/udev/rules.d/11-sd-cards-auto-mount.rules
    KERNEL!="sda[0-9]", GOTO="sd_cards_auto_mount_end"
    # Global mount options
    ACTION=="add", ENV{mount_options}="relatime"
    # Filesystem specific options
    ACTION=="add", IMPORT{program}="/sbin/blkid -o udev -p %N"
    ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"
    ACTION=="add", RUN+="/bin/mkdir -p /mnt/%k", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%k"
    ACTION=="remove", RUN+="/bin/umount -l /mnt/%k", RUN+="/bin/rmdir /mnt/%k"
    # exit
    LABEL="sd_cards_auto_mount_end"
    
    udevadm control --reload-rules
    
    なるほど、(e)udev を使わないのはサイズの問題だね。system image はできるだけ小さくするのが最優先になっている。
  8. hardware button の処理 procd ???? triggerhappy ? 検証する。

Bricked 文鎮化

My Yún doesn't boot anymore! How can I restore it?

YunSerialTerminal をロードしてシリアルコンソールを有効にする。SDカードは抜いておく事。YUN RST ボタンをおす。

  1. YunSerialTerminal で prompt が出て OS の操作ができる場合。
    1. なんとかして network を生かす。
      ifconfig インターフェース IPアドレス
      route add default gw どこか
      
      /etc/resolv.conf を編集。
    2. SD card で正常な sysupgrade のイメージをもってくる。
      mkdir /mnt/sda1
      mount -t vfat /dev/sda1 /mnt/sda1
      
  2. YunSerialTerminal で u-boot を操作できる場合。
    1. https://www.arduino.cc/en/Tutorial/YunUBootReflash