You are on page 1of 3

xin chao thay va cac ban, hom nay minh se huong dan cac ban build kernel

dau tien la buoc chuan bi

buoc nay kha ton thoi gian cac ban chiu kho cho nhe

ok xong buoc chuan bi


tiep theo cac ban cau hinh cho kernel

toi duoc day thi cac ban se build nhu trong sach nhe

buoc nay don gian minh se tua nhanh nhe

cung kha mat thoi gian

nhanh hay cham tuy vao may cua ban manh hay yeu

tiep theo minh se chay thu code hello

tiep theo minh phai make file


Makefile cac ban nhe

*Prepare
~$ sudo apt install git bc bison flex libssl-dev make (thư viện git).
~$ git clone --depth=1 -b rpi-5.4.y https://github.com/raspberrypi/linux (kernel
source).
~$ sudo apt install crossbuild-essential-armhf (tool chain)
~$ sudo apt install libncurses5-dev

* Config kernel
//truy cap vao thu muc linux
cd linux/
~linux$ KERNEL=kernel7l (rpi4) ( ~/linux$ KERNEL=kernel7 (rpi2,3,3+))
~/linux$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2711_defconfig
(~/linux$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig)
~/linux$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig

(Cấu hình giống yêu cầu trong sách)


Device drivers >
[*] SPI support --->
<*> User mode SPI device driver support
Device drivers >
[*] LED Support --->
<*> LED Class Support
-*- LED Trigger support --->
<*> LED Timer Trigger
<*> LED Heartbeat Trigger
Device drivers >
<*> Industrial I/O support --->
-*- Enable buffer support within IIO
-*- Industrial I/O buffering based on kfifo
<*> Enable IIO configuration via configfs
-*- Enable triggered sampling support
<*> Enable software IIO device support
<*> Enable software triggers support
Triggers - standalone --->
<*> High resolution timer trigger
<*> SYSFS trigger
Device drivers >
<*> Userspace I/O drivers --->
<*> Userspace I/O platform driver with generic IRQ handling
<*> Userspace platform driver with generic irq and dynamic memory
Device drivers >
Input device support --->
-*- Generic input layer (needed for keyboard, mouse, ...)
<*> Polled input device skeleton
<*> Event interface

* Build kernel
~/linux$ make -j4 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs
* Copy to SD card
~$ lsblk
~$ mkdir ~/mnt
~$ mkdir ~/mnt/fat32
~$ mkdir ~/mnt/ext4
~$ sudo mount /dev/sdd1 ~/mnt/fat32/ (thay đổi tùy máy)
~$ sudo mount /dev/sdd2 ~/mnt/ext4/ (thay đổi tùy máy)
~/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/kernel7l.img ~/mnt/fat32/kernel7l-backup.img
~/linux$ sudo cp arch/arm/boot/zImage ~/mnt/fat32/kernel7l.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

day la code

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/int.h>

static int __init hello_init(void)


{
printk("Nguyen Dinh Phuoc 18119036\n");
return 0;
}
static void __exit hello_exit(void)
{
pr_info("Hello world exit\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("HCMUTE");
MODULE_AUTHOR("nguyen dinh phuoc>");
MODULE_DESCRIPTION("hello,mssv,hoten");

tiep theo cac ban phai make file

obj-m = hello.o

all:

make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

code minh co loi nhung den day la cac ban da thanh cong build duoc kernel roi

chuc cac ban thanh cong nhe

You might also like