<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[基于社区最新开源仓库（Opensbi、Linux）构建nezha - d1开发环境]]></title><description><![CDATA[<p dir="auto"><strong><strong>一、 本文目的</strong></strong></p>
<p dir="auto">介绍如何基于NEZHA-D1平台搭建社区最新的opensbi和Linux最小系统。<br />
启动分为两大阶段：<br />
第一阶段brom-&gt;boot0-&gt;uboot，该阶段固件烧写在nand flash。<br />
第二阶段：opensbi-&gt;kernel-&gt;rootfs，该阶段固件存储在TF卡上。TF卡实现2个分区，分区1为FAT文件系统，方便开发者拷贝linux、dtb、opensbi等固件，分区2为EXT4的rootfs。</p>
<p dir="auto"><strong>二、实验准备</strong></p>
<p dir="auto">硬件：nezha开发板+电源线+串口线+TF卡<br />
软件：github仓库：<strong><a href="https://github.com/chinchilla222/nezha-d1.git" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/chinchilla222/nezha-d1.git</a></strong></p>
<p dir="auto">nezha-d1仓库简要说明：</p>
<p dir="auto">├── <a href="http://build.sh" target="_blank" rel="noopener noreferrer nofollow ugc">build.sh</a> -&gt; scripts/build.sh  -- 编译脚本<br />
├── HOW-TO-CN.txt  -- 说明文档<br />
├── <a href="http://README.md" target="_blank" rel="noopener noreferrer nofollow ugc">README.md</a><br />
├── resource  -- 代码资源<br />
│   ├── linux -- 存放最小系统必要的patch<br />
│   │   ├── 0001-riscv-pgtable.h-Fixup-_PAGE_CHG_MASK-usage.patch<br />
│   │   ├── 0002-riscv-Add-DMA_COHERENT-for-custom-PTE-attributes.patch<br />
│   │   ├── 0003-riscv-Add-SYNC_DMA_FOR_CPU-DEVICE-for-DMA_COHERENT.patch<br />
│   │   ├── 0004-dt-bindings-clk-sunxi-ccu-add-compatible-string-for-.patch<br />
│   │   ├── 0005-clk-sunxi-ng-add-support-for-the-Allwinner-D1-CCU.patch<br />
│   │   ├── 0006-dt-bindings-pinctrl-sunxi-Add-D1-pinctrl-bindings.patch<br />
│   │   ├── 0007-pinctrl-sunxi-add-support-for-the-Allwinner-D1-pin-c.patch<br />
│   │   ├── 0008-rv64-allwinner-d1-add-the-basical-d1-dtsi-file.patch<br />
│   │   ├── 0009-rv64-allwinner-D1-add-support-for-Allwinner-nezha-bo.patch<br />
│   │   ├── 0010-mmc-sunxi-mmc-add-mmc0-support-on-d1-and-fix-clk-set.patch<br />
│   │   ├── 0011-riscv-d1-nezha-default-config.patch<br />
│   │   ├── 0012-rv64-allwinner-d1-support-card-boot-ext4-file-system.patch<br />
│   │   └── useless-patch -- 暂时无用<br />
│   │       ├── 0001-dump_reg-support-interface-to-Read-Write-IO.patch<br />
│   │       ├── 0001-riscv-pgtable.h-Fixup-_PAGE_CHG_MASK-usage.patch<br />
│   │       ├── 0002-gmac-support-temporary-driver.patch<br />
│   │       ├── 0002-riscv-Add-DMA_COHERENT-for-custom-PTE-attributes.patch<br />
│   │       ├── 0003-riscv-Add-SYNC_DMA_FOR_CPU-DEVICE-for-DMA_COHERENT.patch<br />
│   │       └── 0004-drivers-ccu-pinctrl-uart-gmac-mmc-driver-support.patch<br />
│   ├── opensbi  -- 社区最新opensbi源码<br />
│   │   └── opensbi-master.zip<br />
│   ├── rootfs -- 编译好根文件系统<br />
│   │   └── rootfs.tar.gz<br />
│   └── tools -- 存放开发需要的工具<br />
│       ├── make_ext4fs<br />
│       ├── mkbootimg<br />
│       └── toolchain -- 存放PTG工具链<br />
│           ├── riscv64-glibc-gcc-thead_20200702.tar.xz.00<br />
│           ├── riscv64-glibc-gcc-thead_20200702.tar.xz.01<br />
│           └── riscv64-glibc-gcc-thead_20200702.tar.xz.02<br />
├── scripts<br />
│   ├── <a href="http://build.sh" target="_blank" rel="noopener noreferrer nofollow ugc">build.sh</a><br />
│   └── gdbinit<br />
└── tina-d1-open -- 存放基于tina-d1-open仓库编译好的固件（更改了启动顺序）<br />
├── 0001-d1-add-new-board-nezha_debug.patch<br />
├── 0001-uboot-nezha-suport-boot0-uboot-opensbi-kernel-startu.patch<br />
└── tina_d1-nezha_debug_uart0.img</p>
<p dir="auto"><strong>三、 搭建环境</strong></p>
<p dir="auto"><em><strong>1、下载nezha-d1仓库</strong></em></p>
<p dir="auto">git clone <a href="https://github.com/chinchilla222/nezha-d1.git" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/chinchilla222/nezha-d1.git</a>  由于仓库中包含交叉编译工具，下载速度会受影响，请大家耐心等待。</p>
<p dir="auto"><em><strong>2、烧写固件</strong></em>：nezha-d1/tina-d1-open/tina_d1-nezha_debug_uart0.img</p>
<p dir="auto">tina_d1-nezha_debug_uart0.img固件同tina-d1-open源码仓库编译打包的原生固件区别在于修改了启动顺序，并且在uboot阶段修改直接引导TF卡中opensbi、kernel的功能。（原流程：brom-&gt;boot0-&gt;opensbi-&gt;uboot-&gt;kernel，改后：brom-&gt;boot0-&gt;uboot-&gt;opensbi-&gt;kernel）</p>
<p dir="auto"><em><strong>3、编译opensbi/kernel/dtb</strong></em></p>
<p dir="auto"><strong>3.1、自动编译</strong><br />
执行scripts/build.sh脚本，生成的目标文件输出至build/debug目录。</p>
<p dir="auto">3.2、手动编译 - <strong>下文中提到的命令为示意性命令，请大家根据实际的目录结构使用。已经执行了build.sh脚本的同学忽略3.2，以及第4/5节的操作</strong></p>
<p dir="auto">（1）创建临时目录：mkdir build</p>
<p dir="auto">（2）准备工具链：tar xvf resource/tools/riscv64-glibc-gcc-thead_20200702.tar.xz -C build/</p>
<p dir="auto">（3）编译linux</p>
<ul>
<li>
<p dir="auto">解压：tar xzvf resource/linux/linux-5.13-rc3.tar.gz  -C build/</p>
</li>
<li>
<p dir="auto">打补丁：cd nezha-d1/build/linux-5.13-rc3;git init; git add ./; git commit -s -m "init version";git am *.patch</p>
</li>
<li>
<p dir="auto">编译：<br />
make ARCH=riscv CROSS_COMPILE=../riscv64-glibc-gcc-thead_20200702/bin/riscv64-unknown-linux-gnu- d1_nezha_defconfig<br />
make ARCH=riscv CROSS_COMPILE=../riscv64-glibc-gcc-thead_20200702/bin/riscv64-unknown-linux-gnu- all -j32</p>
</li>
<li>
<p dir="auto">生成boot.img：./mkbootimg --kernel Image --board sun20i_riscv --base 0x40200000 --kernel_offset 0  -o boot.img</p>
</li>
</ul>
<p dir="auto"><em><strong>4、编译opensbi</strong></em></p>
<p dir="auto">（1）解压：unzip resource/opensbi/opensbi-master.zip -d build/</p>
<p dir="auto">（2）编译：make PLATFORM=generic CROSS_COMPILE=../riscv64-glibc-gcc-thead_20200702/bin/riscv64-unknown-linux-gnu-</p>
<p dir="auto"><strong>5、制作EXT4根文件系统</strong>*</p>
<p dir="auto">（1）tar -xzvf resource/rootfs/rootfs.tar.gz -C build/</p>
<p dir="auto">（2）make_ext4fs -l 256M roofs.ext4 rootfs/</p>
<p dir="auto"><em><strong>6、 制作启动卡</strong></em></p>
<p dir="auto">（1）制作GPT分区，工具：parted，举例：分区1 - 1G到12G 区间，分区2 - 12G至25G区间</p>
<ul>
<li>parted -s /dev/sdb mklabel gpt</li>
<li>parted -s /dev/sdb unit GB mkpart primary 1 12</li>
<li>parted -s /dev/sdb unit GB mkpart primary 12 25</li>
<li>parted -s /dev/sdb print</li>
</ul>
<p dir="auto">（2）格式化分区1，工具：mkfs.fat，举例：mkfs.fat /dev/sdb1。将boot.img，d1.dtb，d1.dtb拷贝到TF卡的分区1中。</p>
<p dir="auto">（3）烧写分区2，工具：dd，举例：dd if=./build/rootfs.ext4 of=/dev/sdb2</p>
<p dir="auto"><em><strong>7.将TF卡插入开发板，上电启动，大功告成。</strong></em></p>
]]></description><link>https://bbs.aw-ol.com/topic/178/基于社区最新开源仓库-opensbi-linux-构建nezha-d1开发环境</link><generator>RSS for Node</generator><lastBuildDate>Sat, 14 Mar 2026 10:44:10 GMT</lastBuildDate><atom:link href="https://bbs.aw-ol.com/topic/178.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 05 Jul 2021 12:52:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to 基于社区最新开源仓库（Opensbi、Linux）构建nezha - d1开发环境 on Tue, 06 Jul 2021 11:04:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://bbs.aw-ol.com/uid/54">@damon</a> 其实就是没有SDK 整编来的快  没有SDK make 设置来的方便</p>
]]></description><link>https://bbs.aw-ol.com/post/673</link><guid isPermaLink="true">https://bbs.aw-ol.com/post/673</guid><dc:creator><![CDATA[BedRock]]></dc:creator><pubDate>Tue, 06 Jul 2021 11:04:45 GMT</pubDate></item><item><title><![CDATA[Reply to 基于社区最新开源仓库（Opensbi、Linux）构建nezha - d1开发环境 on Tue, 06 Jul 2021 01:40:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://bbs.aw-ol.com/uid/149">@aiminick</a> 在 <a href="/post/657">基于社区最新开源仓库（Opensbi、Linux）构建nezha - d1开发环境</a> 中说：</p>
<blockquote>
<p dir="auto">分开也有分开的优势，这种复合型的可定制化程度没有单独的方便。<br />
没有理解你的意思，可以描述的再详细一点吗？</p>
</blockquote>
]]></description><link>https://bbs.aw-ol.com/post/660</link><guid isPermaLink="true">https://bbs.aw-ol.com/post/660</guid><dc:creator><![CDATA[damon]]></dc:creator><pubDate>Tue, 06 Jul 2021 01:40:08 GMT</pubDate></item><item><title><![CDATA[Reply to 基于社区最新开源仓库（Opensbi、Linux）构建nezha - d1开发环境 on Mon, 05 Jul 2021 13:12:14 GMT]]></title><description><![CDATA[<p dir="auto">分开也有分开的优势，这种复合型的可定制化程度没有单独的方便。</p>
]]></description><link>https://bbs.aw-ol.com/post/657</link><guid isPermaLink="true">https://bbs.aw-ol.com/post/657</guid><dc:creator><![CDATA[aiminick]]></dc:creator><pubDate>Mon, 05 Jul 2021 13:12:14 GMT</pubDate></item></channel></rss>