§2023-10-31
How to get linux kernel source
?
- 機器: orgpi5+8G, running Ubuntu Jammy 22.04
- baskcup /boot
alexlai@orangepi5plus:~$sudo mkdir /mnt/ubuntu-jammy/boot
alexlai@orangepi5plus:~$ sudo cp -Rv /boot//* /mnt/ubuntu-jammy/boot/
alexlai@orangepi5plus:~$ ls -l /mnt/ubuntu-jammy/boot/
total 114880
-rwxr-xr-x 1 root root 230456 Nov 15 10:26 boot.bmp
-rwxr-xr-x 1 root root 3339 Nov 15 10:26 boot.cmd
-rwxr-xr-x 1 root root 3411 Nov 15 10:26 boot.scr
-rwxr-xr-x 1 root root 219610 Nov 15 10:26 config-5.10.110-rockchip-rk3588
drwxr-xr-x 3 root root 4096 Nov 15 10:26 dtb
drwxr-xr-x 3 root root 4096 Nov 15 10:26 dtb-5.10.110-rockchip-rk3588
-rwxr-xr-x 1 root root 34109952 Nov 15 10:26 Image
-rwxr-xr-x 1 root root 19996336 Nov 15 10:26 initrd.img-5.10.110-rockchip-rk3588
-rwxr-xr-x 1 root root 1152056 Nov 15 10:26 logo.bmp
-rwxr-xr-x 1 root root 227 Nov 15 10:26 orangepiEnv.txt
-rwxr-xr-x 1 root root 1542 Nov 15 10:26 orangepi_first_run.txt.template
-rwxr-xr-x 1 root root 7780782 Nov 15 10:26 System.map-5.10.110-rockchip-rk3588
-rwxr-xr-x 1 root root 19996400 Nov 15 10:26 uInitrd
-rwxr-xr-x 1 root root 34109952 Nov 15 10:26 vmlinuz-5.10.110-rockchip-rk3588
nano /etc/apt/sources.list
- uncomment the following lines
# deb-src http://us.ports.ubuntu.com/ubuntu-ports/ jammy main restricted
$ cat /etc/apt/sources.list
deb http://repo.huaweicloud.com/ubuntu-ports/ jammy main restricted universe multiverse
deb-src http://repo.huaweicloud.com/ubuntu-ports/ jammy main restricted universe multiverse <-- uncomment
deb http://repo.huaweicloud.com/ubuntu-ports/ jammy-security main restricted universe multiverse
deb-src http://repo.huaweicloud.com/ubuntu-ports/ jammy-security main restricted universe multiverse <-- uncomment
deb http://repo.huaweicloud.com/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb-src http://repo.huaweicloud.com/ubuntu-ports/ jammy-updates main restricted universe multiverse <-- uncomment
deb http://repo.huaweicloud.com/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb-src http://repo.huaweicloud.com/ubuntu-ports/ jammy-backports main restricted universe multiverse <-- uncomment
---
> # deb-src http://tw.ports.ubuntu.com/ubuntu-ports/ jammy-updates universe
sudo apt update
....
The following packages have been kept back:
wiringpi
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
3)apt-cache search linux-source
$ apt-cache search linux-source
linux-source - Linux kernel source with Ubuntu patches
linux-source-5.15.0 - Linux kernel source for version 5.15.0 with Ubuntu patches
linux-source-5.19.0 - Linux kernel source for version 5.19.0 with Ubuntu patches
linux-source-6.2.0 - Linux kernel source for version 6.2.0 with Ubuntu patches
alexlai@n2JamGen:~/build/src$ apt source linux-source-n.m.r
<-- no sudo
$ sudo apt install dpkg-dev
$ mkdir kernel-6.2.0 && cd $_
$ sudo apt install dpkg-dev
$ apt source linux-source-6.2.0 <-- no sudo
alexlai@orangepi5plus:~/build/kernel-6.2.0$ ls -l
total 222204
drwxrwxr-x 30 alexlai alexlai 4096 Nov 14 07:39 linux-hwe-6.2-6.2.0
-rw-r--r-- 1 alexlai alexlai 8950025 Oct 19 20:19 linux-hwe-6.2_6.2.0-35.35~22.04.1.diff.gz
-rw-r--r-- 1 alexlai alexlai 8835 Oct 19 20:19 linux-hwe-6.2_6.2.0-35.35~22.04.1.dsc
-rw-r--r-- 1 alexlai alexlai 218562620 Jun 9 00:24 linux-hwe-6.2_6.2.0.orig.tar.gz
sudo apt build-dep linux linux-image-$(uname -r)
make kernel required packages
alexlai@orangepi5plus:~/build/kernel-6.2.0$ sudo apt build-dep linux linux-image-$(uname -r)
alexlai@orangepi5plus:~/build/kernel-5.15.0/linux-5.15.0$ sudo apt build-dep linux <-- just this
[sudo] password for alexlai:
Reading package lists... Done
E: Unable to find a source package for linux-image-5.10.110-rockchip-rk3588
$ sudo apt build-dep linux
$ sudo apt-get install libncurses-dev gawk flex bison openssl libssl-dev dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf llvm
- using 5.19.0
$ ls -l
total 212996
drwxrwxr-x 29 alexlai alexlai 4096 Nov 15 11:19 linux-hwe-5.19-5.19.0
-rw-r--r-- 1 alexlai alexlai 9825208 Jul 24 23:45 linux-hwe-5.19_5.19.0-50.50.diff.gz
-rw-r--r-- 1 alexlai alexlai 8439 Jul 24 23:45 linux-hwe-5.19_5.19.0-50.50.dsc
-rw-r--r-- 1 alexlai alexlai 208263574 Nov 22 2022 linux-hwe-5.19_5.19.0.orig.tar.gz
alexlai@orangepi5plus:~/build/kernel-5.19.0/linux-hwe-5.19-5.19.0$ cp -v /boot/config-5.10.110-rockchip-rk3588 ./config
'/boot/config-5.10.110-rockchip-rk3588' -> './config'
alexlai@orangepi5plus:~/build/kernel-5.19.0/linux-hwe-5.19-5.19.0$ make oldconfig
$ make menuconfig --> [*] Rockchip Platforms
- make -j8
real 29m3.198s
user 200m49.418s
sys 27m21.404s
- make modules_install
$ ls /lib/modules
5.10.110-rockchip-rk3588
alexlai@orangepi5plus:~/build/kernel-5.19.0/linux-hwe-5.19-5.19.0$ sudo make modules_install
...
INSTALL /lib/modules/5.19.17/kernel/sound/drivers/snd-mtpav.ko
INSTALL /lib/modules/5.19.17/kernel/sound/drivers/snd-serial-u16550.ko
INSTALL /lib/modules/5.19.17/kernel/sound/drivers/snd-virmidi.ko
DEPMOD /lib/modules/5.19.17
alexlai@orangepi5plus:~/build/kernel-5.19.0/linux-hwe-5.19-5.19.0$ ls /lib/modules
5.10.110-rockchip-rk3588 5.19.17
- make install
alexlai@orangepi5plus:~/build/kernel-5.19.0/linux-hwe-5.19-5.19.0$ sudo ln -sf /usr/lib/linux-image-legacy-rockchip-rk3588/ /usr/lib/linux-image-6.2.16
alexlai@orangepi5plus:~/build/kernel-5.19.0/linux-hwe-5.19-5.19.0$ ls -l /usr/lib/linux-image-*
lrwxrwxrwx 1 root root 44 Nov 15 12:39 /usr/lib/linux-image-6.2.16 -> /usr/lib/linux-image-legacy-rockchip-rk3588/
/usr/lib/linux-image-legacy-rockchip-rk3588:
total 4
drwxr-xr-x 3 root root 4096 Jun 1 02:32 rockchip
alexlai@orangepi5plus:~/build/kernel-5.19.0/linux-hwe-5.19-5.19.0$ sudo make install
INSTALL /boot
run-parts: executing /etc/kernel/postinst.d/dkms 5.19.17 /boot/vmlinuz-5.19.17
* dkms: running auto installation service for kernel 5.19.17 [ OK ]
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 5.19.17 /boot/vmlinuz-5.19.17
update-initramfs: Generating /boot/initrd.img-5.19.17
update-initramfs: Converting to u-boot format
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 5.19.17 /boot/vmlinuz-5.19.17
run-parts: executing /etc/kernel/postinst.d/xx-initramfs-cleanup 5.19.17 /boot/vmlinuz-5.19.17
Free space after deleting the package in /boot: 852.9M
run-parts: executing /etc/kernel/postinst.d/xx-update-initrd-links 5.19.17 /boot/vmlinuz-5.19.17
Cpoy /boot/vmlinuz-5.19.17 to /boot/Image
- check /boot
alexlai@orangepi5plus:~/build/kernel-5.19.0/linux-hwe-5.19-5.19.0$ ls -l /boot/
total 167352
-rwxr-xr-x 1 root root 230456 Jun 1 02:32 boot.bmp
-rwxr-xr-x 1 root root 3339 Jun 1 02:31 boot.cmd
-rwxr-xr-x 1 root root 3411 Jun 1 02:39 boot.scr
-rwxr-xr-x 1 root root 219610 Jun 1 00:04 config-5.10.110-rockchip-rk3588
-rwxr-xr-x 1 root root 216719 Nov 15 12:41 config-5.19.17
drwxr-xr-x 3 root root 4096 Jun 1 02:32 dtb
drwxr-xr-x 3 root root 4096 Jun 1 02:32 dtb-5.10.110-rockchip-rk3588
-rwxr-xr-x 1 root root 30300672 Nov 15 12:41 Image
-rwxr-xr-x 1 root root 19996336 Nov 15 04:54 initrd.img-5.10.110-rockchip-rk3588
-rwxr-xr-x 1 root root 19921582 Nov 15 12:41 initrd.img-5.19.17
-rwxr-xr-x 1 root root 1152056 Jun 1 02:32 logo.bmp
-rwxr-xr-x 1 root root 227 Nov 15 10:58 orangepiEnv.txt
-rwxr-xr-x 1 root root 1542 Jun 1 02:38 orangepi_first_run.txt.template
-rwxr-xr-x 1 root root 7780782 Jun 1 00:04 System.map-5.10.110-rockchip-rk3588
-rwxr-xr-x 1 root root 7172477 Nov 15 12:41 System.map-5.19.17
-rwxr-xr-x 1 root root 19921646 Nov 15 12:41 uInitrd
-rwxr-xr-x 1 root root 34109952 Jun 1 00:04 vmlinuz-5.10.110-
-rwxr-xr-x 1 root root 30300672 Nov 15 12:41 vmlinuz-5.19.17
alexlai@orangepi5plus:/boot$ diff Image vmlinuz-5.19.17
[alexlai@orgpi58G mnt]$ sudo mv uInitrd uInitrd.old
[alexlai@orgpi58G mnt]$ sudo mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 -n uInitrd -d initrd.img-5.19.17 uInitrd
Image Name: uInitrd
Created: Wed Nov 15 13:10:32 2023
Image Type: ARM Linux RAMDisk Image (uncompressed)
Data Size: 19921582 Bytes = 19454.67 KiB = 19.00 MiB
Load Address: 00000000
Entry Point: 00000000
[alexlai@orgpi58G mnt]$ file uInitrd
uInitrd: u-boot legacy uImage, uInitrd, Linux/ARM, RAMDisk Image (Not compressed), 19921582 bytes, Wed Nov 15 05:10:32 2023, Load Address: 00000000, Entry Point: 00000000, Header CRC: 0XDF58B7AE, Data CRC: 0X5BDC5928
[alexlai@orgpi58G mnt]$ file uInitrd/old
uInitrd/old: cannot open `uInitrd/old' (Not a directory)
[alexlai@orgpi58G mnt]$ file uInitrd.old
uInitrd.old: u-boot legacy uImage, uInitrd, Linux/ARM 64-bit, RAMDisk Image (gzip), 19921582 bytes, Wed Nov 15 04:41:12 2023, Load Address: 00000000, Entry Point: 00000000, Header CRC: 0XE3F773BB, Data CRC: 0X5BDC5928
failed to build 5.15.0
- cp -v /boot/config-5.10.110-rockchip-rk3588 .config
$ cp -v /boot/config-5.10.110-rockchip-rk3588 .config
alexlai@orangepi5plus:~/build/kernel-5.15.0/linux-5.15.0$ make oldconfig
/bin/sh: 1: ./scripts/pahole-flags.sh: Permission denied
HOSTCC scripts/basic/fixdep
/bin/sh: 1: ./scripts/pahole-flags.sh: Permission denied
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/confdata.o
HOSTCC scripts/kconfig/expr.o
LEX scripts/kconfig/lexer.lex.c
YACC scripts/kconfig/parser.tab.[ch]
HOSTCC scripts/kconfig/lexer.lex.o
HOSTCC scripts/kconfig/menu.o
HOSTCC scripts/kconfig/parser.tab.o
HOSTCC scripts/kconfig/preprocess.o
HOSTCC scripts/kconfig/symbol.o
HOSTCC scripts/kconfig/util.o
HOSTLD scripts/kconfig/conf
sh: 1: ./scripts/pahole-version.sh: Permission denied
init/Kconfig:97: syntax error
init/Kconfig:96: invalid statement
make[1]: *** [scripts/kconfig/Makefile:77: oldconfig] Error 1
make: *** [Makefile:630: oldconfig] Error 2
alexlai@orangepi5plus:~/build/kernel-5.15.0/linux-5.15.0$ make oldconfig
/bin/sh: 1: ./scripts/pahole-flags.sh: Permission denied
/bin/sh: 1: ./scripts/pahole-flags.sh: Permission denied
sh: 1: ./scripts/pahole-version.sh: Permission denied
init/Kconfig:97: syntax error
init/Kconfig:96: invalid statement
make[1]: *** [scripts/kconfig/Makefile:77: oldconfig] Error 1
make: *** [Makefile:630: oldconfig] Error 2
$ chmod a+x ./scripts/pahole-version.sh
alexlai@orangepi5plus:~/build/kernel-5.15.0/linux-5.15.0$ make oldconfig
/bin/sh: 1: ./scripts/pahole-flags.sh: Permission denied
/bin/sh: 1: ./scripts/pahole-flags.sh: Permission denied
.config:8056:warning: symbol value 'm' invalid for CRYPTO_LIB_BLAKE2S_GENERIC
*
* Restart config...
*
*
* General setup
*
Compile also drivers which will not load (COMPILE_TEST) [N/y/?] n
Compile the kernel with warnings as errors (WERROR) [N/y/?] (NEW) ^Cmake[1]: *** [scripts/kconfig/Makefile:77: oldconfig] Interrupt
make: *** [Makefile:630: oldconfig] Interrupt
alexlai@orangepi5plus:~/build/kernel-5.15.0/linux-5.15.0$ make oldconfig
.config:8056:warning: symbol value 'm' invalid for CRYPTO_LIB_BLAKE2S_GENERIC
*
* Restart config...
*
*
* General setup
*
Compile also drivers which will not load (COMPILE_TEST) [N/y/?] n
Compile the kernel with warnings as errors (WERROR) [N/y/?] (NEW) ---> then take all defaults
$ make menuconfig --> make sure [*] Rockchip Platforms is selecrted
- time make -j8
real 05m7.854s
user 35m30.518s
sys 4m16.918s
make install
$ ls /lib/modules
5.10.110-rockchip-rk3588
$ sudo make install modules_install
[sudo] password for alexlai:
sh ./arch/arm64/boot/install.sh 5.15.122 \
arch/arm64/boot/Image System.map "/boot"
*** Missing file: arch/arm64/boot/Image
*** You need to run "make" before "make install".
make[1]: *** [arch/arm64/Makefile:163: install] Error 1
make: *** [Makefile:357: __build_one_by_one] Error 2
make
$ cd linux-hwe-6.2-6.2.0/
$ cp -v /boot/config-5.10.110-rockchip-rk3588 .config
'/boot/config-5.10.110-rockchip-rk3588' -> '.config'
$ make oldconfig
---
alexlai@n2JamGen:~/build/src/linux-5.15.0$ chmod a+x scripts/pahole-flags.sh
alexlai@n2JamGen:~/build/src/linux-5.15.0$ chmod a+x scripts/pahole-version.sh
$ sudo apt install libncurses-dev
$ make oldconfig --> take defaults for new options
$ make menuconfig
---> only [*] Rockchip Platforms selected
$ time make -j8
real 29m27.578s
user 203m47.992s
sys 28m28.799s
- on hc4Odroid
real 141m40.236s
user 511m12.448s
sys 46m22.344s
- make modules_install
$ ls /lib/modules
5.10.110-rockchip-rk3588
alexlai@n2JamGen:~/build/src/linux-5.15.0$ sudo make modules_install
...
INSTALL /lib/modules/6.2.16/kernel/net/qrtr/qrtr.ko
INSTALL /lib/modules/6.2.16/kernel/net/qrtr/qrtr-tun.ko
INSTALL /lib/modules/6.2.16/kernel/net/qrtr/qrtr-mhi.ko
DEPMOD /lib/modules/6.2.16
- make install
/usr/lib/linux-image-*
alexlai@n2JamGen:/var/log$ ls -l /usr/lib/linux-image-*
lrwxrwxrwx 1 root root 41 Nov 12 13:16 /usr/lib/linux-image-5.15.126 -> /usr/lib/linux-image-5.15.0-odroid-arm64/
lrwxrwxrwx 1 root root 41 Nov 12 15:58 /usr/lib/linux-image-6.2.16 -> /usr/lib/linux-image-5.15.0-odroid-arm64/
/usr/lib/linux-image-5.15.0-odroid-arm64:
total 8
drwxr-xr-x 3 root root 4096 Nov 12 08:31 amlogic
drwxr-xr-x 2 root root 4096 Nov 12 08:31 rockchip
$ ls -l /boot
total 114876
-rwxr-xr-x 1 root root 230456 Jun 1 02:32 boot.bmp
-rwxr-xr-x 1 root root 3339 Jun 1 02:31 boot.cmd
-rwxr-xr-x 1 root root 3411 Jun 1 02:39 boot.scr
-rwxr-xr-x 1 root root 219610 Jun 1 00:04 config-5.10.110-rockchip-rk3588
drwxr-xr-x 3 root root 4096 Jun 1 02:32 dtb
drwxr-xr-x 3 root root 4096 Jun 1 02:32 dtb-5.10.110-rockchip-rk3588
-rwxr-xr-x 1 root root 34109952 Jun 1 00:04 Image
-rwxr-xr-x 1 root root 19995785 Nov 14 06:06 initrd.img-5.10.110-rockchip-rk3588
-rwxr-xr-x 1 root root 1152056 Jun 1 02:32 logo.bmp
-rwxr-xr-x 1 root root 227 Nov 14 06:10 orangepiEnv.txt
-rwxr-xr-x 1 root root 1542 Jun 1 02:38 orangepi_first_run.txt.template
-rwxr-xr-x 1 root root 7780782 Jun 1 00:04 System.map-5.10.110-rockchip-rk3588
-rwxr-xr-x 1 root root 19995849 Nov 14 06:06 uInitrd
-rwxr-xr-x 1 root root 34109952 Jun 1 00:04 vmlinuz-5.10.110-rockchip-rk3588
alexlai@orangepi5plus:~/build/kernel-6.2.0/linux-hwe-6.2-6.2.0$ sudo make install
INSTALL /boot
run-parts: executing /etc/kernel/postinst.d/dkms 6.2.16 /boot/vmlinuz-6.2.16
* dkms: running auto installation service for kernel 6.2.16 [ OK ]
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 6.2.16 /boot/vmlinuz-6.2.16
update-initramfs: Generating /boot/initrd.img-6.2.16
update-initramfs: Converting to u-boot format
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 6.2.16 /boot/vmlinuz-6.2.16
run-parts: executing /etc/kernel/postinst.d/xx-initramfs-cleanup 6.2.16 /boot/vmlinuz-6.2.16
Free space after deleting the package in /boot: 852.4M
run-parts: executing /etc/kernel/postinst.d/xx-update-initrd-links 6.2.16 /boot/vmlinuz-6.2.16
Cpoy /boot/vmlinuz-6.2.16 to /boot/Image
alexlai@orangepi5plus:~/build/kernel-6.2.0/linux-hwe-6.2-6.2.0$ ls -l /boot/
total 169480
-rwxr-xr-x 1 root root 230456 Jun 1 02:32 boot.bmp
-rwxr-xr-x 1 root root 3339 Jun 1 02:31 boot.cmd
-rwxr-xr-x 1 root root 3411 Jun 1 02:39 boot.scr
-rwxr-xr-x 1 root root 219610 Jun 1 00:04 config-5.10.110-rockchip-rk3588
-rwxr-xr-x 1 root root 221425 Nov 14 08:31 config-6.2.16
drwxr-xr-x 3 root root 4096 Jun 1 02:32 dtb
drwxr-xr-x 3 root root 4096 Jun 1 02:32 dtb-5.10.110-rockchip-rk3588
-rwxr-xr-x 1 root root 31863296 Nov 14 08:31 Image
-rwxr-xr-x 1 root root 19995785 Nov 14 06:06 initrd.img-5.10.110-rockchip-rk3588
-rwxr-xr-x 1 root root 20014999 Nov 14 08:31 initrd.img-6.2.16
-rwxr-xr-x 1 root root 1152056 Jun 1 02:32 logo.bmp
-rwxr-xr-x 1 root root 227 Nov 14 06:10 orangepiEnv.txt
-rwxr-xr-x 1 root root 1542 Jun 1 02:38 orangepi_first_run.txt.template
-rwxr-xr-x 1 root root 7780782 Jun 1 00:04 System.map-5.10.110-rockchip-rk3588
-rwxr-xr-x 1 root root 6028527 Nov 14 08:31 System.map-6.2.16
-rwxr-xr-x 1 root root 20015063 Nov 14 08:31 uInitrd
-rwxr-xr-x 1 root root 34109952 Jun 1 00:04 vmlinuz-5.10.110-rockchip-rk3588
-rwxr-xr-x 1 root root 31863296 Nov 14 08:31 vmlinuz-6.2.16
alexlai@orangepi5plus:~/build/kernel-6.2.0/linux-hwe-6.2-6.2.0$ cat /boot/orangepiEnv.txt
verbosity=1
bootlogo=false
extraargs=cma=128M
overlay_prefix=rk3588
fdtfile=rockchip/rk3588-orangepi-5-plus.dtb
rootdev=UUID=1d503487-9341-4440-a0a9-2677d1a862f1
rootfstype=ext4
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u
- modify boot.scripts
if test -z "${fk_kvers}"; then
# setenv fk_kvers "5.15.0-odroid-arm64"
setenv fk_kvers "5.15.126"
alexlai@n2JamGen:/boot$ sudo mkimage -A arm -T script -C none -n "Ubuntu boot script" -d boot.script boot.scr
Image Name: Ubuntu boot script
Created: Sun Nov 12 11:19:21 2023
Image Type: ARM Linux Script (uncompressed)
Data Size: 4484 Bytes = 4.38 KiB = 0.00 MiB
Load Address: 00000000
Entry Point: 00000000
Contents:
Image 0: 4476 Bytes = 4.37 KiB = 0.00 MiB