【u-boot】u-boot的分区支持

一、源码结构解读

在u-boot源码中对分区表的支持代码实现在/disk目录中,原生目录结构如下:

特定芯片厂家将会开发自己的分区类型,这时候这些文件也放置到/disk目录中。

使用如下命令:

plain 复制代码
part list mmc 0

可查看具体设备的所有分区信息(包括分区类型),上述示例是查看mmc 0设备的分区类型。例如:

u-boot支持分区类型如下表所示:

分区类型 源码文件 详细描述
DOS/MBR part_dos.c 解析 DOS/MBR (Master Boot Record) 分区表。
GPT part_efi.c 解析 GPT (GUID Partition Table),即 EFI/UEFI 分区格式。
ISO (CD-ROM) part_iso.c 解析 ISO 9660 分区(光盘镜像格式)。
Mac part_mac.c/part_mac.h 解析 Apple Partition Map (APM)。
Amiga part_amiga.c/part_amiga.h 解析 Amiga Rigid Disk Block (RDB) 分区表格式。

二、分区类型的实现

在u-boot中,当需要实现分区类型的时候,需要使用U_BOOT_PART_TYPE声明一个新的U-Boot分区类型驱动。例如dos分区类型的实现:

c 复制代码
U_BOOT_PART_TYPE(dos) = {
    .name		= "DOS",
    .part_type	= PART_TYPE_DOS,
    .max_entries	= DOS_ENTRY_NUMBERS,
    .get_info	= part_get_info_ptr(part_get_info_dos),
    .print		= part_print_ptr(part_print_dos),
    .test		= part_test_dos,
};

U_BOOT_PART_TYPE宏的实现本质是创建struct part_driver类型的全局结构变量,并将其放置到特定段中。struct part_drvier实现如下:

c 复制代码
struct part_driver {
	const char *name;
	int part_type;
	const int max_entries;	/* maximum number of entries to search */

	/**
	 * get_info() - 获取有关分区的信息
	 *
	 * @dev_desc:	Block device descriptor
	 * @part:	Partition number (1 = first)
	 * @info:	Returns partition information
	 */
	int (*get_info)(struct blk_desc *dev_desc, int part,
			disk_partition_t *info);

	/**
	 * print() - 打印分区表信息
	 *
	 * @dev_desc:	Block device descriptor
	 */
	void (*print)(struct blk_desc *dev_desc);

	/**
	 * test() - Test if a device contains this partition type
	 *
	 * @dev_desc:	Block device descriptor
	 * @return 0 if the block device appears to contain this partition
	 *	   type, -ve if not
	 */
	int (*test)(struct blk_desc *dev_desc);
};

在创建特定分区表驱动的时候需要填充上述结构中的组成元素。

->print回调的调用发生在执行part_print()的时候,函数调用链如下图所示:

->get_info回调的调用发生在执行part_get_info_by_name_option()的时候,函数调用链如下:

相关推荐
余衫马1 天前
为什么在 Windows 上用 Clang/LLVM?
c++·windows·c
一枝小雨2 天前
【OTA专题】 20 上电立即跳转:加快MCU启动速度
stm32·单片机·嵌入式·ota·bootloader·加速启动
REDcker3 天前
AIGCJson 库介绍与使用指南
c++·json·aigc·c
一枝小雨4 天前
【OTA专题】17 打通Bootloader与App逻辑之间的通信
stm32·单片机·嵌入式·流程图·freertos·ota·bootloader
一枝小雨4 天前
【OTA专题】18 OTA性能优化:优化bootloader存储空间与固件完整性校验(CRC)
stm32·单片机·性能优化·嵌入式·freertos·ota·bootloader
消失的旧时光-19435 天前
函数指针 + 结构体 = C 语言的“对象模型”
c·对象模型
REDcker5 天前
RTCP 刀尖点跟随技术详解
c++·机器人·操作系统·嵌入式·c·数控·机床
一枝小雨5 天前
【OTA专题】15 实现App后台无感下载固件
stm32·单片机·嵌入式·ota·bootloader
消失的旧时光-19436 天前
函数指针 + 结构体 = C 语言的“对象模型”?——从 C 到 C++ / Java 的本质统一
linux·c语言·开发语言·c++·c
埃伊蟹黄面7 天前
ELF深入解剖:从文件头到动态段,图解库的二进制构成
linux·c·