From Fedora Project Wiki
No edit summary
 
(37 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{lang|en|zh-cn|page=Architectures/RISC-V/Allwinner}}
{| style="width: 50%; float: right; margin-left: 2em;"
|-
| style="border-width: 0;" | {{admon/tip | Have a question? | Join the Fedora riscv on IRC in {{fpchat|#fedora-riscv}} on [https://libera.chat Libera]
}}
|}
[[File:Nezha.png|512px|right]]
Nezha is a SBC based on Allwinner D1. This is a placeholder page to collect all information about running Fedora on Nezha.
Nezha is a SBC based on Allwinner D1. This is a placeholder page to collect all information about running Fedora on Nezha.
Currently D1 is '''not''' officially supported by Fedora.
== Simple HOWTO ==
== Simple HOWTO ==
   
   
=== Prebuild Image ===
=== Prebuild Image ===
we have made the prebuild Fedora Image for Allwinner D1:
We have prebuild image for Allwinner D1. You can download from [https://openkoji.iscas.ac.cn/pub/dl/riscv/Allwinner/Nezha_D1/images-release/Fedora/ here].
[https://openkoji.iscas.ac.cn/pub/dl/d1-images-release/Fedora-riscv64-d1-developer-xfce-with-esp-Rawhide-20210723-173234.n.0-sda.raw.zst Fedora-riscv64-d1-developer-xfce-with-esp-Rawhide-20210723-173234.n.0-sda.raw.zst]


For booting it on D1, what you need to do just:
For booting it on D1, what you need to do just:
==== Decompress ====
==== Decompress ====
<pre>
<pre>
unzstd  Fedora-riscv64-d1-developer-xfce-with-esp-Rawhide-20210723-173234.n.0-sda.raw.zst`
unzstd  Fedora-riscv64-d1-developer-xfce-with-esp-Rawhide-latest-sda.raw.zst
</pre>
</pre>
==== Flash into a SD card (>= 16GB) ====
==== Flash into a SD card (>= 16GB) ====
<pre>
<pre>
sudo dd if=Fedora-riscv64-d1-developer-xfce-with-esp-Rawhide-20210723-173234.n.0-sda.raw of=/dev/sdX status=progress
sudo wipefs -a /dev/sdX
sudo dd if=Fedora-riscv64-d1-developer-xfce-with-esp-Rawhide-latest-sda.raw of=/dev/sdX status=progress bs=4M
</pre>
</pre>
==== insert the SD card and power up ====
==== insert the SD card and power up ====
Line 23: Line 34:
cd /sys/kernel/debug/dispdbg
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;
echo disp0 > name; echo switch1 > command; echo 4 10 0 0 0x4 0x101 0 0 0 8 > param; echo 1 > start;
</pre>
==== The latest test Image ====
The latest Image with mainline kernel(with some patches): [https://openkoji.iscas.ac.cn/pub/dl/riscv/Allwinner/Nezha_D1/images-release/Fedora/fedora-riscv64-d1-developer-xfce-rawhide-Rawhide-20211124-132603.n.0-sda.raw.zst fedora-riscv64-d1-developer-xfce-rawhide-Rawhide-20211124-132603.n.0-sda.raw.zst]
* How to boot the latest kernel by GRUB: using "v" to stop u-boot autoboot, then input
<pre>
run boot_grub
</pre>
</pre>


Line 42: Line 62:
[[File:Boot order allwinner nezha grub.png|center|1024px]]
[[File:Boot order allwinner nezha grub.png|center|1024px]]


=== Original source code ===
=== Reference source code ===
Allwinner: [https://open.allwinnertech.com/ Allwinner Customer Service Platform Portal]<br>
==== Original source code ====
* '''Allwinner''': [https://open.allwinnertech.com/ Allwinner Customer Service Platform Portal]<br>
You need to register and login.  
You need to register and login.  
 
* ''Alternative'': [https://dl.linux-sunxi.org/D1/ D1 resource in SUNXI website]
Or you can download then from [https://dl.linux-sunxi.org/D1/ SUNXI website]
==== Smaeul's REPO ====
 
=== FYI: Smaeul's REPO ===
* [https://github.com/smaeul/sun20i_d1_spl SPL/BOOT0]
* [https://github.com/smaeul/sun20i_d1_spl SPL/BOOT0]
* [https://github.com/smaeul/opensbi OpenSBI]
* [https://github.com/smaeul/opensbi OpenSBI]
* [https://github.com/smaeul/u-boot U-Boot]
* [https://github.com/smaeul/u-boot U-Boot]
* [https://github.com/smaeul/linux/commits/riscv/d1-wip Linux kernel]
* [https://github.com/smaeul/linux/commits/riscv/d1-wip Linux kernel]


=== Tekkaman REPO for Fedora Image===
=== Tekkaman REPOs for '''Fedora Image'''===
==== Firmware Build order ====
==== Firmware Build order ====
[[File:Build order allwinner nezhe grub.png|center|1024px]]
[[File:Build_order_allwinner_nezhe_grub.png|center|1024px]]
 
==== SPL(Boot0) ====
==== SPL(Boot0) ====


Line 92: Line 109:
git clone https://github.com/tekkamanninja/opensbi -b allwinner_d1
git clone https://github.com/tekkamanninja/opensbi -b allwinner_d1
pushd opensbi
pushd opensbi
CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic FW_PIC=y make
CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic FW_PIC=y BUILD_INFO=y make
popd
popd
</pre>
</pre>
Line 102: Line 119:
Using Smaeul's patches, but enable more features and add some default env for auto-booting into GRUB, and also rebase to the latest upstream U-boot.
Using Smaeul's patches, but enable more features and add some default env for auto-booting into GRUB, and also rebase to the latest upstream U-boot.


[https://github.com/tekkamanninja/u-boot Tekkaman's OpenSBI REPO]
[https://github.com/tekkamanninja/u-boot Tekkaman's U-boot REPO]


===== Build binary =====
===== Build binary =====
Line 144: Line 161:
sudo dd if=u-boot.toc1 of=/dev/sdX bs=512 seek=32800
sudo dd if=u-boot.toc1 of=/dev/sdX bs=512 seek=32800
</pre>
</pre>
==== GRUB for RISC-V ====
Please reference to this page: [[Architectures/RISC-V/GRUB2]]
You can build a '''grubriscv64.efi''' by following the page above. Then put it into '''the /EFI/ dir''' of '''the EFI partition''' of SD card.
[[File:SD Allwinner nezha.png|center|1024px]]
Some '''example files''' in the boot partition:
/boot/uEnv.txt
<pre>
bootcmd=load mmc 0:2 0x58000000 /EFI/fedora/grubriscv64.efi; bootefi 0x58000000
bootcmd_mmc0=devnum=0; run mmc_boot
</pre>
/grub.cfg
<pre>
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
}
</pre>
==== Linux kernel from Allwinner ====
[http://openkoji.iscas.ac.cn/pub/dl/riscv/Allwinner/Nezha_D1/sources/ sources_with_defconfig_and_patches]
==== Linux kernel for Nezha D1 '''(upstreaming, WIP)''' ====
Using the patches from Smaeul/Ren Guo(T-HEAD)/Allwinner Engineers, enable almost all the features for Fedora,and also rebase to the latest upstream kernel master branch.
===== Important reference =====
* [https://github.com/c-sky/csky-linux Linux kernel source from T-Head]
* [https://github.com/chinchilla222/nezha-d1 Allwinner Engineer's REPO]
===== '''WIP for Fedora''' =====
[https://github.com/tekkamanninja/linux Tekkaman's Linux kernel REPO]
'''Note: We are still working on this for Fedora Image'''
===== Build Linux Kernel for D1 =====
====== Checkout Source ======
<pre>
git clone https://github.com/tekkamanninja/linux.git
pushd linux
git checkout origin/allwinner_nezha_d1_devel
popd
</pre>
Branches: allwinner_nezha_d1_* are all for Nezha D1
====== Config ======
<pre>
pushd linux
make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv nezha_fedora_defconfig
make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv menuconfig
popd
</pre>
====== '''Cross Build''' and install ======
<pre>
# RISCV_ROOTFS_BOOT is the mount point of the boot partition in SD card
# RISCV_ROOTFS_BOOT=/run/media/../boot
# RISCV_ROOTFS  is the mount point of the Fedora rootfs partition in SD card
# 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
</pre>
=== How to Build RPM package for D1===
==== using rpmbuild on QEMU ====
How to boot Fedora on QEMU, please reference [[Architectures/RISC-V/Build Bootable Image#Run_Fedora_on_QEMU]]
* Boot into Fedora on QEMU, then:
# prepare directory tree: Put spec file to /rpmbuild/SPECS and all source files to /rpmbuild/SOURCES
# For building RPM package:
<pre>
#From spec file
$ rpmbuild -ba ~/rpmbuild/SPECS/pakcage.spec
#'''OR''' to build from an existing SRPM file:
$ rpmbuild -ra package.src.rpm
</pre>
Please reference to [https://docs.fedoraproject.org/en-US/quick-docs/create-hello-world-rpm/ How to Create a GNU Hello World RPM Package] for more RPM info.
==== using mock with Qemu usermod ====
We also can build riscv64 RPMS on x86_64 machine by mock and Qemu usermode.'''[WIP]'''


=== How to Build your own Fedora Remix Image ===
=== How to Build your own Fedora Remix Image ===
Please reference to [[Architectures/RISC-V/Build Bootable Image|RISC-V: Build Bootable Image]]
Please reference to [[Architectures/RISC-V/Build Bootable Image|RISC-V: Build Bootable Image]]
=== How to make D1 as a Koji Builder ===
If we have already deployed a koji hub(like [https://openkoji.iscas.ac.cn/koji openkoji] and [https://koji.oepkgs.net/koji/ oepkg]),then we can add a Nezha D1 as koji builder.
For example:
* [https://koji.oepkgs.net/koji/hosts oepkgs hosts]
* [https://koji.oepkgs.net/koji/taskinfo?taskID=1004 example build on D1 builder in oepkgs]
Please follow the simple instruction below:
* NEED: koji CA certificate and builder authentication certificate: They are provided by koji hub admin.
* Install necessary packages
<pre>
# dnf install koji-builder
</pre>
* Modifying /etc/kojid.conf
# server=<koji hub XMLRPC server URL>
# topurl=<koji HTT file share URL>
# allowed_scms=<SCM repo rules>
# cert=<builder certificate>
# serverca=<koji CA certificate>
* Trust koji hub's CA cert
<pre>
cp koji_ca_cert.crt /etc/pki/ca-trust/source/anchors/
update-ca-trust
</pre>
* add host '''on koji hub (operated by koji hub admin)'''
<pre>
koji add-host <hostname> riscv64
#The *hostname* should be same in authentication certificate.
</pre>
* Enable and start kojid
<pre>
systemctl enable --now kojid
</pre>
* Verify koji builder online '''on koji hub (operated by koji hub admin)''':
<pre>
koji list-hosts
# After initialization: The new added builder's status should be ready in the list.
</pre>
*NOTICE:* builder won't ready until free space on /var/lib/mock is greater than 8GiB, and /var/lib/mock on NFS is not supported. Thus, using a high capacity SD card for builder and resize root file system to adapt all free space on SD is necessary.

Latest revision as of 06:48, 11 July 2022

Have a question?
Join the Fedora riscv on IRC in #fedora-riscv[?] on Libera

Nezha is a SBC based on Allwinner D1. This is a placeholder page to collect all information about running Fedora on Nezha. Currently D1 is not officially supported by Fedora.

Simple HOWTO

Prebuild Image

We have prebuild image for Allwinner D1. You can download from here.

For booting it on D1, what you need to do just:

Decompress

unzstd  Fedora-riscv64-d1-developer-xfce-with-esp-Rawhide-latest-sda.raw.zst

Flash into a SD card (>= 16GB)

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

insert the SD card and power up

  • default display is LCD (vertical):
  • (optional) switch display to HDMI (1080p mode, vertical)
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;

The latest test Image

The latest Image with mainline kernel(with some patches): fedora-riscv64-d1-developer-xfce-rawhide-Rawhide-20211124-132603.n.0-sda.raw.zst

  • How to boot the latest kernel by GRUB: using "v" to stop u-boot autoboot, then input
 run boot_grub

Hardware info

IP info

T-Head: XuanTie C906 RISC-V

Soc & Development boardinfo

Allwinner: D1 SoC Introduction

Sunxi: D1

Sunxi: Allwinner Nezha

Software

Reference source code

Original source code

You need to register and login.

Smaeul's REPO

Tekkaman REPOs for Fedora Image

Firmware Build order

SPL(Boot0)

boot0 or SPL (Secondary Program Loader) which the first stage after BootROM, it is responsible for initializing DRAM and loading next stage firmware from storage(Flash or SD).

Using Smaeul SPL directly.

Build binary
git clone https://github.com/smaeul/sun20i_d1_spl
pushd sun20i_d1_spl
git checkout origin/mainline
make CROSS_COMPILE=riscv64-linux-gnu- p=sun20iw1p1 mmc
popd
Flash to SD card
pushd sun20i_d1_spl
sudo dd if=nboot/boot0_sdcard_sun20iw1p1.bin of=/dev/sdX bs=512 seek=16

OpenSBI

RISC-V Open Source Supervisor Binary Interface, like arm-TF

Using Smaeul's patches, but rebase to the latest upstream OpenSBI, and fix some issue.

Tekkaman's OpenSBI REPO

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

The build/platform/generic/firmware/fw_dynamic.bin will be used to make u-boot.toc1 below.

U-boot

Using Smaeul's patches, but enable more features and add some default env for auto-booting into GRUB, and also rebase to the latest upstream U-boot.

Tekkaman's U-boot REPO

Build binary
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

The u-boot.bin and u-boot.dtb will be used to make u-boot.toc1 below.

Build 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
  • build command:
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

Flash u-boot.toc1 to SD card

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

GRUB for RISC-V

Please reference to this page: Architectures/RISC-V/GRUB2

You can build a grubriscv64.efi by following the page above. Then put it into the /EFI/ dir of the EFI partition of SD card.

Some example files in the boot partition:

/boot/uEnv.txt

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


/grub.cfg

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
}

Linux kernel from Allwinner

sources_with_defconfig_and_patches

Linux kernel for Nezha D1 (upstreaming, WIP)

Using the patches from Smaeul/Ren Guo(T-HEAD)/Allwinner Engineers, enable almost all the features for Fedora,and also rebase to the latest upstream kernel master branch.

Important reference
WIP for Fedora

Tekkaman's Linux kernel REPO

Note: We are still working on this for Fedora Image

Build Linux Kernel for D1
Checkout Source
git clone https://github.com/tekkamanninja/linux.git
pushd linux
git checkout origin/allwinner_nezha_d1_devel
popd

Branches: allwinner_nezha_d1_* are all for Nezha D1

Config
pushd linux
make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv nezha_fedora_defconfig
make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv menuconfig
popd
Cross Build and install
# RISCV_ROOTFS_BOOT is the mount point of the boot partition in SD card 
# RISCV_ROOTFS_BOOT=/run/media/../boot
# RISCV_ROOTFS  is the mount point of the Fedora rootfs partition in SD card 
# 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

How to Build RPM package for D1

using rpmbuild on QEMU

How to boot Fedora on QEMU, please reference Architectures/RISC-V/Build Bootable Image#Run_Fedora_on_QEMU

  • Boot into Fedora on QEMU, then:
  1. prepare directory tree: Put spec file to /rpmbuild/SPECS and all source files to /rpmbuild/SOURCES
  2. For building RPM package:
#From spec file
$ rpmbuild -ba ~/rpmbuild/SPECS/pakcage.spec

#'''OR''' to build from an existing SRPM file:
$ rpmbuild -ra package.src.rpm

Please reference to How to Create a GNU Hello World RPM Package for more RPM info.

using mock with Qemu usermod

We also can build riscv64 RPMS on x86_64 machine by mock and Qemu usermode.[WIP]

How to Build your own Fedora Remix Image

Please reference to RISC-V: Build Bootable Image

How to make D1 as a Koji Builder

If we have already deployed a koji hub(like openkoji and oepkg),then we can add a Nezha D1 as koji builder.

For example:

Please follow the simple instruction below:

  • NEED: koji CA certificate and builder authentication certificate: They are provided by koji hub admin.
  • Install necessary packages
# dnf install koji-builder
  • Modifying /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>
  • Trust koji hub's CA cert
cp koji_ca_cert.crt /etc/pki/ca-trust/source/anchors/
update-ca-trust
  • add host on koji hub (operated by koji hub admin)
koji add-host <hostname> riscv64
#The *hostname* should be same in authentication certificate.
  • Enable and start kojid
systemctl enable --now kojid
  • Verify koji builder online on koji hub (operated by koji hub admin):
koji list-hosts
# After initialization: The new added builder's status should be ready in the list.
  • NOTICE:* builder won't ready until free space on /var/lib/mock is greater than 8GiB, and /var/lib/mock on NFS is not supported. Thus, using a high capacity SD card for builder and resize root file system to adapt all free space on SD is necessary.