From Fedora Project Wiki
Idea.png
您有疑问?
请加入 Fedora riscv 的 IRC: #fedora-riscv[?] 位于 Libera
Nezha.png

哪吒是一个基于全志 D1的单板计算机(SBC). 此页用于集中所有关于Fedora on Nezha的信息.

在哪吒上启动Fedora的最简说明

预编译的镜像文件

我们已经为您准备好一个可以在全志 D1上直接运行的预编译Fedora镜像文件: Fedora-riscv64-d1-developer-xfce-with-esp-Rawhide-20210723-173234.n.0-sda.raw.zst

您只需要做以下操作:

解压镜像文件

unzstd  Fedora-riscv64-d1-developer-xfce-with-esp-Rawhide-20210723-173234.n.0-sda.raw.zst

写入一个TF卡 (必须大于或等于16GB)

sudo wipefs -a /dev/sdX
sudo dd if=Fedora-riscv64-d1-developer-xfce-with-esp-Rawhide-20210723-173234.n.0-sda.raw of=/dev/sdX status=progress bs=4M

请在烧录前一定要使用wipefs清理备份的GPT分区表,否则会出现这种问题:Architectures/RISC-V/Allwinner/zh-cn#内核无法访挂载rootfs

插入TF卡并上电

  • 默认是在 LCD (竖屏)上显示:
Allwinner D1 LCD.jpg
  • (可选) 转换到HDMI显示器上 (仅支持 1080p 模式竖屏)
cd /sys/kernel/debug/dispdbg
echo disp0 > name; echo switch1 > command; echo 4 10 0 0 0x4 0x101 0 0 0 8 > param; echo 1 > start;

可能出现的问题

内核无法访挂载rootfs

如果你出现以下启动失败的问题:

[    9.015501] md: Waiting for all devices to be available before autodetect
[    9.039910] md: If you don't use raid, use raid=noautodetect
[    9.064235] md: Autodetecting RAID arrays.
[    9.085291] md: autorun ...
[    9.104713] md: ... autorun DONE.
[    9.126379] List of all partitions:
[    9.146691] b300        15558144 mmcblk0 
[    9.146697]  driver: mmcblk
[    9.186490]   b301         1048576 mmcblk0p1 1676bb7b-c349-4f5b-a48a-0f77d0cb680b
[    9.186495] 
[    9.228663]   b302              32 mmcblk0p2 de35d1f7-9081-4f33-8952-3bc51a4b10c6
[    9.228668] 
[    9.270932]   b303           16384 mmcblk0p3 47aae416-9ac3-47dc-a4f4-8023251eaefc
[    9.270937] 
[    9.313210]   b304        14491119 mmcblk0p4 b93e5544-034f-41b7-b64d-1d7c2a5cfe58
[    9.313214] 
[    9.355206] No filesystem could mount root, tried: 
[    9.355212]  ext4
[    9.376478] 
[    9.411420] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(179,4)
[    9.436391] CPU: 0 PID: 1 Comm: swapper Not tainted 5.4.61 #3
[    9.458151] Call Trace:
[    9.475929] [<ffffffe0000d6598>] walk_stackframe+0x0/0xc4
[    9.496999] [<ffffffe0000d6838>] show_stack+0x3c/0x46
[    9.517441] [<ffffffe000bb19f6>] dump_stack+0x24/0x2c
[    9.537749] [<ffffffe0000e1f0a>] panic+0x100/0x32a
[    9.557557] [<ffffffe000001522>] 0xffffffe000001522
[    9.577224] [<ffffffe0000015e2>] 0xffffffe0000015e2
[    9.596711] [<ffffffe00000173c>] 0xffffffe00000173c
[    9.616044] [<ffffffe00000105e>] 0xffffffe00000105e
[    9.635113] [<ffffffe000bc6e5a>] kernel_init+0x1c/0x100
[    9.654494] [<ffffffe0000d4838>] ret_from_exception+0x0/0xc
[    9.674194] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(179,4) ]---

说明您使用的SD卡存在GPT分区表残留,导致内核不知道如何找到rootfs。(似乎您忘记了在烧写前使用wipefs清理GPT备份分区表) 解决的办法如下:

  • 将出问题的SD卡插入PC,通过gdisk清除残余的分区表,过程如下:
$ sudo gdisk  /dev/sdf
GPT fdisk (gdisk) version 1.0.5

Caution: invalid main GPT header, but valid backup; regenerating main header
from backup!

Warning: Invalid CRC on main header data; loaded backup partition table.
Warning! Main and backup partition tables differ! Use the 'c' and 'e' options
on the recovery & transformation menu to examine the two tables.

Warning! Main partition table CRC mismatch! Loaded backup partition table
instead of main partition table!

Warning! One or more CRCs don't match. You should repair the disk!
Main header: ERROR
Backup header: OK
Main partition table: ERROR
Backup partition table: OK

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: damaged

Found valid MBR and corrupt GPT. Which do you want to use? (Using the
GPT MAY permit recovery of GPT data.)
 1 - MBR
 2 - GPT
 3 - Create blank GPT

Your answer: 1

Command (? for help): p
Disk /dev/sdf: 62333952 sectors, 29.7 GiB
Model: Multi-Reader  -3
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 632BFA1B-F09D-42A8-82F4-5FAB32E41DC2
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 62333918
Partitions will be aligned on 2048-sector boundaries
Total free space is 37084093 sectors (17.7 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   2           69632          319487   122.0 MiB   0700  Microsoft basic data
   3          319488         1320959   489.0 MiB   8300  Linux filesystem
   4         1320960        25319423   11.4 GiB    8300  Linux filesystem

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdf.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.

如果此过程中导致您的 boot0_sdcard_sun20iw1p1.bin 或者 boot_package.fex 受损,请通过以下预编译固件修复

修复SD卡中的启动固件
  • 针对5.4内核
   * boot0_sdcard_sun20iw1p1.bin
   * boot_package.fex
sudo dd if=boot_package.fex of=/dev/sdf seek=32800 bs=512
sudo dd if=boot0_sdcard_sun20iw1p1.bin of=/dev/sdf seek=16 bs=512
  • 建议:先刷boot_package.fex,再刷boot0_sdcard_sun20iw1p1.bin
桌面自动息屏

XFCE桌面有自动节能息屏功能,如果需要禁用息屏,操作如下:

  • 登录桌面后,菜单,applications-> settings-> xscreensaver里选disable
Open xscreensaver.png
Disable screensaver.png


  • 登录桌面后,在桌面中运行一个terminal,在其中使用 root 权限运行命令:sudo xset s 0
Set s 0.png

硬件信息

IP 信息

平头哥: 玄铁 C906 RISC-V

Soc 和开发板信息

全志: D1 SoC 介绍

Sunxi: D1芯片

Sunxi: 全志哪吒开发板

软件

Boot order allwinner nezha grub.png

参考源码

最初源码来源

为了获取源码,您需要注册并登录.

Smaeul的仓库

Tekkaman用于Fedora Image的仓库

固件构建顺序

Build order allwinner nezhe grub.png

SPL(Boot0)

`boot0 或者 SPL (二级程序加载器) 是 BootROM 之后的第一个被执行的程序, 负责初始化内存控制器和加载下一级固件(来自于固态存储,闪存或者SD卡)。

使用可直接使用 Smaeul的SPL,也可以使用 Tekkaman 的fork

编译
git clone https://github.com/tekkamanninja/sun20i_d1_spl
pushd sun20i_d1_spl
git checkout origin/mainline
make CROSS_COMPILE=riscv64-linux-gnu- p=sun20iw1p1 mmc
popd
导入SD卡
pushd sun20i_d1_spl
sudo dd if=nboot/boot0_sdcard_sun20iw1p1.bin of=/dev/sdX bs=512 seek=16

OpenSBI

RISC-V 开源管理者模式(Supervisor)二进制接口, 类似 arm-TF

本文主要使用 Smaeul 的补丁, 但是会 rebase 到最新的主线上游 OpenSBI, 并修复可能出现的小问题。

Tekkaman 的 OpenSBI 仓库

编译
git clone https://github.com/tekkamanninja/opensbi -b allwinner_d1
pushd opensbi
CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic FW_PIC=y make
popd

最终结果中的 build/platform/generic/firmware/fw_dynamic.bin 将在下面被放入 u-boot.toc1

U-boot

本文主要使用 Smaeul 的补丁, 但是会 rebase 到最新的主线上游 U-boot, 并使能更多的特性并添加一些运行时的默认环境变量来自动载入 GRUB。

Tekkaman 的 U-boot 仓库

编译
git clone https://github.com/tekkamanninja/u-boot -b allwinner_d1
pushd u-boot
make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv nezha_defconfig
make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv menuconfig
make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv u-boot.bin u-boot.dtb
popd

最终生成的u-boot.binu-boot.dtb 将在下面被放入 u-boot.toc1 中.

创建 u-boot.toc1

  • 下面需要使用的配置文件 toc1.cfg 如下:
[opensbi]
file = fw_dynamic.bin
addr = 0x40000000
[dtb]
file = u-boot.dtb
addr = 0x44000000
[u-boot]
file = u-boot.bin
addr = 0x4a000000
  • 构建命令:

首先拷贝配置文件和opensbi,连同本目录中的u-boot.dtb以及u-boot.bin一起生成 u-boot.toc1。

pushd u-boot
cp ${PATH_TO_TOC1_CFG}/toc1.cfg ${PATH_TO_OPENSBI}/fw_dynamic.bin .
tools/mkimage -T sunxi_toc1 -d toc1.cfg  u-boot.toc1
popd

导入 u-boot.toc1 到 SD 卡中

pushd u-boot
sudo dd if=u-boot.toc1 of=/dev/sdX bs=512 seek=32800

GRUB for RISC-V

请仓库这个页面来编译GRUB2 for RISCV: Architectures/RISC-V/GRUB2

你可以通过上面的页面编译出一个 grubriscv64.efi 。然后将其放入SD卡EFI分区中的EFI/目录。.

SD Allwinner nezha.png

一些位于boot分区中范例文件:

/boot/uEnv.txt 目的在于让u-boot自动执行加载GRUB2并跳入执行的步骤。

bootcmd=load mmc 0:2 0x58000000 /EFI/fedora/grubriscv64.efi; bootefi 0x58000000
bootcmd_mmc0=devnum=0; run mmc_boot


/grub.cfg GRUB的启动配置文件,和普通PC机类似。

set default=0
set timeout_style=menu
set timeout=3

set debug="linux,loader,mm"
set term="vt100"

menuentry 'Fedora vmlinux-5.15.0-rc1' {
        linux /vmlinuz-5.15.0-rc1 earlyprintk=sunxi-uart,0x02500000 console=ttyS0,115200 console=tty0 loglevel=8  root=/dev/mmcblk0p4 selinux=0 rhgb LANG=en_US.UTF-8
        devicetree /sun20i-d1-nezha.dtb
	initrd /initramfs-5.15.0-rc1.img
}

针对哪吒 D1 的 Linux 内核 (正在开发中)

本项目使用了来自Smaeul/郭任(平头哥)/全志软件工程师的补丁,使能Fedora需要的了尽可能多的特性,并可能让主线可能 to the latest upstream kernel master branch.

重点参考
Fedora 内核 正在开发中

Tekkaman's Linux 内核仓库

注意: 此内核还在开发中,目标是尽量和主线 Fedora 的配置匹配,以方便构建RPM包以及和Fedora文件系统一起工作

为 D1 编译内核
导出源码
git clone https://github.com/tekkamanninja/linux.git
pushd linux
git checkout origin/allwinner_nezha_d1_devel
popd
配置
pushd linux
make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv nezha_fedora_defconfig
make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv menuconfig
popd
(交叉)编译 并将其安装到合适的位置
# RISCV_ROOTFS_BOOT 是 SD 卡中 boot 分区的挂载点 
# RISCV_ROOTFS_BOOT=/run/media/../boot
# RISCV_ROOTFS  是 SD 卡中 Fedora rootfs 分区的挂载点 
# RISCV_ROOTFS=/run/media/../rootfs
pushd linux
make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv
make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv INSTALL_PATH=${RISCV_ROOTFS_BOOT} zinstall
make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv INSTALL_MOD_PATH=${RISCV_ROOTFS} modules_install
popd

如何为 D1 编译 RPM 包

借助 QEMU 使用 rpmbuild 命令编译

Idea.png
如何使用RISC-V QEMU 启动 Fedora
请参考Architectures/RISC-V/Build Bootable Image#Run_Fedora_on_QEMU


  • 在RISC-V QEMU 上启动 Fedora:
  1. 准备目录树: 将 spec file 放入 /rpmbuild/SPECS 并将所有的源码文件放入 /rpmbuild/SOURCES
  2. 然后通过 rpmbuild 编译RPM包:
#From spec file
$ rpmbuild -ba ~/rpmbuild/SPECS/pakcage.spec
  • 当然,您也可以通过现有的SRPM编译RPM包:
#'''OR''' to build from an existing SRPM file:
$ rpmbuild -ra package.src.rpm

使用SPEC文件的方法比较适合开发调试阶段的代码和RPM包,使用现有SRPM包的方法比较适合单纯的RPM包重新编译。

Idea.png
更多RPM相关的知识
请参考如何创建 GNU 的 Hello World RPM 包

使用 mock 和 Qemu 用户空间模式(usermode)

我们可以在 x86_64 系统上借助 mock 和 Qemu 用户空间模式(usermode) 编译 RISC-V 的 RPMS 包 。[正在总结整理中]

如何创建你自己的 Fedora Remix Image

Idea.png
想要创建自己的 Fedora 镜像?
请参考 RISC-V: Build Bootable Image

如何将 D1 作为 Koji Builder

如果我们已经部署了一个 koji hub(例如 openkojioepkg),然后我们添加 Nezha D1 作为新的 koji builder.

效果如以下页面所示,我们已经尝试添加了Nezha D1 作为 koji builder,并测试了编包:


您可按照以下简单的流程:

  • 前提条件: koji CA 证书和 builder 认证证书,必须由 koji hub 的管理员提供。
  • 安装必要的软件包
# dnf install koji-builder
  • 调整 /etc/kojid.conf 中关键的配置
  1. server=<koji hub XMLRPC server URL>
  2. topurl=<koji HTT file share URL>
  3. allowed_scms=<SCM repo rules>
  4. cert=<builder certificate>
  5. serverca=<koji CA certificate>
  • 信任 koji hub 的 CA 证书
cp koji_ca_cert.crt /etc/pki/ca-trust/source/anchors/
update-ca-trust
  • 在 koji hub 中添加 Builder,必须由 koji hub 的管理员操作
koji add-host <hostname> riscv64
# *hostname* 必须和证书中的一致
  • 使能并启动 kojid
systemctl enable --now kojid
  • 验证 koji builder 是否在线,必须由 koji hub 的管理员操作:
koji list-hosts
# 初始化后: 新添加的 builder状态在列表中应该是 ready(就绪/待命) .
  • 注意:* builder 需要最少 8GiB 的空闲磁盘空间在 /var/lib/mock 中,否则不会进入 ready(就绪/待命)状态。且不支持将 NFS 网络存储挂载到 /var/lib/mock 中。 所以在 builder 中使用高容量 SD 卡,并 resize 跟文件系统到整个SD卡的空闲空间是必要条件。