Lichee Pi Nano をはじめてみる

###はじめに

秋月電子やスイッチサイエンスで Lichee Pi Nano という小型Linuxボードが発売されるようになりました。
AllwinnerのF1C100SというSoCを使用したSDカードサイズの小型ボードです。

http://akizukidenshi.com/catalog/g/gM-14787/
https://jp.seeedstudio.com/Sipeed-Lichee-Nano-Linux-Development-Board-p-2892.html

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/146663/9bcf42ce-d8e7-ab2a-da56-d0a046acd224.png)

とりあえず秋月で買ってきたのをドキュメントを見ながら火入れしたいと思います。

####起動

http://nano.lichee.pro/index.html

ドキュメントは中国語しかまだないようなので、Google翻訳を使って読んでいきます。
UARTに接続して電源を入れると起動メッセージが出力されました。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/146663/113a7416-4fc8-6d68-d3d1-2ef268694061.png)



```
U-Boot SPL 2018.01-05679-g013ca457fd-dirty (Aug 02 2019 - 09:57:28)
DRAM: 32 MiB
Trying to boot from MMC1
Card did not respond to voltage select!
mmc_init: -95, time 22
spl: mmc init failed with error: -95
Trying to boot from sunxi SPI


U-Boot 2018.01-05679-g013ca457fd-dirty (Aug 02 2019 - 09:57:28 +0800) Allwinner Technology

CPU:   Allwinner F Series (SUNIV)
Model: Lichee Pi Nano
DRAM:  32 MiB
MMC:   SUNXI SD/MMC: 0
SF: Detected xt25f128b with page size 256 Bytes, erase size 4 KiB, total 16 MiB
*** Warning - bad CRC, using default environment

Setting up a 800x480 lcd console (overscan 0x0)
In:    serial@1c25000
Out:   serial@1c25000
Err:   serial@1c25000
Net:   No ethernet found.
starting USB...
No controllers found
Hit any key to stop autoboot:  2  1  0 
SF: Detected xt25f128b with page size 256 Bytes, erase size 4 KiB, total 16 MiB
device 0 offset 0x100000, size 0x4000
SF: 16384 bytes @ 0x100000 Read: OK
device 0 offset 0x110000, size 0x400000
SF: 4194304 bytes @ 0x110000 Read: OK
## Flattened Device Tree blob at 80c00000
   Booting using the fdt blob at 0x80c00000
   Loading Device Tree to 80e03000, end 80e07ddc ... OK

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 5.2.0-licheepi-nano+ (zhuhao@sipeed_ai) (gcc version 7.4.1 20181213 [linaro-7.4-2019.02 revision 56ec6f6b99cc167ff0c2f8e1a2eed33b1edc85d4] (Linaro GCC 7.4-2019.02)) #2 Thu Aug 1 09:45:44 UTC 2019
[    0.000000] CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=0005317f
[    0.000000] CPU: VIVT data cache, VIVT instruction cache
[    0.000000] OF: fdt: Machine model: Lichee Pi Nano
[    0.000000] Memory policy: Data cache writeback
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 8128
[    0.000000] Kernel command line: console=tty0 console=ttyS0,115200 panic=5 rootwait root=/dev/mtdblock3 rw rootfstype=jffs2
[    0.000000] Dentry cache hash table entries: 4096 (order: 2, 16384 bytes)
[    0.000000] Inode-cache hash table entries: 2048 (order: 1, 8192 bytes)
[    0.000000] Memory: 23760K/32768K available (5120K kernel code, 209K rwdata, 1300K rodata, 1024K init, 221K bss, 9008K reserved, 0K cma-reserved, 0K highmem)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[    0.000000] random: get_random_bytes called from start_kernel+0x254/0x3cc with crng_init=0
[    0.000054] sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 89478484971ns
[    0.000139] clocksource: timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns
[    0.000722] Console: colour dummy device 80x30
[    0.001358] printk: console [tty0] enabled
[    0.001459] Calibrating delay loop... 203.16 BogoMIPS (lpj=1015808)
[    0.070289] pid_max: default: 32768 minimum: 301
[    0.070786] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.070866] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.072692] CPU: Testing write buffer coherency: ok
[    0.074993] Setting up static identity map for 0x80100000 - 0x80100058
[    0.077455] devtmpfs: initialized
[    0.083887] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.084060] futex hash table entries: 256 (order: -1, 3072 bytes)
[    0.084455] pinctrl core: initialized pinctrl subsystem
[    0.088167] DMA: preallocated 256 KiB pool for atomic coherent allocations
[    0.090448] cpuidle: using governor menu
[    0.147266] SCSI subsystem initialized
[    0.147752] usbcore: registered new interface driver usbfs
[    0.147997] usbcore: registered new interface driver hub
[    0.148244] usbcore: registered new device driver usb
[    0.148789] pps_core: LinuxPPS API ver. 1 registered
[    0.148872] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[    0.149459] Advanced Linux Sound Architecture Driver Initialized.
[    0.149987] clocksource: Switched to clocksource timer
[    0.182595] NetWinder Floating Point Emulator V0.97 (double precision)
[    0.184953] Initialise system trusted keyrings
[    0.185690] workingset: timestamp_bits=30 max_order=13 bucket_order=0
[    0.204803] jffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
[    0.212791] Key type asymmetric registered
[    0.212919] Asymmetric key parser 'x509' registered
[    0.213147] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 252)
[    0.213240] io scheduler mq-deadline registered
[    0.213290] io scheduler kyber registered
[    0.226461] suniv-f1c100s-pinctrl 1c20800.pinctrl: initialized sunXi PIO driver
[    0.429017] Serial: 8250/16550 driver, 8 ports, IRQ sharing disabled
[    0.435430] suniv-f1c100s-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pe not found, using dummy regulator
[    0.437509] printk: console [ttyS0] disabled
[    0.457897] 1c25000.serial: ttyS0 at MMIO 0x1c25000 (irq = 24, base_baud = 6250000) is a 16550A
[    0.798164] printk: console [ttyS0] enabled
[    0.806566] suniv-f1c100s-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pd not found, using dummy regulator
[    0.825626] SCSI Media Changer driver v0.25 
[    0.831714] suniv-f1c100s-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pc not found, using dummy regulator
[    0.844905] m25p80 spi0.0: xt25f128 (16384 Kbytes)
[    0.851017] 4 fixed-partitions partitions found on MTD device spi0.0
[    0.857453] Creating 4 MTD partitions on "spi0.0":
[    0.862441] 0x000000000000-0x000000100000 : "u-boot"
[    0.871797] 0x000000100000-0x000000110000 : "dtb"
[    0.880718] 0x000000110000-0x000000510000 : "kernel"
[    0.889626] 0x000000510000-0x000001000000 : "rootfs"
[    0.899261] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    0.906035] ehci-platform: EHCI generic platform driver
[    0.911732] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[    0.918033] ohci-platform: OHCI generic platform driver
[    0.923875] usbcore: registered new interface driver usb-storage
[    0.930805] udc-core: couldn't find an available UDC - added [zero] to list of pending drivers
[    0.939811] i2c /dev entries driver
[    0.947538] suniv-f1c100s-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pf not found, using dummy regulator
[    0.986074] sunxi-mmc 1c0f000.mmc: initialized, max. request size: 16384 KB
[    0.995734] usbcore: registered new interface driver usbhid
[    1.001533] usbhid: USB HID core driver
[    1.025088] Loading compiled-in X.509 certificates
[    1.041188] suniv-f1c100s-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pd not found, using dummy regulator
[    1.052883] sun4i-backend 1e60000.display-backend: Couldn't find matching frontend, frontend features disabled
[    1.063897] sun4i-drm display-engine: bound 1e60000.display-backend (ops 0xc0637c94)
[    1.073128] sun4i-drm display-engine: bound 1c0c000.lcd-controller (ops 0xc06368ec)
[    1.081008] [drm] Supports vblank timestamp caching Rev 2 (21.10.2013).
[    1.087662] [drm] No driver support for vblank timestamp query.
[    1.095005] [drm] Initialized sun4i-drm 1.0.0 20150629 for display-engine on minor 0
[    1.347886] Console: switching to colour frame buffer device 100x30
[    1.401403] sun4i-drm display-engine: fb0: sun4i-drmdrmfb frame buffer device
[    1.423621] ALSA device list:
[    1.440940]   #0: Loopback 1
[    1.460822] random: fast init done
[    1.593734] random: crng init done
[    3.597483] VFS: Mounted root (jffs2 filesystem) on device 31:3.
[    3.619638] devtmpfs: mounted
[    3.643424] Freeing unused kernel memory: 1024K
[    3.662630] Run /sbin/init as init process
Starting logging: OK
Initializing random number generator... done.
Starting network: ip: socket: Function not implemented
ip: socket: Function not implemented
FAIL


Welcome to Buildroot

nano login:
```

ユーザ名: root
パスワード: licheepi

でログインできます。
適当にコマンドを打ってみます。
カーネルが5系ですね！

```
# uname -a
Linux nano 5.2.0-licheepi-nano+ #2 Thu Aug 1 09:45:44 UTC 2019 armv5tejl GNU/Linux
# cat /proc/cpuinfo
processor	: 0
model name	: ARM926EJ-S rev 5 (v5l)
BogoMIPS	: 203.16
Features	: swp half thumb fastmult edsp java 
CPU implementer	: 0x41
CPU architecture: 5TEJ
CPU variant	: 0x0
CPU part	: 0x926
CPU revision	: 5

Hardware	: Allwinner suniv Family
Revision	: 0000
Serial		: 0000000000000000
# 
```

Lチカできるでしょうか？
ラズパイと同じようにやってみます。

最初Pin番号がわからなかったのですが、回路図とLichee Pi Zeroの資料をみて、D0→E3→131を指定したら
LEDが点灯しました。

http://zero.lichee.pro/%E9%A9%B1%E5%8A%A8/GPIO_file.html
https://fdvad021asfd8q.oss-cn-hangzhou.aliyuncs.com/migrate/Lichee_nano.pdf


```
# echo 131 > /sys/class/gpio/export
# echo out > /sys/class/gpio/gpio131/direction 
# echo 1 > /sys/class/gpio/gpio131/value
# echo 0 > /sys/class/gpio/gpio131/value
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/146663/6b7e84a4-2e22-7789-bffc-fbd9efd28bb4.png)


####その他

・ドキュメント（中国語）
http://nano.lichee.pro/

・資料やSDKなど
https://pan.baidu.com/s/1smzuGS9#list/path=%2F&parentPath=%2Fsharelink3658413294-628283680456500

・同じSoC使った商品
https://ja.aliexpress.com/item/33050695657.html

購入した人のレビュー
https://ajiwai.hatenablog.com/entry/2019/07/04/124923

・同じSoCで自作基板起こした人！
https://gigazine.net/news/20191225-business-card-runs-linux/