Milk-V Duo runs openEuler RISC-V

I saw some people successfully running Archlinux RISC-V, so it should also work for openEuler RISC-V

The entire process was completed on Archlinux, and the compilation was run in a schroot container with Ubuntu 20.04 LTS. The environment configuration can be referenced from this post.

Building the Image

This part is completed within the Ubuntu 20.04 LTS container.

mkdir somewhere && cd somewhere
git clone https://github.com/milkv-duo/duo-buildroot-sdk.git
cd duo-buildroot-sdk/

Because I am not quite sure about which kernel configurations it depends on, I copied the kernel configuration completely from Milkv-duo Running Arch Linux System.

vim build/boards/cv180x/cv1800b_milkv_duo_sd/linux/cvitek_cv1800b_milkv_duo_sd_defconfig

# for openEuler
CONFIG_CGROUPS=y
CONFIG_CGROUP_FREEZER=y
CONFIG_CGROUP_PIDS=y
CONFIG_CGROUP_DEVICE=y
CONFIG_CPUSETS=y
CONFIG_PROC_PID_CPUSET=y
CONFIG_CGROUP_CPUACCT=y
CONFIG_PAGE_COUNTER=y
CONFIG_MEMCG=y
CONFIG_CGROUP_SCHED=y
CONFIG_NAMESPACES=y
CONFIG_OVERLAY_FS=y
CONFIG_AUTOFS4_FS=y
CONFIG_SIGNALFD=y
CONFIG_TIMERFD=y
CONFIG_EPOLL=y
CONFIG_IPV6=y
CONFIG_FANOTIFY

Since I am not using the camera (and also due to memory constraints), I set ION_SIZE to 0M:

vim build/boards/cv180x/cv1800b_milkv_duo_sd/memmap.py

# line 43
ION_SIZE = 0

Due to the relatively large size of the rootfs for openEuler RISC-V, I increased the size of the root partition of the image.

vim milkv/genimage-milkv-duo.cfg

# line 16
size = 2048M

One-click compilation:

./build_milkv.sh

Finally, you can see the successful compilation log:

Gen image successful: out/milkv-duo-20230815-1447.img

Copy this image out for future use.

Replace the root file system

Exit from the container and copy the image

cp /PATH/TO/CHROOT/duo-buildroot-sdk/out/milkv-duo-20230815-1447.img .
cp milkv-duo-20230815-1447.img milkv-duo-openeuler.img

Check available loopback devices, which is shown as /dev/loop0 in my case

sudo losetup -f

Bind the device

sudo losetup /dev/loop0 milkv-duo-openeuler.img

Load the partition, and you can see two partitions

sudo kpartx -av /dev/loop0

add map loop0p1 (254:0): 0 262144 linear 7:0 1
add map loop0p2 (254:1): 0 4194304 linear 7:0 262145

View the devices, you can see loop0p1 and loop0p2 two partitions, of which loop0p2 is the root partition

ls /dev/mapper/

control  loop0p1  loop0p2

Mount

sudo mkdir /mnt/sd
sudo mount /dev/mapper/loop0p2 /mnt/sd

Download oErv 23.03 V1

wget https://mirror.iscas.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/preview/openEuler-23.03-V1-riscv64/openeuler-rootfs.tar.gz

Delete everything

cd /mnt/sd
sudo rm -r ./*

Extract oErv rootfs

tar zxvf /PATH/TO/openeuler-rootfs.tar.gz

Suddenly, the disk space is insufficient. However, after running df -i, I found that this 2G partition only has 4096 inodes, so I have to re-create the ext4 file system and extract again.
Using the same method, I mounted the second partition of the original image to /mnt/sd1, and copied the kernel modules and scripts inside.

sudo cp -r /mnt/sd1/mnt/system /mnt/sd/mnt
sudo cp /mnt/sd1/etc/run_usb.sh /mnt/sd/etc/
sudo cp /mnt/sd1/etc/uhubon.sh /mnt/sd/etc/
sudo cp /mnt/sd1/etc/init.d/S99user /mnt/sd/etc/init.d/

chroot into rootfs (qemu required), run neofetch, and install dhcp

# Enter chroot
sudo cp /etc/resolv.conf /mnt/sd/etc/resolv.conf
chroot /mnt/sd

# Install neofetch
wget https://github.com/dylanaraps/neofetch/raw/master/neofetch
mv neofetch /usr/bin/
chmod +x /usr/bin/neofetch

# Install dhcp for RNDIS
dnf install dhcp
cat <<EOF >> /etc/dhcp/dhcpd.conf
subnet 192.168.42.0 netmask 255.255.255.0 {
        option routers 192.168.42.1;
        range 192.168.42.100 192.168.42.200;
}
EOF
# systemctl enable dhcpd

Unmount

sudo umount /mnt/sd
sudo kpartx -d /dev/loop0
sudo losetup -d /dev/loop0

oErv is up and running!

Burn the image, pay attention to the image path and target device

dd if=/PATH/TO/milkv-duo-openeuler.img of=/dev/sdX bs=4M status=progress
sync

Serial connection

Name Pin
TX 16
RX 17
GND 18

Since I don’t have header pins at the moment, I connected it directly with DuPont wires to the holes and the USB serial connection. Surprisingly, the connection worked well, and communication is normal.

sudo minicom -D /dev/ttyUSB0

Then, it will boot up! The username is “root,” and the password is “openEuler12#$.”

[root@openeuler-riscv64 ~]# neofetch
                 `.cc.`
             ``.cccccccc..`                ----------------------
          `.cccccccccccccccc.`             OS: openEuler 23.03 riscv64
      ``.cccccccccccccccccccccc.``         Host: Cvitek. CV180X ASIC. C906.
   `..cccccccccccccccccccccccccccc..`      Kernel: 5.10.4-tag-
`.ccccccccccccccc/++/ccccccccccccccccc.`   Uptime: 52 secs
.cccccccccccccccmNMMNdo+oso+ccccccccccc.   Shell: bash 5.1.9
.cccccccccc/++odms+//+mMMMMm/:+syso/cccc   Terminal: /dev/ttyS0
.cccccccccyNNMMMs:::/::+o+/:cdMMMMMmcccc   CPU: (1)
.ccccccc:+NmdyyhNNmNNNd:ccccc:oyyyo:cccc   Memory: 33MiB / 55MiB
.ccc:ohdmMs:cccc+mNMNmyccccccccccccccccc
.cc/NMMMMMo////:c:///:cccccccccccccccccc
.cc:syysyNMNNNMNyccccccccccccccccccccccc
.cccccccc+MMMMMNyc:/+++/cccccccccccccccc
.cccccccccohhhs/comMMMMNhccccccccccccccc
.ccccccccccccccc:MMMMMMMM/cccccccccccccc
.ccccccccccccccccsNNNNNd+cccccccccccccc.
`..cccccccccccccccc/+/:cccccccccccccc..`
   ``.cccccccccccccccccccccccccccc.``
       `.cccccccccccccccccccccc.`
          ``.cccccccccccccc.``
              `.cccccccc.`
                 `....`

[root@openeuler-riscv64 ~]#

Enable UNDIS

systemctl start S99user
systemctl start dhcpd

More work is needed to automatically enable UNDIS, but I’ll write it here for now.

And, there is not enough memory.

To be honest, that SD card is not very friendly, and I almost tore off the LED.

by ISCAS weilinfox