qemu+u-boot在镜像中读取内核启动

该博客详细介绍了如何使用QEMU和U-Boot从磁盘镜像启动内核及根文件系统的步骤。首先,通过dd命令创建一个64M的空磁盘,然后使用fdisk进行分区,接着利用kpartx刷新分区并格式化。随后,将内核、设备树和根文件系统分别拷贝到对应的分区,并在U-Boot中加载内核和设备树,设置启动参数。最后,使用qemu-system-arm启动U-Boot。
摘要由CSDN通过智能技术生成

qemu+u-boot在镜像中读取内核启动

u-boot,内核,根文件系统过程就不介绍了。

Step 0 预备

下载kpartx ,路径: [http://ftp.sjtu.edu.cn/ubuntu/pool/main/m/multipath-tools/], 当前用的kpartx_0.4.9-3ubuntu5.3_amd64.deb这个版本可用,更新的版本没有尝试, 最新的版本ubuntu14.04无法安装(依赖不满足)。

Step 1 创建空磁盘

这里先创建一个64M的:

dd if=/dev/zero of=./mmc bs=1M count=64

Step2 对空磁盘进行分区

可以参考博客:[https://www.cnblogs.com/pengdonglin137/p/3549585.html]。

sudo losetup /dev/loop0 mmc.ext4
sudo fdisk /dev/loop0

分区情况:

➜  tmp sudo fdisk /dev/loop0
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x77978d12.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
Using default value 1
First sector (2048-131071, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-131071, default 131071): +2M

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): e
Partition number (1-4, default 2): 
Using default value 2
First sector (6144-131071, default 6144): 
Using default value 6144
Last sector, +sectors or +size{K,M,G} (6144-131071, default 131071): 
Using default value 131071

Command (m for help): n
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (8192-131071, default 8192): 
Using default value 8192
Last sector, +sectors or +size{K,M,G} (8192-131071, default 131071): +8M

Command (m for help): n
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 6
First sector (26624-131071, default 26624): 
Using default value 26624
Last sector, +sectors or +size{K,M,G} (26624-131071, default 131071): 
Using default value 131071

Command (m for help): p

Disk /dev/loop0: 67 MB, 67108864 bytes
255 heads, 63 sectors/track, 8 cylinders, total 131072 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x77978d12

      Device Boot      Start         End      Blocks   Id  System
/dev/loop0p1            2048        6143        2048   83  Linux
/dev/loop0p2            6144      131071       62464    5  Extended
/dev/loop0p5            8192       24575        8192   83  Linux
/dev/loop0p6           26624      131071       52224   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 22: Invalid argument.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

利用kpartx刷新分区:

sudo kpartx -av /dev/loop0
➜  tmp sudo kpartx -av /dev/loop0
add map loop1p1 (252:4): 0 4096 linear /dev/loop0 2048
add map loop1p2 (252:5): 0 2 linear /dev/loop0 6144
add map loop1p5 : 0 16384 linear /dev/loop0 8192
add map loop1p6 : 0 104448 linear /dev/loop0 26624

格式化分区:

sudo mkfs.ext4 /dev/mapper/loop0p1
sudo mkfs.ext4 /dev/mapper/loop0p5
sudo mkfs.ext4 /dev/mapper/loop0p6

Step 3 拷贝内核和设备树到分区

mkdir ttt
sudo mount /dev/mapper/loop0p5 ttt/
sudo cp img/uImage  ttt/
sudo cp img/vexpress-v2p-ca9.dtb  ttt/
sudo umount ttt/

Step 4 拷贝根文件系统文件到分区

sudo mount /dev/mapper/loop0p6 ttt/
sudo cp -arpf ~/mwork/busybox/rootfs/* ttt/
sudo umount ttt/
rm ttt
sudo losetup -d /dev/loop0

Step 5 qemu起u-boot

#!/bin/sh

qemu-system-arm -M vexpress-a9 -m 1024M -kernel u-boot --nographic -append "console=ttyAMA0" -sd mmc.ext4

在u-boot输入命令起内核:

ext4load mmc 0:5 0x60400000 uImage
ext4load mmc 0:5 0x60800000 vexpress-v2p-ca9.dtb
setenv bootargs root=/dev/mmcblk0p6 init=/linuxrc  console=ttyAMA0,38400n8
bootm 0x60400000 - 0x60800000
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值