# Milk-V Duo 运行Open-Wrt系统

仓库地址：<https://github.com/Pillar1989/VizOS>

开始编译Open-Wrt之前请保证已经安装RISC-V交叉编译工具。

检测方法：

```bash
riscv64-unknown-linux-musl-gcc --version 
```

交叉编译工具安装方法：

打开[github](https://github.com/riscv-collab/riscv-gnu-toolchain/releases/tag/2024.04.12)下载压缩包：

<figure><img src="https://1162625277-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FztE2V8982Hhix6DGmMHJ%2Fuploads%2FNbBGlPawHai28v0Z9FNy%2Fimage.png?alt=media&#x26;token=f80bf272-d681-43cc-8f3f-77ecba3ebe30" alt=""><figcaption></figcaption></figure>

解压后移动至某一位置,例如`/opt`

然后加入环境变量。在.zshrc中添加一行：

```bash
export PATH="/opt/riscv64-musl-ubuntu-22.04-gcc-nightly-2024.04.12-nightly/riscv/bin:$PATH"
```

然后source .zshrc或者重启一下shell。

```
riscv64-unknown-linux-musl-gcc --version
```

就能得到正确版本号了。

再来安装一些必要的依赖：

```bash
sudo apt update
sudo apt install ack antlr3 aria2 asciidoc autoconf automake autopoint binutils bison build-essential bzip2 ccache cmake cpio curl device-tree-compiler fastjar flex gawk gettext gcc-multilib g++-multilib git gperf haveged help2man intltool libc6-dev-i386 libelf-dev libglib2.0-dev libgmp3-dev libltdl-dev libmpc-dev libmpfr-dev libncurses5-dev libncursesw5-dev libreadline-dev libssl-dev libtool lrzsz mkisofs msmtp nano ninja-build p7zip p7zip-full patch pkgconf python3 python3-pip libpython3-dev qemu-utils rsync rename scons squashfs-tools subversion swig texinfo uglifyjs upx-ucl unzip vim wget xmlto xxd zlib1g-dev
```

下载并安装格外的工具：

```bash
wget https://sophon-file.sophon.cn/sophon-prod-s3/drive/23/03/07/16/host-tools.tar.gz
tar xf host-tools.tar.gz
sudo mv host-tools /opt/host-tools

wget https://mirrors.sdu.edu.cn/ubuntu/ubuntu/pool/universe/g/genimage/genimage_16-2_amd64.deb
sudo apt install libconfuse2 genext2fs
sudo dpkg -i genimage_16-2_amd64.deb
```

克隆必要的仓库：

```bash
git clone -b vizos --single-branch https://github.com/Pillar1989/VizOS feeds-vizos
git clone https://github.com/Pillar1989/openwrt --single-branch
```

配置OpenWrt：

```bash
cd openwrt
echo "src-link vizos ${PWD}/../feeds-vizos" >> feeds.conf.default
./scripts/feeds update vizos
./scripts/feeds install vizos
./scripts/feeds install -f sophgo
./scripts/feeds install -f uboot-sophgo
```

应用配置：

```bash
cp ../feeds-vizos/configs/cv180x-config .config
```

编译：

```bash
make -j$(nproc) || make package/feeds/vizos/uboot-sophgo/compile V=s
make -j1 V=s
```

编译完成后，镜像文件应该位于：

```bash
bin/targets/sophgo/cv180x/
```

<figure><img src="https://1162625277-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FztE2V8982Hhix6DGmMHJ%2Fuploads%2FsB8AYYyklmgEXMCeyjwA%2Fimage.png?alt=media&#x26;token=9a395a7c-2567-46e0-b0fc-3d90c1915f33" alt=""><figcaption></figcaption></figure>

然后将镜像烧录进Milk-V Duo就好了

注意事项：

* 确保你有足够的磁盘空间和内存进行编译。
* 编译过程可能需要几个小时，取决于你的硬件配置。
* 如果遇到错误，可以尝试使用单线程编译（`make -j1 V=s`）来获取更详细的错误信息。
* 确保你的网络连接良好，因为编译过程中需要下载许多包。
