文章目录
由于已经开始 linux-5.8.5 和 busybox-1.31.1 的移植,经常需要烧写 kernel 和 system 分区,所以还是先把需要的功能移植到 u-boot 上比较方便。
一、fdisk
移植官方 u-boot 的 fdisk 功能,可以进行 mbr 分区。关于 mbr 分区可以看下面参考的百度百科,不过直接看 fdisk 的 code 就能看出 mbr 是如何分区的了。
1. prepare
- 创建文件:
cmd/fdisk.c
- 修改:
cmd/Makefile
添加一行:obj-$(CONFIG_XHR4412) += fdisk.o
- 将官方 fdisk 文件拷贝过来
common/cmd_mmc_fdisk.c
2. build
简单报错就不记录了,记录一些比较难办的。
2.1 fatal error: movi.h: No such file or directory
将 include/movi.h
拷贝过来。
2.2 error: ‘struct mmc’ has no member named ‘block_dev’
新版的 u-boot 在 API 上有变化,将这类报错改为新版的 mmc block 的读写函数。
3. debug
完成上述 build 后,已经可以正常使用 fdisk -p 0
,将 mbr 表全写为 0x55 的情况:
xhr4412 # fdisk -p 0
partion # size(MB) block start # block count partition_Id
1 699050 1431655765 1431655765 0x55
2 699050 1431655765 1431655765 0x55
3 699050 1431655765 1431655765 0x55
4 699050 1431655765 1431655765 0x55
但是 fdisk -c 0
还没有正常工作。
3.1 total_block_count = -771751936
读到的 block count 为负数,原因为 mmc->capacity
被改为了 u64 类型,并且表示的是字节而不是 block。所以将它改为 block 就可以了。
xhr4412 # fdisk -p 0
partion # size(MB) block start # block count partition_Id
1 699050 1431655765 1431655765 0x55
2 699050 1431655765 1431655765 0x55
3 699050 1431655765 1431655765 0x55
4 699050 1431655765 1431655765 0x55
xhr4412 # fdisk -c 0
fdisk is completed
partion # size(MB) block start # block count partition_Id
1 5050 4881129 10344411 0x0C
2 1027 44781 2104707 0x83
3 1027 2149488 2104707 0x83
4 306 4254195 626934 0x83
修改后,分区就成功了。
二、write_compressed_ext4
之前移植过了,可以烧写根文件系统。(如果之后有补充再添加)