https://blog.csdn.net/skyleemon/article/details/78360241
guang@guang-kylin:~/Develop/linux-stable$ git branch
* master
guang@guang-kylin:~/Develop/linux-stable$ vi Makefile
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:”%”=%)
修改为:
ARCH ?= arm
CROSS_COMPILE ?= arm-linux-gnueabi-
make vexpress_defconfig
make zImage
make modules
make dtbs
zImage生成路径:
arch/arm/boot/zImage
modules生成路径:
drivers/video/backlight/*.ko
dtbs生成路径:
arch/arm/boot/dts/vexpress-v2p-ca9.dtb
guang@guang-kylin:~/Develop/linux-stable$ qemu-system-arm -M vexpress-a9 -m 512M -kernel arch/arm/boot/zImage -dtb arch/arm/boot/dts/vexpress-v2p-ca9.dtb -nographic -append “console=ttyAMA0”
/****************************************************************/
pulseaudio: set_sink_input_volume() failed
pulseaudio: Reason: Invalid argument
pulseaudio: set_sink_input_mute() failed
pulseaudio: Reason: Invalid argument
Booting Linux on physical CPU 0x0
Linux version 4.17.0+ (guang@guang-kylin) (gcc version 7.3.0 (Ubuntu/Linaro 7.3.0-16ubuntu3)) #1 SMP Mon Jun 11 05:05:41 CST 2018
……// 省略了很多打印信息
VFS: Cannot open root device “(null)” or unknown-block(0,0): error -6
Please append a correct “root=” boot option; here are the available partitions:
1f00 131072 mtdblock0
(driver?)
1f01 32768 mtdblock1
(driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.17.0+ #1
Hardware name: ARM-Versatile Express
[<8011074c>] (unwind_backtrace) from [<8010cd4c>] (show_stack+0x10/0x14)
[<8010cd4c>] (show_stack) from [<80694dd4>] (dump_stack+0x88/0x9c)
[<80694dd4>] (dump_stack) from [<8011ff6c>] (panic+0xf0/0x25c)
[<8011ff6c>] (panic) from [<80901588>] (mount_block_root+0x1ec/0x2d8)
[<80901588>] (mount_block_root) from [<809017b8>] (mount_root+0x144/0x160)
[<809017b8>] (mount_root) from [<80901924>] (prepare_namespace+0x150/0x198)
[<80901924>] (prepare_namespace) from [<80901174>] (kernel_init_freeable+0x340/0x350)
[<80901174>] (kernel_init_freeable) from [<806a91f8>] (kernel_init+0x8/0x114)
[<806a91f8>] (kernel_init) from [<801010e8>] (ret_from_fork+0x14/0x2c)
Exception stack(0x9f48ffb0 to 0x9f48fff8)
ffa0: 00000000 00000000 00000000 00000000
ffc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
ffe0: 00000000 00000000 00000000 00000000 00000013 00000000
—[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) ]—
/****************************************************************/
CROSS_COMPILE ?= arm-linux-gnueabi-
ARCH ?= arm
make defconfig或者make menuconfig
如果是menuconfig,下图选*:
Settings —>
— Build Options
[ ] Build static binary (no shared libs)
guang@guang-kylin:~/Develop/busybox$ ls -al .config
-rw-rw-r– 1 guang guang 27083 6月 11 12:34 .config
https://blog.csdn.net/qq_36788698/article/details/76647347
https://www.cnblogs.com/PengfeiSong/p/6443149.html
https://unix.stackexchange.com/questions/120198/how-to-fix-boot-into-initramfs-prompt-and-mount-cant-read-etc-fstab-no-su
make
make install
*————————————————–
You will probably need to make your busybox binary
setuid root to ensure all configured applets will
work properly.
*————————————————–
guang@guang-kylin:~/Develop/busybox$ ls -al ./_install/
total 20
drwxrwxr-x 5 guang guang 4096 6月 11 12:49 .
drwxrwxr-x 38 guang guang 4096 6月 11 12:48 ..
drwxrwxr-x 2 guang guang 4096 6月 11 12:49 bin
lrwxrwxrwx 1 root root 11 6月 11 12:49 linuxrc -> bin/busybox
drwxrwxr-x 2 guang guang 4096 6月 11 12:49 sbin
drwxrwxr-x 4 guang guang 4096 6月 11 12:48 usr
guang@guang-kylin:~/Develop$ mkdir trainning
guang@guang-kylin:~/Develop$ cd trainning/
guang@guang-kylin:~/Develop/trainning$ mkdir rootfs
guang@guang-kylin:~/Develop/trainning$ cd rootfs/
guang@guang-kylin:~/Develop/trainning/rootfs$ mkdir lib
guang@guang-kylin:~/Develop/trainning/rootfs$ ls
lib
guang@guang-kylin:~/Develop/trainning/rootfs$ cp -r ../../busybox/_install/* ./
guang@guang-kylin:~/Develop/trainning/rootfs$ ls
bin lib linuxrc sbin usr
guang@guang-kylin:~/Develop/trainning/rootfs$ cp -p /usr/arm-linux-gnueabi/lib/* ./lib
guang@guang-kylin:~/Develop/trainning/rootfs$ mkdir dev
guang@guang-kylin:~/Develop/trainning/rootfs$ ls
bin dev lib linuxrc sbin usr
guang@guang-kylin:~/Develop/trainning/rootfs/dev$ sudo mknod -m 666 tty1 c 4 1
[sudo] password for guang:
guang@guang-kylin:~/Develop/trainning/rootfs/dev$ sudo mknod -m 666 tty2 c 4 2
guang@guang-kylin:~/Develop/trainning/rootfs/dev$ sudo mknod -m 666 tty3 c 4 3
guang@guang-kylin:~/Develop/trainning/rootfs/dev$ sudo mknod -m 666 tty4 c 4 4
guang@guang-kylin:~/Develop/trainning/rootfs/dev$ sudo mknod -m 666 console c 5 1
guang@guang-kylin:~/Develop/trainning/rootfs/dev$ sudo mknod -m 666 null c 1 3
dd if=/dev/zero of=rootfs.ext3 bs=1M count=32
mkfs.ext3 rootfs.ext3
mount -t ext3 rootfs.ext3 /mnt/ -o loop
cp -r rootfs/* /mnt
umount /mnt
guang@guang-kylin:~/Develop/trainning$ qemu-system-arm -M vexpress-a9 -m 512M -dtb ../linux-stable/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -kernel ../linux-stable/arch/arm/boot/zImage -nographic -append “root=/dev/mmcblk0 rw console=ttyAMA0” -sd rootfs.ext3
qemu-system-arm -M vexpress-a9 -m 512M -dtb ../linux-stable/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -kernel ../linux-stable/arch/arm/boot/zImage -append “root=/dev/mmcblk0 rw console=tty0” -sd rootfs.ext3
// qemu.c:
#include
#include
static int __init qemu_init (void)
{
printk (KERN_INFO"[Info]Hello! Enter QEMU.");
return 0;
}
module_init (qemu_init);
static void __exit qemu_exit (void)
{
printk (KERN_INFO"[Info]Hello! Exit QEMU.");
}
module_exit (qemu_exit);
MODULE_AUTHOR ("Guang-kylin");
MODULE_LICENSE ("GPL v2");
MODULE_DESCRIPTION ("A simple qume test module");
MODULE_ALIAS ("QEMU module");
// Makefile
KVERS = $(shell uname -r)
# Kernel modules
obj-m += qemu.o
#EXTRA_CFLAGS=-g -O0
build: kernel_modules
kernel_modules:
make -C /lib/modules/$(KVERS)/build M=$(CURDIR) modules
clean:
make -C /lib/modules/$(KVERS)/build M=$(CURDIR) clean
mount -t ext3 rootfs.ext3 /mnt/ -o loop
cp -r rootfs/* /mnt
umount /mnt
KDIR=/home/guang/Develop/linux-stable #linux代码路径,没有详细研究依赖了那些文件,全部包含了
PWD=$(shell pwd)
# Kernel modules
obj-m += qemu.o
module-objs = qemu.o
ARCH=arm
CROSS_COMPILE=arm-linux-gnueabi-
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
#EXTRA_CFLAGS=-g -O0
default:
make -C $(KDIR) M=$(PWD) modules
clean:
rm -f *.ko *.o *.mod.c *.symvers *.order
/*****/
qemu-system-arm -M vexpress-a9 -m 512M -dtb ./vexpress-v2p-ca9.dtb -kernel ./zImage -nographic -append “root=/dev/mmcblk0 rw console=ttyAMA0” -sd rootfs.ext3
/*****/
guang@guang-ubuntu:~/Develop/trainning/rootfs$ mkdir etc
guang@guang-ubuntu:~/Develop/trainning/rootfs$ cd etc
::sysinit:/etc/init.d/rcS
#::respawn:-/bin/sh
#tty2::askfirst:-/bin/sh
#::ctrlaltdel:/bin/umount -a -r
console::askfirst:-/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
proc /proc proc defaults 0 0
tmpfs /tmp tmpfs defaults 0 0
sysfs /sys sysfs defaults 0 0
tmpfs /dev tmpfs defaults 0 0
var /dev tmpfs defaults 0 0
ramfs /dev ramfs defaults 0 0
PS1='guang@arm-vexpress:\w # '
export PS1
#! /bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
LD_LIBRARY_PATH=/lib
export PATH LD_LIBRARY_PATH
mount -a
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
mdev -s
mkdir -p /var/lock
echo "-----------------------------------"
echo " welcome to A9 vexpress board"
echo "-----------------------------------"
CROSS_COMPILE ?= arm-linux-gnueabi-
ARCH := arm
make vexpress_ca9x4_defconfig
make –j4
qemu-system-arm -M vexpress-a9 -kernel u-boot -nographic -m 512M
采用桥接(bridge)的网络连接与Host通信
需要主机内核tun/tap模块支持(linux17.04以后的版本都支持了,不支持的老版本需要自己创建,我安装的ubuntu是18.04,故已经有了这个模块)
apt install uml-utilities bridge-utils
auto enp0s3
auto br0
iface br0 inet dhcp
bridge_ports enp0s3
guang@guang-ubuntu:~$ ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::a00:27ff:fe6e:98c6 prefixlen 64 scopeid 0x20
ether 08:00:27:6e:98:c6 txqueuelen 1000 (Ethernet)
RX packets 156 bytes 346295 (346.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 229 bytes 27996 (27.9 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 08:00:27:6e:98:c6 txqueuelen 1000 (Ethernet)
RX packets 374 bytes 360251 (360.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 229 bytes 28436 (28.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 62 bytes 5127 (5.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 62 bytes 5127 (5.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
guang@guang-ubuntu:~$
make LOADADDR=0x60003000 uImage -j4
apt-get install tftp-hpa tftpd-hpa xinetd
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/home/guang/Develop/trainning/tftpboot"
TFTP_ADDRESS="0.0.0.0:69"
# TFTP_OPTIONS="--secure"
TFTP_OPTIONS="-l -c -s"
guang@guang-ubuntu:~/Develop/trainning$ mkdir tftpboot
guang@guang-ubuntu:~/Develop/trainning$ chmod +rwx tftpboot
guang@guang-ubuntu:~/Develop/trainning$ cd tftpboot/
guang@guang-ubuntu:~/Develop/trainning/tftpboot$ pwd
/home/guang/Develop/trainning/tftpboot
guang@guang-ubuntu:~/Develop/trainning$ sudo /etc/init.d/tftpd-hpa restart
[ ok ] Restarting tftpd-hpa (via systemctl): tftpd-hpa.service.
/*config qemu' network*/
#define CONFIG_BOOTCOMMAND \
"tftp 0x60003000 uImage;tftp 0x60500000 vexpress-v2p-ca9.dtb; \
setenv bootargs 'root=/dev/mmcblk0 console=tty0'; \
bootm 0x60003000 - 0x60500000;"
#define CONFIG_IPADDR 10.0.2.14
#define CONFIG_NETMASK 255.255.255.0
#define CONFIG_SERVERIP 10.0.2.15