lk中的flashlayout

来源:互联网 发布:崩坏三矩阵buff 编辑:程序博客网 时间:2024/05/20 13:04
在lk中通过如下方式得到flashlayout的信息
ptable = flash_get_ptable();
我们看看flash_get_ptable的实现
struct ptable *flash_get_ptable(void)
{
return flash_ptable;
}
仅仅是返回flash_ptable这个全局变量。
那这个变量是在哪里赋值的呢?
void flash_set_ptable(struct ptable *new_ptable)
{
ASSERT(flash_ptable == NULL && new_ptable != NULL);
flash_ptable = new_ptable;
}
可见是通过flash_set_ptable 进行赋值的
那又是在哪里调用flash_set_ptable的呢?
一般在target下面的Init.c中进行
void target_init(void)
{
for (i = 0; i < num_parts; i++) {
struct ptentry *ptn = &board_part_list[i];
unsigned len = ptn->length;


if ((len == 0) && (i == num_parts - 1))
len = flash_info->num_blocks - offset - ptn->start;
ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
  len, ptn->flags);
}


ptable_dump(&flash_ptable);
flash_set_ptable(&flash_ptable);
}
可以看到将board_part_list 中的flashlayout一个一个通过ptable_add 添加到flash_ptable 这个局部变量中。
最后在调用flash_set_ptable来设定flashlayout


其中board_part_list是静态定义的数组,通过也是在init.c中实现的


static struct ptentry board_part_list[] = {
{
.start = 0,
.length = 40,
.name = "boot",
},
{
.start = 56,
.length = 608 /* 76MB */,
.name = "system",
},
{
.start = 664,
.length = 608 /* 76MB */,
.name = "cache",
},
{
.start = 1272,
.length = 0,
.name = "userdata",
},
};
0 0