Standalone---基础认知

参考:doc/README.standalone

  1. The functions are exported by U-Boot via a jump table.

    • 跳转表的初始函数jumptable_init()在common/exports.c文件中实现
    • 跳转表结构体在include/exports.h文件中定义
    // u-boot/include/asm-generic/global_data.h
    typedef struct global_data {
    	bd_t *bd;
        ...
    	struct jt_funcs *jt;		/* jump table */
    
    // u-boot/include/exports.h
    struct jt_funcs {
    #define EXPORT_FUNC(impl, res, func, ...) res(*func)(__VA_ARGS__);			// 先宏定义
    #include <_exports.h>
    #undef EXPORT_FUNC																				// 去宏定义
    };
        
    // u-boot/include/_exports.h
    #ifndef EXPORT_FUNC										// 宏定义检查,规避直接引用导致异常
    #define EXPORT_FUNC(a, b, c, ...)
    #endif
    	...
    	EXPORT_FUNC(malloc, void *, malloc, size_t)
    	...
    	EXPORT_FUNC(free, void, free, void *)    
    

    此时,standlone程序就可以使用malloc与free。

    此外可以使用修改gd->jt中默认函数,如:

    	DECLARE_GLOBAL_DATA_PTR;				// 定义变量gd;
    
    	gd->jt->malloc	= my_malloc;				// 修改为自定义的my_malloc
    	gd->jt->free      = my_free;
    

    此时,standalone使用就是替换后的malloc与free。

  2. The pointer to the jump table is passed to the application in a machine-dependent way.

    standalone程序可以直接访问全局变量gd,如:

    	DECLARE_GLOBAL_DATA_PTR;
    
    	printf("U-Boot relocation offset: %x\n", gd->reloc_off);
    
  3. The application should call the app_startup() function before any call to the exported functions.

    standalone程序入口先使用app_startup()函数启动应用,再进行后续操作,如:

    	int my_app (int argc, char * const argv[])
    	{
    		app_startup (argv);
    		if (get_version () != XF_VERSION)
    			return 1;
    	}
    
  4. The default load and start addresses of the applications are as follows:

    standalone程序默认运行地址如下:

    	          Load address  Start address
    	x86         0x00040000     0x00040000
    	PowerPC     0x00040000     0x00040004
    	ARM	        0x0c100000     0x0c100000
    	MIPS        0x80200000     0x80200000
    	Blackfin    0x00001000     0x00001000
    	NDS32       0x00300000     0x00300000
    	Nios II     0x02000000     0x02000000
    

    进而,加载运行时可以使用命令:

       => tftp 0x40000 hello_world.bin
       => go 0x40004
    
  5. To export some additional function long foobar(int i,char c), the following steps should be undertaken:

    导出自定义的函数实现给standalone程序需要遵循如下步骤(要求):

    1. include/_exports.h中添加函数属性,如:

      #ifdef CONFIG_FOOBAR
      	EXPORT_FUNC(foobar, long, foobar, int, char)
      #else
      	EXPORT_FUNC(dummy, void, foobar, void)
      #endif
      
      • foobar,函数名;
      • long,函数返回值类型;
      • foobar,gd->jt中成员名;
      • 余下,函数入参;
    2. 在gd->tj新装成员foobar后,可以使用赋值的方式直接修改指向的函数实现,如:

      	gd->jt->foobar = another_foobar;
      
    3. standalone版本号递增更新

      #define XF_VERSION	9
      
  6. The code for exporting the U-Boot functions to applications is mostly machine-independent.

    导出给standalone程序使用函数多是设备无关的代码实现,所以standalone在移植到一个新设备时,唯一需要关注的是examples/stubs.c中的代码。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值