11.OP-TEE OS启动(二)

   

  

如果系统中有ATF,则generic_boot_init_primary函数执行完成之后需要返回OP-TEE的向量表。如果不止ATF则不需返回向量表。OP-TEE启动过程中主体初始化操作都是在generic_boot_init_primary函数中被执行的。下图为该函数的执行流程图:

1.generic_boot_init_primary

  generic_boot_init_primary函数是OP-TEE OS进行初始化的主要函数,该函数最终会调用init_primary_helper函数来完成实际的启动操作。init_primary_helper函数内容如下:

static void init_primary_helper(unsigned long pageable_part,
				unsigned long nsec_entry, unsigned long fdt)
{
	/*
	 * Mask asynchronous exceptions before switch to the thread vector
	 * as the thread handler requires those to be masked while
	 * executing with the temporary stack. The thread subsystem also
	 * asserts that the foreign interrupts are blocked when using most of
	 * its functions.
	 */
	thread_set_exceptions(THREAD_EXCP_ALL);	//设置支持哪些异常处理
	init_vfp_sec();	//初始化浮点运算(根据实际需要考虑是否开启)

	init_runtime(pageable_part);	//初始化各种memory,清空BSS段,分配TA运行时的memory

	IMSG("Initializing (%s)\n", core_v_str);

/* 初始化TEE中支持的线程栈,异常处理,pagetable */
	thread_init_primary(generic_boot_get_handlers());
	
//初始化每个CPU的monitor态的处理方式,如果支持ATF则无需该操作
thread_init_per_cpu();	

/* 如果系统不支持ATF,则需要配置在Linux kernel中monitor的处理方式 */
	init_sec_mon(nsec_entry);

/* 初始化device tree */
	init_fdt(fdt);

/* 初始化中断控制器 */
	main_init_gic();

/* 初始化非安全侧的浮点运算 */
	init_vfp_nsec();

/* 初始化共享内存并执行存放在__initcall_start段的其他初始化函数 */
	if (init_teecore() != TEE_SUCCESS)
		panic();
	DMSG("Primary CPU switching to normal world boot\n");
}

2. __define_initcall

  介绍各种service之前,有必要先介绍以下_define_initcall宏的作用。通过使用该宏,在编译的时候可以将需要需要的内容编译到__initcall段。该宏的定义如下:

#define __define_initcall(level, fn) \
	static initcall_t __initcall_##fn __attribute__((used)) \
	__attribute__((__section__(".initcall" level))) = fn

initcall_t:一个函数指针类型,typedef int(*initcall_t)(void)

__attribute__((__section__()) : 将fn对象放在一个由括号中的名称指定的section中。

## :连接作用

例如如果使用该宏如下:

__define_initcall("1", init_operation)

则该宏的作用是声明一个名称为__initcall_init_operation的函数指针,将该函数指针初始化为init_operation,并在编译的时候将该函数的内容存放在名称为".initcall1"段中

3. call_initcalls

  当初始化完memory,CPU相关设置,中断控制器,share memory,线程堆栈设置,TA运行memory分配等操作之后,最终通过init_teecore函数来调用call_initcalls函数完成OP-TEE OS中的各种service的启动。该操作是通过执行__initcallx段的代码来实现。该端代码的内容如下:

static void call_initcalls(void)
{
	initcall_t *call;

/* 遍历并执行_initcallx段中所有函数 */
	for (call = &__initcall_start; call < &__initcall_end; call++) {
		TEE_Result ret;
		ret = (*call)();
		if (ret != TEE_SUCCESS) {
			EMSG("Initial call 0x%08" PRIxVA " failed",
			     (vaddr_t)call);
		}
	}
}


  call_initcalls将会遍历从__initcall_start到__initcall_end之间的段中所有的函数,并执行。该区块的定义在core/arch/arm/kernel/kern.ld.S文件中,具体内容如下:

  由此可见,调用call_initcalls函数的将会去执行initcall1, initcall2, initcall3, initcall4段中的所有内容。通过使用__define_initcall宏来将特定的initcall代码存放到对应的段中,在OP-TEE中,会使用到__define_initcall宏的定义在core/include/initcall.h文件中,具体内容如下:

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值