Yocto:NXP s32g emmc镜像生成过程分析

研究一下nxp s32g平台emmc分区如何分配,发现不像高通和MTK平台有专门的地方配置分区。

怎么办?可以从结果推导,emmc和sdcard都是烧录fsl-image-auto-s32g399ardb3-20221027054141.rootfs.sdcard这个文件。

一、如何生成rootfs.sdcard文件

 fsl-image-auto-s32g399ardb3-20221027054141.rootfs.sdcard这个文件是如何产生的呢?

办法可以通过bitbake fsl-image-auto -c listtasks查看生成fsl-image-auto有哪些task

 看名字应该就是do_image_sdcard这个task。Ok,现在强制执行do_image_sdcard命令并开启编译信息和debug log

bitbake fsl-image-auto -c do_image_sdcard -f -vv -DD 2>&1 | tee build4.log

从编译log中梳理了下,一共做了这几件事。

1、生成空的rootfs.scard文件

++ expr 1024 '*' 598016
//生成大小为612368384, 全为0的fsl-image-auto-s32g399ardb3-20221027155143.rootfs.sdcard文件
+ dd if=/dev/zero of=/work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221027155143.rootfs.sdcard bs=1 count=0 seek=612368384

0+0 records in
0+0 records out
0 bytes copied, 7.344e-06 s, 0.0 kB/s

2、写入分区信息

//将rootfs.sdcard的Partition Table: msdos命名为msdos
+ parted -s /work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221027155143.rootfs.sdcard mklabel msdos

uh-oh!  '/proc/1/root' seems to be a symlink, but I can't read it.  Ignoring.
sh: udevadm: command not found

sh: udevadm: command not found

++ expr 4096 + 65536
//新建fat32分区信息,起始地址为4096K,大小69632K
+ parted -s /work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221027155143.rootfs.sdcard unit KiB mkpart primary fat32 4096 69632

uh-oh!  '/proc/1/root' seems to be a symlink, but I can't read it.  Ignoring.
sh: udevadm: command not found

sh: udevadm: command not found

+ create_rootfs_partition 69632 524288 /work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221027155143.rootfs.ext4

+ SDCARD_ROOTFS_START=69632

+ SDCARD_ROOTFS_SIZE=524288
+ SDCARD_ROOTFS_NAME=/work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221027155143.rootfs.ext4

+ '[' -n /work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221027155143.rootfs.ext4 ']'

++ expr 69632 + 524288
//新建分区起始地址为69632K大小为593920, 这个分区用来存rootfs是ext4格式
+ parted -s /work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221027155143.rootfs.sdcard unit KiB mkpart primary 69632 593920

uh-oh!  '/proc/1/root' seems to be a symlink, but I can't read it.  Ignoring.
sh: udevadm: command not found

sh: udevadm: command not found

+ create_rootfs_partition 0 0

+ SDCARD_ROOTFS_START=0

+ SDCARD_ROOTFS_SIZE=0
+ SDCARD_ROOTFS_NAME=

+ '[' -n '' ']'
+ create_rootfs_partition 0 0

+ SDCARD_ROOTFS_START=0
+ SDCARD_ROOTFS_SIZE=0
+ SDCARD_ROOTFS_NAME=

+ '[' -n '' ']'
//打印分区信息
+ parted /work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221027155143.rootfs.sdcard print

Model:  (file)
Disk /work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221027155143.rootfs.sdcard: 612MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      4194kB  71.3MB  67.1MB  primary               lba
 2      71.3MB  608MB   537MB   primary

3、写入uboot镜像

+ _burn_bootloader

+ case "u-boot-s32" in

+ '[' -n '' ']'

+ '[' 0 = 0 ']'

//将uboot镜像从0地址写入256字节
+ dd if=/work/projects/b33_6/build_s32g399ardb3/tmp/deploy/images/s32g399ardb3/fip.s32-sdcard of=/work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221027155143.rootfs.sdcard conv=notrunc seek=0 bs=256 count=1

1+0 records in
1+0 records out
256 bytes copied, 1.1612e-05 s, 22.0 MB/s

//将uboot镜像跳过512字节,同时待写文件也跳过512字节再写入
+ dd if=/work/projects/b33_6/build_s32g399ardb3/tmp/deploy/images/s32g399ardb3/fip.s32-sdcard of=/work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221027155143.rootfs.sdcard conv=notrunc bs=512 seek=1 skip=1

1917+1 records in
1917+1 records out
981600 bytes (982 kB, 959 KiB) copied, 0.0012824 s, 765 MB/s

+ '[' -n 0x001e0000 -a -n u-boot-flashenv-sd-s32g399ardb3.bin ']'

++ printf %d 0x001e0000
//将uboot环境变量写入到1966080地址
+ dd if=/work/projects/b33_6/build_s32g399ardb3/tmp/deploy/images/s32g399ardb3/u-boot-flashenv-sd-s32g399ardb3.bin of=/work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221027155143.rootfs.sdcard conv=notrunc seek=1966080 bs=1

8192+0 records in
8192+0 records out
8192 bytes (8.2 kB, 8.0 KiB) copied, 0.00412364 s, 2.0 MB/s

4、写入boot.img镜像


++ expr 4096 '*' 1024

//下面通过dd命令将生成好的boot.img写入到rootfs.sdcard中,从4M地址开始写

+ dd if=/work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/boot.img of=/work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221027155143.rootfs.sdcard conv=notrunc,fsync seek=1 bs=4194304

16+0 records in
16+0 records out
67108864 bytes (67 MB, 64 MiB) copied, 0.0280287 s, 2.4 GB/s

5、写入rootfs.ext4镜像

++ expr 69632 '*' 1024

//将rootfs镜像文件rootfs.ext4写入到rootfs.sdcard中去,从69632K地址开始
+ dd if=/work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221027155143.rootfs.ext4 of=/work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221027155143.rootfs.sdcard conv=notrunc,fsync seek=1 bs=71303168

总结:目前整个镜像文件fsl-image-auto-s32g399ardb3-20221027155143.rootfs.sdcard包含三部分。 1.前面4M用来存放bootloader, 还有uboot环境变量

        2.第二段是存放boot.img, 这个boot.img里面是fat32类型文件系统,用来存放kernel镜像和对应板子的dtb

        3.第三部分用来存放rootfs.ext4,也就是文件系统,其文件系统是ext4

二、boot.img如何生成的?

还有这里再写一下这个boot.img是如何生成的?他又是怎么生成fat32格式的呢?还是从编译Log上入手.

1、生成空的boot.img格式是fat32格式

+ _generate_boot_image 1

+ local boot_part=1

++ LC_ALL=C
++ parted -s /work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221027155143.rootfs.sdcard unit b print

++ awk '/ 1 / { print substr($4, 1, length($4 -1)) / 1024 }'

+ BOOT_BLOCKS=65536

++ expr 65536 / 1024

+ '[' 64 -gt 512 ']'

+ rm -f /work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/boot.img

//通过mkfs.vfat生成大小为65536KB的分区
+ mkfs.vfat -n boot_s32g399ardb3 -S 512 -C /work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/boot.img 65536

mkfs.fat: warning - lowercase labels might not work properly with DOS or Windows

mkfs.fat 4.1 (2017-01-24)

2、将kernel编译出来的bin拷贝到boot.img中

//通过mcopy将下面将-s后面的文件拷贝到-i boot.img里面并重新命名为Image
+ mcopy -i /work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/boot.img -s /work/projects/b33_6/build_s32g399ardb3/tmp/deploy/images/s32g399ardb3/Image-s32g399ardb3.bin ::/Image

3、将板子对应的dtb文件拷贝到boot.img中

+ test -n freescale/s32g399a-rdb3.dtb

++ readlink /work/projects/b33_6/build_s32g399ardb3/tmp/deploy/images/s32g399ardb3/Image-s32g399ardb3.bin

+ kernel_bin=Image--5.10.109-r0-s32g399ardb3-20221027155143.bin
+ for DTS_FILE in freescale/s32g399a-rdb3.dtb

++ basename freescale/s32g399a-rdb3.dtb

++ awk -F . '{print $1}'
+ DTS_BASE_NAME=s32g399a-rdb3

+ DTB_PATH=
+ kernel_bin_for_dtb=

+ '[' -e /work/projects/b33_6/build_s32g399ardb3/tmp/deploy/images/s32g399ardb3/Image-s32g399a-rdb3.dtb ']'

+ '[' -e /work/projects/b33_6/build_s32g399ardb3/tmp/deploy/images/s32g399ardb3/s32g399a-rdb3.dtb ']'

+ DTB_PATH=/work/projects/b33_6/build_s32g399ardb3/tmp/deploy/images/s32g399ardb3/s32g399a-rdb3.dtb

++ readlink /work/projects/b33_6/build_s32g399ardb3/tmp/deploy/images/s32g399ardb3/s32g399a-rdb3.dtb

++ sed 's,s32g399a-rdb3,Image,;s,\.dtb$,.bin,g'

+ kernel_bin_for_dtb=Image--5.10.109-r0-s32g399ardb3-20221027155143.bin

+ '[' -n /work/projects/b33_6/build_s32g399ardb3/tmp/deploy/images/s32g399ardb3/s32g399a-rdb3.dtb ']'
+ '[' Image--5.10.109-r0-s32g399ardb3-20221027155143.bin = Image--5.10.109-r0-s32g399ardb3-20221027155143.bin ']'

//下面将-s后面的文件s32g399a-rdb3.dtb拷贝到-i boot.img里面并命名为s32g399a-rdb3.dtb

+ mcopy -i /work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/boot.img -s /work/projects/b33_6/build_s32g399ardb3/tmp/deploy/images/s32g399ardb3/s32g399a-rdb3.dtb ::/s32g399a-rdb3.dtb


三、rootfs.ext4如何生成的?

1.生成空的rootfs.ext4

//通过dd生成大小为524266KB全为0的rootfs.ext4
+ dd if=/dev/zero of=/work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221028121601.rootfs.ext4 seek=524288 count=0 bs=1024

0+0 records in
0+0 records out
0 bytes copied, 7.614e-06 s, 0.0 kB/s

2.将rootfs.ext4文件格式为ext4,并把roofs文件拷贝经rootfs.ext4文件中

//将rootfs.ext4格式化为ext4并把路径*fsl-image-auto/1.0-r0/rootfs下所有
//文件拷贝到rootfs.ext4中
+ mkfs.ext4 -F -i 4096 -L fsl-image-auto-s32g399ardb3-20221028121601 /work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221028121601.rootfs.ext4 -d /work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/rootfs

Warning: label too long; will be truncated to 'fsl-image-auto-s'

mke2fs 1.45.6 (20-Mar-2020)

Discarding device blocks:   4096/131072^H^H^H^H^H^H^H^H^H^H^H^H^H             ^H^H^H^H^H^H^H^H^H^H^H^H^Hdone

Creating filesystem with 131072 4k blocks and 131072 inodes
Filesystem UUID: 75fa8ef7-814a-4e09-b3df-745dc8bb8af1
Superblock backups stored on blocks:
    32768, 98304

Allocating group tables: 0/4^H^H^H   ^H^H^Hdone
Writing inode tables: 0/4^H^H^H
   ^H^H^Hdone

Creating journal (4096 blocks):
done
Copying files into the device:
done
Writing superblocks and filesystem accounting information: 0/4^H^H^H   ^H^H^Hdone

//对刚才生成的rootfs.ext4,用fsck.ext4命令对ext4型文件系统进行检测

+ fsck.ext4 -pvfD /work/projects/b33_6/build_s32g399ardb3/tmp/work/s32g399ardb3-fsl-linux/fsl-image-auto/1.0-r0/deploy-fsl-image-auto-image-complete/fsl-image-auto-s32g399ardb3-20221028121601.rootfs.ext4


       16802 inodes used (12.82%, out of 131072)
           4 non-contiguous files (0.0%)
          23 non-contiguous directories (0.1%)
             # of inodes with ind/dind/tind blocks: 0/0/0
             Extent depth histogram: 14685/2
      112284 blocks used (85.67%, out of 131072)
           0 bad blocks
           1 large file

       12811 regular files
        1749 directories
           0 character device files
           0 block device files
           0 fifos
        3155 links
        2233 symbolic links (2107 fast symbolic links)
           0 sockets
------------
       19948 files

类似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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值