制作imx6ull Linux系统的img镜像文件(emmc烧录 )

制作imx6ull Linux系统的img镜像文件

1.什么是img镜像文件

在讲解img镜像文件之前我们要了解一般的imx6ull系列开发板烧录F方法一般有两种一种是通过通过USB刷机,用mfgtools工具将uboot kernel dtb rootfs这些文件烧写到emmc nandflash sd卡等存储介质上面,但是这种方法的缺点是烧写比较慢,而且只能一个一个刷写,官方推荐的量产烧写方式是通过SD卡刷机,就是把SD卡做成启动盘,然后启动系统,再把内容烧录到emmc或者nand flash里面。
另外一种就是通过SD卡(EMMC)进行烧录,这里介绍一种将uboot kernel dtb rootfs打包成img镜像,然后通过Win32 Disk Imager烧录的方法。

接着我们介绍一下img镜像文件,我们可以img文件可以简单理解为一个磁盘,可以存放二进制数据,可以进行分区,可以建立文件系统等操作。
一般img镜像文件分区如下表:

Start AddresssizeUsage
0x02 sectors(1K)Reserved for partition table
2 sector(K,0x400)20414 sectors(9M+)i.MX6MQ u-boot image
20480 sector (10M,0xa00000)204800 sectors(100MB)FAT32 Boot partition
225280 sector(110M,0x6e00000)Remaining SpaceEXT4 filesystem for rootfs

2.制作流程

1.使用dd 命令,根据固件的大小建立一个合适的 img 空文件。
2. 对 img 文件进行分区。
3. 用dd命令创建装载u-boot。
4. 用losetup命令将 img 文件虚拟成循环块设备 /dev/loopx ,并用 kpartx命令在/dev/mapper/下,将虚拟出的循环块设备分区并格式化。
5.创建挂载点,下面建立文件系统并且 mount 上来 。
6.使用文件复制命令cp将 zImage dtb rootfs 放到指定的文件系统分区 。
7.取消挂载,复制文件,烧录到 emmc卡。

下面开始制作img镜像

准备工作:

需要安装的软件:

sudo apt-get install dosfstools dump parted kpartx

将制作镜像需要的 zImage dtb rootfs等文件拷贝到imx6ull文件下并建立镜像文件夹:

mkdir images

在这里插入图片描述
我们先启动编译脚本编译生成内核:

./build.sh

内核编译生成后,我们进入images文件夹

开始制作镜像

首先我们用先创建一个空的img文件:

dd if=/dev/zero of=linuxsys_iMX6ULL_512MB.img bs=512k count=1024  && sync

of=linuxsys_iMX6ULL_512MB.img 表示输出文件为 linuxsys_iMX6ULL_512MB.img
bs=512 扇区是 512 字节
count=1024 表示扇区的数量
sync 是用于将内容直接写入磁盘
到这里我们的空镜像文件就已经创建好了

接下来我们根据分区表进行分区

    parted linuxsys_iMX6ULL_512MB.img mklabel msdos
    parted linuxsys_iMX6ULL_512MB.img mkpart primary fat32 10M 110M
    parted linuxsys_iMX6ULL_512MB.img mkpart primary ext4 110M 100%
	
	sync

fat32 文件系统类型为 fat32 这是内核设备树的文件系统
10M 这个表示内核设备树扇区的起始地址(注意不是实际地址,扇区地址x扇区大小=实际地址),这个分区紧跟在 10M 的 u-boot 空间后面
110M内核设备树扇区的结束地址=扇区起始地址+扇区大小-1,

ext4 文件系统为 ext4 这是根文件系统的
110M 文件系统的扇区起始地址,100%为文件系统的结束地址剩余内存,也可以不填。

接下来安装u-boot

sudo dd if=`pwd`/../bin//u-boot-imx6ull-14x14-ddr512-emmc.imx of=linuxsys_iMX6ULL_512MB.img bs=1k seek=1 conv=notrunc,sync

将img文件虚拟成块设备

 losetup /dev/loop0 linuxsys_iMX6ULL_512MB.img

这里的loop0如果被占用,那么可以用losetup -f 查找空闲的循环设备

将虚拟成的块设备分区

 kpartx -av /dev/loop0

被分区后的设备在/dev/mapper/路径下

接着我们将分区格式化

mkfs.vfat  /dev/mapper/loop0p1
mkfs.ext4 /dev/mapper/loop0p2
    
sync

格式化后,创建分区对应的挂载点,将分区挂载起来以便于拷贝内核和根文件系统

#创建内核挂载点
mkdir -p sd1 
#将内核分区挂载到对应的挂载点
mount -t vfat /dev/mapper/loop0p1 sd1
#拷贝内核
cp `pwd`/../tarballs/zImage sd1
cp `pwd`/../tarballs//imx6ull-xly-emmc-lcd.dtb   sd1

sync

#卸载挂载点
umount sd1
#删除sd1
rm -rf sd1

接着和上面一样,移植根文件系统

mkdir -p sd2
mount -t ext4 /dev/mapper/loop0p2 sd2

tar -xjf `pwd`/../tarballs//rootfs.tar.bz2 -C sd2 && sync

umount sd2
rm -rf sd2

接着我们要将刚才的虚拟和分区,卸载还原

kpartx -dv /dev/loop0
losetup -d /dev/loop0

最后我们将做好的img文件打包

bzip2 linuxsys_iMX6ULL_512MB.img

再拷贝到windows下,烧录就完成了

类似UltraISO的系统镜像制作U盘启动工具。 Installing an operating system from a USB drive is much more convenient than from a disc, and a bootable drive even enables you to work from a system that does not have an OS installed. Rufus is a small-sized app that enables users to format USB flash disks and create bootable drives rapidly. It provides standard and advanced options alike, to suit the preferences of all skill levels. Format to the desired file system The tool is wrapped in a user-friendly interface that resembles the Format panel found in Windows built-in features. You can select a device, partition scheme and target system type, file system type (FAT32, NTFS, UDF, exFAT), cluster size, and new volume label. Connected devices are detected and selected from a drop-down menu. Be sure to save all important data, because the USB drive is formatted and everything is removed in the process. Compatibility options for old BIOS Basic formatting options enable you to check the device for bad blocks and select the algorithm type (from 1 to 4 passes). Plus, you can set the quick format mode, create an extended label and icon files, as well as create a bootable disk using an ISO or various other disc image types. Advanced tweaks can make Rufus list fixed (non-flash) or unpartitioned USB flash disks, add fixes for old BIOS (e.g. extra partition), and you may use Rufus MBR with a selected BIOS ID. To conclude The program records all activity to a separate panel, and it can be saved to a LOG file. It carries out a formatting task rapidly and error-free, using low system resources. We have not come across any issues during our tests since the utility did not cause Windows to hang or crash. To sum it up, Rufus is a straightforward solution to formatting and creating bootable USB drive, providing users with a series of useful features.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值