리눅스 커널 포팅 가이드
- 작성자
- 고친과정
2025년 10월 14일 : 처음씀
Contents
- 1. 리눅스 커널 포팅 가이드
- 1.1. 개요
- 1.2. Kernel 프로그래밍을 위해서 알아야 할 것들
- 1.3. Kernel version별 주요 변화
- 1.4. Kernel source directory
- 1.4.1. scripts
- 1.4.2. arch
- 1.4.3. block
- 1.4.4. certs
- 1.4.5. crypto
- 1.4.6. Documentation
- 1.4.7. drivers
- 1.4.8. fs
- 1.4.9. include
- 1.4.10. init
- 1.4.11. io_uring
- 1.4.12. ipc
- 1.4.13. kernel
- 1.4.14. lib
- 1.4.15. LICENSES
- 1.4.16. mm
- 1.4.17. net
- 1.4.18. rust
- 1.4.19. samples
- 1.4.20. security
- 1.4.21. sound
- 1.4.22. tools
- 1.4.23. usr
- 1.4.24. virt
- 1.5. 참고자료
1.1. 개요
리눅스 커널은 "리누스 토발즈"가 개발하여 1991년에 처음으로 v0.01이 Copyleft로 처음 공개되어진 커널입니다. 현재는 전세계 수많은 개발자들이 협력하여 커널이 개발되고 있습니다.
버전이 올라가면서 수많은 발전을 하고 있는 부분에 대해서 어떤 변화를 가져왔고 어떻게 바뀌는지 정리를 시작해봅니다. 커널 개발하면서 겪었던 사항을 조금씩 정리해보겠습니다.
본 문서는 개인적인 해석관점에서 작성되었으므로 사실과 다른 부분이 있을지도 모릅니다. 만약 올바르지 않은 사항이 있다면 알려주세요.
버전이 올라가면서 수많은 발전을 하고 있는 부분에 대해서 어떤 변화를 가져왔고 어떻게 바뀌는지 정리를 시작해봅니다. 커널 개발하면서 겪었던 사항을 조금씩 정리해보겠습니다.
본 문서는 개인적인 해석관점에서 작성되었으므로 사실과 다른 부분이 있을지도 모릅니다. 만약 올바르지 않은 사항이 있다면 알려주세요.
1.2. Kernel 프로그래밍을 위해서 알아야 할 것들
1.2.1. Kernel build
1.2.2. Kernel vs User side 구분
Kernel code와 User side application을 source상에서 구분해야 할 경우가 있는데 이 경우 다음과 같이 구분할 수 있습니다.
#if defined(__KERNEL__) /* Kernel code 영역 */ #else /* User side application 영역 */ #endif
1.2.3. Kernel version에 따른 호환성 구현
LINUX_VERSION_CODE 상수는 현재 빌드한 커널의 버전 상수를 가지고 있습니다. 이 상수를 KERNEL_VERSION(<VERSION>,<PATCHLEVEL>,<SUBLEVEL>) macro 로 지정한 버젼과 비교하여 호환에 맞는 구현을 구분하도록 할 수 있습니다.
#include <linux/version.h> #include <linux/kernel.h> #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0) /* Kernel version 4.15 이상에서 작동하는 코드 */ #else /* Kernel version 4.15 미만에서 작동하는 코드 */ #endif
1.2.4. Kernel config 식별
- IS_ENABLED(<config-name>) macro
#if IS_ENABLED(CONFIG_VLAN_8021Q) /* CONFIG_VLAN_8021Q 가 Kernel config에서 y 또는 m으로 설정되었음 */ #endif
1.2.5. Kernel module 작성
1.2.6. 디버그(Debug) / 분석
1.3. Kernel version별 주요 변화
- v6.15
- x86계열의 경우 gcc v8.1.0이상의 버젼을 요구합니다.
1.4. Kernel source directory
1.4.1. scripts
- scripts/min-tool-version.sh 에서 빌드에 필요한 binutils / gcc / llvm / rustc / bindgen 등의 최소 요구되는 버전을 체크합니다.
1.4.2. arch
1.4.3. block
1.4.4. certs
1.4.5. crypto
1.4.6. Documentation
1.4.7. drivers
1.4.8. fs
1.4.9. include
1.4.10. init
1.4.11. io_uring
1.4.12. ipc
1.4.13. kernel
1.4.14. lib
1.4.15. LICENSES
1.4.16. mm
1.4.17. net
1.4.17.1. struct net_device
- net_device ifname
printk(KERN_INFO "this dev's ifname is %s\n", netdev_name(dev));
- ifalias
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0) /* rcu ifalias */ const struct dev_ifalias *alias = rcu_dereference(dev->ifalias); if(alias) { printk(KERN_INFO "ifalias=%s\n", alias->ifalias); } #else if(dev->ifalias) { printk(KERN_INFO "ifalias=%s\n", dev->ifalias); } #endif
- netif_has_l3_rx_handler / IFF_L3MDEV_RX_HANDLER
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,20,7) /* netif_has_l3_rx_handler */ if(netif_has_l3_rx_handler(dev)) { /* IFF_L3MDEV_RX_HANDLER */ printk(KERN_INFO "this dev is l3mdev_rx\n"); } #endif
- netif_is_failover / IFF_FAILOVER, netif_is_failover_slave / IFF_FAILOVER_SLAVE
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,18,0) /* netif_is_failover/netif_is_failover_slave IFF_FAILOVER/IFF_FAILOVER_SLAVE */ if(netif_is_failover(dev)) { /* IFF_FAILOVER */ printk(KERN_INFO "this dev is failover\n"); } if(netif_is_failover_slave(dev)) { /* IFF_FAILOVER_SLAVE */ printk(KERN_INFO "this dev is failover_port\n"); } #endif
- is_vlan_dev / IFF_802_1Q_VLAN
#if IS_ENABLED(CONFIG_VLAN_8021Q) if(is_vlan_dev(dev)) { /* IFF_802_1Q_VLAN */ printk(KERN_INFO "this dev is vlan\n"); } #endif
- is LLTX / NETIF_F_LLTX
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,12,0) /* LLTX flag */ if(!!dev->lltx) { printk(KERN_INFO "this dev is lltx\n"); } #else if(!!(dev->features & NETIF_F_LLTX)) { printk(KERN_INFO "this dev is lltx\n"); } #endif
1.4.18. rust
1.4.19. samples
1.4.20. security
1.4.21. sound
1.4.22. tools
1.4.23. usr
1.4.24. virt
1.5. 참고자료
- 리눅스에 대하여
- 리눅스 커널에 대하여
- 절대적 순방향 시간자원 얻기
- Netlink socket에 대하여
- 러스트(Rust) 언어
- Linux Network Device Driver
- Linux Kernel의 skbuff(Socket buffer descriptors)에 대하여
- XDP(eXpress Data Path)
- i386 보호모드 (i386 Protected Mode)
The Linux Kernel Archives
Bootlin Elixir Cross Referencer
NVD Vulnerability Search
Arm GNU Toolchain Downloads
https://junsoolee.gitbook.io/linux-insides-ko/summary/interrupts/linux-interrupts-9
https://kjy8901.github.io/blog/2019/10/28/kernel_list.html