Author: WhoAmI
Date: 20220731
Copyright: CC BY-NC-SA
以下做過 才能累積經驗!!! 以後才能舉一反三
也許很煩~
其實每一個 Embedded System 都差不多!!
這是蓋房子的基礎~
怎麼編 Linux Kernel (ARM), 使用 Sourcery G++ Lite 2011.03-42 編譯 Linux Kernel for QEMU ARM Version
怎麼產生 Root Filesystem
使用
laikc@laikc-virtual-machine:~/arm$ tar xjfv busybox-1.22.0.tar.bz2
警告 注意還有一些 沒有 mount…/proc /sys 還有 /dev 沒作, 好吧後面寫了…
警告出現 & gt ; 那個是 IO 轉向的 '大於' > 的數學符號, 打不出來
我是一邊作一邊貼, 怪符號請見諒
日期我的VM 沒更新日期~~~~別管
確認 PATH /opt/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin
確認 prefix arm-none-linux-gnueabi-
先用 ARM default
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- defconfig
再來 config, 沒有 ncurse 請參考 kernel 編譯
laikc@laikc-virtual-machine:~/arm/busybox-1.22.0$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- menuconfig
需要 init (如果您需要, 我用 /bin/sh 代替, 現沒用到)
BusyBox 1.22.0 Configuration
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq Init Utilities qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
x Arrow keys navigate the menu. selects submenus –->. Highlighted letters are x
x hotkeys. Pressing includes, excludes, modularizes features. Press x
x to exit, for Help, </> for Search. Legend: [] built-in [ ] excluded x
x module < > module capable x
x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
x x [] bootchartd x x
x x [] Compatible, bloated header x x
x x [] Support bootchartd.conf x x
x x [] poweroff, halt, and reboot x x
x x [] init x x
x x [] Support reading an inittab file x x
x x [ ] Support killing processes that have been removed from inittab x x
x x [] Run commands with leading dash with controlling tty x x
x x [] Enable init to write to syslog x x
x x [] Be extra quiet on boot x x
x x [] Support dumping core for child processes (debugging only) x x
x x [] Support running init from within an initrd (not initramfs) x x
x x (linux) Initial terminal type x x
x x [*] mesg x x
x mqqqqqqqv(+)qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
x
mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
進入 Build Options –->
BusyBox 1.22.0 Configuration
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq Busybox Settings qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
x Arrow keys navigate the menu. selects submenus –->. Highlighted letters are x
x hotkeys. Pressing includes, excludes, modularizes features. Press x
x to exit, for Help, </> for Search. Legend: [*] built-in [ ] excluded x
x module < > module capable x
x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
x x General Configuration –-> x x
x x Build Options –-> x x
x x Debugging Options –-> x x
x x Installation Options ("make install" behavior) –-> x x
x x Busybox Library Tuning –-> x x
x x x x
x x x x
x x x x
x x x x
x x x x
x x x x
x x x x
x x x x
x x x x
x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
x
mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
改成 static binary (no shared libs) , 否則需要準備 libxxx.so 等, 懶人法
BusyBox 1.22.0 Configuration
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq Build Options qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
x Arrow keys navigate the menu. selects submenus –->. Highlighted letters are x
x hotkeys. Pressing includes, excludes, modularizes features. Press x
x to exit, for Help, </> for Search. Legend: [] built-in [ ] excluded x
x module < > module capable x
x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
x x [] Build BusyBox as a static binary (no shared libs) x x
x x [ ] Force NOMMU build x x
x x [*] Build with Large File Support (for accessing files > 2 GB) x x
x x () Cross Compiler prefix x x
x x () Path to sysroot x x
x x () Additional CFLAGS x x
x x () Additional LDFLAGS x x
x x () Additional LDLIBS x x
x x x x
x x x x
x x x x
x x x x
x x x x
x x x x
x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
x
mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
/*
上面 Build BusyBox as a static binary (no shared libs) 使用懶人法, **
但也可用shared libs, 您必需 於 rootfs 中產生
/lib
此路徑, 並且將 arm tools chain 裏的 libc*.so copy 至 /lib (不是您 VM 裡的 /lib !!!)
*/
laikc@laikc-virtual-machine:~/arm/busybox-1.22.0$make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- install
laikc@laikc-virtual-machine:~/arm/busybox-1.22.0$ cd _install/
laikc@laikc-virtual-machine:~/arm/busybox-1.22.0/_install$
看看 busybox header
是正確armv5te因此可進行 產生 rootfs image
我們使用 /bin/sh 代替 init … 誰說不可以呢?
/ # ls
bin dev linuxrc root sbin usr
/ #
完工, ~~~沒用 init 與 tty密碼等
/ # ps
PID USER TIME COMMAND
ps: can't open '/proc': No such file or directory
解決ProcFs問題:
/ # mkdir /proc
/ # mount -t proc none /proc
/ # ps
PID USER TIME COMMAND
1 0 0:03 /bin/sh
2 0 0:00 [kthreadd]
3 0 0:00 [ksoftirqd/0]
4 0 0:00 [watchdog/0]
5 0 0:00 [events/0]
6 0 0:00 [khelper]
9 0 0:00 [async/mgr]
91 0 0:00 [sync_supers]
93 0 0:00 [bdi-default]
95 0 0:00 [kblockd/0]
99 0 0:00 [kseriod]
101 0 0:00 [kmmcd]
118 0 0:00 [rpciod/0]
127 0 0:00 [khungtaskd]
128 0 0:00 [kswapd0]
129 0 0:00 [aio/0]
130 0 0:00 [nfsiod]
273 0 0:00 [mtdblockd]
287 0 0:00 [kpsmoused]
309 0 0:00 ps
/ #
/ # ls /dev
console
/ #
哇 …好多沒有喔, 只好 DIY
/ # mkdir /sys
/ # mount -t sysfs none /sys
/ # mdev -s
現在 出來了!!!
/ # ls /dev
console ram13 tty28 tty59
cpu_dma_latency ram14 tty29 tty6
fb0 ram15 tty3 tty60
full ram2 tty30 tty61
input ram3 tty31 tty62
kmem ram4 tty32 tty63
kmsg ram5 tty33 tty7
mem ram6 tty34 tty8
network_latency ram7 tty35 tty9
network_throughput ram8 tty36 ttyAMA0
null ram9 tty37 ttyAMA1
psaux random tty38 ttyAMA2
ptmx tty tty39 ttyp0
ptyp0 tty0 tty4 ttyp1
ptyp1 tty1 tty40 ttyp2
ptyp2 tty10 tty41 ttyp3
ptyp3 tty11 tty42 ttyp4
ptyp4 tty12 tty43 ttyp5
ptyp5 tty13 tty44 ttyp6
ptyp6 tty14 tty45 ttyp7
ptyp7 tty15 tty46 ttyp8
ptyp8 tty16 tty47 ttyp9
ptyp9 tty17 tty48 ttypa
ptypa tty18 tty49 ttypb
ptypb tty19 tty5 ttypc
ptypc tty2 tty50 ttypd
ptypd tty20 tty51 ttype
ptype tty21 tty52 ttypf
ptypf tty22 tty53 urandom
ram0 tty23 tty54 vcs
ram1 tty24 tty55 vcs1
ram10 tty25 tty56 vcsa
ram11 tty26 tty57 vcsa1
ram12 tty27 tty58 zero
以下使用 /sbin/init 當 init
––––––––––––––––––––––––––––––––––
laikc@laikc-virtual-machine:~/arm/busybox-1.22.0/_install$ pwd
/home/laikc/arm/busybox-1.22.0/_install
laikc@laikc-virtual-machine:~/arm/busybox-1.22.0/_install$
製造路徑
mkdir proc sys etc etc/init.d dev
記得一定存 unix 格式, 不知就用 vi 寫吧
把 rcS 寫好並且 chmod 改權限
放到 etc/init.d
準備 inittab
laikc@laikc-virtual-machine:~/arm/busybox-1.22.0/_install/etc$ ls
init.d inittab
laikc@laikc-virtual-machine:~/arm/busybox-1.22.0/_install/etc$
laikc@laikc-virtual-machine:~/arm/busybox-1.22.0/_install/etc$ cat inittab
放到 etc 底下
重新 製作 rootfs.img.gz
若是出現 & gt ; 那個是 IO 轉向的 '大於' > 的數學符號,
–––––––––––––––––––––––––––––––––––––––––-
開始 產生 rootfs
laikc@laikc-virtual-machine:~/arm/busybox-1.22.0/_install$ find . | cpio -o –format=newc > ../rootfs.img
4015 blocks
可以 reboot 了
/ # reboot
/ # swapoff: /etc/fstab: No such file or directory
The system is going down NOW!
Sent SIGTERM to all processes
Sent SIGKILL to all processes
Requesting system reboot
Restarting system.
Uncompressing Linux… done, booting the kernel.
Linux version 2.6.33 (laikc@laikc-virtual-machine) (gcc version 4.5.2 (Sourcery G++ Lite 2011.03-42) ) #1 Sat Jun 7 14:19:01 CST 2014
CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00093177
CPU: VIVT data cache, VIVT instruction cache
Machine: ARM-Versatile AB
Memory policy: ECC disabled, Data cache writeback
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 32512
Kernel command line: root=/dev/ram rdinit=/sbin/init console=ttyAMA0
PID hash table entries: 512 (order: -1, 2048 bytes)
Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
Memory: 128MB = 128MB total
Memory: 125680KB available (2572K code, 219K data, 100K init, 0K highmem)
Hierarchical RCU implementation.
RCU-based detection of stalled CPUs is enabled.
NR_IRQS:192
VIC @f1140000: id 0x00041190, vendor 0x41
Console: colour dummy device 80x30
Calibrating delay loop… 418.61 BogoMIPS (lpj=2093056)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
NET: Registered protocol family 16
Serial: AMBA PL011 UART driver
dev:f1: ttyAMA0 at MMIO 0x101f1000 (irq = 12) is a AMBA/PL011
console [ttyAMA0] enabled
dev:f2: ttyAMA1 at MMIO 0x101f2000 (irq = 13) is a AMBA/PL011
dev:f3: ttyAMA2 at MMIO 0x101f3000 (irq = 14) is a AMBA/PL011
bio: create slab at 0
Switching to clocksource timer3
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 4096 (order: 3, 32768 bytes)
TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
TCP reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
Trying to unpack rootfs image as initramfs…
Freeing initrd memory: 1084K
NetWinder Floating Point Emulator V0.97 (double precision)
Installing knfsd (copyright © 1996 okir@monad.swb.de).
JFFS2 version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
ROMFS MTD © 2007 Red Hat, Inc.
msgmni has been set to 247
Block layer SCSI generic (bsg) driver version 0.4 loaded (major 254)
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
CLCD: Versatile hardware, VGA display
Console: switching to colour frame buffer device 80x60
brd: module loaded
armflash.0: Found 1 x32 devices at 0x0 in 32-bit bank
Intel/Sharp Extended Query Table at 0x0031
Using buffer write method
RedBoot partition parsing not available
afs partition parsing not available
smc91x.c: v1.1, sep 22 2004 by Nicolas Pitre
eth0: SMC91C11xFD (rev 1) at c88be000 IRQ 25 [nowait]
eth0: Ethernet addr: 52:54:00:12:34:56
mice: PS/2 mouse device common for all mice
TCP cubic registered
NET: Registered protocol family 17
VFP support v0.3: not present
Freeing init memory: 100K
input: AT Raw Set 2 keyboard as /devices/fpga:06/serio0/input/input0
input: ImExPS/2 Generic Explorer Mouse as /devices/fpga:07/serio1/input/input1
Please press Enter to activate this console.
/ #