Professional Documents
Culture Documents
tw
(02)2705-5066
www.wunan.com.tw
(02)2705-5066
Linux
Linux Linux
Linux
Linux
C/OS-II
Linux Linux
Linux
Linux
ARM Jean J.
Labrosse
Linux
1. Linux
Yes!
2.
www.wunan.com.tw
(02)2705-5066
3. Linux Windows
Linux
4.Linux
Linux
Linux
Linux
Linux
5.
Yes!
6. Linux
Linux Linux
www.wunan.com.tw
(02)2705-5066
Linux
Linux
C/OS-IIT-KERNEL
7. Linux
Shell Linux
Linux
renzhe71@sina.com
www.wunan.com.tw
(02)2705-5066
1
2
Linux
1.1Linux
1.2Linux
1.3Linux C
11
1.4Linux
13
1.5Linux
23
Linux
41
2.1
42
2.2
42
2.3Linux
58
2.4Linux
62
2.5Linux
67
2.6 Slab
85
2.7Linux
88
Linux
3.1Linux processing
91
92
www.wunan.com.tw
(02)2705-5066
4
5
3.2Linux
100
3.3Linux
118
3.4Linux 2.6
125
135
4.1
136
4.2Linux
140
4.3Linux
142
4.4Linux
152
4.5
170
Linux
179
5.1
180
5.2
184
5.3
189
5.4Ext2
194
5.5
203
5.6
206
5.7Linux
210
5.8Linux Proc
226
5.9
227
5.10
230
www.wunan.com.tw
(02)2705-5066
7
8
5.11
236
5.12
239
Linux
241
6.1
242
6.2System V IPC
244
6.3
248
6.4
260
6.5
270
6.6Linux
278
Linux
291
7.1
292
7.2Linux
297
Linux
315
8.1
316
8.2
325
8.3
329
8.4
330
8.5Linux
336
8.6Linux
340
www.wunan.com.tw
(02)2705-5066
CLinux
359
9.1Linux
360
9.2CLinux
360
9.3CLinux
362
9.4CLinux
365
9.5CLinux
379
381
www.wunan.com.tw
(02)2705-5066
1
Linux
Linux
Linux Linux
Linux
1.1Linux
1.2Linux
1.3Linux C
1.4Linux
1.5Linux
www.wunan.com.tw
(02)2705-5066
Chapter 1Linux
1.1Linux
0 0 Andrew S.Tanenbaum
UNIX MINIX Linus
Tovalds MINIX Linux
LinuxLinus Tovalds GNU
GNU GPL, General Public License GNU
Linux
Linux
Linux
IBMCOMPAQHPOracleSybaseInformix Linux
Linux Linux
UNIX POSIX
1. Linux
Linux 1-1
VFS
Ext2
1-1Linux
Linux
www.wunan.com.tw
(02)2705-5066
1.1Linux
Linux MMU
Linux VFS
openclosereadwrite chmod
Linux 11
Linux Linux
KB MB
Linux Linux
Linux
Linux
Linux
(1)
Linux
Linux
(2)
Linux GNU
GNU GPL
Linux
www.wunan.com.tw
(02)2705-5066
Chapter 1Linux
Linux Linux
Linux
(3)
Linux xARMMIPSALPHA PowerPC
Linux
Linux
MMU
Linux
(4)
Linux Linux
Linux
(5)
In-Circuit EmulatorICE
Linux
Linux
tool chain
(6)
Linux Internet Internet
Linux
www.wunan.com.tw
(02)2705-5066
1.1Linux
NFS
Linux ExtFAT
romfs
(7) UNIX
Linux UNIX
Linux Linux
2. Linux
Linux x.yy.zz
x 0
yy 0
zz 0
pNN
NN 0 0
Linux x.yy.zz x yy
3. Linux
Linus Linux Linux
Linux
Linux
Red HatCalderaUbuntu SUSE Linux
Linux Linux
www.wunan.com.tw
(02)2705-5066
Chapter 1Linux
1.2Linux
Linux
Linux
Linux Linux
Linux
1. Linux
Linux
(1)
() Linux
()
() QoS
2. CLinux
CLinux Linux.0 Linux
MMU ARMTDMIColdfire Linux
CLinux Linux Linux
MMU
MMU MMU
CLinux Linux .0
CLinux Linux
www.wunan.com.tw
(02)2705-5066
1.2Linux
romfs Superblock romfs
RAMDISK
CLinux
NOR FLASH JFFS JFFS NAND FLASH
YAFFS MTD
vfork() CLinux
Linux vfork() fork()
Linux CLinux
CLinux
Linux CLinux
CLinux
CLinux
CLinux
3. RT-Linux RTAI
Linux
RT-LinuxRT-Linux
Linux
Linux Linux
RT-Linux 1-
www.wunan.com.tw
(02)2705-5066
Chapter 1Linux
RTLinux
RTLinux
Linux
RT-Linux
1-2RT-Linux
RT-Linux
Linux Linux RT-Linux
Linux
RT-Linux
Linux
Linux
Linux
www.wunan.com.tw
(02)2705-5066
1.2Linux
Linux
RT-Linux
10ms
RT-Linux
Linux
Linux
RT-Linux
Linux RT-Linux
Linux RTAI
Linux
Linux Linux
Linux
4. Kurt-Linux
Kurt-Linux micro second
RT-Linux
Linux Kurt-Linux
Linux
Linux
Kurt-Linux Linux
www.wunan.com.tw
(02)2705-5066
Chapter 1Linux
Kurt-Linux TD
KurtLinux
5. RED-Linux
RED-Linux Irvine Linux
Linux Time-DrivenPriority-Dirven
Share-Driven
RED-Linux RT-Linux
RED-Linux
Linux
RED-Linux Linux
RED-Linux
(1) Priority
() Start-Time
() Finish-Time
() Budget
RED-Linux
Schedule Allocator job Schedule Dispatcher
10
www.wunan.com.tw
(02)2705-5066
1.3Linux C
job job
1.3Linux C
1. Linux C
Linux C gcc
C/C++ Linux C C++
inline
C
struct
struct student{
......
};
C
student S;
gcc C
struct student S;
Linux C
Linux
2. Linux
Intel gcc AT&T
(1)
(a)
www.wunan.com.tw 11
(02)2705-5066
Chapter 1Linux
AT&T %%eax
(b)
AT&T Intel
Intel mov ebx,eax AT&T movl %eax,%ebx
(c)
AT&T $movl $_value,%ebx Intel
mov eax,_value _value eax
(d)
AT&T l
w 1 b
movw %ax,%bx
(e)
AT&T Intel
[]%eax
(f)
AT&T Intel
AT&T: _variable(%eax) Intel: [eax + _variable]
AT&T: _array(,%eax,4) Intel: [eax*4 + _array]
AT&T: _array(%ebx,%eax,8)Intel: [ebx + eax*8 + _array]
(2) C
asm("statements")
asm("nop"); asm("cli")
12
www.wunan.com.tw
(02)2705-5066
1.4Linux
asm("pushl %eax\n\t"
"movl $0,%eax\n\t"
"popl %eax");
gcc asm(...)
asm("movl %eax,%ebx");
asm("xorl %ebx,%edx");
asm("movl $0,_booga);
(3) C
Watcom
asm ("statements": output_regs: input_regs: clobbered_regs);
clobbered_regs
1.4Linux
www.wunan.com.tw 13
(02)2705-5066
Chapter 1Linux
1. Linux
struct student_struct {
student_struct *next, *prev;//
char name[NAME_SIZE]; //
int age;
//
int sex;
//
......
};
Linux
Linux linux/list.h
list_head 1-
struct list_head
{
struct list_head *next, *prev;
};
struct head_list
prevnext
next prev
list_head
14
www.wunan.com.tw
(02)2705-5066
1.4Linux
list_head student_struct
struct student_struct{
char name[NAME_SIZE];
int age;
int sex;
......
};
list_head
list
struct student_struct{
char name[NAME_SIZE];
int age;
int sex;
struct list_head list;
// list_head
......
};
struct student_struct
name[]
age
sex
list
prevnext
1-4student_struct
head_list
www.wunan.com.tw 15
(02)2705-5066
Chapter 1Linux
1- head_list
struct student_struct
struct student_struct
struct student_struct
name[]
name[]
name[]
age
age
age
sex
sex
sex
prevnext
prevnext
prevnext
1-5student_struct
2.
student_struct
struct student_struct{
char name[NAME_SIZE];
int age;
int sex;
struct list_head list;
// list_head
......
};
student_struct student_list
(1) Linux LIST_HEAD()
Linux linux/list.h
LIST_HEAD()
#define LIST_HEAD_INIT(name) {&(name), &(name)}
#define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)
16
www.wunan.com.tw
(02)2705-5066
1.4Linux
LIST_HEAD(student_list) student_list
next prev 1-
struct list_head student_list
prevnext
1-6
LIST_HEAD() Linux
INIT_LIST_HEAD()
linux/list.h
#define INIT_LIST_HEAD(ptr) do { \
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
} while (0)
(2)
__list_add()
www.wunan.com.tw 17
(02)2705-5066
Chapter 1Linux
static inline void __list_add(
struct list_head *new,
//
//
// next
)
{
next->prev = new;
new->next = next;
new->prev = prev;
prev->next = new;
}
new
student_struct student_node student_list
list_add(&student_node.list, &student_list);
student_list student_node
list student_node
list student_node
static inline void list_add_tail (struct list_head *new, struct list_head *head);
3.
(1)
list list
list list list
Linux list_entry()
18
www.wunan.com.tw
(02)2705-5066
1.4Linux
#define list_entry(ptr, type, member) \
container_of(ptr, type, member)
linux/kernel.h container_of()
#define container_of(ptr, type, member) ({
ptr list_head
type member list_head
student_list student_struct
list_entry
www.wunan.com.tw 19
(02)2705-5066
Chapter 1Linux
student_node
(struct student_struct *)0
name[]
age
offsetof(struct student_struct.list)
((struct student_struct *)0)->list
sex
prevnext
1-7offsetof()
(2) traversable
list_for_each()
include/linux/list.h list_for_each()
#define list_for_each(pos, head) \
for (pos = (head)->next; prefetch(pos->next), pos != (head); \
pos = pos->next)
list_for_each() (struct
list_head *) i list_for_each(i,&student_list)
list_for_each(i, & student_list) {
struct student_struct *ops = (struct student_struct *)i;
......
}
......
20
www.wunan.com.tw
(02)2705-5066
1.4Linux
list_for_each() list_entry() Linux list_for_each_
entry()
#define list_for_each_entry(pos, head, member)
......
4.
(1)
entry
(2)
list
head
static inline void list_move (struct list_head *list, struct list_head *head);
list
head
static inline void list_move_tail (struct list_head *list, struct list_head *head);
www.wunan.com.tw 21
(02)2705-5066
Chapter 1Linux
(3)
0
0
static inline int list_empty (struct list_head *head);
(4)
list head
static inline void list_splice (struct list_head *list, struct list_head *head);
list head
static inline void list_splice_init (struct list_head *list, struct list_head *head);
5. hlist
Linux next prev HASH
HASH hlist
1-
head
(a)
head
(b)
1-8
22
www.wunan.com.tw
(02)2705-5066
1.5Linux
hlist
HASH
include/linux/list.h hlist
struct hlist_head {
struct hlist_node *first;
};
struct hlist_node {
struct hlist_node *next, **pprev;
};
first
list_add() hlist prev
next first
struct list_head **pprev *(node>pprev) next first
1.5Linux
Linux
1.
Linux
www.wunan.com.tw 23
(02)2705-5066
Chapter 1Linux
Linux C Hello.
c
#include<linux/module.h>
MODULE_LICENSE("GPL");
MODULE_LICENSE("GPL") GNU
Makefile
Makefile
#Makefile******************************************
obj-m := hello.o
KERNELBUILD :=/lib/modules/$(shell uname -r)/build
1-
1-9 C Makefile
24
www.wunan.com.tw
(02)2705-5066
1.5Linux
Linux make
$ make
C ko 1-10
1-10
insmod
$ sudo insmod hello.ko
www.wunan.com.tw 25
(02)2705-5066
Chapter 1Linux
hello
1-11
rmmod hello
Linux
module_init() module_exit()
module_init module_exit
26
www.wunan.com.tw
(02)2705-5066
1.5Linux
__init __exit
1-1 hello_init()
hello_exit()
hello_init() Hello World!Bye World!
printk printf
(1)
#include<linux/module.h>
#include<linux/kernel.h>
MODULE_LICENSE("GPL");
static int __init hello_init(void)
{
printk(KERN_ALERT "Hello World!\n");
return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_ALERT "Bye World!\n");
}
module_init(hello_init);
module_exit(hello_exit);
#Makefile******************************************
obj-m := Hello_mod.o
KERNELBUILD :=/lib/modules/$(shell uname -r)/build
www.wunan.com.tw 27
(02)2705-5066
Chapter 1Linux
() make Hello_mod.
ko insmod dmesg printk
1-12
1-13
28
www.wunan.com.tw
(02)2705-5066
1.5Linux
modinfo
filename:
license:
srcversion:
Hello_mod.ko
GPL
5AE1900EE1F1617C327CFC7
depends:
vermagic:
2.
Linux
(1)
Linux
insmod
module_param()
module_param(name, type, perm);
1-2
www.wunan.com.tw 29
(02)2705-5066
Chapter 1Linux
#include<linux/module.h>
#include<linux/kernel.h>
#include <linux/moduleparam.h>
MODULE_LICENSE("GPL");
static const char*str="default";
module_param(str, charp, S_IRUGO);
static int __init hello_init(void)
{
printk(KERN_ALERT "%s\n",str);
return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_ALERT "Bye World!\n");
}
module_init(hello_init);
module_exit(hello_exit);
dmesg 1-1
1-14
30
www.wunan.com.tw
(02)2705-5066
1.5Linux
(2)
Linux
MODULE_AUTHOR() MODULE_DESCRIP
-TION() MODULE_VERSION
1-
#include<linux/module.h>
#include<linux/kernel.h>
#include <linux/moduleparam.h>
MODULE_LICENSE("GPL");
static const char*str="default";
module_param(str, charp, S_IRUGO);
static int __init hello_init(void)
{
printk(KERN_ALERT "%s\n",str);
return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_ALERT "Bye World!\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_AUTHOR("renzhe");
//
MODULE_DESCRIPTION("this is a module"); //
1-1
$ modinfo Hello_mod.ko
www.wunan.com.tw 31
(02)2705-5066
Chapter 1Linux
1-15
3. Linux
1-1
32
www.wunan.com.tw
(02)2705-5066
1.5Linux
export
extern
export
c
opf
jiffies
jiffies
adg
1-16
.
$ cat /proc/kallsyms | more
Linux
c010edf0 t intel_pmu_disable_all
c010eed0 t x86_pmu_read
c010eee0 t x86_pmu_start_txn
c010ef10 t x86_pmu_cancel_txn
c010ef40 t backtrace_warning_symbol
c010ef50 t backtrace_warning
c010ef60 t backtrace_stack
c010ef70 t backtrace_address
c010efd0 T perf_arch_fetch_caller_regs
c010f040 T perf_instruction_pointer
www.wunan.com.tw 33
(02)2705-5066
Chapter 1Linux
c010f070 T perf_misc_flags
c010f0d0 t p4_pmu_disable_all
c010f140 t x86_pmu_enable_all
c010f1b0 t x86_pmu_disable_all
--More--
EXPORT_SYMBOL( );
EXPORT_SYMBOL_GPL( );
EXPORT_SYMBOL_GPL() GPL
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
int add_int(int a, int b)
{
return (a + b);
}
int sub_int(int a, int b)
{
return (a - b);
}
EXPORT_SYMBOL(add_int);
EXPORT_SYMBOL(sub_int);
34
www.wunan.com.tw
(02)2705-5066
1.5Linux
insmod
$ cat /proc/kallsyms |grep add_int
f9d70034 r __ksymtab_add_int
[modadd]
f9d7004c r __kstrtab_add_int
[modadd]
f9d70040 r __kcrctab_add_int
[modadd]
6ce40a9f a __crc_add_int
[modadd]
f9d70000 T add_int
[modadd]
[modadd]
f9d70044 r __kstrtab_sub_int
[modadd]
f9d7003c r __kcrctab_sub_int
[modadd]
bb5e85f9 a __crc_sub_int
[modadd]
f9d70004 T sub_int
[modadd]
4.
strcut module strcut module
//
......
struct list_head list;
//
char name[MODULE_NAME_LEN];
//
......
const struct kernel_symbol *syms;;
//
......
const struct kernel_symbol *gpl_syms;
www.wunan.com.tw 35
(02)2705-5066
Chapter 1Linux
......
int (*init)(void);
//
......
void (*exit)(void);
//
......
};
struct kernel_symbol
{
unsigned long value;
//
//
};
kernel/linux/module.c
static LIST_HEAD(modules);
modules
export
struct module state
MODULE_STATE_LIVEMODULE_STATE_COMING MODULE_
STATE_ GOING
insmod
MODULE_STATE_COMING
(02)2705-5066
1.5Linux
modules->next name
Linux THIS_MODULE
#define THIS_MODULE (&__this_module)
Hello_mod.
c
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
unsigned int cpu = get_cpu();
struct module *mod;
printk(KERN_ALERT "this module:
%p==%p\n", &__this_module, THIS_MODULE );
printk(KERN_ALERT "module state: %d\n", THIS_MODULE->state );
printk(KERN_ALERT "module name: %s\n", THIS_MODULE->name );
list_for_each_entry(mod, *(&THIS_MODULE->list.prev), list )
printk(KERN_ALERT "module name: %s\n", mod->name );
return 0;
}
www.wunan.com.tw 37
(02)2705-5066
Chapter 1Linux
printk(KERN_ALERT "module state: %d\n", THIS_MODULE->state );
}
module_init(hello_init);
module_exit(hello_exit);
insmod dmesg
38
www.wunan.com.tw
(02)2705-5066
1.5Linux
[ 349.247680] module name: serio_raw
[ 349.247682] module name: parport_pc
[ 349.247683] module name: soundcore
[ 349.247685] module name: snd_page_alloc
[ 349.247686] module name: shpchp
[ 349.247688] module name: lp
[ 349.247689] module name: agpgart
[ 349.247691] module name: i2c_piix4
[ 349.247692] module name: parport
[ 349.247694] module name: mptspi
[ 349.247695] module name: mptscsih
[ 349.247699] module name: pcnet32
[ 349.247701] module name: mptbase
[ 349.247702] module name: floppy
[ 349.247704] module name: scsi_transport_spi
[ 349.247705] module name: mii
[ 349.247707] module name: vmw_pvscsi
www.wunan.com.tw 39
(02)2705-5066
D
DMAZONE_DMA69, 71
M
MTDmemory technology device
7, 373, 374
N
NFSNetwork File System5,
117, 204, 205
Binutils380
socket244, 245
flash memory
3, 6, 21, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56,
58, 59, 60, 61, 62, 65, 66, 67, 68,
69, 70, 71, 72, 73, 74, 75, 76, 77,
78, 79, 80, 81, 83, 85, 86, 88, 92,
93, 94, 95, 97, 101, 89, 101, 92,
93, 97, 103, 107, 108, 110, 113,
115, 116, 117, 136, 157, 161, 176,
180, 184, 185, 187, 188, 193, 196,
206, 207, 210, 213, 215, 217, 218,
219, 220, 222, 223, 224, 225, 227,
236, 238, 239, 241, 242, 244, 245,
246, 247, 248, 249, 250, 251, 252,
253, 254, 255, 256, 257, 258, 259,
260, 265, 270, 271, 272, 276, 280,
301, 316, 317, 318, 319, 322, 323,
326, 327, 329, 330, 343, 348, 349,
350, 359, 360, 361, 362, 363, 364,
365, 370, 372, 373, 374, 376, 377,
378, 379, 380
signal65, 95, 96, 97, 99,
www.wunan.com.tw 381
(02)2705-5066
136, 139, 142, 143, 153, 241, 244,
245, 246, 247, 248, 251, 260, 263,
264, 266, 278, 279, 280, 281, 282,
283, 284, 285, 286, 287, 288, 289,
290, 291, 292, 294, 295, 296, 297,
298, 299, 300, 301, 302, 303, 304,
305, 306, 307, 308, 309, 311, 312,
313, 318, 323, 330, 337
semaphore244, 245,
246, 247, 248, 291, 292, 297, 298,
299, 300, 301, 302, 303, 304, 305,
306, 307, 308, 311, 312, 313
ZONE_HIGHMEM
69, 73
pipe245, 270, 271,
274, 276, 278
mount375
GPL, General
Public License2
POS-IX244
In-Circuit Emulator
ICE4
critical section293
critical resource293
bad block372
ZONE_NORMOL69,
72
RAMDISK7
Superblock7, 193, 200,
201, 202, 213, 214, 215, 216, 217,
219, 220, 227, 229, 230, 239, 366,
368, 370
micro second9
382
www.wunan.com.tw
(02)2705-5066
Linux,
. ., 2012.12
ISBN 978-957-11-6942-2 ()
1.
312.54
101025633
5DF8
Linux
Linux in Embedded System
106 3 3 9 4
(02)2705-5066(02)2706-6100
http://www.wunan.com.tw
wunanwunan.com.tw
0 1 0 6 8 9 5 3
/6
(04)2223-0891(04)2223-3549
/290
(07)2358-702 (07)2350-236
2011
2 0 1 3 2
5 2 0
(02)2705-5066
www.wunan.com.tw