又见炊烟升起

导航

=熟悉《Linux设备驱动开发详解:基于最新的Linux4.0内核_宋宝华》的LINUX QEMU虚拟开发板

单板原型

基于的QEMU模拟的vexpress ARM Cortex-A9四核开发板

编译内核

Linux内核在/home/baohua/develop/linux目录中,在该目录下面,包含内核编译脚本:
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabi-
make LDDD3_vexpress_defconfig
make zImage -j8 
make modules -j8 
make dtbs
cp arch/arm/boot/zImage extra/
cp arch/arm/boot/dts/*ca9.dtb   extra/
cp .config extra/

由此可见,我们用的默认内核配置文件是LDDD3_vexpress_defconfig。
在源代码的根目录下会得到未压缩的内核映像vmlinux和内核符号表文件System.map, 在arch/arm/boot/目录下会得到压缩的内核映像zImage, 在内核各对应目录内得到选中的内核模块。
上述脚本也会自动将编译好的zImage和dtbs复制到extra目录中,即:

baohua@baohua-VirtualBox:~/develop$ find . -name zImage |xargs ls -al
-rwxrwxr-x 1 baohua baohua 3436008 2月 5 2020 ./linux/arch/arm/boot/zImage
-rwxrwxr-x 1 baohua baohua 3436008 2月 5 2020 ./linux/extra/zImage
baohua@baohua-VirtualBox:~/develop$ find . -name vexpress-v2p-ca9.dtb|xargs ls -al
-rw-rw-r-- 1 baohua baohua 14112 2月 5 2020 ./linux/arch/arm/boot/dts/vexpress-v2p-ca9.dtb
-rw-rw-r-- 1 baohua baohua 14112 2月 5 2020 ./linux/extra/vexpress-v2p-ca9.dtb

文件系统

extra目录下的vexpress.img是一张虚拟的SD卡,将作为根文件系统的存放介质。它能以loop的形式被挂载(mount).

sudo mount -o loop,offset=$((2048*512)) extra/vexpress.img extra/img

编译内核模块

/home/baohua/develop/linux/module.sh编译模块的脚本,它会自动编译内核模块并安装到vexpress.img中,其内容如下:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules
sudo mount -o loop,offset=$((2048*512)) extra/vexpress.img extra/img
sudo make ARCH=arm modules_install INSTALL_MOD_PATH=extra/img
sudo umount extra/img

单板的启动

运行extra下面的 run-nolcd.sh :

cd /home/baohua/develop/linux/extra
./run-nolcd.sh

其内容如下,可以启动一个不含LCD的ARM Linux。run-nolcd.sh的内容为

qemu-system-arm -nographic -sd vexpress.img -M vexpress-a9 -m 512M -kernel zImage -dtb vexpress-v2p-ca9.dtb -smp 4 -append "init=/linuxrc root=/dev/mmcblk0p1 rw rootwait earlyprintk console=ttyAMA0" 2>/dev/null

qemu单板和vmware之间传递文件

单板的基本信息

# lsmod
Module                  Size  Used by    Not tainted
# cat cpuinfo
processor	: 0
model name	: ARMv7 Processor rev 0 (v7l)
BogoMIPS	: 364.44
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpd32 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc09
CPU revision	: 0

processor	: 1
model name	: ARMv7 Processor rev 0 (v7l)
BogoMIPS	: 104.34
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpd32 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc09
CPU revision	: 0

processor	: 2
model name	: ARMv7 Processor rev 0 (v7l)
BogoMIPS	: 2.43
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpd32 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc09
CPU revision	: 0

processor	: 3
model name	: ARMv7 Processor rev 0 (v7l)
BogoMIPS	: 380.92
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpd32 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc09
CPU revision	: 0

Hardware	: ARM-Versatile Express
Revision	: 0000
Serial		: 0000000000000000
# 
# cat meminfo
MemTotal:         513064 kB
MemFree:          502088 kB
MemAvailable:     499808 kB
Buffers:              64 kB
Cached:             1400 kB
SwapCached:            0 kB
Active:             1360 kB
Inactive:            204 kB
Active(anon):        100 kB
Inactive(anon):        0 kB
Active(file):       1260 kB
Inactive(file):      204 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 4 kB
Writeback:             0 kB
AnonPages:           100 kB
Mapped:             1032 kB
Shmem:                 0 kB
Slab:               4548 kB
SReclaimable:       1132 kB
SUnreclaim:         3416 kB
KernelStack:         368 kB
PageTables:           28 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:      256532 kB
Committed_AS:        612 kB
VmallocTotal:    1548288 kB
VmallocUsed:      174728 kB
VmallocChunk:    1212448 kB
CmaTotal:              0 kB
CmaFree:               0 kB
# cat mounts
/dev/root / ext2 rw,relatime,errors=continue 0 0
devtmpfs /dev devtmpfs rw,relatime,size=256400k,nr_inodes=64100,mode=755 0 0
nodev /proc proc rw,relatime 0 0
nodev /sys sysfs rw,relatime 0 0
nodev /tmp tmpfs rw,relatime 0 0
nodev /sys/kernel/debug debugfs rw,relatime 0 0
nodev /dev/pts devpts rw,relatime,mode=600 0 0
# uname -a
Linux (none) 4.0.0-rc1+ #6 SMP Wed Feb 5 14:29:53 CST 2020 armv7l GNU/Linux
# cat /proc/cmdline 
init=/linuxrc root=/dev/mmcblk0p1 rw rootwait earlyprintk console=ttyAMA0
# cd /proc
# cat interrupts 
           CPU0       CPU1       CPU2       CPU3       
 16:      73175      73036      73085      73107       GIC  29  twd
 17:          9          0          0          0       GIC  34  timer
 31:          0          0          0          0       GIC  47  eth0
 34:        888        215        111         90       GIC  41  mmci-pl18x (cmd)
 35:       5443       5690       5762       5512       GIC  42  mmci-pl18x (pio)
 36:          8          0          0          0       GIC  44  kmi-pl050
 37:        100          1          0          0       GIC  45  kmi-pl050
 38:       1492       1930        115         57       GIC  37  uart-pl011
 44:          0          0          0          0       GIC  36  rtc-pl031
IPI0:          0          1          1          1  CPU wakeup interrupts
IPI1:          0          0          0          0  Timer broadcast interrupts
IPI2:        288        255        283        324  Rescheduling interrupts
IPI3:          0          1          1          1  Function call interrupts
IPI4:          0          0          0          0  Single function call interrupts
IPI5:          0          0          0          0  CPU stop interrupts
IPI6:          0          0          0          0  IRQ work interrupts
IPI7:          0          0          0          0  completion interrupts
Err:          0
# cat devices 
Character devices:
  1 mem
  2 pty
  3 ttyp
  4 /dev/vc/0
  4 tty
  5 /dev/tty
  5 /dev/console
  5 /dev/ptmx
  7 vcs
 10 misc
 13 input
 14 sound
 29 fb
 90 mtd
116 alsa
128 ptm
136 pts
180 usb
189 usb_device
204 ttyAMA
253 usbmon
254 rtc

Block devices:
259 blkext
  8 sd
 31 mtdblock
 65 sd
 66 sd
 67 sd
 68 sd
 69 sd
 70 sd
 71 sd
128 sd
129 sd
130 sd
131 sd
132 sd
133 sd
134 sd
135 sd
179 mmc
254 virtblk
# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                45.5M     27.2M     16.0M  63% /
devtmpfs                250.4M         0    250.4M   0% /dev
nodev                   250.5M         0    250.5M   0% /tmp
# fdisk -l

Disk /dev/mtdblock0: 134 MB, 134217728 bytes
255 heads, 63 sectors/track, 16 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/mtdblock0 doesn't contain a valid partition table

Disk /dev/mmcblk0: 50 MB, 50331648 bytes
31 heads, 24 sectors/track, 132 cylinders
Units = cylinders of 744 * 512 = 380928 bytes

        Device Boot      Start         End      Blocks  Id System
/dev/mmcblk0p1               3         133       48128  83 Linux
Partition 1 has different physical/logical beginnings (non-Linux?):
     phys=(0, 32, 33) logical=(2, 23, 9)
Partition 1 has different physical/logical endings:
     phys=(6, 30, 24) logical=(132, 3, 24)
# lsblk
-/bin/sh: lsblk: not found
# iotop
-/bin/sh: iotop: not found
# ps 
  PID USER       VSZ STAT COMMAND
    1 root      1672 S    init
    2 root         0 SW   [kthreadd]
    3 root         0 SW   [ksoftirqd/0]
    5 root         0 SW<  [kworker/0:0H]
    6 root         0 SW   [kworker/u8:0]
    7 root         0 SW   [rcu_sched]
    8 root         0 SW   [rcu_bh]
    9 root         0 SW   [migration/0]
   10 root         0 SW   [migration/1]
   11 root         0 SW   [ksoftirqd/1]
   12 root         0 SW   [kworker/1:0]
   13 root         0 SW<  [kworker/1:0H]
   14 root         0 SW   [migration/2]
   15 root         0 SW   [ksoftirqd/2]
   16 root         0 SW   [kworker/2:0]
   17 root         0 SW<  [kworker/2:0H]
   18 root         0 SW   [migration/3]
   19 root         0 SW   [ksoftirqd/3]
   20 root         0 SW   [kworker/3:0]
   21 root         0 SW<  [kworker/3:0H]
   22 root         0 SW<  [khelper]
   23 root         0 SW   [kdevtmpfs]
   24 root         0 SW   [kworker/u8:1]
   26 root         0 SW<  [perf]
   47 root         0 SW   [kworker/1:1]
  279 root         0 SW   [khungtaskd]
  280 root         0 SW<  [writeback]
  282 root         0 SW<  [kintegrityd]
  283 root         0 SW<  [bioset]
  284 root         0 SW<  [kblockd]
  291 root         0 SW<  [ata_sff]
  409 root         0 SW<  [rpciod]
  424 root         0 SW   [kswapd0]
  425 root         0 SW   [kworker/3:2]
  472 root         0 SW   [fsnotify_mark]
  486 root         0 SW<  [nfsiod]
  511 root         0 SW   [kworker/2:1]
  593 root         0 SW   [kworker/0:1]
  599 root         0 SW<  [kpsmoused]
  601 root         0 SW   [kworker/0:2]
  663 root         0 SW   [mmcqd/0]
  682 root         0 SW<  [deferwq]
  713 root      1676 S    -/bin/sh
  721 root      1676 R    ps
# busybox --help
BusyBox v1.18.5 (2014-12-01 10:44:09 CST) multi-call binary.
Copyright (C) 1998-2009 Erik Andersen, Rob Landley, Denys Vlasenko
and others. Licensed under GPLv2.
See source distribution for full notice.

Usage: busybox [function] [arguments]...
   or: busybox --list[-full]
   or: function [arguments]...

	BusyBox is a multi-call binary that combines many common Unix
	utilities into a single executable.  Most people will create a
	link to busybox for each function they wish to use and BusyBox
	will act like whatever it was invoked as.

Currently defined functions:
	[, [[, acpid, addgroup, adduser, adjtimex, ar, arp, arping, ash, awk,
	base64, basename, beep, blkid, blockdev, bootchartd, brctl, bunzip2,
	bzcat, bzip2, cal, cat, catv, chat, chattr, chgrp, chmod, chown,
	chpasswd, chpst, chroot, chrt, chvt, cksum, clear, cmp, comm, cp, cpio,
	crond, crontab, cryptpw, cttyhack, cut, date, dc, dd, deallocvt,
	delgroup, deluser, depmod, devmem, df, dhcprelay, diff, dirname, dmesg,
	dnsd, dnsdomainname, dos2unix, du, dumpkmap, dumpleases, echo, ed,
	egrep, eject, env, envdir, envuidgid, ether-wake, expand, expr,
	fakeidentd, false, fbset, fbsplash, fdflush, fdformat, fdisk,
	fgconsole, fgrep, find, findfs, flock, fold, free, freeramdisk, fsck,
	fsck.minix, fsync, ftpd, ftpget, ftpput, fuser, getopt, getty, grep,
	gunzip, gzip, halt, hd, hdparm, head, hexdump, hostid, hostname, httpd,
	hush, hwclock, id, ifconfig, ifdown, ifenslave, ifplugd, ifup, inetd,
	init, insmod, install, ionice, iostat, ip, ipaddr, ipcalc, ipcrm, ipcs,
	iplink, iproute, iprule, iptunnel, kbd_mode, kill, killall, killall5,
	klogd, last, length, less, linux32, linux64, linuxrc, ln, loadfont,
	loadkmap, logger, login, logname, logread, losetup, lpd, lpq, lpr, ls,
	lsattr, lsmod, lspci, lsusb, lzcat, lzma, lzop, lzopcat, makedevs,
	makemime, man, md5sum, mdev, mesg, microcom, mkdir, mkdosfs, mkfifo,
	mkfs.minix, mkfs.vfat, mknod, mkpasswd, mkswap, mktemp, modinfo,
	modprobe, more, mount, mountpoint, mpstat, msh, mt, mv, nameif,
	nbd-client, nc, netstat, nice, nmeter, nohup, nslookup, ntpd, od,
	openvt, passwd, patch, pgrep, pidof, ping, ping6, pipe_progress,
	pivot_root, pkill, pmap, popmaildir, poweroff, powertop, printenv,
	printf, ps, pscan, pwd, raidautorun, rdate, rdev, readahead, readlink,
	readprofile, realpath, reboot, reformime, renice, reset, resize, rev,
	rm, rmdir, rmmod, route, rtcwake, run-parts, runlevel, runsv, runsvdir,
	rx, script, scriptreplay, sed, sendmail, seq, setarch, setconsole,
	setfont, setkeycodes, setlogcons, setsid, setuidgid, sh, sha1sum,
	sha256sum, sha512sum, showkey, slattach, sleep, smemcap, softlimit,
	sort, split, start-stop-daemon, stat, strings, stty, su, sulogin, sum,
	sv, svlogd, swapoff, swapon, switch_root, sync, sysctl, syslogd, tac,
	tail, tar, tcpsvd, tee, telnet, telnetd, test, tftp, tftpd, time,
	timeout, top, touch, tr, traceroute, traceroute6, true, tty, ttysize,
	tunctl, udhcpc, udhcpd, udpsvd, umount, uname, uncompress, unexpand,
	uniq, unix2dos, unlzma, unlzop, unxz, unzip, uptime, usleep, uudecode,
	uuencode, vconfig, vi, vlock, volname, wall, watch, watchdog, wc, wget,
	which, who, whoami, xargs, xz, xzcat, yes, zcat, zcip
# i2cdetect -l
-/bin/sh: i2cdetect: not found
# find /etc/init.d
/etc/init.d
/etc/init.d/rcS
# cat /etc/init.d/rcS 
#!/bin/sh
mount -n -t proc nodev /proc
mount -n -t sysfs nodev /sys
mount -n -t tmpfs nodev /tmp
mount -n -t debugfs nodev /sys/kernel/debug
mkdir /dev/pts && mount -n -t devpts nodev /dev/pts
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
cat /etc/motd

posted on 2023-09-23 23:42  ni_sy  阅读(29)  评论(0编辑  收藏  举报