README.standalone 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. Design Notes on Exporting U-Boot Functions to Standalone Applications:
  2. ======================================================================
  3. 1. The functions are exported by U-Boot via a jump table. The jump
  4. table is allocated and initialized in the jumptable_init() routine
  5. (common/exports.c). Other routines may also modify the jump table,
  6. however. The jump table can be accessed as the 'jt' field of the
  7. 'global_data' structure. The struct members for the jump table are
  8. defined in the <include/exports.h> header. E.g., to substitute the
  9. malloc() and free() functions that will be available to standalone
  10. applications, one should do the following:
  11. DECLARE_GLOBAL_DATA_PTR;
  12. gd->jt->malloc = my_malloc;
  13. gd->jt->free = my_free;
  14. Note that the pointers to the functions are real function pointers
  15. so the compiler can perform type checks on these assignments.
  16. 2. The pointer to the jump table is passed to the application in a
  17. machine-dependent way. PowerPC, ARM, MIPS, Blackfin and Nios II
  18. architectures use a dedicated register to hold the pointer to the
  19. 'global_data' structure: r2 on PowerPC, r9 on ARM, k0 on MIPS,
  20. P3 on Blackfin and gp on Nios II. The x86 architecture does not
  21. use such a register; instead, the pointer to the 'global_data'
  22. structure is passed as 'argv[-1]' pointer.
  23. The application can access the 'global_data' structure in the same
  24. way as U-Boot does:
  25. DECLARE_GLOBAL_DATA_PTR;
  26. printf("U-Boot relocation offset: %x\n", gd->reloc_off);
  27. 3. The application should call the app_startup() function before any
  28. call to the exported functions. Also, implementor of the
  29. application may want to check the version of the ABI provided by
  30. U-Boot. To facilitate this, a get_version() function is exported
  31. that returns the ABI version of the running U-Boot. I.e., a
  32. typical application startup may look like this:
  33. int my_app (int argc, char *const argv[])
  34. {
  35. app_startup (argv);
  36. if (get_version () != XF_VERSION)
  37. return 1;
  38. }
  39. 4. The default load and start addresses of the applications are as
  40. follows:
  41. Load address Start address
  42. x86 0x00040000 0x00040000
  43. PowerPC 0x00040000 0x00040004
  44. ARM 0x0c100000 0x0c100000
  45. MIPS 0x80200000 0x80200000
  46. Blackfin 0x00001000 0x00001000
  47. NDS32 0x00300000 0x00300000
  48. Nios II 0x02000000 0x02000000
  49. RISC-V 0x00600000 0x00600000
  50. For example, the "hello world" application may be loaded and
  51. executed on a PowerPC board with the following commands:
  52. => tftp 0x40000 hello_world.bin
  53. => go 0x40004
  54. 5. To export some additional function long foobar(int i,char c), the following steps
  55. should be undertaken:
  56. - Append the following line at the end of the include/_exports.h
  57. file:
  58. EXPORT_FUNC(foobar, long, foobar, int, char)
  59. Parameters to EXPORT_FUNC:
  60. - the first parameter is the function that is exported (default implementation)
  61. - the second parameter is the return value type
  62. - the third parameter is the name of the member in struct jt_funcs
  63. this is also the name that the standalone application will used.
  64. the rest of the parameters are the function arguments
  65. - Add the prototype for this function to the include/exports.h
  66. file:
  67. long foobar(int i, char c);
  68. Initialization with the default implementation is done in jumptable_init()
  69. You can override the default implementation using:
  70. gd->jt->foobar = another_foobar;
  71. The signature of another_foobar must then match the declaration of foobar.
  72. - Increase the XF_VERSION value by one in the include/exports.h
  73. file
  74. - If you want to export a function which depends on a CONFIG_XXX
  75. use 2 lines like this:
  76. #ifdef CONFIG_FOOBAR
  77. EXPORT_FUNC(foobar, long, foobar, int, char)
  78. #else
  79. EXPORT_FUNC(dummy, void, foobar, void)
  80. #endif
  81. 6. The code for exporting the U-Boot functions to applications is
  82. mostly machine-independent. The only places written in assembly
  83. language are stub functions that perform the jump through the jump
  84. table. That said, to port this code to a new architecture, the
  85. only thing to be provided is the code in the examples/stubs.c
  86. file. If this architecture, however, uses some uncommon method of
  87. passing the 'global_data' pointer (like x86 does), one should add
  88. the respective code to the app_startup() function in that file.
  89. Note that these functions may only use call-clobbered registers;
  90. those registers that are used to pass the function's arguments,
  91. the stack contents and the return address should be left intact.