打印
[RISC-V MCU 应用开发]

[经验] 哪吒 D1 通过 TF 卡运行 Arch Linux RISC-V rootfs

[复制链接]
615|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
豌豆爹|  楼主 | 2022-9-20 09:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
ar, AN, rc
1 简介
哪吒 D1 是目前市面上性能最强的国产 RISC-V 芯片,本文介绍如何通过 TF 卡运行 ArchLinux RISC-V rootfs。
目前在 RISC-V 上运行 ArchLinux 还要走一点弯路,需要先制作 Debian 的启动盘,之后把文件系统部分替换为 ArchLinux,其他部分还需要共享 Debian 提供的支持。
2 制作 RVBoards 的 Debian RISC-V TF 启动卡
那接下来,先制作 Debian RISC-V TF 启动卡,请参考:[color=rgb(12, 147, 228) !important]「RVBoards-哪吒」D1 Debian系统镜像和安装方法
另外,上面没提到的坑也需要修复一下。





使用特权

评论回复

相关帖子

沙发
豌豆爹|  楼主 | 2022-9-20 10:00 | 只看该作者
2.1 修复可能残留的分区表导致的 rootfs 挂载失败问题
根据 [color=rgb(12, 147, 228) !important]内核无法访挂载 rootfs 这里的介绍,如果出现下面的错误日志,说明您使用的 SD 卡存在 GPT 分区表残留,导致内核不知道如何找到 rootfs (似乎您忘记了在烧写前使用 wipefs 清理 GPT 备份分区表) :
[    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 卡插入 PC,通过 gdisk 清除残余的分区表,过程如下:
# sdX 表示 TF/SD 卡磁盘号,此处以 sdf 为例$ sudo gdisk  /dev/sdfGPT fdisk (gdisk) version 1.0.5Caution: invalid main GPT header, but valid backup; regenerating main headerfrom backup!Warning: Invalid CRC on main header data; loaded backup partition table.Warning! Main and backup partition tables differ! Use the 'c' and 'e' optionson the recovery & transformation menu to examine the two tables.Warning! Main partition table CRC mismatch! Loaded backup partition tableinstead of main partition table!Warning! One or more CRCs don't match. You should repair the disk!Main header: ERRORBackup header: OKMain partition table: ERRORBackup partition table: OKPartition table scan:  MBR: MBR only  BSD: not present  APM: not present  GPT: damagedFound valid MBR and corrupt GPT. Which do you want to use? (Using theGPT MAY permit recovery of GPT data.) 1 - MBR 2 - GPT 3 - Create blank GPTYour answer: 1Command (? for help): pDisk /dev/sdf: 62333952 sectors, 29.7 GiBModel: Multi-Reader  -3Sector size (logical/physical): 512/512 bytesDisk identifier (GUID): 632BFA1B-F09D-42A8-82F4-5FAB32E41DC2Partition table holds up to 128 entriesMain partition table begins at sector 2 and ends at sector 33First usable sector is 34, last usable sector is 62333918Partitions will be aligned on 2048-sector boundariesTotal 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 filesystemCommand (? for help): wFinal checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTINGPARTITIONS!!Do you want to proceed? (Y/N): yOK; 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 yourun partprobe(8) or kpartx(8)The operation has completed successfully.
可进一步通过 wipefs 擦除 TF 卡的分区信息
# sdX 表示 TF/SD 卡磁盘号sudo wipefs -a /dev/sdXsudo dd if=Fedora-riscv64-d1-developer-xfce-with-esp-Rawhide-latest-sda.raw of=/dev/sdX status=progress bs=4M2.2 修复潜在的启动卡无法格式化问题
如果在 win10 上通过全志的 TF 卡制作启动盘工具,请使用 [color=rgb(12, 147, 228) !important]*附件:PhoenixCardv4.2.7.7z 在 2021/07/14 08:56:40 更新的版本,否则会出现 启动卡无法格式化 ,无法制作成功等糟心的问题。

使用特权

评论回复
板凳
豌豆爹|  楼主 | 2022-9-20 10:02 | 只看该作者
2.3 可选操作:扩展根文件系统分区尺寸
插入读卡器到 Linux 系统下,执行以下操作来扩展根文件系统分区尺寸:(sdX 的 X 表示你实际的读卡器盘符字母)
sudo e2fsck -f /dev/sdX7sudo resize2fs -p /dev/sdX73 启动 Debian RISC-V TF卡
制作完成后,接下来启动 Debian RISC-V TF 卡。
首先使用 USB2TTL 串口工具链接 D1 的 debug 口,插入 TF 到 D1 的 TF 卡座,然后使用 minicom 连接串口。
连接之前,请确认关闭 minicom 的硬件流控,具体操作如下:
$ sudo minicom -s+------[设置]---------+| 文件名和路径            || 文件传输协定            || 串口设置              || 调制解调器和拨接          || 屏幕和键盘             || 保存设置为 dfl         || 另存设置为…            || 离开本画面             || 离开 Minicom        |+-------------------+
选择 “串口设置”,设定效果如下:
+-----------------------------------------------------------------------+      || A - 串行设备               : /dev/modem                                   | || B - 锁文件位置              : /var/run                                     ||| C - 拨入程序               :                                              | || D - 拨出程序               :                                              | || E - Bps/Par/Bits       : 115200 8N1                                   |     || F - 硬件流控制              : 否                                            || G - 软件流控制              : 否                                            || H -     RS485 Enable      : No                                        || I -   RS485 Rts On Send   : No                                        |       || J -  RS485 Rts After Send : No                                        || K -  RS485 Rx During Tx   : No                                        || L -  RS485 Terminate Bus  : No                                        |       || M - RS485 Delay Rts Before: 0                                         || N - RS485 Delay Rts After : 0                                         |          ||                                                                       |               ||    变更设置?                                                              |       |+-----------------------------------------------------------------------+
说明 :按 F 切换硬件流控,选择为关闭,按回车间确认,放回到主界面保存设置。
确认无误后,再次连接 D1 串口:
$ minicom -c on -b **115200** -D /dev/ttyUSB0
然后使用 Type-C 数据线连接 OTG 接口,minicom 会输出相应启动信息。
不出意外的话会进入 Debian RISC-V 的系统。
Debian RISC-V 系统默认用户名:root 密码:rvboards
4 备份 Debian RISC-V 的 rootfs
后面需要把 Debian 替换为 ArchLinux,这里先做一下备份,方便后面使用。
将 D1 断电,拔出 TF 卡,通过读卡器挂载到自己的开发主机上,然后备份好 Debian RISC-V 的 rootfs。
此处以 sde5 为例,根据实际情况找到 rootfs 磁盘:
$ mount /dev/sde5 /mnt$ cd /mnt
备份当前 Debian RISC-V rootfs:
$ tar -zcvf . ~/debian-riscv-`date -s`.tar.xz
删除 Debian RISC-V rootfs( 注意 :请确保当前在刚挂载的 /mnt 目录下):
$ pwd/mnt$ sudo rm -rf .5 替换为 ArchLinux RISC-V rootfs
接下来回到主题,我们把 Debian rootfs 替换为 ArchLinux。
5.1 下载 ArchLinux risc-v rootfs 系统
将 archriscv-20210601.tar.zst 下载到 ~/ 下:
$ wget -c https://archriscv.felixc.at/images/archriscv-20210601.tar.zst5.2 解压 ArchLinux RISC-V rootfs
将 archriscv-20210601.tar.zst 解压到上面准备好的 /mnt 下:
ArchLinux 系统用户可以这么操作:
$ sudo bsdtar -xvf ~/archriscv-20210601.tar.zst -C /mnt/
非 ArchLinux 系统用户,依赖 zstd 库,没有此库的用户自行安装:
sudo tar -I zstd -xvf ~/archriscv-20210601.tar.zst -C /mnt/6 配置 ArchLinux RISC-V rootfs6.1 通过虚拟机启动 ArchLinux RISC-V rootfs$ sudo systemd-nspawn -D /mnt/ --machine archriscv -a -U
ArchLinux RISC-V 的默认<span> </span>root 密码为 sifive。
说明 : systemd-nspawn 来自包 systemd-container。
6.2 配置 ArchLinux RISC-V 的静态 IP 地址
此处以默认网卡为 eth0 为例,实际通过 ip addr 获取网卡信息:
首先查看网络状态:
$ sudo systemctl status systemd-networkd
通过 cat 配置静态 IP 文件:
$ sudo cat > /etc/systemd/network/10-static-eth0.network << EOF[Match]Name=eth0[Network]Address=192.168.1.199/24Gateway=192.168.1.1DNS=192.168.1.1 223.5.5.5 114.114.114.114EOF
把服务加入开机自启:
sudo systemctl reenable systemd-networkd
重启系统:
sudo reboot
查看 IP:
$ ip addr # 或者 ifconfig
如果静态 IP 重启后变成动态 IP,可以审查是否因为 networkmanager 引起,如果是请执行下面命令卸载:
sudo pacman -Rsn pacman -Qsq networkmanager network-manager-applet
6.3 配置 /etc/fstab
这里主要是使得根目录是 rw 的(这能避免一些 SEGV):
/dev/mmcblk0p5  /       ext4    rw      0       16.4 修改镜像源
如果存在类似下面的 SSL 连接错误:
pacman -Syyus.ac.cn/archriscv_archriscv.felixc.at_g' /etc/pacman.conf cat /etc/pacman.conf:: Synchronizing package databases...error: failed retrieving file 'core.db' from archriscv.felixc.at : SSL certificate problem: certificate is not yet validerror: failed to update core (download library error)error: failed retrieving file 'extra.db' from archriscv.felixc.at : SSL certificate problem: certificate is not yet validerror: failed to update extra (download library error)error: failed retrieving file 'community.db' from archriscv.felixc.at : SSL certificate problem: certificate is not yet validerror: failed to update community (download library error)error: failed to syn
请将 https 替换成 http:
$ sudo sed -i 's_https_http_g' /etc/pacman.conf
如果是下载速度慢可以换其他镜像站:
$ sudo sed -i 's_archriscv.felixc.at_mirrors.wsyu.edu.cn/archriscv_g' /etc/pacman.conf6.5 退出 ArchLinux RISC-V 虚拟机
按下 Ctrl + D 或输入:
exit6.6 卸载 /mnt 分区sudo umount -R /mnt7 正式使用 ArchLinux RISC-V rootfs
安全弹出 TF 卡,插入 D1 TF 卡座,OTG 接口供电,不出意外是能进入 ArchLinux risc-v 的 rootfs。
请注意,ArchLinux RISC-V 的默认<span> </span>root 密码为 sifive。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

503

主题

1924

帖子

5

粉丝