Step 1: Download (the same version) -----------------------------------------------
- Linux Kernel Source
https://github.com/raspberrypi/linux/releases
"linux-raspberrypi-kernel_1.20210303-1.tar.gz"
- Kernel-Header file
https://archive.raspberrypi.org/debian/pool/main/r/raspberrypi-firmware/?
C=M;O=Download
"raspberrypi-kernel-headers_1.20210303-1_armhf.deb"
Step 2: Copy "Linux Kernel Source" to Ubuntu
---------------------------------------
$sudo apt-get update
*Copy by hand "linux*.tar.gz" to ~ "/home/accountname"
$tar -xvzf tarfile.tar.gz
Step3: Create Built-in character driver
--------------------------------------------
$cp mymodule.c ~/linux*/drivers/char/
$nano ~/linux*/drivers/char/Makefile
obj-$(CONFIG_MYDRIVER01) += mymodule.o
$nano ~/linux-raspberrypi-kernel_1.20210303-1/drivers/char/Kconfig
.....
config MYDRIVER01
tristate "My Manual Driver 01"
default n
help
read more about my driver 01
config .....
$cat ~/linux*/.config | grep MYDRIVER01
"# CONFIG_MYDRIVER01 is not set"
Step4: Install necessary tools -------------------------------------------
~$ sudo apt install git bc bison flex libssl-dev make
~$ sudo apt install crossbuild-essential-armhf
~$ sudo apt install libncurses5-dev
Step5: Config Kernel ------------------------------------------------------
~$cd linux*/
~/linux*$ KERNEL=kernel7
~/linux*$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig
~/linux*$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
"Device Drivers/Character Devices/
[*] My Manual Driver 01"
=> Save & Exit.
$cat ~/linux*/.config | grep MYDRIVER01
"CONFIG_MYDRIVER01=y"
Step6: build kernel ------------------------------------------------------
~/linux*$ make -j6 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs
Step7: Copy to SD card ---------------------------------------------------
~$ lsblk
~$ mkdir ~/mnt
~$ mkdir ~/mnt/fat32
~$ mkidr ~/mnt/ext4
~$ sudo mount /dev/sdb1 ~/mnt/fat32 (thay doi tuy may)
~$ sudo mount /dev/sdb2 ~/mnt/ext4 (thay doi tuy may)
~/linux$ sudo env PATH=$PATH make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf
INSTALL_MOD_PATH=~/mnt/ext4 modules_install
~/linux$ sudo cp ~/mnt/fat32/kernel7.img ~/mnt/fat32/kernel7-backup.image
~/linux$ sudo cp arch/arm/boot/zImage ~/mnt/fat32/kernel7_name.img
~/linux$ sudo cp arch/arm/boot/dts/*.dtb ~/mnt/fat32/
~/linux$ sudo cp arch/arm/boot/dts/overlays/*.dtb* ~/mnt/fat32/overlays/
~/linux$ sudo cp arch/arm/boot/dts/overlays/README ~/mnt/fat32/overlays/
~$ sudo umount ~/mnt/fat32
~$ sudo umount ~/mnt/ext4
// Another option is to copy the kernel into the same place, but with a different
filename - for instance, kernel-myconfig.img - rather
// than overwriting the kernel.img file. You can then edit the config.txt file to
select the kernel that the Pi will boot into:
// dev/sdb1 = ~/mnt/fat32/ = boot(FAT) 256MB
mkdir = ~/mnt./ext4 = root(ext4) xxGB
kernel=kernel_name.img
Step8: Check "MSSV - Hoten" ---------------------------------------------
*Reboot HDH on Pi/
$dmesg | tail -n 5
(if not have mssc, you will failt!)
Step9: Install kernel headers (Raspberry Pi) ----------------------------
$sudo apt install ./raspberrypi-kernel-headers_1.20210303-1_armhf.deb
(or sudo dpkg -i raspberrypi-kernel-headers_1.20210303-1_armhf.deb)
(> 10 miniute)
Step 10: build a ex_module on Pi ---------------------------------------------
- make to check the version compatible.