Standalone

编程入门 行业动态 更新时间:2024-10-13 18:20:47

<a href=https://www.elefans.com/category/jswz/34/1586889.html style=Standalone"/>

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_mallocgd->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 addressx86         0x00040000     0x00040000PowerPC     0x00040000     0x00040004ARM	        0x0c100000     0x0c100000MIPS        0x80200000     0x80200000Blackfin    0x00001000     0x00001000NDS32       0x00300000     0x00300000Nios 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_FOOBAREXPORT_FUNC(foobar, long, foobar, int, char)
      #elseEXPORT_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中的代码。

更多推荐

Standalone

本文发布于:2023-12-03 19:34:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1657008.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Standalone

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!