2020年10月21日水曜日

Lichee Zero-Dockを使ってみる

LCDが使用できて、安価なSBCを探していたら、見つけた。
https://akizukidenshi.com/catalog/g/gM-15544/
https://akizukidenshi.com/catalog/g/gM-14787/
https://akizukidenshi.com/catalog/g/gM-14873/

日本語の情報があまりないように思えるので、ちょっと気が重いがとりあえず購入。

情報源

公式はこのあたりなのかな
http://zero.lichee.pro/
http://nano.lichee.pro/
https://licheepizero.us/
https://licheepizero.us/downloads/readme_en.txt
https://dl.sipeed.com/LICHEE/Zero

中国語読めないよー

翻訳版

https://translate.google.co.jp/translate?hl=ja&sl=auto&tl=ja&u=http%3A%2F%2Fzero.lichee.pro%2F

作成済みイメージで動作確認

作成済みイメージをダウンロード

情報源や、貴重な日本語ページを参考にさせていただいてイメージをダウンロードする
https://qiita.com/17_kitano/items/8f8add216affa81ad321
https://dl.sipeed.com/LICHEE/Zero/Images/dd_img

minX_dd.tar.bz2
にしてみた。

適当なmicroSDカードに書き込んでみる

udo dd bs=4M if=minX_dd/lichee_zero-mindX_alpha.dd of=/dev/sdd conv=fsync

そして、Licheeに装着、シリアルコンソールも接続
TX,RXの表示は基板シルクが正しいみたい(webのは間違っている?)

起動してみる

シリアルコンソールの設定は、115200-8-N-1

Linux LicheePi 4.10.2-licheepi-zero+ #15 SMP Sat Apr 15 21:38:23 CST 2017 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
root@LicheePi:~#

初期パスワードはroot/licheepiだった。

液晶パネルを接続してみる

40pinのRGB液晶が対応しているというざっくりとした情報しかなくて
かなり不安だったが、とりあえずつなげてみた


 

接続したのは、同じところが出しているこれ
https://akizukidenshi.com/catalog/g/gM-14873/

u-Bootの表示がされたみたい。

調子に乗って、startxしてみたけどウィンドウマネージャ的なものが無いのか起動はしなかった。
でもXサーバーは起動しているようだ。一歩づついこう。

xアプリケーションを起動してみる

なんて呼んだらいいかわからないけど、xclockとかxcalc、xeyesなんかのx系のアプリケーションが入っているみたい。

root@LicheePi:~# ls /usr/bin/x*
/usr/bin/x-terminal-emulator  /usr/bin/xgamma	   /usr/bin/xmore
/usr/bin/x11perf	      /usr/bin/xgc	   /usr/bin/xprop
/usr/bin/x11perfcomp	      /usr/bin/xhost	   /usr/bin/xrandr
/usr/bin/xargs		      /usr/bin/xinit	   /usr/bin/xrdb
/usr/bin/xauth		      /usr/bin/xkbbell	   /usr/bin/xrefresh
/usr/bin/xbiff		      /usr/bin/xkbcomp	   /usr/bin/xset
/usr/bin/xcalc		      /usr/bin/xkbevd	   /usr/bin/xsetmode
/usr/bin/xclipboard	      /usr/bin/xkbprint    /usr/bin/xsetpointer
/usr/bin/xclock		      /usr/bin/xkbvleds    /usr/bin/xsetroot
/usr/bin/xcmsdb		      /usr/bin/xkbwatch    /usr/bin/xsm
/usr/bin/xconsole	      /usr/bin/xkeystone   /usr/bin/xstdcmap
/usr/bin/xcursorgen	      /usr/bin/xkill	   /usr/bin/xsubpp
/usr/bin/xcutsel	      /usr/bin/xload	   /usr/bin/xterm
/usr/bin/xditview	      /usr/bin/xlogo	   /usr/bin/xvidtune
/usr/bin/xdpyinfo	      /usr/bin/xlsatoms    /usr/bin/xvinfo
/usr/bin/xdriinfo	      /usr/bin/xlsclients  /usr/bin/xwd
/usr/bin/xedit		      /usr/bin/xlsfonts    /usr/bin/xwininfo
/usr/bin/xev		      /usr/bin/xmag	   /usr/bin/xwud
/usr/bin/xeyes		      /usr/bin/xman	   /usr/bin/xxd
/usr/bin/xfd		      /usr/bin/xmessage
/usr/bin/xfontsel	      /usr/bin/xmodmap

実行してみよう

startx /usr/bin/xclock -- :0


 

うぉー懐かしい。久しぶりに見たなこれー

開発環境を導入する

このままでは何ができるのかとか手探りになってしまうので
思い切って開発環境を導入してみようと思う
作成済みのイメージでは、以下のやり方がわからなかった。

  • 有線LANが使えない
  • タッチパネルのキャリブレーションができない
  • ウィンドウマネージャが開かない

公式の方法 Dockerで環境構築

http://zero.lichee.pro/入门/docker_index.html
の手順でやってみる。

adeno@drakorange:~/develop$ docker pull zepan/licheepi
Using default tag: latest
latest: Pulling from zepan/licheepi
9fb6c798fa41: Pull complete 
3b61febd4aef: Pull complete 
9d99b9777eb0: Pull complete 
d010c8cf75d7: Pull complete 
7fac07fb303e: Pull complete 
4a3e8d4abe49: Pull complete 
4e7cdc979849: Pull complete 
68de60586b36: Pull complete 
Digest: sha256:da6824787eb6b2e8b2556be6863b4dbfbe1683a1c834f257f9f8f5d993224bae
Status: Downloaded newer image for zepan/licheepi:latest
docker.io/zepan/licheepi:latest

取得できた

adeno@drakorange:~/develop$ docker run -d -p 6666:22 zepan/licheepi /usr/sbin/sshd -D
<略>
adeno@drakorange:~/develop$ ssh root@localhost -p 6666
The authenticity of host '[localhost]:6666 ([127.0.0.1]:6666)' can't be established.
ECDSA key fingerprint is <略>
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:6666' (ECDSA) to the list of known hosts.
root@localhost's password: 
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 5.4.0-42-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
Last login: Thu Oct  5 09:15:27 2017 from 192.168.242.1
root@50959d444d56:~# cat README.txt 
u-boot	is mainline uboot, support tf or spi nor boot.
linux is mainline linux, 4.13 branch.
lichee is BSP linux, 3.4 kernel.
camdroid is BSP camdroid.

every dir have rebuild.sh to rebuild the source code.

sshでコンテナ内に入れた

U-bootのコンパイル

http://zero.lichee.pro/系统开发/uboot_index.html

コンフィングファイルは

root@50959d444d56:~/u-boot# ls configs/Lichee*
configs/LicheePi_Zero_480x272LCD_defconfig  configs/LicheePi_Zero_defconfig
configs/LicheePi_Zero_800x480LCD_defconfig

繋いでいるLCDは800x480だったような気がするので

make LicheePi_Zero_800x480LCD_defconfig

とりあえず、何か変えてU-bootが更新できることを確認する。

サンプルとして紹介されている、起動時の「バージョン情報の非表示」をやってみる
http://zero.lichee.pro/系统开发/uboot_logo.html

#define CONFIG_HIDE_LOGO_VERSION

/* Locals */
static GraphicDevice *pGD;      /* Pointer to Graphic array */

249行目辺りに #define CONFIG_HIDE_LOGO_VERSION を追記した。
コンパイルは

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-
または
./rebuild.sh

で行う。
すると
u-boot-sunxi-with-spl.bin
が生成される

U-bootの更新

早速、更新してみる。
http://zero.lichee.pro/系统开发/uboot_build.html
には、
「コンパイル後、u-boot-sunxi-with-spl.binが現在のディレクトリに生成されます。これを8Kオフセットに書き込んで開始できます。」 by Google翻訳
とある。
8Kオフセットとは?なので、他の情報源にて探してみる。
https://linux-sunxi.org/Mainline_U-Boot#Compile_U-Boot
ここによると

dd if=u-boot-sunxi-with-spl.bin of=/dev/sdX bs=1024 seek=8

sdXの部分を自分の環境に合わせる。
ハマったのはデバイス全体?を指定すること。sdd1にしていたら、起動できなくて。。。

8Kオフセットの説明は、ここにあった。
https://linux-sunxi.org/Bootable_SD_card#SD_Card_Layout

このSDカードを刺して起動してみると、ちゃんと?バージョン情報が非表示になった。

USB OTGで仮想イーサーネットを使用する

U-bootやカーネル更新毎にSDカード挿抜するのは大変だし、耐久性が心配。
挿抜が面倒。挿抜が面倒。

USB-OTG

仮想イーサーネットが使用できるらしいので使ってみる
http://zero.lichee.pro/应用/otg2PC.html

Lichee Zero側

インターフェースを作成する

root@LicheePi:~# ifconfig usb0 192.168.10.100
root@LicheePi:~# ifconfig
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

usb0      Link encap:Ethernet  HWaddr 4e:40:46:**:**:**  
          inet addr:192.168.10.100  Bcast:192.168.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4 errors:0 dropped:3 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:592 (592.0 B)  TX bytes:0 (0.0 B)

PC側

特に複雑な手順はなし。

adeno@drakorange:~/develop/licheepizoro$ lsusb
Bus 001 Device 009: ID 0525:a4aa Netchip Technology, Inc. Linux-USB CDC Composite Gadge (Ethernet and ACM)

adeno@drakorange:~/develop/licheepizoro$ ifconfig

enp1s0f0u3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.1  netmask 255.255.255.0  broadcast 192.168.10.255
        inet6 ****::****:****:****:****  prefixlen 64  scopeid 0x20<link>
        ether 6a:91:64:**:**:**  txqueuelen 1000  (イーサネット)
        RX packets 6  bytes 392 (392.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 143  bytes 24341 (24.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

やってみる

u-Bootイメージファイルをscpで、Licheeに転送。
そして、自身でdd使って書き換える。

root@LicheePi:~# fdisk -l                           

Disk /dev/mmcblk0: 3.7 GiB, 3980394496 bytes, 7774208 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: 0x33f10fcb

Device         Boot Start     End Sectors  Size Id Type
/dev/mmcblk0p1       2048   34815   32768   16M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      34816 1419263 1384448  676M 83 Linux

root@LicheePi:~# dd if=u-boot-sunxi-with-spl.bin of=/dev/mmcblk0 bs=1024 seek=8

できた!

でも、でも、接続のたびにMACアドレスが変わってしまい、インターフェース設定をやり直す必要があるみたい。

イーサーネットを使用する

せっかくLANコネクタのあるDockを入手したので、LANを有用化したい。
http://zero.lichee.pro/驱动/Ethernet.html

Linuxカーネルコンパイル

root@50959d444d56:~# cat README.txt 
u-boot	is mainline uboot, support tf or spi nor boot.
linux is mainline linux, 4.13 branch.
lichee is BSP linux, 3.4 kernel.
camdroid is BSP camdroid.

every dir have rebuild.sh to rebuild the source code.

linuxディレクトリの中に入り
手順通り、dts、dtsiファイルを修正して

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

arch/arm/boot/zImage
arch/arm/boot/dts/sun8i-v3s-licheepi-zero.dtb
をSDカードにコピーして、再起動

eth0の有効化

無事に起動したら

root@LicheePi:~# ifup eth0
Internet Systems Consortium DHCP Client 4.3.1
Copyright 2004-2014 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

[  374.205155] Generic PHY stmmac-0:01: attached PHY driver [Generic PHY] (mii_bus:phy_addr=stmmac-0:01, irq=-1)
[  374.217488] dwmac-sun8i 1c30000.ethernet eth0: No MAC Management Counters available
[  374.225386] dwmac-sun8i 1c30000.ethernet eth0: PTP not supported by HW
Listening on LPF/eth0/02:0f:e2:**:**:**
Sending on   LPF/eth0/02:0f:e2:**:**:**
Sending on   Socket/fallback
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 7
[  381.526816] dwmac-sun8i 1c30000.ethernet eth0: Link is Up - 100Mbps/Full - flow control off
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 8
DHCPREQUEST on eth0 to 255.255.255.255 port 67
DHCPOFFER from 192.168.1.1
DHCPACK from 192.168.1.1
bound to 192.168.1.121 -- renewal in 83698 seconds.
root@LicheePi:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 02:0f:e2:**:**:**
          inet addr:192.168.1.121  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:45 errors:0 dropped:0 overruns:0 frame:0
          TX packets:42 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:4536 (4.4 KiB)  TX bytes:4124 (4.0 KiB)
          Interrupt:35 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:1 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:112 (112.0 B)  TX bytes:112 (112.0 B)

root@LicheePi:~# 

いけた!

LAN未接続で、待たされる件

喜んでいたのだが
LAN未接続時に

a start job is running for raise network interfaces

で20秒くらい待たされてしまう。なんとかしたい。
https://askubuntu.com/questions/862176/how-to-fix-a-start-job-is-running-for-the-raise-network-in-ubuntu-server-16

mkdir -p /etc/systemd/system/networking.service.d/
bash -c 'echo -e "[Service]\nTimeoutStartSec=5sec" > /etc/systemd/system/networking.service.d/timeout.conf'
systemctl daemon-reload

いいね!

U-Bootの自己書き換え

といっても、sshできているので、PCから/boot/あたりにイメージデータを保存して
以下を実行するだけ、/dev/以降が変わるくらいで、他に気にするところはなかった。

dd if=/boot/u-boot-sunxi-with-spl.bin of=/dev/mmcblk0 bs=1024 seek=8

状況の整理

いろいろやりながらで、時間も経ってきたのでよくわからなくなってきた。
今一度整理。

分類 方法 状況 ソース
U-boot docker内の u-boot 出来た。ブート時のLCD表示もOK http://zero.lichee.pro/系统开发/uboot_build.html おそらく [git clone https://github.com/Lichee-Pi/u-boot.git -b v3s-current]
Linuxカーネル docker内の linux 出来た。 eth0の有効化もOK http://zero.lichee.pro/驱动/Ethernet.html
ルートシステム docker内の emdebian emdebianの開発終了のため試していない https://en.wikipedia.org/wiki/Emdebian_Grip
ルートシステム docker内の buildroot ルートシステムを作るのみ?
統合 buildroot 最新のやつはlicheepi対応しているみたいだが、LCDの確認はまだ
統合 OpenWrt 不明 https://qinfengling.pro/build_openwrt_image_for_licheepi_nano.html

docker内にいろいろサンプルがあるのがありがたい。

buildrootのあれこれ

buildrootって敷居が高かったのだけど、調べてみたらちょっとやってみたくなってきた。
docker内のやつは、ルートシステムを作るのみのように見えた。
u-Boot、カーネルこみこみでやる方法もあるらしいので、次は、それを試してみる。

https://qiita.com/aselectroworks/items/550370b4129c0afdda68
https://github.com/unframework/licheepi-nano-buildroot
https://github.com/Squonk42/buildroot-licheepi-zero
https://hackaday.io/project/134065-funkey-zero/log/144796-linux-distribution