背景
以前制作工厂烧录的bin文件一直是先烧录板子,然后在板子上dd一个bin文件出来用于产线烧录,这种方式dd出来的bin文件是被在板子上运行过的,不是原始状态。
那么工作上遇到一些需求就是不想用这种方式,想要PC端原始生成一个bin文件,那么如下这种办法提供了一种方法,可以在PC端用dd命令生成一整个emmc的bin文件(partition+boot+rootfs)。
思路
通过dd制作partition后不要执行最后一步,即不执行dd if=disk.img of=partition.img bs=1k count=32,此时partition已经在了,然后再通过dd命令将其余的img加进去即可。
方法(example)
1)dd一个4G的bin文件
dd if=/dev/zero of=emmc.bin bs=1M count=4096
2)创建partition
hui@hui:~/work/tools/partition$ gdisk emmc.bin
GPT fdisk (gdisk) version 1.0.3
Partition table scan:
MBR: not present
BSD: not present
APM: not present
GPT: not present
Creating new GPT entries.
Command (? for help): n
Partition number (1-128, default 1):
First sector (34-8388574, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-8388574, default = 8388574) or {+-}size{KMGTP}: +256M
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Command (? for help): n
Partition number (2-128, default 2):
First sector (34-8388574, default = 526336) or {+-}size{KMGTP}:
Last sector (526336-8388574, default = 8388574) or {+-}size{KMGTP}: +3G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Command (? for help): p
Disk emmc.bin: 8388608 sectors, 4.0 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): A985885F-8435-49F1-AA58-5C82B863B981
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 8388574
Partitions will be aligned on 2048-sector boundaries
Total free space is 1572797 sectors (768.0 MiB)
Number Start (sector) End (sector) Size Code Name
1 2048 526335 256.0 MiB 8300 Linux filesystem
2 526336 6817791 3.0 GiB 8300 Linux filesystem
Command (? for help): c
Partition number (1-2): 1
Enter name: boot
Command (? for help): c
Partition number (1-2): 2
Enter name: rootfs
Command (? for help): p
Disk emmc.bin: 8388608 sectors, 4.0 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): A985885F-8435-49F1-AA58-5C82B863B981
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 8388574
Partitions will be aligned on 2048-sector boundaries
Total free space is 1572797 sectors (768.0 MiB)
Number Start (sector) End (sector) Size Code Name
1 2048 526335 256.0 MiB 8300 boot
2 526336 6817791 3.0 GiB 8300 rootfs
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to emmc.bin.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
3)将boot.img加到emmc.bin
simg2img boot.img boot.ext4
dd if=boot.ext4 of=emmc.bin bs=1K seek=1024 conv=notrunc
4)将rootfs.img添加到emmc.bin
simg2img rootfs.img rootfs.ext4
dd if=rootfs.ext4 of=emmc.bin bs=1M seek=257 conv=notrunc
完结!
如果对您有帮助,请动动手指点个赞哦 !
声明:自己总结,请结合自己情况使用!