• 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 *)    
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18
      • 19
      • 20
      • 21

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

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

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

      此时,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);
      
      • 1
      • 2
      • 3
    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;
      	}
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
    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
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8

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

         => tftp 0x40000 hello_world.bin
         => go 0x40004
      
      • 1
      • 2
    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
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • foobar,函数名;
        • long,函数返回值类型;
        • foobar,gd->jt中成员名;
        • 余下,函数入参;
      2. 在gd->tj新装成员foobar后,可以使用赋值的方式直接修改指向的函数实现,如:

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

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

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

  • 相关阅读:
    cocos入门3:新建项目
    依赖库:Ceres-solver-2.0.0安装
    7.20 - 每日一题 - 408
    关于Pandas数据分析
    Golang——从入门到放弃
    Vue搭建移动端h5项目(已开源,附带git地址)Vant+Vue Router+Vuex+axios封装+案例交互+部分代码说明
    adb官方最新下载链接和常用操作
    编译支持GPU的opencv,并供python的import cv2调用
    MySQL 5.7 安装教程(全步骤、保姆级教程)
    G. SlavicG‘s Favorite Problem(DFS序) 2022绵阳H(思维构造),M(并查集)
  • 原文地址:https://blog.csdn.net/gaoyang3513/article/details/134023672