Lichee RVの開発環境について


Lichee RVの開発環境について

Lichee RVの開発環境は、Allwinner社のD1-Hチップ用のTina LinuxをベースにSipeed社が追加した形で提供されています。

簡単な開発環境構築には、WSL2と提供されているDockerイメージを利用します。

WSL2

WSL2のインストールは、WindowsのPowerShellコンソールで次のコマンドを入力します

wsl --install

Docker

Dockerイメージは次の場所からダウンロードします。
licheerv_d1_compile.7z.001〜009

ダウンロード後7zipを使って licheerv_d1_compile.tar に解凍します。

import

WSL2でイメージをインポートします。

ディストリビューション名:TinaBuild
インストール場所:C:¥VirtVM¥Tina_build
ダウンロードしたイメージ:Downloads¥licheerv_d1_compile.tar

wsl --import TinaBuild C:¥VirtVM¥Tina_build Downloads¥licheerv_d1_compile.tar

開発環境の検証

イメージのnihaoユーザー下に開発環境が設定されているので、nihaoユーザーで実行します。

wsl -d TinaBuild -u nihao

WSLが起動したら、以下のコマンドで環境を設定します。

cd ~/sdk/tina-d1-open_new
source build/envsetup.sh
lunch

このようなメニューが表示されるので、1. d1_nezha-tina を選択すると、環境変数が設定されます。

You're building on Linux

Lunch menu... pick a combo:
     1. d1_nezha-tina
     2. d1_nezha_min-tina

Which would you like? [Default d1_nezha]: 1
============================================
TINA_BUILD_TOP=/home/nihao/sdk/tina-d1-open_new
TINA_TARGET_ARCH=riscv
TARGET_PRODUCT=d1_nezha
TARGET_PLATFORM=d1
TARGET_BOARD=d1-nezha
TARGET_PLAN=nezha
TARGET_BUILD_VARIANT=tina
TARGET_BUILD_TYPE=release
TARGET_KERNEL_VERSION=5.4
TARGET_UBOOT=u-boot-2018
TARGET_CHIP=sun20iw1p1
============================================

menuconfigでコンポーネントを設定します。alsa-pluginを無効にする必要があります。

make menuconfig

メニューが表示されます。

Librariesにカーソルキー↓を押して移動しEnterキーで選択します。

alsa-pluginsにカーソルキー↓を押して移動しSpaceキーで*を外します。
その後、Tabキーで、< Save >に移動し選択します。

OK で Enterします。

ESCキーを何度か押して終了します。

ビルドします。

make -j1

私の環境(Core i7 2.8GHz)ではmake -j1の場合ビルドに83分かかりました。

out/d1-nezha ディレクトリに以下のようなファイルが作成されます。

-rw-r--r--  1 nihao nihao   9750528 Feb 24 21:31 boot.img
drwxr-xr-x  5 nihao nihao      4096 Feb 24 20:21 compile_dir
-rwxr-xr-x  1 nihao nihao   9745036 Feb 24 21:31 d1-nezha-Image
-rw-r--r--  1 nihao nihao   9750528 Feb 24 21:31 d1-nezha-boot.img
-rw-r--r--  1 nihao nihao   9745100 Feb 24 21:31 d1-nezha-uImage
-rw-r--r--  1 nihao nihao       239 Feb 24 21:31 md5sums
drwxr-xr-x 10 nihao nihao      4096 Feb 24 21:32 packages
-rw-r--r--  1 nihao nihao 104857600 Feb 24 21:31 rootfs.img
-rw-r--r--  1 nihao nihao       524 Feb 24 21:31 sha256sums
drwxr-xr-x  4 nihao nihao      4096 Feb 24 20:21 staging_dir

packコマンドでAllwinner A10イメージを作成します。

pack
--==========--
PACK_CHIP         sun20iw1p1
PACK_PLATFORM     tina
PACK_BOARD        d1-nezha
PACK_KERN
PACK_DEBUG        uart0
PACK_SIG          none
PACK_SECURE       none
PACK_MODE         normal
PACK_FUNC         android
PACK_PROGRAMMER   none
PACK_TAR_IMAGE    none
PACK_TOPDIR       /home/nihao/sdk/tina-d1-open_new
--==========--
No kernel param, parse it from d1
copying tools file
copying configs file
storage_type value is 5
rm /home/nihao/sdk/tina-d1-open_new/out/d1-nezha/image/sys_partition_nor.fex
rm /home/nihao/sdk/tina-d1-open_new/out/d1-nezha/image/image_nor.cfg
copying boot resource

LZMA 4.65 : Igor Pavlov : Public domain : 2009-02-03
copying boot file
make user resource for : /home/nihao/sdk/tina-d1-open_new/out/d1-nezha/image/sys_partition.fex
handle partition user-res
no user resource partitions
APP_PART_DOWNLOAD_FILE = /home/nihao/sdk/tina-d1-open_new/out/d1-nezha/image/app.fex
Need size of filesystem
no data resource partitions
don't build dtbo ...
update_chip
pack boot package
GetPrivateProfileSection read to end
content_count=3
LICHEE_REDUNDANT_ENV_SIZE config in BoardConfig.mk
--mkenvimage create redundant env data!--
---redundant env data size 0x20000---
packing for tina linux
normal
this is not a partition key
gpt_head->header_crc32 = 0xf45be3b4
GPT----part num 8---
gpt_entry: 128
gpt_header: 92
GPT:boot-resource: 1f8           2177
GPT:env         : 2178          236f
GPT:env-redund  : 2370          2567
GPT:boot        : 2568          761f
GPT:dsp0        : 7620          7a0f
GPT:recovery    : 7a10          e84f
GPT:rootfs      : e850          100e84f
GPT:UDISK       : 100e850       100e85f
update gpt file ok
update mbr file ok
====================================
show "sys_partition_for_dragon.fex" message
------------------------------------
  [mbr]
  mbr_size  : 252 Kbyte
------------------------------------
  partition_name  : boot-resource
  partition_size  : 8064
  downloadfile  : boot-resource.fex
  boot-resource.fex size : 718K byte
------------------------------------
  partition_name  : env
  partition_size  : 504
  downloadfile  : env.fex
  env.fex size : 128K byte
------------------------------------
  partition_name  : env-redund
  partition_size  : 504
  downloadfile  : env.fex
  env.fex size : 128K byte
------------------------------------
  partition_name  : boot
  partition_size  : 20664
  downloadfile  : boot.fex
  boot.fex -> /home/nihao/sdk/tina-d1-open_new/out/d1-nezha/boot.img
  boot.img size : 9.3M byte
------------------------------------
  partition_name  : dsp0
  partition_size  : 1008
  downloadfile  : dsp0.fex
  dsp0.fex size : 258K byte
------------------------------------
  partition_name  : recovery
  partition_size  : 28224
------------------------------------
  partition_name  : rootfs
  partition_size  : 0x1000000
  downloadfile  : rootfs.fex
  rootfs.fex -> /home/nihao/sdk/tina-d1-open_new/out/d1-nezha/rootfs.img
  rootfs.img size : 100M byte
------------------------------------
  partition_name  : UDISK
------------------------------------
/home/nihao/sdk/tina-d1-open_new/out/host/bin/
/home/nihao/sdk/tina-d1-open_new/out/d1-nezha/image
Begin Parse sys_partion.fex
Add partion boot-resource.fex BOOT-RESOURCE_FEX
Add partion very boot-resource.fex BOOT-RESOURCE_FEX
FilePath: boot-resource.fex
FileLength=b3800Add partion env.fex ENV_FEX000000000
Add partion very env.fex ENV_FEX000000000
FilePath: env.fex
FileLength=20000Add partion env.fex ENV_FEX000000000
Add partion very env.fex ENV_FEX000000000
FilePath: env.fex
FileLength=20000Add partion boot.fex BOOT_FEX00000000
Add partion very boot.fex BOOT_FEX00000000
FilePath: boot.fex
FileLength=94c800Add partion dsp0.fex DSP0_FEX00000000
Add partion very dsp0.fex DSP0_FEX00000000
FilePath: dsp0.fex
FileLength=4059cAdd partion rootfs.fex ROOTFS_FEX000000
Add partion very rootfs.fex ROOTFS_FEX000000
FilePath: rootfs.fex
FileLength=6400000sys_config.fex Len: 0x4ec3
config.fex Len: 0x6c00
board.fex Len: 0x400
split_xxxx.fex Len: 0x200
sys_partition.fex Len: 0xc2b
sunxi.fex Len: 0xd600
boot0_nand.fex Len: 0x10000
boot0_sdcard.fex Len: 0x10000
u-boot.fex Len: 0xa0000
u-boot-crash.fex Len: 0x25
toc1.fex Len: 0x8
toc0.fex Len: 0x8
fes1.fex Len: 0xa560
boot_package.fex Len: 0xc0000
usbtool.fex Len: 0x24e00
usbtool_crash.fex Len: 0x1ec00
aultools.fex Len: 0x28a73
aultls32.fex Len: 0x25205
cardtool.fex Len: 0x11e00
cardscript.fex Len: 0x6de
sunxi_gpt.fex Len: 0x2000
sunxi_mbr.fex Len: 0x10000
dlinfo.fex Len: 0x4000
arisc.fex Len: 0xf
vmlinux.fex Len: 0x8
tinaconf.fex Len: 0xe177
boot-resource.fex Len: 0xb3800
Vboot-resource.fex Len: 0x4
env.fex Len: 0x20000
Venv.fex Len: 0x4
env.fex Len: 0x20000
Venv.fex Len: 0x4
boot.fex Len: 0x94c800
Vboot.fex Len: 0x4
dsp0.fex Len: 0x4059c
Vdsp0.fex Len: 0x4
rootfs.fex Len: 0x6400000
Vrootfs.fex Len: 0x4
BuildImg 0
Dragon execute image.cfg SUCCESS !
----------image is for nand/emmc----------
----------image is at----------

/home/nihao/sdk/tina-d1-open_new/out/d1-nezha/tina_d1-nezha_uart0.img

pack finish

/home/nihao/sdk/tina-d1-open_new/out/d1-nezha/tina_d1-nezha_uart0.img に作成されたイメージを、Windowsのフォルダーにコピーして、PhoenixCardでSDカードに書き込みます。

cp /home/nihao/sdk/tina-d1-open_new/out/d1-nezha/tina_d1-nezha_uart0.img /mnt/c/VirtVM

(私の方は使用しないので問題ありませんが、現時点で、提供されているイメージには8723dsドライバーは含まれていないようです。Megaの同じフォルダーにソースがpatchの形式で提供されています)

Hello World

開発環境の動作確認ができたので、Hello Worldアプリを実行してみます。

前のWSL環境から引き続き、nihaoユーザーのホームに移動してソースを作成します。

cd ~
vi hello_world.c
hello_world.c
#include <stdio.h>
int main(int argc, char const *argv[])
{
    printf("Hello NeZha\n");
    return 0;
}

コンパイルします

sdk/tina-d1-open_new/prebuilt/gcc/linux-x86/riscv/toolchain-thead-glibc/riscv64-glibc-gcc-thead_20200702/bin/riscv64-unknown-linux-gnu-gcc -o hello_world hello_world.c

adbでLichee RVに転送するため、一旦WSLイメージからWindowsファイルシステムにコピーします

cp hello_world /mnt/c/VirtVM

WindowsコマンドプロンプトのadbでLichee RVにファイルを転送します。

cd C:\Users\....>cd C:\Users\....\AppData\Local\Android\Sdk\platform-tools
adb push C:\VirtVM\hello_world /root

Lichee RVでHello Worldを動かしてみます。

adb shell
cd /root
chmod 755 hello_world
./hello_world
Hello NeZha

完成しました