X210开发板(S5PV210芯片)uboot中SD卡分区分析(init_raw_area_table函数)

该博客详细介绍了U-Boot中init_raw_area_table函数的调用过程,以及struct raw_area和struct member结构体的定义。该函数主要用于初始化SD卡/iNand的分区信息,包括BL1、环境分区、BL2、内核和根文件系统等分区的起始扇区、大小和用途。同时,博客还展示了未分配分区的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、init_raw_area_table函数调用关系

	start.s
		start_armboot()
			mmc_initialize()
				mmc_init()
					mmc_startup()
						init_raw_area_table()

2、struct raw_area结构体 & struct member结构体

//这个结构体包含所有分区的信息
typedef struct raw_area {
	uint magic_number; /* to identify itself */
	uint start_blk; /* compare with PT on coherency test */
	uint total_blk;
	uint next_raw_area; /* should be sector number */
	char description[16];
	member_t image[15];	//具体每个分区的描述信息
} raw_area_t; /* 512 bytes */

//描述单个分区信息
typedef struct member {
	uint start_blk; //分区开始扇区号
	uint used_blk;	//分区总共的扇区数
	uint size;		//分区大小
	uint attribute; //表示分区的用途:
	char description[16]; //用字符串的方式表示分区用途
} member_t; /* 32 bytes */

3、init_raw_area_table()函数功能分析

(1)主要是就是初始化全局变量raw_area_control的image成员变量,image数组里记录了每个分区的起始扇区、大小等信息;
(2)初始化image数组的宏定义在./include/movi.h中定义;
(3)uboot在读写分区时,就是按照iamge中描述的分区信息(扇区号、大小)进行操作;

4、init_raw_area_table()函数代码

//cmd_movi.c

raw_area_t raw_area_control;

int init_raw_area_table (block_dev_desc_t * dev_desc)
{
	struct mmc *host = find_mmc_device(dev_desc->dev);
	
	/* when last block does not have raw_area definition. */
	if (raw_area_control.magic_number != MAGIC_NUMBER_MOVI) {
		int i = 0;
		member_t *image;
		u32 capacity;
	
		if (host->high_capacity) {
			capacity = host->capacity;
		} else {
			capacity = host->capacity;
		}

		dev_desc->block_read(dev_desc->dev,
			capacity - (eFUSE_SIZE/MOVI_BLKSIZE) - 1,
			1, &raw_area_control);
		if (raw_area_control.magic_number == MAGIC_NUMBER_MOVI) {
			return 0;
		}
		
		dbg("Warning: cannot find the raw area table(%p) %08x\n",
			&raw_area_control, raw_area_control.magic_number);
		/* add magic number */
		raw_area_control.magic_number = MAGIC_NUMBER_MOVI;

		/* init raw_area will be 16MB */
		raw_area_control.start_blk = 16*1024*1024/MOVI_BLKSIZE;
		raw_area_control.total_blk = capacity;
		raw_area_control.next_raw_area = 0;
		strcpy(raw_area_control.description, "initial raw table");

		/*开始初始化各个分区信息保存到raw_area_control.image数组*/
		image = raw_area_control.image;

		/* image 1 should be bl1 */
		image[1].start_blk = (eFUSE_SIZE/MOVI_BLKSIZE);
		image[1].used_blk = MOVI_BL1_BLKCNT;
		image[1].size = SS_SIZE;

		image[1].attribute = 0x1;
		
		strcpy(image[1].description, "u-boot parted");
		dbg("bl1: %d\n", image[1].start_blk);

		/* image 2 should be environment */
		image[2].start_blk = image[1].start_blk + MOVI_BL1_BLKCNT;
		image[2].used_blk = MOVI_ENV_BLKCNT;
		image[2].size = CFG_ENV_SIZE;
		image[2].attribute = 0x10;
		strcpy(image[2].description, "environment");
		dbg("env: %d\n", image[2].start_blk);

		/* image 3 should be bl2 */
		image[3].start_blk = image[2].start_blk + MOVI_ENV_BLKCNT;
		image[3].start_blk = image[2].start_blk - MOVI_BL2_BLKCNT;
		image[3].used_blk = MOVI_BL2_BLKCNT;
		image[3].size = PART_SIZE_BL;
		image[3].attribute = 0x2;
		strcpy(image[3].description, "u-boot");
		dbg("bl2: %d\n", image[3].start_blk);

		/* image 4 should be kernel */
		image[4].start_blk = image[3].start_blk + MOVI_BL2_BLKCNT;
		image[4].used_blk = MOVI_ZIMAGE_BLKCNT;
		image[4].size = PART_SIZE_KERNEL;
		image[4].attribute = 0x4;
		strcpy(image[4].description, "kernel");
		dbg("knl: %d\n", image[4].start_blk);

		/* image 5 should be RFS */
		image[5].start_blk = image[4].start_blk + MOVI_ZIMAGE_BLKCNT;
		image[5].used_blk = MOVI_ROOTFS_BLKCNT;
		image[5].size = PART_SIZE_ROOTFS;
		image[5].attribute = 0x8;
		strcpy(image[5].description, "rfs");
		dbg("rfs: %d\n", image[5].start_blk);

		/*没用到的全部初始化为0*/
		for (i=6; i<15; i++) {
			raw_area_control.image[i].start_blk = 0;
			raw_area_control.image[i].used_blk = 0;
		}
	}
}

5、SD卡/iNand的分区情况

iamge数组扇区号分区名大小分区名
00MBR512B引导扇区
11-16BL18KBu-boot parted(BL1)
217-48environment16KBenvironment
349-1072BL2512KBu-boot(BL2,完整的uboot)
41073-9264kernel4MBkernel
59265-62512rootfs26MBrfs
6-1462512-100%未分配剩余全部未分配
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

正在起飞的蜗牛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值