Linux內核打實時補丁preempt_rt


 

 補丁下載

 

內核代碼

root@Ubuntu-riscv64:/usr/src/linux-5.14# head Makefile 
# SPDX-License-Identifier: GPL-2.0
VERSION = 5
PATCHLEVEL = 14
SUBLEVEL = 0
EXTRAVERSION =
NAME = Opossums on Parade

 

http://ftp.ntu.edu.tw/pub/linux/kernel/projects/rt/5.14/
 
 
 
at Makefile  | head
# SPDX-License-Identifier: GPL-2.0
VERSION = 5
PATCHLEVEL = 14
SUBLEVEL = 0
EXTRAVERSION =
NAME = Opossums on Parade

 

tar -xvf patches-5.14.2-rt21.tar.xz

root@Ubuntu-riscv64:~# uname -a
Linux Ubuntu-riscv64 5.14.0-rt21 #1 SMP PREEMPT Thu Oct 14 10:27:33 CST 2021 riscv64 riscv64 riscv64 GNU/Linux

 

root@Ubuntu-riscv64:/usr/src/linux-5.14# cat include/config/kernel.release
5.14.0-rt21
root@Ubuntu-riscv64:/usr/src/linux-5.14# 

 

打補丁

由於解壓出來補丁有200多個patch, 在內核目錄下借用腳本合並補丁

 

linux-5.14$ ls patches/series 
patches/series
linux-5.14$ ls patches/series 
patches/series

 

cat patch.sh 
#!/bin/sh
cat ./patches/series | while read line
do
            patch -p1 < ./patches/$line
done

 

交叉編譯

 

交叉編譯
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- menuconfig
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- -j

 

cat include/config/kernel.release
5.14.0-rt21

 

 

0

 

0

 

linux-5.14$ ls arch/riscv/boot/ -al
total 26624
drwxrwxr-x  3 ubuntu ubuntu     4096 Oct 14 10:29 .
drwxrwxr-x 10 ubuntu ubuntu     4096 Oct 14 10:27 ..
drwxrwxr-x  5 ubuntu ubuntu     4096 Aug 30 06:04 dts
-rw-rw-r--  1 ubuntu ubuntu       83 Aug 30 06:04 .gitignore
-rwxrwxr-x  1 ubuntu ubuntu 27421184 Oct 14 10:29 Image
-rw-rw-r--  1 ubuntu ubuntu      151 Oct 14 10:29 .Image.cmd
-rw-rw-r--  1 ubuntu ubuntu  8707892 Oct 14 10:29 Image.gz
-rw-rw-r--  1 ubuntu ubuntu      101 Oct 14 10:29 .Image.gz.cmd
-rw-rw-r--  1 ubuntu ubuntu     1561 Aug 30 06:04 install.sh
-rw-rw-r--  1 ubuntu ubuntu      206 Aug 30 06:04 loader.lds.S
-rw-rw-r--  1 ubuntu ubuntu      143 Aug 30 06:04 loader.S
-rw-rw-r--  1 ubuntu ubuntu     1852 Aug 30 06:04 Makefile

Generating Kernel modules

linux-5.14$ make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu-  modules_install INSTALL_MOD_PATH=./modules_install

 

 INSTALL modules_install/lib/modules/5.14.0-rt21/kernel/sound/usb/line6/snd-usb-podhd.ko
  INSTALL modules_install/lib/modules/5.14.0-rt21/kernel/sound/usb/line6/snd-usb-toneport.ko
  INSTALL modules_install/lib/modules/5.14.0-rt21/kernel/sound/usb/line6/snd-usb-variax.ko
  INSTALL modules_install/lib/modules/5.14.0-rt21/kernel/sound/usb/misc/snd-ua101.ko
  DEPMOD  ./modules_install/lib/modules/5.14.0-rt21

 

tar -cvf  5.14.0-rt21.tar  modules_install/lib/modules/5.14.0-rt21

 

 buildroot

 

git clone https://gitee.com/mirrors/buildroot.git
Cloning into 'buildroot'...
remote: Enumerating objects: 556, done.

 

 

 make qemu_riscv64_virt_defconfig
mkdir -p /root/buildroot-2021.08.1/output/build/buildroot-config/lxdialog
PKG_CONFIG_PATH="" make CC="/usr/bin/gcc" HOSTCC="/usr/bin/gcc" \

 

 

make menuconfig
mkdir -p /root/buildroot-2021.08.1/output/build/buildroot-config/lxdialog

 

 

 

 

 

make -j 128

modules are missing:

 
          

ExtUtils::MakeMaker

 

 

yum install -y perl-ExtUtils-MakeMaker

 

 

configure: error: you should not run configure as root (set FORCE_UNSAFE_CONFIGURE=1 in environment to bypass this check)
See `config.log' for more details
make: *** [/root/buildroot-2021.08.1/output/build/host-tar-1.34/.stamp_configured] Error 1
[root@centos7 buildroot-2021.08.1]# export FORCE_UNSAFE_CONFIGURE=1
[root@centos7 buildroot-2021.08.1]# make -j 128

 

生成

ln -snf /root/buildroot /output/host/riscv64-buildroot-linux-uclibc/sysroot /root/buildroot-2021.08.1/output/staging
>>>   Executing post-image script board/qemu/post-image.sh
You have new mail in /var/spool/mail/root
[root@centos7 buildroot-]# 
[root@centos7 buildroot-]# ls buildroot-/output/
ls: cannot access buildroot-/output/: No such file or directory
[root@centos7 buildroot ]# ls output/images/
fw_dynamic.bin  fw_dynamic.elf  fw_jump.bin  fw_jump.elf  rootfs.ext2  rootfs.tar  start-qemu.sh
[root@centos7 buildroot-]# file output/images/rootfs.ext2 
output/images/rootfs.ext2: Linux rev 1.0 ext2 filesystem data, UUID=f782840d-9251-495d-b646-32800af3ca12 (large files)
[root@centos7 buildroot ]# file output/images/rootfs.tar 
output/images/rootfs.tar: POSIX tar archive
[root@centos7 buildroot-]# 

 

sd卡

root@ :~# ls data1/
boot.scr.uimg                       Image_git_GPIO_initramfs_rebuil  Image_l2.gz        sifive_5.14.gz
extlinux                            Image.gz                         Image_nol2.gz      System Volume Information
hifive-unleashed-a00-microsemi.dtb  Image_hotplug_initramfs          Image_only_git.gz

 

 

 

ls data2
bin  boot  dev  etc  home  lib  lost+found  media  mnt  proc  run  sbin  sys  tmp  usr  var

 留下lost+found

~/data2# rm -rf bin  boot  dev  etc  home  lib media  mnt  proc  run  sbin  sys  tmp  usr  var

 

 

ls
lost+found

 

 

~/data2# ls
lost+found  rootfs.tar
tar xvf rootfs.tar 

 

~/data2# ls
bin  etc  lib64    lost+found  mnt  proc  rootfs.tar  sbin  tmp  var
dev  lib  linuxrc  media       opt  root  run         sys   usr

 

 

cat data1/extlinux/extlinux.conf 
default OpenEmbedded
label OpenEmbedded-SiFive-HiFive-Unleashed
   kernel /sifive_5.14.gz
   fdt /hifive-unleashed-a00-microsemi.dtb
append root=/dev/mmcblk0p4 rootfstype=ext4 rootwait console=ttySIF0,115200 earlycon=sbi

 

 

 啟動

deleting routers
[   13.578454] random: mktemp: uninitialized urandom read (6 bytes read)
adding dns 192.168.8.17
adding dns 192.168.8.18
OK

Welcome to Buildroot
buildroot login: root
# ls
# pwd
/root
# ls -al
total 12
drwx------    2 root     root          4096 Jan  1 00:01 .
drwxr-xr-x   18 root     root          4096 Oct 14  2021 ..
-rw-------    1 root     root            14 Jan  1 00:01 .ash_history
# uname -a
Linux buildroot 5.14.0-rt21 #1 SMP PREEMPT Thu Oct 14 10:27:33 CST 2021 riscv64 GNU/Linux
# 

 

 采用buildroot構建的系統不能使用 yum apt等

# apt-get  -y install lrzsz
-sh: apt-get: not found
# cat /etc/os-release 
NAME=Buildroot
VERSION=2021.08.1
ID=buildroot
VERSION_ID=2021.08.1
PRETTY_NAME="Buildroot 2021.08.1"
# 

RISC-V Ubuntu Rootfs from scratch

As the root filesystem, you can choose between downloading a pre-built Debian or Ubuntu or build the rootfs yourself.

The pre-built Debian tarball can be downloaded with: wget -O rootfs.tar.bz2 https://github.com/carlosedp/riscv-bringup/releases/download/v1.0/debian-sid-riscv64-rootfs-20200108.tar.bz2.

The pre-built Ubuntu Focal tarball can be downloaded with: wget -O rootfs.tar.bz2 https://github.com/carlosedp/riscv-bringup/releases/download/v1.0/UbuntuFocal-riscv64-rootfs.tar.gz.

If you want to build a Debian rootfs from scratch, check this guide.

 

阿里鏡像下載

 

基本鏡像(debian-base) http://mirrors.aliyun.com/thead/images/riscv64-ice/debian-rootfs.ext4.gz 59MB
開發鏡像 (debian-dev) http://mirrors.aliyun.com/thead/images/riscv64-ice/debian-dev-rootfs.ext4.gz 197MB
xfce 桌面(debian-desktop) http://mirrors.aliyun.com/thead/images/riscv64-ice/debian-desktop-rootfs.ext4.gz

 

Installing new version of config file /etc/xdg/virt-builder/repos.d/libguestfs.conf ...
Setting up libguestfs-xfs:arm64 (1:1.44.1-1ubuntu3) ...
Processing triggers for initramfs-tools (0.130ubuntu3.8) ...
update-initramfs: Generating /boot/initrd.img-5.5.19-050519-generic
Warning: couldn't identify filesystem type for fsck hook, ignoring.
Processing triggers for libc-bin (2.33-0ubuntu5) ...
W: APT had planned for dpkg to do more than it reported back (21 vs 25). Affected packages: udev:arm64
root@cloud:~/risc_ubuntu# dpkg -l |grep uuid 
ii  libuuid1:arm64                             2.36.1-7ubuntu2                         arm64        Universally Unique ID library
ii  uuid-dev:arm64                             2.36.1-7ubuntu2                         arm64        Universally Unique ID library - headers and static libraries
ii  uuid-runtime                               2.31.1-0.4ubuntu3.3                     arm64        runtime components for the Universally Unique ID library
root@cloud:~/risc_ubuntu# 

 

 

安裝libuuid庫
libuuid是一個跨平台的開源的uuid操作庫。一般的機器上默認是沒有,先安裝一下。

執行:sudo apt-get install uuid-dev

然后再執行:sudo apt-get -f install 就成功了

 

 

root@cloud:~/risc_ubuntu# chroot temp-rootfs /bin/bash
groups: cannot find name for group ID 0
I have no name!@cloud:/# 
I have no name!@cloud:/# ls
bin  boot  debootstrap  dev  etc  home  lib  proc  root  run  sbin  sys  tmp  usr  var
I have no name!@cloud:/#

 

 

/debootstrap/debootstrap --second-stage

 

apt-get install --no-install-recommends -y util-linux haveged openssh-server systemd kmod initramfs-tools conntrack ebtables ethtool iproute2 iptables mount socat ifupdown iputils-ping vim dhcpcd5 neofetch sudo chrony

 

> LABEL=rootfs/ext4user_xattr,errors=remount-ro01
> EOF^C
I have no name!@cloud:/# cat >/etc/fstab <<EOF
> LABEL=rootfs / ext4 user_xattr,errors=remount-ro 0 1
> EOF
I have no name!@cloud:/# echo "Ubuntu-riscv64" > /etc/hostname
I have no name!@cloud:/# echo "root:riscv" | chpasswd
I have no name!@cloud:/# sed -i "s/#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config
I have no name!@cloud:/# rm -rf /var/cache/apt/
I have no name!@cloud:/# exit
exit
root@cloud:~/risc_ubuntu# 

 

總結

# Install pre-reqs
sudo apt install debootstrap qemu qemu-user-static binfmt-support dpkg-cross --no-install-recommends

# Generate minimal bootstrap rootfs
sudo debootstrap --arch=riscv64 --foreign hirsute ./temp-rootfs http://ports.ubuntu.com/ubuntu-ports

# chroot to it and finish debootstrap
sudo chroot temp-rootfs /bin/bash

/debootstrap/debootstrap --second-stage

# Add package sources
cat >/etc/apt/sources.list <<EOF
deb http://ports.ubuntu.com/ubuntu-ports hirsute main restricted

deb http://ports.ubuntu.com/ubuntu-ports hirsute-updates main restricted

deb http://ports.ubuntu.com/ubuntu-ports hirsute universe
deb http://ports.ubuntu.com/ubuntu-ports hirsute-updates universe

deb http://ports.ubuntu.com/ubuntu-ports hirsute multiverse
deb http://ports.ubuntu.com/ubuntu-ports hirsute-updates multiverse

deb http://ports.ubuntu.com/ubuntu-ports hirsute-backports main restricted universe multiverse

deb http://ports.ubuntu.com/ubuntu-ports hirsute-security main restricted
deb http://ports.ubuntu.com/ubuntu-ports hirsute-security universe
deb http://ports.ubuntu.com/ubuntu-ports hirsute-security multiverse
EOF

# Install essential packages
apt-get update
apt-get install --no-install-recommends -y util-linux haveged openssh-server systemd kmod initramfs-tools conntrack ebtables ethtool iproute2 iptables mount socat ifupdown iputils-ping vim dhcpcd5 neofetch sudo chrony

# Create base config files
mkdir -p /etc/network
cat >>/etc/network/interfaces <<EOF
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
EOF

cat >/etc/resolv.conf <<EOF
nameserver 1.1.1.1
nameserver 8.8.8.8
EOF

cat >/etc/fstab <<EOF
LABEL=rootfs / ext4 user_xattr,errors=remount-ro 0 1
EOF

echo "Ubuntu-riscv64" > /etc/hostname

# Disable some services on Qemu, 這兩步不需要
#ln -s /dev/null /etc/systemd/network/99-default.link
#ln -sf /dev/null /etc/systemd/system/serial-getty@hvc0.service

# Set root passwd
echo "root:riscv" | chpasswd

sed -i "s/#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config

# Clean APT cache and debootstrap dirs
rm -rf /var/cache/apt/

# Exit chroot
exit
sudo tar -cSf Ubuntu-Hippo-rootfs.tar -C temp-rootfs .
gzip Ubuntu-Hippo-rootfs.tar
rm -rf temp-rootfs

 

登陸

root@Ubuntu-riscv64:~# 
root@Ubuntu-riscv64:~# 
root@Ubuntu-riscv64:~# 
root@Ubuntu-riscv64:~# ls
root@Ubuntu-riscv64:~# 
root@Ubuntu-riscv64:~# ls /r
ls: cannot access '/r': No such file or directory
root@Ubuntu-riscv64:~# ls /
bin   dev  home  lost+found  mnt  proc  run   srv  tmp  var
boot  etc  lib   media       opt  root  sbin  sys  usr
root@Ubuntu-riscv64:~# 

 

root@Ubuntu-riscv64:~# uname -a
Linux Ubuntu-riscv64 5.14.0-rt21 #1 SMP PREEMPT Thu Oct 14 10:27:33 CST 2021 riscv64 riscv64 riscv64 GNU/Linux
root@Ubuntu-riscv64:~# 

 

Read-only file system

root@Ubuntu-riscv64:~# touch txt.txt
touch: cannot touch 'txt.txt': Read-only file system

 

 

root@Ubuntu-riscv64:/# touch txt.txt
touch: cannot touch 'txt.txt': Read-only file system
root@Ubuntu-riscv64:/# mount -o remount,rw /
mount: /: can't find LABEL=rootfs.
root@Ubuntu-riscv64:/# touch txt.txt        
touch: cannot touch 'txt.txt': Read-only file system
root@Ubuntu-riscv64:/#  blkid
/dev/mmcblk0p3: SEC_TYPE="msdos" LABEL_FATBOOT="boot" LABEL="boot" UUID="48B8-EE4D" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="boot" PARTUUID="eb771f44-4547-416d-82f5-619de5c0ffae"
/dev/mmcblk0p4: LABEL="root" UUID="eede8079-01cd-46d1-995f-50185ef3888d" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="root" PARTUUID="88cd64c7-cd99-4d8a-a833-2d3441319154"
/dev/mtdblock0: PTUUID="05a48cfd-119d-59c4-8c6a-d76e8de6a289" PTTYPE="gpt"
/dev/mmcblk0p1: PARTLABEL="primary" PARTUUID="5a8d762e-3f43-44ef-8afa-f1b71512b988"
/dev/mmcblk0p2: PARTLABEL="primary" PARTUUID="306f5864-1122-4f55-9b04-9b1149f6568e"
root@Ubuntu-riscv64:/# 
LABEL="root,label錯誤了
更改
/etc/fstab 
 
root@Ubuntu-riscv64:~# touch txt.txt
root@Ubuntu-riscv64:~# cat /etc/fstab 
LABEL=root /  ext4 noatime,lazytime,rw 0 1
root@Ubuntu-riscv64:~# 

 

 

可以rw的build rootfs

cat etc/fstab 
# <file system> <mount pt>      <type>  <options>       <dump>  <pass>
/dev/root       /               ext2    rw,noauto       0       1
proc            /proc           proc    defaults        0       0
devpts          /dev/pts        devpts  defaults,gid=5,mode=620,ptmxmode=0666   0       0
tmpfs           /dev/shm        tmpfs   mode=0777       0       0
tmpfs           /tmp            tmpfs   mode=1777       0       0
tmpfs           /run            tmpfs   mode=0755,nosuid,nodev  0       0
sysfs           /sys            sysfs   defaults        0       0

 

 

Key exchange failed.

No compatible key exchange method. The server supports these methods: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256

 

KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1

 

 

yum -y install gcc automake autoconf libtool make

 

 You don't have enough free space in /var/cache/apt/archives/

解決辦法:

清除所有已下載的過期安裝包

sudo apt-get autoclean

清除所有已下載的安裝包

sudo apt-get clean

虛擬機環境下Ubuntu主機硬盤較小,清理緩存仍空間不足。
解決辦法:在虛擬機軟件中增加Ubuntu主機硬盤空間,並在Ubuntu Disks中增大實際使用的硬盤大小。

root@Ubuntu-riscv64:/# df -lh
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       6.3G  5.9G   16M 100% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           1.6G  1.4M  1.6G   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
tmpfs           796M     0  796M   0% /run/user/0

 

 

W: Download is performed unsandboxed as root as file '/var/cache/apt/archives/partial/perl-base_5.32.1-3ubuntu2.1_riscv64.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)

chmod 755 / 解決它。
root@Ubuntu-riscv64:~# chmod 755 /
root@Ubuntu-riscv64:~#

 

 

 

修改/dev/shm的大小

root@Ubuntu-riscv64:~# df -lh
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       6.3G  5.0G  990M  84% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           1.6G  1.4M  1.6G   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
tmpfs           796M     0  796M   0% /run/user/0

修改/etc/fstab的這行

root@Ubuntu-riscv64:~# cat /etc/fstab 
LABEL=root /  ext4 noatime,lazytime,rw 0 1
none      /dev/shm        tmpfs   defaults,size=1024M        0 0

 

 

root@Ubuntu-riscv64:~# mount -o remount /dev/shm
root@Ubuntu-riscv64:~# df -lh
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       6.3G  5.0G  990M  84% /
tmpfs           1.0G     0  1.0G   0% /dev/shm
tmpfs           1.6G  1.4M  1.6G   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
tmpfs           796M     0  796M   0% /run/user/0

 

 

root@Ubuntu-riscv64:~# df -lh
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       6.3G  5.0G  990M  84% /
tmpfs           1.0G     0  1.0G   0% /dev/shm
tmpfs           1.6G  1.4M  1.6G   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
tmpfs           796M     0  796M   0% /run/user/0
root@Ubuntu-riscv64:~# 

 

 

root@Ubuntu-riscv64:/usr/src/linux-5.14# mount -o remount /run
root@Ubuntu-riscv64:/usr/src/linux-5.14# df -lh
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       6.3G  5.3G  703M  89% /
tmpfs           256M     0  256M   0% /dev/shm
tmpfs           256M  1.4M  255M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
tmpfs           796M     0  796M   0% /run/user/0
root@Ubuntu-riscv64:/usr/src/linux-5.14# cat /etc/fstab 
LABEL=root /  ext4 noatime,lazytime,rw 0 1
none      /dev/shm        tmpfs   defaults,size=256M        0 0
none      /run        tmpfs   defaults,size=256M        0 0
root@Ubuntu-riscv64:/usr/src/linux-5.14# 

 

  scripts/basic/fixdep: Exec format error

root@Ubuntu-riscv64:/usr/src/linux-5.14# make scripts
  SYNC    include/config/auto.conf.cmd
  HOSTCC  scripts/kconfig/conf.o
/bin/sh: 1: scripts/basic/fixdep: Exec format error
make[2]: *** [scripts/Makefile.host:112: scripts/kconfig/conf.o] Error 126
make[2]: *** Deleting file 'scripts/kconfig/conf.o'
make[1]: *** [Makefile:625: syncconfig] Error 2
Makefile:712: include/config/auto.conf.cmd: No such file or directory
make: *** [Makefile:735: include/config/auto.conf.cmd] Error 2

 

 

include/config/kernel.release

root@Ubuntu-riscv64:/usr/src/linux-5.14# find ./ -name kernel.release
root@Ubuntu-riscv64:/usr/src/linux-5.14# make include/config/kernel.release
  SYNC    include/config/auto.conf.cmd
  HOSTCC  scripts/kconfig/conf.o
  HOSTLD  scripts/kconfig/conf
  UPD     include/config/kernel.release
root@Ubuntu-riscv64:/usr/src/linux-5.14# find ./ -name kernel.release
./include/config/kernel.release
root@Ubuntu-riscv64:/usr/src/linux-5.14# 

make asm-generic

Re: Question about "asm/rwonce.h: No such file or directory"
root@Ubuntu-riscv64:/usr/src/linux-5.14# make asm-generic
  WRAP    arch/riscv/include/generated/asm/early_ioremap.h
  WRAP    arch/riscv/include/generated/asm/extable.h
  WRAP    arch/riscv/include/generated/asm/flat.h
  WRAP    arch/riscv/include/generated/asm/kvm_para.h
  WRAP    arch/riscv/include/generated/asm/user.h
  WRAP    arch/riscv/include/generated/asm/vmlinux.lds.h
  WRAP    arch/riscv/include/generated/asm/bugs.h
  WRAP    arch/riscv/include/generated/asm/checksum.h
  WRAP    arch/riscv/include/generated/asm/compat.h
  WRAP    arch/riscv/include/generated/asm/device.h
  WRAP    arch/riscv/include/generated/asm/div64.h
  WRAP    arch/riscv/include/generated/asm/dma-mapping.h
  WRAP    arch/riscv/include/generated/asm/dma.h
  WRAP    arch/riscv/include/generated/asm/emergency-restart.h
  WRAP    arch/riscv/include/generated/asm/exec.h
  WRAP    arch/riscv/include/generated/asm/fb.h
  WRAP    arch/riscv/include/generated/asm/hardirq.h
  WRAP    arch/riscv/include/generated/asm/hw_irq.h
  WRAP    arch/riscv/include/generated/asm/irq_regs.h
  WRAP    arch/riscv/include/generated/asm/kmap_size.h
  WRAP    arch/riscv/include/generated/asm/local.h
  WRAP    arch/riscv/include/generated/asm/local64.h
  WRAP    arch/riscv/include/generated/asm/msi.h
  WRAP    arch/riscv/include/generated/asm/percpu.h
  WRAP    arch/riscv/include/generated/asm/preempt.h
  WRAP    arch/riscv/include/generated/asm/serial.h
  WRAP    arch/riscv/include/generated/asm/shmparam.h
  WRAP    arch/riscv/include/generated/asm/simd.h
  WRAP    arch/riscv/include/generated/asm/softirq_stack.h
  WRAP    arch/riscv/include/generated/asm/topology.h
  WRAP    arch/riscv/include/generated/asm/trace_clock.h
  WRAP    arch/riscv/include/generated/asm/unaligned.h
  WRAP    arch/riscv/include/generated/asm/vga.h
  WRAP    arch/riscv/include/generated/asm/xor.h

 

root@Ubuntu-riscv64:/usr/src/linux-5.14# make asm-generic
  WRAP    arch/riscv/include/generated/asm/rwonce.h

 

generated/bounds.h: No such file or directory

./include/linux/page-flags-layout.h:6:10: fatal error: generated/bounds.h: No such file or directory
    6 | #include <generated/bounds.h>

原因:bounds.h是在編譯內核時生成的,類似於編譯產生的.o文件,如果你運行

"make clean" or "make distclean",這個文件就會被清除掉(詳情查看內核Makefile)。因此,如果再利用此內核源碼編譯內核模塊,如果有涉及bounds.h,就會出現找不到該文件的錯誤。

 

解決:獨立內核目錄之外編譯模塊時,要確保makefile文件中所定義的內核源代碼樹已經make過一遍,且沒有make  clean。這樣就不會清除生成的bound.h頭文件,這個文件是生成模塊必須的。

 

或者"make prepare"

 

這樣就會重新生成bounds.h,搞定了!

 

 

root@Ubuntu-riscv64:/usr/src/linux-5.14# make prepare
  UPD     include/generated/timeconst.h
  CC      arch/riscv/kernel/asm-offsets.s
  UPD     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
  CALL    scripts/atomic/check-atomics.sh

root@Ubuntu-riscv64:/usr/src/linux-5.14# find ./ -name bounds.h
./include/generated/bounds.h
root@Ubuntu-riscv64:/usr/src/linux-5.14# 

 

No rule to make target 'scripts/module.lds

 

root@Ubuntu-riscv64:/usr/src/linux-5.14# make modules_prepare
  CALL    scripts/checksyscalls.sh
  CALL    scripts/atomic/check-atomics.sh
  LDS     scripts/module.lds
root@Ubuntu-riscv64:/usr/src/linux-5.14# find ./ -name module.lds
./scripts/module.lds

 

 

modules_install: missing 'System.map' file. Skipping depmod.

ERROR: could not fstatat(/lib/modules/5.14.0-rt21, modules.dep): No such file or directory

 

Warning: modules_install: missing 'System.map' file. Skipping depmod.
make[1]: Leaving directory '/usr/src/linux-5.14'
depmod -A
depmod: ERROR: could not fstatat(/lib/modules/5.14.0-rt21, modules.dep): No such file or directory
depmod: WARNING: could not open modules.order at /lib/modules/5.14.0-rt21: No such file or directory
depmod: WARNING: could not open modules.builtin at /lib/modules/5.14.0-rt21: No such file or directory

 

root@Ubuntu-riscv64: # ls /lib/modules/5.14.0-rt21/modules.
modules.alias              modules.builtin.bin        modules.devname            modules.symbols.bin
modules.alias.bin          modules.dep                modules.softdep            
modules.builtin.alias.bin  modules.dep.bin            modules.symbols            
root@Ubuntu-riscv64:~ # ls /lib/modules/5.14.0-rt21/modules.de
modules.dep      modules.dep.bin  modules.devname  
root@Ubuntu-riscv64:~ # ls /lib/modules/5.14.0-rt21/modules.de

 

ls /lib/modules/5.14.0-rt21/modules.*
/lib/modules/5.14.0-rt21/modules.alias              /lib/modules/5.14.0-rt21/modules.dep.bin
/lib/modules/5.14.0-rt21/modules.alias.bin          /lib/modules/5.14.0-rt21/modules.devname
/lib/modules/5.14.0-rt21/modules.builtin.alias.bin  /lib/modules/5.14.0-rt21/modules.softdep
/lib/modules/5.14.0-rt21/modules.builtin.bin        /lib/modules/5.14.0-rt21/modules.symbols
/lib/modules/5.14.0-rt21/modules.dep                /lib/modules/5.14.0-rt21/modules.symbols.bin

 

ls  /lib/modules/`uname -r`
          modules.builtin.alias.bin  modules.dep.bin  modules.symbols
modules.alias      modules.builtin.bin        modules.devname  modules.symbols.bin
modules.alias.bin  modules.dep                modules.softdep

 運行
cd  /lib/modules/`uname -r` && depmod -a

 

root@Ubuntu-riscv64:/lib/modules/5.14.0-rt21#  depmod -a
depmod: WARNING: could not open modules.order at /lib/modules/5.14.0-rt21: No such file or directory
depmod: WARNING: could not open modules.builtin at /lib/modules/5.14.0-rt21: No such file or directory

 

 CONFIG_LTO

 

Due to recent bug fixes in the toolchain, it's recommended to use clang
5.0 or later, and GNU gold from binutils 2.27 or later, although older
versions may also work depending on your kernel configuration. Here are
the steps for compiling arm64 defconfig with LTO, assuming LLVMgold.so is
in LD_LIBRARY_PATH and the rest of the toolchain is in PATH:

  $ make ARCH=arm64 defconfig
  $ ./scripts/config -e LTO_CLANG
  $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- CC=clang

 

 ls ./arch/riscv/include/asm/

 

 

riscv 開發工具安裝

Prerequisites
Several standard packages are needed to build the toolchain.

On Ubuntu, executing the following command should suffice:

$ sudo apt-get install autoconf automake autotools-dev curl python3 libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev
On Fedora/CentOS/RHEL OS, executing the following command should suffice:

$ sudo yum install autoconf automake python3 libmpc-devel mpfr-devel gmp-devel gawk  bison flex texinfo patchutils gcc gcc-c++ zlib-devel expat-devel
On Arch Linux, executing the following command should suffice:

$ sudo pacman -Syyu autoconf automake curl python3 libmpc mpfr gmp gawk base-devel bison flex texinfo gperf libtool patchutils bc zlib expat
Also available for Arch users on the AUR: https://aur.archlinux.org/packages/riscv-gnu-toolchain/

 

RISC-V Ubuntu Rootfs from scratch

Generating Kernel modules

Flashing to the SD Card

Creating disk image

Linux內核打實時補丁preempt_rt

RISC-V ICE EVB 開發板 linux環境下燒寫更新開發板鏡像


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM