Standalone"/>
Standalone
参考:doc/README.standalone
-
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。
-
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);
-
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;}
-
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
-
To export some additional function long foobar(int i,char c), the following steps should be undertaken:
导出自定义的函数实现给standalone程序需要遵循如下步骤(要求):
-
在
include/_exports.h
中添加函数属性,如:#ifdef CONFIG_FOOBAREXPORT_FUNC(foobar, long, foobar, int, char) #elseEXPORT_FUNC(dummy, void, foobar, void) #endif
- foobar,函数名;
- long,函数返回值类型;
- foobar,gd->jt中成员名;
- 余下,函数入参;
-
在gd->tj新装成员foobar后,可以使用赋值的方式直接修改指向的函数实现,如:
gd->jt->foobar = another_foobar;
-
standalone版本号递增更新
#define XF_VERSION 9
-
-
The code for exporting the U-Boot functions to applications is mostly machine-independent.
导出给standalone程序使用函数多是设备无关的代码实现,所以standalone在移植到一个新设备时,唯一需要关注的是
examples/stubs.c
中的代码。
更多推荐
Standalone
发布评论