LINUX KERNEL
rootfs
busybox
embedded Linux
Authors: WhoAmI, CrazyMonkey
email: kccddb@gmail.com
Date: 2023-10-11
Copyright: CC BY-NC-SA
故不積跬步,無以至千里;不積小流,無以成江海~荀子
學而不思則罔 思而不學則殆~論語
偉大的 GNU GPL 前輩 Richard Matthew Stallman (rms)
The course covers the basic and advanced issues of Embedded Linux System such as boot loader, toolchain, linux kernel source code, root file system, kernel module and device driver.
Stability is an important issue.
先修科目 (Prerequisites) : C (or C++) Language, Linux, Network programming and OS
教室 資電 515 星期二 13:10-16:00
c Language:
ANSI C for Programmers on UNIX Systems, Tim Love
C 也可以寫的很OOP 簡單範例與簡易Makefile, 務必要懂
Win32 c 有 cygwin 可以練習 c 語言 (使用 gcc)
LINUX:
Rute User's Tutorial and Exposition
(Version 1.0.0), by Paul Sheer
Object-oriented design patterns in the kernel, part 1
Object-oriented design patterns in the kernel, part 2
shell (bash): OnlineGDB 可以練習, 還是用自己的 Linux 方便
Linux network commands: ip addr xxxxx, ip route xxxxx, ifconfig xxxxx, …
embedded system 軟體設計中 有遞迴(Recursive) 設計時 要特別注意 stack overflow
善用 ramdisk, tmpfs 降低對 flash 的讀寫次數: How to Create a Ramdisk in Linux
Linux Tmpfs
如果記憶體 夠大~用 Ramdisk 放網頁等也很適合
VirtualBox: Create Ubuntu 16.04.7 (最好有40G, two NICs (NAT Mode and Bridged Mode))
Text editor: vim, nano, gedit(need X-window),…
練習 看 8051 datasheet,[ 8390D datasheet]
(https://pdf1.alldatasheet.com/datasheet-pdf/view/8365/NSC/DP8390D.html)
Futher Reading (宣老師 提供):
Linux Kernel Teaching
Linux 核心模組運作原理
這課程大都是 原理的理解與實作~相信是很花時間的課程
原理老師們會教也給實例, 但要學生自己練習做過, 就像開車也要自己練習一樣, 只是會背名詞考試沒有大用, 基礎要好~計概(含 c, 資料結構) , 微處理機, OS, 要紮實, 基礎要學好
早期 吳大猷院長 也說 "基礎" 很重要, 因為是日後自我學習的基礎
我看過一本書~有讀者問 blog 作者一個問題, 結果 作者 回的是 請 複習 成語辭典 "囫圇吞棗"
我看了都笑出來~
PC817 Photocoupler 可隔離電源
A3144 LINEAR HALL-EFFECT SENSORS, 可用磁鐵當開關
2SD313 NPN (3A) 可換電壓
請看 datasheet 複習 電子學 電路學
Container (abstract data type)
e.g., The HTML element is the generic container for flow content.
Ref. w3schools
另外 還有 Boot Loader 部分 例如 [U-Boot], 因需硬體設備例如 樹莓派(英語:Raspberry Pi)或 Banana Pi ,本課程不含 這部分
What is a bootloader and how does it work?
stackoverflow 可以查到 很多 好心軟體系統等專家幫你解答疑惑, 是您進步的明燈
fcu embedded system (大三)
Linux 的 ls 指令教學與常用範例整理
Course Outlines
1. Embedded Linux and how the system works:
Boot Loader, Linux OS, root file system (rootfs) and init
2. Linux System Calls, VFS, and How it works
以下就是 實作的基礎 請讀者 務必實作一遍, 用 QEMU 代替 實際的 embedded system, 可以方便學習與測試
本課程 與 kernel 相關 都由 source code 做起
第一步驟 能夠用 toolchain 建造 linux kernel image 與 rootfs.
4. Busybox, build x86 kernel (linux-[4.4.50]) and rootfs (busybox 1.22.0)
How to enable PXE boot with VirtualBox, by Jack Wallen
Setting up a ‘PXE Network Boot Server’ for Multiple Linux Distribution Installations in RHEL/CentOS 7
Build SYSLINUX 6.03
A bootloader for Linux using the PXE network booting protocol
master boot record (MBR)
UEFI (Unified Extensible Firmware Interface)
UEFI 是什麼以及如何在 Windows 中使用它?【完整教學】
讀者有空時 可用 真正的電腦測試, 這種方式 可以 避免 每個人都要 裝 toolchain…等等 方便 版本維護
重點: Build rootfs (busybox 1.22.0) and understand rootfs
wget https://www.busybox.net/downloads/busybox-1.22.0.tar.bz2 –no-check-certificate
HW (期中考後一星期完成, 同一組只須交一份紙本, 期末口試):
Linux Kernel: 簡介HZ, tick and jiffies
sysfs - a filesystem for exporting kernel objects
proc - process information, system information, and sysctl pseudo-filesystem
enum
{
HI_SOFTIRQ=0,
TIMER_SOFTIRQ,
NET_TX_SOFTIRQ,
NET_RX_SOFTIRQ,
BLOCK_SOFTIRQ,
IRQ_POLL_SOFTIRQ,
TASKLET_SOFTIRQ,
SCHED_SOFTIRQ,
HRTIMER_SOFTIRQ,
RCU_SOFTIRQ, /* Preferable RCU should always be the last softirq */
NR_SOFTIRQS
};
softirqs : deferred work runs in interrupt context
tasklets : deferred work runs in interrupt context
work queues : deferred work runs in process context
softirqs : Softirqs of the same type can run concurrently on several CPUs.
tasklets : Tasklets of different types can run concurrently on several CPUs, but tasklets of the same type cannot.
work queues : can run simultaneously on different CPU's
softirqs : cannot go to sleep
tasklets : cannot go to sleep
work queues : can go to sleep
softirqs : cannot be preempted/schedule
tasklets : cannot be preempted/schedule
work queues : maybe be preempted/schedule
softirqs : not easy to use
tasklets : easy to use
work queues : easy to use
int alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count, const char *name)
register a range of char device numbers
udev - Dynamic device management
busybox: mdev
Parameters
dev_t *dev
output parameter for first assigned number
unsigned baseminor
first of the requested range of minor numbers
unsigned count
the number of minor numbers required
const char *name
the name of the associated device or driver
Description
Allocates a range of char device numbers. The major number will be chosen dynamically, and returned (along with the first minor number) in dev. Returns zero or a negative error code.
How to initialize device's class when register device in linux-6.0
通过 Linux sysfs 玩转硬件
Linux下通过sysfs方式控制GPIO(/sys/class/gpio)
The Linux Kernel Module Programming Guide, by Pe Jay Salzman, Michael Burian , Ori Pomerantz, Bob Mottram, Jim Huang
Cultivate teamwork to complete homework in groups of 2-3 people
Final oral test
No interim written test
Class situation
TEXTBOOKS AND ON-LINE EDUCATIONAL MATERIAL
Install:
Ubuntu-16.04.7 server version
install openssh-server
modify sshd_config
putty or MobaXterm
Learn iproute2
ip addr
ip route
Learn commands: (請看 man page)
vim, nano, wget, curl, sudo, cd, ls, cp, cat, more, find, ln, grep, ps, chmod, chown, tar, mkdir, rm, rmdir, df, du, kill, echo, which, man, top, ping, touch, pstree, strace, strip, file, tcpdump, mount, umount, dd, objdump, gzip, mke2fs, sync, cpio, losetup, strip -g (Remove debugging symbols only), rsync, gzip, gunzip, file, chroot, tee, tail, dd, uname, uname -r, mdev (busybox 代替 udev), udevadm - udev management tool, gawk, awk 這比較難且與 Regular Expressions 有關, 您有空與需要再學, …
30+ awk examples for beginners / awk command tutorial in Linux/Unix
ntpd - Network Time Protocol (NTP) daemon
Linux 使用 wget 指令自動下載網頁檔案教學與範例, by G. T. Wang
Shell Scripting for Beginners – How to Write Bash Scripts in Linux
grep: Linux 匹配文字 grep 指令用法教學與範例, by G. T. Wang
Linux 2.6.33
Embedded Linux System, Boot, Linux VFS, System Call, SPI, GPIO, … 課程基礎原理 |
---|
|
C 也可以寫的很OOP 簡單範例與簡易Makefile | c language: function pointer, callback |
---|---|
busybox-1.22.0 and linux-4.4.50 | QEMU 5.0.0 |
System calls in the Linux kernel. Part 1.
Introduction to deferred interrupts (Softirq, Tasklets and Workqueues)
Appendix
練習 看 8051 datasheet 與
DP8390 Datasheet~NIC controller
Sleeping in the Kernel and Frame Reception/Transmission
linux-insides
Linux Network Programming, by WhoAmI
getloadavg - get system load averages
https://www.gnu.org/software/libc/manual/html_node/Integers.html
水不在深 有龍則靈
有內功(基礎理論知識, 演算法, OS, 網路知識, …) 沒 外功 (程式設計, 微處理機, 網路程式設計…) 無法打架 例如 覺遠大師
有外功 沒內功 進步有限, 除非 您是 洪七公
如果 經濟上許可 (課程上 不要求有)
或
如果對 單晶片+Wifi 或 物聯網專題 有興趣可以參考 ESP8266 (可以用 Arduino IDE 開發軟體)
有 硬體 可以練習 實作經驗與技巧
千里之行 始於足下